Skip to content

Commit

Permalink
rename rcbox in other places as per review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jdonszelmann committed Oct 13, 2024
1 parent 34f7831 commit 089c495
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions alloc/src/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ struct RcInner<T: ?Sized> {
}

/// Calculate layout for `RcInner<T>` using the inner value's layout
fn rcbox_layout_for_value_layout(layout: Layout) -> Layout {
fn rc_inner_layout_for_value_layout(layout: Layout) -> Layout {
// Calculate layout using the given value layout.
// Previously, layout was calculated on the expression
// `&*(ptr as *const RcInner<T>)`, but this created a misaligned
Expand Down Expand Up @@ -2009,17 +2009,17 @@ impl<T: ?Sized> Rc<T> {
/// Allocates an `RcInner<T>` with sufficient space for
/// a possibly-unsized inner value where the value has the layout provided.
///
/// The function `mem_to_rcbox` is called with the data pointer
/// The function `mem_to_rc_inner` is called with the data pointer
/// and must return back a (potentially fat)-pointer for the `RcInner<T>`.
#[cfg(not(no_global_oom_handling))]
unsafe fn allocate_for_layout(
value_layout: Layout,
allocate: impl FnOnce(Layout) -> Result<NonNull<[u8]>, AllocError>,
mem_to_rcbox: impl FnOnce(*mut u8) -> *mut RcInner<T>,
mem_to_rc_inner: impl FnOnce(*mut u8) -> *mut RcInner<T>,
) -> *mut RcInner<T> {
let layout = rcbox_layout_for_value_layout(value_layout);
let layout = rc_inner_layout_for_value_layout(value_layout);
unsafe {
Rc::try_allocate_for_layout(value_layout, allocate, mem_to_rcbox)
Rc::try_allocate_for_layout(value_layout, allocate, mem_to_rc_inner)
.unwrap_or_else(|_| handle_alloc_error(layout))
}
}
Expand All @@ -2028,21 +2028,21 @@ impl<T: ?Sized> Rc<T> {
/// a possibly-unsized inner value where the value has the layout provided,
/// returning an error if allocation fails.
///
/// The function `mem_to_rcbox` is called with the data pointer
/// The function `mem_to_rc_inner` is called with the data pointer
/// and must return back a (potentially fat)-pointer for the `RcInner<T>`.
#[inline]
unsafe fn try_allocate_for_layout(
value_layout: Layout,
allocate: impl FnOnce(Layout) -> Result<NonNull<[u8]>, AllocError>,
mem_to_rcbox: impl FnOnce(*mut u8) -> *mut RcInner<T>,
mem_to_rc_inner: impl FnOnce(*mut u8) -> *mut RcInner<T>,
) -> Result<*mut RcInner<T>, AllocError> {
let layout = rcbox_layout_for_value_layout(value_layout);
let layout = rc_inner_layout_for_value_layout(value_layout);

// Allocate for the layout.
let ptr = allocate(layout)?;

// Initialize the RcInner
let inner = mem_to_rcbox(ptr.as_non_null_ptr().as_ptr());
let inner = mem_to_rc_inner(ptr.as_non_null_ptr().as_ptr());
unsafe {
debug_assert_eq!(Layout::for_value_raw(inner), layout);

Expand Down Expand Up @@ -3784,7 +3784,7 @@ impl<T: ?Sized, A: Allocator> UniqueRcUninit<T, A> {
let ptr = unsafe {
Rc::allocate_for_layout(
layout,
|layout_for_rcbox| alloc.allocate(layout_for_rcbox),
|layout_for_rc_inner| alloc.allocate(layout_for_rc_inner),
|mem| mem.with_metadata_of(ptr::from_ref(for_value) as *const RcInner<T>),
)
};
Expand Down Expand Up @@ -3820,10 +3820,10 @@ impl<T: ?Sized, A: Allocator> Drop for UniqueRcUninit<T, A> {
// * new() produced a pointer safe to deallocate.
// * We own the pointer unless into_rc() was called, which forgets us.
unsafe {
self.alloc
.take()
.unwrap()
.deallocate(self.ptr.cast(), rcbox_layout_for_value_layout(self.layout_for_value));
self.alloc.take().unwrap().deallocate(
self.ptr.cast(),
rc_inner_layout_for_value_layout(self.layout_for_value),
);
}
}
}

0 comments on commit 089c495

Please sign in to comment.