zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit e2f24a2d7096e4a28ba74513ed9473da0b7fb372 (tree)
parent c2db5d9cd1c83a5aed20a7e2ec8fdf874f13e3db
Author: Ilia Choly <ilia.choly@gmail.com>
Date:   Sun,  3 Nov 2024 09:47:57 -0500

Allocator.free: document zero-length behavior

It wasn't immediately clear from the implementation whether passing
zero-length memory to free() was undefined behavior or intentionally
supported. Since ArrayList and other core data structures rely on
this behavior working correctly, this should be explicitly documented
as part of the public API contract.

Diffstat:
Mlib/std/mem/Allocator.zig | 5+++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lib/std/mem/Allocator.zig b/lib/std/mem/Allocator.zig @@ -301,8 +301,9 @@ pub fn reallocAdvanced( return mem.bytesAsSlice(T, new_bytes); } -/// Free an array allocated with `alloc`. To free a single item, -/// see `destroy`. +/// Free an array allocated with `alloc`. +/// If memory has length 0, free is a no-op. +/// To free a single item, see `destroy`. pub fn free(self: Allocator, memory: anytype) void { const Slice = @typeInfo(@TypeOf(memory)).pointer; const bytes = mem.sliceAsBytes(memory);