I'm writing a C++ python extension and I've been experiencing a SIGSEGV whenever I call (from C++) a virtually-inherited method of a certain class that is also a PyObject (i.e. it has a PyObject_HEAD).
I finally remembered that python doesn't know anything about C++. Sure enough, GCC is putting a vtable pointer in the first 4 bytes of my object (you can tell because the first field of PyObject_HEAD is offset 4 bytes from the address of the object). When python INCREFs the object, it's actually altering the vtable pointer.
My question: what should I do to fix this? Moving the virtual methods to a subsidiary class would solve it, but it seems like admitting defeat. Any other thoughts / experiences?
(Python 2.7, GCC 4.7.2 on mingw32 / windows 7)
Python doesn't know about C++ but it does know about structures. So have Python call a pure C function that creates a structure. Instead the structure have a pointer to the C++ object. This way Python sees a pure C interface, but the implementation of the C interface creates a private internal object.
We actually do this on one of my projects. It works and it's pretty portable.
I think python is overwriting my vtable (c++ extension)