@@ -41,7 +41,7 @@ const MIN_ALIGN: usize = 8;
41
41
#[ allow( dead_code) ]
42
42
const MIN_ALIGN : usize = 16 ;
43
43
44
- use core:: alloc:: { Alloc , AllocErr , Layout , Excess , CannotReallocInPlace } ;
44
+ use core:: alloc:: { Alloc , GlobalAlloc , AllocErr , Layout , Void } ;
45
45
46
46
#[ unstable( feature = "allocator_api" , issue = "32838" ) ]
47
47
pub struct System ;
@@ -50,65 +50,62 @@ pub struct System;
50
50
unsafe impl Alloc for System {
51
51
#[ inline]
52
52
unsafe fn alloc ( & mut self , layout : Layout ) -> Result < * mut u8 , AllocErr > {
53
- Alloc :: alloc ( & mut & * self , layout)
53
+ GlobalAlloc :: alloc ( self , layout) . into ( )
54
54
}
55
55
56
56
#[ 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 ( )
61
59
}
62
60
63
61
#[ inline]
64
62
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)
66
64
}
67
65
68
66
#[ inline]
69
67
unsafe fn realloc ( & mut self ,
70
68
ptr : * mut u8 ,
71
69
old_layout : Layout ,
72
70
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 ( )
74
72
}
75
73
74
+ #[ inline]
76
75
fn oom ( & mut self ) -> ! {
77
- Alloc :: oom ( & mut & * self )
76
+ :: oom ( )
78
77
}
78
+ }
79
79
80
+ #[ cfg( stage0) ]
81
+ #[ unstable( feature = "allocator_api" , issue = "32838" ) ]
82
+ unsafe impl < ' a > Alloc for & ' a System {
80
83
#[ 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 ( )
83
86
}
84
87
85
88
#[ 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 ( )
88
91
}
89
92
90
93
#[ 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)
96
96
}
97
97
98
98
#[ 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 ( )
104
104
}
105
105
106
106
#[ 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 ( )
112
109
}
113
110
}
114
111
@@ -135,33 +132,6 @@ mod realloc_fallback {
135
132
}
136
133
}
137
134
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
-
165
135
#[ cfg( any( unix, target_os = "cloudabi" , target_os = "redox" ) ) ]
166
136
mod platform {
167
137
extern crate libc;
@@ -170,7 +140,7 @@ mod platform {
170
140
171
141
use MIN_ALIGN ;
172
142
use System ;
173
- use core:: alloc:: { GlobalAlloc , Alloc , AllocErr , Layout , Void } ;
143
+ use core:: alloc:: { GlobalAlloc , Layout , Void } ;
174
144
175
145
#[ unstable( feature = "allocator_api" , issue = "32838" ) ]
176
146
unsafe impl GlobalAlloc for System {
@@ -219,15 +189,6 @@ mod platform {
219
189
}
220
190
}
221
191
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
-
231
192
#[ cfg( any( target_os = "android" , target_os = "redox" , target_os = "solaris" ) ) ]
232
193
#[ inline]
233
194
unsafe fn aligned_malloc ( layout : & Layout ) -> * mut Void {
@@ -270,7 +231,7 @@ mod platform {
270
231
mod platform {
271
232
use MIN_ALIGN ;
272
233
use System ;
273
- use core:: alloc:: { GlobalAlloc , Alloc , Void , AllocErr , Layout , CannotReallocInPlace } ;
234
+ use core:: alloc:: { GlobalAlloc , Void , Layout } ;
274
235
275
236
type LPVOID = * mut u8 ;
276
237
type HANDLE = LPVOID ;
@@ -353,47 +314,6 @@ mod platform {
353
314
}
354
315
}
355
316
}
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
- }
397
317
}
398
318
399
319
// This is an implementation of a global allocator on the wasm32 platform when
@@ -417,7 +337,7 @@ mod platform {
417
337
mod platform {
418
338
extern crate dlmalloc;
419
339
420
- use core:: alloc:: { GlobalAlloc , Alloc , AllocErr , Layout , Void } ;
340
+ use core:: alloc:: { GlobalAlloc , Layout , Void } ;
421
341
use System ;
422
342
423
343
// No need for synchronization here as wasm is currently single-threaded
@@ -445,11 +365,6 @@ mod platform {
445
365
DLMALLOC . realloc ( ptr as * mut u8 , layout. size ( ) , layout. align ( ) , new_size) as * mut Void
446
366
}
447
367
}
448
-
449
- #[ unstable( feature = "allocator_api" , issue = "32838" ) ]
450
- unsafe impl < ' a > Alloc for & ' a System {
451
- alloc_methods_based_on_global_alloc ! ( ) ;
452
- }
453
368
}
454
369
455
370
fn oom ( ) -> ! {
0 commit comments