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
5c3b6e99
Commit
5c3b6e99
authored
Sep 27, 2017
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a pseudo example to the docs showing how to embed a Cython module in Py3.
parent
a56ee071
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
1 deletion
+11
-1
docs/src/userguide/external_C_code.rst
docs/src/userguide/external_C_code.rst
+11
-1
No files found.
docs/src/userguide/external_C_code.rst
View file @
5c3b6e99
...
@@ -370,7 +370,7 @@ For example, in the following snippet that includes :file:`grail.h`:
...
@@ -370,7 +370,7 @@ For example, in the following snippet that includes :file:`grail.h`:
int main() {
int main() {
Py_Initialize();
Py_Initialize();
initgrail();
initgrail();
/* Python 2.x only ! */
Bunny b;
Bunny b;
grail(b);
grail(b);
Py_Finalize();
Py_Finalize();
...
@@ -379,6 +379,16 @@ For example, in the following snippet that includes :file:`grail.h`:
...
@@ -379,6 +379,16 @@ For example, in the following snippet that includes :file:`grail.h`:
This C code can then be built together with the Cython-generated C code
This C code can then be built together with the Cython-generated C code
in a single program (or library).
in a single program (or library).
In Python 3.x, calling the module init function directly should be avoided. Instead,
use the `inittab mechanism <https://docs.python.org/3/c-api/import.html#c._inittab>`_
to link Cython modules into a single shared library or program.
.. code-block:: c
err = PyImport_AppendInittab("grail", PyInit_grail);
Py_Initialize();
grail_module = PyImport_ImportModule("grail");
If the Cython module resides within a package, then the name of the ``.h``
If the Cython module resides within a package, then the name of the ``.h``
file consists of the full dotted name of the module, e.g. a module called
file consists of the full dotted name of the module, e.g. a module called
:mod:`foo.spam` would have a header file called :file:`foo.spam.h`.
:mod:`foo.spam` would have a header file called :file:`foo.spam.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