C Python extension to export an Function

Stefan Behnel stefan_ml at behnel.de
Thu Sep 1 11:58:36 EDT 2016


Ganesh Pal schrieb am 01.09.2016 um 17:24:
> Thanks stefan and  Gollwitzer  , good to know there are many ways to do this
> i.e via cython or SWIG   but  the C/Python API
> <https://docs.python.org/2/c-api/> is probably the most widely used method

It certainly was, years ago, but I honestly doubt that it still is. I don't
think there is still that much manually written C-API code out there that
is actively maintained. Often enough, it's easier to rewrite the code in
Cython at some point, than to keep maintaining it in C over years.

Manually written C-API code is simply too difficult to maintain, and also
too difficult to get right in the first place. There are just too many ways
to introduce reference leaks, crashes and long standing unnoticed bugs
(believe me, I know what I'm talking about). Even experienced CPython core
devs still make mistakes here from time to time.


> - not for it’s simplicity but for the fact that you can manipulate python
> objects in your C code.

Neither SWIG nor Cython prevent you from doing that, although you'd usually
leave these things to Cython since it already generates faster code for
many operations than you would (or could) write by hand.

Stefan





More information about the Python-list mailing list