简体   繁体   中英

How to get the PyBindGen PyObject for a given C++ pointer?

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?

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM