Using C++ and ctypes together: a vast conspiracy? ;)

Thomas Heller theller at ctypes.org
Thu Jun 4 21:35:21 CEST 2009


[Please keep the discussion on the list]

Joseph Garvin schrieb:
> On Thu, Jun 4, 2009 at 3:43 AM, Thomas Heller <theller at python.net> wrote:
>> There have been some attempts to use ctypes to access C++ objects.
>> We (Roman Yakovenko and myself) made some progress.  We were able to
>> handle C++ name mangling, the special C++ calling convention,
>> access virtual, non-virtual, overloaded functions, but finally gave up
>> because the binary layout (function tables, member variables, and so on)
>> of C++ objects is way too complicated and undocumented.
> 
> Have you read the book Inside The C++ Object Model?:

I haven't, but considered to buy it ;-)

> http://www.amazon.com/Inside-Object-Model-Stanley-Lippman/dp/0201834545/ref=sr_1_1?ie=UTF8&s=books&qid=1244139929&sr=8-1
> 
> It's probably out of date now, but I'm about halfway through it and it
> documents a ton of the little unexpected optimizations and such that
> cause the binary layout to be complex. How did you get as far as you
> did without having figured out the layout? (e.g. if you could access
> virtual functions you must have known how to get at the virtual table)

I found a lot of material on the web, also I used the (very good) visual
studio debugger, and finally I did a lot of experimentation.  We were only
able to access some very simple C++ objects.

There is also a patent or patents from MS about the vtable.

All in all, as I said, IMO it is too complicated to figure out the binary
layout of the C++ objects (without using a C++ compiler), also there are
quite some Python packages for accessing them.

-- 
Thanks,
Thomas



More information about the Python-list mailing list