简体   繁体   English

Python Swig包装器:如何访问底层PyObject

[英]Python Swig wrapper: how access underlying PyObject

I've got class A wrapped with method foo implemented using %extend: 我已经用%extend实现的方法foo包装了A类:

class A { ... %extend { void foo() { self->foo_impl(); 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). 现在我想在foo_impl中将引用计数增加到A,但是我只有A *(作为self)。

Question: how can I write/wrap function foo, so that I have an access both to A* and underlying PyObject*? 问题:如何编写/包装函数foo,以便可以同时访问A *和基础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. 如果需要增加引用计数,这是因为您不希望C ++对象超出范围时被销毁,因为在其他地方有指向该对象的指针。 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. 在这种情况下,请查看使用DISOWN类型映射以确保目标语言不认为它“拥有” C ++对象,因此不会被破坏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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