Commit f0eaa48e authored by Stefan Behnel's avatar Stefan Behnel

automatically register with "backports_abc" module if available

parent 93db5844
...@@ -17,6 +17,13 @@ Bugs fixed ...@@ -17,6 +17,13 @@ Bugs fixed
* Large folded or inserted integer constants could use too small C * Large folded or inserted integer constants could use too small C
integer types and thus trigger a value wrap-around. integer types and thus trigger a value wrap-around.
Other changes
-------------
* The coroutine and generator types of Cython now also register directly
with the ``Coroutine`` and ``Generator`` ABCs in the ``backports_abc``
module if it can be imported.
0.23.2 (2015-09-11) 0.23.2 (2015-09-11)
=================== ===================
......
...@@ -1479,13 +1479,32 @@ ignore: ...@@ -1479,13 +1479,32 @@ ignore:
//////////////////// PatchGeneratorABC.proto //////////////////// //////////////////// PatchGeneratorABC.proto ////////////////////
// patch 'collections.abc' if it lacks generator support // register with Generator/Coroutine ABCs in 'collections.abc'
// see https://bugs.python.org/issue24018 // see https://bugs.python.org/issue24018
static int __Pyx_patch_abc(void); /*proto*/ static int __Pyx_patch_abc(void); /*proto*/
//////////////////// PatchGeneratorABC //////////////////// //////////////////// PatchGeneratorABC ////////////////////
//@requires: PatchModuleWithCoroutine //@requires: PatchModuleWithCoroutine
#if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
static PyObject* __Pyx_patch_abc_module(PyObject *module); /*proto*/
static PyObject* __Pyx_patch_abc_module(PyObject *module) {
module = __Pyx_Coroutine_patch_module(
module, CSTRING("""\
if _cython_generator_type is not None:
try: Generator = _module.Generator
except AttributeError: pass
else: Generator.register(_cython_generator_type)
if _cython_coroutine_type is not None:
try: Coroutine = _module.Coroutine
except AttributeError: pass
else: Coroutine.register(_cython_coroutine_type)
""")
);
return module;
}
#endif
static int __Pyx_patch_abc(void) { static int __Pyx_patch_abc(void) {
#if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED) #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
static int abc_patched = 0; static int abc_patched = 0;
...@@ -1501,23 +1520,21 @@ static int __Pyx_patch_abc(void) { ...@@ -1501,23 +1520,21 @@ static int __Pyx_patch_abc(void) {
return -1; return -1;
} }
} else { } else {
module = __Pyx_Coroutine_patch_module( module = __Pyx_patch_abc_module(module);
module, CSTRING("""\
if _cython_generator_type is not None:
try: Generator = _module.Generator
except AttributeError: pass
else: Generator.register(_cython_generator_type)
if _cython_coroutine_type is not None:
try: Coroutine = _module.Coroutine
except AttributeError: pass
else: Coroutine.register(_cython_coroutine_type)
""")
);
abc_patched = 1; abc_patched = 1;
if (unlikely(!module)) if (unlikely(!module))
return -1; return -1;
Py_DECREF(module); Py_DECREF(module);
} }
// also register with "backports_abc" module if available, just in case
module = PyImport_ImportModule("backports_abc");
if (module) {
module = __Pyx_patch_abc_module(module);
Py_XDECREF(module);
}
if (!module) {
PyErr_Clear();
}
} }
#else #else
// avoid "unused" warning for __Pyx_Coroutine_patch_module() // avoid "unused" warning for __Pyx_Coroutine_patch_module()
......
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