Skip to content

bpo-41756: Delete PyGen_Send function #22663

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions Doc/c-api/gen.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``.
5 changes: 0 additions & 5 deletions Doc/data/refcounts.dat
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
2 changes: 1 addition & 1 deletion Doc/whatsnew/3.10.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`.)

Expand Down
9 changes: 0 additions & 9 deletions Include/genobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 0 additions & 10 deletions Misc/NEWS.d/3.10.0a1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 0 additions & 25 deletions Objects/abstract.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
24 changes: 20 additions & 4 deletions Objects/genobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, what function does the ceval look call now when in tracing?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It calls _PyObject_CallMethodIdOneArg(receiver, &PyId_send, v).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense.

{
assert(PyGen_CheckExact(gen) || PyCoro_CheckExact(gen));
assert(result != NULL);
_Py_IDENTIFIER(send);
assert(arg != NULL);
assert(result != NULL);

if (PyGen_CheckExact(iter) || PyCoro_CheckExact(iter)) {
return gen_send_ex2((PyGenObject *)iter, arg, result, 0, 0);
}

return gen_send_ex2(gen, 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 *
Expand Down