diff options
| -rw-r--r-- | lib/compiler/translate-c/main.zig | 6 | ||||
| -rw-r--r-- | lib/std/Build/Cache/Path.zig | 10 | ||||
| -rw-r--r-- | lib/std/Thread.zig | 1 | ||||
| -rw-r--r-- | lib/std/debug/SelfInfo/Windows.zig | 19 | ||||
| -rw-r--r-- | lib/std/fs.zig | 11 | ||||
| -rw-r--r-- | lib/std/fs/Dir.zig | 24 | ||||
| -rw-r--r-- | lib/std/fs/test.zig | 4 | ||||
| -rw-r--r-- | lib/std/os.zig | 3 | ||||
| -rw-r--r-- | lib/std/os/windows.zig | 6 | ||||
| -rw-r--r-- | lib/std/posix.zig | 70 | ||||
| -rw-r--r-- | lib/std/unicode.zig | 13 | ||||
| -rw-r--r-- | lib/std/zig/system.zig | 2 |
12 files changed, 64 insertions, 105 deletions
diff --git a/lib/compiler/translate-c/main.zig b/lib/compiler/translate-c/main.zig index 3a3fd7577e..d0e8faf8c2 100644 --- a/lib/compiler/translate-c/main.zig +++ b/lib/compiler/translate-c/main.zig @@ -18,6 +18,10 @@ pub fn main() u8 { defer arena_instance.deinit(); const arena = arena_instance.allocator(); + var threaded: std.Io.Threaded = .init(gpa); + defer threaded.deinit(); + const io = threaded.io(); + var args = process.argsAlloc(arena) catch { std.debug.print("ran out of memory allocating arguments\n", .{}); if (fast_exit) process.exit(1); @@ -42,7 +46,7 @@ pub fn main() u8 { }; defer diagnostics.deinit(); - var comp = aro.Compilation.initDefault(gpa, arena, &diagnostics, std.fs.cwd()) catch |err| switch (err) { + var comp = aro.Compilation.initDefault(gpa, arena, io, &diagnostics, std.fs.cwd()) catch |err| switch (err) { error.OutOfMemory => { std.debug.print("ran out of memory initializing C compilation\n", .{}); if (fast_exit) process.exit(1); diff --git a/lib/std/Build/Cache/Path.zig b/lib/std/Build/Cache/Path.zig index bf16fc6814..92290cfdf4 100644 --- a/lib/std/Build/Cache/Path.zig +++ b/lib/std/Build/Cache/Path.zig @@ -1,5 +1,7 @@ const Path = @This(); + const std = @import("../../std.zig"); +const Io = std.Io; const assert = std.debug.assert; const fs = std.fs; const Allocator = std.mem.Allocator; @@ -119,7 +121,7 @@ pub fn atomicFile( return p.root_dir.handle.atomicFile(joined_path, options); } -pub fn access(p: Path, sub_path: []const u8, flags: fs.File.OpenFlags) !void { +pub fn access(p: Path, sub_path: []const u8, flags: Io.Dir.AccessOptions) !void { var buf: [fs.max_path_bytes]u8 = undefined; const joined_path = if (p.sub_path.len == 0) sub_path else p: { break :p std.fmt.bufPrint(&buf, "{s}" ++ fs.path.sep_str ++ "{s}", .{ @@ -151,7 +153,7 @@ pub fn fmtEscapeString(path: Path) std.fmt.Alt(Path, formatEscapeString) { return .{ .data = path }; } -pub fn formatEscapeString(path: Path, writer: *std.Io.Writer) std.Io.Writer.Error!void { +pub fn formatEscapeString(path: Path, writer: *Io.Writer) Io.Writer.Error!void { if (path.root_dir.path) |p| { try std.zig.stringEscape(p, writer); if (path.sub_path.len > 0) try std.zig.stringEscape(fs.path.sep_str, writer); @@ -167,7 +169,7 @@ pub fn fmtEscapeChar(path: Path) std.fmt.Alt(Path, formatEscapeChar) { } /// Deprecated, use double quoted escape to print paths. -pub fn formatEscapeChar(path: Path, writer: *std.Io.Writer) std.Io.Writer.Error!void { +pub fn formatEscapeChar(path: Path, writer: *Io.Writer) Io.Writer.Error!void { if (path.root_dir.path) |p| { for (p) |byte| try std.zig.charEscape(byte, writer); if (path.sub_path.len > 0) try writer.writeByte(fs.path.sep); @@ -177,7 +179,7 @@ pub fn formatEscapeChar(path: Path, writer: *std.Io.Writer) std.Io.Writer.Error! } } -pub fn format(self: Path, writer: *std.Io.Writer) std.Io.Writer.Error!void { +pub fn format(self: Path, writer: *Io.Writer) Io.Writer.Error!void { if (std.fs.path.isAbsolute(self.sub_path)) { try writer.writeAll(self.sub_path); return; diff --git a/lib/std/Thread.zig b/lib/std/Thread.zig index 9a602fbd6b..b5f950a08a 100644 --- a/lib/std/Thread.zig +++ b/lib/std/Thread.zig @@ -171,6 +171,7 @@ pub const SetNameError = error{ NameTooLong, Unsupported, Unexpected, + InvalidWtf8, } || posix.PrctlError || posix.WriteError || std.fs.File.OpenError || std.fmt.BufPrintError; pub fn setName(self: Thread, name: []const u8) SetNameError!void { diff --git a/lib/std/debug/SelfInfo/Windows.zig b/lib/std/debug/SelfInfo/Windows.zig index ea2fa96199..324b597d97 100644 --- a/lib/std/debug/SelfInfo/Windows.zig +++ b/lib/std/debug/SelfInfo/Windows.zig @@ -20,11 +20,11 @@ pub fn deinit(si: *SelfInfo, gpa: Allocator) void { module_name_arena.deinit(); } -pub fn getSymbol(si: *SelfInfo, gpa: Allocator, address: usize) Error!std.debug.Symbol { +pub fn getSymbol(si: *SelfInfo, gpa: Allocator, io: Io, address: usize) Error!std.debug.Symbol { si.mutex.lock(); defer si.mutex.unlock(); const module = try si.findModule(gpa, address); - const di = try module.getDebugInfo(gpa); + const di = try module.getDebugInfo(gpa, io); return di.getSymbol(gpa, address - module.base_address); } pub fn getModuleName(si: *SelfInfo, gpa: Allocator, address: usize) Error![]const u8 { @@ -190,6 +190,7 @@ const Module = struct { const DebugInfo = struct { arena: std.heap.ArenaAllocator.State, + io: Io, coff_image_base: u64, mapped_file: ?MappedFile, dwarf: ?Dwarf, @@ -209,9 +210,10 @@ const Module = struct { }; fn deinit(di: *DebugInfo, gpa: Allocator) void { + const io = di.io; if (di.dwarf) |*dwarf| dwarf.deinit(gpa); if (di.pdb) |*pdb| { - pdb.file_reader.file.close(); + pdb.file_reader.file.close(io); pdb.deinit(); } if (di.mapped_file) |*mf| mf.deinit(); @@ -277,11 +279,11 @@ const Module = struct { } }; - fn getDebugInfo(module: *Module, gpa: Allocator) Error!*DebugInfo { - if (module.di == null) module.di = loadDebugInfo(module, gpa); + fn getDebugInfo(module: *Module, gpa: Allocator, io: Io) Error!*DebugInfo { + if (module.di == null) module.di = loadDebugInfo(module, gpa, io); return if (module.di.?) |*di| di else |err| err; } - fn loadDebugInfo(module: *const Module, gpa: Allocator) Error!DebugInfo { + fn loadDebugInfo(module: *const Module, gpa: Allocator, io: Io) Error!DebugInfo { const mapped_ptr: [*]const u8 = @ptrFromInt(module.base_address); const mapped = mapped_ptr[0..module.size]; var coff_obj = coff.Coff.init(mapped, true) catch return error.InvalidDebugInfo; @@ -306,6 +308,7 @@ const Module = struct { ); if (len == 0) return error.MissingDebugInfo; const coff_file = fs.openFileAbsoluteW(name_buffer[0 .. len + 4 :0], .{}) catch |err| switch (err) { + error.Canceled => |e| return e, error.Unexpected => |e| return e, error.FileNotFound => return error.MissingDebugInfo, @@ -314,8 +317,6 @@ const Module = struct { error.NotDir, error.SymLinkLoop, error.NameTooLong, - error.InvalidUtf8, - error.InvalidWtf8, error.BadPathName, => return error.InvalidDebugInfo, @@ -435,7 +436,7 @@ const Module = struct { errdefer pdb_file.close(); const pdb_reader = try arena.create(Io.File.Reader); - pdb_reader.* = pdb_file.reader(try arena.alloc(u8, 4096)); + pdb_reader.* = pdb_file.reader(io, try arena.alloc(u8, 4096)); var pdb = Pdb.init(gpa, pdb_reader) catch |err| switch (err) { error.OutOfMemory, error.ReadFailed, error.Unexpected => |e| return e, diff --git a/lib/std/fs.zig b/lib/std/fs.zig index 395e18e6e5..7fae26cb62 100644 --- a/lib/std/fs.zig +++ b/lib/std/fs.zig @@ -500,7 +500,6 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 { var real_path_buf: [max_path_bytes]u8 = undefined; const real_path = std.posix.realpathZ(&symlink_path_buf, &real_path_buf) catch |err| switch (err) { - error.InvalidWtf8 => unreachable, // Windows-only error.NetworkNotFound => unreachable, // Windows-only else => |e| return e, }; @@ -511,15 +510,11 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 { } switch (native_os) { .linux, .serenity => return posix.readlinkZ("/proc/self/exe", out_buffer) catch |err| switch (err) { - error.InvalidUtf8 => unreachable, // WASI-only - error.InvalidWtf8 => unreachable, // Windows-only error.UnsupportedReparsePointType => unreachable, // Windows-only error.NetworkNotFound => unreachable, // Windows-only else => |e| return e, }, .illumos => return posix.readlinkZ("/proc/self/path/a.out", out_buffer) catch |err| switch (err) { - error.InvalidUtf8 => unreachable, // WASI-only - error.InvalidWtf8 => unreachable, // Windows-only error.UnsupportedReparsePointType => unreachable, // Windows-only error.NetworkNotFound => unreachable, // Windows-only else => |e| return e, @@ -548,7 +543,6 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 { // argv[0] is a path (relative or absolute): use realpath(3) directly var real_path_buf: [max_path_bytes]u8 = undefined; const real_path = posix.realpathZ(std.os.argv[0], &real_path_buf) catch |err| switch (err) { - error.InvalidWtf8 => unreachable, // Windows-only error.NetworkNotFound => unreachable, // Windows-only else => |e| return e, }; @@ -591,10 +585,7 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 { // that the symlink points to, though, so we need to get the realpath. var pathname_w = try windows.wToPrefixedFileW(null, image_path_name); - const wide_slice = std.fs.cwd().realpathW2(pathname_w.span(), &pathname_w.data) catch |err| switch (err) { - error.InvalidWtf8 => unreachable, - else => |e| return e, - }; + const wide_slice = try std.fs.cwd().realpathW2(pathname_w.span(), &pathname_w.data); const len = std.unicode.calcWtf8Len(wide_slice); if (len > out_buffer.len) diff --git a/lib/std/fs/Dir.zig b/lib/std/fs/Dir.zig index 5714d98e39..5187ab69a8 100644 --- a/lib/std/fs/Dir.zig +++ b/lib/std/fs/Dir.zig @@ -1472,11 +1472,9 @@ pub const DeleteDirError = error{ NotDir, SystemResources, ReadOnlyFileSystem, - /// WASI-only; file paths must be valid UTF-8. - InvalidUtf8, - /// Windows-only; file paths provided by the user must be valid WTF-8. + /// WASI: file paths must be valid UTF-8. + /// Windows: file paths provided by the user must be valid WTF-8. /// https://wtf-8.codeberg.page/ - InvalidWtf8, BadPathName, /// On Windows, `\\server` or `\\server\share` was not found. NetworkNotFound, @@ -1577,9 +1575,7 @@ pub fn symLink( // when converting to an NT namespaced path. CreateSymbolicLink in // symLinkW will handle the necessary conversion. var target_path_w: windows.PathSpace = undefined; - if (try std.unicode.checkWtf8ToWtf16LeOverflow(target_path, &target_path_w.data)) { - return error.NameTooLong; - } + try std.unicode.checkWtf8ToWtf16LeOverflow(target_path, &target_path_w.data); target_path_w.len = try std.unicode.wtf8ToWtf16Le(&target_path_w.data, target_path); target_path_w.data[target_path_w.len] = 0; // However, we need to canonicalize any path separators to `\`, since if @@ -1808,11 +1804,9 @@ pub const DeleteTreeError = error{ /// One of the path components was not a directory. /// This error is unreachable if `sub_path` does not contain a path separator. NotDir, - /// WASI-only; file paths must be valid UTF-8. - InvalidUtf8, - /// Windows-only; file paths provided by the user must be valid WTF-8. + /// WASI: file paths must be valid UTF-8. + /// Windows: file paths provided by the user must be valid WTF-8. /// https://wtf-8.codeberg.page/ - InvalidWtf8, /// On Windows, file paths cannot contain these characters: /// '/', '*', '?', '"', '<', '>', '|' BadPathName, @@ -1913,8 +1907,6 @@ pub fn deleteTree(self: Dir, sub_path: []const u8) DeleteTreeError!void { error.AccessDenied, error.PermissionDenied, - error.InvalidUtf8, - error.InvalidWtf8, error.SymLinkLoop, error.NameTooLong, error.SystemResources, @@ -1999,8 +1991,6 @@ pub fn deleteTree(self: Dir, sub_path: []const u8) DeleteTreeError!void { error.AccessDenied, error.PermissionDenied, - error.InvalidUtf8, - error.InvalidWtf8, error.SymLinkLoop, error.NameTooLong, error.SystemResources, @@ -2112,8 +2102,6 @@ fn deleteTreeMinStackSizeWithKindHint(self: Dir, sub_path: []const u8, kind_hint error.AccessDenied, error.PermissionDenied, - error.InvalidUtf8, - error.InvalidWtf8, error.SymLinkLoop, error.NameTooLong, error.SystemResources, @@ -2201,8 +2189,6 @@ fn deleteTreeOpenInitialSubpath(self: Dir, sub_path: []const u8, kind_hint: File error.AccessDenied, error.PermissionDenied, - error.InvalidUtf8, - error.InvalidWtf8, error.SymLinkLoop, error.NameTooLong, error.SystemResources, diff --git a/lib/std/fs/test.zig b/lib/std/fs/test.zig index a20be08fcb..75f35a46da 100644 --- a/lib/std/fs/test.zig +++ b/lib/std/fs/test.zig @@ -2019,8 +2019,8 @@ test "delete a setAsCwd directory on Windows" { test "invalid UTF-8/WTF-8 paths" { const expected_err = switch (native_os) { - .wasi => error.InvalidUtf8, - .windows => error.InvalidWtf8, + .wasi => error.BadPathName, + .windows => error.BadPathName, else => return error.SkipZigTest, }; diff --git a/lib/std/os.zig b/lib/std/os.zig index 8a2c606661..02fddb32b4 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -137,8 +137,6 @@ pub fn getFdPath(fd: std.posix.fd_t, out_buffer: *[max_path_bytes]u8) std.posix. switch (err) { error.NotLink => unreachable, error.BadPathName => unreachable, - error.InvalidUtf8 => unreachable, // WASI-only - error.InvalidWtf8 => unreachable, // Windows-only error.UnsupportedReparsePointType => unreachable, // Windows-only error.NetworkNotFound => unreachable, // Windows-only else => |e| return e, @@ -153,7 +151,6 @@ pub fn getFdPath(fd: std.posix.fd_t, out_buffer: *[max_path_bytes]u8) std.posix. const target = posix.readlinkZ(proc_path, out_buffer) catch |err| switch (err) { error.UnsupportedReparsePointType => unreachable, error.NotLink => unreachable, - error.InvalidUtf8 => unreachable, // WASI-only else => |e| return e, }; return target; diff --git a/lib/std/os/windows.zig b/lib/std/os/windows.zig index f36effe380..b4780ed203 100644 --- a/lib/std/os/windows.zig +++ b/lib/std/os/windows.zig @@ -2425,7 +2425,7 @@ pub fn normalizePath(comptime T: type, path: []T) RemoveDotDirsError!usize { return prefix_len + try removeDotDirsSanitized(T, path[prefix_len..new_len]); } -pub const Wtf8ToPrefixedFileWError = error{InvalidWtf8} || Wtf16ToPrefixedFileWError; +pub const Wtf8ToPrefixedFileWError = Wtf16ToPrefixedFileWError; /// Same as `sliceToPrefixedFileW` but accepts a pointer /// to a null-terminated WTF-8 encoded path. @@ -2438,7 +2438,9 @@ pub fn cStrToPrefixedFileW(dir: ?HANDLE, s: [*:0]const u8) Wtf8ToPrefixedFileWEr /// https://wtf-8.codeberg.page/ pub fn sliceToPrefixedFileW(dir: ?HANDLE, path: []const u8) Wtf8ToPrefixedFileWError!PathSpace { var temp_path: PathSpace = undefined; - temp_path.len = try std.unicode.wtf8ToWtf16Le(&temp_path.data, path); + temp_path.len = std.unicode.wtf8ToWtf16Le(&temp_path.data, path) catch |err| switch (err) { + error.InvalidWtf8 => return error.BadPathName, + }; temp_path.data[temp_path.len] = 0; return wToPrefixedFileW(dir, temp_path.span()); } diff --git a/lib/std/posix.zig b/lib/std/posix.zig index 358715a61f..697ba1a59a 100644 --- a/lib/std/posix.zig +++ b/lib/std/posix.zig @@ -486,8 +486,8 @@ fn fchmodat2(dirfd: fd_t, path: []const u8, mode: mode_t, flags: u32) FChmodAtEr const stat = fstatatZ(pathfd, "", AT.EMPTY_PATH) catch |err| switch (err) { error.NameTooLong => unreachable, error.FileNotFound => unreachable, - error.InvalidUtf8 => unreachable, error.Streaming => unreachable, + error.BadPathName => return error.Unexpected, error.Canceled => return error.Canceled, else => |e| return e, }; @@ -1914,14 +1914,9 @@ pub const SymLinkError = error{ ReadOnlyFileSystem, NotDir, NameTooLong, - - /// WASI-only; file paths must be valid UTF-8. - InvalidUtf8, - - /// Windows-only; file paths provided by the user must be valid WTF-8. + /// WASI: file paths must be valid UTF-8. + /// Windows: file paths provided by the user must be valid WTF-8. /// https://wtf-8.codeberg.page/ - InvalidWtf8, - BadPathName, } || UnexpectedError; @@ -2210,14 +2205,10 @@ pub const UnlinkError = error{ SystemResources, ReadOnlyFileSystem, - /// WASI-only; file paths must be valid UTF-8. - InvalidUtf8, - - /// Windows-only; file paths provided by the user must be valid WTF-8. + /// WASI: file paths must be valid UTF-8. + /// Windows: file paths provided by the user must be valid WTF-8. /// https://wtf-8.codeberg.page/ - InvalidWtf8, - - /// On Windows, file paths cannot contain these characters: + /// Windows: file paths cannot contain these characters: /// '/', '*', '?', '"', '<', '>', '|' BadPathName, @@ -2396,11 +2387,9 @@ pub const RenameError = error{ PathAlreadyExists, ReadOnlyFileSystem, RenameAcrossMountPoints, - /// WASI-only; file paths must be valid UTF-8. - InvalidUtf8, - /// Windows-only; file paths provided by the user must be valid WTF-8. + /// WASI: file paths must be valid UTF-8. + /// Windows: file paths provided by the user must be valid WTF-8. /// https://wtf-8.codeberg.page/ - InvalidWtf8, BadPathName, NoDevice, SharingViolation, @@ -2839,11 +2828,9 @@ pub const DeleteDirError = error{ NotDir, DirNotEmpty, ReadOnlyFileSystem, - /// WASI-only; file paths must be valid UTF-8. - InvalidUtf8, - /// Windows-only; file paths provided by the user must be valid WTF-8. + /// WASI: file paths must be valid UTF-8. + /// Windows: file paths provided by the user must be valid WTF-8. /// https://wtf-8.codeberg.page/ - InvalidWtf8, BadPathName, /// On Windows, `\\server` or `\\server\share` was not found. NetworkNotFound, @@ -2916,12 +2903,10 @@ pub const ChangeCurDirError = error{ FileNotFound, SystemResources, NotDir, - BadPathName, - /// WASI-only; file paths must be valid UTF-8. - InvalidUtf8, - /// Windows-only; file paths provided by the user must be valid WTF-8. + /// WASI: file paths must be valid UTF-8. + /// Windows: file paths provided by the user must be valid WTF-8. /// https://wtf-8.codeberg.page/ - InvalidWtf8, + BadPathName, } || UnexpectedError; /// Changes the current working directory of the calling process. @@ -2933,9 +2918,7 @@ pub fn chdir(dir_path: []const u8) ChangeCurDirError!void { @compileError("WASI does not support os.chdir"); } else if (native_os == .windows) { var wtf16_dir_path: [windows.PATH_MAX_WIDE]u16 = undefined; - if (try std.unicode.checkWtf8ToWtf16LeOverflow(dir_path, &wtf16_dir_path)) { - return error.NameTooLong; - } + try std.unicode.checkWtf8ToWtf16LeOverflow(dir_path, &wtf16_dir_path); const len = try std.unicode.wtf8ToWtf16Le(&wtf16_dir_path, dir_path); return chdirW(wtf16_dir_path[0..len]); } else { @@ -2952,9 +2935,7 @@ pub fn chdirZ(dir_path: [*:0]const u8) ChangeCurDirError!void { if (native_os == .windows) { const dir_path_span = mem.span(dir_path); var wtf16_dir_path: [windows.PATH_MAX_WIDE]u16 = undefined; - if (try std.unicode.checkWtf8ToWtf16LeOverflow(dir_path_span, &wtf16_dir_path)) { - return error.NameTooLong; - } + try std.unicode.checkWtf8ToWtf16LeOverflow(dir_path_span, &wtf16_dir_path); const len = try std.unicode.wtf8ToWtf16Le(&wtf16_dir_path, dir_path_span); return chdirW(wtf16_dir_path[0..len]); } else if (native_os == .wasi and !builtin.link_libc) { @@ -3016,11 +2997,9 @@ pub const ReadLinkError = error{ SystemResources, NotLink, NotDir, - /// WASI-only; file paths must be valid UTF-8. - InvalidUtf8, - /// Windows-only; file paths provided by the user must be valid WTF-8. + /// WASI: file paths must be valid UTF-8. + /// Windows: file paths provided by the user must be valid WTF-8. /// https://wtf-8.codeberg.page/ - InvalidWtf8, BadPathName, /// Windows-only. This error may occur if the opened reparse point is /// of unsupported type. @@ -4705,22 +4684,20 @@ pub const AccessError = error{ NameTooLong, InputOutput, SystemResources, - BadPathName, FileBusy, SymLinkLoop, ReadOnlyFileSystem, - /// WASI-only; file paths must be valid UTF-8. - InvalidUtf8, - /// Windows-only; file paths provided by the user must be valid WTF-8. + /// WASI: file paths must be valid UTF-8. + /// Windows: file paths provided by the user must be valid WTF-8. /// https://wtf-8.codeberg.page/ - InvalidWtf8, + BadPathName, Canceled, } || UnexpectedError; /// check user's permissions for a file /// /// * On Windows, asserts `path` is valid [WTF-8](https://wtf-8.codeberg.page/). -/// * On WASI, invalid UTF-8 passed to `path` causes `error.InvalidUtf8`. +/// * On WASI, invalid UTF-8 passed to `path` causes `error.BadPathName`. /// * On other platforms, `path` is an opaque sequence of bytes with no particular encoding. /// /// On Windows, `mode` is ignored. This is a POSIX API that is only partially supported by @@ -5154,16 +5131,15 @@ pub const RealPathError = error{ SystemResources, NoSpaceLeft, FileSystem, - BadPathName, DeviceBusy, ProcessNotFound, SharingViolation, PipeBusy, - /// Windows-only; file paths provided by the user must be valid WTF-8. + /// Windows: file paths provided by the user must be valid WTF-8. /// https://wtf-8.codeberg.page/ - InvalidWtf8, + BadPathName, /// On Windows, `\\server` or `\\server\share` was not found. NetworkNotFound, diff --git a/lib/std/unicode.zig b/lib/std/unicode.zig index 7fbf1094ba..2a6dca0d8a 100644 --- a/lib/std/unicode.zig +++ b/lib/std/unicode.zig @@ -1809,27 +1809,28 @@ pub fn wtf8ToWtf16Le(wtf16le: []u16, wtf8: []const u8) error{InvalidWtf8}!usize return utf8ToUtf16LeImpl(wtf16le, wtf8, .can_encode_surrogate_half); } -fn checkUtf8ToUtf16LeOverflowImpl(utf8: []const u8, utf16le: []const u16, comptime surrogates: Surrogates) !bool { +fn checkUtf8ToUtf16LeOverflowImpl(utf8: []const u8, utf16le: []const u16, comptime surrogates: Surrogates) !void { // Each u8 in UTF-8/WTF-8 correlates to at most one u16 in UTF-16LE/WTF-16LE. - if (utf16le.len >= utf8.len) return false; + if (utf16le.len >= utf8.len) return; const utf16_len = calcUtf16LeLenImpl(utf8, surrogates) catch { return switch (surrogates) { .cannot_encode_surrogate_half => error.InvalidUtf8, .can_encode_surrogate_half => error.InvalidWtf8, }; }; - return utf16_len > utf16le.len; + if (utf16_len > utf16le.len) + return error.NameTooLong; } /// Checks if calling `utf8ToUtf16Le` would overflow. Might fail if utf8 is not /// valid UTF-8. -pub fn checkUtf8ToUtf16LeOverflow(utf8: []const u8, utf16le: []const u16) error{InvalidUtf8}!bool { +pub fn checkUtf8ToUtf16LeOverflow(utf8: []const u8, utf16le: []const u16) error{ InvalidUtf8, NameTooLong }!void { return checkUtf8ToUtf16LeOverflowImpl(utf8, utf16le, .cannot_encode_surrogate_half); } /// Checks if calling `utf8ToUtf16Le` would overflow. Might fail if wtf8 is not /// valid WTF-8. -pub fn checkWtf8ToWtf16LeOverflow(wtf8: []const u8, wtf16le: []const u16) error{InvalidWtf8}!bool { +pub fn checkWtf8ToWtf16LeOverflow(wtf8: []const u8, wtf16le: []const u16) error{ InvalidWtf8, NameTooLong }!void { return checkUtf8ToUtf16LeOverflowImpl(wtf8, wtf16le, .can_encode_surrogate_half); } @@ -2039,7 +2040,7 @@ fn testRoundtripWtf8(wtf8: []const u8) !void { var wtf16_buf: [32]u16 = undefined; const wtf16_len = try wtf8ToWtf16Le(&wtf16_buf, wtf8); try testing.expectEqual(wtf16_len, calcWtf16LeLen(wtf8)); - try testing.expectEqual(false, checkWtf8ToWtf16LeOverflow(wtf8, &wtf16_buf)); + try checkWtf8ToWtf16LeOverflow(wtf8, &wtf16_buf); const wtf16 = wtf16_buf[0..wtf16_len]; var roundtripped_buf: [32]u8 = undefined; diff --git a/lib/std/zig/system.zig b/lib/std/zig/system.zig index 6313bff374..a2315b3ab9 100644 --- a/lib/std/zig/system.zig +++ b/lib/std/zig/system.zig @@ -674,8 +674,6 @@ fn abiAndDynamicLinkerFromFile( var link_buf: [posix.PATH_MAX]u8 = undefined; const link_name = posix.readlink(dl_path, &link_buf) catch |err| switch (err) { error.NameTooLong => unreachable, - error.InvalidUtf8 => unreachable, // WASI only - error.InvalidWtf8 => unreachable, // Windows only error.BadPathName => unreachable, // Windows only error.UnsupportedReparsePointType => unreachable, // Windows only error.NetworkNotFound => unreachable, // Windows only |
