Python Cython将类传递给\u py\u call\u代码错误 我试图用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类只是一个存根,公开为:Python Cython将类传递给\u py\u call\u代码错误 我试图用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),python,c++,cython,Python,C++,Cython,Isd类只是一个存根,公开为: cdef class Isd: cdef unique_ptr[CppIsd] thisptr def __init__(self): self.thisptr.reset(new CppIsd()) cppmdispugin的最后两个方法抛出以下内容:AttributeError:“ErrorType”对象没有属性“to_py_call_code”(ExprNodes.py中的第12552行) 最小包装器代码为: cdef cl
cdef class Isd:
cdef unique_ptr[CppIsd] thisptr
def __init__(self):
self.thisptr.reset(new CppIsd())
cppmdispugin的最后两个方法抛出以下内容:AttributeError:“ErrorType”对象没有属性“to_py_call_code”(ExprNodes.py中的第12552行)
最小包装器代码为:
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内部发生的某些事情?Cython感到困惑(因此它会给您一个内部错误,而不是有用的错误消息),但这可能是您所做的。我猜问题出在
modelname
-尝试创建一个std::string
临时变量。(这只是一个猜测)一旦我添加了相关的标准库cimports,您的代码在Cython 0.23.4(现在有点旧)上对我有效。所以我不知道问题是什么。