mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-09 15:19:07 +00:00
Make invalidFmtError public and use in place of compileErrors for bad format strings (#13526)
* Export invalidFmtErr To allow consistent use of "invalid format string" compile error response for badly formatted format strings. See https://github.com/ziglang/zig/pull/13489#issuecomment-1311759340. * Replace format compile errors with invalidFmtErr - Provides more consistent compile errors. - Gives user info about the type of the badly formated value. * Rename invalidFmtErr as invalidFmtError For consistency. Zig seems to use “Error” more often than “Err”. * std: add invalid format string checks to remaining custom formatters * pass reference-trace to comp when building build file; fix checkobjectstep
This commit is contained in:
parent
32b97df50e
commit
8a5818535b
18 changed files with 52 additions and 43 deletions
|
|
@ -157,7 +157,7 @@ pub fn format(
|
||||||
out_stream: anytype,
|
out_stream: anytype,
|
||||||
) !void {
|
) !void {
|
||||||
_ = options;
|
_ = options;
|
||||||
if (fmt.len != 0) @compileError("Unknown format string: '" ++ fmt ++ "'");
|
if (fmt.len != 0) std.fmt.invalidFmtError(fmt, self);
|
||||||
try std.fmt.format(out_stream, "{d}.{d}.{d}", .{ self.major, self.minor, self.patch });
|
try std.fmt.format(out_stream, "{d}.{d}.{d}", .{ self.major, self.minor, self.patch });
|
||||||
if (self.pre) |pre| try std.fmt.format(out_stream, "-{s}", .{pre});
|
if (self.pre) |pre| try std.fmt.format(out_stream, "-{s}", .{pre});
|
||||||
if (self.build) |build| try std.fmt.format(out_stream, "+{s}", .{build});
|
if (self.build) |build| try std.fmt.format(out_stream, "+{s}", .{build});
|
||||||
|
|
|
||||||
|
|
@ -187,7 +187,7 @@ const ComputeCompareExpected = struct {
|
||||||
options: std.fmt.FormatOptions,
|
options: std.fmt.FormatOptions,
|
||||||
writer: anytype,
|
writer: anytype,
|
||||||
) !void {
|
) !void {
|
||||||
_ = fmt;
|
if (fmt.len != 0) std.fmt.invalidFmtError(fmt, value);
|
||||||
_ = options;
|
_ = options;
|
||||||
try writer.print("{s} ", .{@tagName(value.op)});
|
try writer.print("{s} ", .{@tagName(value.op)});
|
||||||
switch (value.value) {
|
switch (value.value) {
|
||||||
|
|
@ -360,7 +360,7 @@ fn make(step: *Step) !void {
|
||||||
std.debug.print(
|
std.debug.print(
|
||||||
\\
|
\\
|
||||||
\\========= Comparison failed for action: ===========
|
\\========= Comparison failed for action: ===========
|
||||||
\\{s} {s}
|
\\{s} {}
|
||||||
\\========= From parsed file: =======================
|
\\========= From parsed file: =======================
|
||||||
\\{s}
|
\\{s}
|
||||||
\\
|
\\
|
||||||
|
|
|
||||||
|
|
@ -38,12 +38,13 @@ pub const StackTrace = struct {
|
||||||
options: std.fmt.FormatOptions,
|
options: std.fmt.FormatOptions,
|
||||||
writer: anytype,
|
writer: anytype,
|
||||||
) !void {
|
) !void {
|
||||||
|
if (fmt.len != 0) std.fmt.invalidFmtError(fmt, self);
|
||||||
|
|
||||||
// TODO: re-evaluate whether to use format() methods at all.
|
// TODO: re-evaluate whether to use format() methods at all.
|
||||||
// Until then, avoid an error when using GeneralPurposeAllocator with WebAssembly
|
// Until then, avoid an error when using GeneralPurposeAllocator with WebAssembly
|
||||||
// where it tries to call detectTTYConfig here.
|
// where it tries to call detectTTYConfig here.
|
||||||
if (builtin.os.tag == .freestanding) return;
|
if (builtin.os.tag == .freestanding) return;
|
||||||
|
|
||||||
_ = fmt;
|
|
||||||
_ = options;
|
_ = options;
|
||||||
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
|
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
|
||||||
defer arena.deinit();
|
defer arena.deinit();
|
||||||
|
|
@ -534,7 +535,7 @@ pub const Version = struct {
|
||||||
return std.fmt.format(out_stream, "{d}.{d}.{d}", .{ self.major, self.minor, self.patch });
|
return std.fmt.format(out_stream, "{d}.{d}.{d}", .{ self.major, self.minor, self.patch });
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@compileError("Unknown format string: '" ++ fmt ++ "'");
|
std.fmt.invalidFmtError(fmt, self);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -2123,7 +2123,7 @@ pub fn ConfigurableTrace(comptime size: usize, comptime stack_frame_count: usize
|
||||||
options: std.fmt.FormatOptions,
|
options: std.fmt.FormatOptions,
|
||||||
writer: anytype,
|
writer: anytype,
|
||||||
) !void {
|
) !void {
|
||||||
_ = fmt;
|
if (fmt.len != 0) std.fmt.invalidFmtError(fmt, t);
|
||||||
_ = options;
|
_ = options;
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
try writer.writeAll("\n");
|
try writer.writeAll("\n");
|
||||||
|
|
|
||||||
|
|
@ -454,7 +454,7 @@ fn stripOptionalOrErrorUnionSpec(comptime fmt: []const u8) []const u8 {
|
||||||
fmt[1..];
|
fmt[1..];
|
||||||
}
|
}
|
||||||
|
|
||||||
fn invalidFmtErr(comptime fmt: []const u8, value: anytype) void {
|
pub fn invalidFmtError(comptime fmt: []const u8, value: anytype) void {
|
||||||
@compileError("invalid format string '" ++ fmt ++ "' for type '" ++ @typeName(@TypeOf(value)) ++ "'");
|
@compileError("invalid format string '" ++ fmt ++ "' for type '" ++ @typeName(@TypeOf(value)) ++ "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -486,11 +486,11 @@ pub fn formatType(
|
||||||
return formatValue(value, actual_fmt, options, writer);
|
return formatValue(value, actual_fmt, options, writer);
|
||||||
},
|
},
|
||||||
.Void => {
|
.Void => {
|
||||||
if (actual_fmt.len != 0) invalidFmtErr(fmt, value);
|
if (actual_fmt.len != 0) invalidFmtError(fmt, value);
|
||||||
return formatBuf("void", options, writer);
|
return formatBuf("void", options, writer);
|
||||||
},
|
},
|
||||||
.Bool => {
|
.Bool => {
|
||||||
if (actual_fmt.len != 0) invalidFmtErr(fmt, value);
|
if (actual_fmt.len != 0) invalidFmtError(fmt, value);
|
||||||
return formatBuf(if (value) "true" else "false", options, writer);
|
return formatBuf(if (value) "true" else "false", options, writer);
|
||||||
},
|
},
|
||||||
.Optional => {
|
.Optional => {
|
||||||
|
|
@ -514,14 +514,14 @@ pub fn formatType(
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
.ErrorSet => {
|
.ErrorSet => {
|
||||||
if (actual_fmt.len != 0) invalidFmtErr(fmt, value);
|
if (actual_fmt.len != 0) invalidFmtError(fmt, value);
|
||||||
try writer.writeAll("error.");
|
try writer.writeAll("error.");
|
||||||
return writer.writeAll(@errorName(value));
|
return writer.writeAll(@errorName(value));
|
||||||
},
|
},
|
||||||
.Enum => |enumInfo| {
|
.Enum => |enumInfo| {
|
||||||
try writer.writeAll(@typeName(T));
|
try writer.writeAll(@typeName(T));
|
||||||
if (enumInfo.is_exhaustive) {
|
if (enumInfo.is_exhaustive) {
|
||||||
if (actual_fmt.len != 0) invalidFmtErr(fmt, value);
|
if (actual_fmt.len != 0) invalidFmtError(fmt, value);
|
||||||
try writer.writeAll(".");
|
try writer.writeAll(".");
|
||||||
try writer.writeAll(@tagName(value));
|
try writer.writeAll(@tagName(value));
|
||||||
return;
|
return;
|
||||||
|
|
@ -542,7 +542,7 @@ pub fn formatType(
|
||||||
try writer.writeAll(")");
|
try writer.writeAll(")");
|
||||||
},
|
},
|
||||||
.Union => |info| {
|
.Union => |info| {
|
||||||
if (actual_fmt.len != 0) invalidFmtErr(fmt, value);
|
if (actual_fmt.len != 0) invalidFmtError(fmt, value);
|
||||||
try writer.writeAll(@typeName(T));
|
try writer.writeAll(@typeName(T));
|
||||||
if (max_depth == 0) {
|
if (max_depth == 0) {
|
||||||
return writer.writeAll("{ ... }");
|
return writer.writeAll("{ ... }");
|
||||||
|
|
@ -562,7 +562,7 @@ pub fn formatType(
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
.Struct => |info| {
|
.Struct => |info| {
|
||||||
if (actual_fmt.len != 0) invalidFmtErr(fmt, value);
|
if (actual_fmt.len != 0) invalidFmtError(fmt, value);
|
||||||
if (info.is_tuple) {
|
if (info.is_tuple) {
|
||||||
// Skip the type and field names when formatting tuples.
|
// Skip the type and field names when formatting tuples.
|
||||||
if (max_depth == 0) {
|
if (max_depth == 0) {
|
||||||
|
|
@ -618,7 +618,7 @@ pub fn formatType(
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
invalidFmtErr(fmt, value);
|
invalidFmtError(fmt, value);
|
||||||
},
|
},
|
||||||
.Enum, .Union, .Struct => {
|
.Enum, .Union, .Struct => {
|
||||||
return formatType(value.*, actual_fmt, options, writer, max_depth);
|
return formatType(value.*, actual_fmt, options, writer, max_depth);
|
||||||
|
|
@ -640,7 +640,7 @@ pub fn formatType(
|
||||||
else => {},
|
else => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
invalidFmtErr(fmt, value);
|
invalidFmtError(fmt, value);
|
||||||
},
|
},
|
||||||
.Slice => {
|
.Slice => {
|
||||||
if (actual_fmt.len == 0)
|
if (actual_fmt.len == 0)
|
||||||
|
|
@ -703,20 +703,20 @@ pub fn formatType(
|
||||||
try writer.writeAll(" }");
|
try writer.writeAll(" }");
|
||||||
},
|
},
|
||||||
.Fn => {
|
.Fn => {
|
||||||
if (actual_fmt.len != 0) invalidFmtErr(fmt, value);
|
if (actual_fmt.len != 0) invalidFmtError(fmt, value);
|
||||||
return format(writer, "{s}@{x}", .{ @typeName(T), @ptrToInt(value) });
|
return format(writer, "{s}@{x}", .{ @typeName(T), @ptrToInt(value) });
|
||||||
},
|
},
|
||||||
.Type => {
|
.Type => {
|
||||||
if (actual_fmt.len != 0) invalidFmtErr(fmt, value);
|
if (actual_fmt.len != 0) invalidFmtError(fmt, value);
|
||||||
return formatBuf(@typeName(value), options, writer);
|
return formatBuf(@typeName(value), options, writer);
|
||||||
},
|
},
|
||||||
.EnumLiteral => {
|
.EnumLiteral => {
|
||||||
if (actual_fmt.len != 0) invalidFmtErr(fmt, value);
|
if (actual_fmt.len != 0) invalidFmtError(fmt, value);
|
||||||
const buffer = [_]u8{'.'} ++ @tagName(value);
|
const buffer = [_]u8{'.'} ++ @tagName(value);
|
||||||
return formatBuf(buffer, options, writer);
|
return formatBuf(buffer, options, writer);
|
||||||
},
|
},
|
||||||
.Null => {
|
.Null => {
|
||||||
if (actual_fmt.len != 0) invalidFmtErr(fmt, value);
|
if (actual_fmt.len != 0) invalidFmtError(fmt, value);
|
||||||
return formatBuf("null", options, writer);
|
return formatBuf("null", options, writer);
|
||||||
},
|
},
|
||||||
else => @compileError("unable to format type '" ++ @typeName(T) ++ "'"),
|
else => @compileError("unable to format type '" ++ @typeName(T) ++ "'"),
|
||||||
|
|
@ -786,7 +786,7 @@ pub fn formatIntValue(
|
||||||
radix = 8;
|
radix = 8;
|
||||||
case = .lower;
|
case = .lower;
|
||||||
} else {
|
} else {
|
||||||
invalidFmtErr(fmt, value);
|
invalidFmtError(fmt, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return formatInt(int_value, radix, case, options, writer);
|
return formatInt(int_value, radix, case, options, writer);
|
||||||
|
|
@ -815,7 +815,7 @@ fn formatFloatValue(
|
||||||
error.NoSpaceLeft => unreachable,
|
error.NoSpaceLeft => unreachable,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
invalidFmtErr(fmt, value);
|
invalidFmtError(fmt, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return formatBuf(buf_stream.getWritten(), options, writer);
|
return formatBuf(buf_stream.getWritten(), options, writer);
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ pub const PreopenType = union(PreopenTypeTag) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn format(self: Self, comptime fmt: []const u8, options: std.fmt.FormatOptions, out_stream: anytype) !void {
|
pub fn format(self: Self, comptime fmt: []const u8, options: std.fmt.FormatOptions, out_stream: anytype) !void {
|
||||||
_ = fmt;
|
if (fmt.len != 0) std.fmt.invalidFmtError(fmt, self);
|
||||||
_ = options;
|
_ = options;
|
||||||
try out_stream.print("PreopenType{{ ", .{});
|
try out_stream.print("PreopenType{{ ", .{});
|
||||||
switch (self) {
|
switch (self) {
|
||||||
|
|
|
||||||
|
|
@ -326,7 +326,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
|
||||||
const slot_index = @intCast(SlotIndex, used_bits_byte * 8 + bit_index);
|
const slot_index = @intCast(SlotIndex, used_bits_byte * 8 + bit_index);
|
||||||
const stack_trace = bucketStackTrace(bucket, size_class, slot_index, .alloc);
|
const stack_trace = bucketStackTrace(bucket, size_class, slot_index, .alloc);
|
||||||
const addr = bucket.page + slot_index * size_class;
|
const addr = bucket.page + slot_index * size_class;
|
||||||
log.err("memory address 0x{x} leaked: {s}", .{
|
log.err("memory address 0x{x} leaked: {}", .{
|
||||||
@ptrToInt(addr), stack_trace,
|
@ptrToInt(addr), stack_trace,
|
||||||
});
|
});
|
||||||
leaks = true;
|
leaks = true;
|
||||||
|
|
@ -358,7 +358,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
|
||||||
while (it.next()) |large_alloc| {
|
while (it.next()) |large_alloc| {
|
||||||
if (config.retain_metadata and large_alloc.freed) continue;
|
if (config.retain_metadata and large_alloc.freed) continue;
|
||||||
const stack_trace = large_alloc.getStackTrace(.alloc);
|
const stack_trace = large_alloc.getStackTrace(.alloc);
|
||||||
log.err("memory address 0x{x} leaked: {s}", .{
|
log.err("memory address 0x{x} leaked: {}", .{
|
||||||
@ptrToInt(large_alloc.bytes.ptr), stack_trace,
|
@ptrToInt(large_alloc.bytes.ptr), stack_trace,
|
||||||
});
|
});
|
||||||
leaks = true;
|
leaks = true;
|
||||||
|
|
@ -443,7 +443,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
|
||||||
.index = 0,
|
.index = 0,
|
||||||
};
|
};
|
||||||
std.debug.captureStackTrace(ret_addr, &second_free_stack_trace);
|
std.debug.captureStackTrace(ret_addr, &second_free_stack_trace);
|
||||||
log.err("Double free detected. Allocation: {s} First free: {s} Second free: {s}", .{
|
log.err("Double free detected. Allocation: {} First free: {} Second free: {}", .{
|
||||||
alloc_stack_trace, free_stack_trace, second_free_stack_trace,
|
alloc_stack_trace, free_stack_trace, second_free_stack_trace,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -533,7 +533,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
|
||||||
.index = 0,
|
.index = 0,
|
||||||
};
|
};
|
||||||
std.debug.captureStackTrace(ret_addr, &free_stack_trace);
|
std.debug.captureStackTrace(ret_addr, &free_stack_trace);
|
||||||
log.err("Allocation size {d} bytes does not match free size {d}. Allocation: {s} Free: {s}", .{
|
log.err("Allocation size {d} bytes does not match free size {d}. Allocation: {} Free: {}", .{
|
||||||
entry.value_ptr.bytes.len,
|
entry.value_ptr.bytes.len,
|
||||||
old_mem.len,
|
old_mem.len,
|
||||||
entry.value_ptr.getStackTrace(.alloc),
|
entry.value_ptr.getStackTrace(.alloc),
|
||||||
|
|
@ -606,7 +606,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
|
||||||
.index = 0,
|
.index = 0,
|
||||||
};
|
};
|
||||||
std.debug.captureStackTrace(ret_addr, &free_stack_trace);
|
std.debug.captureStackTrace(ret_addr, &free_stack_trace);
|
||||||
log.err("Allocation size {d} bytes does not match free size {d}. Allocation: {s} Free: {s}", .{
|
log.err("Allocation size {d} bytes does not match free size {d}. Allocation: {} Free: {}", .{
|
||||||
entry.value_ptr.bytes.len,
|
entry.value_ptr.bytes.len,
|
||||||
old_mem.len,
|
old_mem.len,
|
||||||
entry.value_ptr.getStackTrace(.alloc),
|
entry.value_ptr.getStackTrace(.alloc),
|
||||||
|
|
|
||||||
|
|
@ -2061,7 +2061,7 @@ pub const Const = struct {
|
||||||
radix = 16;
|
radix = 16;
|
||||||
case = .upper;
|
case = .upper;
|
||||||
} else {
|
} else {
|
||||||
@compileError("Unknown format string: '" ++ fmt ++ "'");
|
std.fmt.invalidFmtError(fmt, self);
|
||||||
}
|
}
|
||||||
|
|
||||||
var limbs: [128]Limb = undefined;
|
var limbs: [128]Limb = undefined;
|
||||||
|
|
|
||||||
|
|
@ -149,6 +149,7 @@ pub const Address = extern union {
|
||||||
options: std.fmt.FormatOptions,
|
options: std.fmt.FormatOptions,
|
||||||
out_stream: anytype,
|
out_stream: anytype,
|
||||||
) !void {
|
) !void {
|
||||||
|
if (fmt.len != 0) std.fmt.invalidFmtError(fmt, self);
|
||||||
switch (self.any.family) {
|
switch (self.any.family) {
|
||||||
os.AF.INET => try self.in.format(fmt, options, out_stream),
|
os.AF.INET => try self.in.format(fmt, options, out_stream),
|
||||||
os.AF.INET6 => try self.in6.format(fmt, options, out_stream),
|
os.AF.INET6 => try self.in6.format(fmt, options, out_stream),
|
||||||
|
|
@ -274,7 +275,7 @@ pub const Ip4Address = extern struct {
|
||||||
options: std.fmt.FormatOptions,
|
options: std.fmt.FormatOptions,
|
||||||
out_stream: anytype,
|
out_stream: anytype,
|
||||||
) !void {
|
) !void {
|
||||||
_ = fmt;
|
if (fmt.len != 0) std.fmt.invalidFmtError(fmt, self);
|
||||||
_ = options;
|
_ = options;
|
||||||
const bytes = @ptrCast(*const [4]u8, &self.sa.addr);
|
const bytes = @ptrCast(*const [4]u8, &self.sa.addr);
|
||||||
try std.fmt.format(out_stream, "{}.{}.{}.{}:{}", .{
|
try std.fmt.format(out_stream, "{}.{}.{}.{}:{}", .{
|
||||||
|
|
@ -563,7 +564,7 @@ pub const Ip6Address = extern struct {
|
||||||
options: std.fmt.FormatOptions,
|
options: std.fmt.FormatOptions,
|
||||||
out_stream: anytype,
|
out_stream: anytype,
|
||||||
) !void {
|
) !void {
|
||||||
_ = fmt;
|
if (fmt.len != 0) std.fmt.invalidFmtError(fmt, self);
|
||||||
_ = options;
|
_ = options;
|
||||||
const port = mem.bigToNative(u16, self.sa.port);
|
const port = mem.bigToNative(u16, self.sa.port);
|
||||||
if (mem.eql(u8, self.sa.addr[0..12], &[_]u8{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff })) {
|
if (mem.eql(u8, self.sa.addr[0..12], &[_]u8{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff })) {
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ pub const Guid = extern struct {
|
||||||
fmt(std.mem.asBytes(&self.node)),
|
fmt(std.mem.asBytes(&self.node)),
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@compileError("Unknown format character: '" ++ f ++ "'");
|
std.fmt.invalidFmtError(f, self);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -167,19 +167,21 @@ pub const Target = struct {
|
||||||
_: std.fmt.FormatOptions,
|
_: std.fmt.FormatOptions,
|
||||||
out_stream: anytype,
|
out_stream: anytype,
|
||||||
) !void {
|
) !void {
|
||||||
if (fmt.len > 0 and fmt[0] == 's') {
|
if (comptime std.mem.eql(u8, fmt, "s")) {
|
||||||
if (@enumToInt(self) >= @enumToInt(WindowsVersion.nt4) and @enumToInt(self) <= @enumToInt(WindowsVersion.latest)) {
|
if (@enumToInt(self) >= @enumToInt(WindowsVersion.nt4) and @enumToInt(self) <= @enumToInt(WindowsVersion.latest)) {
|
||||||
try std.fmt.format(out_stream, ".{s}", .{@tagName(self)});
|
try std.fmt.format(out_stream, ".{s}", .{@tagName(self)});
|
||||||
} else {
|
} else {
|
||||||
// TODO this code path breaks zig triples, but it is used in `builtin`
|
// TODO this code path breaks zig triples, but it is used in `builtin`
|
||||||
try std.fmt.format(out_stream, "@intToEnum(Target.Os.WindowsVersion, 0x{X:0>8})", .{@enumToInt(self)});
|
try std.fmt.format(out_stream, "@intToEnum(Target.Os.WindowsVersion, 0x{X:0>8})", .{@enumToInt(self)});
|
||||||
}
|
}
|
||||||
} else {
|
} else if (fmt.len == 0) {
|
||||||
if (@enumToInt(self) >= @enumToInt(WindowsVersion.nt4) and @enumToInt(self) <= @enumToInt(WindowsVersion.latest)) {
|
if (@enumToInt(self) >= @enumToInt(WindowsVersion.nt4) and @enumToInt(self) <= @enumToInt(WindowsVersion.latest)) {
|
||||||
try std.fmt.format(out_stream, "WindowsVersion.{s}", .{@tagName(self)});
|
try std.fmt.format(out_stream, "WindowsVersion.{s}", .{@tagName(self)});
|
||||||
} else {
|
} else {
|
||||||
try std.fmt.format(out_stream, "WindowsVersion(0x{X:0>8})", .{@enumToInt(self)});
|
try std.fmt.format(out_stream, "WindowsVersion(0x{X:0>8})", .{@enumToInt(self)});
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
std.fmt.invalidFmtError(fmt, self);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -700,7 +700,7 @@ pub fn checkAllAllocationFailures(backing_allocator: std.mem.Allocator, comptime
|
||||||
error.OutOfMemory => {
|
error.OutOfMemory => {
|
||||||
if (failing_allocator_inst.allocated_bytes != failing_allocator_inst.freed_bytes) {
|
if (failing_allocator_inst.allocated_bytes != failing_allocator_inst.freed_bytes) {
|
||||||
print(
|
print(
|
||||||
"\nfail_index: {d}/{d}\nallocated bytes: {d}\nfreed bytes: {d}\nallocations: {d}\ndeallocations: {d}\nallocation that was made to fail: {s}",
|
"\nfail_index: {d}/{d}\nallocated bytes: {d}\nfreed bytes: {d}\nallocations: {d}\ndeallocations: {d}\nallocation that was made to fail: {}",
|
||||||
.{
|
.{
|
||||||
fail_index,
|
fail_index,
|
||||||
needed_alloc_count,
|
needed_alloc_count,
|
||||||
|
|
|
||||||
|
|
@ -356,7 +356,7 @@ pub const Type = struct {
|
||||||
returns: []const Valtype,
|
returns: []const Valtype,
|
||||||
|
|
||||||
pub fn format(self: Type, comptime fmt: []const u8, opt: std.fmt.FormatOptions, writer: anytype) !void {
|
pub fn format(self: Type, comptime fmt: []const u8, opt: std.fmt.FormatOptions, writer: anytype) !void {
|
||||||
_ = fmt;
|
if (fmt.len != 0) std.fmt.invalidFmtError(fmt, self);
|
||||||
_ = opt;
|
_ = opt;
|
||||||
try writer.writeByte('(');
|
try writer.writeByte('(');
|
||||||
for (self.params) |param, i| {
|
for (self.params) |param, i| {
|
||||||
|
|
|
||||||
|
|
@ -282,8 +282,7 @@ pub const Insn = extern struct {
|
||||||
writer: anytype,
|
writer: anytype,
|
||||||
) !void {
|
) !void {
|
||||||
_ = opts;
|
_ = opts;
|
||||||
if (comptime layout.len != 0 and layout[0] != 's')
|
if (layout.len != 0) std.fmt.invalidFmtError(layout, self);
|
||||||
@compileError("Unsupported format specifier for BPF Insn type '" ++ layout ++ "'.");
|
|
||||||
|
|
||||||
try std.fmt.format(
|
try std.fmt.format(
|
||||||
writer,
|
writer,
|
||||||
|
|
|
||||||
|
|
@ -47,8 +47,8 @@ pub const Address = union(enum) {
|
||||||
opts: fmt.FormatOptions,
|
opts: fmt.FormatOptions,
|
||||||
writer: anytype,
|
writer: anytype,
|
||||||
) !void {
|
) !void {
|
||||||
|
if (layout.len != 0) std.fmt.invalidFmtError(layout, self);
|
||||||
_ = opts;
|
_ = opts;
|
||||||
_ = layout;
|
|
||||||
switch (self) {
|
switch (self) {
|
||||||
.ipv4 => |address| try fmt.format(writer, "{}:{}", .{ address.host, address.port }),
|
.ipv4 => |address| try fmt.format(writer, "{}:{}", .{ address.host, address.port }),
|
||||||
.ipv6 => |address| try fmt.format(writer, "{}:{}", .{ address.host, address.port }),
|
.ipv6 => |address| try fmt.format(writer, "{}:{}", .{ address.host, address.port }),
|
||||||
|
|
|
||||||
|
|
@ -168,9 +168,7 @@ pub const IPv4 = extern struct {
|
||||||
writer: anytype,
|
writer: anytype,
|
||||||
) !void {
|
) !void {
|
||||||
_ = opts;
|
_ = opts;
|
||||||
if (comptime layout.len != 0 and layout[0] != 's') {
|
if (layout.len != 0) std.fmt.invalidFmtError(layout, self);
|
||||||
@compileError("Unsupported format specifier for IPv4 type '" ++ layout ++ "'.");
|
|
||||||
}
|
|
||||||
|
|
||||||
try fmt.format(writer, "{}.{}.{}.{}", .{
|
try fmt.format(writer, "{}.{}.{}.{}", .{
|
||||||
self.octets[0],
|
self.octets[0],
|
||||||
|
|
@ -382,7 +380,7 @@ pub const IPv6 = extern struct {
|
||||||
'x', 'X' => |specifier| specifier,
|
'x', 'X' => |specifier| specifier,
|
||||||
's' => 'x',
|
's' => 'x',
|
||||||
'S' => 'X',
|
'S' => 'X',
|
||||||
else => @compileError("Unsupported format specifier for IPv6 type '" ++ layout ++ "'."),
|
else => std.fmt.invalidFmtError(layout, self),
|
||||||
}};
|
}};
|
||||||
|
|
||||||
if (mem.startsWith(u8, &self.octets, &v4_mapped_prefix)) {
|
if (mem.startsWith(u8, &self.octets, &v4_mapped_prefix)) {
|
||||||
|
|
|
||||||
|
|
@ -127,8 +127,8 @@ pub const Socket = struct {
|
||||||
opts: fmt.FormatOptions,
|
opts: fmt.FormatOptions,
|
||||||
writer: anytype,
|
writer: anytype,
|
||||||
) !void {
|
) !void {
|
||||||
|
if (layout.len != 0) std.fmt.invalidFmtError(layout, self);
|
||||||
_ = opts;
|
_ = opts;
|
||||||
_ = layout;
|
|
||||||
switch (self) {
|
switch (self) {
|
||||||
.ipv4 => |address| try fmt.format(writer, "{}:{}", .{ address.host, address.port }),
|
.ipv4 => |address| try fmt.format(writer, "{}:{}", .{ address.host, address.port }),
|
||||||
.ipv6 => |address| try fmt.format(writer, "{}:{}", .{ address.host, address.port }),
|
.ipv6 => |address| try fmt.format(writer, "{}:{}", .{ address.host, address.port }),
|
||||||
|
|
|
||||||
|
|
@ -3744,6 +3744,7 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
|
||||||
var override_global_cache_dir: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_GLOBAL_CACHE_DIR");
|
var override_global_cache_dir: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_GLOBAL_CACHE_DIR");
|
||||||
var override_local_cache_dir: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_LOCAL_CACHE_DIR");
|
var override_local_cache_dir: ?[]const u8 = try optionalStringEnvVar(arena, "ZIG_LOCAL_CACHE_DIR");
|
||||||
var child_argv = std.ArrayList([]const u8).init(arena);
|
var child_argv = std.ArrayList([]const u8).init(arena);
|
||||||
|
var reference_trace: ?u32 = null;
|
||||||
|
|
||||||
const argv_index_exe = child_argv.items.len;
|
const argv_index_exe = child_argv.items.len;
|
||||||
_ = try child_argv.addOne();
|
_ = try child_argv.addOne();
|
||||||
|
|
@ -3795,10 +3796,16 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
|
||||||
try child_argv.append(arg);
|
try child_argv.append(arg);
|
||||||
} else if (mem.eql(u8, arg, "-freference-trace")) {
|
} else if (mem.eql(u8, arg, "-freference-trace")) {
|
||||||
try child_argv.append(arg);
|
try child_argv.append(arg);
|
||||||
|
reference_trace = 256;
|
||||||
} else if (mem.startsWith(u8, arg, "-freference-trace=")) {
|
} else if (mem.startsWith(u8, arg, "-freference-trace=")) {
|
||||||
try child_argv.append(arg);
|
try child_argv.append(arg);
|
||||||
|
const num = arg["-freference-trace=".len..];
|
||||||
|
reference_trace = std.fmt.parseUnsigned(u32, num, 10) catch |err| {
|
||||||
|
fatal("unable to parse reference_trace count '{s}': {s}", .{ num, @errorName(err) });
|
||||||
|
};
|
||||||
} else if (mem.eql(u8, arg, "-fno-reference-trace")) {
|
} else if (mem.eql(u8, arg, "-fno-reference-trace")) {
|
||||||
try child_argv.append(arg);
|
try child_argv.append(arg);
|
||||||
|
reference_trace = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try child_argv.append(arg);
|
try child_argv.append(arg);
|
||||||
|
|
@ -3932,6 +3939,7 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
|
||||||
.thread_pool = &thread_pool,
|
.thread_pool = &thread_pool,
|
||||||
.use_stage1 = use_stage1,
|
.use_stage1 = use_stage1,
|
||||||
.cache_mode = .whole,
|
.cache_mode = .whole,
|
||||||
|
.reference_trace = reference_trace,
|
||||||
}) catch |err| {
|
}) catch |err| {
|
||||||
fatal("unable to create compilation: {s}", .{@errorName(err)});
|
fatal("unable to create compilation: {s}", .{@errorName(err)});
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue