Skip to content

Commit

Permalink
the memory_deallocated hook can make good use of knowing the size
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Oct 29, 2018
1 parent 2a5eae3 commit d10304e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/librustc_mir/interpret/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ pub trait Machine<'a, 'mir, 'tcx>: Sized {
fn memory_deallocated(
_alloc: &mut Allocation<Self::PointerTag, Self::AllocExtra>,
_ptr: Pointer<Self::PointerTag>,
_size: Size,
) -> EvalResult<'tcx> {
Ok(())
}
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_mir/interpret/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
}

// Let the machine take some extra action
M::memory_deallocated(&mut alloc, ptr)?;
let size = Size::from_bytes(alloc.bytes.len() as u64);
M::memory_deallocated(&mut alloc, ptr, size)?;

// Don't forget to remember size and align of this now-dead allocation
let old = self.dead_alloc_map.insert(
Expand Down

0 comments on commit d10304e

Please sign in to comment.