[pypy-dev] Does/will pypy support cpython's c extension modules?

Sean Lynch seanl at literati.org
Tue Jan 30 20:36:45 CET 2007

Tristan Seligmann wrote:
>> I have tons of code using boost::python.  Wouldn't it be a lot of work to
>> port to ctypes?  I'm guessing, it's basically a complete rewrite.
> Is it even feasible to wrap a C++ library with ctypes?
I have the beginnings of an automatic C and ctypes wrapper generator for
C++ code. I've been successful generating the C wrapper with namespaces
and non-class functions with the user telling the generator how to
rename overloaded functions, and my gccxml parser supports pretty much
all features of C++ except for templates now, but I still need to work
on the output for class-using code and ctypes code output. The idea is
to generate C wrappers for every exported function/constructor/class and
to recreate the same class structure in Python with the methods calling
with ctypes the appropriate C function in the wrapper. I've gotten this
far with about eight hours of programming, including writing my gccxml
parser, switching to pygccxml, then switching back to my own parser and
finishing it when I realized that pygccxml is messy and doesn't properly
support function pointers.

As for boost::python, you knew you were stuck with CPython when you
started, since it doesn't support IronPython or Jython either. However,
given a wrapper generator like the one I've started on, you should be
able to throw out all the Python-related code and just wrap the pure C++
code. I wish we could just support the gcc 3.4+ (i.e. Itanium) ABI
directly, but that would be kind of pointless since VC++ doesn't support
it and uses a completely undocumented and unstable ABI.

It seems kind of strange to say that PyPy can't be practical without
implementing the CPython extension API, since to my knowledge IronPython
will not implement it (and Jython never has) and people are afraid that
IronPython will be such a great Python alternative that it will fragment
the Python community.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 250 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/pypy-dev/attachments/20070130/15e5c557/attachment.pgp>

More information about the Pypy-dev mailing list