From bd9855941c0ff4c877180d2a5fba4f073710fd5b Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Sun, 7 Aug 2022 15:56:18 -0700 Subject: Fix an infinite loop in the garbage collector. --- bytecode/src/heap.rs | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'bytecode/src/heap.rs') diff --git a/bytecode/src/heap.rs b/bytecode/src/heap.rs index d32283e..d047d5a 100644 --- a/bytecode/src/heap.rs +++ b/bytecode/src/heap.rs @@ -7,11 +7,10 @@ fn rewrite_pointers( rewrites: &HashMap, ) -> Result<(), String> { for val in stack.iter_mut() { - let p = match val.to_pointer() { - Ok(p) => p, - Err(_) => { - continue; - } + let p = if val.is_pointer() { + val.to_pointer().unwrap() + } else { + continue; }; let Pointer(u) = p; *val = Value::from_pointer( @@ -68,11 +67,10 @@ impl Heap { spare_heap_ptr: &mut usize, rewrites: &mut HashMap, ) -> Result<(), String> { - let p = match val.to_pointer() { - Ok(p) => p, - Err(_) => { - return Ok(()); - } + let p = if val.is_pointer() { + val.to_pointer().unwrap() + } else { + return Ok(()); }; if rewrites.contains_key(&p) { // Already copied this one. @@ -128,11 +126,10 @@ impl Heap { for j in (i..i + self.alloc_size(p)?).step_by(8) { let q = Pointer(j); let val = self.peek(q)?; - let vp = match val.to_pointer() { - Ok(x) => x, - Err(_) => { - continue; - } + let vp = if val.is_pointer() { + val.to_pointer().unwrap() + } else { + continue; }; let Pointer(u) = vp; self.poke( @@ -144,6 +141,7 @@ impl Heap { q, )?; } + i += self.alloc_size(p)?; } self.last_reachable_cells = spare_heap_ptr; // Done?? -- cgit v1.3.1