Merge remote-tracking branch 'origin/fixes' into wrangle-writer-buffering

This commit is contained in:
Andrew Kelley 2025-07-10 16:57:41 -07:00
commit aa81c2df7c
15 changed files with 38 additions and 21 deletions

View File

@ -387,6 +387,18 @@ set(ZIG_STAGE2_SOURCES
lib/std/Build.zig
lib/std/Build/Cache.zig
lib/std/Build/Cache/DepTokenizer.zig
lib/std/Io.zig
lib/std/Io/Reader.zig
lib/std/Io/Writer.zig
lib/std/Io/buffered_atomic_file.zig
lib/std/Io/buffered_writer.zig
lib/std/Io/change_detection_stream.zig
lib/std/Io/counting_reader.zig
lib/std/Io/counting_writer.zig
lib/std/Io/find_byte_writer.zig
lib/std/Io/fixed_buffer_stream.zig
lib/std/Io/limited_reader.zig
lib/std/Io/seekable_stream.zig
lib/std/Progress.zig
lib/std/Random.zig
lib/std/Target.zig
@ -448,9 +460,6 @@ set(ZIG_STAGE2_SOURCES
lib/std/hash_map.zig
lib/std/heap.zig
lib/std/heap/arena_allocator.zig
lib/std/io.zig
lib/std/io/Reader.zig
lib/std/io/Writer.zig
lib/std/json.zig
lib/std/leb128.zig
lib/std/log.zig

View File

@ -79,13 +79,13 @@ pub const Limit = enum(usize) {
}
};
pub const Reader = @import("io/Reader.zig");
pub const Writer = @import("io/Writer.zig");
pub const Reader = @import("Io/Reader.zig");
pub const Writer = @import("Io/Writer.zig");
pub const ChangeDetectionStream = @import("io/change_detection_stream.zig").ChangeDetectionStream;
pub const changeDetectionStream = @import("io/change_detection_stream.zig").changeDetectionStream;
pub const ChangeDetectionStream = @import("Io/change_detection_stream.zig").ChangeDetectionStream;
pub const changeDetectionStream = @import("Io/change_detection_stream.zig").changeDetectionStream;
pub const tty = @import("io/tty.zig");
pub const tty = @import("Io/tty.zig");
pub fn poll(
gpa: Allocator,
@ -495,5 +495,5 @@ pub fn PollFiles(comptime StreamEnum: type) type {
test {
_ = Reader;
_ = Writer;
_ = @import("io/test.zig");
_ = @import("Io/test.zig");
}

View File

@ -219,13 +219,16 @@ pub fn unlockStderrWriter() void {
std.Progress.unlockStderrWriter();
}
/// Print to stderr, unbuffered, and silently returning on failure. Intended
/// for use in "printf debugging". Use `std.log` functions for proper logging.
/// Print to stderr, silently returning on failure. Intended for use in "printf
/// debugging". Use `std.log` functions for proper logging.
///
/// Uses a 64-byte buffer for formatted printing which is flushed before this
/// function returns.
pub fn print(comptime fmt: []const u8, args: anytype) void {
var buffer: [32]u8 = undefined;
const bw = lockStderrWriter(&buffer);
var buffer: [64]u8 = undefined;
const w = lockStderrWriter(&buffer);
defer unlockStderrWriter();
nosuspend bw.print(fmt, args) catch return;
nosuspend w.print(fmt, args) catch return;
}
pub fn getStderrMutex() *std.Thread.Mutex {

View File

@ -227,8 +227,8 @@ test join {
try testJoinMaybeZWindows(&[_][]const u8{ "c:\\a\\", "b\\", "c" }, "c:\\a\\b\\c", zero);
try testJoinMaybeZWindows(
&[_][]const u8{ "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std", "io.zig" },
"c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std\\io.zig",
&[_][]const u8{ "c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std", "ab.zig" },
"c:\\home\\andy\\dev\\zig\\build\\lib\\zig\\std\\ab.zig",
zero,
);
@ -252,8 +252,8 @@ test join {
try testJoinMaybeZPosix(&[_][]const u8{ "/a/", "b/", "c" }, "/a/b/c", zero);
try testJoinMaybeZPosix(
&[_][]const u8{ "/home/andy/dev/zig/build/lib/zig/std", "io.zig" },
"/home/andy/dev/zig/build/lib/zig/std/io.zig",
&[_][]const u8{ "/home/andy/dev/zig/build/lib/zig/std", "ab.zig" },
"/home/andy/dev/zig/build/lib/zig/std/ab.zig",
zero,
);

View File

@ -136,8 +136,11 @@ pub fn defaultLogEnabled(comptime message_level: Level) bool {
return comptime logEnabled(message_level, default_log_scope);
}
/// The default implementation for the log function, custom log functions may
/// The default implementation for the log function. Custom log functions may
/// forward log messages to this function.
///
/// Uses a 64-byte buffer for formatted printing which is flushed before this
/// function returns.
pub fn defaultLog(
comptime message_level: Level,
comptime scope: @Type(.enum_literal),
@ -146,7 +149,7 @@ pub fn defaultLog(
) void {
const level_txt = comptime message_level.asText();
const prefix2 = if (scope == .default) ": " else "(" ++ @tagName(scope) ++ "): ";
var buffer: [32]u8 = undefined;
var buffer: [64]u8 = undefined;
const stderr = std.debug.lockStderrWriter(&buffer);
defer std.debug.unlockStderrWriter();
nosuspend stderr.print(level_txt ++ prefix2 ++ format ++ "\n", args) catch return;

View File

@ -25,6 +25,7 @@ pub const EnumMap = enums.EnumMap;
pub const EnumSet = enums.EnumSet;
pub const HashMap = hash_map.HashMap;
pub const HashMapUnmanaged = hash_map.HashMapUnmanaged;
pub const Io = @import("Io.zig");
pub const MultiArrayList = @import("multi_array_list.zig").MultiArrayList;
pub const PriorityQueue = @import("priority_queue.zig").PriorityQueue;
pub const PriorityDequeue = @import("priority_dequeue.zig").PriorityDequeue;
@ -65,7 +66,8 @@ pub const hash = @import("hash.zig");
pub const hash_map = @import("hash_map.zig");
pub const heap = @import("heap.zig");
pub const http = @import("http.zig");
pub const io = @import("io.zig");
/// Deprecated
pub const io = Io;
pub const json = @import("json.zig");
pub const leb = @import("leb128.zig");
pub const log = @import("log.zig");