Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/librustc/mir/interpret/allocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@ pub trait AllocationExtra<Tag>: ::std::fmt::Debug + Default + Clone {
) -> EvalResult<'tcx> {
Ok(())
}

/// Hook for performing extra checks on a memory deallocation.
/// `size` will be the size of the allocation.
#[inline]
fn memory_deallocated(
_alloc: &mut Allocation<Tag, Self>,
_ptr: Pointer<Tag>,
_size: Size,
) -> EvalResult<'tcx> {
Ok(())
}
}

impl AllocationExtra<()> for () {}
Expand Down
12 changes: 1 addition & 11 deletions src/librustc_mir/interpret/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::hash::Hash;

use rustc::hir::{self, def_id::DefId};
use rustc::mir;
use rustc::ty::{self, layout::{Size, TyLayout}, query::TyCtxtAt};
use rustc::ty::{self, layout::TyLayout, query::TyCtxtAt};

use super::{
Allocation, AllocId, EvalResult, Scalar, AllocationExtra,
Expand Down Expand Up @@ -174,16 +174,6 @@ pub trait Machine<'a, 'mir, 'tcx>: Sized {
dest: PlaceTy<'tcx, Self::PointerTag>,
) -> EvalResult<'tcx>;

/// Hook for performing extra checks when memory gets deallocated.
#[inline]
fn memory_deallocated(
_alloc: &mut Allocation<Self::PointerTag, Self::AllocExtra>,
_ptr: Pointer<Self::PointerTag>,
_size: Size,
) -> EvalResult<'tcx> {
Ok(())
}

/// Add the tag for a newly allocated pointer.
fn tag_new_allocation(
ecx: &mut EvalContext<'a, 'mir, 'tcx, Self>,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/interpret/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {

// Let the machine take some extra action
let size = Size::from_bytes(alloc.bytes.len() as u64);
M::memory_deallocated(&mut alloc, ptr, size)?;
AllocationExtra::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