@@ -48,9 +48,6 @@ extern "Rust" {
48
48
#[ allocator]
49
49
#[ rustc_allocator_nounwind]
50
50
fn __rust_alloc ( size : usize , align : usize ) -> * mut u8 ;
51
- #[ cold]
52
- #[ rustc_allocator_nounwind]
53
- fn __rust_oom ( ) -> !;
54
51
#[ rustc_allocator_nounwind]
55
52
fn __rust_dealloc ( ptr : * mut u8 , size : usize , align : usize ) ;
56
53
#[ rustc_allocator_nounwind]
@@ -107,16 +104,6 @@ unsafe impl GlobalAlloc for Global {
107
104
let ptr = __rust_alloc_zeroed ( layout. size ( ) , layout. align ( ) , & mut 0 ) ;
108
105
ptr as * mut Opaque
109
106
}
110
-
111
- #[ inline]
112
- fn oom ( & self ) -> ! {
113
- unsafe {
114
- #[ cfg( not( stage0) ) ]
115
- __rust_oom ( ) ;
116
- #[ cfg( stage0) ]
117
- __rust_oom ( & mut 0 ) ;
118
- }
119
- }
120
107
}
121
108
122
109
unsafe impl Alloc for Global {
@@ -147,7 +134,7 @@ unsafe impl Alloc for Global {
147
134
148
135
#[ inline]
149
136
fn oom ( & mut self ) -> ! {
150
- GlobalAlloc :: oom ( self )
137
+ oom ( )
151
138
}
152
139
}
153
140
@@ -165,7 +152,7 @@ unsafe fn exchange_malloc(size: usize, align: usize) -> *mut u8 {
165
152
if !ptr. is_null ( ) {
166
153
ptr as * mut u8
167
154
} else {
168
- Global . oom ( )
155
+ oom ( )
169
156
}
170
157
}
171
158
}
@@ -182,19 +169,33 @@ pub(crate) unsafe fn box_free<T: ?Sized>(ptr: *mut T) {
182
169
}
183
170
}
184
171
172
+ #[ cfg( stage0) ]
173
+ pub fn oom ( ) -> ! {
174
+ unsafe { :: core:: intrinsics:: abort ( ) }
175
+ }
176
+
177
+ #[ cfg( not( stage0) ) ]
178
+ pub fn oom ( ) -> ! {
179
+ extern {
180
+ #[ lang = "oom" ]
181
+ fn oom_impl ( ) -> !;
182
+ }
183
+ unsafe { oom_impl ( ) }
184
+ }
185
+
185
186
#[ cfg( test) ]
186
187
mod tests {
187
188
extern crate test;
188
189
use self :: test:: Bencher ;
189
190
use boxed:: Box ;
190
- use alloc:: { Global , Alloc , Layout } ;
191
+ use alloc:: { Global , Alloc , Layout , oom } ;
191
192
192
193
#[ test]
193
194
fn allocate_zeroed ( ) {
194
195
unsafe {
195
196
let layout = Layout :: from_size_align ( 1024 , 1 ) . unwrap ( ) ;
196
197
let ptr = Global . alloc_zeroed ( layout. clone ( ) )
197
- . unwrap_or_else ( |_| Global . oom ( ) ) ;
198
+ . unwrap_or_else ( |_| oom ( ) ) ;
198
199
199
200
let mut i = ptr. cast :: < u8 > ( ) . as_ptr ( ) ;
200
201
let end = i. offset ( layout. size ( ) as isize ) ;
0 commit comments