Skip to content

Commit 879c85f

Browse files
authored
GH-145667: Merge GET_ITER and GET_YIELD_FROM_ITER (GH-146120)
* Merge GET_ITER and GET_YIELD_FROM_ITER. Modify SEND to make it a bit more like FOR_ITER
1 parent b5e4c46 commit 879c85f

30 files changed

+944
-989
lines changed

Include/internal/pycore_ceval.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ PyAPI_FUNC(PyObject *) _PyEval_GetAwaitable(PyObject *iterable, int oparg);
342342
PyAPI_FUNC(PyObject *) _PyEval_LoadName(PyThreadState *tstate, _PyInterpreterFrame *frame, PyObject *name);
343343
PyAPI_FUNC(int)
344344
_Py_Check_ArgsIterable(PyThreadState *tstate, PyObject *func, PyObject *args);
345+
PyAPI_FUNC(_PyStackRef) _PyEval_GetIter(_PyStackRef iterable, _PyStackRef *null_or_index, int yield_from);
345346

346347
/*
347348
* Indicate whether a special method of given 'oparg' can use the (improved)

Include/internal/pycore_interpframe.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ static inline _PyStackRef *_PyFrame_Stackbase(_PyInterpreterFrame *f) {
102102
return (f->localsplus + _PyFrame_GetCode(f)->co_nlocalsplus);
103103
}
104104

105-
static inline _PyStackRef _PyFrame_StackPeek(_PyInterpreterFrame *f) {
105+
static inline _PyStackRef _PyFrame_StackPeek(_PyInterpreterFrame *f, int depth) {
106106
assert(f->stackpointer > _PyFrame_Stackbase(f));
107-
assert(!PyStackRef_IsNull(f->stackpointer[-1]));
108-
return f->stackpointer[-1];
107+
assert(!PyStackRef_IsNull(f->stackpointer[-depth]));
108+
return f->stackpointer[-depth];
109109
}
110110

111111
static inline _PyStackRef _PyFrame_StackPop(_PyInterpreterFrame *f) {

Include/internal/pycore_magic_number.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,8 @@ Known values:
292292
Python 3.15a4 3659 (Add CALL_FUNCTION_EX specialization)
293293
Python 3.15a4 3660 (Change generator preamble code)
294294
Python 3.15a4 3661 (Lazy imports IMPORT_NAME opcode changes)
295-
Python 3.15a6 3662 (Add counter to RESUME)
295+
Python 3.15a8 3662 (Add counter to RESUME)
296+
Python 3.15a8 3663 (Merge GET_ITER and GET_YIELD_FROM_ITER. Modify SEND to make it a bit more like FOR_ITER)
296297
297298
298299
Python 3.16 will start with 3700
@@ -306,7 +307,7 @@ PC/launcher.c must also be updated.
306307
307308
*/
308309

309-
#define PYC_MAGIC_NUMBER 3662
310+
#define PYC_MAGIC_NUMBER 3663
310311
/* This is equivalent to converting PYC_MAGIC_NUMBER to 2 bytes
311312
(little-endian) and then appending b'\r\n'. */
312313
#define PYC_MAGIC_NUMBER_TOKEN \

Include/internal/pycore_opcode_metadata.h

Lines changed: 13 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_opcode_utils.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ extern "C" {
8686
#define RESUME_OPARG_LOCATION_MASK 0x3
8787
#define RESUME_OPARG_DEPTH1_MASK 0x4
8888

89+
#define GET_ITER_YIELD_FROM 1
90+
#define GET_ITER_YIELD_FROM_NO_CHECK 2
91+
#define GET_ITER_YIELD_FROM_CORO_CHECK 3
92+
8993
#ifdef __cplusplus
9094
}
9195
#endif

0 commit comments

Comments
 (0)