@@ -48,9 +48,6 @@ extern "Rust" {
4848 #[ allocator]
4949 #[ rustc_allocator_nounwind]
5050 fn __rust_alloc ( size : usize , align : usize ) -> * mut u8 ;
51- #[ cold]
52- #[ rustc_allocator_nounwind]
53- fn __rust_oom ( ) -> !;
5451 #[ rustc_allocator_nounwind]
5552 fn __rust_dealloc ( ptr : * mut u8 , size : usize , align : usize ) ;
5653 #[ rustc_allocator_nounwind]
@@ -107,16 +104,6 @@ unsafe impl GlobalAlloc for Global {
107104 let ptr = __rust_alloc_zeroed ( layout. size ( ) , layout. align ( ) , & mut 0 ) ;
108105 ptr as * mut Opaque
109106 }
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- }
120107}
121108
122109unsafe impl Alloc for Global {
@@ -147,7 +134,7 @@ unsafe impl Alloc for Global {
147134
148135 #[ inline]
149136 fn oom ( & mut self ) -> ! {
150- GlobalAlloc :: oom ( self )
137+ oom ( )
151138 }
152139}
153140
@@ -165,7 +152,7 @@ unsafe fn exchange_malloc(size: usize, align: usize) -> *mut u8 {
165152 if !ptr. is_null ( ) {
166153 ptr as * mut u8
167154 } else {
168- Global . oom ( )
155+ oom ( )
169156 }
170157 }
171158}
@@ -182,19 +169,33 @@ pub(crate) unsafe fn box_free<T: ?Sized>(ptr: *mut T) {
182169 }
183170}
184171
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+
185186#[ cfg( test) ]
186187mod tests {
187188 extern crate test;
188189 use self :: test:: Bencher ;
189190 use boxed:: Box ;
190- use alloc:: { Global , Alloc , Layout } ;
191+ use alloc:: { Global , Alloc , Layout , oom } ;
191192
192193 #[ test]
193194 fn allocate_zeroed ( ) {
194195 unsafe {
195196 let layout = Layout :: from_size_align ( 1024 , 1 ) . unwrap ( ) ;
196197 let ptr = Global . alloc_zeroed ( layout. clone ( ) )
197- . unwrap_or_else ( |_| Global . oom ( ) ) ;
198+ . unwrap_or_else ( |_| oom ( ) ) ;
198199
199200 let mut i = ptr. cast :: < u8 > ( ) . as_ptr ( ) ;
200201 let end = i. offset ( layout. size ( ) as isize ) ;
0 commit comments