Wrapping c functions
Andrew Dalke
dalke at dalkescientific.com
Sun May 1 16:00:19 EDT 2005
Glenn Pierce wrote:
> if (!PyArg_ParseTuple(args, "isi", &format, filename, &flags))
> return NULL;
Shouldn't that be &filename ? See
http://docs.python.org/ext/parseTuple.html
for examples.
> dib = FreeImage_Load(format, filename, flags);
> Also I have little Idea what to return from the function. FIBITMAP * is
> an opaque pointer
> that I pass to other FreeImage functions, I pretty certain
> Py_BuildValue("o", dib) is wrong.
If it's truly opaque and you trust your use of the code you can
cast it to an integer, use the integer in the Python code, and
at the Python/C interface cast the integer back to a pointer.
Of course if it no longer exists you'll get a segfault.
If you want more type safety you can use the SWIG approach and
encode the pointers as a string, with type information and
pointer included.
Or use the Python extension API to make a new type.
Searching the archives I see people have tried to write a Python/
FreeImage interface using SWIG.
Andrew
dalke at dalkescientific.com
More information about the Python-list
mailing list