Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cython
Commits
679eff3e
Commit
679eff3e
authored
Oct 03, 2020
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a more common and more versatile example to the Verbatim C-Code documentation.
parent
474573b3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
1 deletion
+20
-1
docs/examples/userguide/external_C_code/platform_adaptation.pyx
...xamples/userguide/external_C_code/platform_adaptation.pyx
+14
-0
docs/examples/userguide/external_C_code/verbatim_c_code.pyx
docs/examples/userguide/external_C_code/verbatim_c_code.pyx
+0
-0
docs/src/userguide/external_C_code.rst
docs/src/userguide/external_C_code.rst
+6
-1
No files found.
docs/examples/userguide/external_C_code/platform_adaptation.pyx
0 → 100644
View file @
679eff3e
cdef
extern
from
*
:
"""
#if defined(WIN32) || defined(MS_WINDOWS)
#include "windows.h"
#define myapp_sleep(m) Sleep(m)
#else
#include <unistd.h>
#define myapp_sleep(m) ((void) usleep((m) * 1000))
#endif
"""
# using "myapp_" prefix in the C code to prevent C naming conflicts
void
msleep
"myapp_sleep"
(
int
milliseconds
)
nogil
msleep
(
milliseconds
=
1
)
docs/examples/userguide/external_C_code/
c_code_docstring
.pyx
→
docs/examples/userguide/external_C_code/
verbatim_c_code
.pyx
View file @
679eff3e
File moved
docs/src/userguide/external_C_code.rst
View file @
679eff3e
...
...
@@ -335,7 +335,7 @@ Including verbatim C code
For advanced use cases, Cython allows you to directly write C code
as "docstring" of a ``cdef extern from`` block:
.. literalinclude:: ../../examples/userguide/external_C_code/
c_code_docstring
.pyx
.. literalinclude:: ../../examples/userguide/external_C_code/
verbatim_c_code
.pyx
The above is essentially equivalent to having the C code in a file
``header.h`` and writing ::
...
...
@@ -344,6 +344,11 @@ The above is essentially equivalent to having the C code in a file
long square(long x)
void assign(long& x, long y)
This feature is commonly used for platform specific adaptations at
compile time, for example::
.. literalinclude:: ../../examples/userguide/external_C_code/platform_adaptation.pyx
It is also possible to combine a header file and verbatim C code::
cdef extern from "badheader.h":
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment