Skip to content

Commit

Permalink
Fix usage of undefined C-API function "_PyGen_Send" in Py3.10.
Browse files Browse the repository at this point in the history
  • Loading branch information
scoder committed Nov 27, 2020
1 parent 65b3785 commit b37607f
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions Cython/Utility/Coroutine.c
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,32 @@ PyObject *__Pyx_Coroutine_MethodReturn(CYTHON_UNUSED PyObject* gen, PyObject *re
return retval;
}

#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03030000 && (defined(__linux__) || PY_VERSION_HEX >= 0x030600B3)
static CYTHON_INLINE
PyObject *__Pyx_PyGen_Send(PyGenObject *gen, PyObject *arg) {
#if PY_VERSION_HEX < 0x030A00A1
return _PyGen_Send(gen, arg);
#else
PyObject *result;
// PyGen_Send() asserts non-NULL arg
if (PyGen_Send(gen, arg ? arg : Py_None, &result) == PYGEN_RETURN) {
if (PyAsyncGen_CheckExact(gen)) {
assert(result == Py_None);
PyErr_SetNone(PyExc_StopAsyncIteration);
}
else if (result == Py_None) {
PyErr_SetNone(PyExc_StopIteration);
}
else {
_PyGen_SetStopIterationValue(result);
}
Py_CLEAR(result);
}
return result;
#endif
}
#endif

static CYTHON_INLINE
PyObject *__Pyx_Coroutine_FinishDelegation(__pyx_CoroutineObject *gen) {
PyObject *ret;
Expand Down Expand Up @@ -829,13 +855,13 @@ static PyObject *__Pyx_Coroutine_Send(PyObject *self, PyObject *value) {
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03030000 && (defined(__linux__) || PY_VERSION_HEX >= 0x030600B3)
// _PyGen_Send() is not exported before Py3.6
if (PyGen_CheckExact(yf)) {
ret = _PyGen_Send((PyGenObject*)yf, value == Py_None ? NULL : value);
ret = __Pyx_PyGen_Send((PyGenObject*)yf, value == Py_None ? NULL : value);
} else
#endif
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03050000 && defined(PyCoro_CheckExact) && (defined(__linux__) || PY_VERSION_HEX >= 0x030600B3)
// _PyGen_Send() is not exported before Py3.6
if (PyCoro_CheckExact(yf)) {
ret = _PyGen_Send((PyGenObject*)yf, value == Py_None ? NULL : value);
ret = __Pyx_PyGen_Send((PyGenObject*)yf, value == Py_None ? NULL : value);
} else
#endif
{
Expand Down Expand Up @@ -931,7 +957,7 @@ static PyObject *__Pyx_Generator_Next(PyObject *self) {
#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03030000 && (defined(__linux__) || PY_VERSION_HEX >= 0x030600B3)
// _PyGen_Send() is not exported before Py3.6
if (PyGen_CheckExact(yf)) {
ret = _PyGen_Send((PyGenObject*)yf, NULL);
ret = __Pyx_PyGen_Send((PyGenObject*)yf, NULL);
} else
#endif
#ifdef __Pyx_Coroutine_USED
Expand Down

0 comments on commit b37607f

Please sign in to comment.