ctypes and setjmp

Thomas Heller theller at python.net
Fri Oct 6 21:14:34 CEST 2006

Richard Jones schrieb:
> Currently ctypes can't play well with any C code that requires use of setjmp
> as part of its API.
> libpng is one of those libraries.
> Can anyone think of a reasonable solution to this? Perhaps ctypes might be
> patched to offer setjmp support in foreign function definitions?
>     Richard
I didn't know that setjmp/longjmp is actually used by production libraries
for error handling.

How is this pattern used in C?  Do you call setjump() before each api call,
or do you call setjump once, and then do all the api calls?  What do you do
when setjmp() returns != 0?  Exit the program?  Log a message?  How do you
determine which call failed?  How do you pass the jmp_buf that you passed to
setjmp() to the api call?

For ctypes, the only solution I can think of is to invent a new calling
convention, which will call setjmp() first internally before calling the
libpng api function...


More information about the Python-list mailing list