╭ changed ───────────────╮ │lib/compiler/objcopy.zig│ ╰────────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────────────────────╮ │409 const shstrtab_shdr = (try section_headers.next()).?; │ │410 │ │411 try in.seekTo(shstrtab_shdr.sh_offset); │ │412 - break :blk try in.interface.readAlloc(allocator, shstrtab_shdr.sh_size); │ │412 + break :blk try in.interface.readAllocAll(allocator, shstrtab_shdr.sh_size);│ │413 }; │ │414 │ │415 errdefer if (self.shstrtab) |shstrtab| allocator.free(shstrtab); │ ╰────────────────────────────────────────────────────────────────────────────────────────────╯ ╭ changed ───────────────╮ │lib/compiler/objdump.zig│ ╰────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────╮ │417 \\ │ │418 ); │ │419 │ │420 - const offsets = try r.readAlloc(gpa, num_symbols * 4); │ │420 + const offsets = try r.readAllocAll(gpa, num_symbols * 4);│ │421 defer gpa.free(offsets); │ │422 │ │423 for (0..num_symbols) |symbol_i| { │ ╰──────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────╮ │549 .longnames => { │ │550 // This member is optional │ │551 if (std.mem.eql(u8, header.name, "//")) { │ │552 - opt_longnames = try r.readAlloc(gpa, header.size); │ │552 + opt_longnames = try r.readAllocAll(gpa, header.size);│ │553 if (dump_header) │ │554 try w.print("{t: >16} type\n", .{expected_kind});│ │555 │ ╰──────────────────────────────────────────────────────────────────────────────────╯ ╭───────────────────────────────────────────────────────────────────────────────────────────╮ │819 const string_table_len = r.peekInt(u32, .little) catch |err| │ │820 return d.failParse("unable to read string table length: {t}", .{err});│ │821 │ │822 - const table = r.readAlloc(gpa, string_table_len) catch |err| │ │822 + const table = r.readAllocAll(gpa, string_table_len) catch |err| │ │823 return d.failParse("unable to read string table: {t}", .{err}); │ │824 │ │825 try fr.seekTo(pos); │ ╰───────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────╮ │1268 const dir = image_info.?.data_dirs[@backingInt(DIRECTORY_ENTRY.EXPORT)];│ │1269 const dir_end_rva = dir.virtual_address + dir.size; │ │1270 const dir_loc = fr.logicalPos(); │ │1271 - const dir_slice = try r.readAlloc(gpa, dir.size); │ │1271 + const dir_slice = try r.readAllocAll(gpa, dir.size); │ │1272 defer gpa.free(dir_slice); │ │1273 │ │1274 const dll_name = std.mem.sliceTo(dir_slice[name_loc - dir_loc ..], 0); │ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ ╭ changed ────────────╮ │lib/std/Io/Reader.zig│ ╰─────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────────────────────╮ │743 try r.readSliceEndian(Elem, dest, endian); │ │744 return dest; │ │745 } │ │746 + │ │747 +/// Deprecated; use readAllocAll. to be removed after 0.17. │ │748 +pub const readAlloc = readAllocAll; │ │749 │ │750 /// Shortcut for calling `readSliceAll` with a buffer provided by `allocator`. │ │748 -pub fn readAlloc(r: *Reader, allocator: Allocator, len: usize) ReadAllocError![]u8 { │ │751 +pub fn readAllocAll(r: *Reader, allocator: Allocator, len: usize) ReadAllocError![]u8 {│ │752 const dest = try allocator.alloc(u8, len); │ │753 errdefer allocator.free(dest); │ │754 try readSliceAll(r, dest); │ ╰────────────────────────────────────────────────────────────────────────────────────────────╯ ╭──────────────────────────────────────────────────────────────────────────────────────────────╮ │755 return dest; │ │756 +} │ │757 + │ │758 +/// Shortcut for calling `readSliceShort` with a buffer provided by `allocator`, │ │759 +/// shrinking allocation if stream reached the end. │ │760 +pub fn readAllocShort(r: *Reader, allocator: Allocator, len: usize) ReadAllocError![]u8 {│ │761 + const dest = try allocator.alloc(u8, len); │ │762 + errdefer allocator.free(dest); │ │763 + const n = try readSliceShort(r, dest); │ │764 + if (n == dest.len) return dest; │ │765 + return try allocator.realloc(dest, n); │ │766 } │ │767 │ │768 pub const DelimiterError = error{ │ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────╮ │1757 try testing.expectEqual(4, try ri.interface.readSliceShort(&buf));│ │1758 try testing.expectEqualStrings("Fren", buf[0..4]); │ │1759 try testing.expectEqual(0, try ri.interface.readSliceShort(&buf));│ │1760 +} │ │1761 + │ │1762 +test readAllocAll { │ │1763 + const allocator = testing.allocator; │ │1764 + var r: Reader = .fixed("HelloFren"); │ │1765 + │ │1766 + const s1 = try r.readAllocAll(allocator, 5); │ │1767 + defer allocator.free(s1); │ │1768 + try testing.expectEqualStrings("Hello", s1); │ │1769 + │ │1770 + const s2 = try r.readAllocAll(allocator, 4); │ │1771 + defer allocator.free(s2); │ │1772 + try testing.expectEqualStrings("Fren", s2); │ │1773 +} │ │1774 + │ │1775 +test "readAllocAll with buffer bigger than content" { │ │1776 + const allocator = testing.allocator; │ │1777 + var r: Reader = .fixed("HelloFren"); │ │1778 + │ │1779 + const s1 = try r.readAllocAll(allocator, 5); │ │1780 + defer allocator.free(s1); │ │1781 + try testing.expectEqualStrings("Hello", s1); │ │1782 + │ │1783 + const res = r.readAllocAll(allocator, 10); │ │1784 + try testing.expectError(Error.EndOfStream, res); │ │1785 +} │ │1786 + │ │1787 +test readAllocShort { │ │1788 + var r: Reader = .fixed("HelloFren"); │ │1789 + │ │1790 + const s1 = try r.readAllocShort(testing.allocator, 5); │ │1791 + defer testing.allocator.free(s1); │ │1792 + try testing.expectEqualStrings("Hello", s1); │ │1793 + │ │1794 + const s2 = try r.readAllocShort(testing.allocator, 10); │ │1795 + defer testing.allocator.free(s2); │ │1796 + try testing.expectEqualStrings("Fren", s2); │ │1797 + │ │1798 + const s3 = try r.readAllocShort(testing.allocator, 10); │ │1799 + defer testing.allocator.free(s3); │ │1800 + try testing.expectEqual(0, s3.len); │ │1801 } │ │1802 │ │1803 test readVec { │ ╰────────────────────────────────────────────────────────────────────────────╯ ╭ changed ────────────╮ │lib/std/debug/Pdb.zig│ ╰─────────────────────╯ ╭────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │171 const header = try stream.interface.peekStruct(pdb.IpiStreamHeader, .little); │ │172 if (header.version != .v80) // only value observed by LLVM team │ │173 return error.UnknownPDBVersion; │ │174 - self.ipi = try stream.interface.readAlloc(gpa, @sizeOf(pdb.IpiStreamHeader) + header.type_record_bytes); │ │174 + self.ipi = try stream.interface.readAllocAll(gpa, @sizeOf(pdb.IpiStreamHeader) + header.type_record_bytes);│ │175 } │ │176 │ │177 pub fn parseInfoStream(self: *Pdb) !void { │ ╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────╮ │196 // Find the string table. │ │197 const string_table_index = str_tab_index: { │ │198 const name_bytes_len = try reader.takeInt(u32, .little); │ │199 - const name_bytes = try reader.readAlloc(gpa, name_bytes_len); │ │199 + const name_bytes = try reader.readAllocAll(gpa, name_bytes_len);│ │200 defer gpa.free(name_bytes); │ │201 │ │202 const HashTableHeader = extern struct { │ ╰─────────────────────────────────────────────────────────────────────────────╯ ╭──────╮ │next →│ ╰──────╯