Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix
  • Loading branch information
corona10 committed Aug 27, 2025
commit 1d54d8701a460d26e1aebe45a8dba6a514dd3c9d
7 changes: 4 additions & 3 deletions Python/optimizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,8 @@ translate_bytecode_to_trace(
* Assumption: 67% reserved for trace, 33% for exit stubs
* TODO: Compute the required number of exit stubs dynamically
*/
int max_length = (buffer_size * 2) / 3;
int max_exit_stubs = (buffer_size * 33) / 100; // 33% for exit stubs
int max_length = buffer_size - 2 - max_exit_stubs;
struct {
PyFunctionObject *func;
PyCodeObject *code;
Expand Down Expand Up @@ -724,9 +725,9 @@ translate_bytecode_to_trace(
{
const struct opcode_macro_expansion *expansion = &_PyOpcode_macro_expansion[opcode];
if (expansion->nuops > 0) {
// Reserve space for nuops (+ _SET_IP + _EXIT_TRACE)
// Reserve space for nuops (exit stub space already pre-reserved)
int nuops = expansion->nuops;
RESERVE(nuops + 1); /* One extra for exit */
RESERVE(nuops);
int16_t last_op = expansion->uops[nuops-1].uop;
if (last_op == _RETURN_VALUE || last_op == _RETURN_GENERATOR || last_op == _YIELD_VALUE) {
// Check for trace stack underflow now:
Expand Down
Loading