1
Fork 0

Stop unintentionally clearing source relocations when copying.

This commit is contained in:
Scott Olson 2016-03-20 20:15:13 -06:00
parent 493b5f649c
commit 2e12b220be

View file

@ -106,25 +106,25 @@ impl Memory {
}
pub fn copy(&mut self, src: Pointer, dest: Pointer, size: usize) -> EvalResult<()> {
let (src_bytes, relocations) = {
let (src_bytes, mut relocations) = {
let alloc = try!(self.get_mut(src.alloc_id));
try!(alloc.check_relocation_edges(src.offset, src.offset + size));
let bytes = alloc.bytes[src.offset..src.offset + size].as_mut_ptr();
let mut relocations: Vec<(usize, AllocId)> = alloc.relocations
let relocations: Vec<(usize, AllocId)> = alloc.relocations
.range(Included(&src.offset), Excluded(&(src.offset + size)))
.map(|(&k, &v)| (k, v))
.collect();
for &mut (ref mut offset, _) in &mut relocations {
alloc.relocations.remove(offset);
*offset += dest.offset;
*offset -= src.offset;
}
(bytes, relocations)
};
// Update relocation offsets for the new positions in the destination allocation.
for &mut (ref mut offset, _) in &mut relocations {
*offset += dest.offset;
*offset -= src.offset;
}
let dest_bytes = try!(self.get_bytes_mut(dest, size)).as_mut_ptr();
// TODO(tsion): Clear the destination range's existing relocations.