Commit 5c3b6e99 authored by Stefan Behnel's avatar Stefan Behnel

Add a pseudo example to the docs showing how to embed a Cython module in Py3.

parent a56ee071
...@@ -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`.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment