| author | |
| committer | |
| log | 1dcfc8787e86ed94d216976e621a49fc488e8214 |
| tree | d5225fa3a0abee6f6ff8f2793fe1ccea951d20a8 |
| parent | 4be8be1d2bd6959efae7df95e3f5713adf953a42 |
16 files changed, 62 insertions(+), 62 deletions(-)
lib/compiler/std-docs.zig+4-2| ... | @@ -179,10 +179,11 @@ fn serveDocsFile( | ... | @@ -179,10 +179,11 @@ fn serveDocsFile( |
| 179 | content_type: []const u8, | 179 | content_type: []const u8, |
| 180 | ) !void { | 180 | ) !void { |
| 181 | const gpa = context.gpa; | 181 | const gpa = context.gpa; |
| 182 | const io = context.io; | ||
| 182 | // The desired API is actually sendfile, which will require enhancing std.http.Server. | 183 | // The desired API is actually sendfile, which will require enhancing std.http.Server. |
| 183 | // We load the file with every request so that the user can make changes to the file | 184 | // We load the file with every request so that the user can make changes to the file |
| 184 | // and refresh the HTML page without restarting this server. | 185 | // and refresh the HTML page without restarting this server. |
| 185 | const file_contents = try context.lib_dir.readFileAlloc(name, gpa, .limited(10 * 1024 * 1024)); | 186 | const file_contents = try context.lib_dir.readFileAlloc(io, name, gpa, .limited(10 * 1024 * 1024)); |
| 186 | defer gpa.free(file_contents); | 187 | defer gpa.free(file_contents); |
| 187 | try request.respond(file_contents, .{ | 188 | try request.respond(file_contents, .{ |
| 188 | .extra_headers = &.{ | 189 | .extra_headers = &.{ |
| ... | @@ -255,6 +256,7 @@ fn serveWasm( | ... | @@ -255,6 +256,7 @@ fn serveWasm( |
| 255 | optimize_mode: std.builtin.OptimizeMode, | 256 | optimize_mode: std.builtin.OptimizeMode, |
| 256 | ) !void { | 257 | ) !void { |
| 257 | const gpa = context.gpa; | 258 | const gpa = context.gpa; |
| 259 | const io = context.io; | ||
| 258 | 260 | ||
| 259 | var arena_instance = std.heap.ArenaAllocator.init(gpa); | 261 | var arena_instance = std.heap.ArenaAllocator.init(gpa); |
| 260 | defer arena_instance.deinit(); | 262 | defer arena_instance.deinit(); |
| ... | @@ -273,7 +275,7 @@ fn serveWasm( | ... | @@ -273,7 +275,7 @@ fn serveWasm( |
| 273 | }); | 275 | }); |
| 274 | // std.http.Server does not have a sendfile API yet. | 276 | // std.http.Server does not have a sendfile API yet. |
| 275 | const bin_path = try wasm_base_path.join(arena, bin_name); | 277 | const bin_path = try wasm_base_path.join(arena, bin_name); |
| 276 | const file_contents = try bin_path.root_dir.handle.readFileAlloc(bin_path.sub_path, gpa, .limited(10 * 1024 * 1024)); | 278 | const file_contents = try bin_path.root_dir.handle.readFileAlloc(io, bin_path.sub_path, gpa, .limited(10 * 1024 * 1024)); |
| 277 | defer gpa.free(file_contents); | 279 | defer gpa.free(file_contents); |
| 278 | try request.respond(file_contents, .{ | 280 | try request.respond(file_contents, .{ |
| 279 | .extra_headers = &.{ | 281 | .extra_headers = &.{ |
lib/std/Build/Cache.zig+2-1| ... | @@ -1075,7 +1075,8 @@ pub const Manifest = struct { | ... | @@ -1075,7 +1075,8 @@ pub const Manifest = struct { |
| 1075 | 1075 | ||
| 1076 | fn addDepFileMaybePost(self: *Manifest, dir: Io.Dir, dep_file_sub_path: []const u8) !void { | 1076 | fn addDepFileMaybePost(self: *Manifest, dir: Io.Dir, dep_file_sub_path: []const u8) !void { |
| 1077 | const gpa = self.cache.gpa; | 1077 | const gpa = self.cache.gpa; |
| 1078 | const dep_file_contents = try dir.readFileAlloc(dep_file_sub_path, gpa, .limited(manifest_file_size_max)); | 1078 | const io = self.cache.io; |
| 1079 | const dep_file_contents = try dir.readFileAlloc(io, dep_file_sub_path, gpa, .limited(manifest_file_size_max)); | ||
| 1079 | defer gpa.free(dep_file_contents); | 1080 | defer gpa.free(dep_file_contents); |
| 1080 | 1081 | ||
| 1081 | var error_buf: std.ArrayList(u8) = .empty; | 1082 | var error_buf: std.ArrayList(u8) = .empty; |
lib/std/Build/Step/CheckFile.zig+2-1| ... | @@ -51,11 +51,12 @@ pub fn setName(check_file: *CheckFile, name: []const u8) void { | ... | @@ -51,11 +51,12 @@ pub fn setName(check_file: *CheckFile, name: []const u8) void { |
| 51 | fn make(step: *Step, options: Step.MakeOptions) !void { | 51 | fn make(step: *Step, options: Step.MakeOptions) !void { |
| 52 | _ = options; | 52 | _ = options; |
| 53 | const b = step.owner; | 53 | const b = step.owner; |
| 54 | const io = b.graph.io; | ||
| 54 | const check_file: *CheckFile = @fieldParentPtr("step", step); | 55 | const check_file: *CheckFile = @fieldParentPtr("step", step); |
| 55 | try step.singleUnchangingWatchInput(check_file.source); | 56 | try step.singleUnchangingWatchInput(check_file.source); |
| 56 | 57 | ||
| 57 | const src_path = check_file.source.getPath2(b, step); | 58 | const src_path = check_file.source.getPath2(b, step); |
| 58 | const contents = Io.Dir.cwd().readFileAlloc(src_path, b.allocator, .limited(check_file.max_bytes)) catch |err| { | 59 | const contents = Io.Dir.cwd().readFileAlloc(io, src_path, b.allocator, .limited(check_file.max_bytes)) catch |err| { |
| 59 | return step.fail("unable to read '{s}': {s}", .{ | 60 | return step.fail("unable to read '{s}': {s}", .{ |
| 60 | src_path, @errorName(err), | 61 | src_path, @errorName(err), |
| 61 | }); | 62 | }); |
lib/std/Build/Step/ConfigHeader.zig+2-2| ... | @@ -208,7 +208,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void { | ... | @@ -208,7 +208,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void { |
| 208 | .autoconf_undef, .autoconf_at => |file_source| { | 208 | .autoconf_undef, .autoconf_at => |file_source| { |
| 209 | try bw.writeAll(c_generated_line); | 209 | try bw.writeAll(c_generated_line); |
| 210 | const src_path = file_source.getPath2(b, step); | 210 | const src_path = file_source.getPath2(b, step); |
| 211 | const contents = Io.Dir.cwd().readFileAlloc(src_path, arena, .limited(config_header.max_bytes)) catch |err| { | 211 | const contents = Io.Dir.cwd().readFileAlloc(io, src_path, arena, .limited(config_header.max_bytes)) catch |err| { |
| 212 | return step.fail("unable to read autoconf input file '{s}': {s}", .{ | 212 | return step.fail("unable to read autoconf input file '{s}': {s}", .{ |
| 213 | src_path, @errorName(err), | 213 | src_path, @errorName(err), |
| 214 | }); | 214 | }); |
| ... | @@ -222,7 +222,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void { | ... | @@ -222,7 +222,7 @@ fn make(step: *Step, options: Step.MakeOptions) !void { |
| 222 | .cmake => |file_source| { | 222 | .cmake => |file_source| { |
| 223 | try bw.writeAll(c_generated_line); | 223 | try bw.writeAll(c_generated_line); |
| 224 | const src_path = file_source.getPath2(b, step); | 224 | const src_path = file_source.getPath2(b, step); |
| 225 | const contents = Io.Dir.cwd().readFileAlloc(src_path, arena, .limited(config_header.max_bytes)) catch |err| { | 225 | const contents = Io.Dir.cwd().readFileAlloc(io, src_path, arena, .limited(config_header.max_bytes)) catch |err| { |
| 226 | return step.fail("unable to read cmake input file '{s}': {s}", .{ | 226 | return step.fail("unable to read cmake input file '{s}': {s}", .{ |
| 227 | src_path, @errorName(err), | 227 | src_path, @errorName(err), |
| 228 | }); | 228 | }); |
lib/std/Build/WebServer.zig+3-2| ... | @@ -469,11 +469,12 @@ pub fn serveFile( | ... | @@ -469,11 +469,12 @@ pub fn serveFile( |
| 469 | content_type: []const u8, | 469 | content_type: []const u8, |
| 470 | ) !void { | 470 | ) !void { |
| 471 | const gpa = ws.gpa; | 471 | const gpa = ws.gpa; |
| 472 | const io = ws.graph.io; | ||
| 472 | // The desired API is actually sendfile, which will require enhancing http.Server. | 473 | // The desired API is actually sendfile, which will require enhancing http.Server. |
| 473 | // We load the file with every request so that the user can make changes to the file | 474 | // We load the file with every request so that the user can make changes to the file |
| 474 | // and refresh the HTML page without restarting this server. | 475 | // and refresh the HTML page without restarting this server. |
| 475 | const file_contents = path.root_dir.handle.readFileAlloc(path.sub_path, gpa, .limited(10 * 1024 * 1024)) catch |err| { | 476 | const file_contents = path.root_dir.handle.readFileAlloc(io, path.sub_path, gpa, .limited(10 * 1024 * 1024)) catch |err| { |
| 476 | log.err("failed to read '{f}': {s}", .{ path, @errorName(err) }); | 477 | log.err("failed to read '{f}': {t}", .{ path, err }); |
| 477 | return error.AlreadyReported; | 478 | return error.AlreadyReported; |
| 478 | }; | 479 | }; |
| 479 | defer gpa.free(file_contents); | 480 | defer gpa.free(file_contents); |
lib/std/Io/Dir.zig+3-3| ... | @@ -1117,10 +1117,10 @@ pub fn readLink(dir: Dir, io: Io, sub_path: []const u8, buffer: []u8) ReadLinkEr | ... | @@ -1117,10 +1117,10 @@ pub fn readLink(dir: Dir, io: Io, sub_path: []const u8, buffer: []u8) ReadLinkEr |
| 1117 | /// On other platforms, `path` is an opaque sequence of bytes with no particular encoding. | 1117 | /// On other platforms, `path` is an opaque sequence of bytes with no particular encoding. |
| 1118 | pub fn readLinkAbsolute(io: Io, absolute_path: []const u8, buffer: []u8) ReadLinkError!usize { | 1118 | pub fn readLinkAbsolute(io: Io, absolute_path: []const u8, buffer: []u8) ReadLinkError!usize { |
| 1119 | assert(path.isAbsolute(absolute_path)); | 1119 | assert(path.isAbsolute(absolute_path)); |
| 1120 | return io.vtable.dirReadLink(io.userdata, .cwd(), path, buffer); | 1120 | return io.vtable.dirReadLink(io.userdata, .cwd(), absolute_path, buffer); |
| 1121 | } | 1121 | } |
| 1122 | 1122 | ||
| 1123 | pub const ReadFileAllocError = File.OpenError || File.ReadError || Allocator.Error || error{ | 1123 | pub const ReadFileAllocError = File.OpenError || File.Reader.Error || Allocator.Error || error{ |
| 1124 | /// File size reached or exceeded the provided limit. | 1124 | /// File size reached or exceeded the provided limit. |
| 1125 | StreamTooLong, | 1125 | StreamTooLong, |
| 1126 | }; | 1126 | }; |
| ... | @@ -1603,7 +1603,7 @@ pub const CopyFileOptions = struct { | ... | @@ -1603,7 +1603,7 @@ pub const CopyFileOptions = struct { |
| 1603 | 1603 | ||
| 1604 | pub const CopyFileError = File.OpenError || File.StatError || | 1604 | pub const CopyFileError = File.OpenError || File.StatError || |
| 1605 | File.Atomic.InitError || File.Atomic.FinishError || | 1605 | File.Atomic.InitError || File.Atomic.FinishError || |
| 1606 | File.ReadError || File.WriteError || error{InvalidFileName}; | 1606 | File.Reader.Error || File.WriteError || error{InvalidFileName}; |
| 1607 | 1607 | ||
| 1608 | /// Atomically creates a new file at `dest_path` within `dest_dir` with the | 1608 | /// Atomically creates a new file at `dest_path` within `dest_dir` with the |
| 1609 | /// same contents as `source_path` within `source_dir`, overwriting any already | 1609 | /// same contents as `source_path` within `source_dir`, overwriting any already |
lib/std/crypto/Certificate/Bundle/macos.zig+1-2| ... | @@ -17,9 +17,8 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator, io: Io, now: Io.Timestamp) RescanM | ... | @@ -17,9 +17,8 @@ pub fn rescanMac(cb: *Bundle, gpa: Allocator, io: Io, now: Io.Timestamp) RescanM |
| 17 | "/Library/Keychains/System.keychain", | 17 | "/Library/Keychains/System.keychain", |
| 18 | }; | 18 | }; |
| 19 | 19 | ||
| 20 | _ = io; // TODO migrate file system to use std.Io | ||
| 21 | for (keychain_paths) |keychain_path| { | 20 | for (keychain_paths) |keychain_path| { |
| 22 | const bytes = Io.Dir.cwd().readFileAlloc(keychain_path, gpa, .limited(std.math.maxInt(u32))) catch |err| switch (err) { | 21 | const bytes = Io.Dir.cwd().readFileAlloc(io, keychain_path, gpa, .limited(std.math.maxInt(u32))) catch |err| switch (err) { |
| 23 | error.StreamTooLong => return error.FileTooBig, | 22 | error.StreamTooLong => return error.FileTooBig, |
| 24 | else => |e| return e, | 23 | else => |e| return e, |
| 25 | }; | 24 | }; |
lib/std/fs/test.zig+14-13| ... | @@ -767,7 +767,7 @@ test "readFileAlloc" { | ... | @@ -767,7 +767,7 @@ test "readFileAlloc" { |
| 767 | var file = try tmp_dir.dir.createFile(io, "test_file", .{ .read = true }); | 767 | var file = try tmp_dir.dir.createFile(io, "test_file", .{ .read = true }); |
| 768 | defer file.close(io); | 768 | defer file.close(io); |
| 769 | 769 | ||
| 770 | const buf1 = try tmp_dir.dir.readFileAlloc("test_file", testing.allocator, .limited(1024)); | 770 | const buf1 = try tmp_dir.dir.readFileAlloc(io, "test_file", testing.allocator, .limited(1024)); |
| 771 | defer testing.allocator.free(buf1); | 771 | defer testing.allocator.free(buf1); |
| 772 | try testing.expectEqualStrings("", buf1); | 772 | try testing.expectEqualStrings("", buf1); |
| 773 | 773 | ||
| ... | @@ -776,7 +776,7 @@ test "readFileAlloc" { | ... | @@ -776,7 +776,7 @@ test "readFileAlloc" { |
| 776 | 776 | ||
| 777 | { | 777 | { |
| 778 | // max_bytes > file_size | 778 | // max_bytes > file_size |
| 779 | const buf2 = try tmp_dir.dir.readFileAlloc("test_file", testing.allocator, .limited(1024)); | 779 | const buf2 = try tmp_dir.dir.readFileAlloc(io, "test_file", testing.allocator, .limited(1024)); |
| 780 | defer testing.allocator.free(buf2); | 780 | defer testing.allocator.free(buf2); |
| 781 | try testing.expectEqualStrings(write_buf, buf2); | 781 | try testing.expectEqualStrings(write_buf, buf2); |
| 782 | } | 782 | } |
| ... | @@ -785,13 +785,13 @@ test "readFileAlloc" { | ... | @@ -785,13 +785,13 @@ test "readFileAlloc" { |
| 785 | // max_bytes == file_size | 785 | // max_bytes == file_size |
| 786 | try testing.expectError( | 786 | try testing.expectError( |
| 787 | error.StreamTooLong, | 787 | error.StreamTooLong, |
| 788 | tmp_dir.dir.readFileAlloc("test_file", testing.allocator, .limited(write_buf.len)), | 788 | tmp_dir.dir.readFileAlloc(io, "test_file", testing.allocator, .limited(write_buf.len)), |
| 789 | ); | 789 | ); |
| 790 | } | 790 | } |
| 791 | 791 | ||
| 792 | { | 792 | { |
| 793 | // max_bytes == file_size + 1 | 793 | // max_bytes == file_size + 1 |
| 794 | const buf2 = try tmp_dir.dir.readFileAlloc("test_file", testing.allocator, .limited(write_buf.len + 1)); | 794 | const buf2 = try tmp_dir.dir.readFileAlloc(io, "test_file", testing.allocator, .limited(write_buf.len + 1)); |
| 795 | defer testing.allocator.free(buf2); | 795 | defer testing.allocator.free(buf2); |
| 796 | try testing.expectEqualStrings(write_buf, buf2); | 796 | try testing.expectEqualStrings(write_buf, buf2); |
| 797 | } | 797 | } |
| ... | @@ -799,7 +799,7 @@ test "readFileAlloc" { | ... | @@ -799,7 +799,7 @@ test "readFileAlloc" { |
| 799 | // max_bytes < file_size | 799 | // max_bytes < file_size |
| 800 | try testing.expectError( | 800 | try testing.expectError( |
| 801 | error.StreamTooLong, | 801 | error.StreamTooLong, |
| 802 | tmp_dir.dir.readFileAlloc("test_file", testing.allocator, .limited(write_buf.len - 1)), | 802 | tmp_dir.dir.readFileAlloc(io, "test_file", testing.allocator, .limited(write_buf.len - 1)), |
| 803 | ); | 803 | ); |
| 804 | } | 804 | } |
| 805 | 805 | ||
| ... | @@ -877,16 +877,16 @@ test "file operations on directories" { | ... | @@ -877,16 +877,16 @@ test "file operations on directories" { |
| 877 | switch (native_os) { | 877 | switch (native_os) { |
| 878 | .dragonfly, .netbsd => { | 878 | .dragonfly, .netbsd => { |
| 879 | // no error when reading a directory. See https://github.com/ziglang/zig/issues/5732 | 879 | // no error when reading a directory. See https://github.com/ziglang/zig/issues/5732 |
| 880 | const buf = try ctx.dir.readFileAlloc(test_dir_name, testing.allocator, .unlimited); | 880 | const buf = try ctx.dir.readFileAlloc(io, test_dir_name, testing.allocator, .unlimited); |
| 881 | testing.allocator.free(buf); | 881 | testing.allocator.free(buf); |
| 882 | }, | 882 | }, |
| 883 | .wasi => { | 883 | .wasi => { |
| 884 | // WASI return EBADF, which gets mapped to NotOpenForReading. | 884 | // WASI return EBADF, which gets mapped to NotOpenForReading. |
| 885 | // See https://github.com/bytecodealliance/wasmtime/issues/1935 | 885 | // See https://github.com/bytecodealliance/wasmtime/issues/1935 |
| 886 | try testing.expectError(error.NotOpenForReading, ctx.dir.readFileAlloc(test_dir_name, testing.allocator, .unlimited)); | 886 | try testing.expectError(error.NotOpenForReading, ctx.dir.readFileAlloc(io, test_dir_name, testing.allocator, .unlimited)); |
| 887 | }, | 887 | }, |
| 888 | else => { | 888 | else => { |
| 889 | try testing.expectError(error.IsDir, ctx.dir.readFileAlloc(test_dir_name, testing.allocator, .unlimited)); | 889 | try testing.expectError(error.IsDir, ctx.dir.readFileAlloc(io, test_dir_name, testing.allocator, .unlimited)); |
| 890 | }, | 890 | }, |
| 891 | } | 891 | } |
| 892 | 892 | ||
| ... | @@ -1679,14 +1679,14 @@ test "copyFile" { | ... | @@ -1679,14 +1679,14 @@ test "copyFile" { |
| 1679 | try ctx.dir.copyFile(src_file, ctx.dir, dest_file2, .{ .override_mode = File.default_mode }); | 1679 | try ctx.dir.copyFile(src_file, ctx.dir, dest_file2, .{ .override_mode = File.default_mode }); |
| 1680 | defer ctx.dir.deleteFile(dest_file2) catch {}; | 1680 | defer ctx.dir.deleteFile(dest_file2) catch {}; |
| 1681 | 1681 | ||
| 1682 | try expectFileContents(ctx.dir, dest_file, data); | 1682 | try expectFileContents(io, ctx.dir, dest_file, data); |
| 1683 | try expectFileContents(ctx.dir, dest_file2, data); | 1683 | try expectFileContents(io, ctx.dir, dest_file2, data); |
| 1684 | } | 1684 | } |
| 1685 | }.impl); | 1685 | }.impl); |
| 1686 | } | 1686 | } |
| 1687 | 1687 | ||
| 1688 | fn expectFileContents(dir: Dir, file_path: []const u8, data: []const u8) !void { | 1688 | fn expectFileContents(io: Io, dir: Dir, file_path: []const u8, data: []const u8) !void { |
| 1689 | const contents = try dir.readFileAlloc(file_path, testing.allocator, .limited(1000)); | 1689 | const contents = try dir.readFileAlloc(io, file_path, testing.allocator, .limited(1000)); |
| 1690 | defer testing.allocator.free(contents); | 1690 | defer testing.allocator.free(contents); |
| 1691 | 1691 | ||
| 1692 | try testing.expectEqualSlices(u8, data, contents); | 1692 | try testing.expectEqualSlices(u8, data, contents); |
| ... | @@ -1695,6 +1695,7 @@ fn expectFileContents(dir: Dir, file_path: []const u8, data: []const u8) !void { | ... | @@ -1695,6 +1695,7 @@ fn expectFileContents(dir: Dir, file_path: []const u8, data: []const u8) !void { |
| 1695 | test "AtomicFile" { | 1695 | test "AtomicFile" { |
| 1696 | try testWithAllSupportedPathTypes(struct { | 1696 | try testWithAllSupportedPathTypes(struct { |
| 1697 | fn impl(ctx: *TestContext) !void { | 1697 | fn impl(ctx: *TestContext) !void { |
| 1698 | const io = ctx.io; | ||
| 1698 | const allocator = ctx.arena.allocator(); | 1699 | const allocator = ctx.arena.allocator(); |
| 1699 | const test_out_file = try ctx.transformPath("tmp_atomic_file_test_dest.txt"); | 1700 | const test_out_file = try ctx.transformPath("tmp_atomic_file_test_dest.txt"); |
| 1700 | const test_content = | 1701 | const test_content = |
| ... | @@ -1709,7 +1710,7 @@ test "AtomicFile" { | ... | @@ -1709,7 +1710,7 @@ test "AtomicFile" { |
| 1709 | try af.file_writer.interface.writeAll(test_content); | 1710 | try af.file_writer.interface.writeAll(test_content); |
| 1710 | try af.finish(); | 1711 | try af.finish(); |
| 1711 | } | 1712 | } |
| 1712 | const content = try ctx.dir.readFileAlloc(test_out_file, allocator, .limited(9999)); | 1713 | const content = try ctx.dir.readFileAlloc(io, test_out_file, allocator, .limited(9999)); |
| 1713 | try testing.expectEqualStrings(test_content, content); | 1714 | try testing.expectEqualStrings(test_content, content); |
| 1714 | 1715 | ||
| 1715 | try ctx.dir.deleteFile(test_out_file); | 1716 | try ctx.dir.deleteFile(test_out_file); |
lib/std/zig/LibCInstallation.zig+2-6| ... | @@ -37,11 +37,7 @@ pub const FindError = error{ | ... | @@ -37,11 +37,7 @@ pub const FindError = error{ |
| 37 | ZigIsTheCCompiler, | 37 | ZigIsTheCCompiler, |
| 38 | }; | 38 | }; |
| 39 | 39 | ||
| 40 | pub fn parse( | 40 | pub fn parse(allocator: Allocator, io: Io, libc_file: []const u8, target: *const std.Target) !LibCInstallation { |
| 41 | allocator: Allocator, | ||
| 42 | libc_file: []const u8, | ||
| 43 | target: *const std.Target, | ||
| 44 | ) !LibCInstallation { | ||
| 45 | var self: LibCInstallation = .{}; | 41 | var self: LibCInstallation = .{}; |
| 46 | 42 | ||
| 47 | const fields = std.meta.fields(LibCInstallation); | 43 | const fields = std.meta.fields(LibCInstallation); |
| ... | @@ -57,7 +53,7 @@ pub fn parse( | ... | @@ -57,7 +53,7 @@ pub fn parse( |
| 57 | } | 53 | } |
| 58 | } | 54 | } |
| 59 | 55 | ||
| 60 | const contents = try Io.Dir.cwd().readFileAlloc(libc_file, allocator, .limited(std.math.maxInt(usize))); | 56 | const contents = try Io.Dir.cwd().readFileAlloc(io, libc_file, allocator, .limited(std.math.maxInt(usize))); |
| 61 | defer allocator.free(contents); | 57 | defer allocator.free(contents); |
| 62 | 58 | ||
| 63 | var it = std.mem.tokenizeScalar(u8, contents, '\n'); | 59 | var it = std.mem.tokenizeScalar(u8, contents, '\n'); |
lib/std/zig/WindowsSdk.zig+1-1| ... | @@ -775,7 +775,7 @@ const MsvcLibDir = struct { | ... | @@ -775,7 +775,7 @@ const MsvcLibDir = struct { |
| 775 | writer.writeByte(std.fs.path.sep) catch unreachable; | 775 | writer.writeByte(std.fs.path.sep) catch unreachable; |
| 776 | writer.writeAll("state.json") catch unreachable; | 776 | writer.writeAll("state.json") catch unreachable; |
| 777 | 777 | ||
| 778 | const json_contents = instances_dir.readFileAlloc(writer.buffered(), allocator, .limited(std.math.maxInt(usize))) catch continue; | 778 | const json_contents = instances_dir.readFileAlloc(io, writer.buffered(), allocator, .limited(std.math.maxInt(usize))) catch continue; |
| 779 | defer allocator.free(json_contents); | 779 | defer allocator.free(json_contents); |
| 780 | 780 | ||
| 781 | var parsed = std.json.parseFromSlice(std.json.Value, allocator, json_contents, .{}) catch continue; | 781 | var parsed = std.json.parseFromSlice(std.json.Value, allocator, json_contents, .{}) catch continue; |
src/Compilation.zig+2-2| ... | @@ -6400,7 +6400,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Pr | ... | @@ -6400,7 +6400,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Pr |
| 6400 | 6400 | ||
| 6401 | if (comp.file_system_inputs != null) { | 6401 | if (comp.file_system_inputs != null) { |
| 6402 | // Use the same file size limit as the cache code does for dependency files. | 6402 | // Use the same file size limit as the cache code does for dependency files. |
| 6403 | const dep_file_contents = try zig_cache_tmp_dir.readFileAlloc(dep_basename, gpa, .limited(Cache.manifest_file_size_max)); | 6403 | const dep_file_contents = try zig_cache_tmp_dir.readFileAlloc(io, dep_basename, gpa, .limited(Cache.manifest_file_size_max)); |
| 6404 | defer gpa.free(dep_file_contents); | 6404 | defer gpa.free(dep_file_contents); |
| 6405 | 6405 | ||
| 6406 | var str_buf: std.ArrayList(u8) = .empty; | 6406 | var str_buf: std.ArrayList(u8) = .empty; |
| ... | @@ -6665,7 +6665,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32 | ... | @@ -6665,7 +6665,7 @@ fn updateWin32Resource(comp: *Compilation, win32_resource: *Win32Resource, win32 |
| 6665 | // Read depfile and update cache manifest | 6665 | // Read depfile and update cache manifest |
| 6666 | { | 6666 | { |
| 6667 | const dep_basename = fs.path.basename(out_dep_path); | 6667 | const dep_basename = fs.path.basename(out_dep_path); |
| 6668 | const dep_file_contents = try zig_cache_tmp_dir.readFileAlloc(dep_basename, arena, .limited(50 * 1024 * 1024)); | 6668 | const dep_file_contents = try zig_cache_tmp_dir.readFileAlloc(io, dep_basename, arena, .limited(50 * 1024 * 1024)); |
| 6669 | defer arena.free(dep_file_contents); | 6669 | defer arena.free(dep_file_contents); |
| 6670 | 6670 | ||
| 6671 | const value = try std.json.parseFromSliceLeaky(std.json.Value, arena, dep_file_contents, .{}); | 6671 | const value = try std.json.parseFromSliceLeaky(std.json.Value, arena, dep_file_contents, .{}); |
src/Package/Fetch/git.zig+2-2| ... | @@ -1602,7 +1602,7 @@ fn runRepositoryTest(io: Io, comptime format: Oid.Format, head_commit: []const u | ... | @@ -1602,7 +1602,7 @@ fn runRepositoryTest(io: Io, comptime format: Oid.Format, head_commit: []const u |
| 1602 | const max_file_size = 8192; | 1602 | const max_file_size = 8192; |
| 1603 | 1603 | ||
| 1604 | if (!skip_checksums) { | 1604 | if (!skip_checksums) { |
| 1605 | const index_file_data = try git_dir.dir.readFileAlloc("testrepo.idx", testing.allocator, .limited(max_file_size)); | 1605 | const index_file_data = try git_dir.dir.readFileAlloc(io, "testrepo.idx", testing.allocator, .limited(max_file_size)); |
| 1606 | defer testing.allocator.free(index_file_data); | 1606 | defer testing.allocator.free(index_file_data); |
| 1607 | // testrepo.idx is generated by Git. The index created by this file should | 1607 | // testrepo.idx is generated by Git. The index created by this file should |
| 1608 | // match it exactly. Running `git verify-pack -v testrepo.pack` can verify | 1608 | // match it exactly. Running `git verify-pack -v testrepo.pack` can verify |
| ... | @@ -1678,7 +1678,7 @@ fn runRepositoryTest(io: Io, comptime format: Oid.Format, head_commit: []const u | ... | @@ -1678,7 +1678,7 @@ fn runRepositoryTest(io: Io, comptime format: Oid.Format, head_commit: []const u |
| 1678 | \\revision 19 | 1678 | \\revision 19 |
| 1679 | \\ | 1679 | \\ |
| 1680 | ; | 1680 | ; |
| 1681 | const actual_file_contents = try worktree.dir.readFileAlloc("file", testing.allocator, .limited(max_file_size)); | 1681 | const actual_file_contents = try worktree.dir.readFileAlloc(io, "file", testing.allocator, .limited(max_file_size)); |
| 1682 | defer testing.allocator.free(actual_file_contents); | 1682 | defer testing.allocator.free(actual_file_contents); |
| 1683 | try testing.expectEqualStrings(expected_file_contents, actual_file_contents); | 1683 | try testing.expectEqualStrings(expected_file_contents, actual_file_contents); |
| 1684 | } | 1684 | } |
src/link.zig+2-2| ... | @@ -624,12 +624,12 @@ pub const File = struct { | ... | @@ -624,12 +624,12 @@ pub const File = struct { |
| 624 | try emit.root_dir.handle.rename(tmp_sub_path, emit.root_dir.handle, emit.sub_path, io); | 624 | try emit.root_dir.handle.rename(tmp_sub_path, emit.root_dir.handle, emit.sub_path, io); |
| 625 | switch (builtin.os.tag) { | 625 | switch (builtin.os.tag) { |
| 626 | .linux => std.posix.ptrace(std.os.linux.PTRACE.ATTACH, pid, 0, 0) catch |err| { | 626 | .linux => std.posix.ptrace(std.os.linux.PTRACE.ATTACH, pid, 0, 0) catch |err| { |
| 627 | log.warn("ptrace failure: {s}", .{@errorName(err)}); | 627 | log.warn("ptrace failure: {t}", .{err}); |
| 628 | }, | 628 | }, |
| 629 | .maccatalyst, .macos => { | 629 | .maccatalyst, .macos => { |
| 630 | const macho_file = base.cast(.macho).?; | 630 | const macho_file = base.cast(.macho).?; |
| 631 | macho_file.ptraceAttach(pid) catch |err| { | 631 | macho_file.ptraceAttach(pid) catch |err| { |
| 632 | log.warn("attaching failed with error: {s}", .{@errorName(err)}); | 632 | log.warn("attaching failed with error: {t}", .{err}); |
| 633 | }; | 633 | }; |
| 634 | }, | 634 | }, |
| 635 | .windows => unreachable, | 635 | .windows => unreachable, |
src/link/MachO.zig+5-3| ... | @@ -4347,11 +4347,13 @@ fn inferSdkVersion(comp: *Compilation, sdk_layout: SdkLayout) ?std.SemanticVersi | ... | @@ -4347,11 +4347,13 @@ fn inferSdkVersion(comp: *Compilation, sdk_layout: SdkLayout) ?std.SemanticVersi |
| 4347 | defer arena_allocator.deinit(); | 4347 | defer arena_allocator.deinit(); |
| 4348 | const arena = arena_allocator.allocator(); | 4348 | const arena = arena_allocator.allocator(); |
| 4349 | 4349 | ||
| 4350 | const io = comp.io; | ||
| 4351 | |||
| 4350 | const sdk_dir = switch (sdk_layout) { | 4352 | const sdk_dir = switch (sdk_layout) { |
| 4351 | .sdk => comp.sysroot.?, | 4353 | .sdk => comp.sysroot.?, |
| 4352 | .vendored => fs.path.join(arena, &.{ comp.dirs.zig_lib.path.?, "libc", "darwin" }) catch return null, | 4354 | .vendored => fs.path.join(arena, &.{ comp.dirs.zig_lib.path.?, "libc", "darwin" }) catch return null, |
| 4353 | }; | 4355 | }; |
| 4354 | if (readSdkVersionFromSettings(arena, sdk_dir)) |ver| { | 4356 | if (readSdkVersionFromSettings(arena, io, sdk_dir)) |ver| { |
| 4355 | return parseSdkVersion(ver); | 4357 | return parseSdkVersion(ver); |
| 4356 | } else |_| { | 4358 | } else |_| { |
| 4357 | // Read from settings should always succeed when vendored. | 4359 | // Read from settings should always succeed when vendored. |
| ... | @@ -4374,9 +4376,9 @@ fn inferSdkVersion(comp: *Compilation, sdk_layout: SdkLayout) ?std.SemanticVersi | ... | @@ -4374,9 +4376,9 @@ fn inferSdkVersion(comp: *Compilation, sdk_layout: SdkLayout) ?std.SemanticVersi |
| 4374 | // Official Apple SDKs ship with a `SDKSettings.json` located at the top of SDK fs layout. | 4376 | // Official Apple SDKs ship with a `SDKSettings.json` located at the top of SDK fs layout. |
| 4375 | // Use property `MinimalDisplayName` to determine version. | 4377 | // Use property `MinimalDisplayName` to determine version. |
| 4376 | // The file/property is also available with vendored libc. | 4378 | // The file/property is also available with vendored libc. |
| 4377 | fn readSdkVersionFromSettings(arena: Allocator, dir: []const u8) ![]const u8 { | 4379 | fn readSdkVersionFromSettings(arena: Allocator, io: Io, dir: []const u8) ![]const u8 { |
| 4378 | const sdk_path = try fs.path.join(arena, &.{ dir, "SDKSettings.json" }); | 4380 | const sdk_path = try fs.path.join(arena, &.{ dir, "SDKSettings.json" }); |
| 4379 | const contents = try Io.Dir.cwd().readFileAlloc(sdk_path, arena, .limited(std.math.maxInt(u16))); | 4381 | const contents = try Io.Dir.cwd().readFileAlloc(io, sdk_path, arena, .limited(std.math.maxInt(u16))); |
| 4380 | const parsed = try std.json.parseFromSlice(std.json.Value, arena, contents, .{}); | 4382 | const parsed = try std.json.parseFromSlice(std.json.Value, arena, contents, .{}); |
| 4381 | if (parsed.value.object.get("MinimalDisplayName")) |ver| return ver.string; | 4383 | if (parsed.value.object.get("MinimalDisplayName")) |ver| return ver.string; |
| 4382 | return error.SdkVersionFailure; | 4384 | return error.SdkVersionFailure; |
src/link/MachO/CodeSignature.zig+8-8| ... | @@ -17,6 +17,12 @@ const MachO = @import("../MachO.zig"); | ... | @@ -17,6 +17,12 @@ const MachO = @import("../MachO.zig"); |
| 17 | 17 | ||
| 18 | const hash_size = Sha256.digest_length; | 18 | const hash_size = Sha256.digest_length; |
| 19 | 19 | ||
| 20 | page_size: u16, | ||
| 21 | code_directory: CodeDirectory, | ||
| 22 | requirements: ?Requirements = null, | ||
| 23 | entitlements: ?Entitlements = null, | ||
| 24 | signature: ?Signature = null, | ||
| 25 | |||
| 20 | const Blob = union(enum) { | 26 | const Blob = union(enum) { |
| 21 | code_directory: *CodeDirectory, | 27 | code_directory: *CodeDirectory, |
| 22 | requirements: *Requirements, | 28 | requirements: *Requirements, |
| ... | @@ -220,12 +226,6 @@ const Signature = struct { | ... | @@ -220,12 +226,6 @@ const Signature = struct { |
| 220 | } | 226 | } |
| 221 | }; | 227 | }; |
| 222 | 228 | ||
| 223 | page_size: u16, | ||
| 224 | code_directory: CodeDirectory, | ||
| 225 | requirements: ?Requirements = null, | ||
| 226 | entitlements: ?Entitlements = null, | ||
| 227 | signature: ?Signature = null, | ||
| 228 | |||
| 229 | pub fn init(page_size: u16) CodeSignature { | 229 | pub fn init(page_size: u16) CodeSignature { |
| 230 | return .{ | 230 | return .{ |
| 231 | .page_size = page_size, | 231 | .page_size = page_size, |
| ... | @@ -246,8 +246,8 @@ pub fn deinit(self: *CodeSignature, allocator: Allocator) void { | ... | @@ -246,8 +246,8 @@ pub fn deinit(self: *CodeSignature, allocator: Allocator) void { |
| 246 | } | 246 | } |
| 247 | } | 247 | } |
| 248 | 248 | ||
| 249 | pub fn addEntitlements(self: *CodeSignature, allocator: Allocator, path: []const u8) !void { | 249 | pub fn addEntitlements(self: *CodeSignature, allocator: Allocator, io: Io, path: []const u8) !void { |
| 250 | const inner = try Io.Dir.cwd().readFileAlloc(path, allocator, .limited(std.math.maxInt(u32))); | 250 | const inner = try Io.Dir.cwd().readFileAlloc(io, path, allocator, .limited(std.math.maxInt(u32))); |
| 251 | self.entitlements = .{ .inner = inner }; | 251 | self.entitlements = .{ .inner = inner }; |
| 252 | } | 252 | } |
| 253 | 253 |
src/main.zig+9-12| ... | @@ -1029,9 +1029,8 @@ fn buildOutputType( | ... | @@ -1029,9 +1029,8 @@ fn buildOutputType( |
| 1029 | if (mem.cutPrefix(u8, arg, "@")) |resp_file_path| { | 1029 | if (mem.cutPrefix(u8, arg, "@")) |resp_file_path| { |
| 1030 | // This is a "compiler response file". We must parse the file and treat its | 1030 | // This is a "compiler response file". We must parse the file and treat its |
| 1031 | // contents as command line parameters. | 1031 | // contents as command line parameters. |
| 1032 | args_iter.resp_file = initArgIteratorResponseFile(arena, resp_file_path) catch |err| { | 1032 | args_iter.resp_file = initArgIteratorResponseFile(arena, io, resp_file_path) catch |err| |
| 1033 | fatal("unable to read response file '{s}': {s}", .{ resp_file_path, @errorName(err) }); | 1033 | fatal("unable to read response file '{s}': {t}", .{ resp_file_path, err }); |
| 1034 | }; | ||
| 1035 | } else if (mem.startsWith(u8, arg, "-")) { | 1034 | } else if (mem.startsWith(u8, arg, "-")) { |
| 1036 | if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) { | 1035 | if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) { |
| 1037 | try Io.File.stdout().writeAll(usage_build_generic); | 1036 | try Io.File.stdout().writeAll(usage_build_generic); |
| ... | @@ -5441,7 +5440,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) | ... | @@ -5441,7 +5440,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) |
| 5441 | // that are missing. | 5440 | // that are missing. |
| 5442 | const s = fs.path.sep_str; | 5441 | const s = fs.path.sep_str; |
| 5443 | const tmp_sub_path = "tmp" ++ s ++ results_tmp_file_nonce; | 5442 | const tmp_sub_path = "tmp" ++ s ++ results_tmp_file_nonce; |
| 5444 | const stdout = dirs.local_cache.handle.readFileAlloc(tmp_sub_path, arena, .limited(50 * 1024 * 1024)) catch |err| { | 5443 | const stdout = dirs.local_cache.handle.readFileAlloc(io, tmp_sub_path, arena, .limited(50 * 1024 * 1024)) catch |err| { |
| 5445 | fatal("unable to read results of configure phase from '{f}{s}': {s}", .{ | 5444 | fatal("unable to read results of configure phase from '{f}{s}': {s}", .{ |
| 5446 | dirs.local_cache, tmp_sub_path, @errorName(err), | 5445 | dirs.local_cache, tmp_sub_path, @errorName(err), |
| 5447 | }); | 5446 | }); |
| ... | @@ -5822,9 +5821,9 @@ pub fn lldMain( | ... | @@ -5822,9 +5821,9 @@ pub fn lldMain( |
| 5822 | const ArgIteratorResponseFile = process.ArgIteratorGeneral(.{ .comments = true, .single_quotes = true }); | 5821 | const ArgIteratorResponseFile = process.ArgIteratorGeneral(.{ .comments = true, .single_quotes = true }); |
| 5823 | 5822 | ||
| 5824 | /// Initialize the arguments from a Response File. "*.rsp" | 5823 | /// Initialize the arguments from a Response File. "*.rsp" |
| 5825 | fn initArgIteratorResponseFile(allocator: Allocator, resp_file_path: []const u8) !ArgIteratorResponseFile { | 5824 | fn initArgIteratorResponseFile(allocator: Allocator, io: Io, resp_file_path: []const u8) !ArgIteratorResponseFile { |
| 5826 | const max_bytes = 10 * 1024 * 1024; // 10 MiB of command line arguments is a reasonable limit | 5825 | const max_bytes = 10 * 1024 * 1024; // 10 MiB of command line arguments is a reasonable limit |
| 5827 | const cmd_line = try Io.Dir.cwd().readFileAlloc(resp_file_path, allocator, .limited(max_bytes)); | 5826 | const cmd_line = try Io.Dir.cwd().readFileAlloc(io, resp_file_path, allocator, .limited(max_bytes)); |
| 5828 | errdefer allocator.free(cmd_line); | 5827 | errdefer allocator.free(cmd_line); |
| 5829 | 5828 | ||
| 5830 | return ArgIteratorResponseFile.initTakeOwnership(allocator, cmd_line); | 5829 | return ArgIteratorResponseFile.initTakeOwnership(allocator, cmd_line); |
| ... | @@ -5952,7 +5951,7 @@ pub const ClangArgIterator = struct { | ... | @@ -5952,7 +5951,7 @@ pub const ClangArgIterator = struct { |
| 5952 | }; | 5951 | }; |
| 5953 | } | 5952 | } |
| 5954 | 5953 | ||
| 5955 | fn next(self: *ClangArgIterator) !void { | 5954 | fn next(self: *ClangArgIterator, io: Io) !void { |
| 5956 | assert(self.has_next); | 5955 | assert(self.has_next); |
| 5957 | assert(self.next_index < self.argv.len); | 5956 | assert(self.next_index < self.argv.len); |
| 5958 | // In this state we know that the parameter we are looking at is a root parameter | 5957 | // In this state we know that the parameter we are looking at is a root parameter |
| ... | @@ -5970,10 +5969,8 @@ pub const ClangArgIterator = struct { | ... | @@ -5970,10 +5969,8 @@ pub const ClangArgIterator = struct { |
| 5970 | const arena = self.arena; | 5969 | const arena = self.arena; |
| 5971 | const resp_file_path = arg[1..]; | 5970 | const resp_file_path = arg[1..]; |
| 5972 | 5971 | ||
| 5973 | self.arg_iterator_response_file = | 5972 | self.arg_iterator_response_file = initArgIteratorResponseFile(arena, io, resp_file_path) catch |err| |
| 5974 | initArgIteratorResponseFile(arena, resp_file_path) catch |err| { | 5973 | fatal("unable to read response file '{s}': {t}", .{ resp_file_path, err }); |
| 5975 | fatal("unable to read response file '{s}': {s}", .{ resp_file_path, @errorName(err) }); | ||
| 5976 | }; | ||
| 5977 | // NOTE: The ArgIteratorResponseFile returns tokens from next() that are slices of an | 5974 | // NOTE: The ArgIteratorResponseFile returns tokens from next() that are slices of an |
| 5978 | // internal buffer. This internal buffer is arena allocated, so it is not cleaned up here. | 5975 | // internal buffer. This internal buffer is arena allocated, so it is not cleaned up here. |
| 5979 | 5976 | ||
| ... | @@ -7405,7 +7402,7 @@ const Templates = struct { | ... | @@ -7405,7 +7402,7 @@ const Templates = struct { |
| 7405 | } | 7402 | } |
| 7406 | 7403 | ||
| 7407 | const max_bytes = 10 * 1024 * 1024; | 7404 | const max_bytes = 10 * 1024 * 1024; |
| 7408 | const contents = templates.dir.readFileAlloc(template_path, arena, .limited(max_bytes)) catch |err| { | 7405 | const contents = templates.dir.readFileAlloc(io, template_path, arena, .limited(max_bytes)) catch |err| { |
| 7409 | fatal("unable to read template file '{s}': {t}", .{ template_path, err }); | 7406 | fatal("unable to read template file '{s}': {t}", .{ template_path, err }); |
| 7410 | }; | 7407 | }; |
| 7411 | templates.buffer.clearRetainingCapacity(); | 7408 | templates.buffer.clearRetainingCapacity(); |