[Pyrex] Calling Pyrex from another Python module

Stefan Behnel stefan_ml at behnel.de
Sun Feb 11 18:13:46 UTC 2007


Hi,

>On Thu, Jan 04, 2007 at 07:55:44AM +0100, konrad.hinsen at laposte.net wrote:
>> Much of my code does C-function calls between two extension modules
>> written in C. Each module makes its callable C functions visible
>> through a CObject. The calling module obtains this CObject through
>> the standard import mechanism. At some time I wrote a section about
>> this mechanism for the "Python extending and embedding" manual; I
>> suppose it's still in there.
>
> Yes, thanks, I found that very useful. I was hoping for a
> Pyrex-specific method but there doesn't seem to be one (or, really,
> any need for one).

Actually, there's even an implementation. Feel free to use this modified Pyrex
version (through SVN):

http://codespeak.net/svn/lxml/pyrex/

lxml has an example for its usage:

http://codespeak.net/lxml/capi.html

The public functions are defined directly in the source (lxml uses a separate
include file here):
http://codespeak.net/svn/lxml/branch/capi/src/lxml/public-api.pxi

The public C-API of lxml is then defined in a .pxd file:
http://codespeak.net/svn/lxml/branch/capi/src/lxml/etreepublic.pxd

Other Pyrex modules can simply "cimport" the .pxd, which makes the C compiler
include the generated public header file (etree.h in this case).

I'll try to come up with a patch against 0.9.5.x to get it integrated into
mainstream Pyrex.

Have fun,
Stefan




More information about the Pyrex mailing list