Skip to content

Commit e9bed3b

Browse files
committed
upgrade more old API uses
1 parent 964b724 commit e9bed3b

File tree

8 files changed

+31
-50
lines changed

8 files changed

+31
-50
lines changed

build.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ pub fn build(b: *std.Build) !void {
304304
if (enable_llvm) {
305305
const cmake_cfg = if (static_llvm) null else blk: {
306306
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;
308308
break :blk parseConfigH(b, file_contents);
309309
} else {
310310
std.log.warn("config.h could not be located automatically. Consider providing it explicitly via \"-Dconfig_h\"", .{});

lib/compiler/aro/aro/Compilation.zig

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,13 +1308,7 @@ fn addSourceFromPathExtra(comp: *Compilation, path: []const u8, kind: Source.Kin
13081308
return error.FileNotFound;
13091309
}
13101310

1311-
const file = try comp.cwd.openFile(path, .{});
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-
};
1311+
const contents = try comp.cwd.readFileAlloc(path, comp.gpa, .limited(std.math.maxInt(u32)));
13181312
errdefer comp.gpa.free(contents);
13191313

13201314
return comp.addSourceFromOwnedBuffer(contents, path, kind);
@@ -1433,19 +1427,7 @@ fn getFileContents(comp: *Compilation, path: []const u8, limit: ?u32) ![]const u
14331427
return error.FileNotFound;
14341428
}
14351429

1436-
const file = try comp.cwd.openFile(path, .{});
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();
1430+
return comp.cwd.readFileAlloc(path, comp.gpa, .limited(limit orelse std.math.maxInt(u32)));
14491431
}
14501432

