PyArg_ParseTuple question

Stefan Behnel stefan_ml at behnel.de
Wed Dec 15 04:19:59 EST 2010


Mark Wooding, 14.12.2010 21:42:
> I could have used PySequence_* functions to read the size and items, but
> that makes error handling more complicated.  One could also borrow the
> references from the underlying list, which would leave the underlying
> storage for the vector as the only thing to free.
>
> I ended up writing a lot of conversion functions when I was doing Python
> library bindings (for a crypto library); they're generally a good thing.
> I found that the trickiest thing about PyArg_ParseTuple is in making
> sure that you can clean everything up even if it goes wrong half way
> through.

I think it's worth mentioning here that the Cython compiler generates 
tightly tailored code for argument unpacking and type conversion. So unless 
you really want (or need) to write your code directly against Python's 
C-API, Cython will do a substantially better job with much less coding. 
Even if you have already written a major part of your code in C, it's worth 
considering to (re-)write the Python API wrapper parts in Cython if you 
need better performance.

Stefan




More information about the Python-list mailing list