Commit 10120c42 authored by scoder's avatar scoder Committed by GitHub

Merge pull request #1945 from AraHaan/mod-init-no-export

Add CYTHON_NO_PYINIT_EXPORT macro. (#1944)
parents 8ad743a2 ce965c08
......@@ -2261,8 +2261,28 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
def generate_module_init_func(self, imported_modules, env, code):
code.enter_cfunc_scope(self.scope)
code.putln("")
header2 = "PyMODINIT_FUNC init%s(void)" % env.module_name
header3 = "PyMODINIT_FUNC %s(void)" % self.mod_init_func_cname('PyInit', env)
code.putln("#if PY_MAJOR_VERSION < 3")
code.putln("#ifdef CYTHON_NO_PYINIT_EXPORT")
code.putln("/* define this to void manually because PyMODINIT_FUNC")
code.putln("* adds __declspec(dllexport) to it's definition.")
code.putln("*/")
code.putln("#define __Pyx_PyMODINIT_FUNC void")
code.putln("#else")
code.putln("#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC")
code.putln("#endif")
code.putln("#else")
code.putln("#ifdef CYTHON_NO_PYINIT_EXPORT")
code.putln("/* define this to PyObject * manually because PyMODINIT_FUNC")
code.putln("* adds __declspec(dllexport) to it's definition.")
code.putln("*/")
code.putln("#define __Pyx_PyMODINIT_FUNC PyObject *")
code.putln("#else")
code.putln("#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC")
code.putln("#endif")
code.putln("#endif")
code.putln("")
header2 = "__Pyx_PyMODINIT_FUNC init%s(void)" % env.module_name
header3 = "__Pyx_PyMODINIT_FUNC %s(void)" % self.mod_init_func_cname('PyInit', env)
code.putln("#if PY_MAJOR_VERSION < 3")
code.putln("%s; /*proto*/" % header2)
code.putln(header2)
......
......@@ -43,6 +43,44 @@ paths to libraries you need to link with]
A ``yourmod.so`` file is now in the same directory and your module,
``yourmod``, is available for you to import as you normally would.
Compiling in a embedded interpreter
===================================
Sometimes you might want to use cython to compile a python module you
made into your hand made embedded python. Here is how to do that.
On the top of your C file above the main function you created
type this without the quotes::
PyMODINIT_FUNC PyInit__test(void);
for python 3.x and::
PyMODINIT_FUNC init_test(void);
for python 2.
Where Module Name is the name of the module you cythonized. If you
are not sure on the name of the module init function refer to your
generated module source file.
You need to use ``PyImport_AppendInittab`` but right
before you use ``Py_SetProgramName`` and ``Py_Initialize`` in your
main as well::
PyImport_AppendInittab("_test", PyInit__test);
for python 3.x and::
PyImport_AppendInittab("_test", init_test)
After that is done go in and for all the sources you use define the
following in the compiler's command line::
CYTHON_NO_PYINIT_EXPORT
This macro is to ensure that your module initialization function is
not exported.
Compiling with ``distutils``
============================
......
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