| author | |
| committer | |
| log | fadd268a609aefa155bbe5c7fe9d7c07956e9cda |
| tree | 6414f5308bfdd89831081785c22bd790e3841ea6 |
| parent | 9a0970a12bdcae105b6f3f65c0a72d95a209bd35 |
9 files changed, 36 insertions(+), 51 deletions(-)
build.zig+1-1| ... | @@ -304,7 +304,7 @@ pub fn build(b: *std.Build) !void { | ... | @@ -304,7 +304,7 @@ pub fn build(b: *std.Build) !void { |
| 304 | if (enable_llvm) { | 304 | if (enable_llvm) { |
| 305 | const cmake_cfg = if (static_llvm) null else blk: { | 305 | const cmake_cfg = if (static_llvm) null else blk: { |
| 306 | if (findConfigH(b, config_h_path_option)) |config_h_path| { | 306 | if (findConfigH(b, config_h_path_option)) |config_h_path| { |
| 307 | const file_contents = fs.cwd().readFileAlloc(b.allocator, config_h_path, max_config_h_bytes) catch unreachable; | 307 | const file_contents = fs.cwd().readFileAlloc(config_h_path, b.allocator, .limited(max_config_h_bytes)) catch unreachable; |
| 308 | break :blk parseConfigH(b, file_contents); | 308 | break :blk parseConfigH(b, file_contents); |
| 309 | } else { | 309 | } else { |
| 310 | std.log.warn("config.h could not be located automatically. Consider providing it explicitly via \"-Dconfig_h\"", .{}); | 310 | std.log.warn("config.h could not be located automatically. Consider providing it explicitly via \"-Dconfig_h\"", .{}); |
lib/compiler/aro/aro/Compilation.zig+2-20| ... | @@ -1308,13 +1308,7 @@ fn addSourceFromPathExtra(comp: *Compilation, path: []const u8, kind: Source.Kin | ... | @@ -1308,13 +1308,7 @@ fn addSourceFromPathExtra(comp: *Compilation, path: []const u8, kind: Source.Kin |
| 1308 | return error.FileNotFound; | 1308 | return error.FileNotFound; |
| 1309 | } | 1309 | } |
| 1310 | 1310 | ||
| 1311 | const file = try comp.cwd.openFile(path, .{}); | 1311 | const contents = try comp.cwd.readFileAlloc(path, comp.gpa, .limited(std.math.maxInt(u32))); |
| 1312 | defer file.close(); | ||
| 1313 | |||
| 1314 | const contents = file.readToEndAlloc(comp.gpa, std.math.maxInt(u32)) catch |err| switch (err) { | ||
| 1315 | error.FileTooBig => return error.StreamTooLong, | ||
| 1316 | else => |e| return e, | ||
| 1317 | }; | ||
| 1318 | errdefer comp.gpa.free(contents); | 1312 | errdefer comp.gpa.free(contents); |
| 1319 | 1313 | ||
| 1320 | return comp.addSourceFromOwnedBuffer(contents, path, kind); | 1314 | return comp.addSourceFromOwnedBuffer(contents, path, kind); |
| ... | @@ -1433,19 +1427,7 @@ fn getFileContents(comp: *Compilation, path: []const u8, limit: ?u32) ![]const u | ... | @@ -1433,19 +1427,7 @@ fn getFileContents(comp: *Compilation, path: []const u8, limit: ?u32) ![]const u |
| 1433 | return error.FileNotFound; | 1427 | return error.FileNotFound; |
| 1434 | } | 1428 | } |
| 1435 | 1429 | ||
| 1436 | const file = try comp.cwd.openFile(path, .{}); | 1430 | return comp.cwd.readFileAlloc(path, comp.gpa, .limited(limit orelse std.math.maxInt(u32))); |
| 1437 | defer file.close(); | ||
| 1438 | |||
| 1439 | var buf = std.array_list.Managed(u8).init(comp.gpa); | ||
| 1440 | defer buf.deinit(); | ||
| 1441 | |||
| 1442 | const max = limit orelse std.math.maxInt(u32); | ||
| 1443 | file.deprecatedReader().readAllArrayList(&buf, max) catch |e| switch (e) { | ||
| 1444 | error.StreamTooLong => if (limit == null) return e, | ||
| 1445 | else => return e, | ||
| 1446 | }; | ||
| 1447 | |||
| 1448 | return buf.toOwnedSlice(); | ||
| 1449 | } | 1431 | } |
| 1450 | 1432 | ||
| 1451 | pub fn findEmbed( | 1433 | pub fn findEmbed( |
lib/compiler/aro/aro/Driver.zig+2-2| ... | @@ -519,8 +519,8 @@ fn option(arg: []const u8, name: []const u8) ?[]const u8 { | ... | @@ -519,8 +519,8 @@ fn option(arg: []const u8, name: []const u8) ?[]const u8 { |
| 519 | 519 | ||
| 520 | fn addSource(d: *Driver, path: []const u8) !Source { | 520 | fn addSource(d: *Driver, path: []const u8) !Source { |
| 521 | if (mem.eql(u8, "-", path)) { | 521 | if (mem.eql(u8, "-", path)) { |
| 522 | const stdin = std.fs.File.stdin().deprecatedReader(); | 522 | var stdin_reader: std.fs.File.Reader = .initStreaming(.stdin(), &.{}); |
| 523 | const input = try stdin.readAllAlloc(d.comp.gpa, std.math.maxInt(u32)); | 523 | const input = try stdin_reader.interface.allocRemaining(d.comp.gpa, .limited(std.math.maxInt(u32))); |
| 524 | defer d.comp.gpa.free(input); | 524 | defer d.comp.gpa.free(input); |
| 525 | return d.comp.addSourceFromBuffer("<stdin>", input); | 525 | return d.comp.addSourceFromBuffer("<stdin>", input); |
| 526 | } | 526 | } |
lib/std/Build/Step/CheckObject.zig+20-20| ... | @@ -1703,7 +1703,7 @@ const ElfDumper = struct { | ... | @@ -1703,7 +1703,7 @@ const ElfDumper = struct { |
| 1703 | var reader: std.Io.Reader = .fixed(bytes); | 1703 | var reader: std.Io.Reader = .fixed(bytes); |
| 1704 | 1704 | ||
| 1705 | const magic = try reader.takeArray(elf.ARMAG.len); | 1705 | const magic = try reader.takeArray(elf.ARMAG.len); |
| 1706 | if (!mem.eql(u8, &magic, elf.ARMAG)) { | 1706 | if (!mem.eql(u8, magic, elf.ARMAG)) { |
| 1707 | return error.InvalidArchiveMagicNumber; | 1707 | return error.InvalidArchiveMagicNumber; |
| 1708 | } | 1708 | } |
| 1709 | 1709 | ||
| ... | @@ -2623,10 +2623,10 @@ const WasmDumper = struct { | ... | @@ -2623,10 +2623,10 @@ const WasmDumper = struct { |
| 2623 | return step.fail("invalid wasm opcode '{d}'", .{byte}); | 2623 | return step.fail("invalid wasm opcode '{d}'", .{byte}); |
| 2624 | }; | 2624 | }; |
| 2625 | switch (opcode) { | 2625 | switch (opcode) { |
| 2626 | .i32_const => try writer.print("i32.const {x}\n", .{try std.leb.readIleb128(i32)}), | 2626 | .i32_const => try writer.print("i32.const {x}\n", .{try reader.takeLeb128(i32)}), |
| 2627 | .i64_const => try writer.print("i64.const {x}\n", .{try std.leb.readIleb128(i64)}), | 2627 | .i64_const => try writer.print("i64.const {x}\n", .{try reader.takeLeb128(i64)}), |
| 2628 | .f32_const => try writer.print("f32.const {x}\n", .{@as(f32, @bitCast(try reader.readInt(u32, .little)))}), | 2628 | .f32_const => try writer.print("f32.const {x}\n", .{@as(f32, @bitCast(try reader.takeInt(u32, .little)))}), |
| 2629 | .f64_const => try writer.print("f64.const {x}\n", .{@as(f64, @bitCast(try reader.readInt(u64, .little)))}), | 2629 | .f64_const => try writer.print("f64.const {x}\n", .{@as(f64, @bitCast(try reader.takeInt(u64, .little)))}), |
| 2630 | .global_get => try writer.print("global.get {x}\n", .{try reader.takeLeb128(u32)}), | 2630 | .global_get => try writer.print("global.get {x}\n", .{try reader.takeLeb128(u32)}), |
| 2631 | else => unreachable, | 2631 | else => unreachable, |
| 2632 | } | 2632 | } |
| ... | @@ -2638,7 +2638,7 @@ const WasmDumper = struct { | ... | @@ -2638,7 +2638,7 @@ const WasmDumper = struct { |
| 2638 | 2638 | ||
| 2639 | /// https://webassembly.github.io/spec/core/appendix/custom.html | 2639 | /// https://webassembly.github.io/spec/core/appendix/custom.html |
| 2640 | fn parseDumpNames(step: *Step, reader: *std.Io.Reader, writer: *std.Io.Writer, data: []const u8) !void { | 2640 | fn parseDumpNames(step: *Step, reader: *std.Io.Reader, writer: *std.Io.Writer, data: []const u8) !void { |
| 2641 | while (reader.context.pos < data.len) { | 2641 | while (reader.seek < data.len) { |
| 2642 | switch (try parseDumpType(step, std.wasm.NameSubsection, reader, writer)) { | 2642 | switch (try parseDumpType(step, std.wasm.NameSubsection, reader, writer)) { |
| 2643 | // The module name subsection ... consists of a single name | 2643 | // The module name subsection ... consists of a single name |
| 2644 | // that is assigned to the module itself. | 2644 | // that is assigned to the module itself. |
| ... | @@ -2646,9 +2646,9 @@ const WasmDumper = struct { | ... | @@ -2646,9 +2646,9 @@ const WasmDumper = struct { |
| 2646 | const size = try reader.takeLeb128(u32); | 2646 | const size = try reader.takeLeb128(u32); |
| 2647 | const name_len = try reader.takeLeb128(u32); | 2647 | const name_len = try reader.takeLeb128(u32); |
| 2648 | if (size != name_len + 1) return error.BadSubsectionSize; | 2648 | if (size != name_len + 1) return error.BadSubsectionSize; |
| 2649 | if (reader.context.pos + name_len > data.len) return error.UnexpectedEndOfStream; | 2649 | if (reader.seek + name_len > data.len) return error.UnexpectedEndOfStream; |
| 2650 | try writer.print("name {s}\n", .{data[reader.context.pos..][0..name_len]}); | 2650 | try writer.print("name {s}\n", .{data[reader.seek..][0..name_len]}); |
| 2651 | reader.context.pos += name_len; | 2651 | reader.seek += name_len; |
| 2652 | }, | 2652 | }, |
| 2653 | 2653 | ||
| 2654 | // The function name subsection ... consists of a name map | 2654 | // The function name subsection ... consists of a name map |
| ... | @@ -2664,9 +2664,9 @@ const WasmDumper = struct { | ... | @@ -2664,9 +2664,9 @@ const WasmDumper = struct { |
| 2664 | for (0..entries) |_| { | 2664 | for (0..entries) |_| { |
| 2665 | const index = try reader.takeLeb128(u32); | 2665 | const index = try reader.takeLeb128(u32); |
| 2666 | const name_len = try reader.takeLeb128(u32); | 2666 | const name_len = try reader.takeLeb128(u32); |
| 2667 | if (reader.context.pos + name_len > data.len) return error.UnexpectedEndOfStream; | 2667 | if (reader.seek + name_len > data.len) return error.UnexpectedEndOfStream; |
| 2668 | const name = data[reader.context.pos..][0..name_len]; | 2668 | const name = data[reader.seek..][0..name_len]; |
| 2669 | reader.context.pos += name.len; | 2669 | reader.seek += name.len; |
| 2670 | 2670 | ||
| 2671 | try writer.print( | 2671 | try writer.print( |
| 2672 | \\index {d} | 2672 | \\index {d} |
| ... | @@ -2694,8 +2694,8 @@ const WasmDumper = struct { | ... | @@ -2694,8 +2694,8 @@ const WasmDumper = struct { |
| 2694 | var current_field: u32 = 0; | 2694 | var current_field: u32 = 0; |
| 2695 | while (current_field < field_count) : (current_field += 1) { | 2695 | while (current_field < field_count) : (current_field += 1) { |
| 2696 | const field_name_length = try reader.takeLeb128(u32); | 2696 | const field_name_length = try reader.takeLeb128(u32); |
| 2697 | const field_name = data[reader.context.pos..][0..field_name_length]; | 2697 | const field_name = data[reader.seek..][0..field_name_length]; |
| 2698 | reader.context.pos += field_name_length; | 2698 | reader.seek += field_name_length; |
| 2699 | 2699 | ||
| 2700 | const value_count = try reader.takeLeb128(u32); | 2700 | const value_count = try reader.takeLeb128(u32); |
| 2701 | try writer.print( | 2701 | try writer.print( |
| ... | @@ -2706,12 +2706,12 @@ const WasmDumper = struct { | ... | @@ -2706,12 +2706,12 @@ const WasmDumper = struct { |
| 2706 | var current_value: u32 = 0; | 2706 | var current_value: u32 = 0; |
| 2707 | while (current_value < value_count) : (current_value += 1) { | 2707 | while (current_value < value_count) : (current_value += 1) { |
| 2708 | const value_length = try reader.takeLeb128(u32); | 2708 | const value_length = try reader.takeLeb128(u32); |
| 2709 | const value = data[reader.context.pos..][0..value_length]; | 2709 | const value = data[reader.seek..][0..value_length]; |
| 2710 | reader.context.pos += value_length; | 2710 | reader.seek += value_length; |
| 2711 | 2711 | ||
| 2712 | const version_length = try reader.takeLeb128(u32); | 2712 | const version_length = try reader.takeLeb128(u32); |
| 2713 | const version = data[reader.context.pos..][0..version_length]; | 2713 | const version = data[reader.seek..][0..version_length]; |
| 2714 | reader.context.pos += version_length; | 2714 | reader.seek += version_length; |
| 2715 | 2715 | ||
| 2716 | try writer.print( | 2716 | try writer.print( |
| 2717 | \\value_name {s} | 2717 | \\value_name {s} |
| ... | @@ -2730,8 +2730,8 @@ const WasmDumper = struct { | ... | @@ -2730,8 +2730,8 @@ const WasmDumper = struct { |
| 2730 | while (index < feature_count) : (index += 1) { | 2730 | while (index < feature_count) : (index += 1) { |
| 2731 | const prefix_byte = try reader.takeLeb128(u8); | 2731 | const prefix_byte = try reader.takeLeb128(u8); |
| 2732 | const name_length = try reader.takeLeb128(u32); | 2732 | const name_length = try reader.takeLeb128(u32); |
| 2733 | const feature_name = data[reader.context.pos..][0..name_length]; | 2733 | const feature_name = data[reader.seek..][0..name_length]; |
| 2734 | reader.context.pos += name_length; | 2734 | reader.seek += name_length; |
| 2735 | 2735 | ||
| 2736 | try writer.print("{c} {s}\n", .{ prefix_byte, feature_name }); | 2736 | try writer.print("{c} {s}\n", .{ prefix_byte, feature_name }); |
| 2737 | } | 2737 | } |
lib/std/Io/Writer.zig+6-3| ... | @@ -2636,7 +2636,7 @@ pub const Allocating = struct { | ... | @@ -2636,7 +2636,7 @@ pub const Allocating = struct { |
| 2636 | assert(a.alignment == alignment); // Required for Allocator correctness. | 2636 | assert(a.alignment == alignment); // Required for Allocator correctness. |
| 2637 | const w = &a.writer; | 2637 | const w = &a.writer; |
| 2638 | const result: std.array_list.Aligned(u8, alignment) = .{ | 2638 | const result: std.array_list.Aligned(u8, alignment) = .{ |
| 2639 | .items = w.buffer[0..w.end], | 2639 | .items = @alignCast(w.buffer[0..w.end]), |
| 2640 | .capacity = w.buffer.len, | 2640 | .capacity = w.buffer.len, |
| 2641 | }; | 2641 | }; |
| 2642 | w.buffer = &.{}; | 2642 | w.buffer = &.{}; |
| ... | @@ -2645,12 +2645,15 @@ pub const Allocating = struct { | ... | @@ -2645,12 +2645,15 @@ pub const Allocating = struct { |
| 2645 | } | 2645 | } |
| 2646 | 2646 | ||
| 2647 | pub fn ensureUnusedCapacity(a: *Allocating, additional_count: usize) Allocator.Error!void { | 2647 | pub fn ensureUnusedCapacity(a: *Allocating, additional_count: usize) Allocator.Error!void { |
| 2648 | const new_capacity = std.math.add(usize, a.writer.buffer.len, additional_count) catch return error.OutOfMemory; | 2648 | const new_capacity = std.math.add(usize, a.writer.end, additional_count) catch return error.OutOfMemory; |
| 2649 | return ensureTotalCapacity(a, new_capacity); | 2649 | return ensureTotalCapacity(a, new_capacity); |
| 2650 | } | 2650 | } |
| 2651 | 2651 | ||
| 2652 | pub fn ensureTotalCapacity(a: *Allocating, new_capacity: usize) Allocator.Error!void { | 2652 | pub fn ensureTotalCapacity(a: *Allocating, new_capacity: usize) Allocator.Error!void { |
| 2653 | return ensureTotalCapacityPrecise(a, ArrayList(u8).growCapacity(a.writer.buffer.len, new_capacity)); | 2653 | // Protects growing unnecessarily since better_capacity will be larger. |
| 2654 | if (a.writer.buffer.len >= new_capacity) return; | ||
| 2655 | const better_capacity = ArrayList(u8).growCapacity(a.writer.buffer.len, new_capacity); | ||
| 2656 | return ensureTotalCapacityPrecise(a, better_capacity); | ||
| 2654 | } | 2657 | } |
| 2655 | 2658 | ||
| 2656 | pub fn ensureTotalCapacityPrecise(a: *Allocating, new_capacity: usize) Allocator.Error!void { | 2659 | pub fn ensureTotalCapacityPrecise(a: *Allocating, new_capacity: usize) Allocator.Error!void { |
lib/std/array_list.zig+1| ... | @@ -405,6 +405,7 @@ pub fn AlignedManaged(comptime T: type, comptime alignment: ?mem.Alignment) type | ... | @@ -405,6 +405,7 @@ pub fn AlignedManaged(comptime T: type, comptime alignment: ?mem.Alignment) type |
| 405 | return; | 405 | return; |
| 406 | } | 406 | } |
| 407 | 407 | ||
| 408 | // Protects growing unnecessarily since better_capacity will be larger. | ||
| 408 | if (self.capacity >= new_capacity) return; | 409 | if (self.capacity >= new_capacity) return; |
| 409 | 410 | ||
| 410 | const better_capacity = Aligned(T, alignment).growCapacity(self.capacity, new_capacity); | 411 | const better_capacity = Aligned(T, alignment).growCapacity(self.capacity, new_capacity); |
src/link/MachO/CodeSignature.zig+1-3| ... | @@ -245,9 +245,7 @@ pub fn deinit(self: *CodeSignature, allocator: Allocator) void { | ... | @@ -245,9 +245,7 @@ pub fn deinit(self: *CodeSignature, allocator: Allocator) void { |
| 245 | } | 245 | } |
| 246 | 246 | ||
| 247 | pub fn addEntitlements(self: *CodeSignature, allocator: Allocator, path: []const u8) !void { | 247 | pub fn addEntitlements(self: *CodeSignature, allocator: Allocator, path: []const u8) !void { |
| 248 | const file = try fs.cwd().openFile(path, .{}); | 248 | const inner = try fs.cwd().readFileAlloc(path, allocator, .limited(std.math.maxInt(u32))); |
| 249 | defer file.close(); | ||
| 250 | const inner = try file.readToEndAlloc(allocator, std.math.maxInt(u32)); | ||
| 251 | self.entitlements = .{ .inner = inner }; | 249 | self.entitlements = .{ .inner = inner }; |
| 252 | } | 250 | } |
| 253 | 251 |
src/main.zig+2-1| ... | @@ -5693,7 +5693,8 @@ fn jitCmd( | ... | @@ -5693,7 +5693,8 @@ fn jitCmd( |
| 5693 | try child.spawn(); | 5693 | try child.spawn(); |
| 5694 | 5694 | ||
| 5695 | if (options.capture) |ptr| { | 5695 | if (options.capture) |ptr| { |
| 5696 | ptr.* = try child.stdout.?.readToEndAlloc(arena, std.math.maxInt(u32)); | 5696 | var stdout_reader = child.stdout.?.readerStreaming(&.{}); |
| 5697 | ptr.* = try stdout_reader.interface.allocRemaining(arena, .limited(std.math.maxInt(u32))); | ||
| 5697 | } | 5698 | } |
| 5698 | 5699 | ||
| 5699 | const term = try child.wait(); | 5700 | const term = try child.wait(); |
test/src/Cases.zig+1-1| ... | @@ -386,7 +386,7 @@ fn addFromDirInner( | ... | @@ -386,7 +386,7 @@ fn addFromDirInner( |
| 386 | current_file.* = filename; | 386 | current_file.* = filename; |
| 387 | 387 | ||
| 388 | const max_file_size = 10 * 1024 * 1024; | 388 | const max_file_size = 10 * 1024 * 1024; |
| 389 | const src = try iterable_dir.readFileAllocOptions(ctx.arena, filename, max_file_size, null, .@"1", 0); | 389 | const src = try iterable_dir.readFileAllocOptions(filename, ctx.arena, .limited(max_file_size), .@"1", 0); |
| 390 | 390 | ||
| 391 | // Parse the manifest | 391 | // Parse the manifest |
| 392 | var manifest = try TestManifest.parse(ctx.arena, src); | 392 | var manifest = try TestManifest.parse(ctx.arena, src); |