Hello,
In Zig 0.15 most File/Dir functions came in a few variants, for example (function signatures slightly simplified):
// The standard variant: accepts a path in the form of a regular u8 slice
pub fn openFile(self: Dir, sub_path: []const u8, ...)
// The '-Z' variant: the same as the standard variant but accepts a zero-terminated path.
// The standard
pub fn openFileZ(self: Dir, sub_path: [*:0]const u8, ...)
// The '-W' variant: Windows-specific, accepts a WTF-16 path.
// The standard variant would convert the path, then call this lower-level function.
pub fn openFileW(self: Dir, sub_path: []const u16, ...)
The path conversion performed by openFile before delegating to openFileW has been problematic for me on Windows:
- Since Zig code avoids hidden heap allocations, a fixed-size buffer large enough to hold any path is placed on the stack (in Zig 0.16 it is called
std.Io.Threaded.WindowsPathSpace) - This can result in stack overflows (found an old related issue: Big executable file when big variables (PathSpace) on stack · Issue #18849 · ziglang/zig · GitHub)
This issue could be avoided by manually ensuring paths are converted to WTF-16 beforehand (converting string literals in comptime or using a heap allocated buffer at runtime) and then calling openFileW directly, bypassing the code path that performs the conversion on the stack.
These ‘-W’ functions no longer exist in Zig 0.16 unfortunately. I totally get why these types of functions no longer exist in the new Io interface, however this makes my previous workaround impossible.
Do I have any options here other than just writing my own wrappers (or modifying the existing Zig ones) around std.os.windows?