14511433
pub fn findEmbed(

lib/compiler/aro/aro/Driver.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,8 +519,8 @@ fn option(arg: []const u8, name: []const u8) ?[]const u8 {
519519

520520
fn addSource(d: *Driver, path: []const u8) !Source {
521521
if (mem.eql(u8, "-", path)) {
522-
const stdin = std.fs.File.stdin().deprecatedReader();
523-
const input = try stdin.readAllAlloc(d.comp.gpa, std.math.maxInt(u32));
522+
var stdin_reader: std.fs.File.Reader = .initStreaming(.stdin(), &.{});
523+
const input = try stdin_reader.interface.allocRemaining(d.comp.gpa, .limited(std.math.maxInt(u32)));
524524
defer d.comp.gpa.free(input);
525525
return d.comp.addSourceFromBuffer("<stdin>", input);
526526
}

lib/std/Build/Step/CheckObject.zig

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,7 +1703,7 @@ const ElfDumper = struct {
17031703
var reader: std.Io.Reader = .fixed(bytes);
17041704

17051705
const magic = try reader.takeArray(elf.ARMAG.len);
1706-
if (!mem.eql(u8, &magic, elf.ARMAG)) {
1706+
if (!mem.eql(u8, magic, elf.ARMAG)) {
17071707
return error.InvalidArchiveMagicNumber;
17081708
}
17091709

@@ -2623,10 +2623,10 @@ const WasmDumper = struct {
26232623
return step.fail("invalid wasm opcode '{d}'", .{byte});
26242624
};
26252625
switch (opcode) {
2626-
.i32_const => try writer.print("i32.const {x}\n", .{try std.leb.readIleb128(i32)}),
2627-
.i64_const => try writer.print("i64.const {x}\n", .{try std.leb.readIleb128(i64)}),
2628-
.f32_const => try writer.print("f32.const {x}\n", .{@as(f32, @bitCast(try reader.readInt(u32, .little)))}),
2629-
.f64_const => try writer.print("f64.const {x}\n", .{@as(f64, @bitCast(try reader.readInt(u64, .little)))}),
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 reader.takeLeb128(i64)}),
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.takeInt(u64, .little)))}),
26302630
.global_get => try writer.print("global.get {x}\n", .{try reader.takeLeb128(u32)}),
26312631
else => unreachable,
26322632
}
@@ -2638,17 +2638,17 @@ const WasmDumper = struct {
26382638

26392639
/// https://webassembly.github.io/spec/core/appendix/custom.html
26402640
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) {
26422642
switch (try parseDumpType(step, std.wasm.NameSubsection, reader, writer)) {
26432643
// The module name subsection ... consists of a single name
26442644
// that is assigned to the module itself.
26452645
.module => {
26462646
const size = try reader.takeLeb128(u32);
26472647
const name_len = try reader.takeLeb128(u32);
26482648
if (size != name_len + 1) return error.BadSubsectionSize;
2649-
if (reader.context.pos + name_len > data.len) return error.UnexpectedEndOfStream;
2650-
try writer.print("name {s}\n", .{data[reader.context.pos..][0..name_len]});
2651-
reader.context.pos += name_len;
2649+
if (reader.seek + name_len > data.len) return error.UnexpectedEndOfStream;
2650+
try writer.print("name {s}\n", .{data[reader.seek..][0..name_len]});
2651+
reader.seek += name_len;
26522652
},
26532653

26542654
// The function name subsection ... consists of a name map
@@ -2664,9 +2664,9 @@ const WasmDumper = struct {
26642664
for (0..entries) |_| {
26652665
const index = try reader.takeLeb128(u32);
26662666
const name_len = try reader.takeLeb128(u32);
2667-
if (reader.context.pos + name_len > data.len) return error.UnexpectedEndOfStream;
2668-
const name = data[reader.context.pos..][0..name_len];
2669-
reader.context.pos += name.len;
2667+
if (reader.seek + name_len > data.len) return error.UnexpectedEndOfStream;
2668+
const name = data[reader.seek..][0..name_len];
2669+
reader.seek += name.len;
26702670

26712671
try writer.print(
26722672
\\index {d}
@@ -2694,8 +2694,8 @@ const WasmDumper = struct {
26942694
var current_field: u32 = 0;
26952695
while (current_field < field_count) : (current_field += 1) {
26962696
const field_name_length = try reader.takeLeb128(u32);
2697-
const field_name = data[reader.context.pos..][0..field_name_length];
2698-
reader.context.pos += field_name_length;
2697+
const field_name = data[reader.seek..][0..field_name_length];
2698+
reader.seek += field_name_length;
26992699

27002700
const value_count = try reader.takeLeb128(u32);
27012701
try writer.print(
@@ -2706,12 +2706,12 @@ const WasmDumper = struct {
27062706
var current_value: u32 = 0;
27072707
while (current_value < value_count) : (current_value += 1) {
27082708
const value_length = try reader.takeLeb128(u32);
2709-
const value = data[reader.context.pos..][0..value_length];
2710-
reader.context.pos += value_length;
2709+
const value = data[reader.seek..][0..value_length];
2710+
reader.seek += value_length;
27112711

27122712
const version_length = try reader.takeLeb128(u32);
2713-
const version = data[reader.context.pos..][0..version_length];
2714-
reader.context.pos += version_length;
2713+
const version = data[reader.seek..][0..version_length];
2714+
reader.seek += version_length;
27152715

27162716
try writer.print(
27172717
\\value_name {s}
@@ -2730,8 +2730,8 @@ const WasmDumper = struct {
27302730
while (index < feature_count) : (index += 1) {
27312731
const prefix_byte = try reader.takeLeb128(u8);
27322732
const name_length = try reader.takeLeb128(u32);
2733-
const feature_name = data[reader.context.pos..][0..name_length];
2734-
reader.context.pos += name_length;
2733+
const feature_name = data[reader.seek..][0..name_length];
2734+
reader.seek += name_length;
27352735

27362736
try writer.print("{c} {s}\n", .{ prefix_byte, feature_name });
27372737
}

lib/std/Io/Writer.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2636,7 +2636,7 @@ pub const Allocating = struct {
26362636
assert(a.alignment == alignment); // Required for Allocator correctness.
26372637
const w = &a.writer;
26382638
const result: std.array_list.Aligned(u8, alignment) = .{
2639-
.items = w.buffer[0..w.end],
2639+
.items = @alignCast(w.buffer[0..w.end]),
26402640
.capacity = w.buffer.len,
26412641
};
26422642
w.buffer = &.{};
@@ -2645,7 +2645,7 @@ pub const Allocating = struct {
26452645
}
26462646

26472647
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;
26492649
return ensureTotalCapacity(a, new_capacity);
26502650
}
26512651

src/link/MachO/CodeSignature.zig

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,7 @@ pub fn deinit(self: *CodeSignature, allocator: Allocator) void {
245245
}
246246

247247
pub fn addEntitlements(self: *CodeSignature, allocator: Allocator, path: []const u8) !void {
248-
const file = try fs.cwd().openFile(path, .{});
249-
defer file.close();
250-
const inner = try file.readToEndAlloc(allocator, std.math.maxInt(u32));
248+
const inner = try fs.cwd().readFileAlloc(path, allocator, .limited(std.math.maxInt(u32)));
251249
self.entitlements = .{ .inner = inner };
252250
}
253251

src/main.zig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5693,7 +5693,8 @@ fn jitCmd(
56935693
try child.spawn();
56945694

56955695
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)));
56975698
}
56985699

56995700
const term = try child.wait();

test/src/Cases.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ fn addFromDirInner(
386386
current_file.* = filename;
387387

388388
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);
390390

391391
// Parse the manifest
392392
var manifest = try TestManifest.parse(ctx.arena, src);

0 commit comments

Comments
 (0)