Skip to content

Commit 32631e8

Browse files
refactor into own function
1 parent a1b0ff1 commit 32631e8

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

Python/optimizer_analysis.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,15 +187,27 @@ incorrect_keys(PyObject *obj, uint32_t version)
187187
#define sym_new_truthiness _Py_uop_sym_new_truthiness
188188

189189
#define JUMP_TO_LABEL(label) goto label;
190+
191+
static int
192+
check_stack_bounds(JitOptContext *ctx, JitOptRef *stack_pointer, int offset, int opcode)
193+
{
194+
int stack_level = (int)(stack_pointer + (offset) - ctx->frame->stack);
195+
int should_check = !CURRENT_FRAME_IS_INIT_SHIM() ||
196+
(opcode == _RETURN_VALUE) ||
197+
(opcode == _RETURN_GENERATOR) ||
198+
(opcode == _YIELD_VALUE);
199+
if (should_check && (stack_level < 0 || stack_level > STACK_SIZE())) {
200+
ctx->contradiction = true;
201+
ctx->done = true;
202+
return 1;
203+
}
204+
return 0;
205+
}
206+
190207
#define CHECK_STACK_BOUNDS(offset) \
191-
do { \
192-
int stack_level = (int)(stack_pointer + (offset) - ctx->frame->stack); \
193-
if (stack_level < 0 || stack_level > STACK_SIZE()) { \
194-
ctx->contradiction = true; \
195-
ctx->done = true; \
208+
if (check_stack_bounds(ctx, stack_pointer, offset, opcode)) { \
196209
break; \
197210
} \
198-
} while (0);
199211

200212
static int
201213
optimize_to_bool(

0 commit comments

Comments
 (0)