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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
10120c42
Commit
10120c42
authored
Oct 28, 2017
by
scoder
Committed by
GitHub
Oct 28, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1945 from AraHaan/mod-init-no-export
Add CYTHON_NO_PYINIT_EXPORT macro. (#1944)
parents
8ad743a2
ce965c08
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
2 deletions
+60
-2
Cython/Compiler/ModuleNode.py
Cython/Compiler/ModuleNode.py
+22
-2
docs/src/reference/compilation.rst
docs/src/reference/compilation.rst
+38
-0
No files found.
Cython/Compiler/ModuleNode.py
View file @
10120c42
...
...
@@ -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
)
...
...
docs/src/reference/compilation.rst
View file @
10120c42
...
...
@@ -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``
============================
...
...
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