Skip to content

Commit a0c414c

Browse files
authored
gh-111354: define names for RESUME oparg values (#111365)
1 parent 309efb3 commit a0c414c

File tree

7 files changed

+16
-8
lines changed

7 files changed

+16
-8
lines changed

Include/internal/pycore_opcode_utils.h

+6
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ extern "C" {
5858
#define MAKE_FUNCTION_ANNOTATIONS 0x04
5959
#define MAKE_FUNCTION_CLOSURE 0x08
6060

61+
/* Values used in the oparg for RESUME */
62+
#define RESUME_AT_FUNC_START 0
63+
#define RESUME_AFTER_YIELD 1
64+
#define RESUME_AFTER_YIELD_FROM 2
65+
#define RESUME_AFTER_AWAIT 3
66+
6167

6268
#ifdef __cplusplus
6369
}

Objects/genobject.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "pycore_modsupport.h" // _PyArg_CheckPositional()
1111
#include "pycore_object.h" // _PyObject_GC_UNTRACK()
1212
#include "pycore_opcode_metadata.h" // _PyOpcode_Caches
13+
#include "pycore_opcode_utils.h" // RESUME_AFTER_YIELD_FROM
1314
#include "pycore_pyerrors.h" // _PyErr_ClearExcState()
1415
#include "pycore_pystate.h" // _PyThreadState_GET()
1516

@@ -363,7 +364,7 @@ _PyGen_yf(PyGenObject *gen)
363364
assert(_PyCode_CODE(_PyGen_GetCode(gen))[0].op.code != SEND);
364365
return NULL;
365366
}
366-
if (!is_resume(frame->instr_ptr) || frame->instr_ptr->op.arg < 2)
367+
if (!is_resume(frame->instr_ptr) || frame->instr_ptr->op.arg < RESUME_AFTER_YIELD_FROM)
367368
{
368369
/* Not in a yield from */
369370
return NULL;

Python/bytecodes.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ dummy_func(
147147
next_instr--;
148148
}
149149
else {
150-
if (oparg < 2) {
150+
if (oparg < RESUME_AFTER_YIELD_FROM) {
151151
CHECK_EVAL_BREAKER();
152152
}
153153
next_instr[-1].op.code = RESUME_CHECK;

Python/ceval.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ static const _Py_CODEUNIT _Py_INTERPRETER_TRAMPOLINE_INSTRUCTIONS[] = {
643643
{ .op.code = INTERPRETER_EXIT, .op.arg = 0 }, /* reached on return */
644644
{ .op.code = NOP, .op.arg = 0 },
645645
{ .op.code = INTERPRETER_EXIT, .op.arg = 0 }, /* reached on yield */
646-
{ .op.code = RESUME, .op.arg = 0 }
646+
{ .op.code = RESUME, .op.arg = RESUME_AT_FUNC_START }
647647
};
648648

649649
extern const struct _PyCode_DEF(8) _Py_InitCleanup;

Python/compile.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -1383,7 +1383,7 @@ compiler_enter_scope(struct compiler *c, identifier name,
13831383
else {
13841384
RETURN_IF_ERROR(compiler_set_qualname(c));
13851385
}
1386-
ADDOP_I(c, loc, RESUME, 0);
1386+
ADDOP_I(c, loc, RESUME, RESUME_AT_FUNC_START);
13871387

13881388
if (u->u_scope_type == COMPILER_SCOPE_MODULE) {
13891389
loc.lineno = -1;
@@ -1552,7 +1552,7 @@ compiler_add_yield_from(struct compiler *c, location loc, int await)
15521552
ADDOP_JUMP(c, loc, SETUP_FINALLY, fail);
15531553
ADDOP_I(c, loc, YIELD_VALUE, 0);
15541554
ADDOP(c, NO_LOCATION, POP_BLOCK);
1555-
ADDOP_I(c, loc, RESUME, await ? 3 : 2);
1555+
ADDOP_I(c, loc, RESUME, await ? RESUME_AFTER_AWAIT : RESUME_AFTER_YIELD_FROM);
15561556
ADDOP_JUMP(c, loc, JUMP_NO_INTERRUPT, send);
15571557

15581558
USE_LABEL(c, fail);
@@ -4161,7 +4161,7 @@ addop_yield(struct compiler *c, location loc) {
41614161
ADDOP_I(c, loc, CALL_INTRINSIC_1, INTRINSIC_ASYNC_GEN_WRAP);
41624162
}
41634163
ADDOP_I(c, loc, YIELD_VALUE, 0);
4164-
ADDOP_I(c, loc, RESUME, 1);
4164+
ADDOP_I(c, loc, RESUME, RESUME_AFTER_YIELD);
41654165
return SUCCESS;
41664166
}
41674167

Python/generated_cases.c.h

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/specialize.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "pycore_moduleobject.h"
1111
#include "pycore_object.h"
1212
#include "pycore_opcode_metadata.h" // _PyOpcode_Caches
13+
#include "pycore_opcode_utils.h" // RESUME_AT_FUNC_START
1314
#include "pycore_pylifecycle.h" // _PyOS_URandomNonblock()
1415
#include "pycore_runtime.h" // _Py_ID()
1516

@@ -2541,6 +2542,6 @@ const struct _PyCode_DEF(8) _Py_InitCleanup = {
25412542
.co_code_adaptive = {
25422543
EXIT_INIT_CHECK, 0,
25432544
RETURN_VALUE, 0,
2544-
RESUME, 0,
2545+
RESUME, RESUME_AT_FUNC_START,
25452546
}
25462547
};

0 commit comments

Comments
 (0)