Skip to content

Commit

Permalink
Merge pull request Manishearth#146 from andersk/set_data_ptr
Browse files Browse the repository at this point in the history
Use set_data_ptr in Gc::set_root and clear_root_bit
  • Loading branch information
Manishearth authored Jul 6, 2022
2 parents 0278c6b + 64c1ebb commit 3edb400
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions gc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,8 @@ impl<T: Trace + ?Sized> Gc<T> {

/// Returns the given pointer with its root bit cleared.
unsafe fn clear_root_bit<T: ?Sized + Trace>(ptr: NonNull<GcBox<T>>) -> NonNull<GcBox<T>> {
let mut ptr = ptr.as_ptr();
*(&mut ptr as *mut _ as *mut usize) &= !1;
// *(&mut ptr as *mut *const GcBox<T> as *mut usize) &= !1;
let ptr = ptr.as_ptr();
let ptr = set_data_ptr(ptr, (ptr as *mut u8 as usize & !1) as *mut u8);
NonNull::new_unchecked(ptr)
}

Expand All @@ -112,8 +111,8 @@ impl<T: Trace + ?Sized> Gc<T> {
}

unsafe fn set_root(&self) {
let mut ptr = self.ptr_root.get().as_ptr();
*(&mut ptr as *mut *mut GcBox<T> as *mut usize) |= 1;
let ptr = self.ptr_root.get().as_ptr();
let ptr = set_data_ptr(ptr, (ptr as *mut u8 as usize | 1) as *mut u8);
self.ptr_root.set(NonNull::new_unchecked(ptr));
}

Expand Down

0 comments on commit 3edb400

Please sign in to comment.