diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2025-08-29 20:34:20 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2025-08-30 00:48:50 -0700 |
| commit | fadd268a609aefa155bbe5c7fe9d7c07956e9cda (patch) | |
| tree | 6414f5308bfdd89831081785c22bd790e3841ea6 /lib/std | |
| parent | 9a0970a12bdcae105b6f3f65c0a72d95a209bd35 (diff) | |
| download | zig-fadd268a609aefa155bbe5c7fe9d7c07956e9cda.tar.gz zig-fadd268a609aefa155bbe5c7fe9d7c07956e9cda.zip | |
upgrade more old API uses
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/Build/Step/CheckObject.zig | 40 | ||||
| -rw-r--r-- | lib/std/Io/Writer.zig | 9 | ||||
| -rw-r--r-- | lib/std/array_list.zig | 1 |
3 files changed, 27 insertions, 23 deletions
diff --git a/lib/std/Build/Step/CheckObject.zig b/lib/std/Build/Step/CheckObject.zig index 2f7afa8dba..4a2efde407 100644 --- a/lib/std/Build/Step/CheckObject.zig +++ b/lib/std/Build/Step/CheckObject.zig @@ -1703,7 +1703,7 @@ const ElfDumper = struct { var reader: std.Io.Reader = .fixed(bytes); const magic = try reader.takeArray(elf.ARMAG.len); - if (!mem.eql(u8, &magic, elf.ARMAG)) { + if (!mem.eql(u8, magic, elf.ARMAG)) { return error.InvalidArchiveMagicNumber; } @@ -2623,10 +2623,10 @@ const WasmDumper = struct { return step.fail("invalid wasm opcode '{d}'", .{byte}); }; switch (opcode) { - .i32_const => try writer.print("i32.const {x}\n", .{try std.leb.readIleb128(i32)}), - .i64_const => try writer.print("i64.const {x}\n", .{try std.leb.readIleb128(i64)}), - .f32_const => try writer.print("f32.const {x}\n", .{@as(f32, @bitCast(try reader.readInt(u32, .little)))}), - .f64_const => try writer.print("f64.const {x}\n", .{@as(f64, @bitCast(try reader.readInt(u64, .little)))}), + .i32_const => try writer.print("i32.const {x}\n", .{try reader.takeLeb128(i32)}), + .i64_const => try writer.print("i64.const {x}\n", .{try reader.takeLeb128(i64)}), + .f32_const => try writer.print("f32.const {x}\n", .{@as(f32, @bitCast(try reader.takeInt(u32, .little)))}), + .f64_const => try writer.print("f64.const {x}\n", .{@as(f64, @bitCast(try reader.takeInt(u64, .little)))}), .global_get => try writer.print("global.get {x}\n", .{try reader.takeLeb128(u32)}), else => unreachable, } @@ -2638,7 +2638,7 @@ const WasmDumper = struct { /// https://webassembly.github.io/spec/core/appendix/custom.html fn parseDumpNames(step: *Step, reader: *std.Io.Reader, writer: *std.Io.Writer, data: []const u8) !void { - while (reader.context.pos < data.len) { + while (reader.seek < data.len) { switch (try parseDumpType(step, std.wasm.NameSubsection, reader, writer)) { // The module name subsection ... consists of a single name // that is assigned to the module itself. @@ -2646,9 +2646,9 @@ const WasmDumper = struct { const size = try reader.takeLeb128(u32); const name_len = try reader.takeLeb128(u32); if (size != name_len + 1) return error.BadSubsectionSize; - if (reader.context.pos + name_len > data.len) return error.UnexpectedEndOfStream; - try writer.print("name {s}\n", .{data[reader.context.pos..][0..name_len]}); - reader.context.pos += name_len; + if (reader.seek + name_len > data.len) return error.UnexpectedEndOfStream; + try writer.print("name {s}\n", .{data[reader.seek..][0..name_len]}); + reader.seek += name_len; }, // The function name subsection ... consists of a name map @@ -2664,9 +2664,9 @@ const WasmDumper = struct { for (0..entries) |_| { const index = try reader.takeLeb128(u32); const name_len = try reader.takeLeb128(u32); - if (reader.context.pos + name_len > data.len) return error.UnexpectedEndOfStream; - const name = data[reader.context.pos..][0..name_len]; - reader.context.pos += name.len; + if (reader.seek + name_len > data.len) return error.UnexpectedEndOfStream; + const name = data[reader.seek..][0..name_len]; + reader.seek += name.len; try writer.print( \\index {d} @@ -2694,8 +2694,8 @@ const WasmDumper = struct { var current_field: u32 = 0; while (current_field < field_count) : (current_field += 1) { const field_name_length = try reader.takeLeb128(u32); - const field_name = data[reader.context.pos..][0..field_name_length]; - reader.context.pos += field_name_length; + const field_name = data[reader.seek..][0..field_name_length]; + reader.seek += field_name_length; const value_count = try reader.takeLeb128(u32); try writer.print( @@ -2706,12 +2706,12 @@ const WasmDumper = struct { var current_value: u32 = 0; while (current_value < value_count) : (current_value += 1) { const value_length = try reader.takeLeb128(u32); - const value = data[reader.context.pos..][0..value_length]; - reader.context.pos += value_length; + const value = data[reader.seek..][0..value_length]; + reader.seek += value_length; const version_length = try reader.takeLeb128(u32); - const version = data[reader.context.pos..][0..version_length]; - reader.context.pos += version_length; + const version = data[reader.seek..][0..version_length]; + reader.seek += version_length; try writer.print( \\value_name {s} @@ -2730,8 +2730,8 @@ const WasmDumper = struct { while (index < feature_count) : (index += 1) { const prefix_byte = try reader.takeLeb128(u8); const name_length = try reader.takeLeb128(u32); - const feature_name = data[reader.context.pos..][0..name_length]; - reader.context.pos += name_length; + const feature_name = data[reader.seek..][0..name_length]; + reader.seek += name_length; try writer.print("{c} {s}\n", .{ prefix_byte, feature_name }); } diff --git a/lib/std/Io/Writer.zig b/lib/std/Io/Writer.zig index a7a92bd180..8bfb1bb75e 100644 --- a/lib/std/Io/Writer.zig +++ b/lib/std/Io/Writer.zig @@ -2636,7 +2636,7 @@ pub const Allocating = struct { assert(a.alignment == alignment); // Required for Allocator correctness. const w = &a.writer; const result: std.array_list.Aligned(u8, alignment) = .{ - .items = w.buffer[0..w.end], + .items = @alignCast(w.buffer[0..w.end]), .capacity = w.buffer.len, }; w.buffer = &.{}; @@ -2645,12 +2645,15 @@ pub const Allocating = struct { } pub fn ensureUnusedCapacity(a: *Allocating, additional_count: usize) Allocator.Error!void { - const new_capacity = std.math.add(usize, a.writer.buffer.len, additional_count) catch return error.OutOfMemory; + const new_capacity = std.math.add(usize, a.writer.end, additional_count) catch return error.OutOfMemory; return ensureTotalCapacity(a, new_capacity); } pub fn ensureTotalCapacity(a: *Allocating, new_capacity: usize) Allocator.Error!void { - return ensureTotalCapacityPrecise(a, ArrayList(u8).growCapacity(a.writer.buffer.len, new_capacity)); + // Protects growing unnecessarily since better_capacity will be larger. + if (a.writer.buffer.len >= new_capacity) return; + const better_capacity = ArrayList(u8).growCapacity(a.writer.buffer.len, new_capacity); + return ensureTotalCapacityPrecise(a, better_capacity); } pub fn ensureTotalCapacityPrecise(a: *Allocating, new_capacity: usize) Allocator.Error!void { diff --git a/lib/std/array_list.zig b/lib/std/array_list.zig index a218e47276..9718d19c7e 100644 --- a/lib/std/array_list.zig +++ b/lib/std/array_list.zig @@ -405,6 +405,7 @@ pub fn AlignedManaged(comptime T: type, comptime alignment: ?mem.Alignment) type return; } + // Protects growing unnecessarily since better_capacity will be larger. if (self.capacity >= new_capacity) return; const better_capacity = Aligned(T, alignment).growCapacity(self.capacity, new_capacity); |
