把课传给你叫你科德

2024-03-28 16:09:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用Cython 0.25.2(Corda Fug Bug)包装两个C++类。将其定义为:

cdef extern from "Isd.h" namespace "csm":
    cdef cppclass CppIsd "csm::Isd":
        Isd() except +

cdef extern from "MdisPlugin.h":
    cdef cppclass CppMdisPlugin "MdisPlugin":
        MdisPlugin() except +
        string getPluginName()
        string getManufacturer()
        string getReleaseDate()
        string getCsmVersion
        size_t getNumModels()
        string getModelName(size_t modelIndex)
        bool canModelBeConstructedFromISD(const CppIsd &isd, const string &modelname)
        string convertISDToModelState(const CppIsd &isd, const string &modelname)

Isd类只是一个存根,公开为:

cdef class Isd:
    cdef unique_ptr[CppIsd] thisptr
    def __init__(self):
        self.thisptr.reset(new CppIsd())

CppMdisPlugin的最后两个方法抛出以下内容:AttributeError:'ErrorType'对象没有属性'to \u py \u call \u code'(中的第12552行)扩展节点.py). 你知道吗

最小包装器代码为:

cdef class MdisPlugin:
    cdef:
        unique_ptr[CppMdisPlugin] thisptr

    def __init__(self):
        self.thisptr.reset(new CppMdisPlugin())

    def from_isd(self, Isd isd, modelname):
        return deref(self.thisptr).convertISDToModelState(deref(isd.thisptr), modelname)

引发错误的原因是.pyx文件中的未命中定义还是Cython内部发生的某些事情?你知道吗


Tags: fromselfstring定义defcythoncdefconst