diff options
author | Vladimir Matveev <vladima@fb.com> | 2020-11-10 12:09:55 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-10 12:09:55 -0800 |
commit | 1e996c3a3b51e9c6f1f4cea8a6dbcf3bcb865060 (patch) | |
tree | 3f3ffd5d90532c6f4b1ec013919e3677d63dd21c /Objects/abstract.c | |
parent | e59b2deffde61e5641cabd65034fa11b4db898ba (diff) | |
download | cpython-git-1e996c3a3b51e9c6f1f4cea8a6dbcf3bcb865060.tar.gz |
bpo-42085: Introduce dedicated entry in PyAsyncMethods for sending values (#22780)
Diffstat (limited to 'Objects/abstract.c')
-rw-r--r-- | Objects/abstract.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/Objects/abstract.c b/Objects/abstract.c index 562549876b..44ed5b3932 100644 --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -2669,6 +2669,32 @@ PyIter_Next(PyObject *iter) return result; } +PySendResult +PyIter_Send(PyObject *iter, PyObject *arg, PyObject **result) +{ + _Py_IDENTIFIER(send); + assert(arg != NULL); + assert(result != NULL); + if (PyType_HasFeature(Py_TYPE(iter), Py_TPFLAGS_HAVE_AM_SEND)) { + assert (Py_TYPE(iter)->tp_as_async != NULL); + assert (Py_TYPE(iter)->tp_as_async->am_send != NULL); + return Py_TYPE(iter)->tp_as_async->am_send(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. |