I would like to recently describe the situation I'm faced with, in order to give the question some context.
I'm writing a Python C++ wrapper. Python's basic unit is PyObject. Every entity in Python is a PyObject + optionally more stuff.
That is to say the first sizeofPyObject)
bytes are guaranteed to fill out the fields of a PyObject, but various objects may allocate additional contiguous memory.
The benefit (reason?) For this is that anything can be typecast back into a meaningful PyObject.
I'm attempting to wrap such a beast:
class CxxWrapper : PyObject { }
Say I create a void foo(PyObject* p)
, and insert foo
into one of the Python runtime's function-pointer tables.
Then the runtime will trigger this function (for whatever reason) passing a pointer to the relevant PyObject.
I would like to be able to typecast this straight back to its corresponding CxxWrapper object:
CxxWrapper* cxxw = static_cast<CxxWrapper>p;
However, I can't see any way to get this mechanism to work.
Because I can't see any way to set the base object to some PyObjectPlusExtra.
Is there any way to do this? And if not, what is the C++ limitation being hit?
Aucun commentaire:
Enregistrer un commentaire