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
Next Next commit
Remove unsafe ctx cast in make_class
Use Context::genesis() directly in make_class to obtain
&'static Context, eliminating the raw pointer cast.
  • Loading branch information
youknowone committed Mar 3, 2026
commit a16cd83ff2a9da3f9f4fc6d1be6ffc6c4f08d85c
6 changes: 2 additions & 4 deletions crates/vm/src/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,10 @@ pub trait PyClassImpl: PyClassDef {
where
Self: StaticType + Sized,
{
let _ = ctx; // only used to ensure Context is initialized
(*Self::static_cell().get_or_init(|| {
let typ = Self::create_static_type();
// SAFETY: Context is heap-allocated via PyRc and stored in a static cell
// (Context::genesis), so it lives for 'static.
let ctx: &'static Context = unsafe { &*(ctx as *const Context) };
Self::extend_class(ctx, unsafe {
Self::extend_class(Context::genesis(), unsafe {
// typ will be saved in static_cell
let r: &Py<PyType> = &typ;
let r: &'static Py<PyType> = core::mem::transmute(r);
Expand Down