[Pyrex] sharing funcitons with distutils for .pyx

Jim Kleckner jek-gmane at kleckner.net
Thu Sep 20 17:49:26 CEST 2007


Thank you for the reply, Greg.

Greg Ewing wrote:
> Jim Kleckner wrote:
>> I have a .pyx file that depends on functions defined in a .c
>> file that is included with another .pyx, say it is "cfunc1" defined in 
>> cfuncs.c
> 
> There's no particularly good way of handling that at
> the moment. The current options seem to be:
> 
> 1) Don't try to link them directly with each other
> at the C level. Use cimport and extension types with
> C methods, or wrap function pointers in PyCObjects to
> pass them from one module to another.

I think this is the best approach as
I can modify the source.

> 2) Use the trick I posted about in the pyrex list the
> other day, where you statically link more than one
> module together into one dynamically loaded file, and
> put explicit calls into the body of one of the modules
> to the init functions of the others, e.g.
> 
> # main.pyx
> cdef extern void initfoo()
> cdef extern void initblarg()
> 
> initfoo()
> initblarg()
> 
> and then in distutils you put all of 'main.pyx',
> 'foo.pyx' and 'blarg.pyx' into a single Extension
> that produces a module called 'main'.
> 
> In Python, you then have to import main *before*
> attempting to import foo or blarg.

Useful when you have to live with the code
that you are given.




More information about the Pyrex mailing list