Skip to content

Commit

Permalink
split out cold error parts
Browse files Browse the repository at this point in the history
  • Loading branch information
Fidget-Spinner committed Jan 5, 2025
1 parent c120a98 commit 6f753da
Show file tree
Hide file tree
Showing 5 changed files with 8,508 additions and 30,641 deletions.
16 changes: 10 additions & 6 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,7 @@ dummy_func(
if (err) {
assert(oparg == 0);
monitor_reraise(tstate, frame, this_instr);
goto exception_unwind;
CEVAL_GOTO(exception_unwind);
}
ERROR_IF(true, error);
}
Expand Down Expand Up @@ -1282,7 +1282,7 @@ dummy_func(
assert(exc && PyExceptionInstance_Check(exc));
_PyErr_SetRaisedException(tstate, exc);
monitor_reraise(tstate, frame, this_instr);
goto exception_unwind;
CEVAL_GOTO(exception_unwind);
}

tier1 inst(END_ASYNC_FOR, (awaitable_st, exc_st -- )) {
Expand All @@ -1297,7 +1297,8 @@ dummy_func(
Py_INCREF(exc);
_PyErr_SetRaisedException(tstate, exc);
monitor_reraise(tstate, frame, this_instr);
goto exception_unwind;
INPUTS_DEAD();
CEVAL_GOTO(exception_unwind);
}
}

Expand All @@ -1315,7 +1316,10 @@ dummy_func(
else {
_PyErr_SetRaisedException(tstate, Py_NewRef(exc_value));
monitor_reraise(tstate, frame, this_instr);
goto exception_unwind;
INPUTS_DEAD();
none = PyStackRef_NULL;
value = PyStackRef_NULL;
CEVAL_GOTO(exception_unwind);
}
}

Expand Down Expand Up @@ -4003,7 +4007,7 @@ dummy_func(
PyObject *res_o = PyLong_FromSsize_t(len_i);
assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
if (res_o == NULL) {
GOTO_ERROR(error);
CEVAL_GOTO(error);
}
PyStackRef_CLOSE(callable[0]);
PyStackRef_CLOSE(arg_stackref);
Expand Down Expand Up @@ -4740,7 +4744,7 @@ dummy_func(
tstate, frame, this_instr, prev_instr);
if (original_opcode < 0) {
next_instr = this_instr+1;
goto error;
CEVAL_GOTO(error);
}
next_instr = frame->instr_ptr;
if (next_instr != this_instr) {
Expand Down
19 changes: 15 additions & 4 deletions Python/ceval_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,31 @@ typedef PyObject* (*py_tail_call_funcptr)(_PyInterpreterFrame *, _PyStackRef *,
__attribute__((musttail)) \
return (INSTRUCTION_TABLE[opcode])(frame, stack_pointer, tstate, next_instr, oparg, entry_frame, lltrace); \
} while (0)
#define CEVAL_GOTO(name) do { \
__attribute__((musttail)) \
return (_TAIL_CALL_##name)(frame, stack_pointer, tstate, next_instr, oparg, entry_frame, lltrace); \
} while (0)
#else
#define DISPATCH_GOTO() do { \
__attribute__((musttail)) \
return (INSTRUCTION_TABLE[opcode])(frame, stack_pointer, tstate, next_instr, oparg, entry_frame); \
} while (0)
#define CEVAL_GOTO(name) do { \
__attribute__((musttail)) \
return (_TAIL_CALL_##name)(frame, stack_pointer, tstate, next_instr, oparg, entry_frame); \
} while (0)
#endif
#elif USE_COMPUTED_GOTOS
# define TARGET(op) TARGET_##op:
# define DISPATCH_GOTO() goto *opcode_targets[opcode]
# define CEVAL_GOTO(name) goto name;
#else
# define TARGET(op) case op: TARGET_##op:
# define DISPATCH_GOTO() goto dispatch_opcode
# define CEVAL_GOTO(name) goto name;
#endif


/* PRE_DISPATCH_GOTO() does lltrace if enabled. Normally a no-op */
#ifdef LLTRACE
#define PRE_DISPATCH_GOTO() if (lltrace >= 5) { \
Expand All @@ -110,7 +121,7 @@ typedef PyObject* (*py_tail_call_funcptr)(_PyInterpreterFrame *, _PyStackRef *,
do { \
lltrace = maybe_lltrace_resume_frame(frame, entry_frame, GLOBALS()); \
if (lltrace < 0) { \
goto exit_unwind; \
CEVAL_GOTO(exit_unwind); \
} \
} while (0)
#else
Expand Down Expand Up @@ -150,13 +161,13 @@ do { \
frame = tstate->current_frame = (NEW_FRAME); \
CALL_STAT_INC(inlined_py_calls); \
if (_Py_EnterRecursivePy(tstate)) {\
goto exit_unwind;\
CEVAL_GOTO(exit_unwind);\
} \
next_instr = frame->instr_ptr; \
stack_pointer = _PyFrame_GetStackPointer(frame); \
lltrace = maybe_lltrace_resume_frame(frame, entry_frame, GLOBALS()); \
if (lltrace < 0) { \
goto exit_unwind; \
CEVAL_GOTO(exit_unwind); \
} \
NEXTOPARG(); \
__attribute__((musttail)) \
Expand Down Expand Up @@ -441,7 +452,7 @@ do { \
stack_pointer = _PyFrame_GetStackPointer(frame); \
if (next_instr == NULL) { \
next_instr = (dest)+1; \
goto error; \
CEVAL_GOTO(error); \
} \
} \
} while (0);
Expand Down
Loading

0 comments on commit 6f753da

Please sign in to comment.