-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
sliceAsBytes: include sentinel #19984
base: master
Are you sure you want to change the base?
Conversation
(This is a reboot of ziglang#18021 after pull request bankruptcy) * `sliceAsBytes()` includes the sentinel value if there is one * fixes 2 bugs the Allocator interface for resize and realloc (they assumed no sentinel before) * cleans up Allocator.free (was manually handling the sentinel) * cleans up resinator (was manually handling the sentinel) Also add `bytesAsSliceSentinel()` for completeness and because I want to use it in [dvui](https://github.com/david-vanderson/dvui) to provide storage for arbitrary user slices.
@@ -3835,6 +3835,7 @@ fn CopyPtrAttrs( | |||
comptime source: type, | |||
comptime size: std.builtin.Type.Pointer.Size, | |||
comptime child: type, | |||
comptime sentinel: ?*const anyopaque, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to me like this should be comptime sentinel: ?child
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried that first, but ran into a bunch of weird errors like error: comptime dereference requires '[:0]u8' to have a well-defined layout
(when a sentinel is present), and error: sentinels are only allowed on slices and unknown-length pointers
(when no sentinel).
I think there's something about how sentinels are represented at comptime that interferes with that, but I don't understand it. Can you make that work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Sorry I should have been clearer - I tried it originally with the first PR, and I tried it again after @InKryption commented and those are the errors I currently get (when trying comptime sentinel: ?child
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I'm doubting myself - let me recheck.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I get those errors when trying comptime sentinel: ?child
with zig version 0.13.0-dev.211+6a65561e3
(This is a reboot of #18021 after pull request bankruptcy)
sliceAsBytes()
includes the sentinel value if there is oneAlso add
bytesAsSliceSentinel()
for completeness and because I want to use it in dvui to provide storage for arbitrary user slices.