@@ -24,28 +24,32 @@ static mut DLMALLOC: dlmalloc::Dlmalloc = dlmalloc::DLMALLOC_INIT;
24
24
unsafe impl GlobalAlloc for System {
25
25
#[ inline]
26
26
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.
28
29
let _lock = lock:: lock ( ) ;
29
30
unsafe { DLMALLOC . malloc ( layout. size ( ) , layout. align ( ) ) }
30
31
}
31
32
32
33
#[ inline]
33
34
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.
35
37
let _lock = lock:: lock ( ) ;
36
38
unsafe { DLMALLOC . calloc ( layout. size ( ) , layout. align ( ) ) }
37
39
}
38
40
39
41
#[ inline]
40
42
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.
42
45
let _lock = lock:: lock ( ) ;
43
46
unsafe { DLMALLOC . free ( ptr, layout. size ( ) , layout. align ( ) ) }
44
47
}
45
48
46
49
#[ inline]
47
50
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.
49
53
let _lock = lock:: lock ( ) ;
50
54
unsafe { DLMALLOC . realloc ( ptr, layout. size ( ) , layout. align ( ) , new_size) }
51
55
}
0 commit comments