Change usages of fmt.bufPrint* to mem.print* (#36263)

This PR doesn't touch usages inside `lib/compiler/aro`

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/36263
Reviewed-by: Ryan Liptak <squeek502@noreply.codeberg.org>
This commit is contained in:
Krzysztof Wolicki authored and Ryan Liptak committed 2026-09-01 02:21:28 +02:00
1 parent 8bb70dbc3f
commit 36dd7e9c37
59 files changed
+118 -118

No files matched your search

+2 -2
View File
@@ -1,7 +1,7 @@
const std = @import("std");
const expectEqual = std.testing.expectEqual;
const expectEqualStrings = std.testing.expectEqualStrings;
const fmt = std.fmt;
const mem = std.mem;
test "using slices for strings" {
// Zig has no concept of strings. String literals are const pointers
@@ -18,7 +18,7 @@ test "using slices for strings" {
_ = &start;
const all_together_slice = all_together[start..];
// String concatenation example.
const hello_world = try fmt.bufPrint(all_together_slice, "{s} {s}", .{ hello, world });
const hello_world = try mem.print(all_together_slice, "{s} {s}", .{ hello, world });
// Generally, you can use UTF-8 and not worry about whether something is a
// string. If you don't need to deal with individual characters, no need
+2 -2
View File
@@ -56,7 +56,7 @@ fn logFn(
const level_txt = comptime message_level.asText();
const prefix2 = if (scope == .default) ": " else "(" ++ @tagName(scope) ++ "): ";
var buf: [500]u8 = undefined;
const line = std.fmt.bufPrint(&buf, level_txt ++ prefix2 ++ format, args) catch l: {
const line = std.mem.print(&buf, level_txt ++ prefix2 ++ format, args) catch l: {
buf[buf.len - 3 ..][0..3].* = "...".*;
break :l &buf;
};
@@ -116,7 +116,7 @@ pub fn Slice(T: type) type {
pub fn fatal(comptime format: []const u8, args: anytype) noreturn {
var buf: [500]u8 = undefined;
const line = std.fmt.bufPrint(&buf, format, args) catch l: {
const line = std.mem.print(&buf, format, args) catch l: {
buf[buf.len - 3 ..][0..3].* = "...".*;
break :l &buf;
};
+1 -1
View File
@@ -959,7 +959,7 @@ pub fn main(init: process.Init.Minimal) !void {
// trigger a rebuild on all steps with modified inputs, as well as their
// recursive dependants.
var caption_buf: [std.Progress.Node.max_name_len]u8 = undefined;
const caption = std.fmt.bufPrint(&caption_buf, "watching {d} directories, {d} processes", .{
const caption = std.mem.print(&caption_buf, "watching {d} directories, {d} processes", .{
w.dir_count, countSubProcesses(&maker),
}) catch &caption_buf;
var debouncing_node = main_progress_node.start(caption, 0);
+2 -2
View File
@@ -362,7 +362,7 @@ pub const JobQueue = struct {
var dest_sub_path_buf: ["p/".len + Package.Hash.max_len + ".tar.gz".len]u8 = undefined;
const dest_path: Path = .{
.root_dir = jq.global_cache,
.sub_path = std.fmt.bufPrint(&dest_sub_path_buf, "p/{s}.tar.gz", .{pkg_hash_slice}) catch unreachable,
.sub_path = std.mem.print(&dest_sub_path_buf, "p/{s}.tar.gz", .{pkg_hash_slice}) catch unreachable,
};
const gpa = jq.http_client.allocator;
@@ -843,7 +843,7 @@ pub fn computedPackageHash(f: *const Fetch) Package.Hash {
if (f.have_manifest) {
const man = &f.manifest;
var version_buffer: [32]u8 = undefined;
const version: []const u8 = std.fmt.bufPrint(&version_buffer, "{f}", .{man.version}) catch &version_buffer;
const version: []const u8 = std.mem.print(&version_buffer, "{f}", .{man.version}) catch &version_buffer;
return .init(f.computed_hash.digest, man.name, version, man.id, saturated_size);
}
// In the future build.zig.zon fields will be added to allow overriding these values
+1 -1
View File
@@ -1008,7 +1008,7 @@ pub const Session = struct {
}
for (wants) |want| {
var buf: [Packet.max_data_length]u8 = undefined;
const arg = std.fmt.bufPrint(&buf, "want {s}\n", .{want}) catch unreachable;
const arg = std.mem.print(&buf, "want {s}\n", .{want}) catch unreachable;
try Packet.write(.{ .data = arg }, &body);
}
try Packet.write(.{ .data = "done\n" }, &body);
+1 -1
View File
@@ -130,7 +130,7 @@ pub const Hash = struct {
}
var bin_digest: [Algo.digest_length]u8 = undefined;
Algo.hash(sub_path, &bin_digest, .{});
_ = std.fmt.bufPrint(result.bytes[i..], "{x}", .{&bin_digest}) catch unreachable;
_ = std.mem.print(result.bytes[i..], "{x}", .{&bin_digest}) catch unreachable;
return result;
}
+1 -1
View File
@@ -892,7 +892,7 @@ fn lowerZigArgs(
var args_hash: [Sha256.digest_length]u8 = undefined;
Sha256.hash(args, &args_hash, .{});
var args_hex_hash: [Sha256.digest_length * 2]u8 = undefined;
_ = std.fmt.bufPrint(&args_hex_hash, "{x}", .{&args_hash}) catch unreachable;
_ = std.mem.print(&args_hex_hash, "{x}", .{&args_hash}) catch unreachable;
const args_file = "args" ++ Dir.path.sep_str ++ args_hex_hash;
local_cache_root.handle.access(io, args_file, .{}) catch {
+1 -1
View File
@@ -971,7 +971,7 @@ const FuzzTestRunner = struct {
i += 1;
}) {
const name_prefix = "f" ++ Dir.path.sep_str ++ "in";
in_name = std.fmt.bufPrint(&in_name_buf, name_prefix ++ "{x}", .{i}) catch unreachable;
in_name = std.mem.print(&in_name_buf, name_prefix ++ "{x}", .{i}) catch unreachable;
in_f = cache_root.handle.openFile(io, in_name, .{
.lock = .exclusive,
.lock_nonblocking = true,
+1 -1
View File
@@ -145,7 +145,7 @@ const Os = switch (builtin.os.tag) {
fn getDirHandle(gpa: Allocator, path: std.Build.Cache.Path, mount_id: *MountId) !FileHandle {
var file_handle_buffer: [@sizeOf(std.os.linux.file_handle) + 128]u8 align(@alignOf(std.os.linux.file_handle)) = undefined;
var buf: [std.fs.max_path_bytes]u8 = undefined;
const adjusted_path = if (path.sub_path.len == 0) "./" else std.fmt.bufPrint(&buf, "{s}/", .{
const adjusted_path = if (path.sub_path.len == 0) "./" else std.mem.print(&buf, "{s}/", .{
path.sub_path,
}) catch return error.NameTooLong;
const stack_ptr: *std.os.linux.file_handle = @ptrCast(&file_handle_buffer);
+1 -1
View File
@@ -615,7 +615,7 @@ const HexWriter = struct {
const payload_bytes = self.getPayloadBytes();
assert(payload_bytes.len <= max_payload_len);
const line = try std.fmt.bufPrint(&outbuf, ":{0X:0>2}{1X:0>4}{2X:0>2}{3X}{4X:0>2}" ++ linesep, .{
const line = try std.mem.print(&outbuf, ":{0X:0>2}{1X:0>4}{2X:0>2}{3X}{4X:0>2}" ++ linesep, .{
@as(u8, @intCast(payload_bytes.len)),
self.address,
@backingInt(self.payload),
+1 -1
View File
@@ -883,7 +883,7 @@ const ResourceTree = struct {
std.mem.writeInt(u32, name_buf[0..4], 0, .little);
std.mem.writeInt(u32, name_buf[4..8], string_table_offset, .little);
} else {
const name_slice = std.fmt.bufPrint(&name_buf, "$R{X:0>6}", .{relocation.data_offset}) catch unreachable;
const name_slice = std.mem.print(&name_buf, "$R{X:0>6}", .{relocation.data_offset}) catch unreachable;
std.debug.assert(name_slice.len == 8);
}
+1 -1
View File
@@ -583,7 +583,7 @@ fn escapeUnprintables(mt: *MacroTranslator) ![]const u8 {
const formatter = std.ascii.hexEscape(zigified, .lower);
const encoded_size = @as(usize, @intCast(std.fmt.count("{f}", .{formatter})));
const output = try mt.t.arena.alloc(u8, encoded_size);
return std.fmt.bufPrint(output, "{f}", .{formatter}) catch |err| switch (err) {
return std.mem.print(output, "{f}", .{formatter}) catch |err| switch (err) {
error.NoSpaceLeft => unreachable,
else => |e| return e,
};
+1 -1
View File
@@ -48,7 +48,7 @@ fn logFn(
) void {
const prefix = if (scope == .default) "" else @tagName(scope) ++ ": ";
var buf: [500]u8 = undefined;
const line = std.fmt.bufPrint(&buf, prefix ++ format, args) catch l: {
const line = std.mem.print(&buf, prefix ++ format, args) catch l: {
buf[buf.len - 3 ..][0..3].* = "...".*;
break :l &buf;
};
+3 -3
View File
@@ -242,7 +242,7 @@ const Executable = struct {
/// Asserts `buf[0..2]` is "in"
fn inputFileName(buf: *[10]u8, i: u32) []u8 {
assert(buf[0..2].* == "in".*);
const hex = std.fmt.bufPrint(buf[2..], "{x}", .{i}) catch unreachable;
const hex = std.mem.print(buf[2..], "{x}", .{i}) catch unreachable;
return buf[0 .. 2 + hex.len];
}
@@ -763,7 +763,7 @@ const Fuzzer = struct {
const input_f = while (true) {
var name_buf: [10]u8 = undefined;
name_buf[0..2].* = "in".*;
const hex = std.fmt.bufPrint(name_buf[2..], "{x}", .{input_i}) catch unreachable;
const hex = std.mem.print(name_buf[2..], "{x}", .{input_i}) catch unreachable;
const name = name_buf[0 .. 2 + hex.len];
if (exec.cache_f.createFile(io, name, .{
@@ -998,7 +998,7 @@ const Fuzzer = struct {
}
pub fn inputName(n: *CorpusFileName, i: u32) []u8 {
const hex = std.fmt.bufPrint(n.buf[Test.dirname_len + 1 ..][0..8], "{x}", .{i}) catch unreachable;
const hex = std.mem.print(n.buf[Test.dirname_len + 1 ..][0..8], "{x}", .{i}) catch unreachable;
return n.buf[0 .. Test.dirname_len + 1 + hex.len];
}
};
+9 -9
View File
@@ -61,7 +61,7 @@ pub fn joinStringZ(p: Path, gpa: Allocator, sub_path: []const u8) Allocator.Erro
pub fn openFile(p: Path, io: Io, sub_path: []const u8, flags: Io.Dir.OpenFileOptions) !Io.File {
var buf: [Io.Dir.max_path_bytes]u8 = undefined;
const joined_path = if (p.sub_path.len == 0) sub_path else p: {
break :p std.fmt.bufPrint(&buf, "{s}" ++ Io.Dir.path.sep_str ++ "{s}", .{
break :p std.mem.print(&buf, "{s}" ++ Io.Dir.path.sep_str ++ "{s}", .{
p.sub_path, sub_path,
}) catch return error.NameTooLong;
};
@@ -76,7 +76,7 @@ pub fn openDir(
) Io.Dir.OpenError!Io.Dir {
var buf: [Io.Dir.max_path_bytes]u8 = undefined;
const joined_path = if (p.sub_path.len == 0) sub_path else p: {
break :p std.fmt.bufPrint(&buf, "{s}" ++ Io.Dir.path.sep_str ++ "{s}", .{
break :p std.mem.print(&buf, "{s}" ++ Io.Dir.path.sep_str ++ "{s}", .{
p.sub_path, sub_path,
}) catch return error.NameTooLong;
};
@@ -86,7 +86,7 @@ pub fn openDir(
pub fn createDirPathOpen(p: Path, io: Io, sub_path: []const u8, opts: Io.Dir.CreateDirPathOpenOptions) !Io.Dir {
var buf: [Io.Dir.max_path_bytes]u8 = undefined;
const joined_path = if (p.sub_path.len == 0) sub_path else p: {
break :p std.fmt.bufPrint(&buf, "{s}" ++ Io.Dir.path.sep_str ++ "{s}", .{
break :p std.mem.print(&buf, "{s}" ++ Io.Dir.path.sep_str ++ "{s}", .{
p.sub_path, sub_path,
}) catch return error.NameTooLong;
};
@@ -96,7 +96,7 @@ pub fn createDirPathOpen(p: Path, io: Io, sub_path: []const u8, opts: Io.Dir.Cre
pub fn statFile(p: Path, io: Io, sub_path: []const u8) !Io.Dir.Stat {
var buf: [Io.Dir.max_path_bytes]u8 = undefined;
const joined_path = if (p.sub_path.len == 0) sub_path else p: {
break :p std.fmt.bufPrint(&buf, "{s}" ++ Io.Dir.path.sep_str ++ "{s}", .{
break :p std.mem.print(&buf, "{s}" ++ Io.Dir.path.sep_str ++ "{s}", .{
p.sub_path, sub_path,
}) catch return error.NameTooLong;
};
@@ -111,7 +111,7 @@ pub fn atomicFile(
buf: *[Io.Dir.max_path_bytes]u8,
) !Io.File.Atomic {
const joined_path = if (p.sub_path.len == 0) sub_path else p: {
break :p std.fmt.bufPrint(buf, "{s}" ++ Io.Dir.path.sep_str ++ "{s}", .{
break :p std.mem.print(buf, "{s}" ++ Io.Dir.path.sep_str ++ "{s}", .{
p.sub_path, sub_path,
}) catch return error.NameTooLong;
};
@@ -121,7 +121,7 @@ pub fn atomicFile(
pub fn access(p: Path, io: Io, sub_path: []const u8, flags: Io.Dir.AccessOptions) !void {
var buf: [Io.Dir.max_path_bytes]u8 = undefined;
const joined_path = if (p.sub_path.len == 0) sub_path else p: {
break :p std.fmt.bufPrint(&buf, "{s}" ++ Io.Dir.path.sep_str ++ "{s}", .{
break :p std.mem.print(&buf, "{s}" ++ Io.Dir.path.sep_str ++ "{s}", .{
p.sub_path, sub_path,
}) catch return error.NameTooLong;
};
@@ -131,7 +131,7 @@ pub fn access(p: Path, io: Io, sub_path: []const u8, flags: Io.Dir.AccessOptions
pub fn createDirPath(p: Path, io: Io, sub_path: []const u8) !void {
var buf: [Io.Dir.max_path_bytes]u8 = undefined;
const joined_path = if (p.sub_path.len == 0) sub_path else p: {
break :p std.fmt.bufPrint(&buf, "{s}" ++ Io.Dir.path.sep_str ++ "{s}", .{
break :p std.mem.print(&buf, "{s}" ++ Io.Dir.path.sep_str ++ "{s}", .{
p.sub_path, sub_path,
}) catch return error.NameTooLong;
};
@@ -139,11 +139,11 @@ pub fn createDirPath(p: Path, io: Io, sub_path: []const u8) !void {
}
pub fn toString(p: Path, allocator: Allocator) Allocator.Error![]u8 {
return std.fmt.allocPrint(allocator, "{f}", .{p});
return allocator.print("{f}", .{p});
}
pub fn toStringZ(p: Path, allocator: Allocator) Allocator.Error![:0]u8 {
return std.fmt.allocPrintSentinel(allocator, "{f}", .{p}, 0);
return allocator.printSentinel("{f}", .{p}, 0);
}
pub fn fmtEscapeString(path: Path) std.fmt.Alt(Path, formatEscapeString) {
+5 -5
View File
@@ -7067,7 +7067,7 @@ fn realPathPosix(fd: posix.fd_t, out_buffer: []u8) File.RealPathError!usize {
.linux, .serenity, .illumos => {
var procfs_buf: ["/proc/self/path/-2147483648\x00".len]u8 = undefined;
const template = if (native_os == .illumos) "/proc/self/path/{d}" else "/proc/self/fd/{d}";
const proc_path = std.fmt.bufPrintSentinel(&procfs_buf, template, .{fd}, 0) catch unreachable;
const proc_path = std.mem.printSentinel(&procfs_buf, template, .{fd}, 0) catch unreachable;
const syscall: Syscall = try .start();
while (true) {
const rc = posix.system.readlink(proc_path, out_buffer.ptr, out_buffer.len);
@@ -7155,7 +7155,7 @@ fn fileHardLink(
error.FileNotFound => {
if (options.follow_symlinks) return error.FileNotFound;
var proc_buf: ["/proc/self/fd/-2147483648\x00".len]u8 = undefined;
const proc_path = std.fmt.bufPrintSentinel(&proc_buf, "/proc/self/fd/{d}", .{file.handle}, 0) catch
const proc_path = std.mem.printSentinel(&proc_buf, "/proc/self/fd/{d}", .{file.handle}, 0) catch
unreachable;
return linkat(posix.AT.FDCWD, proc_path, new_dir.handle, new_sub_path_posix, posix.AT.SYMLINK_FOLLOW);
},
@@ -8633,7 +8633,7 @@ fn fchmodatFallback(
return error.OperationUnsupported;
var procfs_buf: ["/proc/self/fd/-2147483648\x00".len]u8 = undefined;
const proc_path = std.fmt.bufPrintSentinel(&procfs_buf, "/proc/self/fd/{d}", .{path_fd}, 0) catch unreachable;
const proc_path = std.mem.printSentinel(&procfs_buf, "/proc/self/fd/{d}", .{path_fd}, 0) catch unreachable;
const syscall: Syscall = try .start();
while (true) {
switch (posix.errno(posix.system.chmod(proc_path, mode))) {
@@ -10633,7 +10633,7 @@ fn processExecutablePath(userdata: ?*anyopaque, out_buffer: []u8) process.Execut
var it = std.mem.tokenizeScalar(u8, PATH, ':');
it: while (it.next()) |dir| {
var resolved_path_buf: [std.c.PATH_MAX]u8 = undefined;
const resolved_path = std.fmt.bufPrintSentinel(&resolved_path_buf, "{s}/{s}", .{
const resolved_path = std.mem.printSentinel(&resolved_path_buf, "{s}/{s}", .{
dir, argv0,
}, 0) catch continue;
@@ -14002,7 +14002,7 @@ fn netLookupFallible(
const name_c = name_buffer[0..name.len :0];
var port_buffer: [8]u8 = undefined;
const port_c = std.fmt.bufPrintSentinel(&port_buffer, "{d}", .{options.port}, 0) catch unreachable;
const port_c = std.mem.printSentinel(&port_buffer, "{d}", .{options.port}, 0) catch unreachable;
const family: i32 = if (options.family) |f| switch (f) {
.ip4 => posix.AF.INET,
+1 -1
View File
@@ -5793,7 +5793,7 @@ fn realPath(
) File.RealPathError!usize {
_ = ev;
var procfs_buf: [std.fmt.count("/proc/self/fd/{d}\x00", .{std.math.minInt(fd_t)})]u8 = undefined;
const proc_path = std.fmt.bufPrintSentinel(&procfs_buf, "/proc/self/fd/{d}", .{fd}, 0) catch
const proc_path = std.mem.printSentinel(&procfs_buf, "/proc/self/fd/{d}", .{fd}, 0) catch
unreachable;
while (true) {
try sync.cancel_region.await(.nothing);
+1 -1
View File
@@ -1504,7 +1504,7 @@ fn testIp6ParseTransform(expected: []const u8, input: []const u8) !void {
},
};
var buffer: [100]u8 = undefined;
const result = try std.fmt.bufPrint(&buffer, "{f}", .{ua});
const result = try std.mem.print(&buffer, "{f}", .{ua});
try std.testing.expectEqualStrings(expected, result);
}
+2 -2
View File
@@ -65,7 +65,7 @@ test "parse and render IPv6 addresses" {
fn testParseAndRenderIp6Address(input: []const u8, expected_output: []const u8) !void {
var buffer: [100]u8 = undefined;
const parsed = net.Ip6Address.Unresolved.parse(input);
const actual_printed = try std.fmt.bufPrint(&buffer, "{f}", .{parsed.success});
const actual_printed = try std.mem.print(&buffer, "{f}", .{parsed.success});
try testing.expectEqualStrings(expected_output, actual_printed);
}
@@ -115,7 +115,7 @@ test "parse and render IPv4 addresses" {
fn testIp4ParseAndRender(text: []const u8) !void {
var buffer: [18]u8 = undefined;
const addr = try net.IpAddress.parseIp4(text, 0);
const rendered = try std.fmt.bufPrint(&buffer, "{f}", .{addr});
const rendered = try std.mem.print(&buffer, "{f}", .{addr});
const without_port = rendered[0 .. rendered.len - 2];
try testing.expectEqualStrings(text, without_port);
}
+6 -6
View File
@@ -308,7 +308,7 @@ pub const Node = struct {
pub fn startFmt(node: Node, estimated_total_items: usize, comptime format: []const u8, args: anytype) Node {
var buffer: [max_name_len]u8 = undefined;
const name = std.fmt.bufPrint(&buffer, format, args) catch &buffer;
const name = std.mem.print(&buffer, format, args) catch &buffer;
return Node.start(node, name, estimated_total_items);
}
@@ -1355,7 +1355,7 @@ fn computeRedraw(io: Io, serialized_buffer: *Serialized.Buffer) !struct { []u8,
i += progress_pulsing.len;
} else {
const percent = @as(u64, completed_items) * 100 / estimated_total;
if (std.fmt.bufPrint(buf[i..], @"progress_normal {d}", .{percent})) |b| {
if (std.mem.print(buf[i..], @"progress_normal {d}", .{percent})) |b| {
i += b.len;
} else |_| {}
}
@@ -1374,7 +1374,7 @@ fn computeRedraw(io: Io, serialized_buffer: *Serialized.Buffer) !struct { []u8,
i += progress_pulsing_error.len;
} else {
const percent = @as(u64, completed_items) * 100 / estimated_total;
if (std.fmt.bufPrint(buf[i..], @"progress_error {d}", .{percent})) |b| {
if (std.mem.print(buf[i..], @"progress_error {d}", .{percent})) |b| {
i += b.len;
} else |_| {}
}
@@ -1475,16 +1475,16 @@ fn computeNode(
if (!is_empty_root) {
if (name.len != 0 or estimated_total > 0) {
if (estimated_total > 0) {
if (std.fmt.bufPrint(buf[i..], "[{d}/{d}] ", .{ completed_items, estimated_total })) |b| {
if (std.mem.print(buf[i..], "[{d}/{d}] ", .{ completed_items, estimated_total })) |b| {
i += b.len;
} else |_| {}
} else if (completed_items != 0) {
if (std.fmt.bufPrint(buf[i..], "[{d}] ", .{completed_items})) |b| {
if (std.mem.print(buf[i..], "[{d}] ", .{completed_items})) |b| {
i += b.len;
} else |_| {}
}
if (name.len != 0) {
if (std.fmt.bufPrint(buf[i..], "{s}", .{name})) |b| {
if (std.mem.print(buf[i..], "{s}", .{name})) |b| {
i += b.len;
} else |_| {}
}
+1 -1
View File
@@ -2437,7 +2437,7 @@ pub const DynamicLinker = struct {
/// Asserts that the length is less than or equal to 255 bytes.
pub fn setFmt(dl: *DynamicLinker, comptime fmt_str: []const u8, args: anytype) !void {
dl.len = @intCast((try std.fmt.bufPrint(&dl.buffer, fmt_str, args)).len);
dl.len = @intCast((try std.mem.print(&dl.buffer, fmt_str, args)).len);
}
pub fn eql(lhs: DynamicLinker, rhs: DynamicLinker) bool {
+4 -4
View File
@@ -47,7 +47,7 @@ pub const SetNameError = error{
Unsupported,
Unexpected,
InvalidWtf8,
} || posix.PrctlError || Io.File.Writer.Error || Io.File.OpenError || std.fmt.BufPrintError;
} || posix.PrctlError || Io.File.Writer.Error || Io.File.OpenError || std.mem.PrintError;
pub fn setName(self: Thread, io: Io, name: []const u8) SetNameError!void {
if (name.len > max_name_len) return error.NameTooLong;
@@ -75,7 +75,7 @@ pub fn setName(self: Thread, io: Io, name: []const u8) SetNameError!void {
}
} else {
var buf: [32]u8 = undefined;
const path = try std.fmt.bufPrint(&buf, "/proc/self/task/{d}/comm", .{self.getHandle()});
const path = try std.mem.print(&buf, "/proc/self/task/{d}/comm", .{self.getHandle()});
const file = try Io.Dir.cwd().openFile(io, path, .{ .mode = .write_only });
defer file.close(io);
@@ -152,7 +152,7 @@ pub fn setName(self: Thread, io: Io, name: []const u8) SetNameError!void {
pub const GetNameError = error{
Unsupported,
Unexpected,
} || posix.PrctlError || posix.ReadError || Io.File.OpenError || std.fmt.BufPrintError;
} || posix.PrctlError || posix.ReadError || Io.File.OpenError || std.mem.PrintError;
/// On Windows, the result is encoded as [WTF-8](https://wtf-8.codeberg.page/).
/// On other platforms, the result is an opaque sequence of bytes with no particular encoding.
@@ -176,7 +176,7 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co
}
} else {
var buf: [32]u8 = undefined;
const path = try std.fmt.bufPrint(&buf, "/proc/self/task/{d}/comm", .{self.getHandle()});
const path = try std.mem.print(&buf, "/proc/self/task/{d}/comm", .{self.getHandle()});
const io = std.Options.debug_io;
+2 -2
View File
@@ -41,7 +41,7 @@ pub const Component = union(enum) {
return switch (component) {
.raw => |raw| raw,
.percent_encoded => |percent_encoded| if (std.mem.findScalar(u8, percent_encoded, '%')) |_|
try std.fmt.bufPrint(buffer, "{f}", .{std.fmt.alt(component, .formatRaw)})
try std.mem.print(buffer, "{f}", .{std.fmt.alt(component, .formatRaw)})
else
percent_encoded,
};
@@ -52,7 +52,7 @@ pub const Component = union(enum) {
return switch (component) {
.raw => |raw| raw,
.percent_encoded => |percent_encoded| if (std.mem.findScalar(u8, percent_encoded, '%')) |_|
try std.fmt.allocPrint(arena, "{f}", .{std.fmt.alt(component, .formatRaw)})
try arena.print("{f}", .{std.fmt.alt(component, .formatRaw)})
else
percent_encoded,
};
+2 -2
View File
@@ -129,9 +129,9 @@ test "curve25519" {
const p = try Curve25519.basePoint.clampedMul(s);
try p.rejectIdentity();
var buf: [128]u8 = undefined;
try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{&p.toBytes()}), "E6F2A4D1C28EE5C7AD0329268255A468AD407D2672824C0C0EB30EA6EF450145");
try std.testing.expectEqualStrings(try std.mem.print(&buf, "{X}", .{&p.toBytes()}), "E6F2A4D1C28EE5C7AD0329268255A468AD407D2672824C0C0EB30EA6EF450145");
const q = try p.clampedMul(s);
try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{&q.toBytes()}), "3614E119FFE55EC55B87D6B19971A9F4CBC78EFE80BEC55B96392BABCC712537");
try std.testing.expectEqualStrings(try std.mem.print(&buf, "{X}", .{&q.toBytes()}), "3614E119FFE55EC55B87D6B19971A9F4CBC78EFE80BEC55B96392BABCC712537");
try Curve25519.rejectNonCanonical(s);
s[31] |= 0x80;
+3 -3
View File
@@ -585,8 +585,8 @@ test "key pair creation" {
_ = try fmt.hexToBytes(seed[0..], "8052030376d47112be7f73ed7a019293dd12ad910b654455798b4667d73de166");
const key_pair = try Ed25519.KeyPair.generateDeterministic(seed);
var buf: [256]u8 = undefined;
try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{&key_pair.secret_key.toBytes()}), "8052030376D47112BE7F73ED7A019293DD12AD910B654455798B4667D73DE1662D6F7455D97B4A3A10D7293909D1A4F2058CB9A370E43FA8154BB280DB839083");
try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{&key_pair.public_key.toBytes()}), "2D6F7455D97B4A3A10D7293909D1A4F2058CB9A370E43FA8154BB280DB839083");
try std.testing.expectEqualStrings(try std.mem.print(&buf, "{X}", .{&key_pair.secret_key.toBytes()}), "8052030376D47112BE7F73ED7A019293DD12AD910B654455798B4667D73DE1662D6F7455D97B4A3A10D7293909D1A4F2058CB9A370E43FA8154BB280DB839083");
try std.testing.expectEqualStrings(try std.mem.print(&buf, "{X}", .{&key_pair.public_key.toBytes()}), "2D6F7455D97B4A3A10D7293909D1A4F2058CB9A370E43FA8154BB280DB839083");
}
test "signature" {
@@ -596,7 +596,7 @@ test "signature" {
const sig = try key_pair.sign("test", null);
var buf: [128]u8 = undefined;
try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{&sig.toBytes()}), "10A442B4A80CC4225B154F43BEF28D2472CA80221951262EB8E0DF9091575E2687CC486E77263C3418C757522D54F84B0359236ABBBD4ACD20DC297FDCA66808");
try std.testing.expectEqualStrings(try std.mem.print(&buf, "{X}", .{&sig.toBytes()}), "10A442B4A80CC4225B154F43BEF28D2472CA80221951262EB8E0DF9091575E2687CC486E77263C3418C757522D54F84B0359236ABBBD4ACD20DC297FDCA66808");
try sig.verify("test", key_pair.public_key);
try std.testing.expectError(error.SignatureVerificationFailed, sig.verify("TEST", key_pair.public_key));
}
+1 -1
View File
@@ -543,7 +543,7 @@ test "packing/unpacking" {
var b = Edwards25519.basePoint;
const pk = try b.mul(s);
var buf: [128]u8 = undefined;
try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{&pk.toBytes()}), "074BC7E0FCBD587FDBC0969444245FADC562809C8F6E97E949AF62484B5B81A6");
try std.testing.expectEqualStrings(try std.mem.print(&buf, "{X}", .{&pk.toBytes()}), "074BC7E0FCBD587FDBC0969444245FADC562809C8F6E97E949AF62484B5B81A6");
const small_order_ss: [7][32]u8 = .{
.{
+4 -4
View File
@@ -175,21 +175,21 @@ pub const Ristretto255 = struct {
test "ristretto255" {
const p = Ristretto255.basePoint;
var buf: [256]u8 = undefined;
try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{&p.toBytes()}), "E2F2AE0A6ABC4E71A884A961C500515F58E30B6AA582DD8DB6A65945E08D2D76");
try std.testing.expectEqualStrings(try std.mem.print(&buf, "{X}", .{&p.toBytes()}), "E2F2AE0A6ABC4E71A884A961C500515F58E30B6AA582DD8DB6A65945E08D2D76");
var r: [Ristretto255.encoded_length]u8 = undefined;
_ = try fmt.hexToBytes(r[0..], "6a493210f7499cd17fecb510ae0cea23a110e8d5b901f8acadd3095c73a3b919");
var q = try Ristretto255.fromBytes(r);
q = q.dbl().add(p);
try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{&q.toBytes()}), "E882B131016B52C1D3337080187CF768423EFCCBB517BB495AB812C4160FF44E");
try std.testing.expectEqualStrings(try std.mem.print(&buf, "{X}", .{&q.toBytes()}), "E882B131016B52C1D3337080187CF768423EFCCBB517BB495AB812C4160FF44E");
const s = [_]u8{15} ++ @as([31]u8, @splat(0));
const w = try p.mul(s);
try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{&w.toBytes()}), "E0C418F7C8D9C4CDD7395B93EA124F3AD99021BB681DFC3302A9D99A2E53E64E");
try std.testing.expectEqualStrings(try std.mem.print(&buf, "{X}", .{&w.toBytes()}), "E0C418F7C8D9C4CDD7395B93EA124F3AD99021BB681DFC3302A9D99A2E53E64E");
try std.testing.expect(p.dbl().dbl().dbl().dbl().equivalent(w.add(p)));
const h = @as([32]u8, @splat(69)) ++ @as([32]u8, @splat(42));
const ph = Ristretto255.fromUniform(h);
try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{&ph.toBytes()}), "DCCA54E037A4311EFBEEF413ACD21D35276518970B7A61DC88F8587B493D5E19");
try std.testing.expectEqualStrings(try std.mem.print(&buf, "{X}", .{&ph.toBytes()}), "DCCA54E037A4311EFBEEF413ACD21D35276518970B7A61DC88F8587B493D5E19");
}
+3 -3
View File
@@ -850,10 +850,10 @@ test "scalar25519" {
var y = x.toBytes();
try rejectNonCanonical(y);
var buf: [128]u8 = undefined;
try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{&y}), "1E979B917937F3DE71D18077F961F6CEFF01030405060708010203040506070F");
try std.testing.expectEqualStrings(try std.mem.print(&buf, "{X}", .{&y}), "1E979B917937F3DE71D18077F961F6CEFF01030405060708010203040506070F");
const reduced = reduce(field_order_s);
try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{&reduced}), "0000000000000000000000000000000000000000000000000000000000000000");
try std.testing.expectEqualStrings(try std.mem.print(&buf, "{X}", .{&reduced}), "0000000000000000000000000000000000000000000000000000000000000000");
}
test "non-canonical scalar25519" {
@@ -867,7 +867,7 @@ test "mulAdd overflow check" {
const c: [32]u8 = @splat(0xff);
const x = mulAdd(a, b, c);
var buf: [128]u8 = undefined;
try std.testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{&x}), "D14DF91389432C25AD60FF9791B9FD1D67BEF517D273ECCE3D9A307C1B419903");
try std.testing.expectEqualStrings(try std.mem.print(&buf, "{X}", .{&x}), "D14DF91389432C25AD60FF9791B9FD1D67BEF517D273ECCE3D9A307C1B419903");
}
test "scalar field inversion" {
+1 -1
View File
@@ -635,7 +635,7 @@ const crypt_format = struct {
_ = Codec.Encoder.encode(&ct_str, dk[0..]);
var s_buf: [hash_length]u8 = undefined;
const s = fmt.bufPrint(
const s = mem.print(
s_buf[0..],
"{s}b${d}{d}${s}{s}",
.{ prefix, params.rounds_log / 10, params.rounds_log % 10, salt_str, ct_str },
+2 -2
View File
@@ -1145,7 +1145,7 @@ test "xchacha20" {
var c: [m.len]u8 = undefined;
XChaCha20IETF.xor(c[0..], m[0..], 0, key, nonce);
var buf: [2 * c.len]u8 = undefined;
try testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{&c}), "E0A1BCF939654AFDBDC1746EC49832647C19D891F0D1A81FC0C1703B4514BDEA584B512F6908C2C5E9DD18D5CBC1805DE5803FE3B9CA5F193FB8359E91FAB0C3BB40309A292EB1CF49685C65C4A3ADF4F11DB0CD2B6B67FBC174BC2E860E8F769FD3565BBFAD1C845E05A0FED9BE167C240D");
try testing.expectEqualStrings(try std.mem.print(&buf, "{X}", .{&c}), "E0A1BCF939654AFDBDC1746EC49832647C19D891F0D1A81FC0C1703B4514BDEA584B512F6908C2C5E9DD18D5CBC1805DE5803FE3B9CA5F193FB8359E91FAB0C3BB40309A292EB1CF49685C65C4A3ADF4F11DB0CD2B6B67FBC174BC2E860E8F769FD3565BBFAD1C845E05A0FED9BE167C240D");
}
{
const ad = "Additional data";
@@ -1154,7 +1154,7 @@ test "xchacha20" {
var out: [m.len]u8 = undefined;
try XChaCha20Poly1305.decrypt(out[0..], c[0..m.len], c[m.len..].*, ad, nonce, key);
var buf: [2 * c.len]u8 = undefined;
try testing.expectEqualStrings(try std.fmt.bufPrint(&buf, "{X}", .{&c}), "994D2DD32333F48E53650C02C7A2ABB8E018B0836D7175AEC779F52E961780768F815C58F1AA52D211498DB89B9216763F569C9433A6BBFCEFB4D4A49387A4C5207FBB3B5A92B5941294DF30588C6740D39DC16FA1F0E634F7246CF7CDCB978E44347D89381B7A74EB7084F754B90BDE9AAF5A94B8F2A85EFD0B50692AE2D425E234");
try testing.expectEqualStrings(try std.mem.print(&buf, "{X}", .{&c}), "994D2DD32333F48E53650C02C7A2ABB8E018B0836D7175AEC779F52E961780768F815C58F1AA52D211498DB89B9216763F569C9433A6BBFCEFB4D4A49387A4C5207FBB3B5A92B5941294DF30588C6740D39DC16FA1F0E634F7246CF7CDCB978E44347D89381B7A74EB7084F754B90BDE9AAF5A94B8F2A85EFD0B50692AE2D425E234");
try testing.expectEqualSlices(u8, out[0..], m);
c[0] +%= 1;
try testing.expectError(error.AuthenticationFailed, XChaCha20Poly1305.decrypt(out[0..], c[0..m.len], c[m.len..].*, ad, nonce, key));
+1 -1
View File
@@ -1701,7 +1701,7 @@ fn testNistKat(mode: type, hash: []const u8) !void {
var out: [32]u8 = undefined;
fw.hasher.final(&out);
var outHex: [64]u8 = undefined;
_ = try std.fmt.bufPrint(&outHex, "{x}", .{&out});
_ = try std.mem.print(&outHex, "{x}", .{&out});
try testing.expectEqualStrings(&outHex, hash);
}
+2 -2
View File
@@ -529,7 +529,7 @@ test "Dir.Iterator many entries" {
var i: usize = 0;
var buf: [4]u8 = undefined; // Enough to store "1024".
while (i < num) : (i += 1) {
const name = try std.fmt.bufPrint(&buf, "{}", .{i});
const name = try std.mem.print(&buf, "{}", .{i});
const file = try tmp_dir.dir.createFile(io, name, .{});
file.close(io);
}
@@ -551,7 +551,7 @@ test "Dir.Iterator many entries" {
i = 0;
while (i < num) : (i += 1) {
const name = try std.fmt.bufPrint(&buf, "{}", .{i});
const name = try std.mem.print(&buf, "{}", .{i});
try expect(contains(&entries, .{ .name = name, .kind = .file, .inode = 0 }));
}
}
+5 -5
View File
@@ -344,7 +344,7 @@ test "Server.Request.respondStreaming non-chunked, unknown content-length" {
var total: usize = 0;
for (0..500) |i| {
var buf: [30]u8 = undefined;
const line = try std.fmt.bufPrint(&buf, "{d}, ah ha ha!\n", .{i});
const line = try std.mem.print(&buf, "{d}, ah ha ha!\n", .{i});
try expected_response.appendSlice(line);
total += line.len;
}
@@ -1017,7 +1017,7 @@ fn echoTests(client: *http.Client, port: u16) !void {
try expect(client.http_proxy != null or client.connection_pool.free_len == 1);
{ // send chunked request
const uri = try std.Uri.parse(try std.fmt.bufPrint(
const uri = try std.Uri.parse(try std.mem.print(
&location_buffer,
"http://127.0.0.1:{d}/echo-content",
.{port},
@@ -1213,7 +1213,7 @@ test "redirect to different connection" {
defer stream.close(io);
var loc_buf: [50]u8 = undefined;
const new_loc = try std.fmt.bufPrint(&loc_buf, "http://127.0.0.1:{d}/ok", .{
const new_loc = try std.mem.print(&loc_buf, "http://127.0.0.1:{d}/ok", .{
global.other_port.?,
});
@@ -1241,7 +1241,7 @@ test "redirect to different connection" {
defer client.deinit();
var loc_buf: [100]u8 = undefined;
const location = try std.fmt.bufPrint(&loc_buf, "http://127.0.0.1:{d}/help", .{
const location = try std.mem.print(&loc_buf, "http://127.0.0.1:{d}/help", .{
test_server_orig.port(),
});
const uri = try std.Uri.parse(location);
@@ -1300,7 +1300,7 @@ test "boot failed connections from the pool" {
defer client.deinit();
var loc_buf: [100]u8 = undefined;
const location = try std.fmt.bufPrint(&loc_buf, "http://127.0.0.1:{d}/", .{
const location = try std.mem.print(&loc_buf, "http://127.0.0.1:{d}/", .{
test_server_orig.port(),
});
const uri = try std.Uri.parse(location);
+1 -1
View File
@@ -5006,7 +5006,7 @@ pub const TEB = extern struct {
};
comptime {
// XXX: Without this check we cannot use `std.Io.Writer` on 16-bit platforms. `std.fmt.bufPrint` will hit the unreachable in `PEB.GdiHandleBuffer` without this guard.
// XXX: Without this check we cannot use `std.Io.Writer` on 16-bit platforms. `std.mem.print` will hit the unreachable in `PEB.GdiHandleBuffer` without this guard.
if (builtin.os.tag == .windows) {
// Offsets taken from WinDbg info and Geoff Chappell[1] (RIP)
// [1]: https://www.geoffchappell.com/studies/windows/km/ntoskrnl/inc/api/pebteb/teb/index.htm
+2 -2
View File
@@ -466,7 +466,7 @@ pub const Map = struct {
);
i += "ZIG_PROGRESS=".len;
var value_buf: [std.fmt.count("{d}", .{std.math.maxInt(usize)})]u8 = undefined;
const value = std.fmt.bufPrint(&value_buf, "{d}", .{@intFromPtr(handle)}) catch unreachable;
const value = std.mem.print(&value_buf, "{d}", .{@intFromPtr(handle)}) catch unreachable;
for (block[i..][0..value.len], value) |*r, v| r.* = v;
i += value.len;
block[i] = 0;
@@ -840,7 +840,7 @@ pub fn createWindowsBlock(
@memcpy(block[i..][0..zig_progress_key.len], &zig_progress_key);
i += zig_progress_key.len;
var value_buf: [std.fmt.count("{d}", .{std.math.maxInt(usize)})]u8 = undefined;
const value = std.fmt.bufPrint(&value_buf, "{d}", .{@intFromPtr(handle)}) catch unreachable;
const value = std.mem.print(&value_buf, "{d}", .{@intFromPtr(handle)}) catch unreachable;
for (block[i..][0..value.len], value) |*r, v| r.* = v;
i += value.len;
block[i] = 0;
+1 -1
View File
@@ -656,7 +656,7 @@ test expectError {
pub fn expectFmt(expected: []const u8, comptime template: []const u8, args: anytype) !void {
if (@inComptime()) {
var buffer: [std.fmt.count(template, args)]u8 = undefined;
return expectEqualStrings(expected, try std.fmt.bufPrint(&buffer, template, args));
return expectEqualStrings(expected, try std.mem.print(&buffer, template, args));
}
const actual = try std.fmt.allocPrint(allocator, template, args);
defer allocator.free(actual);
+2 -2
View File
@@ -513,7 +513,7 @@ pub const Installation = struct {
const version = version: {
var buf: [Dir.max_path_bytes]u8 = undefined;
const sdk_lib_dir_path = std.fmt.bufPrint(buf[0..], "{s}\\Lib\\", .{path}) catch |err| switch (err) {
const sdk_lib_dir_path = std.mem.print(buf[0..], "{s}\\Lib\\", .{path}) catch |err| switch (err) {
error.NoSpaceLeft => return error.PathTooLong,
};
if (!Dir.path.isAbsolute(sdk_lib_dir_path)) return error.InstallationNotFound;
@@ -985,7 +985,7 @@ const MsvcLibDir = struct {
io.random(std.mem.asBytes(&guid));
var guid_buf: [38]u8 = undefined;
const guid_str = std.fmt.bufPrint(&guid_buf, "{f}", .{guid}) catch unreachable;
const guid_str = std.mem.print(&guid_buf, "{f}", .{guid}) catch unreachable;
var buf: std.ArrayList(u16) = .initBuffer(&key_path_buf);
buf.appendSliceAssumeCapacity(L("\\REGISTRY\\A\\"));
+1 -1
View File
@@ -74,7 +74,7 @@ fn getCpuInfoFromRegistry(core: usize, args: anytype) !void {
const max_cpu_buf = 4;
var next_cpu_buf: [max_cpu_buf]u8 = undefined;
const next_cpu = try std.fmt.bufPrint(&next_cpu_buf, "{d}", .{core});
const next_cpu = try std.mem.print(&next_cpu_buf, "{d}", .{core});
var subkey: [max_cpu_buf + 1]u16 = undefined;
const subkey_len = try std.unicode.utf8ToUtf16Le(&subkey, next_cpu);
+1 -1
View File
@@ -3821,7 +3821,7 @@ pub fn saveState(comp: *Compilation) !void {
}
var basename_buf: [255]u8 = undefined;
const basename = std.fmt.bufPrint(&basename_buf, "{s}.zcs", .{
const basename = std.mem.print(&basename_buf, "{s}.zcs", .{
comp.root_name,
}) catch o: {
basename_buf[basename_buf.len - 4 ..].* = ".zcs".*;
+2 -2
View File
@@ -405,10 +405,10 @@ fn parseAnalUnit(str: []const u8) ?AnalUnit {
}
fn printAnalUnit(unit: AnalUnit, buf: *[32]u8) []const u8 {
const idx: u32 = switch (unit.unwrap()) {
.memoized_state => |stage| return std.fmt.bufPrint(buf, "memoized_state {s}", .{@tagName(stage)}) catch unreachable,
.memoized_state => |stage| return std.mem.print(buf, "memoized_state {s}", .{@tagName(stage)}) catch unreachable,
inline else => |i| @backingInt(i),
};
return std.fmt.bufPrint(buf, "{s} {d}", .{ @tagName(unit.unwrap()), idx }) catch unreachable;
return std.mem.print(buf, "{s} {d}", .{ @tagName(unit.unwrap()), idx }) catch unreachable;
}
fn printType(ty: Type, zcu: *const Zcu, w: *Io.Writer) Io.Writer.Error!void {
+1 -1
View File
@@ -11384,7 +11384,7 @@ pub fn getOrPutStringFmt(
const len: u32 = @intCast(std.fmt.count(format_z, args));
const string_bytes = ip.getLocal(tid).getMutableStringBytes(gpa, io);
const slice = try string_bytes.addManyAsSlice(len);
assert((std.fmt.bufPrint(slice[0], format_z, args) catch unreachable).len == len);
assert((std.mem.print(slice[0], format_z, args) catch unreachable).len == len);
return ip.getOrPutTrailingString(gpa, io, tid, len, embedded_nulls);
}
+2 -2
View File
@@ -83,7 +83,7 @@ fn zonCast(comptime Result: type, zon_value: anytype, symbols: anytype) Result {
.unsigned => std.math.maxInt(Symbol),
}})
]u8 = undefined;
return std.meta.stringToEnum(Result, std.fmt.bufPrint(&buf, "{d}", .{symbol}) catch unreachable).?;
return std.meta.stringToEnum(Result, std.mem.print(&buf, "{d}", .{symbol}) catch unreachable).?;
},
else => return symbol,
},
@@ -256,7 +256,7 @@ fn nextToken(as: *Assemble, buf: *[token_buf_len]u8, comptime opts: struct {
switch (modified_operand) {
.register => |reg| {
as.source = as.source[index + 1 ..];
return std.fmt.bufPrint(buf, "{f}", .{reg.fmt()}) catch unreachable;
return std.mem.print(buf, "{f}", .{reg.fmt()}) catch unreachable;
},
}
} else continue :c invalid_syntax,
+2 -2
View File
@@ -7467,7 +7467,7 @@ const StringLiteral = struct {
},
else => {
var buf: [4]u8 = undefined;
const printed = std.fmt.bufPrint(&buf, "\\{o:0>3}", .{c}) catch unreachable;
const printed = std.mem.print(&buf, "\\{o:0>3}", .{c}) catch unreachable;
try w.writeAll(printed);
return printed.len;
},
@@ -7489,7 +7489,7 @@ const StringLiteral = struct {
} else {
if (!sl.first) try sl.w.writeByte(',');
var buf: [6]u8 = undefined;
const printed = std.fmt.bufPrint(&buf, "'\\x{x}'", .{c}) catch unreachable;
const printed = std.mem.print(&buf, "'\\x{x}'", .{c}) catch unreachable;
try sl.w.writeAll(printed);
sl.cur_len += printed.len;
sl.first = false;
+1 -1
View File
@@ -178194,7 +178194,7 @@ fn airAsm(self: *CodeGen, inst: Air.Inst.Index) !void {
inline for (@typeInfo(encoder.Instruction.Mnemonic).@"enum".field_names) |mnem_name|
max_mnem_len = @max(mnem_name.len, max_mnem_len);
var intel_mnem_buf: [max_mnem_len + 1]u8 = undefined;
const intel_mnem_str = std.fmt.bufPrint(&intel_mnem_buf, "{s}{c}", .{
const intel_mnem_str = std.mem.print(&intel_mnem_buf, "{s}{c}", .{
@tagName(mnem_tag),
@as(u8, switch (mnem_size.size) {
.byte => 'b',
+1 -1
View File
@@ -975,7 +975,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
}
var lib_name_buf: [32]u8 = undefined; // Larger than each of the names "c", "stdthreads", etc.
const asm_file_basename = std.fmt.bufPrint(&lib_name_buf, "{s}.s", .{lib.name}) catch unreachable;
const asm_file_basename = std.mem.print(&lib_name_buf, "{s}.s", .{lib.name}) catch unreachable;
try o_directory.handle.writeFile(io, .{ .sub_path = asm_file_basename, .data = stubs_asm.items });
try buildSharedLib(comp, arena, o_directory, asm_file_basename, lib, prog_node);
}
+1 -1
View File
@@ -1124,7 +1124,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
}
var lib_name_buf: [32]u8 = undefined; // Larger than each of the names "c", "pthread", etc.
const asm_file_basename = std.fmt.bufPrint(&lib_name_buf, "{s}.s", .{lib.name}) catch unreachable;
const asm_file_basename = std.mem.print(&lib_name_buf, "{s}.s", .{lib.name}) catch unreachable;
try o_directory.handle.writeFile(io, .{ .sub_path = asm_file_basename, .data = stubs_asm.items });
try buildSharedLib(comp, arena, o_directory, asm_file_basename, lib, prog_node);
}
+2 -2
View File
@@ -92,9 +92,9 @@ fn addTokenAssumeCapacity(pp: *Preprocessor, tok: Token) void {
fn defineBuiltins(pp: *Preprocessor) !void {
var buf: [5]u8 = undefined;
var val = std.fmt.bufPrint(&buf, "{d}", .{pp.target.cTypeByteSize(.longdouble).?}) catch unreachable;
var val = std.mem.print(&buf, "{d}", .{pp.target.cTypeByteSize(.longdouble).?}) catch unreachable;
try pp.defineBuiltinValue("__SIZEOF_LONG_DOUBLE__", val, .pp_num);
val = std.fmt.bufPrint(&buf, "{d}", .{pp.target.cTypeByteSize(.double).?}) catch unreachable;
val = std.mem.print(&buf, "{d}", .{pp.target.cTypeByteSize(.double).?}) catch unreachable;
try pp.defineBuiltinValue("__SIZEOF_DOUBLE__", val, .pp_num);
if (pp.target.abi.isGnu()) {
+1 -1
View File
@@ -636,7 +636,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
}
var lib_name_buf: [32]u8 = undefined; // Larger than each of the names "c", "pthread", etc.
const asm_file_basename = std.fmt.bufPrint(&lib_name_buf, "{s}.s", .{lib.name}) catch unreachable;
const asm_file_basename = std.mem.print(&lib_name_buf, "{s}.s", .{lib.name}) catch unreachable;
try o_directory.handle.writeFile(io, .{ .sub_path = asm_file_basename, .data = stubs_asm.items });
try buildSharedLib(comp, arena, o_directory, asm_file_basename, lib, prog_node);
}
+1 -1
View File
@@ -557,7 +557,7 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) anye
}
var lib_name_buf: [32]u8 = undefined; // Larger than each of the names "c", "pthread", etc.
const asm_file_basename = std.fmt.bufPrint(&lib_name_buf, "{s}.s", .{lib.name}) catch unreachable;
const asm_file_basename = std.mem.print(&lib_name_buf, "{s}.s", .{lib.name}) catch unreachable;
try o_directory.handle.writeFile(io, .{ .sub_path = asm_file_basename, .data = stubs_asm.items });
try buildSharedLib(comp, arena, o_directory, asm_file_basename, lib, prog_node);
}
+3 -3
View File
@@ -5994,7 +5994,7 @@ fn resolve(coff: *Coff, tid: Zcu.PerThread.Id) !bool {
};
var name: [std.Progress.Node.max_name_len]u8 = undefined;
const sub_prog_node = coff.synth_prog_node.start(
std.fmt.bufPrint(&name, "lazy {s} for {f}", .{
std.mem.print(&name, "lazy {s} for {f}", .{
kind,
Type.fromInterned(lmr.lazySymbol(coff).ty).fmt(pt),
}) catch &name,
@@ -6132,7 +6132,7 @@ fn idleProgNode(
inline .pseudo_section, .object_section => |smi| smi.name(coff).toSlice(coff),
.input_section => |isi| {
const ioi = isi.input(coff);
break :name std.fmt.bufPrint(&name, "{f}{f} {s}", .{
break :name std.mem.print(&name, "{f}{f} {s}", .{
ioi.path(coff).fmtEscapeString(),
fmtMemberNameString(ioi.memberName(coff)),
coff.getNode(isi.symbol(coff).node(coff).parent(&coff.mf).unwrap().?).object_section.name(coff).toSlice(coff),
@@ -6143,7 +6143,7 @@ fn idleProgNode(
const ip = &coff.base.comp.zcu.?.intern_pool;
break :name ip.getNav(nmi.navIndex(coff)).fqn.toSlice(ip);
},
.uav => |umi| std.fmt.bufPrint(&name, "{f}", .{
.uav => |umi| std.mem.print(&name, "{f}", .{
Value.fromInterned(umi.uavValue(coff)).fmtValue(.{
.zcu = coff.base.comp.zcu.?,
.tid = tid,
+3 -3
View File
@@ -3834,7 +3834,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co
.field);
{
var field_name_buf: [std.fmt.count("{d}", .{std.math.maxInt(u32)})]u8 = undefined;
const field_name = std.fmt.bufPrint(&field_name_buf, "{d}", .{field_index}) catch unreachable;
const field_name = std.mem.print(&field_name_buf, "{d}", .{field_index}) catch unreachable;
try wip_nav.strp(field_name);
}
try wip_nav.refType(field_type);
@@ -4456,7 +4456,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co
.tuple_index => |index| {
try wip_nav.abbrevCode(.access);
var field_name_buf: [std.fmt.count("{d}", .{std.math.maxInt(u32)})]u8 = undefined;
const field_name = std.fmt.bufPrint(&field_name_buf, "{d}", .{index}) catch unreachable;
const field_name = std.mem.print(&field_name_buf, "{d}", .{index}) catch unreachable;
try wip_nav.strp(field_name);
},
};
@@ -4551,7 +4551,7 @@ fn updateConstInner(dwarf: *Dwarf, pt: Zcu.PerThread, debug_const_index: link.Co
continue);
{
var field_name_buf: [std.fmt.count("{d}", .{std.math.maxInt(u32)})]u8 = undefined;
const field_name = std.fmt.bufPrint(&field_name_buf, "{d}", .{field_index}) catch unreachable;
const field_name = std.mem.print(&field_name_buf, "{d}", .{field_index}) catch unreachable;
try wip_nav.strp(field_name);
}
const field_value: Value = .fromInterned(switch (aggregate.storage) {
+1 -1
View File
@@ -1026,7 +1026,7 @@ pub fn lowerUav(
};
var name_buf: [32]u8 = undefined;
const name = std.fmt.bufPrint(&name_buf, "__anon_{d}", .{
const name = std.mem.print(&name_buf, "__anon_{d}", .{
@backingInt(uav),
}) catch unreachable;
const sym_index = self.lowerConst(
+5 -5
View File
@@ -3026,7 +3026,7 @@ fn lazySymbolInner(elf: *Elf, lazy: link.File.LazySymbol) Error!link.File.Symbol
};
const node = try shndx.get(elf).ni.addFloatingChild(&elf.mf, gpa, .{});
var name_buf: [64]u8 = undefined;
const name = std.fmt.bufPrint(
const name = std.mem.print(
&name_buf,
"__lazy_{t}_{d}",
.{ lazy.kind, @backingInt(lazy.ty) },
@@ -5361,7 +5361,7 @@ fn uavMapIndex(
.alignment = resolved_align,
});
var name_buf: [32]u8 = undefined;
const name = std.fmt.bufPrint(
const name = std.mem.print(
&name_buf,
"__anon_{d}",
.{@backingInt(uav_val)},
@@ -7916,13 +7916,13 @@ fn idleProgNode(
return prog_node.start(name: switch (node) {
else => |tag| @tagName(tag),
.section => |shndx| shndx.name(elf).slice(elf),
.archive_input_member => |ii| std.fmt.bufPrint(&name, "{f}{f}", .{
.archive_input_member => |ii| std.mem.print(&name, "{f}{f}", .{
ii.path(elf).fmtEscapeString(),
fmtMemberString(ii.member(elf)),
}) catch &name,
.input_section => |isi| {
const ii = isi.input(elf);
break :name std.fmt.bufPrint(&name, "{f}{f} {s}", .{
break :name std.mem.print(&name, "{f}{f} {s}", .{
ii.path(elf).fmtEscapeString(),
fmtMemberString(ii.member(elf)),
elf.getNode(isi.node(elf).parent(&elf.mf).unwrap().?).section.name(elf).slice(elf),
@@ -7932,7 +7932,7 @@ fn idleProgNode(
const ip = &elf.base.comp.zcu.?.intern_pool;
break :name ip.getNav(nmi.navIndex(elf)).fqn.toSlice(ip);
},
.uav => |umi| std.fmt.bufPrint(&name, "{f}", .{
.uav => |umi| std.mem.print(&name, "{f}", .{
Value.fromInterned(umi.uavValue(elf)).fmtValue(.{ .zcu = elf.base.comp.zcu.?, .tid = tid }),
}) catch &name,
}, 0);
+2 -2
View File
@@ -844,7 +844,7 @@ pub const Id = struct {
allocator.free(id.name);
}
pub const ParseError = fmt.ParseIntError || fmt.BufPrintError;
pub const ParseError = fmt.ParseIntError || mem.PrintError;
pub fn parseCurrentVersion(id: *Id, version: anytype) ParseError!void {
id.current_version = try parseVersion(version);
@@ -865,7 +865,7 @@ pub const Id = struct {
},
.float => |float| {
var buf: [256]u8 = undefined;
break :blk try fmt.bufPrint(&buf, "{d}", .{float});
break :blk try mem.print(&buf, "{d}", .{float});
},
.string => |string| {
break :blk string;
+1 -1
View File
@@ -720,7 +720,7 @@ pub fn lowerUav(
}
var name_buf: [32]u8 = undefined;
const name = std.fmt.bufPrint(&name_buf, "__anon_{d}", .{
const name = std.mem.print(&name_buf, "__anon_{d}", .{
@backingInt(uav),
}) catch unreachable;
const sym_index = self.lowerConst(
+3 -3
View File
@@ -1374,7 +1374,7 @@ pub const GlobalImport = extern struct {
.__tls_base => @tagName(Unpacked.__tls_base),
.__tls_size => @tagName(Unpacked.__tls_size),
.object_global => |i| i.name(wasm).slice(wasm),
inline .uav_obj, .uav_exe => |i| std.fmt.bufPrint(
inline .uav_obj, .uav_exe => |i| std.mem.print(
buf,
"__anon_{d}",
.{@backingInt(i.key(wasm).*)},
@@ -1997,7 +1997,7 @@ pub const ObjectDataImport = extern struct {
.__heap_base => @tagName(.__heap_base),
.__heap_end => @tagName(.__heap_end),
.__wasm_first_page_end => @tagName(.__wasm_first_page_end),
inline .uav_exe, .uav_obj => |i| std.fmt.bufPrint(
inline .uav_exe, .uav_obj => |i| std.mem.print(
buf,
"__anon_{d}",
.{@backingInt(i.key(wasm).*)},
@@ -4348,7 +4348,7 @@ pub fn internString(wasm: *Wasm, bytes: []const u8) Allocator.Error!String {
// TODO implement instead by appending to string_bytes
pub fn internStringFmt(wasm: *Wasm, comptime format: []const u8, args: anytype) Allocator.Error!String {
var buffer: [32]u8 = undefined;
const slice = std.fmt.bufPrint(&buffer, format, args) catch unreachable;
const slice = std.mem.print(&buffer, format, args) catch unreachable;
return internString(wasm, slice);
}
+2 -2
View File
@@ -1706,14 +1706,14 @@ pub fn finish(f: *Flush, wasm: *Wasm) !void {
var id: [16]u8 = undefined;
std.crypto.hash.sha3.TurboShake128(null).hash(binary_bytes.items, &id, .{});
var uuid: [36]u8 = undefined;
_ = try std.fmt.bufPrint(&uuid, "{x}-{x}-{x}-{x}-{x}", .{
_ = try std.mem.print(&uuid, "{x}-{x}-{x}-{x}-{x}", .{
id[0..4], id[4..6], id[6..8], id[8..10], id[10..],
});
try emitBuildIdSection(gpa, binary_bytes, &uuid);
},
.hexstring => |hs| {
var buffer: [32 * 2]u8 = undefined;
const str = std.fmt.bufPrint(&buffer, "{x}", .{hs.toSlice()}) catch unreachable;
const str = std.mem.print(&buffer, "{x}", .{hs.toSlice()}) catch unreachable;
try emitBuildIdSection(gpa, binary_bytes, str);
},
else => |mode| {
+1 -1
View File
@@ -23,7 +23,7 @@ const ___tracy_c_zone_context = extern struct {
pub inline fn addTextFmt(self: @This(), comptime fmt: []const u8, args: anytype) void {
var buf: [512]u8 = undefined;
const slice = std.fmt.bufPrint(&buf, fmt, args) catch &buf;
const slice = std.mem.print(&buf, fmt, args) catch &buf;
self.addText(slice);
}
+1 -1
View File
@@ -2,5 +2,5 @@ const std = @import("std");
export fn strFromFloatHelp(float: f64) void {
var buf: [400]u8 = undefined;
_ = std.fmt.bufPrint(&buf, "{d}", .{float}) catch unreachable;
_ = std.mem.print(&buf, "{d}", .{float}) catch unreachable;
}