Delete PyGen_Send (#22663)
diff --git a/Doc/c-api/gen.rst b/Doc/c-api/gen.rst
index 600f534..7441092 100644
--- a/Doc/c-api/gen.rst
+++ b/Doc/c-api/gen.rst
@@ -42,13 +42,3 @@
with ``__name__`` and ``__qualname__`` set to *name* and *qualname*.
A reference to *frame* is stolen by this function. The *frame* argument
must not be ``NULL``.
-
-.. c:function:: PySendResult PyGen_Send(PyGenObject *gen, PyObject *arg, PyObject **presult)
-
- Sends the *arg* value into the generator *gen*. Coroutine objects
- are also allowed to be as the *gen* argument but they need to be
- explicitly casted to PyGenObject*. Returns:
-
- - ``PYGEN_RETURN`` if generator returns. Return value is returned via *presult*.
- - ``PYGEN_NEXT`` if generator yields. Yielded value is returned via *presult*.
- - ``PYGEN_ERROR`` if generator has raised and exception. *presult* is set to ``NULL``.
diff --git a/Doc/data/refcounts.dat b/Doc/data/refcounts.dat
index 87ce5d0..d01e99c 100644
--- a/Doc/data/refcounts.dat
+++ b/Doc/data/refcounts.dat
@@ -959,11 +959,6 @@
PyGen_NewWithQualName:PyObject*:name:0:
PyGen_NewWithQualName:PyObject*:qualname:0:
-PyGen_Send:int:::
-PyGen_Send:PyGenObject*:gen:0:
-PyGen_Send:PyObject*:arg:0:
-PyGen_Send:PyObject**:presult:+1:
-
PyCoro_CheckExact:int:::
PyCoro_CheckExact:PyObject*:ob:0:
diff --git a/Doc/whatsnew/3.10.rst b/Doc/whatsnew/3.10.rst
index 1c50978..c8ddcd2 100644
--- a/Doc/whatsnew/3.10.rst
+++ b/Doc/whatsnew/3.10.rst
@@ -314,7 +314,7 @@
search function.
(Contributed by Hai Shi in :issue:`41842`.)
-* The :c:func:`PyIter_Send` and :c:func:`PyGen_Send` functions were added to allow
+* The :c:func:`PyIter_Send` function was added to allow
sending value into iterator without raising ``StopIteration`` exception.
(Contributed by Vladimir Matveev in :issue:`41756`.)
diff --git a/Include/genobject.h b/Include/genobject.h
index e719b25..e965334 100644
--- a/Include/genobject.h
+++ b/Include/genobject.h
@@ -45,15 +45,6 @@
PyObject *_PyGen_yf(PyGenObject *);
PyAPI_FUNC(void) _PyGen_Finalize(PyObject *self);
-/* Sends the value into the generator or the coroutine. Returns:
- - PYGEN_RETURN (0) if generator has returned.
- 'result' parameter is filled with return value
- - PYGEN_ERROR (-1) if exception was raised.
- 'result' parameter is NULL
- - PYGEN_NEXT (1) if generator has yielded.
- 'result' parameter is filled with yielded value. */
-PyAPI_FUNC(PySendResult) PyGen_Send(PyGenObject *, PyObject *, PyObject **);
-
#ifndef Py_LIMITED_API
typedef struct {
_PyGenObject_HEAD(cr)
diff --git a/Misc/NEWS.d/3.10.0a1.rst b/Misc/NEWS.d/3.10.0a1.rst
index 725dfd1..044bd20 100644
--- a/Misc/NEWS.d/3.10.0a1.rst
+++ b/Misc/NEWS.d/3.10.0a1.rst
@@ -133,16 +133,6 @@
..
-.. bpo: 41756
-.. date: 2020-09-12-12-55-45
-.. nonce: 1h0tbV
-.. section: Core and Builtins
-
-Add PyGen_Send function to allow sending value into generator/coroutine
-without raising StopIteration exception to signal return
-
-..
-
.. bpo: 1635741
.. date: 2020-09-08-21-58-47
.. nonce: vdjSLH
diff --git a/Objects/abstract.c b/Objects/abstract.c
index 502a2d6..5625498 100644
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -2669,31 +2669,6 @@
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
* NULL terminated string pointers with a NULL char* terminating the array.
diff --git a/Objects/genobject.c b/Objects/genobject.c
index eb134eb..c1b26e9 100644
--- a/Objects/genobject.c
+++ b/Objects/genobject.c
@@ -269,13 +269,29 @@
}
PySendResult
-PyGen_Send(PyGenObject *gen, PyObject *arg, PyObject **result)
+PyIter_Send(PyObject *iter, PyObject *arg, PyObject **result)
{
- assert(PyGen_CheckExact(gen) || PyCoro_CheckExact(gen));
- assert(result != NULL);
+ _Py_IDENTIFIER(send);
assert(arg != NULL);
+ assert(result != NULL);
- return gen_send_ex2(gen, arg, result, 0, 0);
+ if (PyGen_CheckExact(iter) || PyCoro_CheckExact(iter)) {
+ return gen_send_ex2((PyGenObject *)iter, arg, result, 0, 0);
+ }
+
+ 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;
}
static PyObject *