Skip to content

Commit c26b4b6

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

File tree

7 files changed

+46
-164
lines changed

7 files changed

+46
-164
lines changed

Include/internal/pycore_opcode_metadata.h

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

Python/bytecodes.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2778,7 +2778,7 @@ dummy_func(
27782778
}
27792779

27802780
inst(KW_NAMES, (--)) {
2781-
assert(kwnames == NULL);
2781+
ASSERT_KWNAMES_IS_NULL();
27822782
assert(oparg < PyTuple_GET_SIZE(FRAME_CO_CONSTS));
27832783
kwnames = GETITEM(FRAME_CO_CONSTS, oparg);
27842784
}
@@ -2930,7 +2930,7 @@ dummy_func(
29302930
}
29312931

29322932
inst(CALL_PY_EXACT_ARGS, (unused/1, func_version/2, method, callable, args[oparg] -- unused)) {
2933-
assert(kwnames == NULL);
2933+
ASSERT_KWNAMES_IS_NULL();
29342934
DEOPT_IF(tstate->interp->eval_frame, CALL);
29352935
int is_meth = method != NULL;
29362936
int argcount = oparg;
@@ -2958,7 +2958,7 @@ dummy_func(
29582958
}
29592959

29602960
inst(CALL_PY_WITH_DEFAULTS, (unused/1, func_version/2, method, callable, args[oparg] -- unused)) {
2961-
assert(kwnames == NULL);
2961+
ASSERT_KWNAMES_IS_NULL();
29622962
DEOPT_IF(tstate->interp->eval_frame, CALL);
29632963
int is_meth = method != NULL;
29642964
int argcount = oparg;
@@ -2996,7 +2996,7 @@ dummy_func(
29962996
}
29972997

29982998
inst(CALL_NO_KW_TYPE_1, (unused/1, unused/2, null, callable, args[oparg] -- res)) {
2999-
assert(kwnames == NULL);
2999+
ASSERT_KWNAMES_IS_NULL();
30003000
assert(oparg == 1);
30013001
DEOPT_IF(null != NULL, CALL);
30023002
PyObject *obj = args[0];
@@ -3008,7 +3008,7 @@ dummy_func(
30083008
}
30093009

30103010
inst(CALL_NO_KW_STR_1, (unused/1, unused/2, null, callable, args[oparg] -- res)) {
3011-
assert(kwnames == NULL);
3011+
ASSERT_KWNAMES_IS_NULL();
30123012
assert(oparg == 1);
30133013
DEOPT_IF(null != NULL, CALL);
30143014
DEOPT_IF(callable != (PyObject *)&PyUnicode_Type, CALL);
@@ -3022,7 +3022,7 @@ dummy_func(
30223022
}
30233023

30243024
inst(CALL_NO_KW_TUPLE_1, (unused/1, unused/2, null, callable, args[oparg] -- res)) {
3025-
assert(kwnames == NULL);
3025+
ASSERT_KWNAMES_IS_NULL();
30263026
assert(oparg == 1);
30273027
DEOPT_IF(null != NULL, CALL);
30283028
DEOPT_IF(callable != (PyObject *)&PyTuple_Type, CALL);
@@ -3041,7 +3041,7 @@ dummy_func(
30413041
* 2. Pushes a shim frame to the frame stack (to cleanup after ``__init__``)
30423042
* 3. Pushes the frame for ``__init__`` to the frame stack
30433043
* */
3044-
assert(kwnames == NULL);
3044+
ASSERT_KWNAMES_IS_NULL();
30453045
_PyCallCache *cache = (_PyCallCache *)next_instr;
30463046
DEOPT_IF(null != NULL, CALL);
30473047
DEOPT_IF(!PyType_Check(callable), CALL);
@@ -3125,7 +3125,7 @@ dummy_func(
31253125

31263126
inst(CALL_NO_KW_BUILTIN_O, (unused/1, unused/2, method, callable, args[oparg] -- res)) {
31273127
/* Builtin METH_O functions */
3128-
assert(kwnames == NULL);
3128+
ASSERT_KWNAMES_IS_NULL();
31293129
int is_meth = method != NULL;
31303130
int total_args = oparg;
31313131
if (is_meth) {
@@ -3156,7 +3156,7 @@ dummy_func(
31563156

31573157
inst(CALL_NO_KW_BUILTIN_FAST, (unused/1, unused/2, method, callable, args[oparg] -- res)) {
31583158
/* Builtin METH_FASTCALL functions, without keywords */
3159-
assert(kwnames == NULL);
3159+
ASSERT_KWNAMES_IS_NULL();
31603160
int is_meth = method != NULL;
31613161
int total_args = oparg;
31623162
if (is_meth) {
@@ -3225,7 +3225,7 @@ dummy_func(
32253225
}
32263226

32273227
inst(CALL_NO_KW_LEN, (unused/1, unused/2, method, callable, args[oparg] -- res)) {
3228-
assert(kwnames == NULL);
3228+
ASSERT_KWNAMES_IS_NULL();
32293229
/* len(o) */
32303230
int is_meth = method != NULL;
32313231
int total_args = oparg;
@@ -3252,7 +3252,7 @@ dummy_func(
32523252
}
32533253

32543254
inst(CALL_NO_KW_ISINSTANCE, (unused/1, unused/2, method, callable, args[oparg] -- res)) {
3255-
assert(kwnames == NULL);
3255+
ASSERT_KWNAMES_IS_NULL();
32563256
/* isinstance(o, o2) */
32573257
int is_meth = method != NULL;
32583258
int total_args = oparg;
@@ -3282,7 +3282,7 @@ dummy_func(
32823282

32833283
// This is secretly a super-instruction
32843284
inst(CALL_NO_KW_LIST_APPEND, (unused/1, unused/2, method, self, args[oparg] -- unused)) {
3285-
assert(kwnames == NULL);
3285+
ASSERT_KWNAMES_IS_NULL();
32863286
assert(oparg == 1);
32873287
assert(method != NULL);
32883288
PyInterpreterState *interp = _PyInterpreterState_GET();
@@ -3302,7 +3302,7 @@ dummy_func(
33023302
}
33033303

33043304
inst(CALL_NO_KW_METHOD_DESCRIPTOR_O, (unused/1, unused/2, method, unused, args[oparg] -- res)) {
3305-
assert(kwnames == NULL);
3305+
ASSERT_KWNAMES_IS_NULL();
33063306
int is_meth = method != NULL;
33073307
int total_args = oparg;
33083308
if (is_meth) {
@@ -3368,7 +3368,7 @@ dummy_func(
33683368
}
33693369

33703370
inst(CALL_NO_KW_METHOD_DESCRIPTOR_NOARGS, (unused/1, unused/2, method, unused, args[oparg] -- res)) {
3371-
assert(kwnames == NULL);
3371+
ASSERT_KWNAMES_IS_NULL();
33723372
assert(oparg == 0 || oparg == 1);
33733373
int is_meth = method != NULL;
33743374
int total_args = oparg;
@@ -3400,7 +3400,7 @@ dummy_func(
34003400
}
34013401

34023402
inst(CALL_NO_KW_METHOD_DESCRIPTOR_FAST, (unused/1, unused/2, method, unused, args[oparg] -- res)) {
3403-
assert(kwnames == NULL);
3403+
ASSERT_KWNAMES_IS_NULL();
34043404
int is_meth = method != NULL;
34053405
int total_args = oparg;
34063406
if (is_meth) {

Python/ceval.c

Lines changed: 3 additions & 1 deletion
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

Lines changed: 2 additions & 0 deletions
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)