summaryrefslogtreecommitdiff
path: root/Cython/Utility/Coroutine.c
diff options
context:
space:
mode:
Diffstat (limited to 'Cython/Utility/Coroutine.c')
-rw-r--r--Cython/Utility/Coroutine.c44
1 files changed, 35 insertions, 9 deletions
diff --git a/Cython/Utility/Coroutine.c b/Cython/Utility/Coroutine.c
index 340bc34f9..6cd1b78b4 100644
--- a/Cython/Utility/Coroutine.c
+++ b/Cython/Utility/Coroutine.c
@@ -797,6 +797,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;
+ // PyIter_Send() asserts non-NULL arg
+ if (PyIter_Send((PyObject*)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;
@@ -838,13 +864,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
{
@@ -939,7 +965,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
@@ -1140,7 +1166,7 @@ static void __Pyx_Coroutine_dealloc(PyObject *self) {
if (unlikely(PyObject_CallFinalizerFromDealloc(self)))
#else
Py_TYPE(gen)->tp_del(self);
- if (unlikely(self->ob_refcnt > 0))
+ if (unlikely(Py_REFCNT(self) > 0))
#endif
{
// resurrected. :(
@@ -1174,7 +1200,7 @@ static void __Pyx_Coroutine_del(PyObject *self) {
#if !CYTHON_USE_TP_FINALIZE
// Temporarily resurrect the object.
assert(self->ob_refcnt == 0);
- self->ob_refcnt = 1;
+ __Pyx_SET_REFCNT(self, 1);
#endif
__Pyx_PyThreadState_assign
@@ -1255,7 +1281,7 @@ static void __Pyx_Coroutine_del(PyObject *self) {
#if !CYTHON_USE_TP_FINALIZE
// Undo the temporary resurrection; can't use DECREF here, it would
// cause a recursive call.
- assert(self->ob_refcnt > 0);
+ assert(Py_REFCNT(self) > 0);
if (likely(--self->ob_refcnt == 0)) {
// this is the normal path out
return;
@@ -1264,12 +1290,12 @@ static void __Pyx_Coroutine_del(PyObject *self) {
// close() resurrected it! Make it look like the original Py_DECREF
// never happened.
{
- Py_ssize_t refcnt = self->ob_refcnt;
+ Py_ssize_t refcnt = Py_REFCNT(self);
_Py_NewReference(self);
- self->ob_refcnt = refcnt;
+ __Pyx_SET_REFCNT(self, refcnt);
}
#if CYTHON_COMPILING_IN_CPYTHON
- assert(PyType_IS_GC(self->ob_type) &&
+ assert(PyType_IS_GC(Py_TYPE(self)) &&
_Py_AS_GC(self)->gc.gc_refs != _PyGC_REFS_UNTRACKED);
// If Py_REF_DEBUG, _Py_NewReference bumped _Py_RefTotal, so