简体   繁体   中英

Python Swig wrapper: how access underlying PyObject

I've got class A wrapped with method foo implemented using %extend:

class A { ... %extend { void foo() { self->foo_impl(); } }

Now I want to increase ref count to an A inside foo_impl, but I only got A* (as self).

Question: how can I write/wrap function foo, so that I have an access both to A* and underlying PyObject*?

Thank you

I think it's not possible. If you need to increase the refcount, it's because you don't want the C++ object to be destroyed when it goes out of scope because there is a pointer to that object elsewhere. In that case, look at using the DISOWN typemap to ensure the target language doesn't think it "owns" the C++ object, so it won't get destroyed.

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