GH-143732: SEND specialization (GH-148963) · python/cpython@70bd1c2

GitHub

File tree

Include

cpython

internal

Lib

test

test_capi

Modules/_testinternalcapi

Objects

Python

Tools/cases_generator

Original file line numberDiff line numberDiff line change@@ -241,7 +241,11 @@ struct _typeobject {

241241 * Otherwise, limited to MAX_VERSIONS_PER_CLASS (defined elsewhere).

242242 */

243243uint16_ttp_versions_used;

244-_Py_iteritemfunc_tp_iteritem; /* Virtual iterator next function */

244+245+/* Virtual iterator next function.

246+ * This function must escape to any code that can result in

247+ * the GC being run, such as Py_DECREF. */

248+_Py_iteritemfunc_tp_iteritem;

245249};

246250247251#define_Py_ATTR_CACHE_UNUSED (30000) // (see tp_versions_used)

Original file line numberDiff line numberDiff line change@@ -60,6 +60,14 @@ PyAPI_FUNC(int) _Py_convert_optional_to_non_negative_ssize_t(PyObject *, void *)

6060// Export for 'math' shared extension.

6161PyAPI_FUNC(PyObject*) _PyNumber_Index(PyObject*o);

626263+typedefstruct {

64+PyObject*object;

65+PySendResultkind;

66+} PySendResultPair;

67+68+// Same as PyIter_Send but returns a struct for MSVC tailcall support

69+PyAPI_FUNC(PySendResultPair) _PyIter_Send(PyObject*iter, PyObject*arg);

70+6371#ifdef__cplusplus

6472}

6573#endif

Original file line numberDiff line numberDiff line change@@ -40,6 +40,8 @@ extern PyTypeObject _PyCoroWrapper_Type;

4040externPyTypeObject_PyAsyncGenWrappedValue_Type;

4141externPyTypeObject_PyAsyncGenAThrow_Type;

424243+PyAPI_FUNC(PySendResult) _PyAsyncGenASend_Send(PyObject*iter, PyObject*arg, PyObject**result);

44+4345#ifdef__cplusplus

4446}

4547#endif

Original file line numberDiff line numberDiff line change@@ -296,6 +296,7 @@ Known values:

296296 Python 3.15a8 3663 (Merge GET_ITER and GET_YIELD_FROM_ITER. Modify SEND to make it a bit more like FOR_ITER)

297297 Python 3.15a8 3664 (Fix __qualname__ for __annotate__ functions)

298298 Python 3.15a8 3665 (Add FOR_ITER_VIRTUAL and GET_ITER specializations)

299+ Python 3.15b1 3666 (Add SEND_VIRTUAL and SEND_ASYNC_GEN specializations)

299300300301301302 Python 3.16 will start with 3700

@@ -309,7 +310,7 @@ PC/launcher.c must also be updated.

309310310311*/

311312312-#definePYC_MAGIC_NUMBER3665

313+#definePYC_MAGIC_NUMBER3666

313314/* This is equivalent to converting PYC_MAGIC_NUMBER to 2 bytes

314315 (little-endian) and then appending b'\r\n'. */

315316#definePYC_MAGIC_NUMBER_TOKEN \