Skip to content

Commit

Permalink
Make grow_impl unsafe
Browse files Browse the repository at this point in the history
  • Loading branch information
TimDiekmann committed Aug 18, 2020
1 parent 66a6512 commit 63d241a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
9 changes: 6 additions & 3 deletions library/alloc/src/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,9 @@ impl Global {
}
}

// Safety: Same as `AllocRef::grow`
#[inline]
fn grow_impl(
unsafe fn grow_impl(
&mut self,
ptr: NonNull<u8>,
layout: Layout,
Expand Down Expand Up @@ -241,7 +242,8 @@ unsafe impl AllocRef for Global {
layout: Layout,
new_size: usize,
) -> Result<NonNull<[u8]>, AllocErr> {
self.grow_impl(ptr, layout, new_size, false)
// SAFETY: all conditions must be upheld by the caller
unsafe { self.grow_impl(ptr, layout, new_size, false) }
}

#[inline]
Expand All @@ -251,7 +253,8 @@ unsafe impl AllocRef for Global {
layout: Layout,
new_size: usize,
) -> Result<NonNull<[u8]>, AllocErr> {
self.grow_impl(ptr, layout, new_size, true)
// SAFETY: all conditions must be upheld by the caller
unsafe { self.grow_impl(ptr, layout, new_size, true) }
}

#[inline]
Expand Down
9 changes: 6 additions & 3 deletions library/std/src/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,9 @@ impl System {
}
}

// Safety: Same as `AllocRef::grow`
#[inline]
fn grow_impl(
unsafe fn grow_impl(
&mut self,
ptr: NonNull<u8>,
layout: Layout,
Expand Down Expand Up @@ -217,7 +218,8 @@ unsafe impl AllocRef for System {
layout: Layout,
new_size: usize,
) -> Result<NonNull<[u8]>, AllocErr> {
self.grow_impl(ptr, layout, new_size, false)
// SAFETY: all conditions must be upheld by the caller
unsafe { self.grow_impl(ptr, layout, new_size, false) }
}

#[inline]
Expand All @@ -227,7 +229,8 @@ unsafe impl AllocRef for System {
layout: Layout,
new_size: usize,
) -> Result<NonNull<[u8]>, AllocErr> {
self.grow_impl(ptr, layout, new_size, true)
// SAFETY: all conditions must be upheld by the caller
unsafe { self.grow_impl(ptr, layout, new_size, true) }
}

#[inline]
Expand Down

0 comments on commit 63d241a

Please sign in to comment.