Skip to content

Commit de48903

Browse files
AndrewKraevskiiandrewrk
authored andcommitted
Remove usages of deprecatedWriter
1 parent 37ecaae commit de48903

File tree

6 files changed

+59
-12
lines changed

6 files changed

+59
-12
lines changed

lib/compiler/reduce.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub fn main() !void {
6868
const arg = args[i];
6969
if (mem.startsWith(u8, arg, "-")) {
7070
if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
71-
const stdout = std.fs.File.stdout().deprecatedWriter();
71+
const stdout = std.fs.File.stdout();
7272
try stdout.writeAll(usage);
7373
return std.process.cleanExit();
7474
} else if (mem.eql(u8, arg, "--")) {

lib/std/Random/benchmark.zig

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ fn mode(comptime x: comptime_int) comptime_int {
122122
}
123123

124124
pub fn main() !void {
125-
const stdout = std.fs.File.stdout().deprecatedWriter();
125+
var stdout_buffer: [0x100]u8 = undefined;
126+
var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);
127+
const stdout = &stdout_writer.interface;
126128

127129
var buffer: [1024]u8 = undefined;
128130
var fixed = std.heap.FixedBufferAllocator.init(buffer[0..]);
@@ -139,6 +141,7 @@ pub fn main() !void {
139141
while (i < args.len) : (i += 1) {
140142
if (std.mem.eql(u8, args[i], "--mode")) {
141143
try stdout.print("{}\n", .{builtin.mode});
144+
try stdout.flush();
142145
return;
143146
} else if (std.mem.eql(u8, args[i], "--filter")) {
144147
i += 1;
@@ -179,6 +182,8 @@ pub fn main() !void {
179182
inline for (prngs) |R| {
180183
if (filter == null or std.mem.indexOf(u8, R.name, filter.?) != null) {
181184
try stdout.print("{s} (long outputs)\n", .{R.name});
185+
try stdout.flush();
186+
182187
const result_long = try benchmark(R, count, long_block_size);
183188
try stdout.print(" {:5} MiB/s\n", .{result_long.throughput / (1 * MiB)});
184189
}
@@ -188,6 +193,8 @@ pub fn main() !void {
188193
inline for (prngs) |R| {
189194
if (filter == null or std.mem.indexOf(u8, R.name, filter.?) != null) {
190195
try stdout.print("{s} (short outputs)\n", .{R.name});
196+
try stdout.flush();
197+
191198
const result_short = try benchmark(R, count, short_block_size);
192199
try stdout.print(" {:5} MiB/s\n", .{result_short.throughput / (1 * MiB)});
193200
}
@@ -199,6 +206,8 @@ pub fn main() !void {
199206
inline for (csprngs) |R| {
200207
if (filter == null or std.mem.indexOf(u8, R.name, filter.?) != null) {
201208
try stdout.print("{s} (cryptographic, long outputs)\n", .{R.name});
209+
try stdout.flush();
210+
202211
const result_long = try benchmark(R, count, long_block_size);
203212
try stdout.print(" {:5} MiB/s\n", .{result_long.throughput / (1 * MiB)});
204213
}
@@ -208,10 +217,13 @@ pub fn main() !void {
208217
inline for (csprngs) |R| {
209218
if (filter == null or std.mem.indexOf(u8, R.name, filter.?) != null) {
210219
try stdout.print("{s} (cryptographic, short outputs)\n", .{R.name});
220+
try stdout.flush();
221+
211222
const result_short = try benchmark(R, count, short_block_size);
212223
try stdout.print(" {:5} MiB/s\n", .{result_short.throughput / (1 * MiB)});
213224
}
214225
}
215226
}
216227
}
228+
try stdout.flush();
217229
}

lib/std/crypto/benchmark.zig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,8 @@ fn mode(comptime x: comptime_int) comptime_int {
460460
}
461461

462462
pub fn main() !void {
463-
var stdout_buffer: [4096]u8 = undefined;
463+
// Size of buffer is about size of printed message.
464+
var stdout_buffer: [0x100]u8 = undefined;
464465
var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);
465466
const stdout = &stdout_writer.interface;
466467

lib/std/hash/benchmark.zig

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@ const Hash = struct {
1919
has_iterative_api: bool = true,
2020
has_crypto_api: bool = false,
2121
has_anytype_api: ?[]const comptime_int = null,
22+
/// `final` value should be read from this field.
23+
has_struct_api: ?[]const u8 = null,
2224
init_u8s: ?[]const u8 = null,
2325
init_u64: ?u64 = null,
26+
init_default: bool = false,
2427
};
2528

2629
const hashes = [_]Hash{
@@ -54,6 +57,8 @@ const hashes = [_]Hash{
5457
Hash{
5558
.ty = hash.Adler32,
5659
.name = "adler32",
60+
.has_struct_api = "adler",
61+
.init_default = true,
5762
},
5863
Hash{
5964
.ty = hash.crc.Crc32,
@@ -112,21 +117,29 @@ pub fn benchmarkHash(comptime H: anytype, bytes: usize, allocator: std.mem.Alloc
112117

113118
const block_count = bytes / block_size;
114119

115-
var h = blk: {
120+
var h: H.ty = blk: {
116121
if (H.init_u8s) |init| {
117-
break :blk H.ty.init(init[0..H.ty.key_length]);
122+
break :blk .init(init[0..H.ty.key_length]);
118123
}
119124
if (H.init_u64) |init| {
120-
break :blk H.ty.init(init);
125+
break :blk .init(init);
121126
}
122-
break :blk H.ty.init();
127+
if (H.init_default) {
128+
break :blk .{};
129+
}
130+
break :blk .init();
123131
};
124132

125133
var timer = try Timer.start();
126134
for (0..block_count) |i| {
127135
h.update(blocks[i * block_size ..][0..block_size]);
128136
}
129-
const final = if (H.has_crypto_api) @as(u64, @truncate(h.finalInt())) else h.final();
137+
const final = if (H.has_struct_api) |field_name|
138+
@field(h, field_name)
139+
else if (H.has_crypto_api)
140+
@as(u64, @truncate(h.finalInt()))
141+
else
142+
h.final();
130143
std.mem.doNotOptimizeAway(final);
131144

132145
const elapsed_ns = timer.read();
@@ -340,7 +353,9 @@ fn mode(comptime x: comptime_int) comptime_int {
340353
}
341354

342355
pub fn main() !void {
343-
const stdout = std.fs.File.stdout().deprecatedWriter();
356+
var stdout_buffer: [0x100]u8 = undefined;
357+
var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);
358+
const stdout = &stdout_writer.interface;
344359

345360
var buffer: [1024]u8 = undefined;
346361
var fixed = std.heap.FixedBufferAllocator.init(buffer[0..]);
@@ -360,6 +375,7 @@ pub fn main() !void {
360375
while (i < args.len) : (i += 1) {
361376
if (std.mem.eql(u8, args[i], "--mode")) {
362377
try stdout.print("{}\n", .{builtin.mode});
378+
try stdout.flush();
363379
return;
364380
} else if (std.mem.eql(u8, args[i], "--seed")) {
365381
i += 1;
@@ -397,6 +413,7 @@ pub fn main() !void {
397413
key_size = try std.fmt.parseUnsigned(usize, args[i], 10);
398414
if (key_size.? > block_size) {
399415
try stdout.print("key_size cannot exceed block size of {}\n", .{block_size});
416+
try stdout.flush();
400417
std.process.exit(1);
401418
}
402419
} else if (std.mem.eql(u8, args[i], "--iterative-only")) {
@@ -416,6 +433,7 @@ pub fn main() !void {
416433

417434
if (test_iterative_only and test_small_key_only) {
418435
try stdout.print("Cannot use iterative-only and small-key-only together!\n", .{});
436+
try stdout.flush();
419437
usage();
420438
std.process.exit(1);
421439
}
@@ -428,13 +446,15 @@ pub fn main() !void {
428446
if (filter == null or std.mem.indexOf(u8, H.name, filter.?) != null) hash: {
429447
if (!test_iterative_only or H.has_iterative_api) {
430448
try stdout.print("{s}\n", .{H.name});
449+
try stdout.flush();
431450

432451
// Always reseed prior to every call so we are hashing the same buffer contents.
433452
// This allows easier comparison between different implementations.
434453
if (H.has_iterative_api and !test_small_key_only) {
435454
prng.seed(seed);
436455
const result = try benchmarkHash(H, count, allocator);
437456
try stdout.print(" iterative: {:5} MiB/s [{x:0<16}]\n", .{ result.throughput / (1 * MiB), result.hash });
457+
try stdout.flush();
438458
}
439459

440460
if (!test_iterative_only) {
@@ -447,6 +467,7 @@ pub fn main() !void {
447467
result_small.throughput / size,
448468
result_small.hash,
449469
});
470+
try stdout.flush();
450471

451472
if (!test_arrays) break :hash;
452473
if (H.has_anytype_api) |sizes| {
@@ -464,6 +485,7 @@ pub fn main() !void {
464485
result_ptr.throughput / (1 * MiB),
465486
result_ptr.hash,
466487
});
488+
try stdout.flush();
467489
}
468490
}
469491
}
@@ -476,6 +498,7 @@ pub fn main() !void {
476498
result_small.throughput / default_small_key_size,
477499
result_small.hash,
478500
});
501+
try stdout.flush();
479502

480503
if (!test_arrays) break :hash;
481504
if (H.has_anytype_api) |sizes| {
@@ -488,6 +511,7 @@ pub fn main() !void {
488511
result.throughput / (1 * MiB),
489512
result.hash,
490513
});
514+
try stdout.flush();
491515
}
492516
try stdout.print(" array ptr: \n", .{});
493517
inline for (sizes) |exact_size| {
@@ -498,6 +522,7 @@ pub fn main() !void {
498522
result.throughput / (1 * MiB),
499523
result.hash,
500524
});
525+
try stdout.flush();
501526
}
502527
}
503528
}

lib/std/log.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@
4747
//! // Print the message to stderr, silently ignoring any errors
4848
//! std.debug.lockStdErr();
4949
//! defer std.debug.unlockStdErr();
50-
//! const stderr = std.fs.File.stderr().deprecatedWriter();
51-
//! nosuspend stderr.print(prefix ++ format ++ "\n", args) catch return;
50+
//! var stderr = std.fs.File.stderr().writer(&.{});
51+
//! nosuspend stderr.interface.print(prefix ++ format ++ "\n", args) catch return;
5252
//! }
5353
//!
5454
//! pub fn main() void {

lib/std/unicode/throughput_test.zig

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,35 +39,44 @@ fn benchmarkCodepointCount(buf: []const u8) !ResultCount {
3939
}
4040

4141
pub fn main() !void {
42-
const stdout = std.fs.File.stdout().deprecatedWriter();
42+
// Size of buffer is about size of printed message.
43+
var stdout_buffer: [0x100]u8 = undefined;
44+
var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);
45+
const stdout = &stdout_writer.interface;
4346

4447
try stdout.print("short ASCII strings\n", .{});
48+
try stdout.flush();
4549
{
4650
const result = try benchmarkCodepointCount("abc");
4751
try stdout.print(" count: {:5} MiB/s [{d}]\n", .{ result.throughput / (1 * MiB), result.count });
4852
}
4953

5054
try stdout.print("short Unicode strings\n", .{});
55+
try stdout.flush();
5156
{
5257
const result = try benchmarkCodepointCount("ŌŌŌ");
5358
try stdout.print(" count: {:5} MiB/s [{d}]\n", .{ result.throughput / (1 * MiB), result.count });
5459
}
5560

5661
try stdout.print("pure ASCII strings\n", .{});
62+
try stdout.flush();
5763
{
5864
const result = try benchmarkCodepointCount("hello" ** 16);
5965
try stdout.print(" count: {:5} MiB/s [{d}]\n", .{ result.throughput / (1 * MiB), result.count });
6066
}
6167

6268
try stdout.print("pure Unicode strings\n", .{});
69+
try stdout.flush();
6370
{
6471
const result = try benchmarkCodepointCount("こんにちは" ** 16);
6572
try stdout.print(" count: {:5} MiB/s [{d}]\n", .{ result.throughput / (1 * MiB), result.count });
6673
}
6774

6875
try stdout.print("mixed ASCII/Unicode strings\n", .{});
76+
try stdout.flush();
6977
{
7078
const result = try benchmarkCodepointCount("Hyvää huomenta" ** 16);
7179
try stdout.print(" count: {:5} MiB/s [{d}]\n", .{ result.throughput / (1 * MiB), result.count });
7280
}
81+
try stdout.flush();
7382
}

0 commit comments

Comments
 (0)