[Pyrex] Pyrex versus ctypes
Bob Ippolito
bob at redivi.com
Fri Jun 11 00:10:07 CEST 2004
On Jun 10, 2004, at 6:01 PM, David McNab wrote:
> After a year or so's hacking with Pyrex, I've come across the 'ctypes'
> package (http://starship.python.net/crew/theller/ctypes/).
>
> ctypes allows the calling of C functions from *pure-python* code,
> without requiring the generation/compilation of a C wrapper module.
>
> Pure python code using ctypes can even receive callbacks from C funcs,
> and manipulate C data structures, pretty much most of what one would
> need for interfacing with C.
>
> All this feels too good to be true.
>
> Can anyone offer some thoughts on the ideal demarcation lines between
> Pyrex and ctypes, and some thoughts on pros and cons, and which
> situations indicate Pyrex over ctypes and vice versa?
>
> For instance, how severe are ctypes' overheads with constructing the C
> call frame, and rendering the return back to python?
Here's a few ctypes disadvantages off the top of my head (I hope the
advantages are obvious, since we're all Python users here, so I won't
list them):
ctypes can be one royal pain in the ass to debug. There are still bugs
in *it*, at least on non-win32 platforms. I would wait a release or
two unless you have very simple requirements (bugs that I've seen are
pretty much limited to structure packing and python callbacks) or want
to become a committer too :)
ctypes is not designed for speed, I'm not sure exactly what the
overhead is, but I guarantee it's more than Pyrex.
It takes more time to wrap a C API with ctypes than with Pyrex because
you can't leverage anything that the C compiler and preprocessor knows
about.
It's not possible to poke back inside the Python C API with ctypes at
this time (since it releases the GIL and has no GIL-holding call
facility, though it wouldn't be too hard to make one).
-bob
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2357 bytes
Desc: not available
Url : http://lists.copyleft.no/pipermail/pyrex/attachments/20040610/f8301fd0/smime.bin
More information about the Pyrex
mailing list