Skip to content

Commit c42e170

Browse files
committed
add documents
1 parent d458a44 commit c42e170

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

‎vm/src/object/core.rs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,10 @@ impl PyObject {
647647
}
648648

649649
pub fn set_class(&self, typ: PyTypeRef, vm: &VirtualMachine) {
650-
self.0.typ.swap_to_frame(typ, vm);
650+
let old = unsafe { self.0.typ.swap(typ) };
651+
if let Some(frame) = vm.current_frame() {
652+
frame.temperary_refs.lock().push(old.into());
653+
}
651654
}
652655

653656
#[inline(always)]

‎vm/src/object/ext.rs‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -250,18 +250,15 @@ impl<T: PyObjectPayload> Deref for PyAtomicRef<T> {
250250
}
251251

252252
impl<T: PyObjectPayload> PyAtomicRef<T> {
253-
unsafe fn swap(&self, pyref: PyRef<T>) -> PyRef<T> {
253+
/// # Safety
254+
/// The caller is responsible to keep the returned PyRef alive
255+
/// until no more reference can be used via PyAtomicRef::deref()
256+
#[must_use]
257+
pub unsafe fn swap(&self, pyref: PyRef<T>) -> PyRef<T> {
254258
let py = PyRef::leak(pyref);
255259
let old = self.0.swap(NonNull::from(py));
256260
PyRef::from_raw(old.as_ptr())
257261
}
258-
259-
pub fn swap_to_frame(&self, pyref: PyRef<T>, vm: &VirtualMachine) {
260-
let old = unsafe { self.swap(pyref) };
261-
if let Some(frame) = vm.current_frame() {
262-
frame.temperary_refs.lock().push(old.into());
263-
}
264-
}
265262
}
266263

267264
pub trait AsObject

0 commit comments

Comments
 (0)