【问题标题】:Cython crash from documentation example文档示例中的 Cython 崩溃
【发布时间】:2013-12-06 14:10:35
【问题描述】:

我使用 Cython 0.19.2(和 Python 2.7.1)将 C++ 类公开给 Python。

作为第一次尝试,我使用文档的“矩形”类示例进行了测试。

http://docs.cython.org/src/userguide/wrapping_CPlusPlus.html

我有一个我不明白的崩溃。

我已经尽量简化代码。但我仍然有问题。

这是我的 pyx 文件,C++ 源代码只是 python/cython 文档的剪切和粘贴。

# distutils: language = c++
# distutils: sources = Rectangle.cpp

cdef extern from "Rectangle.h" namespace "shapes":
  cdef cppclass Rectangle:
    pass

cdef class PyRectangle:
  cdef Rectangle* thisptr

我只想用thisptr声明一个类,它指向C++ Rectangle类实例。

当我尝试编译程序时:

cython -a --cplus rect.pyx

我有以下崩溃:

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'

我尝试使用 pyrex、setup.py、... 一切进行编译。但我仍然有同样的错误。

我有什么遗漏吗?

谢谢

【问题讨论】:

  • 我唯一能注意到的是你的python相当老,而且你的cython也不是最新的。
  • 我的 Cython 是 0.19.2,这是最新的 q[-_-]p
  • 您的帖子使它看起来像 0.19 而不是 0.19.2 ...尝试更新 python 本身?只是猜测......
  • 我已经编辑了我的消息。我用的python是2.7.1,有这么老吗? o_O
  • 你可以自己查看当前版本是什么,你懂的...

标签: c++ python crash cython


【解决方案1】:

好吧,我终于修好了。我的 Python 2.7.1 版本根本不适用于最后一个 Cython 0.19.2。我升级到 2.7.6 并且可以正常工作。

【讨论】:

    猜你喜欢
    • 2019-12-18
    • 1970-01-01
    • 2011-10-13
    • 2018-12-23
    • 1970-01-01
    • 2011-03-01
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多