开发者

Python Swig wrapper: how access underlying PyObject

开发者 https://www.devze.com 2023-01-21 10:56 出处:网络
I\'ve got class A wrapped with method foo implemented using %extend: class A { ... 开发者_开发技巧 %extend {

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消