Skip to content

Commit

Permalink
Reduce use of deprecated IO types
Browse files Browse the repository at this point in the history
Related: ziglang#4917
  • Loading branch information
jayschwa authored and dgbuckley committed Mar 9, 2021
1 parent 744d7b9 commit 447622a
Show file tree
Hide file tree
Showing 43 changed files with 159 additions and 159 deletions.
8 changes: 4 additions & 4 deletions doc/docgen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@ pub fn main() !void {
var out_file = try fs.cwd().createFile(out_file_name, .{});
defer out_file.close();

const input_file_bytes = try in_file.inStream().readAllAlloc(allocator, max_doc_file_size);
const input_file_bytes = try in_file.reader().readAllAlloc(allocator, max_doc_file_size);

var buffered_out_stream = io.bufferedOutStream(out_file.writer());
var buffered_writer = io.bufferedWriter(out_file.writer());

var tokenizer = Tokenizer.init(in_file_name, input_file_bytes);
var toc = try genToc(allocator, &tokenizer);

try fs.cwd().makePath(tmp_dir_name);
defer fs.cwd().deleteTree(tmp_dir_name) catch {};

try genHtml(allocator, &tokenizer, &toc, buffered_out_stream.writer(), zig_exe);
try buffered_out_stream.flush();
try genHtml(allocator, &tokenizer, &toc, buffered_writer.writer(), zig_exe);
try buffered_writer.flush();
}

