Skip to content

Commit 24a54c0

Browse files
authored
Delete PyGen_Send (#22663)
1 parent abe244c commit 24a54c0

File tree

7 files changed

+21
-64
lines changed

7 files changed

+21
-64
lines changed

Doc/c-api/gen.rst

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,3 @@ than explicitly calling :c:func:`PyGen_New` or :c:func:`PyGen_NewWithQualName`.
4242
with ``__name__`` and ``__qualname__`` set to *name* and *qualname*.
4343
A reference to *frame* is stolen by this function. The *frame* argument
4444
must not be ``NULL``.
45-
46-
.. c:function:: PySendResult PyGen_Send(PyGenObject *gen, PyObject *arg, PyObject **presult)
47-
48-
Sends the *arg* value into the generator *gen*. Coroutine objects
49-
are also allowed to be as the *gen* argument but they need to be
50-
explicitly casted to PyGenObject*. Returns:
51-
52-
- ``PYGEN_RETURN`` if generator returns. Return value is returned via *presult*.
53-
- ``PYGEN_NEXT`` if generator yields. Yielded value is returned via *presult*.
54-
- ``PYGEN_ERROR`` if generator has raised and exception. *presult* is set to ``NULL``.

Doc/data/refcounts.dat

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -959,11 +959,6 @@ PyGen_NewWithQualName:PyFrameObject*:frame:0:
959959
PyGen_NewWithQualName:PyObject*:name:0:
960960
PyGen_NewWithQualName:PyObject*:qualname:0:
961961

962-
PyGen_Send:int:::
963-
PyGen_Send:PyGenObject*:gen:0:
964-
PyGen_Send:PyObject*:arg:0:
965-
PyGen_Send:PyObject**:presult:+1:
966-
967962
PyCoro_CheckExact:int:::
968963
PyCoro_CheckExact:PyObject*:ob:0:
969964

Doc/whatsnew/3.10.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ New Features
314314
search function.
315315
(Contributed by Hai Shi in :issue:`41842`.)
316316

317-
* The :c:func:`PyIter_Send` and :c:func:`PyGen_Send` functions were added to allow
317+
* The :c:func:`PyIter_Send` function was added to allow
318318
sending value into iterator without raising ``StopIteration`` exception.
319319
(Contributed by Vladimir Matveev in :issue:`41756`.)
320320

Include/genobject.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,6 @@ PyAPI_FUNC(int) _PyGen_FetchStopIterationValue(PyObject **);
4545
PyObject *_PyGen_yf(PyGenObject *);
4646
PyAPI_FUNC(void) _PyGen_Finalize(PyObject *self);
4747

48-
/* Sends the value into the generator or the coroutine. Returns:
49-
- PYGEN_RETURN (0) if generator has returned.
50-
'result' parameter is filled with return value
51-
- PYGEN_ERROR (-1) if exception was raised.
52-
'result' parameter is NULL
53-
- PYGEN_NEXT (1) if generator has yielded.
54-
'result' parameter is filled with yielded value. */
55-
PyAPI_FUNC(PySendResult) PyGen_Send(PyGenObject *, PyObject *, PyObject **);
56-
5748
#ifndef Py_LIMITED_API
5849
typedef struct {
5950
_PyGenObject_HEAD(cr)

Misc/NEWS.d/3.10.0a1.rst

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,6 @@ Port the :mod:`_lsprof` extension module to multi-phase initialization
133133

134134
..
135135
136-
.. bpo: 41756
137-
.. date: 2020-09-12-12-55-45
138-
.. nonce: 1h0tbV
139-
.. section: Core and Builtins
140-
141-
Add PyGen_Send function to allow sending value into generator/coroutine
142-
without raising StopIteration exception to signal return
143-
144-
..
145-
146136
.. bpo: 1635741
147137
.. date: 2020-09-08-21-58-47
148138
.. nonce: vdjSLH

Objects/abstract.c

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2669,31 +2669,6 @@ PyIter_Next(PyObject *iter)
26692669
return result;
26702670
}
26712671

2672-
PySendResult
2673-
PyIter_Send(PyObject *iter, PyObject *arg, PyObject **result)
2674-
{
2675-
_Py_IDENTIFIER(send);
2676-
assert(result != NULL);
2677-
2678-
if (PyGen_CheckExact(iter) || PyCoro_CheckExact(iter)) {
2679-
return PyGen_Send((PyGenObject *)iter, arg, result);
2680-
}
2681-
2682-
if (arg == Py_None && PyIter_Check(iter)) {
2683-
*result = Py_TYPE(iter)->tp_iternext(iter);
2684-
}
2685-
else {
2686-
*result = _PyObject_CallMethodIdOneArg(iter, &PyId_send, arg);
2687-
}
2688-
if (*result != NULL) {
2689-
return PYGEN_NEXT;
2690-
}
2691-
if (_PyGen_FetchStopIterationValue(result) == 0) {
2692-
return PYGEN_RETURN;
2693-
}
2694-
return PYGEN_ERROR;
2695-
}
2696-
26972672
/*
26982673
* Flatten a sequence of bytes() objects into a C array of
26992674
* NULL terminated string pointers with a NULL char* terminating the array.

Objects/genobject.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,29 @@ gen_send_ex2(PyGenObject *gen, PyObject *arg, PyObject **presult,
269269
}
270270

271271
PySendResult
272-
PyGen_Send(PyGenObject *gen, PyObject *arg, PyObject **result)
272+
PyIter_Send(PyObject *iter, PyObject *arg, PyObject **result)
273273
{
274-
assert(PyGen_CheckExact(gen) || PyCoro_CheckExact(gen));
275-
assert(result != NULL);
274+
_Py_IDENTIFIER(send);
276275
assert(arg != NULL);
276+
assert(result != NULL);
277+
278+
if (PyGen_CheckExact(iter) || PyCoro_CheckExact(iter)) {
279+
return gen_send_ex2((PyGenObject *)iter, arg, result, 0, 0);
280+
}
277281

278-
return gen_send_ex2(gen, arg, result, 0, 0);
282+
if (arg == Py_None && PyIter_Check(iter)) {
283+
*result = Py_TYPE(iter)->tp_iternext(iter);
284+
}
285+
else {
286+
*result = _PyObject_CallMethodIdOneArg(iter, &PyId_send, arg);
287+
}
288+
if (*result != NULL) {
289+
return PYGEN_NEXT;
290+
}
291+
if (_PyGen_FetchStopIterationValue(result) == 0) {
292+
return PYGEN_RETURN;
293+
}
294+
return PYGEN_ERROR;
279295
}
280296

281297
static PyObject *

0 commit comments

Comments
 (0)