3
3
use core:: ffi:: c_void;
4
4
5
5
extern "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 ;
13
14
}
14
15
15
16
#[ cfg( test) ]
@@ -34,4 +35,14 @@ mod tests {
34
35
let ptr = unsafe { mi_realloc_aligned ( ptr as * mut c_void , 8 , 8 ) } as * mut u8 ;
35
36
unsafe { mi_free ( ptr as * mut c_void ) } ;
36
37
}
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
+ }
37
48
}
0 commit comments