Delete PyGen_Send (#22663)

This commit is contained in:
Vladimir Matveev 2020-10-12 12:10:42 -07:00 committed by GitHub
parent abe244c458
commit 24a54c0bd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 21 additions and 64 deletions

View File

@ -42,13 +42,3 @@ than explicitly calling :c:func:`PyGen_New` or :c:func:`PyGen_NewWithQualName`.
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``.

View File

@ -959,11 +959,6 @@ PyGen_NewWithQualName:PyFrameObject*:frame:0:
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:

View File

@ -314,7 +314,7 @@ New Features
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`.)

View File

@ -45,15 +45,6 @@ PyAPI_FUNC(int) _PyGen_FetchStopIterationValue(PyObject **);
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)

View File

@ -133,16 +133,6 @@ Port the :mod:`_lsprof` extension module to multi-phase initialization
..
.. 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

View File

@ -2669,31 +2669,6 @@ 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
* NULL terminated string pointers with a NULL char* terminating the array.

View File

@ -269,13 +269,29 @@ gen_send_ex2(PyGenObject *gen, PyObject *arg, PyObject **presult,
}
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 *