@@ -38,8 +38,8 @@ pub unsafe fn reallocate(ptr: *mut u8, old_size: uint, size: uint, align: uint)
38
38
/// Extends or shrinks the allocation referenced by `ptr` to `size` bytes of
39
39
/// memory in-place.
40
40
///
41
- /// Returns true if successful, otherwise false if the allocation was not
42
- /// altered .
41
+ /// If the operation succeeds, it returns `usable_size(size, align)` and if it
42
+ /// fails (or is a no-op) it returns `usable_size(old_size, align)` .
43
43
///
44
44
/// Behavior is undefined if the requested size is 0 or the alignment is not a
45
45
/// power of 2. The alignment must be no larger than the largest supported page
@@ -49,7 +49,7 @@ pub unsafe fn reallocate(ptr: *mut u8, old_size: uint, size: uint, align: uint)
49
49
/// create the allocation referenced by `ptr`. The `old_size` parameter may be
50
50
/// any value in range_inclusive(requested_size, usable_size).
51
51
#[ inline]
52
- pub unsafe fn reallocate_inplace ( ptr : * mut u8 , old_size : uint , size : uint , align : uint ) -> bool {
52
+ pub unsafe fn reallocate_inplace ( ptr : * mut u8 , old_size : uint , size : uint , align : uint ) -> uint {
53
53
imp:: reallocate_inplace ( ptr, old_size, size, align)
54
54
}
55
55
@@ -178,16 +178,10 @@ mod imp {
178
178
}
179
179
180
180
#[ inline]
181
- pub unsafe fn reallocate_inplace ( ptr : * mut u8 , old_size : uint , size : uint ,
182
- align : uint ) -> bool {
181
+ pub unsafe fn reallocate_inplace ( ptr : * mut u8 , _old_size : uint , size : uint ,
182
+ align : uint ) -> uint {
183
183
let flags = align_to_flags ( align) ;
184
- let new_size = je_xallocx ( ptr as * mut c_void , size as size_t , 0 , flags) as uint ;
185
- // checking for failure to shrink is tricky
186
- if size < old_size {
187
- usable_size ( size, align) == new_size as uint
188
- } else {
189
- new_size >= size
190
- }
184
+ je_xallocx ( ptr as * mut c_void , size as size_t , 0 , flags) as uint
191
185
}
192
186
193
187
#[ inline]
@@ -260,9 +254,9 @@ mod imp {
260
254
}
261
255
262
256
#[ inline]
263
- pub unsafe fn reallocate_inplace ( _ptr : * mut u8 , old_size : uint , size : uint ,
264
- _align : uint ) -> bool {
265
- size == old_size
257
+ pub unsafe fn reallocate_inplace ( _ptr : * mut u8 , old_size : uint , _size : uint ,
258
+ _align : uint ) -> uint {
259
+ old_size
266
260
}
267
261
268
262
#[ inline]
@@ -328,9 +322,9 @@ mod imp {
328
322
}
329
323
330
324
#[ inline]
331
- pub unsafe fn reallocate_inplace ( _ptr : * mut u8 , old_size : uint , size : uint ,
332
- _align : uint ) -> bool {
333
- size == old_size
325
+ pub unsafe fn reallocate_inplace ( _ptr : * mut u8 , old_size : uint , _size : uint ,
326
+ _align : uint ) -> uint {
327
+ old_size
334
328
}
335
329
336
330
#[ inline]
@@ -363,7 +357,7 @@ mod test {
363
357
let ptr = heap:: allocate ( size, 8 ) ;
364
358
let ret = heap:: reallocate_inplace ( ptr, size, size, 8 ) ;
365
359
heap:: deallocate ( ptr, size, 8 ) ;
366
- assert ! ( ret) ;
360
+ assert_eq ! ( ret, heap :: usable_size ( size , 8 ) ) ;
367
361
}
368
362
}
369
363
0 commit comments