【发布时间】:2015-03-12 16:48:44
【问题描述】:
我使用 Cython 包装了许多 C++ 类,它们设法编译。但是,当我尝试使用 python 级别的模块时,我遇到了分段错误(11),所以我想知道我包装的内容是正确的。 “Foo.h”中的A是一个抽象类。
source.pyx
cdef extern from "Foo.h":
cdef cppclass A:
A(MPI_comm comm, int x)
cdef extern from "Foo1.h":
cdef cppclass B:
B(A* obj, int y)
cdef class pyA:
cdef A *thisptrA
def __cinit__(self,MPI.Comm _comm, int x):
pass
def __dealloc__(self):
pass
cdef class pyB:
cdef B* thisptrB
cdef pyA obj
def __cinit__(self, pyA obj, int y):
self.thisptrB = new B(obj.thisptrA, y)
def __dealloc__(self):
del self.thisptrB
testscript.py
import pyA, pyB
class C(pyA):
def __init__(self, comm, x):
self.x = x
comm = MPI.COMM_WORLD
x = 2
y = 24
Aobj = C(comm, x)
Bobj = pyB(Aobj, y)
似乎每当我尝试初始化pyB时,语句都会出现分段错误
self.thisptrB = newB(obj.thisptrA, y)
有人知道我哪里出错了吗?
【问题讨论】: