summaryrefslogtreecommitdiffstats
path: root/Doc/c-api/gen.rst
diff options
context:
space:
mode:
authorVladimir Matveev <vladima@fb.com>2020-09-19 01:38:38 (GMT)
committerGitHub <noreply@github.com>2020-09-19 01:38:38 (GMT)
commit2b05361bf7cbbd76035206fd9befe87f37489f1e (patch)
treed29b4c3ab8e617ee8f5f5440db83a2bfa3050666 /Doc/c-api/gen.rst
parentec8a15b034124f3b58d1addda789fa4c20313006 (diff)
downloadcpython-2b05361bf7cbbd76035206fd9befe87f37489f1e.zip
cpython-2b05361bf7cbbd76035206fd9befe87f37489f1e.tar.gz
cpython-2b05361bf7cbbd76035206fd9befe87f37489f1e.tar.bz2
bpo-41756: Introduce PyGen_Send C API (GH-22196)
The new API allows to efficiently send values into native generators and coroutines avoiding use of StopIteration exceptions to signal returns. ceval loop now uses this method instead of the old "private" _PyGen_Send C API. This translates to 1.6x increased performance of 'await' calls in micro-benchmarks. Aside from CPython core improvements, this new API will also allow Cython to generate more efficient code, benefiting high-performance IO libraries like uvloop.
Diffstat (limited to 'Doc/c-api/gen.rst')
-rw-r--r--Doc/c-api/gen.rst15
1 files changed, 15 insertions, 0 deletions
diff --git a/Doc/c-api/gen.rst b/Doc/c-api/gen.rst
index 7441092..e098425 100644
--- a/Doc/c-api/gen.rst
+++ b/Doc/c-api/gen.rst
@@ -15,6 +15,11 @@ than explicitly calling :c:func:`PyGen_New` or :c:func:`PyGen_NewWithQualName`.
The C structure used for generator objects.
+.. c:type:: PySendResult
+
+ The enum value used to represent different results of :c:func:`PyGen_Send`.
+
+
.. c:var:: PyTypeObject PyGen_Type
The type object corresponding to generator objects.
@@ -42,3 +47,13 @@ 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``.