const Token = struct {
Expand Down
2 changes: 1 addition & 1 deletion lib/std/Progress.zig
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ fn refreshWithHeldLock(self: *Progress) void {
pub fn log(self: *Progress, comptime format: []const u8, args: anytype) void {
const file = self.terminal orelse return;
self.refresh();
file.outStream().print(format, args) catch {
file.writer().print(format, args) catch {
self.terminal = null;
return;
};
Expand Down
8 changes: 4 additions & 4 deletions lib/std/atomic/queue.zig
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ pub fn Queue(comptime T: type) type {

/// Dumps the contents of the queue to `stderr`.
pub fn dump(self: *Self) void {
self.dumpToStream(std.io.getStdErr().outStream()) catch return;
self.dumpToStream(std.io.getStdErr().writer()) catch return;
}

/// Dumps the contents of the queue to `stream`.
Expand Down Expand Up @@ -351,7 +351,7 @@ test "std.atomic.Queue dump" {

// Test empty stream
fbs.reset();
try queue.dumpToStream(fbs.outStream());
try queue.dumpToStream(fbs.writer());
expect(mem.eql(u8, buffer[0..fbs.pos],
\\head: (null)
\\tail: (null)
Expand All @@ -367,7 +367,7 @@ test "std.atomic.Queue dump" {
queue.put(&node_0);

fbs.reset();
try queue.dumpToStream(fbs.outStream());
try queue.dumpToStream(fbs.writer());

var expected = try std.fmt.bufPrint(expected_buffer[0..],
\\head: 0x{x}=1
Expand All @@ -387,7 +387,7 @@ test "std.atomic.Queue dump" {
queue.put(&node_1);

fbs.reset();
try queue.dumpToStream(fbs.outStream());
try queue.dumpToStream(fbs.writer());

expected = try std.fmt.bufPrint(expected_buffer[0..],
\\head: 0x{x}=1
Expand Down
10 changes: 5 additions & 5 deletions lib/std/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@ pub const Builder = struct {

try child.spawn();

const stdout = try child.stdout.?.inStream().readAllAlloc(self.allocator, max_output_size);
const stdout = try child.stdout.?.reader().readAllAlloc(self.allocator, max_output_size);
errdefer self.allocator.free(stdout);

const term = try child.wait();
Expand Down Expand Up @@ -1849,7 +1849,7 @@ pub const LibExeObjStep = struct {
}

pub fn addBuildOption(self: *LibExeObjStep, comptime T: type, name: []const u8, value: T) void {
const out = self.build_options_contents.outStream();
const out = self.build_options_contents.writer();
switch (T) {
[]const []const u8 => {
out.print("pub const {z}: []const []const u8 = &[_][]const u8{{\n", .{name}) catch unreachable;
Expand Down Expand Up @@ -2295,16 +2295,16 @@ pub const LibExeObjStep = struct {
} else {
var mcpu_buffer = std.ArrayList(u8).init(builder.allocator);

try mcpu_buffer.outStream().print("-mcpu={s}", .{cross.cpu.model.name});
try mcpu_buffer.writer().print("-mcpu={s}", .{cross.cpu.model.name});

for (all_features) |feature, i_usize| {
const i = @intCast(std.Target.Cpu.Feature.Set.Index, i_usize);
const in_cpu_set = populated_cpu_features.isEnabled(i);
const in_actual_set = cross.cpu.features.isEnabled(i);
if (in_cpu_set and !in_actual_set) {
try mcpu_buffer.outStream().print("-{s}", .{feature.name});
try mcpu_buffer.writer().print("-{s}", .{feature.name});
} else if (!in_cpu_set and in_actual_set) {
try mcpu_buffer.outStream().print("+{s}", .{feature.name});
try mcpu_buffer.writer().print("+{s}", .{feature.name});
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/std/build/run.zig
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ pub const RunStep = struct {

switch (self.stdout_action) {
.expect_exact, .expect_matches => {
stdout = child.stdout.?.inStream().readAllAlloc(self.builder.allocator, max_stdout_size) catch unreachable;
stdout = child.stdout.?.reader().readAllAlloc(self.builder.allocator, max_stdout_size) catch unreachable;
},
.inherit, .ignore => {},
}
Expand All @@ -210,7 +210,7 @@ pub const RunStep = struct {

switch (self.stderr_action) {
.expect_exact, .expect_matches => {
stderr = child.stderr.?.inStream().readAllAlloc(self.builder.allocator, max_stdout_size) catch unreachable;
stderr = child.stderr.?.reader().readAllAlloc(self.builder.allocator, max_stdout_size) catch unreachable;
},
.inherit, .ignore => {},
}
Expand Down
2 changes: 1 addition & 1 deletion lib/std/child_process.zig
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ fn writeIntFd(fd: i32, value: ErrInt) !void {
.capable_io_mode = .blocking,
.intended_io_mode = .blocking,
};
file.outStream().writeIntNative(u64, @intCast(u64, value)) catch return error.SystemResources;
file.writer().writeIntNative(u64, @intCast(u64, value)) catch return error.SystemResources;
}

fn readIntFd(fd: i32) !ErrInt {
Expand Down
8 changes: 4 additions & 4 deletions lib/std/coff.zig
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ pub const Coff = struct {
pub fn loadHeader(self: *Coff) !void {
const pe_pointer_offset = 0x3C;

const in = self.in_file.inStream();
const in = self.in_file.reader();

var magic: [2]u8 = undefined;
try in.readNoEof(magic[0..]);
Expand Down Expand Up @@ -163,7 +163,7 @@ pub const Coff = struct {
}

fn loadOptionalHeader(self: *Coff) !void {
const in = self.in_file.inStream();
const in = self.in_file.reader();
self.pe_header.magic = try in.readIntLittle(u16);
// For now we're only interested in finding the reference to the .pdb,
// so we'll skip most of this header, which size is different in 32
Expand Down Expand Up @@ -206,7 +206,7 @@ pub const Coff = struct {
const debug_dir = &self.pe_header.data_directory[DEBUG_DIRECTORY];
const file_offset = debug_dir.virtual_address - header.virtual_address + header.pointer_to_raw_data;

const in = self.in_file.inStream();
const in = self.in_file.reader();
try self.in_file.seekTo(file_offset);

// Find the correct DebugDirectoryEntry, and where its data is stored.
Expand Down Expand Up @@ -257,7 +257,7 @@ pub const Coff = struct {

try self.sections.ensureCapacity(self.coff_header.number_of_sections);

const in = self.in_file.inStream();
const in = self.in_file.reader();

var name: [8]u8 = undefined;

Expand Down
2 changes: 1 addition & 1 deletion lib/std/crypto/benchmark.zig
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ fn mode(comptime x: comptime_int) comptime_int {
}

pub fn main() !void {
const stdout = std.io.getStdOut().outStream();
const stdout = std.io.getStdOut().writer();

var buffer: [1024]u8 = undefined;
var fixed = std.heap.FixedBufferAllocator.init(buffer[0..]);
Expand Down
36 changes: 18 additions & 18 deletions lib/std/debug.zig
Original file line number Diff line number Diff line change
Expand Up @@ -517,15 +517,15 @@ fn populateModule(di: *ModuleDebugInfo, mod: *Module) !void {

const modi = di.pdb.getStreamById(mod.mod_info.ModuleSymStream) orelse return error.MissingDebugInfo;

const signature = try modi.inStream().readIntLittle(u32);
const signature = try modi.reader().readIntLittle(u32);
if (signature != 4)
return error.InvalidDebugInfo;

mod.symbols = try allocator.alloc(u8, mod.mod_info.SymByteSize - 4);
try modi.inStream().readNoEof(mod.symbols);
try modi.reader().readNoEof(mod.symbols);

mod.subsect_info = try allocator.alloc(u8, mod.mod_info.C13ByteSize);
try modi.inStream().readNoEof(mod.subsect_info);
try modi.reader().readNoEof(mod.subsect_info);

var sect_offset: usize = 0;
var skip_len: usize = undefined;
Expand Down Expand Up @@ -704,21 +704,21 @@ fn readCoffDebugInfo(allocator: *mem.Allocator, coff_file: File) !ModuleDebugInf
try di.pdb.openFile(di.coff, path);

var pdb_stream = di.pdb.getStream(pdb.StreamType.Pdb) orelse return error.InvalidDebugInfo;
const version = try pdb_stream.inStream().readIntLittle(u32);
const signature = try pdb_stream.inStream().readIntLittle(u32);
const age = try pdb_stream.inStream().readIntLittle(u32);
const version = try pdb_stream.reader().readIntLittle(u32);
const signature = try pdb_stream.reader().readIntLittle(u32);
const age = try pdb_stream.reader().readIntLittle(u32);
var guid: [16]u8 = undefined;
try pdb_stream.inStream().readNoEof(&guid);
try pdb_stream.reader().readNoEof(&guid);
if (version != 20000404) // VC70, only value observed by LLVM team
return error.UnknownPDBVersion;
if (!mem.eql(u8, &di.coff.guid, &guid) or di.coff.age != age)
return error.PDBMismatch;
// We validated the executable and pdb match.

const string_table_index = str_tab_index: {
const name_bytes_len = try pdb_stream.inStream().readIntLittle(u32);
const name_bytes_len = try pdb_stream.reader().readIntLittle(u32);
const name_bytes = try allocator.alloc(u8, name_bytes_len);
try pdb_stream.inStream().readNoEof(name_bytes);
try pdb_stream.reader().readNoEof(name_bytes);

const HashTableHeader = packed struct {
Size: u32,
Expand All @@ -728,26 +728,26 @@ fn readCoffDebugInfo(allocator: *mem.Allocator, coff_file: File) !ModuleDebugInf
return cap * 2 / 3 + 1;
}
};
const hash_tbl_hdr = try pdb_stream.inStream().readStruct(HashTableHeader);
const hash_tbl_hdr = try pdb_stream.reader().readStruct(HashTableHeader);
if (hash_tbl_hdr.Capacity == 0)
return error.InvalidDebugInfo;

if (hash_tbl_hdr.Size > HashTableHeader.maxLoad(hash_tbl_hdr.Capacity))
return error.InvalidDebugInfo;

const present = try readSparseBitVector(&pdb_stream.inStream(), allocator);
const present = try readSparseBitVector(&pdb_stream.reader(), allocator);
if (present.len != hash_tbl_hdr.Size)
return error.InvalidDebugInfo;
const deleted = try readSparseBitVector(&pdb_stream.inStream(), allocator);
const deleted = try readSparseBitVector(&pdb_stream.reader(), allocator);

const Bucket = struct {
first: u32,
second: u32,
};
const bucket_list = try allocator.alloc(Bucket, present.len);
for (present) |_| {
const name_offset = try pdb_stream.inStream().readIntLittle(u32);
const name_index = try pdb_stream.inStream().readIntLittle(u32);
const name_offset = try pdb_stream.reader().readIntLittle(u32);
const name_index = try pdb_stream.reader().readIntLittle(u32);
const name = mem.spanZ(std.meta.assumeSentinel(name_bytes.ptr + name_offset, 0));
if (mem.eql(u8, name, "/names")) {
break :str_tab_index name_index;
Expand All @@ -762,7 +762,7 @@ fn readCoffDebugInfo(allocator: *mem.Allocator, coff_file: File) !ModuleDebugInf
const dbi = di.pdb.dbi;

// Dbi Header
const dbi_stream_header = try dbi.inStream().readStruct(pdb.DbiStreamHeader);
const dbi_stream_header = try dbi.reader().readStruct(pdb.DbiStreamHeader);
if (dbi_stream_header.VersionHeader != 19990903) // V70, only value observed by LLVM team
return error.UnknownPDBVersion;
if (dbi_stream_header.Age != age)
Expand All @@ -776,7 +776,7 @@ fn readCoffDebugInfo(allocator: *mem.Allocator, coff_file: File) !ModuleDebugInf
// Module Info Substream
var mod_info_offset: usize = 0;
while (mod_info_offset != mod_info_size) {
const mod_info = try dbi.inStream().readStruct(pdb.ModInfo);
const mod_info = try dbi.reader().readStruct(pdb.ModInfo);
var this_record_len: usize = @sizeOf(pdb.ModInfo);

const module_name = try dbi.readNullTermString(allocator);
Expand Down Expand Up @@ -814,14 +814,14 @@ fn readCoffDebugInfo(allocator: *mem.Allocator, coff_file: File) !ModuleDebugInf
var sect_contribs = ArrayList(pdb.SectionContribEntry).init(allocator);
var sect_cont_offset: usize = 0;
if (section_contrib_size != 0) {
const ver = @intToEnum(pdb.SectionContrSubstreamVersion, try dbi.inStream().readIntLittle(u32));
const ver = @intToEnum(pdb.SectionContrSubstreamVersion, try dbi.reader().readIntLittle(u32));
if (ver != pdb.SectionContrSubstreamVersion.Ver60)
return error.InvalidDebugInfo;
sect_cont_offset += @sizeOf(u32);
}
while (sect_cont_offset != section_contrib_size) {
const entry = try sect_contribs.addOne();
entry.* = try dbi.inStream().readStruct(pdb.SectionContribEntry);
entry.* = try dbi.reader().readStruct(pdb.SectionContribEntry);
sect_cont_offset += @sizeOf(pdb.SectionContribEntry);

if (sect_cont_offset > section_contrib_size)
Expand Down
10 changes: 5 additions & 5 deletions lib/std/dwarf.zig
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ pub const DwarfInfo = struct {

fn scanAllFunctions(di: *DwarfInfo) !void {
var stream = io.fixedBufferStream(di.debug_info);
const in = &stream.inStream();
const in = &stream.reader();
const seekable = &stream.seekableStream();
var this_unit_offset: u64 = 0;

Expand Down Expand Up @@ -512,7 +512,7 @@ pub const DwarfInfo = struct {

fn scanAllCompileUnits(di: *DwarfInfo) !void {
var stream = io.fixedBufferStream(di.debug_info);
const in = &stream.inStream();
const in = &stream.reader();
const seekable = &stream.seekableStream();
var this_unit_offset: u64 = 0;

Expand Down Expand Up @@ -585,7 +585,7 @@ pub const DwarfInfo = struct {
if (di.debug_ranges) |debug_ranges| {
if (compile_unit.die.getAttrSecOffset(AT_ranges)) |ranges_offset| {
var stream = io.fixedBufferStream(debug_ranges);
const in = &stream.inStream();
const in = &stream.reader();
const seekable = &stream.seekableStream();

// All the addresses in the list are relative to the value
Expand Down Expand Up @@ -640,7 +640,7 @@ pub const DwarfInfo = struct {

fn parseAbbrevTable(di: *DwarfInfo, offset: u64) !AbbrevTable {
var stream = io.fixedBufferStream(di.debug_abbrev);
const in = &stream.inStream();
const in = &stream.reader();
const seekable = &stream.seekableStream();

try seekable.seekTo(offset);
Expand Down Expand Up @@ -691,7 +691,7 @@ pub const DwarfInfo = struct {

pub fn getLineNumberInfo(di: *DwarfInfo, compile_unit: CompileUnit, target_address: usize) !debug.LineInfo {
var stream = io.fixedBufferStream(di.debug_line);
const in = &stream.inStream();
const in = &stream.reader();
const seekable = &stream.seekableStream();

const compile_unit_cwd = try compile_unit.die.getAttrString(di, AT_comp_dir);
Expand Down
2 changes: 1 addition & 1 deletion lib/std/heap/logging_allocator.zig
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ test "LoggingAllocator" {

var allocator_buf: [10]u8 = undefined;
var fixedBufferAllocator = std.mem.validationWrap(std.heap.FixedBufferAllocator.init(&allocator_buf));
const allocator = &loggingAllocator(&fixedBufferAllocator.allocator, fbs.outStream()).allocator;
const allocator = &loggingAllocator(&fixedBufferAllocator.allocator, fbs.writer()).allocator;

var a = try allocator.alloc(u8, 10);
a = allocator.shrink(a, 5);
Expand Down
2 changes: 1 addition & 1 deletion lib/std/io/buffered_atomic_file.zig
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub const BufferedAtomicFile = struct {
self.atomic_file = try dir.atomicFile(dest_path, atomic_file_options);
errdefer self.atomic_file.deinit();

self.file_stream = self.atomic_file.file.outStream();
self.file_stream = self.atomic_file.file.writer();
self.buffered_stream = .{ .unbuffered_writer = self.file_stream };
return self;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/std/io/fixed_buffer_stream.zig
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub fn FixedBufferStream(comptime Buffer: type) type {
return .{ .context = self };
}

/// Deprecated: use `inStream`
/// Deprecated: use `reader`
pub fn inStream(self: *Self) InStream {
return .{ .context = self };
}
Expand Down
6 changes: 3 additions & 3 deletions lib/std/io/test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ test "write a file, read it, then delete it" {
var file = try tmp.dir.createFile(tmp_file_name, .{});
defer file.close();

var buf_stream = io.bufferedOutStream(file.outStream());
const st = buf_stream.outStream();
var buf_stream = io.bufferedWriter(file.writer());
const st = buf_stream.writer();
try st.print("begin", .{});
try st.writeAll(data[0..]);
try st.print("end", .{});
Expand Down Expand Up @@ -72,7 +72,7 @@ test "BitStreams with File Stream" {
var file = try tmp.dir.createFile(tmp_file_name, .{});
defer file.close();

var bit_stream = io.bitOutStream(builtin.endian, file.outStream());
var bit_stream = io.bitWriter(builtin.endian, file.writer());

try bit_stream.writeBits(@as(u2, 1), 1);
try bit_stream.writeBits(@as(u5, 2), 2);
Expand Down
Loading

0 comments on commit 447622a

Please sign in to comment.