Skip to content

Commit f83de62

Browse files
committed
Update for new Shared and NonZero API.
Changed in rust-lang/rust#41064 Fixes Manishearth#55
1 parent d8252ae commit f83de62

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

Diff for: gc/src/gc.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ impl Drop for GcState {
2727
{
2828
let mut p = &self.boxes_start;
2929
while let Some(node) = *p {
30-
Finalize::finalize(&(**node).data);
31-
p = &(**node).header.next;
30+
Finalize::finalize(&(*node.as_ptr()).data);
31+
p = &(*node.as_ptr()).header.next;
3232
}
3333
}
3434

3535
let _guard = DropGuard::new();
3636
while let Some(node) = self.boxes_start {
37-
let node = Box::from_raw(*node);
37+
let node = Box::from_raw(node.as_ptr());
3838
self.boxes_start = node.header.next;
3939
}
4040
}
@@ -162,39 +162,39 @@ fn collect_garbage(st: &mut GcState) {
162162
// Walk the tree, tracing and marking the nodes
163163
let mut mark_head = *head;
164164
while let Some(node) = mark_head {
165-
if (**node).header.roots.get() > 0 {
166-
(**node).trace_inner();
165+
if (*node.as_ptr()).header.roots.get() > 0 {
166+
(*node.as_ptr()).trace_inner();
167167
}
168168

169-
mark_head = (**node).header.next;
169+
mark_head = (*node.as_ptr()).header.next;
170170
}
171171

172172
// Collect a vector of all of the nodes which were not marked,
173173
// and unmark the ones which were.
174174
let mut unmarked = Vec::new();
175175
let mut unmark_head = head;
176176
while let Some(node) = *unmark_head {
177-
if (**node).header.marked.get() {
178-
(**node).header.marked.set(false);
177+
if (*node.as_ptr()).header.marked.get() {
178+
(*node.as_ptr()).header.marked.set(false);
179179
} else {
180180
unmarked.push(Unmarked {
181181
incoming: unmark_head,
182182
this: node,
183183
});
184184
}
185-
unmark_head = &mut (**node).header.next;
185+
unmark_head = &mut (*node.as_ptr()).header.next;
186186
}
187187
unmarked
188188
}
189189

190190
unsafe fn sweep(finalized: Vec<Unmarked>, bytes_allocated: &mut usize) {
191191
let _guard = DropGuard::new();
192192
for node in finalized.into_iter().rev() {
193-
if (**node.this).header.marked.get() {
193+
if (*node.this.as_ptr()).header.marked.get() {
194194
continue;
195195
}
196196
let incoming = node.incoming;
197-
let mut node = Box::from_raw(*node.this);
197+
let mut node = Box::from_raw(node.this.as_ptr());
198198
*bytes_allocated -= mem::size_of_val::<GcBox<_>>(&*node);
199199
*incoming = node.header.next.take();
200200
}
@@ -206,7 +206,7 @@ fn collect_garbage(st: &mut GcState) {
206206
return;
207207
}
208208
for node in &unmarked {
209-
Trace::finalize_glue(&(**node.this).data);
209+
Trace::finalize_glue(&(*node.this.as_ptr()).data);
210210
}
211211
mark(&mut st.boxes_start);
212212
sweep(unmarked, &mut st.bytes_allocated);

Diff for: gc/src/lib.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ impl<T: Trace> Gc<T> {
8383

8484
// When we create a Gc<T>, all pointers which have been moved to the
8585
// heap no longer need to be rooted, so we unroot them.
86-
(**ptr).value().unroot();
86+
(*ptr.as_ptr()).value().unroot();
8787
let gc = Gc {
88-
ptr_root: Cell::new(NonZero::new(*ptr)),
88+
ptr_root: Cell::new(NonZero::new(ptr.as_ptr())),
8989
marker: PhantomData,
9090
};
9191
gc.set_root();
@@ -97,18 +97,18 @@ impl<T: Trace> Gc<T> {
9797
/// Returns the given pointer with its root bit cleared.
9898
unsafe fn clear_root_bit<T: ?Sized + Trace>(ptr: NonZero<*const GcBox<T>>)
9999
-> NonZero<*const GcBox<T>> {
100-
let mut ptr = *ptr;
100+
let mut ptr = ptr.get();
101101
*(&mut ptr as *mut *const GcBox<T> as *mut usize) &= !1;
102102
NonZero::new(ptr)
103103
}
104104

105105
impl<T: Trace + ?Sized> Gc<T> {
106106
fn rooted(&self) -> bool {
107-
*self.ptr_root.get() as *const u8 as usize & 1 != 0
107+
self.ptr_root.get().get() as *const u8 as usize & 1 != 0
108108
}
109109

110110
unsafe fn set_root(&self) {
111-
let mut ptr = *self.ptr_root.get();
111+
let mut ptr = self.ptr_root.get().get();
112112
*(&mut ptr as *mut *const GcBox<T> as *mut usize) |= 1;
113113
self.ptr_root.set(NonZero::new(ptr));
114114
}
@@ -127,7 +127,7 @@ impl<T: Trace + ?Sized> Gc<T> {
127127
// This assert exists just in case.
128128
assert!(finalizer_safe());
129129

130-
unsafe { &**clear_root_bit(self.ptr_root.get()) }
130+
unsafe { &*clear_root_bit(self.ptr_root.get()).get() }
131131
}
132132
}
133133

0 commit comments

Comments
 (0)