Skip to content

Commit 607ba69

Browse files
committed
fix(alloc): update a bunch of uses of ptr::Unique to use new API
API changed in rust-lang/rust#41064; see also the tracking issue rust-lang/rust#27730 for more information.
1 parent 0b7a514 commit 607ba69

File tree

3 files changed

+19
-17
lines changed

3 files changed

+19
-17
lines changed

alloc/src/borrow.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,16 @@ where A: Allocator
4646
impl<'alloc, A> Deref for BorrowedPtr<'alloc, A>
4747
where A: Allocator
4848
, A: 'alloc {
49-
type Target = Address;
50-
fn deref(&self) -> &Self::Target { &(*self.ptr) }
49+
type Target = Unique<u8>;
50+
fn deref(&self) -> &Self::Target { &self.ptr }
5151
}
5252

5353
impl<'alloc, A> Drop for BorrowedPtr<'alloc, A>
5454
where A: Allocator
5555
, A: 'alloc {
5656
fn drop(&mut self) {
5757
unsafe {
58-
self.allocator.lock().dealloc(*self.ptr, self.layout.clone())
58+
self.allocator.lock().dealloc(self.ptr.as_ptr(), self.layout.clone())
5959
}
6060
}
6161
}
@@ -91,14 +91,14 @@ impl<'alloc, A, T> Deref for Borrowed<'alloc, A, T>
9191
where A: Allocator
9292
, A: 'alloc {
9393
type Target = T;
94-
fn deref(&self) -> &Self::Target { unsafe { self.value.get() } }
94+
fn deref(&self) -> &Self::Target { unsafe { self.value.as_ref() } }
9595
}
9696

9797
impl<'alloc, A, T> DerefMut for Borrowed<'alloc, A, T>
9898
where A: Allocator
9999
, A: 'alloc {
100100
fn deref_mut(&mut self) -> &mut Self::Target {
101-
unsafe { self.value.get_mut() }
101+
unsafe { self.value.as_mut() }
102102
}
103103
}
104104

@@ -107,15 +107,15 @@ where A: Allocator
107107
, A: 'alloc {
108108
fn drop(&mut self) {
109109
use mem::drop;
110-
let address = *self.value as Address;
110+
let address = self.value.as_ptr() as Address;
111111
// ensure we drop the object _before_ deallocating it, so that
112112
// the object's destructor gets run first
113113
// i hope this is correct...
114-
drop(*self.value);
114+
drop(self.value.as_ptr());
115115
unsafe {
116116
self.allocator.lock()
117117
.dealloc( address
118-
, Layout::for_value(self.value.get()))
118+
, Layout::for_value(self.value.as_ref()))
119119
}
120120
}
121121
}

alloc/src/lib.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ pub unsafe trait Allocator {
637637
/// Captures a common usage pattern for allocators.
638638
unsafe fn dealloc_one<T>(&mut self, mut ptr: Unique<T>)
639639
where Self: Sized {
640-
let raw_ptr = ptr.get_mut() as *mut T as *mut u8;
640+
let raw_ptr = ptr.as_mut() as *mut T as *mut u8;
641641
self.dealloc(raw_ptr, Layout::new::<T>());
642642
}
643643

@@ -682,7 +682,9 @@ pub unsafe trait Allocator {
682682
n_old: usize,
683683
n_new: usize) -> Result<Unique<T>, AllocErr>
684684
where Self: Sized {
685-
match (Layout::array::<T>(n_old), Layout::array::<T>(n_new), *ptr) {
685+
match ( Layout::array::<T>(n_old)
686+
, Layout::array::<T>(n_new)
687+
, ptr.as_ptr()) {
686688
(Some(ref k_old), Some(ref k_new), ptr) if k_old.size() > 0 && k_new.size() > 0 => {
687689
self.realloc(ptr as *mut u8, k_old.clone(), k_new.clone())
688690
.map(|p|Unique::new(p as *mut T))
@@ -698,7 +700,7 @@ pub unsafe trait Allocator {
698700
/// Captures a common usage pattern for allocators.
699701
unsafe fn dealloc_array<T>(&mut self, ptr: Unique<T>, n: usize) -> Result<(), AllocErr>
700702
where Self: Sized {
701-
let raw_ptr = *ptr as *mut u8;
703+
let raw_ptr = ptr.as_ptr() as *mut u8;
702704
match Layout::array::<T>(n) {
703705
Some(ref k) if k.size() > 0 => {
704706
Ok(self.dealloc(raw_ptr, k.clone()))
@@ -804,9 +806,9 @@ pub unsafe trait Allocator {
804806
n_old: usize,
805807
n_new: usize) -> Option<Unique<T>>
806808
where Self: Sized {
807-
let (k_old, k_new, ptr) = (Layout::array_unchecked::<T>(n_old),
808-
Layout::array_unchecked::<T>(n_new),
809-
*ptr);
809+
let (k_old, k_new, ptr) = ( Layout::array_unchecked::<T>(n_old)
810+
, Layout::array_unchecked::<T>(n_new)
811+
, ptr.as_ptr());
810812
self.realloc_unchecked(ptr as *mut u8, k_old, k_new)
811813
.map(|p|Unique::new(*p as *mut T))
812814
}
@@ -821,7 +823,7 @@ pub unsafe trait Allocator {
821823
unsafe fn dealloc_array_unchecked<T>(&mut self, ptr: Unique<T>, n: usize)
822824
where Self: Sized {
823825
let layout = Layout::array_unchecked::<T>(n);
824-
self.dealloc(*ptr as *mut u8, layout);
826+
self.dealloc(ptr.as_ptr() as *mut u8, layout);
825827
}
826828
}
827829

paging/src/arch/x86_64/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,11 @@ impl ActivePML4 {
251251
}
252252

253253
fn pml4(&self) -> &Table<PML4Level> {
254-
unsafe { self.0.get() }
254+
unsafe { self.0.as_ref() }
255255
}
256256

257257
fn pml4_mut(&mut self) -> &mut Table<PML4Level> {
258-
unsafe { self.0.get_mut() }
258+
unsafe { self.0.as_mut() }
259259
}
260260

261261
/// Returns true if the given page is mapped.

0 commit comments

Comments
 (0)