@@ -39,29 +39,35 @@ const MIN_ALIGN: usize = 8;
39
39
const MIN_ALIGN : usize = 16 ;
40
40
41
41
#[ 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 {
43
43
unsafe { imp:: allocate ( size, align) }
44
44
}
45
45
46
46
#[ 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 ) {
48
48
unsafe { imp:: deallocate ( ptr, old_size, align) }
49
49
}
50
50
51
51
#[ 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 {
54
57
unsafe { imp:: reallocate ( ptr, old_size, size, align) }
55
58
}
56
59
57
60
#[ 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 {
60
66
unsafe { imp:: reallocate_inplace ( ptr, old_size, size, align) }
61
67
}
62
68
63
69
#[ 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 {
65
71
imp:: usable_size ( size, align)
66
72
}
67
73
@@ -80,7 +86,8 @@ mod imp {
80
86
#[ cfg( not( target_os = "android" ) ) ]
81
87
fn posix_memalign ( memptr : * mut * mut libc:: c_void ,
82
88
align : libc:: size_t ,
83
- size : libc:: size_t ) -> libc:: c_int ;
89
+ size : libc:: size_t )
90
+ -> libc:: c_int ;
84
91
}
85
92
86
93
pub unsafe fn allocate ( size : usize , align : usize ) -> * mut u8 {
@@ -94,9 +101,7 @@ mod imp {
94
101
#[ cfg( not( target_os = "android" ) ) ]
95
102
unsafe fn more_aligned_malloc ( size : usize , align : usize ) -> * mut u8 {
96
103
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 ) ;
100
105
if ret != 0 {
101
106
ptr:: null_mut ( )
102
107
} else {
@@ -107,8 +112,7 @@ mod imp {
107
112
}
108
113
}
109
114
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 {
112
116
if align <= MIN_ALIGN {
113
117
libc:: realloc ( ptr as * mut libc:: c_void , size as libc:: size_t ) as * mut u8
114
118
} else {
@@ -119,8 +123,11 @@ mod imp {
119
123
}
120
124
}
121
125
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 {
124
131
old_size
125
132
}
126
133
@@ -141,8 +148,7 @@ mod imp {
141
148
extern "system" {
142
149
fn GetProcessHeap ( ) -> HANDLE ;
143
150
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 ;
146
152
fn HeapFree ( hHeap : HANDLE , dwFlags : DWORD , lpMem : LPVOID ) -> BOOL ;
147
153
}
148
154
@@ -165,32 +171,45 @@ mod imp {
165
171
if align <= MIN_ALIGN {
166
172
HeapAlloc ( GetProcessHeap ( ) , 0 , size as SIZE_T ) as * mut u8
167
173
} 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
+ }
171
178
align_ptr ( ptr, align)
172
179
}
173
180
}
174
181
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 {
177
183
if align <= MIN_ALIGN {
178
184
HeapReAlloc ( GetProcessHeap ( ) , 0 , ptr as LPVOID , size as SIZE_T ) as * mut u8
179
185
} else {
180
186
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 ,
182
190
( size + align) as SIZE_T ) as * mut u8 ;
183
- if new. is_null ( ) { return new }
191
+ if new. is_null ( ) {
192
+ return new
193
+ }
184
194
align_ptr ( new, align)
185
195
}
186
196
}
187
197
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 {
190
203
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
+ }
194
213
} else {
195
214
old_size
196
215
}
0 commit comments