Cython崩溃从文档示例 [英] Cython crash from documentation example
问题描述
我使用Cython 0.19.2(和Python 2.7.1)将C ++类暴露给Python。
作为第一次尝试,我使用文档的Rectangle类示例进行测试。
http://docs.cython.org/src/userguide/wrapping_CPlusPlus.html
我有一个我不明白的崩溃。
我试图简化代码最大值。但我还是有问题。
这是我的pyx文件,C ++源代码只是从python / cython的文档中剪切和粘贴。
#distutils:language = c ++
#distutils:sources = Rectangle.cpp
cdef extern fromRectangle.hnamespaceshapes
cdef cppclass Rectangle:
pass
cdef class PyRectangle:
cdef Rectangle * thisptr
我只想声明一个带有thisptr的类,它指向C ++ Rectangle类实例。
编译程序:
cython -a --cplus rect.pyx
我遇到以下崩溃:
Cython文件:
------------------------------------------- -----------------
...
cdef extern fromRectangle.hnamespaceshapes:
cdef cppclass Rectangle:
pass
cdef class PyRectangle:
cdef Rectangle * thisptr
^
----------------- -------------------------------------------
rect.pyx:9:7:AnalyseDeclarationsTransform中的编译器崩溃
文件'ModuleNode.py',第101行,在analyse_declarations:ModuleNode(rect.pyx:1:0,
full_module_name = 'rect')
在analyse_declarations中的文件'Nodes.py',第382行:StatListNode(rect.pyx:4:0)
分析中的文件'Nodes.py',行4251:CClassDefNode rect.pyx:8:5,
as_name = u'PyRectangle',
class_name = u'PyRectangle',
module_name = u'',
visibility = u'private' )
在analyse_declarations中的文件'Nodes.py',第382行:StatListNode(rect.pyx:9:7)
文件'Nodes.py',行1208,在analyse_declarations中:CVarDefNode :9:7,
modifiers = [...] / 0,
visibility = u'private')
编译器崩溃跟踪从这一点开始:
文件/home/xxx/local/python2.7.1/site-packages/Cython/Compiler/Nodes.py,行1208,在分析报告中
self.entry.doc = embed_position(self.pos,self.doc )
AttributeError:'CVarDefNode'对象没有属性'doc'
编译pyrex,setup.py,...一切。但我仍然有同样的错误。
有没有我缺少的东西?
>
解决方案好吧,我终于解决了。我的Python 2.7.1版本根本不适用于最后一个Cython 0.19.2。我升级到2.7.6,它工作。
I use Cython 0.19.2 (and Python 2.7.1) to expose C++ classes to Python.
As a first try, i did a test with the 'Rectangle' class example of the documentation.
http://docs.cython.org/src/userguide/wrapping_CPlusPlus.html
I have a crash which I don't understand.
I have tried to simplify the code the the max. but I still have the problem.
Here is my pyx file, the C++ sources are just a cut&paste from the python/cython's documentation.
# distutils: language = c++ # distutils: sources = Rectangle.cpp cdef extern from "Rectangle.h" namespace "shapes": cdef cppclass Rectangle: pass cdef class PyRectangle: cdef Rectangle* thisptr
I just want to declare a class with a thisptr, which points the the C++ Rectangle class instance.
When i try to compile the program with:
cython -a --cplus rect.pyx
I have the following crash:
Error compiling Cython file: ------------------------------------------------------------ ... cdef extern from "Rectangle.h" namespace "shapes": cdef cppclass Rectangle: pass cdef class PyRectangle: cdef Rectangle* thisptr ^ ------------------------------------------------------------ rect.pyx:9:7: Compiler crash in AnalyseDeclarationsTransform File 'ModuleNode.py', line 101, in analyse_declarations: ModuleNode(rect.pyx:1:0, full_module_name = 'rect') File 'Nodes.py', line 382, in analyse_declarations: StatListNode(rect.pyx:4:0) File 'Nodes.py', line 4251, in analyse_declarations: CClassDefNode(rect.pyx:8:5, as_name = u'PyRectangle', class_name = u'PyRectangle', module_name = u'', visibility = u'private') File 'Nodes.py', line 382, in analyse_declarations: StatListNode(rect.pyx:9:7) File 'Nodes.py', line 1208, in analyse_declarations: CVarDefNode(rect.pyx:9:7, modifiers = [...]/0, visibility = u'private') Compiler crash traceback from this point on: File "/home/xxx/local/python2.7.1/site-packages/Cython/Compiler/Nodes.py", line 1208, in analyse_declarations self.entry.doc = embed_position(self.pos, self.doc) AttributeError: 'CVarDefNode' object has no attribute 'doc'
I have tried to compile with pyrex, setup.py, ... everything. But I still have the same error.
Is there something I'm missing?
Thanks
解决方案Alright, I finally fixed it. My version of Python 2.7.1 simply doesn't work with the last Cython 0.19.2. I upgraded to 2.7.6 and it works.
这篇关于Cython崩溃从文档示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!