RawBlock: seal base and add Stack::index_dangling_or_frame

Direct accesses to `base` are replaced with dedicated methods with
explicit safety requirements.
This commit is contained in:
Emilie Burgun
2026-05-10 15:07:08 +02:00
parent 3c5818a040
commit 898b6b2b25
5 changed files with 105 additions and 28 deletions

View File

@@ -306,8 +306,7 @@ impl Atom {
AtomTableRef::try_map(atom_table.inner.read(), |buf| unsafe {
let ptr = buf
.block
.base
.add(self.flat_index() as usize - STRINGS.len());
.get_unchecked(self.flat_index() as usize - STRINGS.len());
// TODO use std::ptr::from_raw_parts instead when feature ptr_metadata is stable rust-lang/rust#81513
let atom_data = &*(std::ptr::slice_from_raw_parts(ptr, 0) as *const AtomData);
let len = atom_data.header.len();
@@ -520,12 +519,13 @@ impl AtomTable {
}
};
let ptr_base = block_epoch.block.base.addr();
// SAFETY: `len_ptr` was obtained from `block_epoch.block.alloc()`
let len_offset = block_epoch.block.get_offset(len_ptr);
write_to_ptr(string, len_ptr);
let atom = AtomCell::new()
.with_name((STRINGS.len() + len_ptr.addr() - ptr_base) as u64)
.with_name((STRINGS.len() + len_offset) as u64)
.with_arity(0)
.with_f(false)
.with_m(false)