[Pyrex] [PATCH] public C-API and Py_ssize_t support for 0.9.5.1a

Stefan Behnel stefan_ml at behnel.de
Tue Feb 13 09:57:30 UTC 2007


Hi Greg,

Greg Ewing wrote:
> Stefan Behnel wrote:
> 
>> @Greg: I'd still like to see this integrated soon, maybe in a Pyrex
>> 0.9.6?
> 
> I'll have to look at this fairly carefully. I have
> ideas of my own about how to support exporting C
> functions, and I'll have to see how yours fit in
> with mine before promising anything.

Sure. I don't think there's a better solution, though. It uses the preferred
way of providing C-APIs taken from

http://docs.python.org/ext/using-cobjects.html

and it's very flexible in that it uses a rather loose coupling. The function
mapping is done through string names, which provides a good level of version
independence between different modules. So, as long as a Pyrex module only
adds new public functions, older external modules will continue to work
without recompilation, as the required names are still there. And if a
required function is missing, the import can gracefully raise an exception
when calling the import_MODULENAME function.

I just reviewed the API import function in my patch again and made it a bit
more robust. Compared to the original implementation, it now raises exceptions
for everything that can go wrong in the import. The difference is in the
"generate_c_api_import_code" function.

I also like how simple it is to use the external C-API. Just cimport the
public .pxd file (and thus the generated header file), (py)import the module
itself and then make a C-call to the "import_MODULENAME(PYTHONMODULE)"
function (declared in the .pxd file and implemented statically in the
generated header file). This is where you will get Python exceptions if
anything goes wrong. Afterwards, just call the C-functions as if they were
declared locally. That's just three simple lines of Pyrex code to interface
with an external module at both Python- and C-level. I don't think there's a
way to do better.

Regards,
Stefan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pyrex-0.9.5.1a-lxml.patch
Type: text/x-patch
Size: 25249 bytes
Desc: not available
Url : http://lists.copyleft.no/pipermail/pyrex/attachments/20070213/dcff129e/attachment-0001.bin 


More information about the Pyrex mailing list