C++ - Python API

Markus Kraus kr4uzi at googlemail.com
Wed Sep 1 22:49:19 CEST 2010


Thanks for the answer

On 1 Sep., 22:29, Thomas Jollans <tho... at jollybox.de> wrote:
> On Wednesday 01 September 2010, it occurred to Markus Kraus to exclaim:
>
> > So the feature overview:
>
> First, the obligatory things you don't want to hear: Have you had a look at
> similar efforts? A while ago, Aahz posted something very similar on this very
> list. You should be able to find it in any of the archives without too much
> trouble.
> The most prominent example of this is obviously Boost.Python.

I searched in Aahz posts but i didn't find anything related.
About Boost.Python: I worked with it but (for me) it seems more like
if it's meant to create pyd modules.


> > For C++ classes:
> > - "translating" it into a python object
>
> How do you handle memory management ?

As long as the c++ instanze itself exists, the python object is
existing too. If you delete the c++ instanze the python one is also
deleted (in a multithreaded environment you'll get a "This object has
already been deleted" error).

> > - complete reflexion (attributes and methods) of the c++ instance
> > - call c++ methods nearly directly from python
> > - method-overloading (native python doesnt support it (!))
>
> > Modules:
> > - the API allowes to create hardcoded python modules without having
> > any knowledge about the python C-API
> > - Adding attributes to the module (long/char*/PyObject*)
>
> char*...
> Unicode? Somewhere? wchar_t* maybe, or std::wstring? No? Also -- double? (I'm
> just being pedantic now, at least double should be trivial to add)

I haven't worked too much on this yet but ill add support for all
common c++ types.


> > General:
> > -runs on any platform and doenst need an installed python
>
> Which platforms did you test it on? Which compilers did you test? Are you sure
> your C++ is portable?

My C++ code is not platform dependent so it should (haven't tested it
yet) be portable.


> > -runs in multithreaded environments (requires python > 2.3)
>
> How do you deal with the GIL?
> How do you handle calling to Python from multiple C++ threads?

Since python 2.3 there are the function PyGILState_Ensure and
PyGILState_Release functions which do the whole GIL stuff for you :).

> > -support for python 3.x
> > -no need of any python C-API knowledge (maybe for coding modules but
> > then only 2 or 3 functions)
> > -the project is a VC2010 one and there is also an example module +
> > class
>
> Again, have you tested other compilers?

Dont have the ability for it (could need a linux guy who knows how to
create a makefile).

> > If there is any interest in testing this or using this for your own
> > project, please post; in that case i'll release it now instead of
> > finishing the inheritance support before releasing it (this may take a
> > few days though).
>
> Just publish a bitbucket or github repository ;-)

Ill set up a googlecode site :P




More information about the Python-list mailing list