Skip to content

Commit 1d54d87

Browse files
committed
fix
1 parent 18a8161 commit 1d54d87

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

Python/optimizer.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,8 @@ translate_bytecode_to_trace(
564564
* Assumption: 67% reserved for trace, 33% for exit stubs
565565
* TODO: Compute the required number of exit stubs dynamically
566566
*/
567-
int max_length = (buffer_size * 2) / 3;
567+
int max_exit_stubs = (buffer_size * 33) / 100; // 33% for exit stubs
568+
int max_length = buffer_size - 2 - max_exit_stubs;
568569
struct {
569570
PyFunctionObject *func;
570571
PyCodeObject *code;
@@ -724,9 +725,9 @@ translate_bytecode_to_trace(
724725
{
725726
const struct opcode_macro_expansion *expansion = &_PyOpcode_macro_expansion[opcode];
726727
if (expansion->nuops > 0) {
727-
// Reserve space for nuops (+ _SET_IP + _EXIT_TRACE)
728+
// Reserve space for nuops (exit stub space already pre-reserved)
728729
int nuops = expansion->nuops;
729-
RESERVE(nuops + 1); /* One extra for exit */
730+
RESERVE(nuops);
730731
int16_t last_op = expansion->uops[nuops-1].uop;
731732
if (last_op == _RETURN_VALUE || last_op == _RETURN_GENERATOR || last_op == _YIELD_VALUE) {
732733
// Check for trace stack underflow now:

0 commit comments

Comments
 (0)