File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ extern "C" {
1010 pub fn mi_malloc_aligned ( size : usize , alignment : usize ) -> * const c_void ;
1111 pub fn mi_realloc_aligned ( p : * const c_void , size : usize , alignment : usize ) -> * const c_void ;
1212 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 * const c_void , 8 , 8 ) } as * mut u8 ;
3536 unsafe { mi_free ( ptr as * const 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}
You can’t perform that action at this time.
0 commit comments