Python Swig 包装器:如何访问底层 PyObject
我已经用 foo 方法包装了 A 类,使用 %extend:
class A { ... %延长 { 无效 foo() { self->foo_impl(); } 现在
我想增加 foo_impl 内 A 的引用计数,但我只得到 A* (作为 self)。
问题:如何编写/包装函数 foo,以便可以访问 A* 和底层 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这是不可能的。如果您需要增加引用计数,那是因为您不希望 C++ 对象在超出范围时被销毁,因为其他地方有一个指向该对象的指针。在这种情况下,请考虑使用 DISOWN 类型映射来确保目标语言不认为它“拥有”C++ 对象,因此它不会被破坏。
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.