Cython';s cpython.datetime.datetime\u新原因分段错误
Cython公开了一个新的Cython';s cpython.datetime.datetime\u新原因分段错误,python,datetime,cython,Python,Datetime,Cython,Cython公开了一个新的datetime函数,它是datetime.h的包装器。然而,每当我实际尝试使用这个函数时,我会立即得到一个分段错误,即使是有效值。下面是Cython代码的一个最小工作示例: cimport cpython.datetime cpdef cpython.datetime.datetime construct_datetime(): return cpython.datetime.datetime_new(2017, 12, 1, 12, 30, 15, 0,
datetime
函数,它是datetime.h
的包装器。然而,每当我实际尝试使用这个函数时,我会立即得到一个分段错误,即使是有效值。下面是Cython代码的一个最小工作示例:
cimport cpython.datetime
cpdef cpython.datetime.datetime construct_datetime():
return cpython.datetime.datetime_new(2017, 12, 1, 12, 30, 15, 0, None)
以下是setup.py
:
from distutils.core import setup
from Cython.Build import cythonize
setup(ext_modules = cythonize('test_segfault.pyx'))
如果我运行它,我会得到:
$ python setup.py build_ext --inplace > /dev/null
$ $ python -c 'from test_segfault import construct_datetime; construct_datetime()'
Segmentation fault (core dumped)
我在Arch Linux上使用Cython版本0.25.2,Python 3.6.1:
$ python -c 'import sys; print(sys.version)'
3.6.1 |Continuum Analytics, Inc.| (default, May 11 2017, 13:09:58)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]
我使用这个函数错了吗?我知道我可以在这里调用标准的cpython.datetime.datetime
构造函数,但是datetime\u new
绕过范围检查,我正在尝试查看附加检查需要多少时间。您忘了:
你忘了:
当然有。天哪。不知何故,我得到的印象是,cimport cpython.datetime已经调用了它,但没有,那只是我的愚蠢。谢谢,当然有。天哪。不知何故,我得到的印象是,cimport cpython.datetime已经调用了它,但没有,那只是我的愚蠢。谢谢
# Datetime C API initialization function.
# You have to call it before any usage of DateTime CAPI functions.
cdef inline void import_datetime():
PyDateTime_IMPORT