Skip to content

Commit 5697fc2

Browse files
authored
GH-111537: Avoid using this_instr in asserts. (GH-111600)
1 parent b14e882 commit 5697fc2

File tree

2 files changed

+24
-36
lines changed

2 files changed

+24
-36
lines changed

Python/bytecodes.c

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -669,8 +669,7 @@ dummy_func(
669669
STACK_SHRINK(2);
670670
new_frame->localsplus[0] = container;
671671
new_frame->localsplus[1] = sub;
672-
assert(1 + INLINE_CACHE_ENTRIES_BINARY_SUBSCR == next_instr - this_instr);
673-
frame->return_offset = 1 + INLINE_CACHE_ENTRIES_BINARY_SUBSCR;
672+
frame->return_offset = (uint16_t)(next_instr - this_instr);
674673
DISPATCH_INLINED(new_frame);
675674
}
676675

@@ -1000,8 +999,8 @@ dummy_func(
1000999
gen->gi_frame_state = FRAME_EXECUTING;
10011000
gen->gi_exc_state.previous_item = tstate->exc_info;
10021001
tstate->exc_info = &gen->gi_exc_state;
1003-
assert(1 + INLINE_CACHE_ENTRIES_SEND == next_instr - this_instr);
1004-
frame->return_offset = (uint16_t)(1 + INLINE_CACHE_ENTRIES_SEND + oparg);
1002+
assert(next_instr - this_instr + oparg <= UINT16_MAX);
1003+
frame->return_offset = (uint16_t)(next_instr - this_instr + oparg);
10051004
DISPATCH_INLINED(gen_frame);
10061005
}
10071006
if (Py_IsNone(v) && PyIter_Check(receiver)) {
@@ -1040,8 +1039,8 @@ dummy_func(
10401039
gen->gi_frame_state = FRAME_EXECUTING;
10411040
gen->gi_exc_state.previous_item = tstate->exc_info;
10421041
tstate->exc_info = &gen->gi_exc_state;
1043-
assert(1 + INLINE_CACHE_ENTRIES_SEND == next_instr - this_instr);
1044-
frame->return_offset = (uint16_t)(1 + INLINE_CACHE_ENTRIES_SEND + oparg);
1042+
assert(next_instr - this_instr + oparg <= UINT16_MAX);
1043+
frame->return_offset = (uint16_t)(next_instr - this_instr + oparg);
10451044
DISPATCH_INLINED(gen_frame);
10461045
}
10471046

@@ -2061,8 +2060,7 @@ dummy_func(
20612060
// Manipulate stack directly because we exit with DISPATCH_INLINED().
20622061
STACK_SHRINK(1);
20632062
new_frame->localsplus[0] = owner;
2064-
assert(1 + INLINE_CACHE_ENTRIES_LOAD_ATTR == next_instr - this_instr);
2065-
frame->return_offset = 1 + INLINE_CACHE_ENTRIES_LOAD_ATTR;
2063+
frame->return_offset = (uint16_t)(next_instr - this_instr);
20662064
DISPATCH_INLINED(new_frame);
20672065
}
20682066

@@ -2088,8 +2086,7 @@ dummy_func(
20882086
STACK_SHRINK(1);
20892087
new_frame->localsplus[0] = owner;
20902088
new_frame->localsplus[1] = Py_NewRef(name);
2091-
assert(1 + INLINE_CACHE_ENTRIES_LOAD_ATTR == next_instr - this_instr);
2092-
frame->return_offset = 1 + INLINE_CACHE_ENTRIES_LOAD_ATTR;
2089+
frame->return_offset = (uint16_t)(next_instr - this_instr);
20932090
DISPATCH_INLINED(new_frame);
20942091
}
20952092

@@ -2732,8 +2729,8 @@ dummy_func(
27322729
tstate->exc_info = &gen->gi_exc_state;
27332730
assert(next_instr[oparg].op.code == END_FOR ||
27342731
next_instr[oparg].op.code == INSTRUMENTED_END_FOR);
2735-
assert(1 + INLINE_CACHE_ENTRIES_FOR_ITER == next_instr - this_instr);
2736-
frame->return_offset = (uint16_t)(1 + INLINE_CACHE_ENTRIES_FOR_ITER + oparg);
2732+
assert(next_instr - this_instr + oparg <= UINT16_MAX);
2733+
frame->return_offset = (uint16_t)(next_instr - this_instr + oparg);
27372734
DISPATCH_INLINED(gen_frame);
27382735
}
27392736

@@ -3046,8 +3043,7 @@ dummy_func(
30463043
if (new_frame == NULL) {
30473044
goto error;
30483045
}
3049-
assert(1 + INLINE_CACHE_ENTRIES_CALL == next_instr - this_instr);
3050-
frame->return_offset = 1 + INLINE_CACHE_ENTRIES_CALL;
3046+
frame->return_offset = (uint16_t)(next_instr - this_instr);
30513047
DISPATCH_INLINED(new_frame);
30523048
}
30533049
/* Callable is not a normal Python function */
@@ -3202,8 +3198,7 @@ dummy_func(
32023198
}
32033199
// Manipulate stack and cache directly since we leave using DISPATCH_INLINED().
32043200
STACK_SHRINK(oparg + 2);
3205-
assert(1 + INLINE_CACHE_ENTRIES_CALL == next_instr - this_instr);
3206-
frame->return_offset = 1 + INLINE_CACHE_ENTRIES_CALL;
3201+
frame->return_offset = (uint16_t)(next_instr - this_instr);
32073202
DISPATCH_INLINED(new_frame);
32083203
}
32093204

@@ -3279,8 +3274,7 @@ dummy_func(
32793274
for (int i = 0; i < oparg; i++) {
32803275
init_frame->localsplus[i+1] = args[i];
32813276
}
3282-
assert(1 + INLINE_CACHE_ENTRIES_CALL == next_instr - this_instr);
3283-
frame->return_offset = 1 + INLINE_CACHE_ENTRIES_CALL;
3277+
frame->return_offset = (uint16_t)(next_instr - this_instr);
32843278
STACK_SHRINK(oparg+2);
32853279
_PyFrame_SetStackPointer(frame, stack_pointer);
32863280
/* Link frames */

Python/generated_cases.c.h

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

0 commit comments

Comments
 (0)