| author | |
| committer | |
| log | e2f24a2d7096e4a28ba74513ed9473da0b7fb372 |
| tree | 0a1578713fd639963679874a900948649730a9d8 |
| parent | c2db5d9cd1c83a5aed20a7e2ec8fdf874f13e3db |
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.1 files changed, 3 insertions(+), 2 deletions(-)
lib/std/mem/Allocator.zig+3-2| ... | ... | @@ -301,8 +301,9 @@ pub fn reallocAdvanced( |
| 301 | 301 | return mem.bytesAsSlice(T, new_bytes); |
| 302 | 302 | } |
| 303 | 303 | |
| 304 | /// Free an array allocated with `alloc`. To free a single item, | |
| 305 | /// see `destroy`. | |
| 304 | /// Free an array allocated with `alloc`. | |
| 305 | /// If memory has length 0, free is a no-op. | |
| 306 | /// To free a single item, see `destroy`. | |
| 306 | 307 | pub fn free(self: Allocator, memory: anytype) void { |
| 307 | 308 | const Slice = @typeInfo(@TypeOf(memory)).pointer; |
| 308 | 309 | const bytes = mem.sliceAsBytes(memory); |