Skip to content

fmt: handle printing sentinel terminated arrays - #21840

Closed
bangbangsheshotmedown wants to merge 6 commits into
ziglang:masterfrom
bangbangsheshotmedown:sentinel
Closed

fmt: handle printing sentinel terminated arrays#21840
bangbangsheshotmedown wants to merge 6 commits into
ziglang:masterfrom
bangbangsheshotmedown:sentinel

Conversation

@bangbangsheshotmedown

@bangbangsheshotmedownbangbangsheshotmedown commented Oct 28, 2024

Copy link
Copy Markdown

I came up with all that casting by trial&error, but something tells me that there should be a much simpler solution..

Comment threadlib/std/fmt.zig Outdated
@alexrp

Copy link
Copy Markdown
Member
test
+- test-modules
+- test-std
+- run test std-wasm32-wasi.0.1...0.2.2-musl-generic-Debug
+- zig test Debug wasm32-wasi 1 errors
/home/ci/actions-runner5/_work/zig/zig/lib/std/fmt.zig:668:90: error: @ptrCast increases pointer alignment
/home/ci/actions-runner5/_work/zig/zig/lib/std/fmt.zig:668:99: note: '*const anyopaque' has alignment '1'
/home/ci/actions-runner5/_work/zig/zig/lib/std/fmt.zig:668:90: note: '*const u16' has alignment '2'
/home/ci/actions-runner5/_work/zig/zig/lib/std/fmt.zig:668:90: note: use @alignCast to assert pointer alignment

@rohlem

Copy link
Copy Markdown
Contributor

With #22505 merged, the new implementation should just use .sentinel(), which takes care of all the casting. Something like (untested):

if (info.sentinel()) |s| {
constindex=std.mem.indexOfSentinel(info.child, s, value[0..]);
returnformatBuf(value[0..index], options, writer);
}

Comment threadlib/std/fmt.zig Outdated
@bangbangsheshotmedown

This comment was marked as abuse.

@Vexu

Vexu commented Jan 30, 2025

Copy link
Copy Markdown
Member

You do not need to build Zig to test changes to the standard library, you just need to point --zig-lib-dir at your modified lib directory.

https://github.com/ziglang/zig/wiki/Contributing#directly-testing-the-standard-library-with-zig-test

@ifreundifreund closed this Aug 26, 2025
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@bangbangsheshotmedown@alexrp@rohlem@Vexu@ifreund