summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorVladimir Matveev <vladima@fb.com>2020-10-10 00:15:15 (GMT)
committerGitHub <noreply@github.com>2020-10-10 00:15:15 (GMT)
commit037245c5ac46c3436f617a1f5d965929754be239 (patch)
treece2a797b165e846d59e53ba5d530413cb573a8aa /Objects
parent9975cc5008c795e069ce11e2dbed2110cc12e74e (diff)
downloadcpython-037245c5ac46c3436f617a1f5d965929754be239.zip
cpython-037245c5ac46c3436f617a1f5d965929754be239.tar.gz
cpython-037245c5ac46c3436f617a1f5d965929754be239.tar.bz2
bpo-41756: Add PyIter_Send function (#22443)
Diffstat (limited to 'Objects')
-rw-r--r--Objects/abstract.c24
-rw-r--r--Objects/genobject.c8
2 files changed, 25 insertions, 7 deletions
diff --git a/Objects/abstract.c b/Objects/abstract.c
index 2ab3371..502a2d6 100644
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -2669,6 +2669,30 @@ PyIter_Next(PyObject *iter)
return result;
}
+PySendResult
+PyIter_Send(PyObject *iter, PyObject *arg, PyObject **result)
+{
+ _Py_IDENTIFIER(send);
+ assert(result != NULL);
+
+ if (PyGen_CheckExact(iter) || PyCoro_CheckExact(iter)) {
+ return PyGen_Send((PyGenObject *)iter, arg, result);
+ }
+
+ if (arg == Py_None && PyIter_Check(iter)) {
+ *result = Py_TYPE(iter)->tp_iternext(iter);
+ }
+ else {
+ *result = _PyObject_CallMethodIdOneArg(iter, &PyId_send, arg);
+ }
+ if (*result != NULL) {
+ return PYGEN_NEXT;
+ }
+ if (_PyGen_FetchStopIterationValue(result) == 0) {
+ return PYGEN_RETURN;
+ }
+ return PYGEN_ERROR;
+}
/*
* Flatten a sequence of bytes() objects into a C array of
diff --git a/Objects/genobject.c b/Objects/genobject.c
index f0943ae..eb134eb 100644
--- a/Objects/genobject.c
+++ b/Objects/genobject.c
@@ -308,12 +308,6 @@ gen_send(PyGenObject *gen, PyObject *arg)
return gen_send_ex(gen, arg, 0, 0);
}
-PyObject *
-_PyGen_Send(PyGenObject *gen, PyObject *arg)
-{
- return gen_send(gen, arg);
-}
-
PyDoc_STRVAR(close_doc,
"close() -> raise GeneratorExit inside generator.");
@@ -1012,7 +1006,7 @@ PyDoc_STRVAR(coro_close_doc,
"close() -> raise GeneratorExit inside coroutine.");
static PyMethodDef coro_methods[] = {
- {"send",(PyCFunction)_PyGen_Send, METH_O, coro_send_doc},
+ {"send",(PyCFunction)gen_send, METH_O, coro_send_doc},
{"throw",(PyCFunction)gen_throw, METH_VARARGS, coro_throw_doc},
{"close",(PyCFunction)gen_close, METH_NOARGS, coro_close_doc},
{NULL, NULL} /* Sentinel */