Sign in to follow this  
doeme

code generation for Python/C++11 binding

Recommended Posts

doeme    1189
I am looking for a way to automatically generate the code to expose c++ classes and objects to python. Currently I am using the Py++ ([url="http://sourceforge.net/projects/pygccxml"]http://sourceforge.n...ojects/pygccxml[/url]) package which works fairly well to generate boost::python wrappers. Unfortunately GCCXML is no longer actively maintained and it lacks support for a lot if not all c++11 features.
Are there any other tools out there for generating Python bindings? Since the code base is already quite large writing the wrappers by hand is not really an option as this would be extremly tedious to maintain.

While boost::python is not mandatory it would be nice if I could keep it for the binding, as I quite like it.

Share this post


Link to post
Share on other sites
Storyyeller    215
Boost python already generates the binding code automatically, based on the function and class names you give it. Or are you asking for something that will parse your source and automatically generate the boost python code for everything? If so, you're unlikely to find something that works in all cases, because doing so would require it to read your mind in order to handle pointer ownership correctly. Also, C++ is notoriously difficult to parse anyway.

Share this post


Link to post
Share on other sites
doeme    1189
[quote name='Storyyeller' timestamp='1332040123' post='4922963']
Or are you asking for something that will parse your source and automatically generate the boost python code for everything? If so, you're unlikely to find something that works in all cases, because doing so would require it to read your mind in order to handle pointer ownership correctly. Also, C++ is notoriously difficult to parse anyway.
[/quote]

That is exactly what I am looking for. As I wrote above, I have a working solution for it (Py++/GCCXML), but it does not understand C++11 and some of the nice language-features of it. The parsing of the code is done by GCCXML which is a regular Gcc which "compiles" to XML instead of binary, but unfortunately it is not maintained anymore.

Of course the ownership is a bit of a problem, but I kind of solve it by stating that python is not allowed to own any objects at all and that python-exposed objects they need to be constructed over a factory-method with an explicit owner supplied. Not the nicest way, but pretty safe IMO.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this