From 64c1ebb5e5a9f42e3e138c6c4599a0d895a45ee4 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Wed, 6 Jul 2022 15:25:44 -0700 Subject: [PATCH] Use set_data_ptr in Gc::set_root and clear_root_bit Fixes #145. Signed-off-by: Anders Kaseorg --- gc/src/lib.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/gc/src/lib.rs b/gc/src/lib.rs index 3dc541c..dd469fa 100644 --- a/gc/src/lib.rs +++ b/gc/src/lib.rs @@ -100,9 +100,8 @@ impl Gc { /// Returns the given pointer with its root bit cleared. unsafe fn clear_root_bit(ptr: NonNull>) -> NonNull> { - let mut ptr = ptr.as_ptr(); - *(&mut ptr as *mut _ as *mut usize) &= !1; - // *(&mut ptr as *mut *const GcBox 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) } @@ -112,8 +111,8 @@ impl Gc { } unsafe fn set_root(&self) { - let mut ptr = self.ptr_root.get().as_ptr(); - *(&mut ptr as *mut *mut GcBox 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)); }