Cython无法将Python对象转换为'Handle *'

时间:2012-11-06 06:22:22

标签: python cython

我正在尝试将cpp lib包装到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)

最后一句话给我一个错误Cannot convert Python object to 'Handle *'。我知道我错过了一些简单的事情。如何将嵌入在Python对象中的Handle*传递给调用?

1 个答案:

答案 0 :(得分:0)

将参数显式声明为Handle:

def update(self, Handle h):
        self.store.update(h.handle)