Uh oh!
There was an error while loading. Please reload this page.
std: fix sentinel handling in Allocator interface - #23023
Conversation
ifreund
commented
Feb 27, 2025
Ah, it looks like zig1.wasm hasn't been updated with the new |
Fri3dNstuff
commented
Feb 27, 2025
Should pubfnmain() !void {
vara: [3:0]u8=@splat(1);
a[3] =4;
std.debug.print("{any}\n", .{a[0..4]});
} |
castholm
commented
Feb 27, 2025
Is forbidding passing pointer-to-arrays to Language design-wise, a
|
ifreund
commented
Feb 28, 2025
On the contrary, this is intentional behavior.
In my mind, the answer of whether A pointer to an array can only be directly allocated with |
alexrp
commented
Mar 26, 2025
Is that the only thing blocking this PR? If so, I can go ahead and do an update since I'd also like to start using |
ifreund
commented
Mar 26, 2025
Indeed, the wasm blob update is the only blocker I'm aware of. (Though it seems I also have a conflict to resolve) |
alexrp
commented
Mar 27, 2025
ifreund
commented
Mar 27, 2025
alexrp
commented
Apr 15, 2025
The new CI failures look related FWIW. |
mlugg
commented
May 18, 2025
I just remembered this |
This will allow replacing (currently buggy) mem.sliceAsBytes() usage in the mem.Allocator implementation with, for example: const bytes: []u8 = @constcast(@ptrCast(mem.absorbSentinel(allocation))); References: ziglang#22706
Currently the only function that handles sentinel terminated slices properly is free. All other uses of mem.sliceAsBytes() in the allocator interface lack proper handling of a possible sentinel. This commit changes the Allocator interface to use @ptrCast() plus the new mem.absorbSentinel() instead. This also makes incorrectly passing a pointer to array to Allocator.free() a compile error. The proper function to free a pointer to an array is Allocator.destroy(). Reported-by: David Vanderson <david.vanderson@gmail.com> References: ziglang#19984 References: ziglang#22706 References: ziglang#23020
Currently the only function that handles sentinel terminated slices
properly is free. All other uses of mem.sliceAsBytes() in the allocator
interface lack proper handling of a possible sentinel.
This commit changes the Allocator interface to use @ptrCast() plus
the new mem.absorbSentinel() instead.
This also makes incorrectly passing a pointer to array to
Allocator.free() a compile error. The proper function to free a pointer
to an array is Allocator.destroy().
Reported-by: David Vanderson david.vanderson@gmail.com
References: #19984
References: #22706
References: #23020