Skip to content

Commit 6430c63

Browse files
gh-132758: Fix tail call and pystats builds (GH-132759)
1 parent de9deb7 commit 6430c63

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix building with tail call interpreter and pystats.

Python/ceval.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,11 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
10711071
monitor_throw(tstate, frame, next_instr);
10721072
stack_pointer = _PyFrame_GetStackPointer(frame);
10731073
#if Py_TAIL_CALL_INTERP
1074-
return _TAIL_CALL_error(frame, stack_pointer, tstate, next_instr, 0);
1074+
# if Py_STATS
1075+
return _TAIL_CALL_error(frame, stack_pointer, tstate, next_instr, 0, lastopcode);
1076+
# else
1077+
return _TAIL_CALL_error(frame, stack_pointer, tstate, next_instr, 0);
1078+
# endif
10751079
#else
10761080
goto error;
10771081
#endif
@@ -1083,7 +1087,11 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
10831087
const _PyUOpInstruction *next_uop = NULL;
10841088
#endif
10851089
#if Py_TAIL_CALL_INTERP
1086-
return _TAIL_CALL_start_frame(frame, NULL, tstate, NULL, 0);
1090+
# if Py_STATS
1091+
return _TAIL_CALL_start_frame(frame, NULL, tstate, NULL, 0, lastopcode);
1092+
# else
1093+
return _TAIL_CALL_start_frame(frame, NULL, tstate, NULL, 0);
1094+
# endif
10871095
#else
10881096
goto start_frame;
10891097
# include "generated_cases.c.h"

Python/ceval_macros.h

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,13 @@
7070
#define INSTRUCTION_STATS(op) ((void)0)
7171
#endif
7272

73-
#define TAIL_CALL_PARAMS _PyInterpreterFrame *frame, _PyStackRef *stack_pointer, PyThreadState *tstate, _Py_CODEUNIT *next_instr, int oparg
74-
#define TAIL_CALL_ARGS frame, stack_pointer, tstate, next_instr, oparg
73+
#ifdef Py_STATS
74+
# define TAIL_CALL_PARAMS _PyInterpreterFrame *frame, _PyStackRef *stack_pointer, PyThreadState *tstate, _Py_CODEUNIT *next_instr, int oparg, int lastopcode
75+
# define TAIL_CALL_ARGS frame, stack_pointer, tstate, next_instr, oparg, lastopcode
76+
#else
77+
# define TAIL_CALL_PARAMS _PyInterpreterFrame *frame, _PyStackRef *stack_pointer, PyThreadState *tstate, _Py_CODEUNIT *next_instr, int oparg
78+
# define TAIL_CALL_ARGS frame, stack_pointer, tstate, next_instr, oparg
79+
#endif
7580

7681
#if Py_TAIL_CALL_INTERP
7782
// Note: [[clang::musttail]] works for GCC 15, but not __attribute__((musttail)) at the moment.
@@ -88,10 +93,17 @@
8893
do { \
8994
Py_MUSTTAIL return (_TAIL_CALL_##name)(TAIL_CALL_ARGS); \
9095
} while (0)
91-
# define JUMP_TO_PREDICTED(name) \
92-
do { \
93-
Py_MUSTTAIL return (_TAIL_CALL_##name)(frame, stack_pointer, tstate, this_instr, oparg); \
94-
} while (0)
96+
# ifdef Py_STATS
97+
# define JUMP_TO_PREDICTED(name) \
98+
do { \
99+
Py_MUSTTAIL return (_TAIL_CALL_##name)(frame, stack_pointer, tstate, this_instr, oparg, lastopcode); \
100+
} while (0)
101+
# else
102+
# define JUMP_TO_PREDICTED(name) \
103+
do { \
104+
Py_MUSTTAIL return (_TAIL_CALL_##name)(frame, stack_pointer, tstate, this_instr, oparg); \
105+
} while (0)
106+
# endif
95107
# define LABEL(name) TARGET(name)
96108
#elif USE_COMPUTED_GOTOS
97109
# define TARGET(op) TARGET_##op:

0 commit comments

Comments
 (0)