@@ -39,29 +39,35 @@ const MIN_ALIGN: usize = 8;
3939const MIN_ALIGN : usize = 16 ;
4040
4141#[ no_mangle]
42- pub extern fn __rust_allocate ( size : usize , align : usize ) -> * mut u8 {
42+ pub extern "C" fn __rust_allocate ( size : usize , align : usize ) -> * mut u8 {
4343 unsafe { imp:: allocate ( size, align) }
4444}
4545
4646#[ no_mangle]
47- pub extern fn __rust_deallocate ( ptr : * mut u8 , old_size : usize , align : usize ) {
47+ pub extern "C" fn __rust_deallocate ( ptr : * mut u8 , old_size : usize , align : usize ) {
4848 unsafe { imp:: deallocate ( ptr, old_size, align) }
4949}
5050
5151#[ no_mangle]
52- pub extern fn __rust_reallocate ( ptr : * mut u8 , old_size : usize , size : usize ,
53- align : usize ) -> * mut u8 {
52+ pub extern "C" fn __rust_reallocate ( ptr : * mut u8 ,
53+ old_size : usize ,
54+ size : usize ,
55+ align : usize )
56+ -> * mut u8 {
5457 unsafe { imp:: reallocate ( ptr, old_size, size, align) }
5558}
5659
5760#[ no_mangle]
58- pub extern fn __rust_reallocate_inplace ( ptr : * mut u8 , old_size : usize ,
59- size : usize , align : usize ) -> usize {
61+ pub extern "C" fn __rust_reallocate_inplace ( ptr : * mut u8 ,
62+ old_size : usize ,
63+ size : usize ,
64+ align : usize )
65+ -> usize {
6066 unsafe { imp:: reallocate_inplace ( ptr, old_size, size, align) }
6167}
6268
6369#[ no_mangle]
64- pub extern fn __rust_usable_size ( size : usize , align : usize ) -> usize {
70+ pub extern "C" fn __rust_usable_size ( size : usize , align : usize ) -> usize {
6571 imp:: usable_size ( size, align)
6672}
6773
@@ -80,7 +86,8 @@ mod imp {
8086 #[ cfg( not( target_os = "android" ) ) ]
8187 fn posix_memalign ( memptr : * mut * mut libc:: c_void ,
8288 align : libc:: size_t ,
83- size : libc:: size_t ) -> libc:: c_int ;
89+ size : libc:: size_t )
90+ -> libc:: c_int ;
8491 }
8592
8693 pub unsafe fn allocate ( size : usize , align : usize ) -> * mut u8 {
@@ -94,9 +101,7 @@ mod imp {
94101 #[ cfg( not( target_os = "android" ) ) ]
95102 unsafe fn more_aligned_malloc ( size : usize , align : usize ) -> * mut u8 {
96103 let mut out = ptr:: null_mut ( ) ;
97- let ret = posix_memalign ( & mut out,
98- align as libc:: size_t ,
99- size as libc:: size_t ) ;
104+ let ret = posix_memalign ( & mut out, align as libc:: size_t , size as libc:: size_t ) ;
100105 if ret != 0 {
101106 ptr:: null_mut ( )
102107 } else {
@@ -107,8 +112,7 @@ mod imp {
107112 }
108113 }
109114
110- pub unsafe fn reallocate ( ptr : * mut u8 , old_size : usize , size : usize ,
111- align : usize ) -> * mut u8 {
115+ pub unsafe fn reallocate ( ptr : * mut u8 , old_size : usize , size : usize , align : usize ) -> * mut u8 {
112116 if align <= MIN_ALIGN {
113117 libc:: realloc ( ptr as * mut libc:: c_void , size as libc:: size_t ) as * mut u8
114118 } else {
@@ -119,8 +123,11 @@ mod imp {
119123 }
120124 }
121125
122- pub unsafe fn reallocate_inplace ( _ptr : * mut u8 , old_size : usize , _size : usize ,
123- _align : usize ) -> usize {
126+ pub unsafe fn reallocate_inplace ( _ptr : * mut u8 ,
127+ old_size : usize ,
128+ _size : usize ,
129+ _align : usize )
130+ -> usize {
124131 old_size
125132 }
126133
@@ -141,8 +148,7 @@ mod imp {
141148 extern "system" {
142149 fn GetProcessHeap ( ) -> HANDLE ;
143150 fn HeapAlloc ( hHeap : HANDLE , dwFlags : DWORD , dwBytes : SIZE_T ) -> LPVOID ;
144- fn HeapReAlloc ( hHeap : HANDLE , dwFlags : DWORD , lpMem : LPVOID ,
145- dwBytes : SIZE_T ) -> LPVOID ;
151+ fn HeapReAlloc ( hHeap : HANDLE , dwFlags : DWORD , lpMem : LPVOID , dwBytes : SIZE_T ) -> LPVOID ;
146152 fn HeapFree ( hHeap : HANDLE , dwFlags : DWORD , lpMem : LPVOID ) -> BOOL ;
147153 }
148154
@@ -165,32 +171,45 @@ mod imp {
165171 if align <= MIN_ALIGN {
166172 HeapAlloc ( GetProcessHeap ( ) , 0 , size as SIZE_T ) as * mut u8
167173 } else {
168- let ptr = HeapAlloc ( GetProcessHeap ( ) , 0 ,
169- ( size + align) as SIZE_T ) as * mut u8 ;
170- if ptr. is_null ( ) { return ptr }
174+ let ptr = HeapAlloc ( GetProcessHeap ( ) , 0 , ( size + align) as SIZE_T ) as * mut u8 ;
175+ if ptr. is_null ( ) {
176+ return ptr
177+ }
171178 align_ptr ( ptr, align)
172179 }
173180 }
174181
175- pub unsafe fn reallocate ( ptr : * mut u8 , _old_size : usize , size : usize ,
176- align : usize ) -> * mut u8 {
182+ pub unsafe fn reallocate ( ptr : * mut u8 , _old_size : usize , size : usize , align : usize ) -> * mut u8 {
177183 if align <= MIN_ALIGN {
178184 HeapReAlloc ( GetProcessHeap ( ) , 0 , ptr as LPVOID , size as SIZE_T ) as * mut u8
179185 } else {
180186 let header = get_header ( ptr) ;
181- let new = HeapReAlloc ( GetProcessHeap ( ) , 0 , header. 0 as LPVOID ,
187+ let new = HeapReAlloc ( GetProcessHeap ( ) ,
188+ 0 ,
189+ header. 0 as LPVOID ,
182190 ( size + align) as SIZE_T ) as * mut u8 ;
183- if new. is_null ( ) { return new }
191+ if new. is_null ( ) {
192+ return new
193+ }
184194 align_ptr ( new, align)
185195 }
186196 }
187197
188- pub unsafe fn reallocate_inplace ( ptr : * mut u8 , old_size : usize , size : usize ,
189- align : usize ) -> usize {
198+ pub unsafe fn reallocate_inplace ( ptr : * mut u8 ,
199+ old_size : usize ,
200+ size : usize ,
201+ align : usize )
202+ -> usize {
190203 if align <= MIN_ALIGN {
191- let new = HeapReAlloc ( GetProcessHeap ( ) , HEAP_REALLOC_IN_PLACE_ONLY ,
192- ptr as LPVOID , size as SIZE_T ) as * mut u8 ;
193- if new. is_null ( ) { old_size } else { size }
204+ let new = HeapReAlloc ( GetProcessHeap ( ) ,
205+ HEAP_REALLOC_IN_PLACE_ONLY ,
206+ ptr as LPVOID ,
207+ size as SIZE_T ) as * mut u8 ;
208+ if new. is_null ( ) {
209+ old_size
210+ } else {
211+ size
212+ }
194213 } else {
195214 old_size
196215 }
0 commit comments