Skip to content

Commit a341d14

Browse files
committed
Don't actually allow using kwnames in Tier 2
But allow `assert(kwnames == NULL)`.
1 parent b9d070f commit a341d14

File tree

7 files changed

+46
-164
lines changed

7 files changed

+46
-164
lines changed

Include/internal/pycore_opcode_metadata.h

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

Python/bytecodes.c

+15-15
Original file line numberDiff line numberDiff line change
@@ -2788,7 +2788,7 @@ dummy_func(
27882788
}
27892789

27902790
inst(KW_NAMES, (--)) {
2791-
assert(kwnames == NULL);
2791+
ASSERT_KWNAMES_IS_NULL();
27922792
assert(oparg < PyTuple_GET_SIZE(FRAME_CO_CONSTS));
27932793
kwnames = GETITEM(FRAME_CO_CONSTS, oparg);
27942794
}
@@ -2940,7 +2940,7 @@ dummy_func(
29402940
}
29412941

29422942
inst(CALL_PY_EXACT_ARGS, (unused/1, func_version/2, method, callable, args[oparg] -- unused)) {
2943-
assert(kwnames == NULL);
2943+
ASSERT_KWNAMES_IS_NULL();
29442944
DEOPT_IF(tstate->interp->eval_frame, CALL);
29452945
int is_meth = method != NULL;
29462946
int argcount = oparg;
@@ -2968,7 +2968,7 @@ dummy_func(
29682968
}
29692969

29702970
inst(CALL_PY_WITH_DEFAULTS, (unused/1, func_version/2, method, callable, args[oparg] -- unused)) {
2971-
assert(kwnames == NULL);
2971+
ASSERT_KWNAMES_IS_NULL();
29722972
DEOPT_IF(tstate->interp->eval_frame, CALL);
29732973
int is_meth = method != NULL;
29742974
int argcount = oparg;
@@ -3006,7 +3006,7 @@ dummy_func(
30063006
}
30073007

30083008
inst(CALL_NO_KW_TYPE_1, (unused/1, unused/2, null, callable, args[oparg] -- res)) {
3009-
assert(kwnames == NULL);
3009+
ASSERT_KWNAMES_IS_NULL();
30103010
assert(oparg == 1);
30113011
DEOPT_IF(null != NULL, CALL);
30123012
PyObject *obj = args[0];
@@ -3018,7 +3018,7 @@ dummy_func(
30183018
}
30193019

30203020
inst(CALL_NO_KW_STR_1, (unused/1, unused/2, null, callable, args[oparg] -- res)) {
3021-
assert(kwnames == NULL);
3021+
ASSERT_KWNAMES_IS_NULL();
30223022
assert(oparg == 1);
30233023
DEOPT_IF(null != NULL, CALL);
30243024
DEOPT_IF(callable != (PyObject *)&PyUnicode_Type, CALL);
@@ -3032,7 +3032,7 @@ dummy_func(
30323032
}
30333033

30343034
inst(CALL_NO_KW_TUPLE_1, (unused/1, unused/2, null, callable, args[oparg] -- res)) {
3035-
assert(kwnames == NULL);
3035+
ASSERT_KWNAMES_IS_NULL();
30363036
assert(oparg == 1);
30373037
DEOPT_IF(null != NULL, CALL);
30383038
DEOPT_IF(callable != (PyObject *)&PyTuple_Type, CALL);
@@ -3051,7 +3051,7 @@ dummy_func(
30513051
* 2. Pushes a shim frame to the frame stack (to cleanup after ``__init__``)
30523052
* 3. Pushes the frame for ``__init__`` to the frame stack
30533053
* */
3054-
assert(kwnames == NULL);
3054+
ASSERT_KWNAMES_IS_NULL();
30553055
_PyCallCache *cache = (_PyCallCache *)next_instr;
30563056
DEOPT_IF(null != NULL, CALL);
30573057
DEOPT_IF(!PyType_Check(callable), CALL);
@@ -3135,7 +3135,7 @@ dummy_func(
31353135

31363136
inst(CALL_NO_KW_BUILTIN_O, (unused/1, unused/2, method, callable, args[oparg] -- res)) {
31373137
/* Builtin METH_O functions */
3138-
assert(kwnames == NULL);
3138+
ASSERT_KWNAMES_IS_NULL();
31393139
int is_meth = method != NULL;
31403140
int total_args = oparg;
31413141
if (is_meth) {
@@ -3166,7 +3166,7 @@ dummy_func(
31663166

31673167
inst(CALL_NO_KW_BUILTIN_FAST, (unused/1, unused/2, method, callable, args[oparg] -- res)) {
31683168
/* Builtin METH_FASTCALL functions, without keywords */
3169-
assert(kwnames == NULL);
3169+
ASSERT_KWNAMES_IS_NULL();
31703170
int is_meth = method != NULL;
31713171
int total_args = oparg;
31723172
if (is_meth) {
@@ -3235,7 +3235,7 @@ dummy_func(
32353235
}
32363236

32373237
inst(CALL_NO_KW_LEN, (unused/1, unused/2, method, callable, args[oparg] -- res)) {
3238-
assert(kwnames == NULL);
3238+
ASSERT_KWNAMES_IS_NULL();
32393239
/* len(o) */
32403240
int is_meth = method != NULL;
32413241
int total_args = oparg;
@@ -3262,7 +3262,7 @@ dummy_func(
32623262
}
32633263

32643264
inst(CALL_NO_KW_ISINSTANCE, (unused/1, unused/2, method, callable, args[oparg] -- res)) {
3265-
assert(kwnames == NULL);
3265+
ASSERT_KWNAMES_IS_NULL();
32663266
/* isinstance(o, o2) */
32673267
int is_meth = method != NULL;
32683268
int total_args = oparg;
@@ -3292,7 +3292,7 @@ dummy_func(
32923292

32933293
// This is secretly a super-instruction
32943294
inst(CALL_NO_KW_LIST_APPEND, (unused/1, unused/2, method, self, args[oparg] -- unused)) {
3295-
assert(kwnames == NULL);
3295+
ASSERT_KWNAMES_IS_NULL();
32963296
assert(oparg == 1);
32973297
assert(method != NULL);
32983298
PyInterpreterState *interp = _PyInterpreterState_GET();
@@ -3312,7 +3312,7 @@ dummy_func(
33123312
}
33133313

33143314
inst(CALL_NO_KW_METHOD_DESCRIPTOR_O, (unused/1, unused/2, method, unused, args[oparg] -- res)) {
3315-
assert(kwnames == NULL);
3315+
ASSERT_KWNAMES_IS_NULL();
33163316
int is_meth = method != NULL;
33173317
int total_args = oparg;
33183318
if (is_meth) {
@@ -3378,7 +3378,7 @@ dummy_func(
33783378
}
33793379

33803380
inst(CALL_NO_KW_METHOD_DESCRIPTOR_NOARGS, (unused/1, unused/2, method, unused, args[oparg] -- res)) {
3381-
assert(kwnames == NULL);
3381+
ASSERT_KWNAMES_IS_NULL();
33823382
assert(oparg == 0 || oparg == 1);
33833383
int is_meth = method != NULL;
33843384
int total_args = oparg;
@@ -3410,7 +3410,7 @@ dummy_func(
34103410
}
34113411

34123412
inst(CALL_NO_KW_METHOD_DESCRIPTOR_FAST, (unused/1, unused/2, method, unused, args[oparg] -- res)) {
3413-
assert(kwnames == NULL);
3413+
ASSERT_KWNAMES_IS_NULL();
34143414
int is_meth = method != NULL;
34153415
int total_args = oparg;
34163416
if (is_meth) {

Python/ceval.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -2706,6 +2706,9 @@ void Py_LeaveRecursiveCall(void)
27062706

27072707
///////////////////// Experimental UOp Interpreter /////////////////////
27082708

2709+
#undef ASSERT_KWNAMES_IS_NULL
2710+
#define ASSERT_KWNAMES_IS_NULL() (void)0
2711+
27092712
#undef DEOPT_IF
27102713
#define DEOPT_IF(COND, INSTNAME) \
27112714
if ((COND)) { \
@@ -2746,7 +2749,6 @@ _PyUopExecute(_PyExecutorObject *executor, _PyInterpreterFrame *frame, PyObject
27462749
int opcode;
27472750
uint64_t operand;
27482751
int oparg;
2749-
PyObject *kwnames = NULL; // Borrowed reference. Reset by CALL instructions.
27502752

27512753
for (;;) {
27522754
opcode = self->trace[pc].opcode;

Python/ceval_macros.h

+2
Original file line numberDiff line numberDiff line change
@@ -349,3 +349,5 @@ static const convertion_func_ptr CONVERSION_FUNCTIONS[4] = {
349349
[FVC_REPR] = PyObject_Repr,
350350
[FVC_ASCII] = PyObject_ASCII
351351
};
352+
353+
#define ASSERT_KWNAMES_IS_NULL() assert(kwnames == NULL)

0 commit comments

Comments
 (0)