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

Joseph Garvin joseph.h.garvin at gmail.com
Thu Jun 4 18:23:45 EDT 2009


On Thu, Jun 4, 2009 at 2:35 PM, Thomas Heller <theller at ctypes.org> wrote:
> [Please keep the discussion on the list]
>
> 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.

Requiring that the C++ compiler used to make the dll's/so's to be the
same one Python is compiled with wouldn't be too burdensome would it?
Because then you could have it run a bunch of configure tests to
determine information exposing the layout. I don't know if everything
is testable, but you can for example (I learned this from the object
model book btw) write a C++ program that determines whether the
virtual function table is stored at the beginning or the end of an
object by comparing the address of an object with a virtual function
to the address of its first data member. If they're different, it's
because the vptr is stored there, otherwise it's on the end
(theoretically it could be in the middle but there's no reason for
compiler writers to do that). cpptypes could then use information
generated by tests like this that are run when the interpreter is
compiled.



More information about the Python-list mailing list