Skip to content

Commit

Permalink
Fix parameter order for allocator
Browse files Browse the repository at this point in the history
  • Loading branch information
TimDiekmann committed Apr 20, 2021
1 parent 8293713 commit fba9038
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
14 changes: 7 additions & 7 deletions library/alloc/src/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,12 @@ use crate::vec::Vec;
#[cfg(test)]
mod tests;

struct RcBoxMetadata {
struct RcMetadata {
strong: Cell<usize>,
weak: Cell<usize>,
}

impl RcBoxMetadata {
impl RcMetadata {
// There is an implicit weak pointer owned by all the strong
// pointers, which ensures that the weak destructor never frees
// the allocation while the strong destructor is running, even
Expand All @@ -300,7 +300,7 @@ impl RcBoxMetadata {
// inner types.
#[repr(C)]
struct RcBox<T: ?Sized> {
meta: RcBoxMetadata,
meta: RcMetadata,
value: T,
}

Expand Down Expand Up @@ -363,7 +363,7 @@ impl<T> Rc<T> {
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn new(value: T) -> Rc<T> {
Self::from_inner(Box::leak(box RcBox { meta: RcBoxMetadata::new_strong(), value }).into())
Self::from_inner(Box::leak(box RcBox { meta: RcMetadata::new_strong(), value }).into())
}

/// Constructs a new `Rc<T>` using a weak reference to itself. Attempting
Expand Down Expand Up @@ -395,7 +395,7 @@ impl<T> Rc<T> {
// Construct the inner in the "uninitialized" state with a single
// weak reference.
let uninit_ptr: NonNull<_> = Box::leak(box RcBox {
meta: RcBoxMetadata::new_weak(),
meta: RcMetadata::new_weak(),
value: mem::MaybeUninit::<T>::uninit(),
})
.into();
Expand Down Expand Up @@ -510,7 +510,7 @@ impl<T> Rc<T> {
// the allocation while the strong destructor is running, even
// if the weak pointer is stored inside the strong one.
Ok(Self::from_inner(
Box::leak(Box::try_new(RcBox { meta: RcBoxMetadata::new_strong(), value })?).into(),
Box::leak(Box::try_new(RcBox { meta: RcMetadata::new_strong(), value })?).into(),
))
}

Expand Down Expand Up @@ -2479,7 +2479,7 @@ impl<T: ?Sized> AsRef<T> for Rc<T> {
#[stable(feature = "pin", since = "1.33.0")]
impl<T: ?Sized> Unpin for Rc<T> {}

type RcAllocator = PrefixAllocator<RcBoxMetadata, Global>;
type RcAllocator = PrefixAllocator<Global, RcMetadata>;

/// Get the offset within an `RcBox` for the payload behind a pointer.
///
Expand Down
14 changes: 7 additions & 7 deletions library/alloc/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ impl<T: ?Sized + fmt::Debug> fmt::Debug for Weak<T> {
}
}

struct ArcInnerMetadata {
struct ArcMetadata {
strong: atomic::AtomicUsize,

// the value usize::MAX acts as a sentinel for temporarily "locking" the
Expand All @@ -306,7 +306,7 @@ struct ArcInnerMetadata {
weak: atomic::AtomicUsize,
}

impl ArcInnerMetadata {
impl ArcMetadata {
#[inline]
fn new_strong() -> Self {
Self { strong: atomic::AtomicUsize::new(1), weak: atomic::AtomicUsize::new(1) }
Expand All @@ -323,7 +323,7 @@ impl ArcInnerMetadata {
// inner types.
#[repr(C)]
struct ArcInner<T: ?Sized> {
meta: ArcInnerMetadata,
meta: ArcMetadata,
data: T,
}

Expand All @@ -343,7 +343,7 @@ impl<T> Arc<T> {
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn new(data: T) -> Arc<T> {
let x: Box<_> = box ArcInner { meta: ArcInnerMetadata::new_strong(), data };
let x: Box<_> = box ArcInner { meta: ArcMetadata::new_strong(), data };
Self::from_inner(Box::leak(x).into())
}

Expand Down Expand Up @@ -373,7 +373,7 @@ impl<T> Arc<T> {
// Construct the inner in the "uninitialized" state with a single
// weak reference.
let uninit_ptr: NonNull<_> = Box::leak(box ArcInner {
meta: ArcInnerMetadata::new_weak(),
meta: ArcMetadata::new_weak(),
data: mem::MaybeUninit::<T>::uninit(),
})
.into();
Expand Down Expand Up @@ -503,7 +503,7 @@ impl<T> Arc<T> {
#[unstable(feature = "allocator_api", issue = "32838")]
#[inline]
pub fn try_new(data: T) -> Result<Arc<T>, AllocError> {
let x: Box<_> = Box::try_new(ArcInner { meta: ArcInnerMetadata::new_strong(), data })?;
let x: Box<_> = Box::try_new(ArcInner { meta: ArcMetadata::new_strong(), data })?;
Ok(Self::from_inner(Box::leak(x).into()))
}

Expand Down Expand Up @@ -2521,7 +2521,7 @@ impl<T: ?Sized> AsRef<T> for Arc<T> {
#[stable(feature = "pin", since = "1.33.0")]
impl<T: ?Sized> Unpin for Arc<T> {}

type ArcAllocator = PrefixAllocator<ArcInnerMetadata, Global>;
type ArcAllocator = PrefixAllocator<Global, ArcMetadata>;

/// Get the offset within an `ArcInner` for the payload behind a pointer.
///
Expand Down

0 comments on commit fba9038

Please sign in to comment.