Skip to content

Commit

Permalink
pythonGH-117714: replace athrow().close() and asend().close() stubs w…
Browse files Browse the repository at this point in the history
…ith implimentations
  • Loading branch information
graingert committed Apr 15, 2024
1 parent 3131a70 commit 743ded1
Showing 1 changed file with 39 additions and 4 deletions.
43 changes: 39 additions & 4 deletions Objects/genobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "pycore_pystate.h" // _PyThreadState_GET()

#include "pystats.h"
#include "pyerrors.h"

static PyObject *gen_close(PyGenObject *, PyObject *);
static PyObject *async_gen_asend_new(PyAsyncGenObject *, PyObject *);
Expand Down Expand Up @@ -1843,8 +1844,25 @@ async_gen_asend_throw(PyAsyncGenASend *o, PyObject *const *args, Py_ssize_t narg
static PyObject *
async_gen_asend_close(PyAsyncGenASend *o, PyObject *args)
{
o->ags_state = AWAITABLE_STATE_CLOSED;
Py_RETURN_NONE;
PyObject *result;
if (o->ags_state == AWAITABLE_STATE_CLOSED) {
Py_RETURN_NONE;
}
result = async_gen_asend_throw(o, &PyExc_GeneratorExit, 1);
if (result == NULL) {
if (PyErr_ExceptionMatches(PyExc_StopIteration) ||
PyErr_ExceptionMatches(PyExc_StopAsyncIteration) ||
PyErr_ExceptionMatches(PyExc_GeneratorExit))
{
PyErr_Clear();
Py_RETURN_NONE;
}
return result;
} else {
Py_DECREF(result);
PyErr_SetString(PyExc_RuntimeError, "coroutine ignored GeneratorExit");
return NULL;
}
}

static void
Expand Down Expand Up @@ -2288,8 +2306,25 @@ async_gen_athrow_iternext(PyAsyncGenAThrow *o)
static PyObject *
async_gen_athrow_close(PyAsyncGenAThrow *o, PyObject *args)
{
o->agt_state = AWAITABLE_STATE_CLOSED;
Py_RETURN_NONE;
PyObject *result;
if (o->agt_state == AWAITABLE_STATE_CLOSED) {
Py_RETURN_NONE;
}
result = async_gen_athrow_throw(o, &PyExc_GeneratorExit, 1);
if (result == NULL) {
if (PyErr_ExceptionMatches(PyExc_StopIteration) ||
PyErr_ExceptionMatches(PyExc_StopAsyncIteration) ||
PyErr_ExceptionMatches(PyExc_GeneratorExit))
{
PyErr_Clear();
Py_RETURN_NONE;
}
return result;
} else {
Py_DECREF(result);
PyErr_SetString(PyExc_RuntimeError, "coroutine ignored GeneratorExit");
return NULL;
}
}


Expand Down

0 comments on commit 743ded1

Please sign in to comment.