Skip to content
Merged
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
Tighten CALL_ALLOC_AND_ENTER_INIT stack-space guard
  • Loading branch information
youknowone committed Mar 10, 2026
commit fc4728bbe16e9385521dd662244e06606d35a49f
16 changes: 12 additions & 4 deletions crates/vm/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4704,10 +4704,18 @@ impl ExecutingFrame<'_> {
&& let Some(init_func) = cls.get_cached_init_for_specialization(cached_version)
&& let Some(cls_alloc) = cls.slots.alloc.load()
{
// co_framesize + _Py_InitCleanup.co_framesize guard.
// We do not materialize frame-specials on datastack, so use
// only the cleanup shim's eval-stack payload (2 stack slots).
const INIT_CLEANUP_STACK_BYTES: usize = 2 * core::mem::size_of::<usize>();
// CPython guard is:
// code->co_framesize + _Py_InitCleanup.co_framesize
// and _Py_InitCleanup.co_framesize is defined as:
// 2 + FRAME_SPECIALS_SIZE
// (see cpython/Python/specialize.c).
//
// RustPython datastack stores localsplus payload only, but we
// keep the guard conservative and CPython-shaped by accounting
// for the full cleanup frame size.
const CPYTHON_INIT_CLEANUP_CO_FRAMESIZE_SLOTS: usize = 11;
const INIT_CLEANUP_STACK_BYTES: usize =
CPYTHON_INIT_CLEANUP_CO_FRAMESIZE_SLOTS * core::mem::size_of::<usize>();
if !self.specialization_has_datastack_space_for_func_with_extra(
vm,
&init_func,
Expand Down