Skip to content

Commit 96c9d22

Browse files
committed
Remove impl Alloc for &'a System
This was relevant to `#[global_allocator]`, which is now based on `GlobalAlloc` trait instead.
1 parent c033f1f commit 96c9d22

File tree

1 file changed

+28
-113
lines changed

1 file changed

+28
-113
lines changed

src/liballoc_system/lib.rs

Lines changed: 28 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const MIN_ALIGN: usize = 8;
4141
#[allow(dead_code)]
4242
const MIN_ALIGN: usize = 16;
4343

44-
use core::alloc::{Alloc, AllocErr, Layout, Excess, CannotReallocInPlace};
44+
use core::alloc::{Alloc, GlobalAlloc, AllocErr, Layout, Void};
4545

4646
#[unstable(feature = "allocator_api", issue = "32838")]
4747
pub struct System;
@@ -50,65 +50,62 @@ pub struct System;
5050
unsafe impl Alloc for System {
5151
#[inline]
5252
unsafe fn alloc(&mut self, layout: Layout) -> Result<*mut u8, AllocErr> {
53-
Alloc::alloc(&mut &*self, layout)
53+
GlobalAlloc::alloc(self, layout).into()
5454
}
5555

5656
#[inline]
57-
unsafe fn alloc_zeroed(&mut self, layout: Layout)
58-
-> Result<*mut u8, AllocErr>
59-
{
60-
Alloc::alloc_zeroed(&mut &*self, layout)
57+
unsafe fn alloc_zeroed(&mut self, layout: Layout) -> Result<*mut u8, AllocErr> {
58+
GlobalAlloc::alloc_zeroed(self, layout).into()
6159
}
6260

6361
#[inline]
6462
unsafe fn dealloc(&mut self, ptr: *mut u8, layout: Layout) {
65-
Alloc::dealloc(&mut &*self, ptr, layout)
63+
GlobalAlloc::dealloc(self, ptr as *mut Void, layout)
6664
}
6765

6866
#[inline]
6967
unsafe fn realloc(&mut self,
7068
ptr: *mut u8,
7169
old_layout: Layout,
7270
new_size: usize) -> Result<*mut u8, AllocErr> {
73-
Alloc::realloc(&mut &*self, ptr, old_layout, new_size)
71+
GlobalAlloc::realloc(self, ptr as *mut Void, old_layout, new_size).into()
7472
}
7573

74+
#[inline]
7675
fn oom(&mut self) -> ! {
77-
Alloc::oom(&mut &*self)
76+
::oom()
7877
}
78+
}
7979

80+
#[cfg(stage0)]
81+
#[unstable(feature = "allocator_api", issue = "32838")]
82+
unsafe impl<'a> Alloc for &'a System {
8083
#[inline]
81-
fn usable_size(&self, layout: &Layout) -> (usize, usize) {
82-
Alloc::usable_size(&mut &*self, layout)
84+
unsafe fn alloc(&mut self, layout: Layout) -> Result<*mut u8, AllocErr> {
85+
GlobalAlloc::alloc(*self, layout).into()
8386
}
8487

8588
#[inline]
86-
unsafe fn alloc_excess(&mut self, layout: Layout) -> Result<Excess, AllocErr> {
87-
Alloc::alloc_excess(&mut &*self, layout)
89+
unsafe fn alloc_zeroed(&mut self, layout: Layout) -> Result<*mut u8, AllocErr> {
90+
GlobalAlloc::alloc_zeroed(*self, layout).into()
8891
}
8992

9093
#[inline]
91-
unsafe fn realloc_excess(&mut self,
92-
ptr: *mut u8,
93-
layout: Layout,
94-
new_size: usize) -> Result<Excess, AllocErr> {
95-
Alloc::realloc_excess(&mut &*self, ptr, layout, new_size)
94+
unsafe fn dealloc(&mut self, ptr: *mut u8, layout: Layout) {
95+
GlobalAlloc::dealloc(*self, ptr as *mut Void, layout)
9696
}
9797

9898
#[inline]
99-
unsafe fn grow_in_place(&mut self,
100-
ptr: *mut u8,
101-
layout: Layout,
102-
new_size: usize) -> Result<(), CannotReallocInPlace> {
103-
Alloc::grow_in_place(&mut &*self, ptr, layout, new_size)
99+
unsafe fn realloc(&mut self,
100+
ptr: *mut u8,
101+
old_layout: Layout,
102+
new_size: usize) -> Result<*mut u8, AllocErr> {
103+
GlobalAlloc::realloc(*self, ptr as *mut Void, old_layout, new_size).into()
104104
}
105105

106106
#[inline]
107-
unsafe fn shrink_in_place(&mut self,
108-
ptr: *mut u8,
109-
layout: Layout,
110-
new_size: usize) -> Result<(), CannotReallocInPlace> {
111-
Alloc::shrink_in_place(&mut &*self, ptr, layout, new_size)
107+
fn oom(&mut self) -> ! {
108+
::oom()
112109
}
113110
}
114111

@@ -135,33 +132,6 @@ mod realloc_fallback {
135132
}
136133
}
137134

138-
macro_rules! alloc_methods_based_on_global_alloc {
139-
() => {
140-
#[inline]
141-
unsafe fn alloc(&mut self, layout: Layout) -> Result<*mut u8, AllocErr> {
142-
GlobalAlloc::alloc(*self, layout).into()
143-
}
144-
145-
#[inline]
146-
unsafe fn alloc_zeroed(&mut self, layout: Layout) -> Result<*mut u8, AllocErr> {
147-
GlobalAlloc::alloc_zeroed(*self, layout).into()
148-
}
149-
150-
#[inline]
151-
unsafe fn dealloc(&mut self, ptr: *mut u8, layout: Layout) {
152-
GlobalAlloc::dealloc(*self, ptr as *mut Void, layout)
153-
}
154-
155-
#[inline]
156-
unsafe fn realloc(&mut self,
157-
ptr: *mut u8,
158-
old_layout: Layout,
159-
new_size: usize) -> Result<*mut u8, AllocErr> {
160-
GlobalAlloc::realloc(*self, ptr as *mut Void, old_layout, new_size).into()
161-
}
162-
}
163-
}
164-
165135
#[cfg(any(unix, target_os = "cloudabi", target_os = "redox"))]
166136
mod platform {
167137
extern crate libc;
@@ -170,7 +140,7 @@ mod platform {
170140

171141
use MIN_ALIGN;
172142
use System;
173-
use core::alloc::{GlobalAlloc, Alloc, AllocErr, Layout, Void};
143+
use core::alloc::{GlobalAlloc, Layout, Void};
174144

175145
#[unstable(feature = "allocator_api", issue = "32838")]
176146
unsafe impl GlobalAlloc for System {
@@ -219,15 +189,6 @@ mod platform {
219189
}
220190
}
221191

222-
#[unstable(feature = "allocator_api", issue = "32838")]
223-
unsafe impl<'a> Alloc for &'a System {
224-
alloc_methods_based_on_global_alloc!();
225-
226-
fn oom(&mut self) -> ! {
227-
::oom()
228-
}
229-
}
230-
231192
#[cfg(any(target_os = "android", target_os = "redox", target_os = "solaris"))]
232193
#[inline]
233194
unsafe fn aligned_malloc(layout: &Layout) -> *mut Void {
@@ -270,7 +231,7 @@ mod platform {
270231
mod platform {
271232
use MIN_ALIGN;
272233
use System;
273-
use core::alloc::{GlobalAlloc, Alloc, Void, AllocErr, Layout, CannotReallocInPlace};
234+
use core::alloc::{GlobalAlloc, Void, Layout};
274235

275236
type LPVOID = *mut u8;
276237
type HANDLE = LPVOID;
@@ -353,47 +314,6 @@ mod platform {
353314
}
354315
}
355316
}
356-
357-
#[unstable(feature = "allocator_api", issue = "32838")]
358-
unsafe impl<'a> Alloc for &'a System {
359-
alloc_methods_based_on_global_alloc!();
360-
361-
#[inline]
362-
unsafe fn grow_in_place(&mut self,
363-
ptr: *mut u8,
364-
layout: Layout,
365-
new_size: usize) -> Result<(), CannotReallocInPlace> {
366-
self.shrink_in_place(ptr, layout, new_size)
367-
}
368-
369-
#[inline]
370-
unsafe fn shrink_in_place(&mut self,
371-
ptr: *mut u8,
372-
layout: Layout,
373-
new_size: usize) -> Result<(), CannotReallocInPlace> {
374-
let new = if layout.align() <= MIN_ALIGN {
375-
HeapReAlloc(GetProcessHeap(),
376-
HEAP_REALLOC_IN_PLACE_ONLY,
377-
ptr as LPVOID,
378-
new_size)
379-
} else {
380-
let header = get_header(ptr);
381-
HeapReAlloc(GetProcessHeap(),
382-
HEAP_REALLOC_IN_PLACE_ONLY,
383-
header.0 as LPVOID,
384-
new_size + layout.align())
385-
};
386-
if new.is_null() {
387-
Err(CannotReallocInPlace)
388-
} else {
389-
Ok(())
390-
}
391-
}
392-
393-
fn oom(&mut self) -> ! {
394-
::oom()
395-
}
396-
}
397317
}
398318

399319
// This is an implementation of a global allocator on the wasm32 platform when
@@ -417,7 +337,7 @@ mod platform {
417337
mod platform {
418338
extern crate dlmalloc;
419339

420-
use core::alloc::{GlobalAlloc, Alloc, AllocErr, Layout, Void};
340+
use core::alloc::{GlobalAlloc, Layout, Void};
421341
use System;
422342

423343
// No need for synchronization here as wasm is currently single-threaded
@@ -445,11 +365,6 @@ mod platform {
445365
DLMALLOC.realloc(ptr as *mut u8, layout.size(), layout.align(), new_size) as *mut Void
446366
}
447367
}
448-
449-
#[unstable(feature = "allocator_api", issue = "32838")]
450-
unsafe impl<'a> Alloc for &'a System {
451-
alloc_methods_based_on_global_alloc!();
452-
}
453368
}
454369

455370
fn oom() -> ! {

0 commit comments

Comments
 (0)