[pypy-dev] GSoC proposal - C++ binding

Leonardo Santagada santagada at gmail.com
Tue Mar 24 19:13:25 CET 2009

On Mar 24, 2009, at 2:18 PM, Neal Becker wrote:

> Igor Trindade Oliveira wrote:
>> Hi guys,
>> i was talking with some pypy guys about work in this summer in GSoC  
>> with
>> C++ bindings to Pypy and i wrote a proposal and i like that you  
>> review it.
>> Igor
>> Problem
>> Pypy are becoming one of the most used Python interpreter because  
>> it is
>> easy and flexible, but we still have a big problem, it does not  
>> have any
>> binding to any Graphical User Interface(GUI) and we have the second
>> problem, many GUIs are wrote in C++(like Qt or WxWidgets) and Pypy  
>> can not
>> access C++ code because it does not have any C API, it just can  
>> access C
>> code using ctypes.
>> Solution
>> Many solutions had been argued but the main solution is use
>> Reflex[2],which is developed at CERN (which has an incredible  
>> amount of
>> C++ libraries). It is not mainly intended for writing Python  
>> bindings for
>> C++ libraries but instead provides reflection capabilities for C++.  
>> The
>> idea is that for every C++ shared library, an additional shared  
>> library is
>> produced, which allows together with Reflex to introspect  
>> properties of
>> C++ classes, methods, etc. at runtime. These facilities are then  
>> used for
>> writing a small generic CPython extension module, that allows  
>> CPython to
>> use any C++ library for which this reflection information was  
>> generated
>> [3]. This approach is a bit similar to the ctypes module, apart  
>> from the
>> fact that ctypes does not use any reflection information, but the  
>> user has
>> to specify the data structures that occur in the C code herself. This
>> makes it sometimes rather burdensome to write cross-platform library
>> bindings. For PyPy the approach seems rather fitting: We would need  
>> to
>> implement only the generic extension module(a C language interface to
>> Reflex) and could then use any number of C++ libraries.
> ...
> I wonder if py++ would help?

When people were looking at what would be best to use they considered  
py++ (and boost.python).

One of the reasons to not use it is that if I remember correctly py++  
uses gcc-xml and it needs the source of the C++ library before  
generating some cpython module that needs to be compiled also. One of  
the good points of Reflex is that after the generation of the  
reflection library you don't need the source of the package neither a  
compiler installed, and reflex supports c++ also (which would be  
interesting if we want to convince OS people of including reflex  
modules of c++ libraries).

Could Reflex be made to generate a reflex module of c packages also,  
so you don't have to declare them again in ctypes in python and all  
languages that support libffi? That would be cool.

Leonardo Santagada
santagada at gmail.com

More information about the Pypy-dev mailing list