Skip to content
Open
Changes from all commits
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
9 changes: 7 additions & 2 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ impl AllocationContext {
#[allow(dyn_drop)]
pub fn as_ptr<T>(&mut self, value: T) -> *const T {
let ptr = Box::into_raw(Box::new(value));
self.allocations.push(ptr as *const dyn Droppable);
// Safety: We extend the lifetime of the object type from some anonymous lifetime that `T`
// outlives, to `'static`. I don't know if this is sound or not.
let transmuted_ptr = unsafe {
std::mem::transmute::<*mut (dyn Droppable + '_), *const (dyn Droppable + 'static)>(ptr)
};
self.allocations.push(transmuted_ptr)
ptr
}

Expand Down Expand Up @@ -111,4 +116,4 @@ impl<'a, 'b> Drop for OwnedEvaluationContext<'a, 'b> {
self.sexps.drain(..).for_each(|ptr| unsafe { drop(Box::from_raw(ptr as *mut Sexp<'a>)); });
unsafe { self.allocations.drop() }
}
}
}