Cython无法将Python对象转换为';手柄*';
我正在尝试将cpp库包装到Cython无法将Python对象转换为';手柄*';,python,cython,Python,Cython,我正在尝试将cpp库包装到cython中。以下是一些细节: Handle.h: class Handle { public: // accessors // mutators }; class Store { public: Handle* lookup(char* handleName); int update(Handle*); }; handle.pyx: cdef extern from "Handle.h" nam
cython
中。以下是一些细节:
Handle.h
:
class Handle {
public:
// accessors
// mutators
};
class Store {
public:
Handle* lookup(char* handleName);
int update(Handle*);
};
handle.pyx
:
cdef extern from "Handle.h" namespace "xxx":
cdef cppclass Handle:
....
cdef extern from "Handle.h" namespace "xxx":
cdef cppclass Store:
Handle* lookup(char*)
int update(Handle*)
cdef class PyHandle:
cdef Handle* handle
....
cdef class PyStore:
cdef Store* store
def __cinit__(self):
store = ....
def lookup(self, name):
handle = self.store.lookup(name)
pHandle = PyHandle()
pHandle.handle = handle
return pHandle
def update(self, h):
self.store.update(h.handle)
最后一条语句告诉我一个错误,即
无法将Python对象转换为“Handle*”
。我知道我错过了一些简单的事情。如何将Python对象中嵌入的句柄*
传递给调用?显式声明要处理的参数:
def update(self, Handle h):
self.store.update(h.handle)
传递给update(self,h)的“h”是一个python对象,而store.update()将Handle*作为参数。这就是cython所说的。您应该手动将python对象转换为Handle*,或者make为cdef并键入h参数,或者make store.update()将python对象作为参数。如何将python对象转换为Handle*?谢谢。你可能是指PyHandle而不是Handle