mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
zig fmt the std lib
This commit is contained in:
parent
d7049fc8e0
commit
5f35dc0c0d
20 changed files with 174 additions and 137 deletions
|
|
@ -70,16 +70,8 @@ else switch (std.Target.current.os.tag) {
|
||||||
/// Signals the processor that it is inside a busy-wait spin-loop ("spin lock").
|
/// Signals the processor that it is inside a busy-wait spin-loop ("spin lock").
|
||||||
pub fn spinLoopHint() void {
|
pub fn spinLoopHint() void {
|
||||||
switch (std.Target.current.cpu.arch) {
|
switch (std.Target.current.cpu.arch) {
|
||||||
.i386, .x86_64 => asm volatile ("pause"
|
.i386, .x86_64 => asm volatile ("pause" ::: "memory"),
|
||||||
:
|
.arm, .aarch64 => asm volatile ("yield" ::: "memory"),
|
||||||
:
|
|
||||||
: "memory"
|
|
||||||
),
|
|
||||||
.arm, .aarch64 => asm volatile ("yield"
|
|
||||||
:
|
|
||||||
:
|
|
||||||
: "memory"
|
|
||||||
),
|
|
||||||
else => {},
|
else => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -90,12 +82,11 @@ pub fn spinLoopHint() void {
|
||||||
pub fn getCurrentId() Id {
|
pub fn getCurrentId() Id {
|
||||||
if (use_pthreads) {
|
if (use_pthreads) {
|
||||||
return c.pthread_self();
|
return c.pthread_self();
|
||||||
} else
|
} else return switch (std.Target.current.os.tag) {
|
||||||
return switch (std.Target.current.os.tag) {
|
.linux => os.linux.gettid(),
|
||||||
.linux => os.linux.gettid(),
|
.windows => windows.kernel32.GetCurrentThreadId(),
|
||||||
.windows => windows.kernel32.GetCurrentThreadId(),
|
else => @compileError("Unsupported OS"),
|
||||||
else => @compileError("Unsupported OS"),
|
};
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the handle of this thread.
|
/// Returns the handle of this thread.
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
mutex: Mutex = .{},
|
mutex: Mutex = .{},
|
||||||
cond: Condition = .{},
|
cond: Condition = .{},
|
||||||
//! It is OK to initialize this field to any value.
|
/// It is OK to initialize this field to any value.
|
||||||
permits: usize = 0,
|
permits: usize = 0,
|
||||||
|
|
||||||
const Semaphore = @This();
|
const Semaphore = @This();
|
||||||
|
|
|
||||||
|
|
@ -1237,8 +1237,7 @@ test "shrink" {
|
||||||
if (i < 17) {
|
if (i < 17) {
|
||||||
testing.expect(gop.found_existing == true);
|
testing.expect(gop.found_existing == true);
|
||||||
testing.expect(gop.entry.value == i * 10);
|
testing.expect(gop.entry.value == i * 10);
|
||||||
} else
|
} else testing.expect(gop.found_existing == false);
|
||||||
testing.expect(gop.found_existing == false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test `shrinkAndFree`.
|
// Test `shrinkAndFree`.
|
||||||
|
|
@ -1251,8 +1250,7 @@ test "shrink" {
|
||||||
if (i < 15) {
|
if (i < 15) {
|
||||||
testing.expect(gop.found_existing == true);
|
testing.expect(gop.found_existing == true);
|
||||||
testing.expect(gop.entry.value == i * 10);
|
testing.expect(gop.entry.value == i * 10);
|
||||||
} else
|
} else testing.expect(gop.found_existing == false);
|
||||||
testing.expect(gop.found_existing == false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -222,12 +222,10 @@ pub const Base64DecoderWithIgnore = struct {
|
||||||
} else if (decoder_with_ignore.char_is_ignored[c]) {
|
} else if (decoder_with_ignore.char_is_ignored[c]) {
|
||||||
// we can even ignore chars during the padding
|
// we can even ignore chars during the padding
|
||||||
continue;
|
continue;
|
||||||
} else
|
} else return error.InvalidCharacter;
|
||||||
return error.InvalidCharacter;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
} else
|
} else return error.InvalidCharacter;
|
||||||
return error.InvalidCharacter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (available_chars) {
|
switch (available_chars) {
|
||||||
|
|
|
||||||
|
|
@ -2763,7 +2763,9 @@ pub const InstallDirectoryOptions = struct {
|
||||||
.install_dir = self.install_dir.dupe(b),
|
.install_dir = self.install_dir.dupe(b),
|
||||||
.install_subdir = b.dupe(self.install_subdir),
|
.install_subdir = b.dupe(self.install_subdir),
|
||||||
.exclude_extensions = if (self.exclude_extensions) |extensions|
|
.exclude_extensions = if (self.exclude_extensions) |extensions|
|
||||||
b.dupeStrings(extensions) else null,
|
b.dupeStrings(extensions)
|
||||||
|
else
|
||||||
|
null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,22 @@
|
||||||
|
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
pub fn __builtin_bswap16(val: u16) callconv(.Inline) u16 { return @byteSwap(u16, val); }
|
pub fn __builtin_bswap16(val: u16) callconv(.Inline) u16 {
|
||||||
pub fn __builtin_bswap32(val: u32) callconv(.Inline) u32 { return @byteSwap(u32, val); }
|
return @byteSwap(u16, val);
|
||||||
pub fn __builtin_bswap64(val: u64) callconv(.Inline) u64 { return @byteSwap(u64, val); }
|
}
|
||||||
|
pub fn __builtin_bswap32(val: u32) callconv(.Inline) u32 {
|
||||||
|
return @byteSwap(u32, val);
|
||||||
|
}
|
||||||
|
pub fn __builtin_bswap64(val: u64) callconv(.Inline) u64 {
|
||||||
|
return @byteSwap(u64, val);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn __builtin_signbit(val: f64) callconv(.Inline) c_int { return @boolToInt(std.math.signbit(val)); }
|
pub fn __builtin_signbit(val: f64) callconv(.Inline) c_int {
|
||||||
pub fn __builtin_signbitf(val: f32) callconv(.Inline) c_int { return @boolToInt(std.math.signbit(val)); }
|
return @boolToInt(std.math.signbit(val));
|
||||||
|
}
|
||||||
|
pub fn __builtin_signbitf(val: f32) callconv(.Inline) c_int {
|
||||||
|
return @boolToInt(std.math.signbit(val));
|
||||||
|
}
|
||||||
|
|
||||||
pub fn __builtin_popcount(val: c_uint) callconv(.Inline) c_int {
|
pub fn __builtin_popcount(val: c_uint) callconv(.Inline) c_int {
|
||||||
// popcount of a c_uint will never exceed the capacity of a c_int
|
// popcount of a c_uint will never exceed the capacity of a c_int
|
||||||
|
|
@ -31,40 +41,96 @@ pub fn __builtin_clz(val: c_uint) callconv(.Inline) c_int {
|
||||||
return @bitCast(c_int, @as(c_uint, @clz(c_uint, val)));
|
return @bitCast(c_int, @as(c_uint, @clz(c_uint, val)));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn __builtin_sqrt(val: f64) callconv(.Inline) f64 { return @sqrt(val); }
|
pub fn __builtin_sqrt(val: f64) callconv(.Inline) f64 {
|
||||||
pub fn __builtin_sqrtf(val: f32) callconv(.Inline) f32 { return @sqrt(val); }
|
return @sqrt(val);
|
||||||
|
}
|
||||||
|
pub fn __builtin_sqrtf(val: f32) callconv(.Inline) f32 {
|
||||||
|
return @sqrt(val);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn __builtin_sin(val: f64) callconv(.Inline) f64 { return @sin(val); }
|
pub fn __builtin_sin(val: f64) callconv(.Inline) f64 {
|
||||||
pub fn __builtin_sinf(val: f32) callconv(.Inline) f32 { return @sin(val); }
|
return @sin(val);
|
||||||
pub fn __builtin_cos(val: f64) callconv(.Inline) f64 { return @cos(val); }
|
}
|
||||||
pub fn __builtin_cosf(val: f32) callconv(.Inline) f32 { return @cos(val); }
|
pub fn __builtin_sinf(val: f32) callconv(.Inline) f32 {
|
||||||
|
return @sin(val);
|
||||||
|
}
|
||||||
|
pub fn __builtin_cos(val: f64) callconv(.Inline) f64 {
|
||||||
|
return @cos(val);
|
||||||
|
}
|
||||||
|
pub fn __builtin_cosf(val: f32) callconv(.Inline) f32 {
|
||||||
|
return @cos(val);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn __builtin_exp(val: f64) callconv(.Inline) f64 { return @exp(val); }
|
pub fn __builtin_exp(val: f64) callconv(.Inline) f64 {
|
||||||
pub fn __builtin_expf(val: f32) callconv(.Inline) f32 { return @exp(val); }
|
return @exp(val);
|
||||||
pub fn __builtin_exp2(val: f64) callconv(.Inline) f64 { return @exp2(val); }
|
}
|
||||||
pub fn __builtin_exp2f(val: f32) callconv(.Inline) f32 { return @exp2(val); }
|
pub fn __builtin_expf(val: f32) callconv(.Inline) f32 {
|
||||||
pub fn __builtin_log(val: f64) callconv(.Inline) f64 { return @log(val); }
|
return @exp(val);
|
||||||
pub fn __builtin_logf(val: f32) callconv(.Inline) f32 { return @log(val); }
|
}
|
||||||
pub fn __builtin_log2(val: f64) callconv(.Inline) f64 { return @log2(val); }
|
pub fn __builtin_exp2(val: f64) callconv(.Inline) f64 {
|
||||||
pub fn __builtin_log2f(val: f32) callconv(.Inline) f32 { return @log2(val); }
|
return @exp2(val);
|
||||||
pub fn __builtin_log10(val: f64) callconv(.Inline) f64 { return @log10(val); }
|
}
|
||||||
pub fn __builtin_log10f(val: f32) callconv(.Inline) f32 { return @log10(val); }
|
pub fn __builtin_exp2f(val: f32) callconv(.Inline) f32 {
|
||||||
|
return @exp2(val);
|
||||||
|
}
|
||||||
|
pub fn __builtin_log(val: f64) callconv(.Inline) f64 {
|
||||||
|
return @log(val);
|
||||||
|
}
|
||||||
|
pub fn __builtin_logf(val: f32) callconv(.Inline) f32 {
|
||||||
|
return @log(val);
|
||||||
|
}
|
||||||
|
pub fn __builtin_log2(val: f64) callconv(.Inline) f64 {
|
||||||
|
return @log2(val);
|
||||||
|
}
|
||||||
|
pub fn __builtin_log2f(val: f32) callconv(.Inline) f32 {
|
||||||
|
return @log2(val);
|
||||||
|
}
|
||||||
|
pub fn __builtin_log10(val: f64) callconv(.Inline) f64 {
|
||||||
|
return @log10(val);
|
||||||
|
}
|
||||||
|
pub fn __builtin_log10f(val: f32) callconv(.Inline) f32 {
|
||||||
|
return @log10(val);
|
||||||
|
}
|
||||||
|
|
||||||
// Standard C Library bug: The absolute value of the most negative integer remains negative.
|
// Standard C Library bug: The absolute value of the most negative integer remains negative.
|
||||||
pub fn __builtin_abs(val: c_int) callconv(.Inline) c_int { return std.math.absInt(val) catch std.math.minInt(c_int); }
|
pub fn __builtin_abs(val: c_int) callconv(.Inline) c_int {
|
||||||
pub fn __builtin_fabs(val: f64) callconv(.Inline) f64 { return @fabs(val); }
|
return std.math.absInt(val) catch std.math.minInt(c_int);
|
||||||
pub fn __builtin_fabsf(val: f32) callconv(.Inline) f32 { return @fabs(val); }
|
}
|
||||||
|
pub fn __builtin_fabs(val: f64) callconv(.Inline) f64 {
|
||||||
|
return @fabs(val);
|
||||||
|
}
|
||||||
|
pub fn __builtin_fabsf(val: f32) callconv(.Inline) f32 {
|
||||||
|
return @fabs(val);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn __builtin_floor(val: f64) callconv(.Inline) f64 { return @floor(val); }
|
pub fn __builtin_floor(val: f64) callconv(.Inline) f64 {
|
||||||
pub fn __builtin_floorf(val: f32) callconv(.Inline) f32 { return @floor(val); }
|
return @floor(val);
|
||||||
pub fn __builtin_ceil(val: f64) callconv(.Inline) f64 { return @ceil(val); }
|
}
|
||||||
pub fn __builtin_ceilf(val: f32) callconv(.Inline) f32 { return @ceil(val); }
|
pub fn __builtin_floorf(val: f32) callconv(.Inline) f32 {
|
||||||
pub fn __builtin_trunc(val: f64) callconv(.Inline) f64 { return @trunc(val); }
|
return @floor(val);
|
||||||
pub fn __builtin_truncf(val: f32) callconv(.Inline) f32 { return @trunc(val); }
|
}
|
||||||
pub fn __builtin_round(val: f64) callconv(.Inline) f64 { return @round(val); }
|
pub fn __builtin_ceil(val: f64) callconv(.Inline) f64 {
|
||||||
pub fn __builtin_roundf(val: f32) callconv(.Inline) f32 { return @round(val); }
|
return @ceil(val);
|
||||||
|
}
|
||||||
|
pub fn __builtin_ceilf(val: f32) callconv(.Inline) f32 {
|
||||||
|
return @ceil(val);
|
||||||
|
}
|
||||||
|
pub fn __builtin_trunc(val: f64) callconv(.Inline) f64 {
|
||||||
|
return @trunc(val);
|
||||||
|
}
|
||||||
|
pub fn __builtin_truncf(val: f32) callconv(.Inline) f32 {
|
||||||
|
return @trunc(val);
|
||||||
|
}
|
||||||
|
pub fn __builtin_round(val: f64) callconv(.Inline) f64 {
|
||||||
|
return @round(val);
|
||||||
|
}
|
||||||
|
pub fn __builtin_roundf(val: f32) callconv(.Inline) f32 {
|
||||||
|
return @round(val);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn __builtin_strlen(s: [*c]const u8) callconv(.Inline) usize { return std.mem.lenZ(s); }
|
pub fn __builtin_strlen(s: [*c]const u8) callconv(.Inline) usize {
|
||||||
|
return std.mem.lenZ(s);
|
||||||
|
}
|
||||||
pub fn __builtin_strcmp(s1: [*c]const u8, s2: [*c]const u8) callconv(.Inline) c_int {
|
pub fn __builtin_strcmp(s1: [*c]const u8, s2: [*c]const u8) callconv(.Inline) c_int {
|
||||||
return @as(c_int, std.cstr.cmp(s1, s2));
|
return @as(c_int, std.cstr.cmp(s1, s2));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -300,8 +300,7 @@ const Parser = struct {
|
||||||
try node.initializers.push((try parser.initializer(dr)) orelse return parser.err(.{
|
try node.initializers.push((try parser.initializer(dr)) orelse return parser.err(.{
|
||||||
.ExpectedInitializer = .{ .token = parser.it.index },
|
.ExpectedInitializer = .{ .token = parser.it.index },
|
||||||
}));
|
}));
|
||||||
} else
|
} else try node.initializers.push(&dr.base);
|
||||||
try node.initializers.push(&dr.base);
|
|
||||||
if (parser.eatToken(.Comma) != null) break;
|
if (parser.eatToken(.Comma) != null) break;
|
||||||
dr = @fieldParentPtr(Node.Declarator, "base", (try parser.declarator(.Must)) orelse return parser.err(.{
|
dr = @fieldParentPtr(Node.Declarator, "base", (try parser.declarator(.Must)) orelse return parser.err(.{
|
||||||
.ExpectedDeclarator = .{ .token = parser.it.index },
|
.ExpectedDeclarator = .{ .token = parser.it.index },
|
||||||
|
|
|
||||||
|
|
@ -173,8 +173,7 @@ pub const Coff = struct {
|
||||||
skip_size = 2 * @sizeOf(u8) + 8 * @sizeOf(u16) + 18 * @sizeOf(u32);
|
skip_size = 2 * @sizeOf(u8) + 8 * @sizeOf(u16) + 18 * @sizeOf(u32);
|
||||||
} else if (self.pe_header.magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC) {
|
} else if (self.pe_header.magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC) {
|
||||||
skip_size = 2 * @sizeOf(u8) + 8 * @sizeOf(u16) + 12 * @sizeOf(u32) + 5 * @sizeOf(u64);
|
skip_size = 2 * @sizeOf(u8) + 8 * @sizeOf(u16) + 12 * @sizeOf(u32) + 5 * @sizeOf(u64);
|
||||||
} else
|
} else return error.InvalidPEMagic;
|
||||||
return error.InvalidPEMagic;
|
|
||||||
|
|
||||||
try self.in_file.seekBy(skip_size);
|
try self.in_file.seekBy(skip_size);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -81,8 +81,8 @@ const State128L = struct {
|
||||||
while (i < 7) : (i += 1) {
|
while (i < 7) : (i += 1) {
|
||||||
state.update(tmp, tmp);
|
state.update(tmp, tmp);
|
||||||
}
|
}
|
||||||
return blocks[0].xorBlocks(blocks[1]).xorBlocks(blocks[2]).xorBlocks(blocks[3]).xorBlocks(blocks[4]).
|
return blocks[0].xorBlocks(blocks[1]).xorBlocks(blocks[2]).xorBlocks(blocks[3]).xorBlocks(blocks[4])
|
||||||
xorBlocks(blocks[5]).xorBlocks(blocks[6]).toBytes();
|
.xorBlocks(blocks[5]).xorBlocks(blocks[6]).toBytes();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -244,8 +244,8 @@ const State256 = struct {
|
||||||
while (i < 7) : (i += 1) {
|
while (i < 7) : (i += 1) {
|
||||||
state.update(tmp);
|
state.update(tmp);
|
||||||
}
|
}
|
||||||
return blocks[0].xorBlocks(blocks[1]).xorBlocks(blocks[2]).xorBlocks(blocks[3]).xorBlocks(blocks[4]).
|
return blocks[0].xorBlocks(blocks[1]).xorBlocks(blocks[2]).xorBlocks(blocks[3]).xorBlocks(blocks[4])
|
||||||
xorBlocks(blocks[5]).toBytes();
|
.xorBlocks(blocks[5]).toBytes();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -109,9 +109,7 @@ const State = struct {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const Halves = struct {
|
const Halves = struct { l: u32, r: u32 };
|
||||||
l: u32, r: u32
|
|
||||||
};
|
|
||||||
|
|
||||||
fn feistelF(state: State, x: u32) u32 {
|
fn feistelF(state: State, x: u32) u32 {
|
||||||
var r = state.sboxes[0][@truncate(u8, x >> 24)];
|
var r = state.sboxes[0][@truncate(u8, x >> 24)];
|
||||||
|
|
|
||||||
|
|
@ -213,13 +213,11 @@ const LineNumberProgram = struct {
|
||||||
return error.MissingDebugInfo;
|
return error.MissingDebugInfo;
|
||||||
} else if (self.prev_file - 1 >= self.file_entries.items.len) {
|
} else if (self.prev_file - 1 >= self.file_entries.items.len) {
|
||||||
return error.InvalidDebugInfo;
|
return error.InvalidDebugInfo;
|
||||||
} else
|
} else &self.file_entries.items[self.prev_file - 1];
|
||||||
&self.file_entries.items[self.prev_file - 1];
|
|
||||||
|
|
||||||
const dir_name = if (file_entry.dir_index >= self.include_dirs.len) {
|
const dir_name = if (file_entry.dir_index >= self.include_dirs.len) {
|
||||||
return error.InvalidDebugInfo;
|
return error.InvalidDebugInfo;
|
||||||
} else
|
} else self.include_dirs[file_entry.dir_index];
|
||||||
self.include_dirs[file_entry.dir_index];
|
|
||||||
const file_name = try fs.path.join(self.file_entries.allocator, &[_][]const u8{ dir_name, file_entry.file_name });
|
const file_name = try fs.path.join(self.file_entries.allocator, &[_][]const u8{ dir_name, file_entry.file_name });
|
||||||
errdefer self.file_entries.allocator.free(file_name);
|
errdefer self.file_entries.allocator.free(file_name);
|
||||||
return debug.LineInfo{
|
return debug.LineInfo{
|
||||||
|
|
|
||||||
|
|
@ -98,15 +98,16 @@ pub fn Batch(
|
||||||
/// This function is *not* thread-safe. It must be called from one thread at
|
/// This function is *not* thread-safe. It must be called from one thread at
|
||||||
/// a time, however, it need not be the same thread.
|
/// a time, however, it need not be the same thread.
|
||||||
pub fn wait(self: *Self) CollectedResult {
|
pub fn wait(self: *Self) CollectedResult {
|
||||||
for (self.jobs) |*job| if (job.frame) |f| {
|
for (self.jobs) |*job|
|
||||||
job.result = if (async_ok) await f else nosuspend await f;
|
if (job.frame) |f| {
|
||||||
if (CollectedResult != void) {
|
job.result = if (async_ok) await f else nosuspend await f;
|
||||||
job.result catch |err| {
|
if (CollectedResult != void) {
|
||||||
self.collected_result = err;
|
job.result catch |err| {
|
||||||
};
|
self.collected_result = err;
|
||||||
}
|
};
|
||||||
job.frame = null;
|
}
|
||||||
};
|
job.frame = null;
|
||||||
|
};
|
||||||
return self.collected_result;
|
return self.collected_result;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -646,8 +646,7 @@ pub fn formatIntValue(
|
||||||
const int_value = if (@TypeOf(value) == comptime_int) blk: {
|
const int_value = if (@TypeOf(value) == comptime_int) blk: {
|
||||||
const Int = math.IntFittingRange(value, value);
|
const Int = math.IntFittingRange(value, value);
|
||||||
break :blk @as(Int, value);
|
break :blk @as(Int, value);
|
||||||
} else
|
} else value;
|
||||||
value;
|
|
||||||
|
|
||||||
if (fmt.len == 0 or comptime std.mem.eql(u8, fmt, "d")) {
|
if (fmt.len == 0 or comptime std.mem.eql(u8, fmt, "d")) {
|
||||||
radix = 10;
|
radix = 10;
|
||||||
|
|
@ -1087,8 +1086,7 @@ pub fn formatInt(
|
||||||
const int_value = if (@TypeOf(value) == comptime_int) blk: {
|
const int_value = if (@TypeOf(value) == comptime_int) blk: {
|
||||||
const Int = math.IntFittingRange(value, value);
|
const Int = math.IntFittingRange(value, value);
|
||||||
break :blk @as(Int, value);
|
break :blk @as(Int, value);
|
||||||
} else
|
} else value;
|
||||||
value;
|
|
||||||
|
|
||||||
const value_info = @typeInfo(@TypeOf(int_value)).Int;
|
const value_info = @typeInfo(@TypeOf(int_value)).Int;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,6 @@
|
||||||
// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
|
// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
|
||||||
// The MIT license requires this copyright notice to be included in all copies
|
// The MIT license requires this copyright notice to be included in all copies
|
||||||
// and substantial portions of the software.
|
// and substantial portions of the software.
|
||||||
const std = @import("std.zig");
|
|
||||||
const builtin = std.builtin;
|
|
||||||
const root = @import("root");
|
|
||||||
|
|
||||||
//! std.log is a standardized interface for logging which allows for the logging
|
//! std.log is a standardized interface for logging which allows for the logging
|
||||||
//! of programs and libraries using this interface to be formatted and filtered
|
//! of programs and libraries using this interface to be formatted and filtered
|
||||||
|
|
@ -77,6 +74,10 @@ const root = @import("root");
|
||||||
//! [err] (nice_library): Something went very wrong, sorry
|
//! [err] (nice_library): Something went very wrong, sorry
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
|
const std = @import("std.zig");
|
||||||
|
const builtin = std.builtin;
|
||||||
|
const root = @import("root");
|
||||||
|
|
||||||
pub const Level = enum {
|
pub const Level = enum {
|
||||||
/// Emergency: a condition that cannot be handled, usually followed by a
|
/// Emergency: a condition that cannot be handled, usually followed by a
|
||||||
/// panic.
|
/// panic.
|
||||||
|
|
|
||||||
|
|
@ -534,9 +534,7 @@ pub fn fieldNames(comptime T: type) *const [fields(T).len][]const u8 {
|
||||||
}
|
}
|
||||||
|
|
||||||
test "std.meta.fieldNames" {
|
test "std.meta.fieldNames" {
|
||||||
const E1 = enum {
|
const E1 = enum { A, B };
|
||||||
A, B
|
|
||||||
};
|
|
||||||
const E2 = error{A};
|
const E2 = error{A};
|
||||||
const S1 = struct {
|
const S1 = struct {
|
||||||
a: u8,
|
a: u8,
|
||||||
|
|
@ -1002,19 +1000,19 @@ pub fn sizeof(target: anytype) usize {
|
||||||
// Note: sizeof(void) is 1 on clang/gcc and 0 on MSVC.
|
// Note: sizeof(void) is 1 on clang/gcc and 0 on MSVC.
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
@compileError("Cannot use C sizeof on opaque type "++@typeName(T));
|
@compileError("Cannot use C sizeof on opaque type " ++ @typeName(T));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
.Optional => |opt| {
|
.Optional => |opt| {
|
||||||
if (@typeInfo(opt.child) == .Pointer) {
|
if (@typeInfo(opt.child) == .Pointer) {
|
||||||
return sizeof(opt.child);
|
return sizeof(opt.child);
|
||||||
} else {
|
} else {
|
||||||
@compileError("Cannot use C sizeof on non-pointer optional "++@typeName(T));
|
@compileError("Cannot use C sizeof on non-pointer optional " ++ @typeName(T));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
.Pointer => |ptr| {
|
.Pointer => |ptr| {
|
||||||
if (ptr.size == .Slice) {
|
if (ptr.size == .Slice) {
|
||||||
@compileError("Cannot use C sizeof on slice type "++@typeName(T));
|
@compileError("Cannot use C sizeof on slice type " ++ @typeName(T));
|
||||||
}
|
}
|
||||||
// for strings, sizeof("a") returns 2.
|
// for strings, sizeof("a") returns 2.
|
||||||
// normal pointer decay scenarios from C are handled
|
// normal pointer decay scenarios from C are handled
|
||||||
|
|
@ -1024,8 +1022,9 @@ pub fn sizeof(target: anytype) usize {
|
||||||
if (ptr.size == .One and ptr.is_const and @typeInfo(ptr.child) == .Array) {
|
if (ptr.size == .One and ptr.is_const and @typeInfo(ptr.child) == .Array) {
|
||||||
const array_info = @typeInfo(ptr.child).Array;
|
const array_info = @typeInfo(ptr.child).Array;
|
||||||
if ((array_info.child == u8 or array_info.child == u16) and
|
if ((array_info.child == u8 or array_info.child == u16) and
|
||||||
array_info.sentinel != null and
|
array_info.sentinel != null and
|
||||||
array_info.sentinel.? == 0) {
|
array_info.sentinel.? == 0)
|
||||||
|
{
|
||||||
// length of the string plus one for the null terminator.
|
// length of the string plus one for the null terminator.
|
||||||
return (array_info.len + 1) * @sizeOf(array_info.child);
|
return (array_info.len + 1) * @sizeOf(array_info.child);
|
||||||
}
|
}
|
||||||
|
|
@ -1067,10 +1066,10 @@ test "sizeof" {
|
||||||
|
|
||||||
testing.expect(sizeof(S) == 4);
|
testing.expect(sizeof(S) == 4);
|
||||||
|
|
||||||
testing.expect(sizeof([_]u32{4, 5, 6}) == 12);
|
testing.expect(sizeof([_]u32{ 4, 5, 6 }) == 12);
|
||||||
testing.expect(sizeof([3]u32) == 12);
|
testing.expect(sizeof([3]u32) == 12);
|
||||||
testing.expect(sizeof([3:0]u32) == 16);
|
testing.expect(sizeof([3:0]u32) == 16);
|
||||||
testing.expect(sizeof(&[_]u32{4, 5, 6}) == ptr_size);
|
testing.expect(sizeof(&[_]u32{ 4, 5, 6 }) == ptr_size);
|
||||||
|
|
||||||
testing.expect(sizeof(*u32) == ptr_size);
|
testing.expect(sizeof(*u32) == ptr_size);
|
||||||
testing.expect(sizeof([*]u32) == ptr_size);
|
testing.expect(sizeof([*]u32) == ptr_size);
|
||||||
|
|
@ -1082,7 +1081,7 @@ test "sizeof" {
|
||||||
testing.expect(sizeof(null) == ptr_size);
|
testing.expect(sizeof(null) == ptr_size);
|
||||||
|
|
||||||
testing.expect(sizeof("foobar") == 7);
|
testing.expect(sizeof("foobar") == 7);
|
||||||
testing.expect(sizeof(&[_:0]u16{'f','o','o','b','a','r'}) == 14);
|
testing.expect(sizeof(&[_:0]u16{ 'f', 'o', 'o', 'b', 'a', 'r' }) == 14);
|
||||||
testing.expect(sizeof(*const [4:0]u8) == 5);
|
testing.expect(sizeof(*const [4:0]u8) == 5);
|
||||||
testing.expect(sizeof(*[4:0]u8) == ptr_size);
|
testing.expect(sizeof(*[4:0]u8) == ptr_size);
|
||||||
testing.expect(sizeof([*]const [4:0]u8) == ptr_size);
|
testing.expect(sizeof([*]const [4:0]u8) == ptr_size);
|
||||||
|
|
|
||||||
|
|
@ -544,15 +544,11 @@ test "std.meta.trait.hasUniqueRepresentation" {
|
||||||
|
|
||||||
testing.expect(hasUniqueRepresentation(TestStruct3));
|
testing.expect(hasUniqueRepresentation(TestStruct3));
|
||||||
|
|
||||||
const TestStruct4 = struct {
|
const TestStruct4 = struct { a: []const u8 };
|
||||||
a: []const u8
|
|
||||||
};
|
|
||||||
|
|
||||||
testing.expect(!hasUniqueRepresentation(TestStruct4));
|
testing.expect(!hasUniqueRepresentation(TestStruct4));
|
||||||
|
|
||||||
const TestStruct5 = struct {
|
const TestStruct5 = struct { a: TestStruct4 };
|
||||||
a: TestStruct4
|
|
||||||
};
|
|
||||||
|
|
||||||
testing.expect(!hasUniqueRepresentation(TestStruct5));
|
testing.expect(!hasUniqueRepresentation(TestStruct5));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3263,8 +3263,9 @@ pub fn connect(sock: socket_t, sock_addr: *const sockaddr, len: socklen_t) Conne
|
||||||
.WSAEADDRNOTAVAIL => return error.AddressNotAvailable,
|
.WSAEADDRNOTAVAIL => return error.AddressNotAvailable,
|
||||||
.WSAECONNREFUSED => return error.ConnectionRefused,
|
.WSAECONNREFUSED => return error.ConnectionRefused,
|
||||||
.WSAETIMEDOUT => return error.ConnectionTimedOut,
|
.WSAETIMEDOUT => return error.ConnectionTimedOut,
|
||||||
.WSAEHOSTUNREACH // TODO: should we return NetworkUnreachable in this case as well?
|
.WSAEHOSTUNREACH, // TODO: should we return NetworkUnreachable in this case as well?
|
||||||
, .WSAENETUNREACH => return error.NetworkUnreachable,
|
.WSAENETUNREACH,
|
||||||
|
=> return error.NetworkUnreachable,
|
||||||
.WSAEFAULT => unreachable,
|
.WSAEFAULT => unreachable,
|
||||||
.WSAEINVAL => unreachable,
|
.WSAEINVAL => unreachable,
|
||||||
.WSAEISCONN => unreachable,
|
.WSAEISCONN => unreachable,
|
||||||
|
|
|
||||||
|
|
@ -836,13 +836,15 @@ pub const ucontext_t = extern struct {
|
||||||
sigmask: sigset_t,
|
sigmask: sigset_t,
|
||||||
stack: stack_t,
|
stack: stack_t,
|
||||||
mcontext: mcontext_t,
|
mcontext: mcontext_t,
|
||||||
__pad: [switch (builtin.arch) {
|
__pad: [
|
||||||
.i386 => 4,
|
switch (builtin.arch) {
|
||||||
.mips, .mipsel, .mips64, .mips64el => 14,
|
.i386 => 4,
|
||||||
.arm, .armeb, .thumb, .thumbeb => 1,
|
.mips, .mipsel, .mips64, .mips64el => 14,
|
||||||
.sparc, .sparcel, .sparcv9 => if (@sizeOf(usize) == 4) 43 else 8,
|
.arm, .armeb, .thumb, .thumbeb => 1,
|
||||||
else => 0,
|
.sparc, .sparcel, .sparcv9 => if (@sizeOf(usize) == 4) 43 else 8,
|
||||||
}]u32,
|
else => 0,
|
||||||
|
}
|
||||||
|
]u32,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const EPERM = 1; // Operation not permitted
|
pub const EPERM = 1; // Operation not permitted
|
||||||
|
|
|
||||||
|
|
@ -1315,11 +1315,13 @@ pub const PEB = extern struct {
|
||||||
ImageSubSystemMinorVersion: ULONG,
|
ImageSubSystemMinorVersion: ULONG,
|
||||||
// note: there is padding here on 64 bit
|
// note: there is padding here on 64 bit
|
||||||
ActiveProcessAffinityMask: KAFFINITY,
|
ActiveProcessAffinityMask: KAFFINITY,
|
||||||
GdiHandleBuffer: [switch (@sizeOf(usize)) {
|
GdiHandleBuffer: [
|
||||||
4 => 0x22,
|
switch (@sizeOf(usize)) {
|
||||||
8 => 0x3C,
|
4 => 0x22,
|
||||||
else => unreachable,
|
8 => 0x3C,
|
||||||
}]ULONG,
|
else => unreachable,
|
||||||
|
}
|
||||||
|
]ULONG,
|
||||||
|
|
||||||
// Fields appended in 5.0 (Windows 2000):
|
// Fields appended in 5.0 (Windows 2000):
|
||||||
PostProcessInitRoutine: PVOID,
|
PostProcessInitRoutine: PVOID,
|
||||||
|
|
|
||||||
|
|
@ -66,10 +66,7 @@ pub fn __aeabi_uidivmod() callconv(.Naked) void {
|
||||||
\\ ldr r1, [sp]
|
\\ ldr r1, [sp]
|
||||||
\\ add sp, #4
|
\\ add sp, #4
|
||||||
\\ pop {pc}
|
\\ pop {pc}
|
||||||
:
|
::: "memory");
|
||||||
:
|
|
||||||
: "memory"
|
|
||||||
);
|
|
||||||
unreachable;
|
unreachable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -86,10 +83,7 @@ pub fn __aeabi_uldivmod() callconv(.Naked) void {
|
||||||
\\ ldr r3, [sp, #12]
|
\\ ldr r3, [sp, #12]
|
||||||
\\ add sp, #16
|
\\ add sp, #16
|
||||||
\\ pop {r4, pc}
|
\\ pop {r4, pc}
|
||||||
:
|
::: "memory");
|
||||||
:
|
|
||||||
: "memory"
|
|
||||||
);
|
|
||||||
unreachable;
|
unreachable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -104,10 +98,7 @@ pub fn __aeabi_idivmod() callconv(.Naked) void {
|
||||||
\\ ldr r1, [sp]
|
\\ ldr r1, [sp]
|
||||||
\\ add sp, #4
|
\\ add sp, #4
|
||||||
\\ pop {pc}
|
\\ pop {pc}
|
||||||
:
|
::: "memory");
|
||||||
:
|
|
||||||
: "memory"
|
|
||||||
);
|
|
||||||
unreachable;
|
unreachable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -124,9 +115,6 @@ pub fn __aeabi_ldivmod() callconv(.Naked) void {
|
||||||
\\ ldr r3, [sp, #12]
|
\\ ldr r3, [sp, #12]
|
||||||
\\ add sp, #16
|
\\ add sp, #16
|
||||||
\\ pop {r4, pc}
|
\\ pop {r4, pc}
|
||||||
:
|
::: "memory");
|
||||||
:
|
|
||||||
: "memory"
|
|
||||||
);
|
|
||||||
unreachable;
|
unreachable;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue