Skip to content

Commit 6f753da

Browse files
split out cold error parts
1 parent c120a98 commit 6f753da

File tree

5 files changed

+8508
-30641
lines changed

5 files changed

+8508
-30641
lines changed

Python/bytecodes.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ dummy_func(
10121012
if (err) {
10131013
assert(oparg == 0);
10141014
monitor_reraise(tstate, frame, this_instr);
1015-
goto exception_unwind;
1015+
CEVAL_GOTO(exception_unwind);
10161016
}
10171017
ERROR_IF(true, error);
10181018
}
@@ -1282,7 +1282,7 @@ dummy_func(
12821282
assert(exc && PyExceptionInstance_Check(exc));
12831283
_PyErr_SetRaisedException(tstate, exc);
12841284
monitor_reraise(tstate, frame, this_instr);
1285-
goto exception_unwind;
1285+
CEVAL_GOTO(exception_unwind);
12861286
}
12871287

12881288
tier1 inst(END_ASYNC_FOR, (awaitable_st, exc_st -- )) {
@@ -1297,7 +1297,8 @@ dummy_func(
12971297
Py_INCREF(exc);
12981298
_PyErr_SetRaisedException(tstate, exc);
12991299
monitor_reraise(tstate, frame, this_instr);
1300-
goto exception_unwind;
1300+
INPUTS_DEAD();
1301+
CEVAL_GOTO(exception_unwind);
13011302
}
13021303
}
13031304

@@ -1315,7 +1316,10 @@ dummy_func(
13151316
else {
13161317
_PyErr_SetRaisedException(tstate, Py_NewRef(exc_value));
13171318
monitor_reraise(tstate, frame, this_instr);
1318-
goto exception_unwind;
1319+
INPUTS_DEAD();
1320+
none = PyStackRef_NULL;
1321+
value = PyStackRef_NULL;
1322+
CEVAL_GOTO(exception_unwind);
13191323
}
13201324
}
13211325

@@ -4003,7 +4007,7 @@ dummy_func(
40034007
PyObject *res_o = PyLong_FromSsize_t(len_i);
40044008
assert((res_o != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
40054009
if (res_o == NULL) {
4006-
GOTO_ERROR(error);
4010+
CEVAL_GOTO(error);
40074011
}
40084012
PyStackRef_CLOSE(callable[0]);
40094013
PyStackRef_CLOSE(arg_stackref);
@@ -4740,7 +4744,7 @@ dummy_func(
47404744
tstate, frame, this_instr, prev_instr);
47414745
if (original_opcode < 0) {
47424746
next_instr = this_instr+1;
4743-
goto error;
4747+
CEVAL_GOTO(error);
47444748
}
47454749
next_instr = frame->instr_ptr;
47464750
if (next_instr != this_instr) {

Python/ceval_macros.h

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,20 +83,31 @@ typedef PyObject* (*py_tail_call_funcptr)(_PyInterpreterFrame *, _PyStackRef *,
8383
__attribute__((musttail)) \
8484
return (INSTRUCTION_TABLE[opcode])(frame, stack_pointer, tstate, next_instr, oparg, entry_frame, lltrace); \
8585
} while (0)
86+
#define CEVAL_GOTO(name) do { \
87+
__attribute__((musttail)) \
88+
return (_TAIL_CALL_##name)(frame, stack_pointer, tstate, next_instr, oparg, entry_frame, lltrace); \
89+
} while (0)
8690
#else
8791
#define DISPATCH_GOTO() do { \
8892
__attribute__((musttail)) \
8993
return (INSTRUCTION_TABLE[opcode])(frame, stack_pointer, tstate, next_instr, oparg, entry_frame); \
9094
} while (0)
95+
#define CEVAL_GOTO(name) do { \
96+
__attribute__((musttail)) \
97+
return (_TAIL_CALL_##name)(frame, stack_pointer, tstate, next_instr, oparg, entry_frame); \
98+
} while (0)
9199
#endif
92100
#elif USE_COMPUTED_GOTOS
93101
# define TARGET(op) TARGET_##op:
94102
# define DISPATCH_GOTO() goto *opcode_targets[opcode]
103+
# define CEVAL_GOTO(name) goto name;
95104
#else
96105
# define TARGET(op) case op: TARGET_##op:
97106
# define DISPATCH_GOTO() goto dispatch_opcode
107+
# define CEVAL_GOTO(name) goto name;
98108
#endif
99109

110+
100111
/* PRE_DISPATCH_GOTO() does lltrace if enabled. Normally a no-op */
101112
#ifdef LLTRACE
102113
#define PRE_DISPATCH_GOTO() if (lltrace >= 5) { \
@@ -110,7 +121,7 @@ typedef PyObject* (*py_tail_call_funcptr)(_PyInterpreterFrame *, _PyStackRef *,
110121
do { \
111122
lltrace = maybe_lltrace_resume_frame(frame, entry_frame, GLOBALS()); \
112123
if (lltrace < 0) { \
113-
goto exit_unwind; \
124+
CEVAL_GOTO(exit_unwind); \
114125
} \
115126
} while (0)
116127
#else
@@ -150,13 +161,13 @@ do { \
150161
frame = tstate->current_frame = (NEW_FRAME); \
151162
CALL_STAT_INC(inlined_py_calls); \
152163
if (_Py_EnterRecursivePy(tstate)) {\
153-
goto exit_unwind;\
164+
CEVAL_GOTO(exit_unwind);\
154165
} \
155166
next_instr = frame->instr_ptr; \
156167
stack_pointer = _PyFrame_GetStackPointer(frame); \
157168
lltrace = maybe_lltrace_resume_frame(frame, entry_frame, GLOBALS()); \
158169
if (lltrace < 0) { \
159-
goto exit_unwind; \
170+
CEVAL_GOTO(exit_unwind); \
160171
} \
161172
NEXTOPARG(); \
162173
__attribute__((musttail)) \
@@ -441,7 +452,7 @@ do { \
441452
stack_pointer = _PyFrame_GetStackPointer(frame); \
442453
if (next_instr == NULL) { \
443454
next_instr = (dest)+1; \
444-
goto error; \
455+
CEVAL_GOTO(error); \
445456
} \
446457
} \
447458
} while (0);

0 commit comments

Comments
 (0)