Reputation: 17049
Given the PyObject
created by PyBindGen
, it's easy to get the pointer to the wrapped C++ object, just use the obj
member in the struct:
typedef struct {
PyObject_HEAD
MyWrappedClass *obj;
PyObject *inst_dict;
PyBindGenWrapperFlags flags:8;
} PyMyWrappedClass;
However, let's say I have just MyWrappedClass*
, and want to get the PyObject
(if any, it might not exist) that wraps it. Is there any way to do this without maintaining my own dictionary of backpointers?
Upvotes: 1
Views: 419
Reputation: 30450
I would have added this as a comment if I had enough reputation as I'm not familiar with PyBindGen
, but unless inst_dict
is a dictionary of backpointers (as the name might suggest) I think you're out of luck (Unless you want to trawl through the Python heap to see if there are any instances of your class there).
Upvotes: -1