Rollup merge of #104568 - RalfJung:realloc, r=Amanieu
clarify that realloc refreshes pointer provenance even when the allocation remains in-place This [matches what C does](https://en.cppreference.com/w/c/memory/realloc): > The original pointer ptr is invalidated and any access to it is undefined behavior (even if reallocation was in-place). Cc `@rust-lang/wg-allocators`
This commit is contained in:
commit
db5f005f35
@ -208,9 +208,11 @@ unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
|
||||
///
|
||||
/// If this returns a non-null pointer, then ownership of the memory block
|
||||
/// referenced by `ptr` has been transferred to this allocator.
|
||||
/// The memory may or may not have been deallocated, and should be
|
||||
/// considered unusable. The new memory block is allocated with `layout`,
|
||||
/// but with the `size` updated to `new_size`. This new layout should be
|
||||
/// Any access to the old `ptr` is Undefined Behavior, even if the
|
||||
/// allocation remained in-place. The newly returned pointer is the only valid pointer
|
||||
/// for accessing this memory now.
|
||||
/// The new memory block is allocated with `layout`,
|
||||
/// but with the `size` updated to `new_size`. This new layout must be
|
||||
/// used when deallocating the new memory block with `dealloc`. The range
|
||||
/// `0..min(layout.size(), new_size)` of the new memory block is
|
||||
/// guaranteed to have the same values as the original block.
|
||||
|
@ -169,8 +169,9 @@ fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
|
||||
/// this, the allocator may extend the allocation referenced by `ptr` to fit the new layout.
|
||||
///
|
||||
/// If this returns `Ok`, then ownership of the memory block referenced by `ptr` has been
|
||||
/// transferred to this allocator. The memory may or may not have been freed, and should be
|
||||
/// considered unusable.
|
||||
/// transferred to this allocator. Any access to the old `ptr` is Undefined Behavior, even if the
|
||||
/// allocation was grown in-place. The newly returned pointer is the only valid pointer
|
||||
/// for accessing this memory now.
|
||||
///
|
||||
/// If this method returns `Err`, then ownership of the memory block has not been transferred to
|
||||
/// this allocator, and the contents of the memory block are unaltered.
|
||||
@ -295,8 +296,9 @@ unsafe fn grow_zeroed(
|
||||
/// this, the allocator may shrink the allocation referenced by `ptr` to fit the new layout.
|
||||
///
|
||||
/// If this returns `Ok`, then ownership of the memory block referenced by `ptr` has been
|
||||
/// transferred to this allocator. The memory may or may not have been freed, and should be
|
||||
/// considered unusable.
|
||||
/// transferred to this allocator. Any access to the old `ptr` is Undefined Behavior, even if the
|
||||
/// allocation was shrunk in-place. The newly returned pointer is the only valid pointer
|
||||
/// for accessing this memory now.
|
||||
///
|
||||
/// If this method returns `Err`, then ownership of the memory block has not been transferred to
|
||||
/// this allocator, and the contents of the memory block are unaltered.
|
||||
|
Loading…
Reference in New Issue
Block a user