Skip to content

Commit

Permalink
extend comments
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed May 24, 2024
1 parent 1b374df commit b84620f
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/tools/miri/src/alloc_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ pub struct MiriAllocBytes {
layout: alloc::Layout,
/// Pointer to the allocation contents.
/// Invariant:
/// * If `self.layout.size() == 0`, then `self.ptr` is some suitably aligned pointer
/// that was allocated with the same layout but `size == 1`.
/// * If `self.layout.size() == 0`, then `self.ptr` was allocated with the equivalent layout with size 1.
/// * Otherwise, `self.ptr` points to memory allocated with `self.layout`.
ptr: *mut u8,
}
Expand All @@ -30,6 +29,8 @@ impl Clone for MiriAllocBytes {

impl Drop for MiriAllocBytes {
fn drop(&mut self) {
// We have to reconstruct the actual layout used for allocation.
// (`Deref` relies on `size` so we can't just always set it to at least 1.)
let alloc_layout = if self.layout.size() == 0 {
Layout::from_size_align(1, self.layout.align()).unwrap()
} else {
Expand Down

0 comments on commit b84620f

Please sign in to comment.