Alex said:
One advantage of solutions generating C code that gets compiled (SWIG,
Pyrex, writing C-API code directly, etc) is that the C compiler can warn
you, or produce compile-time mistakes, for many kinds of programming
errors; with ctypes, you will instead be finding every such error at
runtime, each time by noticing that Python crashed and facing a
substantial amount of debugging and code inspection to find out why.
In principle this is true, some points however I would like to point out:
- The ctypes codegenerator, based on GCCXML, is in a pretty good shape.
A lot of boilerplate (Python) code can be generated automatically.
The codegenerator is available from CVS, with 'easy_install ctypeslib'.
GCCXML has to be installed separately.
- Not always does Python crash on programming errors. On windows, calls
to foreign functions are 'protected' by windows structured exception
handling. In other words, most of the time you get a Python traceback
instead of a segfault.
- There are some large libraries and also smaller ones that are already
wrapped with ctypes. PyOpenGL is probably the most promiment example,
comtypes (although still in heavy development) another one.
As the ctypes author I'm of course biased.
Thomas