@@ -81,30 +81,30 @@ unsafe fn alloc_helper(size: usize, zero: bool) -> *mut c_void {
8181///
8282/// # Safety
8383/// The returned pointer must be freed with `memory::free` when it is no longer needed, otherwise memory will leak.
84- #[ no_mangle]
85- pub unsafe extern "C" fn malloc ( size : usize ) -> * mut c_void {
84+ #[ unsafe ( no_mangle) ]
85+ pub unsafe extern "C" fn malloc ( size : usize ) -> * mut c_void { unsafe {
8686 alloc_helper ( size, false )
87- }
87+ } }
8888
8989/// Allocates a block of memory for an array of `nmemb` elements, each of `size` bytes.
9090/// The memory is initialized to 0s.
9191///
9292/// # Safety
9393/// The returned pointer must be freed with `memory::free` when it is no longer needed, otherwise memory will leak.
94- #[ no_mangle]
95- pub unsafe extern "C" fn calloc ( nmemb : usize , size : usize ) -> * mut c_void {
94+ #[ unsafe ( no_mangle) ]
95+ pub unsafe extern "C" fn calloc ( nmemb : usize , size : usize ) -> * mut c_void { unsafe {
9696 let total_size = nmemb
9797 . checked_mul ( size)
9898 . expect ( "nmemb * size should not overflow in calloc" ) ;
9999
100100 alloc_helper ( total_size, true )
101- }
101+ } }
102102
103103/// Frees the memory block pointed to by `ptr`.
104104///
105105/// # Safety
106106/// `ptr` must be a pointer to a memory block previously allocated by `memory::malloc`, `memory::calloc`, or `memory::realloc`.
107- #[ no_mangle]
107+ #[ unsafe ( no_mangle) ]
108108pub unsafe extern "C" fn free ( ptr : * mut c_void ) {
109109 if !ptr. is_null ( ) {
110110 unsafe {
@@ -120,8 +120,8 @@ pub unsafe extern "C" fn free(ptr: *mut c_void) {
120120///
121121/// # Safety
122122/// `ptr` must be a pointer to a memory block previously allocated by `memory::malloc`, `memory::calloc`, or `memory::realloc`.
123- #[ no_mangle]
124- pub unsafe extern "C" fn realloc ( ptr : * mut c_void , size : usize ) -> * mut c_void {
123+ #[ unsafe ( no_mangle) ]
124+ pub unsafe extern "C" fn realloc ( ptr : * mut c_void , size : usize ) -> * mut c_void { unsafe {
125125 if ptr. is_null ( ) {
126126 // If the pointer is null, treat as a malloc
127127 return malloc ( size) ;
@@ -155,4 +155,4 @@ pub unsafe extern "C" fn realloc(ptr: *mut c_void, size: usize) -> *mut c_void {
155155 new_block_start. add ( 1 ) as * mut c_void
156156 }
157157 }
158- }
158+ } }
0 commit comments