-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
std: fix sentinel handling in Allocator interface #23023
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Ah, it looks like zig1.wasm hasn't been updated with the new |
Should pub fn main() !void {
var a: [3:0]u8 = @splat(1);
a[3] = 4;
std.debug.print("{any}\n", .{a[0..4]});
} |
Is forbidding passing pointer-to-arrays to Language design-wise, a
|
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 |
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 |
Indeed, the wasm blob update is the only blocker I'm aware of. (Though it seems I also have a conflict to resolve) |
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 <[email protected]> References: ziglang#19984 References: ziglang#22706 References: ziglang#23020
The new CI failures look related FWIW. |
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 [email protected]
References: #19984
References: #22706
References: #23020