ziglang/zig
262
6.0k
Fork
You've already forked zig
777

libzigc: strdup, strndup, wcsdup #31935

Merged
andrewrk merged 11 commits from chrboesch/zig:libzigc_string into master 2026年04月22日 01:58:01 +02:00
Contributor
Copy link

This commit adds strdup and strndup based on musl.

Contributes to: #30978

This commit adds `strdup` and `strndup` based on musl. Contributes to: #30978
libzigc: strdup and strndup
Some checks failed
ci / x86_64-netbsd-release (pull_request) Failing after 26m2s
ci / x86_64-freebsd-release (pull_request) Failing after 30m51s
ci / x86_64-netbsd-debug (pull_request) Failing after 35m38s
ci / x86_64-freebsd-debug (pull_request) Failing after 39m9s
ci / aarch64-macos-release (pull_request) Failing after 49m49s
ci / aarch64-linux-release (pull_request) Failing after 55m26s
ci / powerpc64le-linux-release (pull_request) Failing after 44m6s
ci / aarch64-linux-debug (pull_request) Failing after 1h6m59s
ci / powerpc64le-linux-debug (pull_request) Failing after 54m5s
ci / aarch64-macos-debug (pull_request) Failing after 1h8m13s
ci / x86_64-linux-debug (pull_request) Failing after 14m18s
ci / x86_64-linux-debug-llvm (pull_request) Failing after 21m42s
ci / x86_64-linux-release (pull_request) Failing after 45m57s
ci / x86_64-openbsd-release (pull_request) Failing after 40m57s
ci / x86_64-openbsd-debug (pull_request) Failing after 57m7s
ci / s390x-linux-debug (pull_request) Failing after 38m18s
ci / s390x-linux-release (pull_request) Failing after 36m18s
ci / x86_64-windows-debug (pull_request) Failing after 1h13m46s
ci / x86_64-windows-release (pull_request) Failing after 1h5m17s
ci / aarch64-freebsd-debug (pull_request) Has been cancelled
ci / aarch64-freebsd-release (pull_request) Has been cancelled
ci / aarch64-netbsd-debug (pull_request) Has been cancelled
ci / aarch64-netbsd-release (pull_request) Has been cancelled
ci / loongarch64-linux-debug (pull_request) Has been cancelled
ci / loongarch64-linux-release (pull_request) Has been cancelled
ci / riscv64-linux-debug (pull_request) Has been cancelled
ci / riscv64-linux-release (pull_request) Has been cancelled
298eb55088

lmk if you want help understanding those failures. By the way, thanks a ton for your work maintaining ziglings!

lmk if you want help understanding those failures. By the way, thanks a ton for your work maintaining ziglings!
chrboesch changed title from (削除) libzigc: strdup and strndup (削除ここまで) to WIP: libzigc: strdup and strndup 2026年04月18日 12:26:57 +02:00
Author
Contributor
Copy link

