@@ -24,28 +24,32 @@ static mut DLMALLOC: dlmalloc::Dlmalloc = dlmalloc::DLMALLOC_INIT;
2424unsafe impl GlobalAlloc for System {
2525 #[ inline]
2626 unsafe fn alloc ( & self , layout : Layout ) -> * mut u8 {
27- // SAFETY: DLMALLOC.malloc() is guranteed to be safe since lock::lock() aqcuire a globl lock
27+ // SAFETY: DLMALLOC access is guranteed to be safe because the lock gives us unique and non-reentrant access.
28+ // Calling malloc() is safe because preconditions on this function match the trait method preconditions.
2829 let _lock = lock:: lock ( ) ;
2930 unsafe { DLMALLOC . malloc ( layout. size ( ) , layout. align ( ) ) }
3031 }
3132
3233 #[ inline]
3334 unsafe fn alloc_zeroed ( & self , layout : Layout ) -> * mut u8 {
34- // SAFETY: DLMALLOC.calloc() is guranteed to be safe since lock::lock() aqcuire a globl lock
35+ // SAFETY: DLMALLOC access is guranteed to be safe because the lock gives us unique and non-reentrant access.
36+ // Calling calloc() is safe because preconditions on this function match the trait method preconditions.
3537 let _lock = lock:: lock ( ) ;
3638 unsafe { DLMALLOC . calloc ( layout. size ( ) , layout. align ( ) ) }
3739 }
3840
3941 #[ inline]
4042 unsafe fn dealloc ( & self , ptr : * mut u8 , layout : Layout ) {
41- // SAFETY: DLMALLOC.free() is guranteed to be safe since lock::lock() aqcuire a globl lock
43+ // SAFETY: DLMALLOC access is guranteed to be safe because the lock gives us unique and non-reentrant access.
44+ // Calling free() is safe because preconditions on this function match the trait method preconditions.
4245 let _lock = lock:: lock ( ) ;
4346 unsafe { DLMALLOC . free ( ptr, layout. size ( ) , layout. align ( ) ) }
4447 }
4548
4649 #[ inline]
4750 unsafe fn realloc ( & self , ptr : * mut u8 , layout : Layout , new_size : usize ) -> * mut u8 {
48- // SAFETY: DLMALLOC.realloc() is guranteed to be safe since lock::lock() aqcuire a globl lock
51+ // SAFETY: DLMALLOC access is guranteed to be safe because the lock gives us unique and non-reentrant access.
52+ // Calling realloc() is safe because preconditions on this function match the trait method preconditions.
4953 let _lock = lock:: lock ( ) ;
5054 unsafe { DLMALLOC . realloc ( ptr, layout. size ( ) , layout. align ( ) , new_size) }
5155 }
0 commit comments