[Cython] 0.9.8.1.1 and .pxd files
Jason Evans
jasone at canonware.com
Fri Nov 14 21:35:21 CET 2008
Lisandro Dalcin wrote:
> Sorry, forgot to attach...
>
> On Thu, Oct 30, 2008 at 11:28 PM, Lisandro Dalcin <dalcinl at gmail.com> wrote:
>> If all you can accept some vile hackery, see the attached tarball ;-) .
>>
>> Python recognizes a PKGNAME directory as a pakage if '__init__.py' is
>> there, if not, no way. BUT if '__init__.so' is also there, it loads
>> '__init__.so' !!! But then the exported module init function in the
>> dynlib needs to be named initPKGNAME, and "PKGNAME" needs to be passed
>> to Py_InitModule()
>>
>> So, Greg, here you have the rules if you want to implement it ;-).
>>
>> PS: tried only in Py 2.5, this is surely undocumented, and probably it
>> is in fact some bugy code in CPython's 'import.c' .
I finally got around to playing with your example, and after working
past a couple of issues, I got it to work for my software. For the
record, I had to use the following __init__.h file:
---------------------------------------------------------------------
#if SIZEOF_SIZE_T != SIZEOF_INT
# define Py_InitModule4_64(name,a,b,c,d) Py_InitModule4_64("Crux",a,b,c,d)
#else
# define Py_InitModule4(name,a,b,c,d) Py_InitModule4("Crux",a,b,c,d)
#endif
#define init__init__(a) initCrux(a)
---------------------------------------------------------------------
After I got this working, I took a look at the generated __init__.c, and
realized that there is no simple way to extend the approach to Python 3,
since "__init__" is directly embedded in a data structure used for
module initialization. The attached patch modifies Cython to handle the
__init__ module name specially. This works correctly for my software.
Does it look like a general solution?
Thanks,
Jason
-------------- next part --------------
A non-text attachment was scrubbed...
Name: __init__.pyx.patch
Type: text/x-diff
Size: 812 bytes
Desc: not available
Url : http://codespeak.net/pipermail/cython-dev/attachments/20081114/840f0d0b/attachment.bin
More information about the Cython-dev
mailing list