Thank you very much, I gladly accept your help. After reading the error message, I think I've identified my mistake. I followed the Zig convention and expected an external allocator, which isn't the case with a C function (apart from the function signatures, which are also incorrect). Since nobody has yet implemented a function that requires malloc (at least I haven't found one), I lack the blueprint. However, I see that malloc has already been implemented and I am wondering how this is supposed to work: should I import malloc from malloc.zig, or what is the idea behind it, and is my analysis generally correct?

Thank you very much, I gladly accept your help. After reading the error message, I think I've identified my mistake. I followed the Zig convention and expected an external allocator, which isn't the case with a C function (apart from the function signatures, which are also incorrect). Since nobody has yet implemented a function that requires `malloc` (at least I haven't found one), I lack the blueprint. However, I see that `malloc` has already been implemented and I am wondering how this is supposed to work: should I import `malloc` from malloc.zig, or what is the idea behind it, and is my analysis generally correct?
Author
Contributor
Copy link

@andrewrk I have now found this closed PR #31144 and I think it contains the solution I am looking for, right?
edit: your explanation, I mean.

@andrewrk I have now found this closed PR #31144 and I think it contains the solution I am looking for, right? edit: your explanation, I mean.
andrewrk requested changes 2026年04月18日 18:50:00 +02:00
Dismissed
andrewrk left a comment
Copy link

Rather than additionally reviewing an old, abandoned PR, I'll just review yours, hopefully that helps :-)

Rather than additionally reviewing an old, abandoned PR, I'll just review yours, hopefully that helps :-)
lib/c/string.zig Outdated
@ -164,6 +166,18 @@ fn strtok(noalias maybe_str: ?[*:0]c_char, noalias values: [*:0]const c_char) ca
returnstrtok_r(maybe_str,values,&state.str);
}
fnstrdup(allocator:std.mem.Allocator,s:[]constu8)error{OutOfMemory}![]u8{
Owner
Copy link

Consider carefully what the function signature should be:

  • it should have the same number of arguments as the C function
  • it should have the same calling convention as the C function
  • note that slices and pointers are fundamentally different types
Consider carefully what the function signature should be: * it should have the same number of arguments as the C function * it should have the same calling convention as the C function * note that slices and pointers are fundamentally different types
chrboesch marked this conversation as resolved
lib/c/string.zig Outdated
@ -165,2 +167,4 @@
}
fnstrdup(allocator:std.mem.Allocator,s:[]constu8)error{OutOfMemory}![]u8{
returnallocator.dupe(u8,s);
Owner
Copy link

I recommend to port the musl logic directly rather than doing this.

I recommend to port the musl logic directly rather than doing this.
chrboesch marked this conversation as resolved
Author
Contributor
Copy link

Thanks. Now I have ported the musl logic directly, but I need malloc in string.zig. Should I make malloc in malloc.zig public and @import it, or declare it as extern fn in string.zig: extern fn malloc(size: usize) ?*anyopaque;?
But I could also extract a malloc_inner as you described in #31144

Thanks. Now I have ported the musl logic directly, but I need `malloc` in string.zig. Should I make `malloc` in malloc.zig public and @import it, or declare it as extern fn in string.zig: `extern fn malloc(size: usize) ?*anyopaque;`? But I could also extract a `malloc_inner` as you described in #31144
ported the musl logic directly
Some checks failed
ci / aarch64-linux-release (pull_request) Has been cancelled
ci / aarch64-linux-debug (pull_request) Has been cancelled
ci / aarch64-macos-release (pull_request) Has been cancelled
ci / aarch64-macos-debug (pull_request) Has been cancelled
ci / powerpc64le-linux-release (pull_request) Has been cancelled
ci / powerpc64le-linux-debug (pull_request) Has been cancelled
ci / s390x-linux-debug (pull_request) Has been cancelled
ci / s390x-linux-release (pull_request) Has been cancelled
ci / x86_64-linux-debug (pull_request) Has been cancelled
ci / x86_64-netbsd-debug (pull_request) Has been cancelled
ci / aarch64-freebsd-debug (pull_request) Has been cancelled
ci / x86_64-netbsd-release (pull_request) Has been cancelled
ci / aarch64-freebsd-release (pull_request) Has been cancelled
ci / x86_64-linux-release (pull_request) Has been cancelled
ci / x86_64-linux-debug-llvm (pull_request) Has been cancelled
ci / aarch64-netbsd-debug (pull_request) Has been cancelled
ci / aarch64-netbsd-release (pull_request) Has been cancelled
ci / loongarch64-linux-debug (pull_request) Has been cancelled
ci / loongarch64-linux-release (pull_request) Has been cancelled
ci / riscv64-linux-debug (pull_request) Has been cancelled
ci / riscv64-linux-release (pull_request) Has been cancelled
ci / x86_64-freebsd-debug (pull_request) Has been cancelled
ci / x86_64-freebsd-release (pull_request) Has been cancelled
ci / x86_64-openbsd-debug (pull_request) Has been cancelled
ci / x86_64-openbsd-release (pull_request) Has been cancelled
ci / x86_64-windows-debug (pull_request) Has been cancelled
ci / x86_64-windows-release (pull_request) Has been cancelled
65af80feb3
removed 'malloc_inner'tests
Some checks failed
ci / aarch64-linux-release (pull_request) Has been cancelled
ci / aarch64-linux-debug (pull_request) Has been cancelled
ci / s390x-linux-debug (pull_request) Has been cancelled
ci / s390x-linux-release (pull_request) Has been cancelled
ci / powerpc64le-linux-release (pull_request) Has been cancelled
ci / aarch64-macos-release (pull_request) Has been cancelled
ci / powerpc64le-linux-debug (pull_request) Has been cancelled
ci / aarch64-macos-debug (pull_request) Has been cancelled
ci / x86_64-freebsd-debug (pull_request) Has been cancelled
ci / x86_64-freebsd-release (pull_request) Has been cancelled
ci / x86_64-linux-debug-llvm (pull_request) Has been cancelled
ci / x86_64-linux-debug (pull_request) Has been cancelled
ci / x86_64-linux-release (pull_request) Has been cancelled
ci / x86_64-netbsd-debug (pull_request) Has been cancelled
ci / x86_64-netbsd-release (pull_request) Has been cancelled
ci / x86_64-openbsd-debug (pull_request) Has been cancelled
ci / x86_64-openbsd-release (pull_request) Has been cancelled
ci / aarch64-freebsd-debug (pull_request) Has been cancelled
ci / x86_64-windows-debug (pull_request) Has been cancelled
ci / x86_64-windows-release (pull_request) Has been cancelled
ci / aarch64-freebsd-release (pull_request) Has been cancelled
ci / aarch64-netbsd-debug (pull_request) Has been cancelled
ci / aarch64-netbsd-release (pull_request) Has been cancelled
ci / loongarch64-linux-debug (pull_request) Has been cancelled
ci / loongarch64-linux-release (pull_request) Has been cancelled
ci / riscv64-linux-debug (pull_request) Has been cancelled
ci / riscv64-linux-release (pull_request) Has been cancelled
6c298100e9

Any C functions you need you should get from std.c. In this case it looks like malloc is already there, so you should be good.

Any C functions you need you should get from `std.c`. In this case it looks like `malloc` is already there, so you should be good.
switched to /std/c.zig:malloc
Some checks are pending
ci / aarch64-freebsd-debug (pull_request) Waiting to run
ci / aarch64-freebsd-release (pull_request) Waiting to run
ci / aarch64-netbsd-debug (pull_request) Waiting to run
ci / aarch64-netbsd-release (pull_request) Waiting to run
ci / riscv64-linux-debug (pull_request) Waiting to run
ci / riscv64-linux-release (pull_request) Waiting to run
ci / x86_64-netbsd-release (pull_request) Successful in 34m23s
ci / x86_64-freebsd-release (pull_request) Successful in 38m36s
ci / x86_64-netbsd-debug (pull_request) Successful in 44m37s
ci / x86_64-freebsd-debug (pull_request) Successful in 47m16s
ci / x86_64-linux-debug (pull_request) Successful in 50m4s
ci / x86_64-windows-release (pull_request) Successful in 54m28s
ci / x86_64-openbsd-release (pull_request) Successful in 55m1s
ci / aarch64-macos-release (pull_request) Successful in 56m28s
ci / x86_64-windows-debug (pull_request) Successful in 1h5m28s
ci / x86_64-openbsd-debug (pull_request) Successful in 1h5m41s
ci / aarch64-macos-debug (pull_request) Successful in 1h25m0s
ci / s390x-linux-release (pull_request) Successful in 1h27m30s
ci / aarch64-linux-release (pull_request) Successful in 1h29m5s
ci / powerpc64le-linux-release (pull_request) Successful in 1h59m23s
ci / x86_64-linux-debug-llvm (pull_request) Successful in 2h22m16s
ci / aarch64-linux-debug (pull_request) Successful in 2h23m31s
ci / x86_64-linux-release (pull_request) Successful in 2h26m2s
ci / s390x-linux-debug (pull_request) Successful in 2h37m2s
ci / powerpc64le-linux-debug (pull_request) Successful in 3h27m57s
ci / loongarch64-linux-release (pull_request) Successful in 2h25m32s
ci / loongarch64-linux-debug (pull_request) Successful in 3h28m41s
480563eea5
Author
Contributor
Copy link

Now that I see it works, I will also take over the wasm function.

Now that I see it works, I will also take over the wasm function.
chrboesch changed title from (削除) WIP: libzigc: strdup and strndup (削除ここまで) to WIP: libzigc: strdup, strndup, wcsdup 2026年04月19日 00:20:29 +02:00
andrewrk requested changes 2026年04月19日 00:32:15 +02:00
Dismissed
lib/c/string.zig Outdated
@ -165,2 +168,4 @@
}
fnstrdup(str:[*:0]constc_char)callconv(.c)?[*:0]c_char{
conststr_u8:[*:0]constu8=@ptrCast(str);
Owner
Copy link

I think you should be able to implement these functions without this @ptrCast - please do that whenever possible, because it makes the code simpler and easier to verify. You'll still need one from malloc's return value, which is OK.

I think you should be able to implement these functions without this `@ptrCast` - please do that whenever possible, because it makes the code simpler and easier to verify. You'll still need one from malloc's return value, which is OK.
Author
Contributor
Copy link

done

done
chrboesch marked this conversation as resolved
added wcsdup and removed unnecessary pointer casts
Some checks are pending
ci / aarch64-freebsd-debug (pull_request) Waiting to run
ci / aarch64-freebsd-release (pull_request) Waiting to run
ci / aarch64-netbsd-debug (pull_request) Waiting to run
ci / aarch64-netbsd-release (pull_request) Waiting to run
ci / riscv64-linux-debug (pull_request) Waiting to run
ci / riscv64-linux-release (pull_request) Waiting to run
ci / x86_64-netbsd-release (pull_request) Successful in 29m31s
ci / x86_64-freebsd-release (pull_request) Successful in 38m1s
ci / x86_64-freebsd-debug (pull_request) Successful in 47m43s
ci / x86_64-linux-debug (pull_request) Successful in 52m18s
ci / x86_64-netbsd-debug (pull_request) Successful in 52m37s
ci / aarch64-macos-release (pull_request) Successful in 52m58s
ci / x86_64-openbsd-release (pull_request) Successful in 54m26s
ci / x86_64-windows-release (pull_request) Successful in 57m45s
ci / x86_64-openbsd-debug (pull_request) Successful in 1h0m14s
ci / x86_64-windows-debug (pull_request) Successful in 1h19m32s
ci / aarch64-macos-debug (pull_request) Successful in 1h20m22s
ci / powerpc64le-linux-release (pull_request) Successful in 1h30m7s
ci / aarch64-linux-release (pull_request) Successful in 1h30m41s
ci / s390x-linux-release (pull_request) Successful in 1h58m57s
ci / x86_64-linux-debug-llvm (pull_request) Successful in 2h15m29s
ci / x86_64-linux-release (pull_request) Successful in 2h28m22s
ci / aarch64-linux-debug (pull_request) Successful in 3h1m23s
ci / s390x-linux-debug (pull_request) Successful in 3h13m32s
ci / loongarch64-linux-release (pull_request) Successful in 2h36m25s
ci / loongarch64-linux-debug (pull_request) Successful in 3h12m37s
ci / powerpc64le-linux-debug (pull_request) Successful in 5h7m12s
50de39e021
chrboesch changed title from (削除) WIP: libzigc: strdup, strndup, wcsdup (削除ここまで) to libzigc: strdup, strndup, wcsdup 2026年04月19日 18:31:13 +02:00
andrewrk requested changes 2026年04月19日 19:44:42 +02:00
Dismissed
andrewrk left a comment
Copy link

The code in lib/std/c/test.zig goes in test/c/ somewhere.

wcsdup.c file should be deleted

The code in lib/std/c/test.zig goes in test/c/ somewhere. wcsdup.c file should be deleted
removed wcsdup.c amd moved tests to test/c
Some checks failed
ci / x86_64-netbsd-release (pull_request) Successful in 46m21s
ci / x86_64-freebsd-release (pull_request) Successful in 46m28s
ci / x86_64-freebsd-debug (pull_request) Successful in 1h4m2s
ci / x86_64-netbsd-debug (pull_request) Successful in 1h6m1s
ci / x86_64-windows-release (pull_request) Failing after 53m17s
ci / aarch64-macos-release (pull_request) Successful in 1h11m24s
ci / x86_64-openbsd-release (pull_request) Successful in 1h11m54s
ci / aarch64-macos-debug (pull_request) Successful in 1h21m44s
ci / x86_64-openbsd-debug (pull_request) Successful in 1h27m21s
ci / x86_64-linux-debug (pull_request) Successful in 1h28m28s
ci / aarch64-linux-release (pull_request) Has been cancelled
ci / powerpc64le-linux-debug (pull_request) Has been cancelled
ci / aarch64-linux-debug (pull_request) Has been cancelled
ci / x86_64-windows-debug (pull_request) Has been cancelled
ci / s390x-linux-release (pull_request) Has been cancelled
ci / x86_64-linux-release (pull_request) Has been cancelled
ci / s390x-linux-debug (pull_request) Has been cancelled
ci / x86_64-linux-debug-llvm (pull_request) Has been cancelled
ci / powerpc64le-linux-release (pull_request) Has been cancelled
ci / aarch64-freebsd-debug (pull_request) Has been cancelled
ci / aarch64-freebsd-release (pull_request) Has been cancelled
ci / aarch64-netbsd-debug (pull_request) Has been cancelled
ci / aarch64-netbsd-release (pull_request) Has been cancelled
ci / loongarch64-linux-debug (pull_request) Has been cancelled
ci / loongarch64-linux-release (pull_request) Has been cancelled
ci / riscv64-linux-debug (pull_request) Has been cancelled
ci / riscv64-linux-release (pull_request) Has been cancelled
13b49f6707
Author
Contributor
Copy link

I've moved all the tests to /test/c/string.zig, including wscdup. Is that okay, or should I create a separate test file for them?

I've moved all the tests to /test/c/string.zig, including `wscdup`. Is that okay, or should I create a separate test file for them?
fixed skipping tests for windows
Some checks are pending
ci / aarch64-freebsd-debug (pull_request) Waiting to run
ci / aarch64-freebsd-release (pull_request) Waiting to run
ci / aarch64-netbsd-debug (pull_request) Waiting to run
ci / aarch64-netbsd-release (pull_request) Waiting to run
ci / riscv64-linux-debug (pull_request) Waiting to run
ci / riscv64-linux-release (pull_request) Waiting to run
ci / x86_64-netbsd-release (pull_request) Successful in 36m6s
ci / x86_64-freebsd-release (pull_request) Successful in 38m41s
ci / x86_64-freebsd-debug (pull_request) Successful in 45m13s
ci / x86_64-netbsd-debug (pull_request) Successful in 45m46s
ci / aarch64-macos-release (pull_request) Successful in 53m3s
ci / x86_64-linux-debug (pull_request) Successful in 1h0m31s
ci / x86_64-openbsd-release (pull_request) Successful in 1h6m3s
ci / aarch64-macos-debug (pull_request) Successful in 1h11m32s
ci / x86_64-windows-debug (pull_request) Successful in 1h13m49s
ci / x86_64-openbsd-debug (pull_request) Successful in 1h15m35s
ci / x86_64-windows-release (pull_request) Successful in 1h15m30s
ci / powerpc64le-linux-release (pull_request) Successful in 1h21m51s
ci / aarch64-linux-release (pull_request) Successful in 1h28m4s
ci / s390x-linux-release (pull_request) Successful in 1h55m10s
ci / s390x-linux-debug (pull_request) Successful in 2h31m12s
ci / aarch64-linux-debug (pull_request) Successful in 2h48m41s
ci / x86_64-linux-release (pull_request) Successful in 2h55m5s
ci / x86_64-linux-debug-llvm (pull_request) Successful in 3h37m7s
ci / powerpc64le-linux-debug (pull_request) Successful in 4h4m47s
ci / loongarch64-linux-release (pull_request) Successful in 2h4m40s
ci / loongarch64-linux-debug (pull_request) Successful in 3h36m14s
92fdaf8b29
andrewrk requested changes 2026年04月20日 03:05:08 +02:00
Dismissed
lib/c/wchar.zig Outdated
@ -192,0 +197,4 @@
constsize=(len+1)*@sizeOf(wchar_t);
constd_opaque=c.malloc(size)orelsereturnnull;
constd:[*]wchar_t=@ptrCast(@alignCast(d_opaque));
_=wmemcpy(d,str,len+1);
Owner
Copy link

should be return wmemcpy(... like the musl source

should be `return wmemcpy(...` like the musl source
chrboesch marked this conversation as resolved
@ -13,0 +52,4 @@
trytesting.expectEqualStrings("Hello",std.mem.span(@as([*:0]constu8,copy3_u8)));
}
test"wcsdup"{
Owner
Copy link

Please move to a new test/c/wchar.zig file to maintain symmetry with the implementation code.

Please move to a new `test/c/wchar.zig` file to maintain symmetry with the implementation code.
Author
Contributor
Copy link

done

done
chrboesch marked this conversation as resolved
moved wasm tests to own file /test/c/wchar.zig
Some checks failed
ci / aarch64-linux-debug (pull_request) Has been cancelled
ci / aarch64-linux-release (pull_request) Has been cancelled
ci / aarch64-macos-release (pull_request) Has been cancelled
ci / aarch64-macos-debug (pull_request) Has been cancelled
ci / aarch64-freebsd-debug (pull_request) Has been cancelled
ci / aarch64-freebsd-release (pull_request) Has been cancelled
ci / aarch64-netbsd-debug (pull_request) Has been cancelled
ci / aarch64-netbsd-release (pull_request) Has been cancelled
ci / loongarch64-linux-debug (pull_request) Has been cancelled
ci / loongarch64-linux-release (pull_request) Has been cancelled
ci / powerpc64le-linux-debug (pull_request) Has been cancelled
ci / s390x-linux-debug (pull_request) Has been cancelled
ci / s390x-linux-release (pull_request) Has been cancelled
ci / powerpc64le-linux-release (pull_request) Has been cancelled
ci / riscv64-linux-debug (pull_request) Has been cancelled
ci / riscv64-linux-release (pull_request) Has been cancelled
ci / x86_64-freebsd-debug (pull_request) Has been cancelled
ci / x86_64-freebsd-release (pull_request) Has been cancelled
ci / x86_64-linux-debug (pull_request) Has been cancelled
ci / x86_64-linux-debug-llvm (pull_request) Has been cancelled
ci / x86_64-linux-release (pull_request) Has been cancelled
ci / x86_64-netbsd-debug (pull_request) Has been cancelled
ci / x86_64-netbsd-release (pull_request) Has been cancelled
ci / x86_64-openbsd-debug (pull_request) Has been cancelled
ci / x86_64-openbsd-release (pull_request) Has been cancelled
ci / x86_64-windows-debug (pull_request) Has been cancelled
ci / x86_64-windows-release (pull_request) Has been cancelled
02caf1453e
switched return to @ptrCast(wmemcpy(..
Some checks failed
ci / x86_64-freebsd-release (pull_request) Successful in 52m27s
ci / x86_64-netbsd-release (pull_request) Successful in 57m51s
ci / x86_64-freebsd-debug (pull_request) Successful in 1h5m45s
ci / x86_64-netbsd-debug (pull_request) Successful in 1h9m56s
ci / x86_64-windows-release (pull_request) Successful in 1h16m57s
ci / x86_64-openbsd-release (pull_request) Successful in 1h20m46s
ci / x86_64-openbsd-debug (pull_request) Successful in 1h23m10s
ci / x86_64-linux-debug (pull_request) Successful in 1h31m14s
ci / aarch64-macos-release (pull_request) Successful in 1h33m55s
ci / powerpc64le-linux-release (pull_request) Successful in 1h35m55s
ci / aarch64-linux-release (pull_request) Successful in 1h40m50s
ci / aarch64-macos-debug (pull_request) Successful in 1h56m25s
ci / s390x-linux-release (pull_request) Successful in 1h56m54s
ci / x86_64-windows-debug (pull_request) Successful in 1h56m46s
ci / aarch64-linux-debug (pull_request) Successful in 2h31m24s
ci / x86_64-linux-debug-llvm (pull_request) Successful in 2h54m53s
ci / s390x-linux-debug (pull_request) Successful in 3h5m21s
ci / x86_64-linux-release (pull_request) Successful in 3h8m10s
ci / powerpc64le-linux-debug (pull_request) Successful in 3h31m20s
ci / loongarch64-linux-debug (pull_request) Has been cancelled
ci / aarch64-freebsd-debug (pull_request) Has been cancelled
ci / aarch64-freebsd-release (pull_request) Has been cancelled
ci / aarch64-netbsd-debug (pull_request) Has been cancelled
ci / aarch64-netbsd-release (pull_request) Has been cancelled
ci / loongarch64-linux-release (pull_request) Has been cancelled
ci / riscv64-linux-debug (pull_request) Has been cancelled
ci / riscv64-linux-release (pull_request) Has been cancelled
5d8387a7cc
andrewrk requested changes 2026年04月20日 16:48:32 +02:00
Dismissed
@ -12,1 +12,4 @@
}
test"strdup"{
if(builtin.target.os.tag==.windows)return;// no strdup
Owner
Copy link

why do you think this?

why do you think this?
Author
Contributor
Copy link

UCRT on Windows does have _strdup, but as I understand it, that would only forward the test to their library and not test our Zig function.

UCRT on Windows does have _strdup, but as I understand it, that would only forward the test to their library and not test our Zig function.
Author
Contributor
Copy link

I don't really know much about Windows; I was just trying to understand how library calls work under Windows and where the error messages came from. If it turns out that's not the case and the tests do have the desired effect, I'll remove this skip again.

I don't really know much about Windows; I was just trying to understand how library calls work under Windows and where the error messages came from. If it turns out that's not the case and the tests do have the desired effect, I'll remove this skip again.
Owner
Copy link

As of #31923 being merged, we do want the libc API tests to run against all libc code, even if it's not ours.

According to https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/strdup-wcsdup, the strdup and wcsdup symbols in std.c should link to _strdup and _wcsdup on Windows (see the private namespace there for examples of how you can accomplish this without exposing both names).

It does appear that strndup doesn't exist on Windows, however, so the Windows check in that particular test is appropriate.

As of https://codeberg.org/ziglang/zig/pulls/31923 being merged, we do want the libc API tests to run against all libc code, even if it's not ours. According to https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/strdup-wcsdup, the `strdup` and `wcsdup` symbols in `std.c` should link to `_strdup` and `_wcsdup` on Windows (see the `private` namespace there for examples of how you can accomplish this without exposing both names). It does appear that `strndup` doesn't exist on Windows, however, so the Windows check in that particular test is appropriate.
Owner
Copy link

It does appear that strndup doesn't exist on Windows, however, so the Windows check in that particular test is appropriate.

Why don't we simply provide all the functions on all the targets?

> It does appear that strndup doesn't exist on Windows, however, so the Windows check in that particular test is appropriate. Why don't we simply provide all the functions on all the targets?
Owner
Copy link

Because we're matching existing libc ABIs. If we provide a symbol that the 'real' libc doesn't provide, it means that link tests in build systems will succeed where they shouldn't, and/or people will write code assuming the presence of a symbol only to discover that it's not there when using a compiler that isn't zig cc but which ostensibly targets the same ABI.

I'm not opposed to providing a better libc that doesn't have seemingly arbitrary gaps like this, but as with other questions that have to do with differences in the libc ABI surface or observable behavior, my opinion is that this should be done under a different std.Target.Abi tag.

Because we're matching existing libc ABIs. If we provide a symbol that the 'real' libc doesn't provide, it means that link tests in build systems will succeed where they shouldn't, and/or people will write code assuming the presence of a symbol only to discover that it's not there when using a compiler that isn't `zig cc` but which ostensibly targets the same ABI. I'm not opposed to providing a better libc that doesn't have seemingly arbitrary gaps like this, but as with other questions that have to do with differences in the libc ABI surface or observable behavior, my opinion is that this should be done under a different `std.Target.Abi` tag.
Owner
Copy link

but strndup has been part of posix since 2008

but `strndup` has been part of posix since 2008
Author
Contributor
Copy link

Now you're entering the world of standardization, and the question of why Microsoft doesn't adhere to standards fills thick files here. They prefer to define their own (mostly proprietary) things so that their competitors (if you can call them that) have a harder time.

Fortunately for everyone, things are changing a little (especially in the EU), but whether they will include strndup in their library is another matter. But how to deal with this now, I (unfortunately) cannot answer that question.

Now you're entering the world of standardization, and the question of why Microsoft doesn't adhere to standards fills thick files here. They prefer to define their own (mostly proprietary) things so that their competitors (if you can call them that) have a harder time. Fortunately for everyone, things are changing a little (especially in the EU), but whether they will include `strndup` in their library is another matter. But how to deal with this now, I (unfortunately) cannot answer that question.
Contributor
Copy link

strndup seems to also be C23 and added to mingw a few days ago.

`strndup` seems to also be C23 and [added to mingw](https://sourceforge.net/p/mingw-w64/mingw-w64/ci/250bb18f032236e7b26f42994437ac09f26b2872/) a few days ago.
chrboesch marked this conversation as resolved
removed unnecessary windows skips
Some checks failed
ci / aarch64-macos-release (pull_request) Successful in 1h0m58s
ci / x86_64-netbsd-release (pull_request) Successful in 44m59s
ci / powerpc64le-linux-release (pull_request) Successful in 1h28m30s
ci / x86_64-netbsd-debug (pull_request) Successful in 59m21s
ci / x86_64-freebsd-release (pull_request) Successful in 43m42s
ci / x86_64-freebsd-debug (pull_request) Successful in 59m32s
ci / aarch64-macos-debug (pull_request) Successful in 2h22m7s
ci / aarch64-linux-release (pull_request) Successful in 1h29m36s
ci / aarch64-linux-debug (pull_request) Successful in 2h25m18s
ci / powerpc64le-linux-debug (pull_request) Successful in 3h31m15s
ci / x86_64-linux-debug (pull_request) Successful in 1h10m26s
ci / x86_64-openbsd-release (pull_request) Successful in 1h13m12s
ci / x86_64-openbsd-debug (pull_request) Successful in 1h21m25s
ci / x86_64-windows-release (pull_request) Failing after 54m51s
ci / x86_64-windows-debug (pull_request) Failing after 1h19m36s
ci / x86_64-linux-debug-llvm (pull_request) Successful in 3h13m41s
ci / x86_64-linux-release (pull_request) Successful in 3h7m51s
ci / s390x-linux-release (pull_request) Successful in 3h14m15s
ci / s390x-linux-debug (pull_request) Successful in 5h29m41s
ci / loongarch64-linux-debug (pull_request) Has been cancelled
ci / loongarch64-linux-release (pull_request) Has been cancelled
ci / aarch64-freebsd-debug (pull_request) Has been cancelled
ci / aarch64-freebsd-release (pull_request) Has been cancelled
ci / aarch64-netbsd-debug (pull_request) Has been cancelled
ci / aarch64-netbsd-release (pull_request) Has been cancelled
ci / riscv64-linux-debug (pull_request) Has been cancelled
ci / riscv64-linux-release (pull_request) Has been cancelled
f301c253d9
Author
Contributor
Copy link

I've removed the skips except for strndup. If the feature is actually implemented, I can remove that skip later as well.

I've removed the skips except for `strndup`. If the feature is actually implemented, I can remove that skip later as well.
Merge branch 'master' into libzigc_string
Some checks failed
ci / x86_64-freebsd-release (pull_request) Successful in 42m48s
ci / x86_64-netbsd-release (pull_request) Successful in 42m45s
ci / x86_64-freebsd-debug (pull_request) Successful in 56m51s
ci / x86_64-netbsd-debug (pull_request) Successful in 1h1m49s
ci / x86_64-openbsd-release (pull_request) Successful in 1h9m47s
ci / aarch64-macos-release (pull_request) Successful in 1h22m18s
ci / x86_64-openbsd-debug (pull_request) Successful in 1h30m31s
ci / aarch64-linux-release (pull_request) Successful in 1h32m15s
ci / powerpc64le-linux-release (pull_request) Successful in 1h33m6s
ci / x86_64-windows-release (pull_request) Successful in 1h21m28s
ci / aarch64-macos-debug (pull_request) Successful in 1h53m39s
ci / x86_64-windows-debug (pull_request) Successful in 1h44m58s
ci / x86_64-linux-debug (pull_request) Successful in 1h16m33s
ci / aarch64-linux-debug (pull_request) Successful in 2h30m25s
ci / powerpc64le-linux-debug (pull_request) Successful in 2h52m27s
ci / x86_64-linux-debug-llvm (pull_request) Successful in 3h1m19s
ci / x86_64-linux-release (pull_request) Successful in 2h51m6s
ci / s390x-linux-release (pull_request) Successful in 1h30m0s
ci / s390x-linux-debug (pull_request) Successful in 2h57m4s
ci / loongarch64-linux-debug (pull_request) Successful in 3h25m6s
ci / aarch64-freebsd-debug (pull_request) Has been cancelled
ci / loongarch64-linux-release (pull_request) Has been cancelled
ci / aarch64-freebsd-release (pull_request) Has been cancelled
ci / aarch64-netbsd-debug (pull_request) Has been cancelled
ci / aarch64-netbsd-release (pull_request) Has been cancelled
ci / riscv64-linux-debug (pull_request) Has been cancelled
ci / riscv64-linux-release (pull_request) Has been cancelled
51d3e447bc
andrewrk left a comment
Copy link

OK, nice, it looks like this made it across the finish line.

OK, nice, it looks like this made it across the finish line.

3 down, 1855 to go!

3 down, 1855 to go!
Author
Contributor
Copy link

that's my blueprint now!

that's my blueprint now!
Sign in to join this conversation.
No reviewers
Labels
Clear labels
abi/f32
abi/ilp32
abi/sf
accepted
This proposal is planned.
arch/21k
arch/6502
arch/aarch64
arch/alpha
arch/amdgcn
arch/arc
arch/arc32
arch/arc64
arch/arm
arch/avr
arch/bfin
arch/bpf
arch/colossus
arch/cris
arch/csky
arch/dlx
arch/epiphany
arch/fr30
arch/frv
arch/hexagon
arch/hppa
arch/hppa64
arch/ia64
arch/kalimba
arch/kvx
arch/lanai
arch/lm32
arch/loongarch32
arch/loongarch64
arch/m32r
arch/m68k
arch/m88k
arch/mcore
arch/microblaze
arch/mips
arch/mips64
arch/mmix
arch/moxie
arch/mrisc32
arch/msp430
arch/nds32
arch/ns32k
arch/nvptx
arch/or1k
arch/powerpc
arch/powerpc64
arch/propeller
arch/riscv32
arch/riscv64
arch/rl78
arch/rx
arch/s390x
arch/sh
arch/sparc
arch/sparc64
arch/spirv
arch/spu
arch/tricore
arch/v850
arch/vax
arch/vc4
arch/ve
arch/wasm
arch/x86
arch/x86_64
arch/xcore
arch/xtensa
autodoc
The web application for interactive documentation and generation of its assets.
backend/c
The C backend outputs C source code.
backend/llvm
The LLVM backend outputs an LLVM bitcode module.
backend/self-hosted
The self-hosted backends produce machine code directly.
binutils
Zig's included binary utilities: zig ar, zig dlltool, zig lib, zig ranlib, zig objcopy, and zig rc.
breaking
Implementing this issue could cause existing code to no longer compile or have different behavior.
build system
The Zig build system - zig build, std.Build, the build runner, and package management.
debug info
An issue related to debug information (e.g. DWARF) produced by the Zig compiler.
docs
An issue with documentation, e.g. the language reference or standard library doc comments.
error message
This issue points out an error message that is unhelpful and should be improved.
frontend
Tokenization, parsing, AstGen, ZonGen, Sema, Legalize, and Liveness.
fuzzing
An issue related to Zig's integrated fuzz testing.
incremental
Reuse of internal compiler state for faster compilation.
lib/c
This issue relates to Zig's libc implementation and/or vendored libcs.
lib/compiler-rt
This issue relates to Zig's compiler-rt library.
lib/cxx
This issue relates to Zig's vendored libc++ and/or libc++abi.
lib/std
This issue relates to Zig's standard library.
lib/tsan
This issue relates to Zig's vendored libtsan.
lib/ubsan-rt
This issue relates to Zig's ubsan-rt library.
lib/unwind
This issue relates to Zig's vendored libunwind.
linking
Zig's integrated object file and incremental linker.
miscompilation
The compiler reports success but produces semantically incorrect code.
os/android
os/contiki
os/dragonfly
os/driverkit
os/emscripten
os/freebsd
os/fuchsia
os/haiku
os/hermit
os/hurd
os/illumos
os/ios
os/linux
os/maccatalyst
os/macos
os/managarm
os/netbsd
os/ohos
os/openbsd
os/plan9
os/redox
os/rtems
os/serenity
os/tvos
os/uefi
os/visionos
os/wasi
os/watchos
os/windows
proposal
This issue suggests language modifications. If it also has the "accepted" label then it is planned.
release notes
This issue or pull request should be mentioned in the release notes.
testing
This issue is related to testing the compiler, standard library, or other parts of Zig.
zig cc
Zig as a drop-in C-family compiler.
zig fmt
The Zig source code formatter.
zig reduce
The Zig source code reduction tool.
bounty
https://ziglang.org/news/announcing-donor-bounties
bug
Observed behavior contradicts documented or intended behavior.
contributor-friendly
This issue is limited in scope and/or knowledge of project internals.
downstream
An issue with a third-party project that uses this project.
enhancement
Solving this issue will likely involve adding new logic or components to the codebase.
infra
An issue related to project infrastructure, e.g. continuous integration.
optimization
A task to improve performance and/or resource usage.
question
No questions on the issue tracker; use a community space instead.
regression
Something that used to work in a previous version stopped working
upstream
An issue with a third-party project that this project uses.
use case
Describes a real use case that is difficult or impossible, but does not propose a solution.
No labels
abi/f32
abi/ilp32
abi/sf
accepted
arch/21k
arch/6502
arch/aarch64
arch/alpha
arch/amdgcn
arch/arc
arch/arc32
arch/arc64
arch/arm
arch/avr
arch/bfin
arch/bpf
arch/colossus
arch/cris
arch/csky
arch/dlx
arch/epiphany
arch/fr30
arch/frv
arch/hexagon
arch/hppa
arch/hppa64
arch/ia64
arch/kalimba
arch/kvx
arch/lanai
arch/lm32
arch/loongarch32
arch/loongarch64
arch/m32r
arch/m68k
arch/m88k
arch/mcore
arch/microblaze
arch/mips
arch/mips64
arch/mmix
arch/moxie
arch/mrisc32
arch/msp430
arch/nds32
arch/ns32k
arch/nvptx
arch/or1k
arch/powerpc
arch/powerpc64
arch/propeller
arch/riscv32
arch/riscv64
arch/rl78
arch/rx
arch/s390x
arch/sh
arch/sparc
arch/sparc64
arch/spirv
arch/spu
arch/tricore
arch/v850
arch/vax
arch/vc4
arch/ve
arch/wasm
arch/x86
arch/x86_64
arch/xcore
arch/xtensa
autodoc
backend/c
backend/llvm
backend/self-hosted
binutils
breaking
build system
debug info
docs
error message
frontend
fuzzing
incremental
lib/c
lib/compiler-rt
lib/cxx
lib/std
lib/tsan
lib/ubsan-rt
lib/unwind
linking
miscompilation
os/android
os/contiki
os/dragonfly
os/driverkit
os/emscripten
os/freebsd
os/fuchsia
os/haiku
os/hermit
os/hurd
os/illumos
os/ios
os/linux
os/maccatalyst
os/macos
os/managarm
os/netbsd
os/ohos
os/openbsd
os/plan9
os/redox
os/rtems
os/serenity
os/tvos
os/uefi
os/visionos
os/wasi
os/watchos
os/windows
proposal
release notes
testing
zig cc
zig fmt
zig reduce
bounty
bug
contributor-friendly
downstream
enhancement
infra
optimization
question
regression
upstream
use case
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
4 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ziglang/zig!31935
Reference in a new issue
ziglang/zig
No description provided.
Delete branch "chrboesch/zig:libzigc_string"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?