]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-111354: define names for RESUME oparg values (#111365)
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>
Thu, 26 Oct 2023 15:30:18 +0000 (16:30 +0100)
committerGitHub <noreply@github.com>
Thu, 26 Oct 2023 15:30:18 +0000 (16:30 +0100)
Include/internal/pycore_opcode_utils.h
Objects/genobject.c
Python/bytecodes.c
Python/ceval.c
Python/compile.c
Python/generated_cases.c.h
Python/specialize.c

index c4acb00a4b291e34a55bf62a06fca1b908f4d384..a6733362d3bfdb2e225a6b2752e5fbe642454cd9 100644 (file)
@@ -58,6 +58,12 @@ extern "C" {
 #define MAKE_FUNCTION_ANNOTATIONS 0x04
 #define MAKE_FUNCTION_CLOSURE     0x08
 
+/* Values used in the oparg for RESUME */
+#define RESUME_AT_FUNC_START 0
+#define RESUME_AFTER_YIELD 1
+#define RESUME_AFTER_YIELD_FROM 2
+#define RESUME_AFTER_AWAIT 3
+
 
 #ifdef __cplusplus
 }
index 092fd5f19b187ec3e97aee4ff86770448c16e86a..14771396619a3a127a585aff82b2d2e0c63bc062 100644 (file)
@@ -10,6 +10,7 @@
 #include "pycore_modsupport.h"    // _PyArg_CheckPositional()
 #include "pycore_object.h"        // _PyObject_GC_UNTRACK()
 #include "pycore_opcode_metadata.h" // _PyOpcode_Caches
+#include "pycore_opcode_utils.h"  // RESUME_AFTER_YIELD_FROM
 #include "pycore_pyerrors.h"      // _PyErr_ClearExcState()
 #include "pycore_pystate.h"       // _PyThreadState_GET()
 
@@ -363,7 +364,7 @@ _PyGen_yf(PyGenObject *gen)
             assert(_PyCode_CODE(_PyGen_GetCode(gen))[0].op.code != SEND);
             return NULL;
         }
-        if (!is_resume(frame->instr_ptr) || frame->instr_ptr->op.arg < 2)
+        if (!is_resume(frame->instr_ptr) || frame->instr_ptr->op.arg < RESUME_AFTER_YIELD_FROM)
         {
             /* Not in a yield from */
             return NULL;
index e101efaae4cad44506299b7530853659e90fad3b..2d7b5ba21ea09df6291bc0f9177dd83e71b2ebcd 100644 (file)
@@ -147,7 +147,7 @@ dummy_func(
                 next_instr--;
             }
             else {
-                if (oparg < 2) {
+                if (oparg < RESUME_AFTER_YIELD_FROM) {
                     CHECK_EVAL_BREAKER();
                 }
                 next_instr[-1].op.code = RESUME_CHECK;
index 61f83871016543aa8e068d3f6af00626f09720fe..e3a7c5f38403a78d4358f458845357a788a9c349 100644 (file)
@@ -643,7 +643,7 @@ static const _Py_CODEUNIT _Py_INTERPRETER_TRAMPOLINE_INSTRUCTIONS[] = {
     { .op.code = INTERPRETER_EXIT, .op.arg = 0 },  /* reached on return */
     { .op.code = NOP, .op.arg = 0 },
     { .op.code = INTERPRETER_EXIT, .op.arg = 0 },  /* reached on yield */
-    { .op.code = RESUME, .op.arg = 0 }
+    { .op.code = RESUME, .op.arg = RESUME_AT_FUNC_START }
 };
 
 extern const struct _PyCode_DEF(8) _Py_InitCleanup;
index 1d9ae6266773100224e48a9a0ea1c934f201f664..3ff64182ba2dff0bb0455040743827ddbe60e818 100644 (file)
@@ -1383,7 +1383,7 @@ compiler_enter_scope(struct compiler *c, identifier name,
     else {
         RETURN_IF_ERROR(compiler_set_qualname(c));
     }
-    ADDOP_I(c, loc, RESUME, 0);
+    ADDOP_I(c, loc, RESUME, RESUME_AT_FUNC_START);
 
     if (u->u_scope_type == COMPILER_SCOPE_MODULE) {
         loc.lineno = -1;
@@ -1552,7 +1552,7 @@ compiler_add_yield_from(struct compiler *c, location loc, int await)
     ADDOP_JUMP(c, loc, SETUP_FINALLY, fail);
     ADDOP_I(c, loc, YIELD_VALUE, 0);
     ADDOP(c, NO_LOCATION, POP_BLOCK);
-    ADDOP_I(c, loc, RESUME, await ? 3 : 2);
+    ADDOP_I(c, loc, RESUME, await ? RESUME_AFTER_AWAIT : RESUME_AFTER_YIELD_FROM);
     ADDOP_JUMP(c, loc, JUMP_NO_INTERRUPT, send);
 
     USE_LABEL(c, fail);
@@ -4161,7 +4161,7 @@ addop_yield(struct compiler *c, location loc) {
         ADDOP_I(c, loc, CALL_INTRINSIC_1, INTRINSIC_ASYNC_GEN_WRAP);
     }
     ADDOP_I(c, loc, YIELD_VALUE, 0);
-    ADDOP_I(c, loc, RESUME, 1);
+    ADDOP_I(c, loc, RESUME, RESUME_AFTER_YIELD);
     return SUCCESS;
 }
 
index 3ae1a58b7393ec93c7b9e2f75be85f70d8bae964..d5e0d849efe9d274438aa8843f40847a04b35842 100644 (file)
@@ -23,7 +23,7 @@
                 next_instr--;
             }
             else {
-                if (oparg < 2) {
+                if (oparg < RESUME_AFTER_YIELD_FROM) {
                     CHECK_EVAL_BREAKER();
                 }
                 next_instr[-1].op.code = RESUME_CHECK;
index cd26ff542720f82279682f820a78652569c83c62..07fd93d29b09dce32207afff37d0d8392412e060 100644 (file)
@@ -10,6 +10,7 @@
 #include "pycore_moduleobject.h"
 #include "pycore_object.h"
 #include "pycore_opcode_metadata.h" // _PyOpcode_Caches
+#include "pycore_opcode_utils.h"  // RESUME_AT_FUNC_START
 #include "pycore_pylifecycle.h"   // _PyOS_URandomNonblock()
 #include "pycore_runtime.h"       // _Py_ID()
 
@@ -2541,6 +2542,6 @@ const struct _PyCode_DEF(8) _Py_InitCleanup = {
     .co_code_adaptive = {
         EXIT_INIT_CHECK, 0,
         RETURN_VALUE, 0,
-        RESUME, 0,
+        RESUME, RESUME_AT_FUNC_START,
     }
 };