@@ -11,37 +11,37 @@ unsafe impl GlobalAlloc for System {
1111 // Also see <https://github.com/rust-lang/rust/issues/45955> and
1212 // <https://github.com/rust-lang/rust/issues/62251#issuecomment-507580914>.
1313 if layout. align ( ) <= MIN_ALIGN && layout. align ( ) <= layout. size ( ) {
14- libc:: malloc ( layout. size ( ) ) as * mut u8
14+ unsafe { libc:: malloc ( layout. size ( ) ) as * mut u8 }
1515 } else {
16- aligned_malloc ( & layout)
16+ unsafe { aligned_malloc ( & layout) }
1717 }
1818 }
1919
2020 #[ inline]
2121 unsafe fn alloc_zeroed ( & self , layout : Layout ) -> * mut u8 {
2222 // See the comment above in `alloc` for why this check looks the way it does.
2323 if layout. align ( ) <= MIN_ALIGN && layout. align ( ) <= layout. size ( ) {
24- libc:: calloc ( layout. size ( ) , 1 ) as * mut u8
24+ unsafe { libc:: calloc ( layout. size ( ) , 1 ) as * mut u8 }
2525 } else {
26- let ptr = self . alloc ( layout) ;
26+ let ptr = unsafe { self . alloc ( layout) } ;
2727 if !ptr. is_null ( ) {
28- ptr:: write_bytes ( ptr, 0 , layout. size ( ) ) ;
28+ unsafe { ptr:: write_bytes ( ptr, 0 , layout. size ( ) ) } ;
2929 }
3030 ptr
3131 }
3232 }
3333
3434 #[ inline]
3535 unsafe fn dealloc ( & self , ptr : * mut u8 , _layout : Layout ) {
36- libc:: free ( ptr as * mut libc:: c_void )
36+ unsafe { libc:: free ( ptr as * mut libc:: c_void ) }
3737 }
3838
3939 #[ inline]
4040 unsafe fn realloc ( & self , ptr : * mut u8 , layout : Layout , new_size : usize ) -> * mut u8 {
4141 if layout. align ( ) <= MIN_ALIGN && layout. align ( ) <= new_size {
42- libc:: realloc ( ptr as * mut libc:: c_void , new_size) as * mut u8
42+ unsafe { libc:: realloc ( ptr as * mut libc:: c_void , new_size) as * mut u8 }
4343 } else {
44- realloc_fallback ( self , ptr, layout, new_size)
44+ unsafe { realloc_fallback ( self , ptr, layout, new_size) }
4545 }
4646 }
4747}
@@ -52,6 +52,6 @@ unsafe fn aligned_malloc(layout: &Layout) -> *mut u8 {
5252 // posix_memalign requires that the alignment be a multiple of `sizeof(void*)`.
5353 // Since these are all powers of 2, we can just use max.
5454 let align = layout. align ( ) . max ( crate :: mem:: size_of :: < usize > ( ) ) ;
55- let ret = libc:: posix_memalign ( & mut out, align, layout. size ( ) ) ;
55+ let ret = unsafe { libc:: posix_memalign ( & mut out, align, layout. size ( ) ) } ;
5656 if ret != 0 { ptr:: null_mut ( ) } else { out as * mut u8 }
5757}
0 commit comments