33use core:: ffi:: c_void;
44
55extern "C" {
6- pub fn mi_zalloc ( size : usize ) -> * mut c_void ;
7- pub fn mi_malloc ( size : usize ) -> * mut c_void ;
8- pub fn mi_realloc ( p : * mut c_void , size : usize ) -> * mut c_void ;
9- pub fn mi_zalloc_aligned ( size : usize , alignment : usize ) -> * mut c_void ;
10- pub fn mi_malloc_aligned ( size : usize , alignment : usize ) -> * mut c_void ;
11- pub fn mi_realloc_aligned ( p : * mut c_void , size : usize , alignment : usize ) -> * mut c_void ;
12- pub fn mi_free ( p : * mut c_void ) -> c_void ;
6+ pub fn mi_zalloc ( size : usize ) -> * const c_void ;
7+ pub fn mi_malloc ( size : usize ) -> * const c_void ;
8+ pub fn mi_realloc ( p : * const c_void , size : usize ) -> * const c_void ;
9+ pub fn mi_zalloc_aligned ( size : usize , alignment : usize ) -> * const c_void ;
10+ pub fn mi_malloc_aligned ( size : usize , alignment : usize ) -> * const c_void ;
11+ pub fn mi_realloc_aligned ( p : * const c_void , size : usize , alignment : usize ) -> * const c_void ;
12+ pub fn mi_free ( p : * const c_void ) -> c_void ;
13+ pub fn mi_usable_size ( p : * mut c_void ) -> usize ;
1314}
1415
1516#[ cfg( test) ]
@@ -34,4 +35,14 @@ mod tests {
3435 let ptr = unsafe { mi_realloc_aligned ( ptr as * mut c_void , 8 , 8 ) } as * mut u8 ;
3536 unsafe { mi_free ( ptr as * mut c_void ) } ;
3637 }
38+
39+ #[ test]
40+ fn it_calculates_usable_size ( ) {
41+ let ptr = unsafe { mi_malloc ( 32 ) } as * mut u8 ;
42+ let usable_size = unsafe { mi_usable_size ( ptr as * mut c_void ) } ;
43+ assert ! (
44+ usable_size >= 32 ,
45+ "usable_size should at least equal to the allocated size"
46+ ) ;
47+ }
3748}
0 commit comments