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

Philip Semanchuk philip at semanchuk.com
Thu Jun 4 15:50:25 EDT 2009


On Jun 4, 2009, at 3:35 PM, Thomas Heller wrote:

> [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?:
> 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.

Hi Thomas,
We're weighing options for accessing C++ objects via Python. I know of  
SIWG and Boost; are there others that you think deserve consideration?

I've been happy with ctypes in my limited exposure to it and would  
love to find a way to make that work. This thread has been very  
interesting to me.

Thanks
Philip











More information about the Python-list mailing list