Commit 94ea7d09 authored by Stefan Behnel's avatar Stefan Behnel Committed by GitHub

Work around error "__reduce_cython__ cannot be found" (GH-3549)

* Work around error that "__reduce_cython__ cannot be found" when re-importing an extension module that was already initialised before.
* Exclude "reimport_failure" test in Py2 and PyPy since Py2 does not allow reimports and PyPy3 apparently does nothing for them.

Closes #3545.
parent 8cff92eb
......@@ -235,16 +235,28 @@ static int __Pyx_setup_reduce(PyObject* type_obj) {
reduce = __Pyx_PyObject_GetAttrStr(type_obj, PYIDENT("__reduce__")); if (unlikely(!reduce)) goto __PYX_BAD;
if (reduce == object_reduce || __Pyx_setup_reduce_is_named(reduce, PYIDENT("__reduce_cython__"))) {
reduce_cython = __Pyx_PyObject_GetAttrStr(type_obj, PYIDENT("__reduce_cython__")); if (unlikely(!reduce_cython)) goto __PYX_BAD;
reduce_cython = __Pyx_PyObject_GetAttrStrNoError(type_obj, PYIDENT("__reduce_cython__"));
if (likely(reduce_cython)) {
ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, PYIDENT("__reduce__"), reduce_cython); if (unlikely(ret < 0)) goto __PYX_BAD;
ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, PYIDENT("__reduce_cython__")); if (unlikely(ret < 0)) goto __PYX_BAD;
} else if (reduce == object_reduce || PyErr_Occurred()) {
// Ignore if we're done, i.e. if 'reduce' already has the right name and the original is gone.
// Otherwise: error.
goto __PYX_BAD;
}
setstate = __Pyx_PyObject_GetAttrStrNoError(type_obj, PYIDENT("__setstate__"));
if (!setstate) PyErr_Clear();
if (!setstate || __Pyx_setup_reduce_is_named(setstate, PYIDENT("__setstate_cython__"))) {
setstate_cython = __Pyx_PyObject_GetAttrStr(type_obj, PYIDENT("__setstate_cython__")); if (unlikely(!setstate_cython)) goto __PYX_BAD;
setstate_cython = __Pyx_PyObject_GetAttrStrNoError(type_obj, PYIDENT("__setstate_cython__"));
if (likely(setstate_cython)) {
ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, PYIDENT("__setstate__"), setstate_cython); if (unlikely(ret < 0)) goto __PYX_BAD;
ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, PYIDENT("__setstate_cython__")); if (unlikely(ret < 0)) goto __PYX_BAD;
} else if (!setstate || PyErr_Occurred()) {
// Ignore if we're done, i.e. if 'setstate' already has the right name and the original is gone.
// Otherwise: error.
goto __PYX_BAD;
}
}
PyType_Modified((PyTypeObject*)type_obj);
}
......
......@@ -417,6 +417,7 @@ VER_DEP_MODULES = {
'run.test_raisefrom',
'run.different_package_names',
'run.unicode_imports', # encoding problems on appveyor in Py2
'run.reimport_failure', # reimports don't do anything in Py2
]),
(3,): (operator.ge, lambda x: x in ['run.non_future_division',
'compile.extsetslice',
......
......@@ -38,6 +38,7 @@ run.index
run.pyclass_special_methods
run.reimport_from_package
run.reimport_from_subinterpreter
run.reimport_failure
pkg.cimportfrom
embedded
TestCyCache
......
# mode: run
# tag: pep489
"""
PYTHON setup.py build_ext -i
PYTHON tester.py
"""
######## setup.py ########
from Cython.Build.Dependencies import cythonize
from distutils.core import setup
setup(
ext_modules = cythonize("*.pyx"),
)
######## failure.pyx ########
if globals(): # runtime True to confuse dead code removal
raise ImportError
cdef class C:
cdef int a
######## tester.py ########
try:
try:
import failure # 1
except ImportError:
import failure # 2
except ImportError:
pass
else:
raise RuntimeError("ImportError was not raised on second import!")
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment