best "void" return of a member function

Stefan Behnel stefan_ml at behnel.de
Mon Apr 20 06:57:09 EDT 2009


Andreas Otto writes:
>   I'm writing a native language binding for a library.
> 
>         http://libmsgque.sourceforge.net/
> 
>   Every native method called by PYTHON have to return
>   a PyObject* even if the function itself does not
>   return anything.
>  [...]
>   Question: what is the best return statement for a "void" function ?

Hmmm, this sounds like your goal is to write an exact 1:1 wrapper of the C
library API (for which there are tools like SWIG&friends). If the library
happens to have a rather unusual, close-to object oriented, high-level C API,
that might work. Otherwise, you might want to try to wrap it in a more Pythonic
look&feel style, that wraps operations and use-cases rather than plain
functions. That should make it easier to hide things like memory allocation and
other C implementation details from users, and will generally increase the
performance of your binding, as it will require less calls for larger operations
in C space.

Stefan





More information about the Python-list mailing list