1

我正在尝试将 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 *'。我知道我错过了一些简单的东西。如何将Handle*嵌入在 Python 对象中的那个传递给调用?

4

1 回答 1

0

将参数显式声明为 Handle:

def update(self, Handle h):
        self.store.update(h.handle)
于 2012-11-06T22:24:55.997 回答