Ray Chen schrieb am 02.09.21 um 12:51:
> On Thursday, September 2, 2021 at 11:20:32 AM UTC+1 Ray Chen wrote:
>
>> I see in the generated .c file from Cython that on Windows, it seems that
>> the init function for __init__.py is PyInit___init__ not PyInit_<package
>> name>. There is a clear #if directive for Windows:
>>
>> #if !defined(CYTHON_NO_PYINIT_EXPORT) && (defined(_WIN32) ||
>> defined(WIN32) || defined(MS_WINDOWS))
>> __Pyx_PyMODINIT_FUNC PyInit___init__(void) { return PyInit_submodule(); }
>> #endif
>>
>> This also means that if i turn off CYTHON_NO_PYINIT_EXPORT, then this wont
>> happen. As I am new to cython, what exactly happens when i unset
>> CYTHON_NO_PYINIT_EXPORT?
It hides the exported symbol of the PyInit module entry point, so that it's
only accessible from inside the C code file. That's intended specifically
for the use case of including Cython modules in external libraries or
applications, which use the inittab mechanism for initialising the
statically included extension modules.
>> The reason why I am trying to do this is because I am replicating a Python
>> library for merak which combines a Python package into a single shared
>> library. So far, this works on Linux but on Windows what happens is all
>> subpackages (which use a __init__.py file) have their init function in C
>> called PyInit___init__ unlike on Linux, where it is called PyInit_<package
>> name>. In the C code PyInit_submodule is also defined, and all other code
>> that was generated from my python code also uses the name
>> __pyx_mdef_9_submodule_8___init__ (which i take to mean submodule.__init__).
>
> Ok edit: i meant if I turn on CYTHON_NO_PYINIT_EXPORT. However that just
> breaks everything
Does it? I assume you're not using the symbol directly then, but trying to
access it externally, right?
> and I cannot import my built library. What makes the
> Linux and Windows code different so that on linux PyInit_submodule is used
> as the module name?
The code that you copied above is a work-around for a CPython bug on
Windows, which searches for the wrong symbol name of the PyInit function of
package modules (__init__.py). Thus, Cython exports two symbols on Windows,
the correct one and the one that CPython searches for, both leading to the
same PyInit function.
This obviously conflicts with the goal of linking together multiple packages.
Stefan