2

我在 test.pyx 中有以下代码

cdef class Test:
    cdef long long i

    def __cinit__(self, long long i):
        self.i = i

    def __truediv__(Test self, Test other):
        return Test(self.i / other.i)

在一个简短的 python 脚本中,我有这个:

import test
print('Done')

当我在编译 test.pyx 后运行脚本时,我得到以下输出以及 Windows 错误对话框“python.exe 已停止工作”。

Done

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

请注意,我从不调用编译后的代码,只导入它。另请注意,崩溃仅在 python 脚本完成执行后发生。我注意到将ilong long更改为 just a long会导致错误消失。我是否缺少一些基本的东西,或者被long long分割并不总是安全的?

有关我的设置的一些信息(如果有影响):

操作系统:Windows 7、64 位

Python 版本:3.4.2,MSC v 1600 32 位

Cython 版本:0.22

编译器:mingw32

编辑:附加说明

  • 还在 Python 2.7.9 32 位上进行了测试,结果相同
  • 将 / 替换为 // 得到相同的结果
  • 如果所有涉及除法的代码都被删除(注释掉、被编译器删除等),错误就会消失
  • 即使 Python 在完成时崩溃,编译后的代码在调用时似乎也能正常运行。
4

0 回答 0