Commit ac4d55dec1
Changed files (19)
std/fmt/index.zig
@@ -11,9 +11,7 @@ const max_int_digits = 65;
/// Renders fmt string with args, calling output with slices of bytes.
/// If `output` returns an error, the error is returned from `format` and
/// `output` is not called again.
-pub fn format(context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void,
- comptime fmt: []const u8, args: ...) Errors!void
-{
+pub fn format(context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void, comptime fmt: []const u8, args: ...) Errors!void {
const State = enum {
Start,
OpenBrace,
@@ -221,7 +219,7 @@ pub fn format(context: var, comptime Errors: type, output: fn(@typeOf(context),
}
}
-pub fn formatValue(value: var, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8)Errors!void) Errors!void {
+pub fn formatValue(value: var, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void {
const T = @typeOf(value);
switch (@typeId(T)) {
builtin.TypeId.Int => {
@@ -256,7 +254,7 @@ pub fn formatValue(value: var, context: var, comptime Errors: type, output: fn(@
},
builtin.TypeId.Pointer => {
if (@typeId(T.Child) == builtin.TypeId.Array and T.Child.Child == u8) {
- return output(context, (*value)[0..]);
+ return output(context, (value.*)[0..]);
} else {
return format(context, Errors, output, "{}@{x}", @typeName(T.Child), @ptrToInt(value));
}
@@ -270,13 +268,11 @@ pub fn formatValue(value: var, context: var, comptime Errors: type, output: fn(@
}
}
-pub fn formatAsciiChar(c: u8, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8)Errors!void) Errors!void {
+pub fn formatAsciiChar(c: u8, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void {
return output(context, (&c)[0..1]);
}
-pub fn formatBuf(buf: []const u8, width: usize,
- context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8)Errors!void) Errors!void
-{
+pub fn formatBuf(buf: []const u8, width: usize, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void {
try output(context, buf);
var leftover_padding = if (width > buf.len) (width - buf.len) else return;
@@ -289,7 +285,7 @@ pub fn formatBuf(buf: []const u8, width: usize,
// Print a float in scientific notation to the specified precision. Null uses full precision.
// It should be the case that every full precision, printed value can be re-parsed back to the
// same type unambiguously.
-pub fn formatFloatScientific(value: var, maybe_precision: ?usize, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8)Errors!void) Errors!void {
+pub fn formatFloatScientific(value: var, maybe_precision: ?usize, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void {
var x = f64(value);
// Errol doesn't handle these special cases.
@@ -338,7 +334,7 @@ pub fn formatFloatScientific(value: var, maybe_precision: ?usize, context: var,
var printed: usize = 0;
if (float_decimal.digits.len > 1) {
const num_digits = math.min(float_decimal.digits.len, precision + 1);
- try output(context, float_decimal.digits[1 .. num_digits]);
+ try output(context, float_decimal.digits[1..num_digits]);
printed += num_digits - 1;
}
@@ -350,12 +346,9 @@ pub fn formatFloatScientific(value: var, maybe_precision: ?usize, context: var,
try output(context, float_decimal.digits[0..1]);
try output(context, ".");
if (float_decimal.digits.len > 1) {
- const num_digits = if (@typeOf(value) == f32)
- math.min(usize(9), float_decimal.digits.len)
- else
- float_decimal.digits.len;
+ const num_digits = if (@typeOf(value) == f32) math.min(usize(9), float_decimal.digits.len) else float_decimal.digits.len;
- try output(context, float_decimal.digits[1 .. num_digits]);
+ try output(context, float_decimal.digits[1..num_digits]);
} else {
try output(context, "0");
}
@@ -381,7 +374,7 @@ pub fn formatFloatScientific(value: var, maybe_precision: ?usize, context: var,
// Print a float of the format x.yyyyy where the number of y is specified by the precision argument.
// By default floats are printed at full precision (no rounding).
-pub fn formatFloatDecimal(value: var, maybe_precision: ?usize, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8)Errors!void) Errors!void {
+pub fn formatFloatDecimal(value: var, maybe_precision: ?usize, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void {
var x = f64(value);
// Errol doesn't handle these special cases.
@@ -431,14 +424,14 @@ pub fn formatFloatDecimal(value: var, maybe_precision: ?usize, context: var, com
if (num_digits_whole > 0) {
// We may have to zero pad, for instance 1e4 requires zero padding.
- try output(context, float_decimal.digits[0 .. num_digits_whole_no_pad]);
+ try output(context, float_decimal.digits[0..num_digits_whole_no_pad]);
var i = num_digits_whole_no_pad;
while (i < num_digits_whole) : (i += 1) {
try output(context, "0");
}
} else {
- try output(context , "0");
+ try output(context, "0");
}
// {.0} special case doesn't want a trailing '.'
@@ -470,10 +463,10 @@ pub fn formatFloatDecimal(value: var, maybe_precision: ?usize, context: var, com
// Remaining fractional portion, zero-padding if insufficient.
debug.assert(precision >= printed);
if (num_digits_whole_no_pad + precision - printed < float_decimal.digits.len) {
- try output(context, float_decimal.digits[num_digits_whole_no_pad .. num_digits_whole_no_pad + precision - printed]);
+ try output(context, float_decimal.digits[num_digits_whole_no_pad..num_digits_whole_no_pad + precision - printed]);
return;
} else {
- try output(context, float_decimal.digits[num_digits_whole_no_pad ..]);
+ try output(context, float_decimal.digits[num_digits_whole_no_pad..]);
printed += float_decimal.digits.len - num_digits_whole_no_pad;
while (printed < precision) : (printed += 1) {
@@ -489,14 +482,14 @@ pub fn formatFloatDecimal(value: var, maybe_precision: ?usize, context: var, com
if (num_digits_whole > 0) {
// We may have to zero pad, for instance 1e4 requires zero padding.
- try output(context, float_decimal.digits[0 .. num_digits_whole_no_pad]);
+ try output(context, float_decimal.digits[0..num_digits_whole_no_pad]);
var i = num_digits_whole_no_pad;
while (i < num_digits_whole) : (i += 1) {
try output(context, "0");
}
} else {
- try output(context , "0");
+ try output(context, "0");
}
// Omit `.` if no fractional portion
@@ -516,14 +509,11 @@ pub fn formatFloatDecimal(value: var, maybe_precision: ?usize, context: var, com
}
}
- try output(context, float_decimal.digits[num_digits_whole_no_pad ..]);
+ try output(context, float_decimal.digits[num_digits_whole_no_pad..]);
}
}
-
-pub fn formatInt(value: var, base: u8, uppercase: bool, width: usize,
- context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8)Errors!void) Errors!void
-{
+pub fn formatInt(value: var, base: u8, uppercase: bool, width: usize, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void {
if (@typeOf(value).is_signed) {
return formatIntSigned(value, base, uppercase, width, context, Errors, output);
} else {
@@ -531,9 +521,7 @@ pub fn formatInt(value: var, base: u8, uppercase: bool, width: usize,
}
}
-fn formatIntSigned(value: var, base: u8, uppercase: bool, width: usize,
- context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8)Errors!void) Errors!void
-{
+fn formatIntSigned(value: var, base: u8, uppercase: bool, width: usize, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void {
const uint = @IntType(false, @typeOf(value).bit_count);
if (value < 0) {
const minus_sign: u8 = '-';
@@ -552,9 +540,7 @@ fn formatIntSigned(value: var, base: u8, uppercase: bool, width: usize,
}
}
-fn formatIntUnsigned(value: var, base: u8, uppercase: bool, width: usize,
- context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8)Errors!void) Errors!void
-{
+fn formatIntUnsigned(value: var, base: u8, uppercase: bool, width: usize, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void {
// max_int_digits accounts for the minus sign. when printing an unsigned
// number we don't need to do that.
var buf: [max_int_digits - 1]u8 = undefined;
@@ -566,8 +552,7 @@ fn formatIntUnsigned(value: var, base: u8, uppercase: bool, width: usize,
index -= 1;
buf[index] = digitToChar(u8(digit), uppercase);
a /= base;
- if (a == 0)
- break;
+ if (a == 0) break;
}
const digits_buf = buf[index..];
@@ -579,8 +564,7 @@ fn formatIntUnsigned(value: var, base: u8, uppercase: bool, width: usize,
while (true) {
try output(context, (&zero_byte)[0..1]);
leftover_padding -= 1;
- if (leftover_padding == 0)
- break;
+ if (leftover_padding == 0) break;
}
mem.set(u8, buf[0..index], '0');
return output(context, buf);
@@ -592,7 +576,7 @@ fn formatIntUnsigned(value: var, base: u8, uppercase: bool, width: usize,
}
pub fn formatIntBuf(out_buf: []u8, value: var, base: u8, uppercase: bool, width: usize) usize {
- var context = FormatIntBuf {
+ var context = FormatIntBuf{
.out_buf = out_buf,
.index = 0,
};
@@ -609,10 +593,8 @@ fn formatIntCallback(context: &FormatIntBuf, bytes: []const u8) (error{}!void) {
}
pub fn parseInt(comptime T: type, buf: []const u8, radix: u8) !T {
- if (!T.is_signed)
- return parseUnsigned(T, buf, radix);
- if (buf.len == 0)
- return T(0);
+ if (!T.is_signed) return parseUnsigned(T, buf, radix);
+ if (buf.len == 0) return T(0);
if (buf[0] == '-') {
return math.negate(try parseUnsigned(T, buf[1..], radix));
} else if (buf[0] == '+') {
@@ -632,9 +614,10 @@ test "fmt.parseInt" {
assert(if (parseInt(u8, "256", 10)) |_| false else |err| err == error.Overflow);
}
-const ParseUnsignedError = error {
+const ParseUnsignedError = error{
/// The result cannot fit in the type specified
Overflow,
+
/// The input had a byte that was not a digit
InvalidCharacter,
};
@@ -659,8 +642,7 @@ pub fn charToDigit(c: u8, radix: u8) (error{InvalidCharacter}!u8) {
else => return error.InvalidCharacter,
};
- if (value >= radix)
- return error.InvalidCharacter;
+ if (value >= radix) return error.InvalidCharacter;
return value;
}
@@ -684,20 +666,21 @@ fn bufPrintWrite(context: &BufPrintContext, bytes: []const u8) !void {
}
pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: ...) ![]u8 {
- var context = BufPrintContext { .remaining = buf, };
+ var context = BufPrintContext{ .remaining = buf };
try format(&context, error{BufferTooSmall}, bufPrintWrite, fmt, args);
return buf[0..buf.len - context.remaining.len];
}
pub fn allocPrint(allocator: &mem.Allocator, comptime fmt: []const u8, args: ...) ![]u8 {
var size: usize = 0;
- format(&size, error{}, countSize, fmt, args) catch |err| switch (err) {};
+ format(&size, error{}, countSize, fmt, args) catch |err| switch (err) {
+ };
const buf = try allocator.alloc(u8, size);
return bufPrint(buf, fmt, args);
}
fn countSize(size: &usize, bytes: []const u8) (error{}!void) {
- *size += bytes.len;
+ size.* += bytes.len;
}
test "buf print int" {
@@ -773,9 +756,7 @@ test "fmt.format" {
unused: u8,
};
var buf1: [32]u8 = undefined;
- const value = Struct {
- .unused = 42,
- };
+ const value = Struct{ .unused = 42 };
const result = try bufPrint(buf1[0..], "pointer: {}\n", &value);
assert(mem.startsWith(u8, result, "pointer: Struct@"));
}
@@ -988,7 +969,7 @@ test "fmt.format" {
pub fn trim(buf: []const u8) []const u8 {
var start: usize = 0;
- while (start < buf.len and isWhiteSpace(buf[start])) : (start += 1) { }
+ while (start < buf.len and isWhiteSpace(buf[start])) : (start += 1) {}
var end: usize = buf.len;
while (true) {
@@ -1000,7 +981,6 @@ pub fn trim(buf: []const u8) []const u8 {
}
}
break;
-
}
return buf[start..end];
}
@@ -1015,7 +995,10 @@ test "fmt.trim" {
pub fn isWhiteSpace(byte: u8) bool {
return switch (byte) {
- ' ', '\t', '\n', '\r' => true,
+ ' ',
+ '\t',
+ '\n',
+ '\r' => true,
else => false,
};
}
std/os/linux/index.zig
@@ -30,96 +30,95 @@ pub const FUTEX_PRIVATE_FLAG = 128;
pub const FUTEX_CLOCK_REALTIME = 256;
-
-pub const PROT_NONE = 0;
-pub const PROT_READ = 1;
-pub const PROT_WRITE = 2;
-pub const PROT_EXEC = 4;
+pub const PROT_NONE = 0;
+pub const PROT_READ = 1;
+pub const PROT_WRITE = 2;
+pub const PROT_EXEC = 4;
pub const PROT_GROWSDOWN = 0x01000000;
-pub const PROT_GROWSUP = 0x02000000;
-
-pub const MAP_FAILED = @maxValue(usize);
-pub const MAP_SHARED = 0x01;
-pub const MAP_PRIVATE = 0x02;
-pub const MAP_TYPE = 0x0f;
-pub const MAP_FIXED = 0x10;
-pub const MAP_ANONYMOUS = 0x20;
-pub const MAP_NORESERVE = 0x4000;
-pub const MAP_GROWSDOWN = 0x0100;
-pub const MAP_DENYWRITE = 0x0800;
+pub const PROT_GROWSUP = 0x02000000;
+
+pub const MAP_FAILED = @maxValue(usize);
+pub const MAP_SHARED = 0x01;
+pub const MAP_PRIVATE = 0x02;
+pub const MAP_TYPE = 0x0f;
+pub const MAP_FIXED = 0x10;
+pub const MAP_ANONYMOUS = 0x20;
+pub const MAP_NORESERVE = 0x4000;
+pub const MAP_GROWSDOWN = 0x0100;
+pub const MAP_DENYWRITE = 0x0800;
pub const MAP_EXECUTABLE = 0x1000;
-pub const MAP_LOCKED = 0x2000;
-pub const MAP_POPULATE = 0x8000;
-pub const MAP_NONBLOCK = 0x10000;
-pub const MAP_STACK = 0x20000;
-pub const MAP_HUGETLB = 0x40000;
-pub const MAP_FILE = 0;
+pub const MAP_LOCKED = 0x2000;
+pub const MAP_POPULATE = 0x8000;
+pub const MAP_NONBLOCK = 0x10000;
+pub const MAP_STACK = 0x20000;
+pub const MAP_HUGETLB = 0x40000;
+pub const MAP_FILE = 0;
pub const F_OK = 0;
pub const X_OK = 1;
pub const W_OK = 2;
pub const R_OK = 4;
-pub const WNOHANG = 1;
-pub const WUNTRACED = 2;
-pub const WSTOPPED = 2;
-pub const WEXITED = 4;
+pub const WNOHANG = 1;
+pub const WUNTRACED = 2;
+pub const WSTOPPED = 2;
+pub const WEXITED = 4;
pub const WCONTINUED = 8;
-pub const WNOWAIT = 0x1000000;
-
-pub const SA_NOCLDSTOP = 1;
-pub const SA_NOCLDWAIT = 2;
-pub const SA_SIGINFO = 4;
-pub const SA_ONSTACK = 0x08000000;
-pub const SA_RESTART = 0x10000000;
-pub const SA_NODEFER = 0x40000000;
-pub const SA_RESETHAND = 0x80000000;
-pub const SA_RESTORER = 0x04000000;
-
-pub const SIGHUP = 1;
-pub const SIGINT = 2;
-pub const SIGQUIT = 3;
-pub const SIGILL = 4;
-pub const SIGTRAP = 5;
-pub const SIGABRT = 6;
-pub const SIGIOT = SIGABRT;
-pub const SIGBUS = 7;
-pub const SIGFPE = 8;
-pub const SIGKILL = 9;
-pub const SIGUSR1 = 10;
-pub const SIGSEGV = 11;
-pub const SIGUSR2 = 12;
-pub const SIGPIPE = 13;
-pub const SIGALRM = 14;
-pub const SIGTERM = 15;
+pub const WNOWAIT = 0x1000000;
+
+pub const SA_NOCLDSTOP = 1;
+pub const SA_NOCLDWAIT = 2;
+pub const SA_SIGINFO = 4;
+pub const SA_ONSTACK = 0x08000000;
+pub const SA_RESTART = 0x10000000;
+pub const SA_NODEFER = 0x40000000;
+pub const SA_RESETHAND = 0x80000000;
+pub const SA_RESTORER = 0x04000000;
+
+pub const SIGHUP = 1;
+pub const SIGINT = 2;
+pub const SIGQUIT = 3;
+pub const SIGILL = 4;
+pub const SIGTRAP = 5;
+pub const SIGABRT = 6;
+pub const SIGIOT = SIGABRT;
+pub const SIGBUS = 7;
+pub const SIGFPE = 8;
+pub const SIGKILL = 9;
+pub const SIGUSR1 = 10;
+pub const SIGSEGV = 11;
+pub const SIGUSR2 = 12;
+pub const SIGPIPE = 13;
+pub const SIGALRM = 14;
+pub const SIGTERM = 15;
pub const SIGSTKFLT = 16;
-pub const SIGCHLD = 17;
-pub const SIGCONT = 18;
-pub const SIGSTOP = 19;
-pub const SIGTSTP = 20;
-pub const SIGTTIN = 21;
-pub const SIGTTOU = 22;
-pub const SIGURG = 23;
-pub const SIGXCPU = 24;
-pub const SIGXFSZ = 25;
+pub const SIGCHLD = 17;
+pub const SIGCONT = 18;
+pub const SIGSTOP = 19;
+pub const SIGTSTP = 20;
+pub const SIGTTIN = 21;
+pub const SIGTTOU = 22;
+pub const SIGURG = 23;
+pub const SIGXCPU = 24;
+pub const SIGXFSZ = 25;
pub const SIGVTALRM = 26;
-pub const SIGPROF = 27;
-pub const SIGWINCH = 28;
-pub const SIGIO = 29;
-pub const SIGPOLL = 29;
-pub const SIGPWR = 30;
-pub const SIGSYS = 31;
+pub const SIGPROF = 27;
+pub const SIGWINCH = 28;
+pub const SIGIO = 29;
+pub const SIGPOLL = 29;
+pub const SIGPWR = 30;
+pub const SIGSYS = 31;
pub const SIGUNUSED = SIGSYS;
pub const O_RDONLY = 0o0;
pub const O_WRONLY = 0o1;
-pub const O_RDWR = 0o2;
+pub const O_RDWR = 0o2;
pub const SEEK_SET = 0;
pub const SEEK_CUR = 1;
pub const SEEK_END = 2;
-pub const SIG_BLOCK = 0;
+pub const SIG_BLOCK = 0;
pub const SIG_UNBLOCK = 1;
pub const SIG_SETMASK = 2;
@@ -408,7 +407,6 @@ pub const DT_LNK = 10;
pub const DT_SOCK = 12;
pub const DT_WHT = 14;
-
pub const TCGETS = 0x5401;
pub const TCSETS = 0x5402;
pub const TCSETSW = 0x5403;
@@ -539,23 +537,23 @@ pub const MS_BIND = 4096;
pub const MS_MOVE = 8192;
pub const MS_REC = 16384;
pub const MS_SILENT = 32768;
-pub const MS_POSIXACL = (1<<16);
-pub const MS_UNBINDABLE = (1<<17);
-pub const MS_PRIVATE = (1<<18);
-pub const MS_SLAVE = (1<<19);
-pub const MS_SHARED = (1<<20);
-pub const MS_RELATIME = (1<<21);
-pub const MS_KERNMOUNT = (1<<22);
-pub const MS_I_VERSION = (1<<23);
-pub const MS_STRICTATIME = (1<<24);
-pub const MS_LAZYTIME = (1<<25);
-pub const MS_NOREMOTELOCK = (1<<27);
-pub const MS_NOSEC = (1<<28);
-pub const MS_BORN = (1<<29);
-pub const MS_ACTIVE = (1<<30);
-pub const MS_NOUSER = (1<<31);
-
-pub const MS_RMT_MASK = (MS_RDONLY|MS_SYNCHRONOUS|MS_MANDLOCK|MS_I_VERSION|MS_LAZYTIME);
+pub const MS_POSIXACL = (1 << 16);
+pub const MS_UNBINDABLE = (1 << 17);
+pub const MS_PRIVATE = (1 << 18);
+pub const MS_SLAVE = (1 << 19);
+pub const MS_SHARED = (1 << 20);
+pub const MS_RELATIME = (1 << 21);
+pub const MS_KERNMOUNT = (1 << 22);
+pub const MS_I_VERSION = (1 << 23);
+pub const MS_STRICTATIME = (1 << 24);
+pub const MS_LAZYTIME = (1 << 25);
+pub const MS_NOREMOTELOCK = (1 << 27);
+pub const MS_NOSEC = (1 << 28);
+pub const MS_BORN = (1 << 29);
+pub const MS_ACTIVE = (1 << 30);
+pub const MS_NOUSER = (1 << 31);
+
+pub const MS_RMT_MASK = (MS_RDONLY | MS_SYNCHRONOUS | MS_MANDLOCK | MS_I_VERSION | MS_LAZYTIME);
pub const MS_MGC_VAL = 0xc0ed0000;
pub const MS_MGC_MSK = 0xffff0000;
@@ -565,7 +563,6 @@ pub const MNT_DETACH = 2;
pub const MNT_EXPIRE = 4;
pub const UMOUNT_NOFOLLOW = 8;
-
pub const S_IFMT = 0o170000;
pub const S_IFDIR = 0o040000;
@@ -626,15 +623,30 @@ pub const TFD_CLOEXEC = O_CLOEXEC;
pub const TFD_TIMER_ABSTIME = 1;
pub const TFD_TIMER_CANCEL_ON_SET = (1 << 1);
-fn unsigned(s: i32) u32 { return @bitCast(u32, s); }
-fn signed(s: u32) i32 { return @bitCast(i32, s); }
-pub fn WEXITSTATUS(s: i32) i32 { return signed((unsigned(s) & 0xff00) >> 8); }
-pub fn WTERMSIG(s: i32) i32 { return signed(unsigned(s) & 0x7f); }
-pub fn WSTOPSIG(s: i32) i32 { return WEXITSTATUS(s); }
-pub fn WIFEXITED(s: i32) bool { return WTERMSIG(s) == 0; }
-pub fn WIFSTOPPED(s: i32) bool { return (u16)(((unsigned(s)&0xffff)*%0x10001)>>8) > 0x7f00; }
-pub fn WIFSIGNALED(s: i32) bool { return (unsigned(s)&0xffff)-%1 < 0xff; }
-
+fn unsigned(s: i32) u32 {
+ return @bitCast(u32, s);
+}
+fn signed(s: u32) i32 {
+ return @bitCast(i32, s);
+}
+pub fn WEXITSTATUS(s: i32) i32 {
+ return signed((unsigned(s) & 0xff00) >> 8);
+}
+pub fn WTERMSIG(s: i32) i32 {
+ return signed(unsigned(s) & 0x7f);
+}
+pub fn WSTOPSIG(s: i32) i32 {
+ return WEXITSTATUS(s);
+}
+pub fn WIFEXITED(s: i32) bool {
+ return WTERMSIG(s) == 0;
+}
+pub fn WIFSTOPPED(s: i32) bool {
+ return (u16)(((unsigned(s) & 0xffff) *% 0x10001) >> 8) > 0x7f00;
+}
+pub fn WIFSIGNALED(s: i32) bool {
+ return (unsigned(s) & 0xffff) -% 1 < 0xff;
+}
pub const winsize = extern struct {
ws_row: u16,
@@ -707,8 +719,7 @@ pub fn umount2(special: &const u8, flags: u32) usize {
}
pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: u32, fd: i32, offset: isize) usize {
- return syscall6(SYS_mmap, @ptrToInt(address), length, prot, flags, usize(fd),
- @bitCast(usize, offset));
+ return syscall6(SYS_mmap, @ptrToInt(address), length, prot, flags, usize(fd), @bitCast(usize, offset));
}
pub fn munmap(address: usize, length: usize) usize {
@@ -812,7 +823,8 @@ pub fn clock_gettime(clk_id: i32, tp: ×pec) usize {
if (@ptrToInt(f) != 0) {
const rc = f(clk_id, tp);
switch (rc) {
- 0, @bitCast(usize, isize(-EINVAL)) => return rc,
+ 0,
+ @bitCast(usize, isize(-EINVAL)) => return rc,
else => {},
}
}
@@ -823,8 +835,7 @@ var vdso_clock_gettime = init_vdso_clock_gettime;
extern fn init_vdso_clock_gettime(clk: i32, ts: ×pec) usize {
const addr = vdso.lookup(VDSO_CGT_VER, VDSO_CGT_SYM);
var f = @intToPtr(@typeOf(init_vdso_clock_gettime), addr);
- _ = @cmpxchgStrong(@typeOf(init_vdso_clock_gettime), &vdso_clock_gettime, init_vdso_clock_gettime, f,
- builtin.AtomicOrder.Monotonic, builtin.AtomicOrder.Monotonic);
+ _ = @cmpxchgStrong(@typeOf(init_vdso_clock_gettime), &vdso_clock_gettime, init_vdso_clock_gettime, f, builtin.AtomicOrder.Monotonic, builtin.AtomicOrder.Monotonic);
if (@ptrToInt(f) == 0) return @bitCast(usize, isize(-ENOSYS));
return f(clk, ts);
}
@@ -918,18 +929,18 @@ pub fn getpid() i32 {
}
pub fn sigprocmask(flags: u32, noalias set: &const sigset_t, noalias oldset: ?&sigset_t) usize {
- return syscall4(SYS_rt_sigprocmask, flags, @ptrToInt(set), @ptrToInt(oldset), NSIG/8);
+ return syscall4(SYS_rt_sigprocmask, flags, @ptrToInt(set), @ptrToInt(oldset), NSIG / 8);
}
pub fn sigaction(sig: u6, noalias act: &const Sigaction, noalias oact: ?&Sigaction) usize {
assert(sig >= 1);
assert(sig != SIGKILL);
assert(sig != SIGSTOP);
- var ksa = k_sigaction {
+ var ksa = k_sigaction{
.handler = act.handler,
.flags = act.flags | SA_RESTORER,
.mask = undefined,
- .restorer = @ptrCast(extern fn()void, restore_rt),
+ .restorer = @ptrCast(extern fn() void, restore_rt),
};
var ksa_old: k_sigaction = undefined;
@memcpy(@ptrCast(&u8, &ksa.mask), @ptrCast(&const u8, &act.mask), 8);
@@ -952,22 +963,22 @@ const all_mask = []usize{@maxValue(usize)};
const app_mask = []usize{0xfffffffc7fffffff};
const k_sigaction = extern struct {
- handler: extern fn(i32)void,
+ handler: extern fn(i32) void,
flags: usize,
- restorer: extern fn()void,
+ restorer: extern fn() void,
mask: [2]u32,
};
/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
pub const Sigaction = struct {
- handler: extern fn(i32)void,
+ handler: extern fn(i32) void,
mask: sigset_t,
flags: u32,
};
-pub const SIG_ERR = @intToPtr(extern fn(i32)void, @maxValue(usize));
-pub const SIG_DFL = @intToPtr(extern fn(i32)void, 0);
-pub const SIG_IGN = @intToPtr(extern fn(i32)void, 1);
+pub const SIG_ERR = @intToPtr(extern fn(i32) void, @maxValue(usize));
+pub const SIG_DFL = @intToPtr(extern fn(i32) void, 0);
+pub const SIG_IGN = @intToPtr(extern fn(i32) void, 1);
pub const empty_sigset = []usize{0} ** sigset_t.len;
pub fn raise(sig: i32) usize {
@@ -980,25 +991,25 @@ pub fn raise(sig: i32) usize {
}
fn blockAllSignals(set: &sigset_t) void {
- _ = syscall4(SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&all_mask), @ptrToInt(set), NSIG/8);
+ _ = syscall4(SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&all_mask), @ptrToInt(set), NSIG / 8);
}
fn blockAppSignals(set: &sigset_t) void {
- _ = syscall4(SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&app_mask), @ptrToInt(set), NSIG/8);
+ _ = syscall4(SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&app_mask), @ptrToInt(set), NSIG / 8);
}
fn restoreSignals(set: &sigset_t) void {
- _ = syscall4(SYS_rt_sigprocmask, SIG_SETMASK, @ptrToInt(set), 0, NSIG/8);
+ _ = syscall4(SYS_rt_sigprocmask, SIG_SETMASK, @ptrToInt(set), 0, NSIG / 8);
}
pub fn sigaddset(set: &sigset_t, sig: u6) void {
const s = sig - 1;
- (*set)[usize(s) / usize.bit_count] |= usize(1) << (s & (usize.bit_count - 1));
+ (set.*)[usize(s) / usize.bit_count] |= usize(1) << (s & (usize.bit_count - 1));
}
pub fn sigismember(set: &const sigset_t, sig: u6) bool {
const s = sig - 1;
- return ((*set)[usize(s) / usize.bit_count] & (usize(1) << (s & (usize.bit_count - 1)))) != 0;
+ return ((set.*)[usize(s) / usize.bit_count] & (usize(1) << (s & (usize.bit_count - 1)))) != 0;
}
pub const in_port_t = u16;
@@ -1062,9 +1073,7 @@ pub fn recvmsg(fd: i32, msg: &msghdr, flags: u32) usize {
return syscall3(SYS_recvmsg, usize(fd), @ptrToInt(msg), flags);
}
-pub fn recvfrom(fd: i32, noalias buf: &u8, len: usize, flags: u32,
- noalias addr: ?&sockaddr, noalias alen: ?&socklen_t) usize
-{
+pub fn recvfrom(fd: i32, noalias buf: &u8, len: usize, flags: u32, noalias addr: ?&sockaddr, noalias alen: ?&socklen_t) usize {
return syscall6(SYS_recvfrom, usize(fd), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen));
}
@@ -1132,25 +1141,16 @@ pub fn fgetxattr(fd: usize, name: &const u8, value: &void, size: usize) usize {
return syscall4(SYS_lgetxattr, fd, @ptrToInt(name), @ptrToInt(value), size);
}
-pub fn setxattr(path: &const u8, name: &const u8, value: &const void,
- size: usize, flags: usize) usize {
-
- return syscall5(SYS_setxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value),
- size, flags);
+pub fn setxattr(path: &const u8, name: &const u8, value: &const void, size: usize, flags: usize) usize {
+ return syscall5(SYS_setxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size, flags);
}
-pub fn lsetxattr(path: &const u8, name: &const u8, value: &const void,
- size: usize, flags: usize) usize {
-
- return syscall5(SYS_lsetxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value),
- size, flags);
+pub fn lsetxattr(path: &const u8, name: &const u8, value: &const void, size: usize, flags: usize) usize {
+ return syscall5(SYS_lsetxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size, flags);
}
-pub fn fsetxattr(fd: usize, name: &const u8, value: &const void,
- size: usize, flags: usize) usize {
-
- return syscall5(SYS_fsetxattr, fd, @ptrToInt(name), @ptrToInt(value),
- size, flags);
+pub fn fsetxattr(fd: usize, name: &const u8, value: &const void, size: usize, flags: usize) usize {
+ return syscall5(SYS_fsetxattr, fd, @ptrToInt(name), @ptrToInt(value), size, flags);
}
pub fn removexattr(path: &const u8, name: &const u8) usize {
@@ -1199,7 +1199,7 @@ pub fn timerfd_create(clockid: i32, flags: u32) usize {
pub const itimerspec = extern struct {
it_interval: timespec,
- it_value: timespec
+ it_value: timespec,
};
pub fn timerfd_gettime(fd: i32, curr_value: &itimerspec) usize {
@@ -1211,30 +1211,30 @@ pub fn timerfd_settime(fd: i32, flags: u32, new_value: &const itimerspec, old_va
}
pub const _LINUX_CAPABILITY_VERSION_1 = 0x19980330;
-pub const _LINUX_CAPABILITY_U32S_1 = 1;
+pub const _LINUX_CAPABILITY_U32S_1 = 1;
pub const _LINUX_CAPABILITY_VERSION_2 = 0x20071026;
-pub const _LINUX_CAPABILITY_U32S_2 = 2;
+pub const _LINUX_CAPABILITY_U32S_2 = 2;
pub const _LINUX_CAPABILITY_VERSION_3 = 0x20080522;
-pub const _LINUX_CAPABILITY_U32S_3 = 2;
+pub const _LINUX_CAPABILITY_U32S_3 = 2;
-pub const VFS_CAP_REVISION_MASK = 0xFF000000;
-pub const VFS_CAP_REVISION_SHIFT = 24;
-pub const VFS_CAP_FLAGS_MASK = ~VFS_CAP_REVISION_MASK;
+pub const VFS_CAP_REVISION_MASK = 0xFF000000;
+pub const VFS_CAP_REVISION_SHIFT = 24;
+pub const VFS_CAP_FLAGS_MASK = ~VFS_CAP_REVISION_MASK;
pub const VFS_CAP_FLAGS_EFFECTIVE = 0x000001;
pub const VFS_CAP_REVISION_1 = 0x01000000;
-pub const VFS_CAP_U32_1 = 1;
-pub const XATTR_CAPS_SZ_1 = @sizeOf(u32)*(1 + 2*VFS_CAP_U32_1);
+pub const VFS_CAP_U32_1 = 1;
+pub const XATTR_CAPS_SZ_1 = @sizeOf(u32) * (1 + 2 * VFS_CAP_U32_1);
pub const VFS_CAP_REVISION_2 = 0x02000000;
-pub const VFS_CAP_U32_2 = 2;
-pub const XATTR_CAPS_SZ_2 = @sizeOf(u32)*(1 + 2*VFS_CAP_U32_2);
+pub const VFS_CAP_U32_2 = 2;
+pub const XATTR_CAPS_SZ_2 = @sizeOf(u32) * (1 + 2 * VFS_CAP_U32_2);
-pub const XATTR_CAPS_SZ = XATTR_CAPS_SZ_2;
-pub const VFS_CAP_U32 = VFS_CAP_U32_2;
-pub const VFS_CAP_REVISION = VFS_CAP_REVISION_2;
+pub const XATTR_CAPS_SZ = XATTR_CAPS_SZ_2;
+pub const VFS_CAP_U32 = VFS_CAP_U32_2;
+pub const VFS_CAP_REVISION = VFS_CAP_REVISION_2;
pub const vfs_cap_data = extern struct {
//all of these are mandated as little endian
@@ -1245,49 +1245,48 @@ pub const vfs_cap_data = extern struct {
};
magic_etc: u32,
- data: [VFS_CAP_U32]Data,
+ data: [VFS_CAP_U32]Data,
};
-
-pub const CAP_CHOWN = 0;
-pub const CAP_DAC_OVERRIDE = 1;
-pub const CAP_DAC_READ_SEARCH = 2;
-pub const CAP_FOWNER = 3;
-pub const CAP_FSETID = 4;
-pub const CAP_KILL = 5;
-pub const CAP_SETGID = 6;
-pub const CAP_SETUID = 7;
-pub const CAP_SETPCAP = 8;
-pub const CAP_LINUX_IMMUTABLE = 9;
-pub const CAP_NET_BIND_SERVICE = 10;
-pub const CAP_NET_BROADCAST = 11;
-pub const CAP_NET_ADMIN = 12;
-pub const CAP_NET_RAW = 13;
-pub const CAP_IPC_LOCK = 14;
-pub const CAP_IPC_OWNER = 15;
-pub const CAP_SYS_MODULE = 16;
-pub const CAP_SYS_RAWIO = 17;
-pub const CAP_SYS_CHROOT = 18;
-pub const CAP_SYS_PTRACE = 19;
-pub const CAP_SYS_PACCT = 20;
-pub const CAP_SYS_ADMIN = 21;
-pub const CAP_SYS_BOOT = 22;
-pub const CAP_SYS_NICE = 23;
-pub const CAP_SYS_RESOURCE = 24;
-pub const CAP_SYS_TIME = 25;
-pub const CAP_SYS_TTY_CONFIG = 26;
-pub const CAP_MKNOD = 27;
-pub const CAP_LEASE = 28;
-pub const CAP_AUDIT_WRITE = 29;
-pub const CAP_AUDIT_CONTROL = 30;
-pub const CAP_SETFCAP = 31;
-pub const CAP_MAC_OVERRIDE = 32;
-pub const CAP_MAC_ADMIN = 33;
-pub const CAP_SYSLOG = 34;
-pub const CAP_WAKE_ALARM = 35;
-pub const CAP_BLOCK_SUSPEND = 36;
-pub const CAP_AUDIT_READ = 37;
-pub const CAP_LAST_CAP = CAP_AUDIT_READ;
+pub const CAP_CHOWN = 0;
+pub const CAP_DAC_OVERRIDE = 1;
+pub const CAP_DAC_READ_SEARCH = 2;
+pub const CAP_FOWNER = 3;
+pub const CAP_FSETID = 4;
+pub const CAP_KILL = 5;
+pub const CAP_SETGID = 6;
+pub const CAP_SETUID = 7;
+pub const CAP_SETPCAP = 8;
+pub const CAP_LINUX_IMMUTABLE = 9;
+pub const CAP_NET_BIND_SERVICE = 10;
+pub const CAP_NET_BROADCAST = 11;
+pub const CAP_NET_ADMIN = 12;
+pub const CAP_NET_RAW = 13;
+pub const CAP_IPC_LOCK = 14;
+pub const CAP_IPC_OWNER = 15;
+pub const CAP_SYS_MODULE = 16;
+pub const CAP_SYS_RAWIO = 17;
+pub const CAP_SYS_CHROOT = 18;
+pub const CAP_SYS_PTRACE = 19;
+pub const CAP_SYS_PACCT = 20;
+pub const CAP_SYS_ADMIN = 21;
+pub const CAP_SYS_BOOT = 22;
+pub const CAP_SYS_NICE = 23;
+pub const CAP_SYS_RESOURCE = 24;
+pub const CAP_SYS_TIME = 25;
+pub const CAP_SYS_TTY_CONFIG = 26;
+pub const CAP_MKNOD = 27;
+pub const CAP_LEASE = 28;
+pub const CAP_AUDIT_WRITE = 29;
+pub const CAP_AUDIT_CONTROL = 30;
+pub const CAP_SETFCAP = 31;
+pub const CAP_MAC_OVERRIDE = 32;
+pub const CAP_MAC_ADMIN = 33;
+pub const CAP_SYSLOG = 34;
+pub const CAP_WAKE_ALARM = 35;
+pub const CAP_BLOCK_SUSPEND = 36;
+pub const CAP_AUDIT_READ = 37;
+pub const CAP_LAST_CAP = CAP_AUDIT_READ;
pub fn cap_valid(u8: x) bool {
return x >= 0 and x <= CAP_LAST_CAP;
std/os/index.zig
@@ -137,7 +137,7 @@ pub fn getRandomBytes(buf: []u8) !void {
}
},
Os.zen => {
- const randomness = []u8 {
+ const randomness = []u8{
42,
1,
7,
@@ -265,7 +265,7 @@ pub fn posixRead(fd: i32, buf: []u8) !void {
}
}
-pub const PosixWriteError = error {
+pub const PosixWriteError = error{
WouldBlock,
FileClosed,
DestinationAddressRequired,
@@ -310,7 +310,7 @@ pub fn posixWrite(fd: i32, bytes: []const u8) !void {
}
}
-pub const PosixOpenError = error {
+pub const PosixOpenError = error{
OutOfMemory,
AccessDenied,
FileTooBig,
@@ -477,7 +477,7 @@ pub fn posixExecve(argv: []const []const u8, env_map: &const BufMap, allocator:
return posixExecveErrnoToErr(err);
}
-pub const PosixExecveError = error {
+pub const PosixExecveError = error{
SystemResources,
AccessDenied,
InvalidExe,
@@ -512,7 +512,7 @@ fn posixExecveErrnoToErr(err: usize) PosixExecveError {
};
}
-pub var linux_aux_raw = []usize {0} ** 38;
+pub var linux_aux_raw = []usize{0} ** 38;
pub var posix_environ_raw: []&u8 = undefined;
/// Caller must free result when done.
@@ -667,7 +667,7 @@ pub fn symLink(allocator: &Allocator, existing_path: []const u8, new_path: []con
}
}
-pub const WindowsSymLinkError = error {
+pub const WindowsSymLinkError = error{
OutOfMemory,
Unexpected,
};
@@ -686,7 +686,7 @@ pub fn symLinkWindows(allocator: &Allocator, existing_path: []const u8, new_path
}
}
-pub const PosixSymLinkError = error {
+pub const PosixSymLinkError = error{
OutOfMemory,
AccessDenied,
DiskQuota,
@@ -895,7 +895,7 @@ pub const AtomicFile = struct {
else => return err,
};
- return AtomicFile {
+ return AtomicFile{
.allocator = allocator,
.file = file,
.tmp_path = tmp_path,
@@ -1087,7 +1087,7 @@ pub fn deleteDir(allocator: &Allocator, dir_path: []const u8) !void {
/// removes it. If it cannot be removed because it is a non-empty directory,
/// this function recursively removes its entries and then tries again.
/// TODO non-recursive implementation
-const DeleteTreeError = error {
+const DeleteTreeError = error{
OutOfMemory,
AccessDenied,
FileTooBig,
@@ -1217,7 +1217,7 @@ pub const Dir = struct {
Os.ios => 0,
else => {},
};
- return Dir {
+ return Dir{
.allocator = allocator,
.fd = fd,
.darwin_seek = darwin_seek_init,
@@ -1294,7 +1294,7 @@ pub const Dir = struct {
posix.DT_WHT => Entry.Kind.Whiteout,
else => Entry.Kind.Unknown,
};
- return Entry {
+ return Entry{
.name = name,
.kind = entry_kind,
};
@@ -1355,7 +1355,7 @@ pub const Dir = struct {
posix.DT_SOCK => Entry.Kind.UnixDomainSocket,
else => Entry.Kind.Unknown,
};
- return Entry {
+ return Entry{
.name = name,
.kind = entry_kind,
};
@@ -1465,7 +1465,7 @@ pub fn posix_setregid(rgid: u32, egid: u32) !void {
};
}
-pub const WindowsGetStdHandleErrs = error {
+pub const WindowsGetStdHandleErrs = error{
NoStdHandles,
Unexpected,
};
@@ -1489,7 +1489,7 @@ pub const ArgIteratorPosix = struct {
count: usize,
pub fn init() ArgIteratorPosix {
- return ArgIteratorPosix {
+ return ArgIteratorPosix{
.index = 0,
.count = raw.len,
};
@@ -1522,16 +1522,14 @@ pub const ArgIteratorWindows = struct {
quote_count: usize,
seen_quote_count: usize,
- pub const NextError = error {
- OutOfMemory,
- };
+ pub const NextError = error{OutOfMemory};
pub fn init() ArgIteratorWindows {
return initWithCmdLine(windows.GetCommandLineA());
}
pub fn initWithCmdLine(cmd_line: &const u8) ArgIteratorWindows {
- return ArgIteratorWindows {
+ return ArgIteratorWindows{
.index = 0,
.cmd_line = cmd_line,
.in_quote = false,
@@ -1676,9 +1674,7 @@ pub const ArgIterator = struct {
inner: InnerType,
pub fn init() ArgIterator {
- return ArgIterator {
- .inner = InnerType.init(),
- };
+ return ArgIterator{ .inner = InnerType.init() };
}
pub const NextError = ArgIteratorWindows.NextError;
@@ -1757,33 +1753,33 @@ pub fn argsFree(allocator: &mem.Allocator, args_alloc: []const []u8) void {
}
test "windows arg parsing" {
- testWindowsCmdLine(c"a b\tc d", [][]const u8 {
+ testWindowsCmdLine(c"a b\tc d", [][]const u8{
"a",
"b",
"c",
"d",
});
- testWindowsCmdLine(c"\"abc\" d e", [][]const u8 {
+ testWindowsCmdLine(c"\"abc\" d e", [][]const u8{
"abc",
"d",
"e",
});
- testWindowsCmdLine(c"a\\\\\\b d\"e f\"g h", [][]const u8 {
+ testWindowsCmdLine(c"a\\\\\\b d\"e f\"g h", [][]const u8{
"a\\\\\\b",
"de fg",
"h",
});
- testWindowsCmdLine(c"a\\\\\\\"b c d", [][]const u8 {
+ testWindowsCmdLine(c"a\\\\\\\"b c d", [][]const u8{
"a\\\"b",
"c",
"d",
});
- testWindowsCmdLine(c"a\\\\\\\\\"b c\" d e", [][]const u8 {
+ testWindowsCmdLine(c"a\\\\\\\\\"b c\" d e", [][]const u8{
"a\\\\b c",
"d",
"e",
});
- testWindowsCmdLine(c"a b\tc \"d f", [][]const u8 {
+ testWindowsCmdLine(c"a b\tc \"d f", [][]const u8{
"a",
"b",
"c",
@@ -1791,7 +1787,7 @@ test "windows arg parsing" {
"f",
});
- testWindowsCmdLine(c"\".\\..\\zig-cache\\build\" \"bin\\zig.exe\" \".\\..\" \".\\..\\zig-cache\" \"--help\"", [][]const u8 {
+ testWindowsCmdLine(c"\".\\..\\zig-cache\\build\" \"bin\\zig.exe\" \".\\..\" \".\\..\\zig-cache\" \"--help\"", [][]const u8{
".\\..\\zig-cache\\build",
"bin\\zig.exe",
".\\..",
@@ -1811,7 +1807,7 @@ fn testWindowsCmdLine(input_cmd_line: &const u8, expected_args: []const []const
// TODO make this a build variable that you can set
const unexpected_error_tracing = false;
-const UnexpectedError = error {
+const UnexpectedError = error{
/// The Operating System returned an undocumented error code.
Unexpected,
};
@@ -1950,7 +1946,7 @@ pub fn isTty(handle: FileHandle) bool {
}
}
-pub const PosixSocketError = error {
+pub const PosixSocketError = error{
/// Permission to create a socket of the specified type and/or
/// proโtocol is denied.
PermissionDenied,
@@ -1992,7 +1988,7 @@ pub fn posixSocket(domain: u32, socket_type: u32, protocol: u32) !i32 {
}
}
-pub const PosixBindError = error {
+pub const PosixBindError = error{
/// The address is protected, and the user is not the superuser.
/// For UNIX domain sockets: Search permission is denied on a component
/// of the path prefix.
@@ -2065,7 +2061,7 @@ pub fn posixBind(fd: i32, addr: &const posix.sockaddr) PosixBindError!void {
}
}
-const PosixListenError = error {
+const PosixListenError = error{
/// Another socket is already listening on the same port.
/// For Internet domain sockets, the socket referred to by sockfd had not previously
/// been bound to an address and, upon attempting to bind it to an ephemeral port, it
@@ -2098,7 +2094,7 @@ pub fn posixListen(sockfd: i32, backlog: u32) PosixListenError!void {
}
}
-pub const PosixAcceptError = error {
+pub const PosixAcceptError = error{
/// The socket is marked nonblocking and no connections are present to be accepted.
WouldBlock,
@@ -2165,7 +2161,7 @@ pub fn posixAccept(fd: i32, addr: &posix.sockaddr, flags: u32) PosixAcceptError!
}
}
-pub const LinuxEpollCreateError = error {
+pub const LinuxEpollCreateError = error{
/// Invalid value specified in flags.
InvalidSyscall,
@@ -2198,7 +2194,7 @@ pub fn linuxEpollCreate(flags: u32) LinuxEpollCreateError!i32 {
}
}
-pub const LinuxEpollCtlError = error {
+pub const LinuxEpollCtlError = error{
/// epfd or fd is not a valid file descriptor.
InvalidFileDescriptor,
@@ -2271,7 +2267,7 @@ pub fn linuxEpollWait(epfd: i32, events: []linux.epoll_event, timeout: i32) usiz
}
}
-pub const PosixGetSockNameError = error {
+pub const PosixGetSockNameError = error{
/// Insufficient resources were available in the system to perform the operation.
SystemResources,
@@ -2295,7 +2291,7 @@ pub fn posixGetSockName(sockfd: i32) PosixGetSockNameError!posix.sockaddr {
}
}
-pub const PosixConnectError = error {
+pub const PosixConnectError = error{
/// For UNIX domain sockets, which are identified by pathname: Write permission is denied on the socket
/// file, or search permission is denied for one of the directories in the path prefix.
/// or
@@ -2484,7 +2480,7 @@ pub const Thread = struct {
}
};
-pub const SpawnThreadError = error {
+pub const SpawnThreadError = error{
/// A system-imposed limit on the number of threads was encountered.
/// There are a number of limits that may trigger this error:
/// * the RLIMIT_NPROC soft resource limit (set via setrlimit(2)),
@@ -2532,7 +2528,7 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!&Thread
if (@sizeOf(Context) == 0) {
return startFn({});
} else {
- return startFn(*@ptrCast(&Context, @alignCast(@alignOf(Context), arg)));
+ return startFn(@ptrCast(&Context, @alignCast(@alignOf(Context), arg)).*);
}
}
};
@@ -2562,7 +2558,7 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!&Thread
if (@sizeOf(Context) == 0) {
return startFn({});
} else {
- return startFn(*@intToPtr(&const Context, ctx_addr));
+ return startFn(@intToPtr(&const Context, ctx_addr).*);
}
}
extern fn posixThreadMain(ctx: ?&c_void) ?&c_void {
@@ -2570,7 +2566,7 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!&Thread
_ = startFn({});
return null;
} else {
- _ = startFn(*@ptrCast(&const Context, @alignCast(@alignOf(Context), ctx)));
+ _ = startFn(@ptrCast(&const Context, @alignCast(@alignOf(Context), ctx)).*);
return null;
}
}
@@ -2590,7 +2586,7 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!&Thread
stack_end -= stack_end % @alignOf(Context);
assert(stack_end >= stack_addr);
const context_ptr = @alignCast(@alignOf(Context), @intToPtr(&Context, stack_end));
- *context_ptr = context;
+ context_ptr.* = context;
arg = stack_end;
}
std/special/compiler_rt/fixuint.zig
@@ -36,12 +36,10 @@ pub fn fixuint(comptime fp_t: type, comptime fixuint_t: type, a: fp_t) fixuint_t
const significand: rep_t = (aAbs & significandMask) | implicitBit;
// If either the value or the exponent is negative, the result is zero.
- if (sign == -1 or exponent < 0)
- return 0;
+ if (sign == -1 or exponent < 0) return 0;
// If the value is too large for the integer type, saturate.
- if (c_uint(exponent) >= fixuint_t.bit_count)
- return ~fixuint_t(0);
+ if (c_uint(exponent) >= fixuint_t.bit_count) return ~fixuint_t(0);
// If 0 <= exponent < significandBits, right shift to get the result.
// Otherwise, shift left.
std/special/compiler_rt/fixunsdfdi.zig
@@ -9,4 +9,3 @@ pub extern fn __fixunsdfdi(a: f64) u64 {
test "import fixunsdfdi" {
_ = @import("fixunsdfdi_test.zig");
}
-
std/special/compiler_rt/fixunsdfsi.zig
@@ -9,4 +9,3 @@ pub extern fn __fixunsdfsi(a: f64) u32 {
test "import fixunsdfsi" {
_ = @import("fixunsdfsi_test.zig");
}
-
std/special/compiler_rt/fixunssfti.zig
@@ -9,4 +9,3 @@ pub extern fn __fixunssfti(a: f32) u128 {
test "import fixunssfti" {
_ = @import("fixunssfti_test.zig");
}
-
std/special/compiler_rt/fixunstfti.zig
@@ -9,4 +9,3 @@ pub extern fn __fixunstfti(a: f128) u128 {
test "import fixunstfti" {
_ = @import("fixunstfti_test.zig");
}
-
std/special/compiler_rt/index.zig
@@ -91,9 +91,10 @@ pub fn setXmm0(comptime T: type, value: T) void {
const aligned_value: T align(16) = value;
asm volatile (
\\movaps (%[ptr]), %%xmm0
- :
- : [ptr] "r" (&aligned_value)
- : "xmm0");
+
+ :
+ : [ptr] "r" (&aligned_value)
+ : "xmm0");
}
extern fn __udivdi3(a: u64, b: u64) u64 {
@@ -282,26 +283,27 @@ extern fn __udivmodsi4(a: u32, b: u32, rem: &u32) u32 {
@setRuntimeSafety(is_test);
const d = __udivsi3(a, b);
- *rem = u32(i32(a) -% (i32(d) * i32(b)));
+ rem.* = u32(i32(a) -% (i32(d) * i32(b)));
return d;
}
-
extern fn __udivsi3(n: u32, d: u32) u32 {
@setRuntimeSafety(is_test);
const n_uword_bits: c_uint = u32.bit_count;
// special cases
- if (d == 0)
- return 0; // ?!
- if (n == 0)
- return 0;
+ if (d == 0) return 0; // ?!
+ if (n == 0) return 0;
var sr = @bitCast(c_uint, c_int(@clz(d)) - c_int(@clz(n)));
// 0 <= sr <= n_uword_bits - 1 or sr large
- if (sr > n_uword_bits - 1) // d > r
+ if (sr > n_uword_bits - 1) {
+ // d > r
return 0;
- if (sr == n_uword_bits - 1) // d == 1
+ }
+ if (sr == n_uword_bits - 1) {
+ // d == 1
return n;
+ }
sr += 1;
// 1 <= sr <= n_uword_bits - 1
// Not a special case
@@ -340,139 +342,667 @@ fn test_one_umoddi3(a: u64, b: u64, expected_r: u64) void {
}
test "test_udivsi3" {
- const cases = [][3]u32 {
- []u32{0x00000000, 0x00000001, 0x00000000},
- []u32{0x00000000, 0x00000002, 0x00000000},
- []u32{0x00000000, 0x00000003, 0x00000000},
- []u32{0x00000000, 0x00000010, 0x00000000},
- []u32{0x00000000, 0x078644FA, 0x00000000},
- []u32{0x00000000, 0x0747AE14, 0x00000000},
- []u32{0x00000000, 0x7FFFFFFF, 0x00000000},
- []u32{0x00000000, 0x80000000, 0x00000000},
- []u32{0x00000000, 0xFFFFFFFD, 0x00000000},
- []u32{0x00000000, 0xFFFFFFFE, 0x00000000},
- []u32{0x00000000, 0xFFFFFFFF, 0x00000000},
- []u32{0x00000001, 0x00000001, 0x00000001},
- []u32{0x00000001, 0x00000002, 0x00000000},
- []u32{0x00000001, 0x00000003, 0x00000000},
- []u32{0x00000001, 0x00000010, 0x00000000},
- []u32{0x00000001, 0x078644FA, 0x00000000},
- []u32{0x00000001, 0x0747AE14, 0x00000000},
- []u32{0x00000001, 0x7FFFFFFF, 0x00000000},
- []u32{0x00000001, 0x80000000, 0x00000000},
- []u32{0x00000001, 0xFFFFFFFD, 0x00000000},
- []u32{0x00000001, 0xFFFFFFFE, 0x00000000},
- []u32{0x00000001, 0xFFFFFFFF, 0x00000000},
- []u32{0x00000002, 0x00000001, 0x00000002},
- []u32{0x00000002, 0x00000002, 0x00000001},
- []u32{0x00000002, 0x00000003, 0x00000000},
- []u32{0x00000002, 0x00000010, 0x00000000},
- []u32{0x00000002, 0x078644FA, 0x00000000},
- []u32{0x00000002, 0x0747AE14, 0x00000000},
- []u32{0x00000002, 0x7FFFFFFF, 0x00000000},
- []u32{0x00000002, 0x80000000, 0x00000000},
- []u32{0x00000002, 0xFFFFFFFD, 0x00000000},
- []u32{0x00000002, 0xFFFFFFFE, 0x00000000},
- []u32{0x00000002, 0xFFFFFFFF, 0x00000000},
- []u32{0x00000003, 0x00000001, 0x00000003},
- []u32{0x00000003, 0x00000002, 0x00000001},
- []u32{0x00000003, 0x00000003, 0x00000001},
- []u32{0x00000003, 0x00000010, 0x00000000},
- []u32{0x00000003, 0x078644FA, 0x00000000},
- []u32{0x00000003, 0x0747AE14, 0x00000000},
- []u32{0x00000003, 0x7FFFFFFF, 0x00000000},
- []u32{0x00000003, 0x80000000, 0x00000000},
- []u32{0x00000003, 0xFFFFFFFD, 0x00000000},
- []u32{0x00000003, 0xFFFFFFFE, 0x00000000},
- []u32{0x00000003, 0xFFFFFFFF, 0x00000000},
- []u32{0x00000010, 0x00000001, 0x00000010},
- []u32{0x00000010, 0x00000002, 0x00000008},
- []u32{0x00000010, 0x00000003, 0x00000005},
- []u32{0x00000010, 0x00000010, 0x00000001},
- []u32{0x00000010, 0x078644FA, 0x00000000},
- []u32{0x00000010, 0x0747AE14, 0x00000000},
- []u32{0x00000010, 0x7FFFFFFF, 0x00000000},
- []u32{0x00000010, 0x80000000, 0x00000000},
- []u32{0x00000010, 0xFFFFFFFD, 0x00000000},
- []u32{0x00000010, 0xFFFFFFFE, 0x00000000},
- []u32{0x00000010, 0xFFFFFFFF, 0x00000000},
- []u32{0x078644FA, 0x00000001, 0x078644FA},
- []u32{0x078644FA, 0x00000002, 0x03C3227D},
- []u32{0x078644FA, 0x00000003, 0x028216FE},
- []u32{0x078644FA, 0x00000010, 0x0078644F},
- []u32{0x078644FA, 0x078644FA, 0x00000001},
- []u32{0x078644FA, 0x0747AE14, 0x00000001},
- []u32{0x078644FA, 0x7FFFFFFF, 0x00000000},
- []u32{0x078644FA, 0x80000000, 0x00000000},
- []u32{0x078644FA, 0xFFFFFFFD, 0x00000000},
- []u32{0x078644FA, 0xFFFFFFFE, 0x00000000},
- []u32{0x078644FA, 0xFFFFFFFF, 0x00000000},
- []u32{0x0747AE14, 0x00000001, 0x0747AE14},
- []u32{0x0747AE14, 0x00000002, 0x03A3D70A},
- []u32{0x0747AE14, 0x00000003, 0x026D3A06},
- []u32{0x0747AE14, 0x00000010, 0x00747AE1},
- []u32{0x0747AE14, 0x078644FA, 0x00000000},
- []u32{0x0747AE14, 0x0747AE14, 0x00000001},
- []u32{0x0747AE14, 0x7FFFFFFF, 0x00000000},
- []u32{0x0747AE14, 0x80000000, 0x00000000},
- []u32{0x0747AE14, 0xFFFFFFFD, 0x00000000},
- []u32{0x0747AE14, 0xFFFFFFFE, 0x00000000},
- []u32{0x0747AE14, 0xFFFFFFFF, 0x00000000},
- []u32{0x7FFFFFFF, 0x00000001, 0x7FFFFFFF},
- []u32{0x7FFFFFFF, 0x00000002, 0x3FFFFFFF},
- []u32{0x7FFFFFFF, 0x00000003, 0x2AAAAAAA},
- []u32{0x7FFFFFFF, 0x00000010, 0x07FFFFFF},
- []u32{0x7FFFFFFF, 0x078644FA, 0x00000011},
- []u32{0x7FFFFFFF, 0x0747AE14, 0x00000011},
- []u32{0x7FFFFFFF, 0x7FFFFFFF, 0x00000001},
- []u32{0x7FFFFFFF, 0x80000000, 0x00000000},
- []u32{0x7FFFFFFF, 0xFFFFFFFD, 0x00000000},
- []u32{0x7FFFFFFF, 0xFFFFFFFE, 0x00000000},
- []u32{0x7FFFFFFF, 0xFFFFFFFF, 0x00000000},
- []u32{0x80000000, 0x00000001, 0x80000000},
- []u32{0x80000000, 0x00000002, 0x40000000},
- []u32{0x80000000, 0x00000003, 0x2AAAAAAA},
- []u32{0x80000000, 0x00000010, 0x08000000},
- []u32{0x80000000, 0x078644FA, 0x00000011},
- []u32{0x80000000, 0x0747AE14, 0x00000011},
- []u32{0x80000000, 0x7FFFFFFF, 0x00000001},
- []u32{0x80000000, 0x80000000, 0x00000001},
- []u32{0x80000000, 0xFFFFFFFD, 0x00000000},
- []u32{0x80000000, 0xFFFFFFFE, 0x00000000},
- []u32{0x80000000, 0xFFFFFFFF, 0x00000000},
- []u32{0xFFFFFFFD, 0x00000001, 0xFFFFFFFD},
- []u32{0xFFFFFFFD, 0x00000002, 0x7FFFFFFE},
- []u32{0xFFFFFFFD, 0x00000003, 0x55555554},
- []u32{0xFFFFFFFD, 0x00000010, 0x0FFFFFFF},
- []u32{0xFFFFFFFD, 0x078644FA, 0x00000022},
- []u32{0xFFFFFFFD, 0x0747AE14, 0x00000023},
- []u32{0xFFFFFFFD, 0x7FFFFFFF, 0x00000001},
- []u32{0xFFFFFFFD, 0x80000000, 0x00000001},
- []u32{0xFFFFFFFD, 0xFFFFFFFD, 0x00000001},
- []u32{0xFFFFFFFD, 0xFFFFFFFE, 0x00000000},
- []u32{0xFFFFFFFD, 0xFFFFFFFF, 0x00000000},
- []u32{0xFFFFFFFE, 0x00000001, 0xFFFFFFFE},
- []u32{0xFFFFFFFE, 0x00000002, 0x7FFFFFFF},
- []u32{0xFFFFFFFE, 0x00000003, 0x55555554},
- []u32{0xFFFFFFFE, 0x00000010, 0x0FFFFFFF},
- []u32{0xFFFFFFFE, 0x078644FA, 0x00000022},
- []u32{0xFFFFFFFE, 0x0747AE14, 0x00000023},
- []u32{0xFFFFFFFE, 0x7FFFFFFF, 0x00000002},
- []u32{0xFFFFFFFE, 0x80000000, 0x00000001},
- []u32{0xFFFFFFFE, 0xFFFFFFFD, 0x00000001},
- []u32{0xFFFFFFFE, 0xFFFFFFFE, 0x00000001},
- []u32{0xFFFFFFFE, 0xFFFFFFFF, 0x00000000},
- []u32{0xFFFFFFFF, 0x00000001, 0xFFFFFFFF},
- []u32{0xFFFFFFFF, 0x00000002, 0x7FFFFFFF},
- []u32{0xFFFFFFFF, 0x00000003, 0x55555555},
- []u32{0xFFFFFFFF, 0x00000010, 0x0FFFFFFF},
- []u32{0xFFFFFFFF, 0x078644FA, 0x00000022},
- []u32{0xFFFFFFFF, 0x0747AE14, 0x00000023},
- []u32{0xFFFFFFFF, 0x7FFFFFFF, 0x00000002},
- []u32{0xFFFFFFFF, 0x80000000, 0x00000001},
- []u32{0xFFFFFFFF, 0xFFFFFFFD, 0x00000001},
- []u32{0xFFFFFFFF, 0xFFFFFFFE, 0x00000001},
- []u32{0xFFFFFFFF, 0xFFFFFFFF, 0x00000001},
+ const cases = [][3]u32{
+ []u32{
+ 0x00000000,
+ 0x00000001,
+ 0x00000000,
+ },
+ []u32{
+ 0x00000000,
+ 0x00000002,
+ 0x00000000,
+ },
+ []u32{
+ 0x00000000,
+ 0x00000003,
+ 0x00000000,
+ },
+ []u32{
+ 0x00000000,
+ 0x00000010,
+ 0x00000000,
+ },
+ []u32{
+ 0x00000000,
+ 0x078644FA,
+ 0x00000000,
+ },
+ []u32{
+ 0x00000000,
+ 0x0747AE14,
+ 0x00000000,
+ },
+ []u32{
+ 0x00000000,
+ 0x7FFFFFFF,
+ 0x00000000,
+ },
+ []u32{
+ 0x00000000,
+ 0x80000000,
+ 0x00000000,
+ },
+ []u32{
+ 0x00000000,
+ 0xFFFFFFFD,
+ 0x00000000,
+ },
+ []u32{
+ 0x00000000,
+ 0xFFFFFFFE,
+ 0x00000000,
+ },
+ []u32{
+ 0x00000000,
+ 0xFFFFFFFF,
+ 0x00000000,
+ },
+ []u32{
+ 0x00000001,
+ 0x00000001,
+ 0x00000001,
+ },
+ []u32{
+ 0x00000001,
+ 0x00000002,
+ 0x00000000,
+ },
+ []u32{
+ 0x00000001,
+ 0x00000003,
+ 0x00000000,
+ },
+ []u32{
+ 0x00000001,
+ 0x00000010,
+ 0x00000000,
+ },
+ []u32{
+ 0x00000001,
+ 0x078644FA,
+ 0x00000000,
+ },
+ []u32{
+ 0x00000001,
+ 0x0747AE14,
+ 0x00000000,
+ },
+ []u32{
+ 0x00000001,
+ 0x7FFFFFFF,
+ 0x00000000,
+ },
+ []u32{
+ 0x00000001,
+ 0x80000000,
+ 0x00000000,
+ },
+ []u32{
+ 0x00000001,
+ 0xFFFFFFFD,
+ 0x00000000,
+ },
+ []u32{
+ 0x00000001,
+ 0xFFFFFFFE,
+ 0x00000000,
+ },
+ []u32{
+ 0x00000001,
+ 0xFFFFFFFF,
+ 0x00000000,
+ },
+ []u32{
+ 0x00000002,
+ 0x00000001,
+ 0x00000002,
+ },
+ []u32{
+ 0x00000002,
+ 0x00000002,
+ 0x00000001,
+ },
+ []u32{
+ 0x00000002,
+ 0x00000003,
+ 0x00000000,
+ },
+ []u32{
+ 0x00000002,
+ 0x00000010,
+ 0x00000000,
+ },
+ []u32{
+ 0x00000002,
+ 0x078644FA,
+ 0x00000000,
+ },
+ []u32{
+ 0x00000002,
+ 0x0747AE14,
+ 0x00000000,
+ },
+ []u32{
+ 0x00000002,
+ 0x7FFFFFFF,
+ 0x00000000,
+ },
+ []u32{
+ 0x00000002,
+ 0x80000000,
+ 0x00000000,
+ },
+ []u32{
+ 0x00000002,
+ 0xFFFFFFFD,
+ 0x00000000,
+ },
+ []u32{
+ 0x00000002,
+ 0xFFFFFFFE,
+ 0x00000000,
+ },
+ []u32{
+ 0x00000002,
+ 0xFFFFFFFF,
+ 0x00000000,
+ },
+ []u32{
+ 0x00000003,
+ 0x00000001,
+ 0x00000003,
+ },
+ []u32{
+ 0x00000003,
+ 0x00000002,
+ 0x00000001,
+ },
+ []u32{
+ 0x00000003,
+ 0x00000003,
+ 0x00000001,
+ },
+ []u32{
+ 0x00000003,
+ 0x00000010,
+ 0x00000000,
+ },
+ []u32{
+ 0x00000003,
+ 0x078644FA,
+ 0x00000000,
+ },
+ []u32{
+ 0x00000003,
+ 0x0747AE14,
+ 0x00000000,
+ },
+ []u32{
+ 0x00000003,
+ 0x7FFFFFFF,
+ 0x00000000,
+ },
+ []u32{
+ 0x00000003,
+ 0x80000000,
+ 0x00000000,
+ },
+ []u32{
+ 0x00000003,
+ 0xFFFFFFFD,
+ 0x00000000,
+ },
+ []u32{
+ 0x00000003,
+ 0xFFFFFFFE,
+ 0x00000000,
+ },
+ []u32{
+ 0x00000003,
+ 0xFFFFFFFF,
+ 0x00000000,
+ },
+ []u32{
+ 0x00000010,
+ 0x00000001,
+ 0x00000010,
+ },
+ []u32{
+ 0x00000010,
+ 0x00000002,
+ 0x00000008,
+ },
+ []u32{
+ 0x00000010,
+ 0x00000003,
+ 0x00000005,
+ },
+ []u32{
+ 0x00000010,
+ 0x00000010,
+ 0x00000001,
+ },
+ []u32{
+ 0x00000010,
+ 0x078644FA,
+ 0x00000000,
+ },
+ []u32{
+ 0x00000010,
+ 0x0747AE14,
+ 0x00000000,
+ },
+ []u32{
+ 0x00000010,
+ 0x7FFFFFFF,
+ 0x00000000,
+ },
+ []u32{
+ 0x00000010,
+ 0x80000000,
+ 0x00000000,
+ },
+ []u32{
+ 0x00000010,
+ 0xFFFFFFFD,
+ 0x00000000,
+ },
+ []u32{
+ 0x00000010,
+ 0xFFFFFFFE,
+ 0x00000000,
+ },
+ []u32{
+ 0x00000010,
+ 0xFFFFFFFF,
+ 0x00000000,
+ },
+ []u32{
+ 0x078644FA,
+ 0x00000001,
+ 0x078644FA,
+ },
+ []u32{
+ 0x078644FA,
+ 0x00000002,
+ 0x03C3227D,
+ },
+ []u32{
+ 0x078644FA,
+ 0x00000003,
+ 0x028216FE,
+ },
+ []u32{
+ 0x078644FA,
+ 0x00000010,
+ 0x0078644F,
+ },
+ []u32{
+ 0x078644FA,
+ 0x078644FA,
+ 0x00000001,
+ },
+ []u32{
+ 0x078644FA,
+ 0x0747AE14,
+ 0x00000001,
+ },
+ []u32{
+ 0x078644FA,
+ 0x7FFFFFFF,
+ 0x00000000,
+ },
+ []u32{
+ 0x078644FA,
+ 0x80000000,
+ 0x00000000,
+ },
+ []u32{
+ 0x078644FA,
+ 0xFFFFFFFD,
+ 0x00000000,
+ },
+ []u32{
+ 0x078644FA,
+ 0xFFFFFFFE,
+ 0x00000000,
+ },
+ []u32{
+ 0x078644FA,
+ 0xFFFFFFFF,
+ 0x00000000,
+ },
+ []u32{
+ 0x0747AE14,
+ 0x00000001,
+ 0x0747AE14,
+ },
+ []u32{
+ 0x0747AE14,
+ 0x00000002,
+ 0x03A3D70A,
+ },
+ []u32{
+ 0x0747AE14,
+ 0x00000003,
+ 0x026D3A06,
+ },
+ []u32{
+ 0x0747AE14,
+ 0x00000010,
+ 0x00747AE1,
+ },
+ []u32{
+ 0x0747AE14,
+ 0x078644FA,
+ 0x00000000,
+ },
+ []u32{
+ 0x0747AE14,
+ 0x0747AE14,
+ 0x00000001,
+ },
+ []u32{
+ 0x0747AE14,
+ 0x7FFFFFFF,
+ 0x00000000,
+ },
+ []u32{
+ 0x0747AE14,
+ 0x80000000,
+ 0x00000000,
+ },
+ []u32{
+ 0x0747AE14,
+ 0xFFFFFFFD,
+ 0x00000000,
+ },
+ []u32{
+ 0x0747AE14,
+ 0xFFFFFFFE,
+ 0x00000000,
+ },
+ []u32{
+ 0x0747AE14,
+ 0xFFFFFFFF,
+ 0x00000000,
+ },
+ []u32{
+ 0x7FFFFFFF,
+ 0x00000001,
+ 0x7FFFFFFF,
+ },
+ []u32{
+ 0x7FFFFFFF,
+ 0x00000002,
+ 0x3FFFFFFF,
+ },
+ []u32{
+ 0x7FFFFFFF,
+ 0x00000003,
+ 0x2AAAAAAA,
+ },
+ []u32{
+ 0x7FFFFFFF,
+ 0x00000010,
+ 0x07FFFFFF,
+ },
+ []u32{
+ 0x7FFFFFFF,
+ 0x078644FA,
+ 0x00000011,
+ },
+ []u32{
+ 0x7FFFFFFF,
+ 0x0747AE14,
+ 0x00000011,
+ },
+ []u32{
+ 0x7FFFFFFF,
+ 0x7FFFFFFF,
+ 0x00000001,
+ },
+ []u32{
+ 0x7FFFFFFF,
+ 0x80000000,
+ 0x00000000,
+ },
+ []u32{
+ 0x7FFFFFFF,
+ 0xFFFFFFFD,
+ 0x00000000,
+ },
+ []u32{
+ 0x7FFFFFFF,
+ 0xFFFFFFFE,
+ 0x00000000,
+ },
+ []u32{
+ 0x7FFFFFFF,
+ 0xFFFFFFFF,
+ 0x00000000,
+ },
+ []u32{
+ 0x80000000,
+ 0x00000001,
+ 0x80000000,
+ },
+ []u32{
+ 0x80000000,
+ 0x00000002,
+ 0x40000000,
+ },
+ []u32{
+ 0x80000000,
+ 0x00000003,
+ 0x2AAAAAAA,
+ },
+ []u32{
+ 0x80000000,
+ 0x00000010,
+ 0x08000000,
+ },
+ []u32{
+ 0x80000000,
+ 0x078644FA,
+ 0x00000011,
+ },
+ []u32{
+ 0x80000000,
+ 0x0747AE14,
+ 0x00000011,
+ },
+ []u32{
+ 0x80000000,
+ 0x7FFFFFFF,
+ 0x00000001,
+ },
+ []u32{
+ 0x80000000,
+ 0x80000000,
+ 0x00000001,
+ },
+ []u32{
+ 0x80000000,
+ 0xFFFFFFFD,
+ 0x00000000,
+ },
+ []u32{
+ 0x80000000,
+ 0xFFFFFFFE,
+ 0x00000000,
+ },
+ []u32{
+ 0x80000000,
+ 0xFFFFFFFF,
+ 0x00000000,
+ },
+ []u32{
+ 0xFFFFFFFD,
+ 0x00000001,
+ 0xFFFFFFFD,
+ },
+ []u32{
+ 0xFFFFFFFD,
+ 0x00000002,
+ 0x7FFFFFFE,
+ },
+ []u32{
+ 0xFFFFFFFD,
+ 0x00000003,
+ 0x55555554,
+ },
+ []u32{
+ 0xFFFFFFFD,
+ 0x00000010,
+ 0x0FFFFFFF,
+ },
+ []u32{
+ 0xFFFFFFFD,
+ 0x078644FA,
+ 0x00000022,
+ },
+ []u32{
+ 0xFFFFFFFD,
+ 0x0747AE14,
+ 0x00000023,
+ },
+ []u32{
+ 0xFFFFFFFD,
+ 0x7FFFFFFF,
+ 0x00000001,
+ },
+ []u32{
+ 0xFFFFFFFD,
+ 0x80000000,
+ 0x00000001,
+ },
+ []u32{
+ 0xFFFFFFFD,
+ 0xFFFFFFFD,
+ 0x00000001,
+ },
+ []u32{
+ 0xFFFFFFFD,
+ 0xFFFFFFFE,
+ 0x00000000,
+ },
+ []u32{
+ 0xFFFFFFFD,
+ 0xFFFFFFFF,
+ 0x00000000,
+ },
+ []u32{
+ 0xFFFFFFFE,
+ 0x00000001,
+ 0xFFFFFFFE,
+ },
+ []u32{
+ 0xFFFFFFFE,
+ 0x00000002,
+ 0x7FFFFFFF,
+ },
+ []u32{
+ 0xFFFFFFFE,
+ 0x00000003,
+ 0x55555554,
+ },
+ []u32{
+ 0xFFFFFFFE,
+ 0x00000010,
+ 0x0FFFFFFF,
+ },
+ []u32{
+ 0xFFFFFFFE,
+ 0x078644FA,
+ 0x00000022,
+ },
+ []u32{
+ 0xFFFFFFFE,
+ 0x0747AE14,
+ 0x00000023,
+ },
+ []u32{
+ 0xFFFFFFFE,
+ 0x7FFFFFFF,
+ 0x00000002,
+ },
+ []u32{
+ 0xFFFFFFFE,
+ 0x80000000,
+ 0x00000001,
+ },
+ []u32{
+ 0xFFFFFFFE,
+ 0xFFFFFFFD,
+ 0x00000001,
+ },
+ []u32{
+ 0xFFFFFFFE,
+ 0xFFFFFFFE,
+ 0x00000001,
+ },
+ []u32{
+ 0xFFFFFFFE,
+ 0xFFFFFFFF,
+ 0x00000000,
+ },
+ []u32{
+ 0xFFFFFFFF,
+ 0x00000001,
+ 0xFFFFFFFF,
+ },
+ []u32{
+ 0xFFFFFFFF,
+ 0x00000002,
+ 0x7FFFFFFF,
+ },
+ []u32{
+ 0xFFFFFFFF,
+ 0x00000003,
+ 0x55555555,
+ },
+ []u32{
+ 0xFFFFFFFF,
+ 0x00000010,
+ 0x0FFFFFFF,
+ },
+ []u32{
+ 0xFFFFFFFF,
+ 0x078644FA,
+ 0x00000022,
+ },
+ []u32{
+ 0xFFFFFFFF,
+ 0x0747AE14,
+ 0x00000023,
+ },
+ []u32{
+ 0xFFFFFFFF,
+ 0x7FFFFFFF,
+ 0x00000002,
+ },
+ []u32{
+ 0xFFFFFFFF,
+ 0x80000000,
+ 0x00000001,
+ },
+ []u32{
+ 0xFFFFFFFF,
+ 0xFFFFFFFD,
+ 0x00000001,
+ },
+ []u32{
+ 0xFFFFFFFF,
+ 0xFFFFFFFE,
+ 0x00000001,
+ },
+ []u32{
+ 0xFFFFFFFF,
+ 0xFFFFFFFF,
+ 0x00000001,
+ },
};
for (cases) |case| {
std/special/compiler_rt/udivmod.zig
@@ -1,7 +1,10 @@
const builtin = @import("builtin");
const is_test = builtin.is_test;
-const low = switch (builtin.endian) { builtin.Endian.Big => 1, builtin.Endian.Little => 0 };
+const low = switch (builtin.endian) {
+ builtin.Endian.Big => 1,
+ builtin.Endian.Little => 0,
+};
const high = 1 - low;
pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: ?&DoubleInt) DoubleInt {
@@ -11,8 +14,8 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
const SignedDoubleInt = @IntType(true, DoubleInt.bit_count);
const Log2SingleInt = @import("../../math/index.zig").Log2Int(SingleInt);
- const n = *@ptrCast(&const [2]SingleInt, &a); // TODO issue #421
- const d = *@ptrCast(&const [2]SingleInt, &b); // TODO issue #421
+ const n = @ptrCast(&const [2]SingleInt, &a).*; // TODO issue #421
+ const d = @ptrCast(&const [2]SingleInt, &b).*; // TODO issue #421
var q: [2]SingleInt = undefined;
var r: [2]SingleInt = undefined;
var sr: c_uint = undefined;
@@ -23,7 +26,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
// ---
// 0 X
if (maybe_rem) |rem| {
- *rem = n[low] % d[low];
+ rem.* = n[low] % d[low];
}
return n[low] / d[low];
}
@@ -31,7 +34,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
// ---
// K X
if (maybe_rem) |rem| {
- *rem = n[low];
+ rem.* = n[low];
}
return 0;
}
@@ -42,7 +45,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
// ---
// 0 0
if (maybe_rem) |rem| {
- *rem = n[high] % d[low];
+ rem.* = n[high] % d[low];
}
return n[high] / d[low];
}
@@ -54,7 +57,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
if (maybe_rem) |rem| {
r[high] = n[high] % d[high];
r[low] = 0;
- *rem = *@ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &r[0]); // TODO issue #421
+ rem.* = @ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &r[0]).*; // TODO issue #421
}
return n[high] / d[high];
}
@@ -66,7 +69,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
if (maybe_rem) |rem| {
r[low] = n[low];
r[high] = n[high] & (d[high] - 1);
- *rem = *@ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &r[0]); // TODO issue #421
+ rem.* = @ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &r[0]).*; // TODO issue #421
}
return n[high] >> Log2SingleInt(@ctz(d[high]));
}
@@ -77,7 +80,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
// 0 <= sr <= SingleInt.bit_count - 2 or sr large
if (sr > SingleInt.bit_count - 2) {
if (maybe_rem) |rem| {
- *rem = a;
+ rem.* = a;
}
return 0;
}
@@ -98,7 +101,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
if ((d[low] & (d[low] - 1)) == 0) {
// d is a power of 2
if (maybe_rem) |rem| {
- *rem = n[low] & (d[low] - 1);
+ rem.* = n[low] & (d[low] - 1);
}
if (d[low] == 1) {
return a;
@@ -106,7 +109,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
sr = @ctz(d[low]);
q[high] = n[high] >> Log2SingleInt(sr);
q[low] = (n[high] << Log2SingleInt(SingleInt.bit_count - sr)) | (n[low] >> Log2SingleInt(sr));
- return *@ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &q[0]); // TODO issue #421
+ return @ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &q[0]).*; // TODO issue #421
}
// K X
// ---
@@ -141,7 +144,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
// 0 <= sr <= SingleInt.bit_count - 1 or sr large
if (sr > SingleInt.bit_count - 1) {
if (maybe_rem) |rem| {
- *rem = a;
+ rem.* = a;
}
return 0;
}
@@ -170,25 +173,25 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
var r_all: DoubleInt = undefined;
while (sr > 0) : (sr -= 1) {
// r:q = ((r:q) << 1) | carry
- r[high] = (r[high] << 1) | (r[low] >> (SingleInt.bit_count - 1));
- r[low] = (r[low] << 1) | (q[high] >> (SingleInt.bit_count - 1));
- q[high] = (q[high] << 1) | (q[low] >> (SingleInt.bit_count - 1));
- q[low] = (q[low] << 1) | carry;
+ r[high] = (r[high] << 1) | (r[low] >> (SingleInt.bit_count - 1));
+ r[low] = (r[low] << 1) | (q[high] >> (SingleInt.bit_count - 1));
+ q[high] = (q[high] << 1) | (q[low] >> (SingleInt.bit_count - 1));
+ q[low] = (q[low] << 1) | carry;
// carry = 0;
// if (r.all >= b)
// {
// r.all -= b;
// carry = 1;
// }
- r_all = *@ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &r[0]); // TODO issue #421
+ r_all = @ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &r[0]).*; // TODO issue #421
const s: SignedDoubleInt = SignedDoubleInt(b -% r_all -% 1) >> (DoubleInt.bit_count - 1);
carry = u32(s & 1);
r_all -= b & @bitCast(DoubleInt, s);
- r = *@ptrCast(&[2]SingleInt, &r_all); // TODO issue #421
+ r = @ptrCast(&[2]SingleInt, &r_all).*; // TODO issue #421
}
- const q_all = ((*@ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &q[0])) << 1) | carry; // TODO issue #421
+ const q_all = ((@ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &q[0]).*) << 1) | carry; // TODO issue #421
if (maybe_rem) |rem| {
- *rem = r_all;
+ rem.* = r_all;
}
return q_all;
}
std/special/compiler_rt/udivmodti4.zig
@@ -9,7 +9,7 @@ pub extern fn __udivmodti4(a: u128, b: u128, maybe_rem: ?&u128) u128 {
pub extern fn __udivmodti4_windows_x86_64(a: &const u128, b: &const u128, maybe_rem: ?&u128) void {
@setRuntimeSafety(builtin.is_test);
- compiler_rt.setXmm0(u128, udivmod(u128, *a, *b, maybe_rem));
+ compiler_rt.setXmm0(u128, udivmod(u128, a.*, b.*, maybe_rem));
}
test "import udivmodti4" {
std/special/compiler_rt/umodti3.zig
@@ -11,5 +11,5 @@ pub extern fn __umodti3(a: u128, b: u128) u128 {
pub extern fn __umodti3_windows_x86_64(a: &const u128, b: &const u128) void {
@setRuntimeSafety(builtin.is_test);
- compiler_rt.setXmm0(u128, __umodti3(*a, *b));
+ compiler_rt.setXmm0(u128, __umodti3(a.*, b.*));
}
std/special/bootstrap.zig
@@ -27,10 +27,10 @@ extern fn zen_start() noreturn {
nakedcc fn _start() noreturn {
switch (builtin.arch) {
builtin.Arch.x86_64 => {
- argc_ptr = asm("lea (%%rsp), %[argc]": [argc] "=r" (-> &usize));
+ argc_ptr = asm ("lea (%%rsp), %[argc]" : [argc] "=r" (-> &usize));
},
builtin.Arch.i386 => {
- argc_ptr = asm("lea (%%esp), %[argc]": [argc] "=r" (-> &usize));
+ argc_ptr = asm ("lea (%%esp), %[argc]" : [argc] "=r" (-> &usize));
},
else => @compileError("unsupported arch"),
}
@@ -46,7 +46,7 @@ extern fn WinMainCRTStartup() noreturn {
}
fn posixCallMainAndExit() noreturn {
- const argc = *argc_ptr;
+ const argc = argc_ptr.*;
const argv = @ptrCast(&&u8, &argc_ptr[1]);
const envp_nullable = @ptrCast(&?&u8, &argv[argc + 1]);
var envp_count: usize = 0;
@@ -56,7 +56,7 @@ fn posixCallMainAndExit() noreturn {
const auxv = &@ptrCast(&usize, envp.ptr)[envp_count + 1];
var i: usize = 0;
while (auxv[i] != 0) : (i += 2) {
- if (auxv[i] < std.os.linux_aux_raw.len) std.os.linux_aux_raw[auxv[i]] = auxv[i+1];
+ if (auxv[i] < std.os.linux_aux_raw.len) std.os.linux_aux_raw[auxv[i]] = auxv[i + 1];
}
std.debug.assert(std.os.linux_aux_raw[std.elf.AT_PAGESZ] == std.os.page_size);
}
std/array_list.zig
@@ -8,7 +8,7 @@ pub fn ArrayList(comptime T: type) type {
return AlignedArrayList(T, @alignOf(T));
}
-pub fn AlignedArrayList(comptime T: type, comptime A: u29) type{
+pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
return struct {
const Self = this;
@@ -21,7 +21,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type{
/// Deinitialize with `deinit` or use `toOwnedSlice`.
pub fn init(allocator: &Allocator) Self {
- return Self {
+ return Self{
.items = []align(A) T{},
.len = 0,
.allocator = allocator,
@@ -48,7 +48,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type{
/// allocated with `allocator`.
/// Deinitialize with `deinit` or use `toOwnedSlice`.
pub fn fromOwnedSlice(allocator: &Allocator, slice: []align(A) T) Self {
- return Self {
+ return Self{
.items = slice,
.len = slice.len,
.allocator = allocator,
@@ -59,7 +59,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type{
pub fn toOwnedSlice(self: &Self) []align(A) T {
const allocator = self.allocator;
const result = allocator.alignedShrink(T, A, self.items, self.len);
- *self = init(allocator);
+ self.* = init(allocator);
return result;
}
@@ -67,21 +67,21 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type{
try l.ensureCapacity(l.len + 1);
l.len += 1;
- mem.copy(T, l.items[n+1..l.len], l.items[n..l.len-1]);
- l.items[n] = *item;
+ mem.copy(T, l.items[n + 1..l.len], l.items[n..l.len - 1]);
+ l.items[n] = item.*;
}
pub fn insertSlice(l: &Self, n: usize, items: []align(A) const T) !void {
try l.ensureCapacity(l.len + items.len);
l.len += items.len;
- mem.copy(T, l.items[n+items.len..l.len], l.items[n..l.len-items.len]);
- mem.copy(T, l.items[n..n+items.len], items);
+ mem.copy(T, l.items[n + items.len..l.len], l.items[n..l.len - items.len]);
+ mem.copy(T, l.items[n..n + items.len], items);
}
pub fn append(l: &Self, item: &const T) !void {
const new_item_ptr = try l.addOne();
- *new_item_ptr = *item;
+ new_item_ptr.* = item.*;
}
pub fn appendSlice(l: &Self, items: []align(A) const T) !void {
@@ -124,8 +124,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type{
}
pub fn popOrNull(self: &Self) ?T {
- if (self.len == 0)
- return null;
+ if (self.len == 0) return null;
return self.pop();
}
};
@@ -135,25 +134,35 @@ test "basic ArrayList test" {
var list = ArrayList(i32).init(debug.global_allocator);
defer list.deinit();
- {var i: usize = 0; while (i < 10) : (i += 1) {
- list.append(i32(i + 1)) catch unreachable;
- }}
+ {
+ var i: usize = 0;
+ while (i < 10) : (i += 1) {
+ list.append(i32(i + 1)) catch unreachable;
+ }
+ }
- {var i: usize = 0; while (i < 10) : (i += 1) {
- assert(list.items[i] == i32(i + 1));
- }}
+ {
+ var i: usize = 0;
+ while (i < 10) : (i += 1) {
+ assert(list.items[i] == i32(i + 1));
+ }
+ }
assert(list.pop() == 10);
assert(list.len == 9);
- list.appendSlice([]const i32 { 1, 2, 3 }) catch unreachable;
+ list.appendSlice([]const i32{
+ 1,
+ 2,
+ 3,
+ }) catch unreachable;
assert(list.len == 12);
assert(list.pop() == 3);
assert(list.pop() == 2);
assert(list.pop() == 1);
assert(list.len == 9);
- list.appendSlice([]const i32 {}) catch unreachable;
+ list.appendSlice([]const i32{}) catch unreachable;
assert(list.len == 9);
}
@@ -166,12 +175,15 @@ test "insert ArrayList test" {
assert(list.items[0] == 5);
assert(list.items[1] == 1);
- try list.insertSlice(1, []const i32 { 9, 8 });
+ try list.insertSlice(1, []const i32{
+ 9,
+ 8,
+ });
assert(list.items[0] == 5);
assert(list.items[1] == 9);
assert(list.items[2] == 8);
- const items = []const i32 { 1 };
+ const items = []const i32{1};
try list.insertSlice(0, items[0..0]);
assert(list.items[0] == 5);
}
std/heap.zig
@@ -10,7 +10,7 @@ const c = std.c;
const Allocator = mem.Allocator;
pub const c_allocator = &c_allocator_state;
-var c_allocator_state = Allocator {
+var c_allocator_state = Allocator{
.allocFn = cAlloc,
.reallocFn = cRealloc,
.freeFn = cFree,
@@ -18,10 +18,7 @@ var c_allocator_state = Allocator {
fn cAlloc(self: &Allocator, n: usize, alignment: u29) ![]u8 {
assert(alignment <= @alignOf(c_longdouble));
- return if (c.malloc(n)) |buf|
- @ptrCast(&u8, buf)[0..n]
- else
- error.OutOfMemory;
+ return if (c.malloc(n)) |buf| @ptrCast(&u8, buf)[0..n] else error.OutOfMemory;
}
fn cRealloc(self: &Allocator, old_mem: []u8, new_size: usize, alignment: u29) ![]u8 {
@@ -48,8 +45,8 @@ pub const DirectAllocator = struct {
const HeapHandle = if (builtin.os == Os.windows) os.windows.HANDLE else void;
pub fn init() DirectAllocator {
- return DirectAllocator {
- .allocator = Allocator {
+ return DirectAllocator{
+ .allocator = Allocator{
.allocFn = alloc,
.reallocFn = realloc,
.freeFn = free,
@@ -71,39 +68,39 @@ pub const DirectAllocator = struct {
const self = @fieldParentPtr(DirectAllocator, "allocator", allocator);
switch (builtin.os) {
- Os.linux, Os.macosx, Os.ios => {
+ Os.linux,
+ Os.macosx,
+ Os.ios => {
const p = os.posix;
- const alloc_size = if(alignment <= os.page_size) n else n + alignment;
- const addr = p.mmap(null, alloc_size, p.PROT_READ|p.PROT_WRITE,
- p.MAP_PRIVATE|p.MAP_ANONYMOUS, -1, 0);
- if(addr == p.MAP_FAILED) return error.OutOfMemory;
-
- if(alloc_size == n) return @intToPtr(&u8, addr)[0..n];
-
+ const alloc_size = if (alignment <= os.page_size) n else n + alignment;
+ const addr = p.mmap(null, alloc_size, p.PROT_READ | p.PROT_WRITE, p.MAP_PRIVATE | p.MAP_ANONYMOUS, -1, 0);
+ if (addr == p.MAP_FAILED) return error.OutOfMemory;
+
+ if (alloc_size == n) return @intToPtr(&u8, addr)[0..n];
+
var aligned_addr = addr & ~usize(alignment - 1);
aligned_addr += alignment;
-
+
//We can unmap the unused portions of our mmap, but we must only
// pass munmap bytes that exist outside our allocated pages or it
// will happily eat us too
-
+
//Since alignment > page_size, we are by definition on a page boundry
const unused_start = addr;
const unused_len = aligned_addr - 1 - unused_start;
var err = p.munmap(unused_start, unused_len);
debug.assert(p.getErrno(err) == 0);
-
+
//It is impossible that there is an unoccupied page at the top of our
// mmap.
-
+
return @intToPtr(&u8, aligned_addr)[0..n];
},
Os.windows => {
const amt = n + alignment + @sizeOf(usize);
const heap_handle = self.heap_handle ?? blk: {
- const hh = os.windows.HeapCreate(os.windows.HEAP_NO_SERIALIZE, amt, 0)
- ?? return error.OutOfMemory;
+ const hh = os.windows.HeapCreate(os.windows.HEAP_NO_SERIALIZE, amt, 0) ?? return error.OutOfMemory;
self.heap_handle = hh;
break :blk hh;
};
@@ -113,7 +110,7 @@ pub const DirectAllocator = struct {
const march_forward_bytes = if (rem == 0) 0 else (alignment - rem);
const adjusted_addr = root_addr + march_forward_bytes;
const record_addr = adjusted_addr + n;
- *@intToPtr(&align(1) usize, record_addr) = root_addr;
+ @intToPtr(&align(1) usize, record_addr).* = root_addr;
return @intToPtr(&u8, adjusted_addr)[0..n];
},
else => @compileError("Unsupported OS"),
@@ -124,7 +121,9 @@ pub const DirectAllocator = struct {
const self = @fieldParentPtr(DirectAllocator, "allocator", allocator);
switch (builtin.os) {
- Os.linux, Os.macosx, Os.ios => {
+ Os.linux,
+ Os.macosx,
+ Os.ios => {
if (new_size <= old_mem.len) {
const base_addr = @ptrToInt(old_mem.ptr);
const old_addr_end = base_addr + old_mem.len;
@@ -144,13 +143,13 @@ pub const DirectAllocator = struct {
Os.windows => {
const old_adjusted_addr = @ptrToInt(old_mem.ptr);
const old_record_addr = old_adjusted_addr + old_mem.len;
- const root_addr = *@intToPtr(&align(1) usize, old_record_addr);
+ const root_addr = @intToPtr(&align(1) usize, old_record_addr).*;
const old_ptr = @intToPtr(os.windows.LPVOID, root_addr);
const amt = new_size + alignment + @sizeOf(usize);
const new_ptr = os.windows.HeapReAlloc(??self.heap_handle, 0, old_ptr, amt) ?? blk: {
if (new_size > old_mem.len) return error.OutOfMemory;
const new_record_addr = old_record_addr - new_size + old_mem.len;
- *@intToPtr(&align(1) usize, new_record_addr) = root_addr;
+ @intToPtr(&align(1) usize, new_record_addr).* = root_addr;
return old_mem[0..new_size];
};
const offset = old_adjusted_addr - root_addr;
@@ -158,7 +157,7 @@ pub const DirectAllocator = struct {
const new_adjusted_addr = new_root_addr + offset;
assert(new_adjusted_addr % alignment == 0);
const new_record_addr = new_adjusted_addr + new_size;
- *@intToPtr(&align(1) usize, new_record_addr) = new_root_addr;
+ @intToPtr(&align(1) usize, new_record_addr).* = new_root_addr;
return @intToPtr(&u8, new_adjusted_addr)[0..new_size];
},
else => @compileError("Unsupported OS"),
@@ -169,12 +168,14 @@ pub const DirectAllocator = struct {
const self = @fieldParentPtr(DirectAllocator, "allocator", allocator);
switch (builtin.os) {
- Os.linux, Os.macosx, Os.ios => {
+ Os.linux,
+ Os.macosx,
+ Os.ios => {
_ = os.posix.munmap(@ptrToInt(bytes.ptr), bytes.len);
},
Os.windows => {
const record_addr = @ptrToInt(bytes.ptr) + bytes.len;
- const root_addr = *@intToPtr(&align(1) usize, record_addr);
+ const root_addr = @intToPtr(&align(1) usize, record_addr).*;
const ptr = @intToPtr(os.windows.LPVOID, root_addr);
_ = os.windows.HeapFree(??self.heap_handle, 0, ptr);
},
@@ -195,8 +196,8 @@ pub const ArenaAllocator = struct {
const BufNode = std.LinkedList([]u8).Node;
pub fn init(child_allocator: &Allocator) ArenaAllocator {
- return ArenaAllocator {
- .allocator = Allocator {
+ return ArenaAllocator{
+ .allocator = Allocator{
.allocFn = alloc,
.reallocFn = realloc,
.freeFn = free,
@@ -228,7 +229,7 @@ pub const ArenaAllocator = struct {
const buf = try self.child_allocator.alignedAlloc(u8, @alignOf(BufNode), len);
const buf_node_slice = ([]BufNode)(buf[0..@sizeOf(BufNode)]);
const buf_node = &buf_node_slice[0];
- *buf_node = BufNode {
+ buf_node.* = BufNode{
.data = buf,
.prev = null,
.next = null,
@@ -253,7 +254,7 @@ pub const ArenaAllocator = struct {
cur_node = try self.createNode(cur_buf.len, n + alignment);
continue;
}
- const result = cur_buf[adjusted_index .. new_end_index];
+ const result = cur_buf[adjusted_index..new_end_index];
self.end_index = new_end_index;
return result;
}
@@ -269,7 +270,7 @@ pub const ArenaAllocator = struct {
}
}
- fn free(allocator: &Allocator, bytes: []u8) void { }
+ fn free(allocator: &Allocator, bytes: []u8) void {}
};
pub const FixedBufferAllocator = struct {
@@ -278,8 +279,8 @@ pub const FixedBufferAllocator = struct {
buffer: []u8,
pub fn init(buffer: []u8) FixedBufferAllocator {
- return FixedBufferAllocator {
- .allocator = Allocator {
+ return FixedBufferAllocator{
+ .allocator = Allocator{
.allocFn = alloc,
.reallocFn = realloc,
.freeFn = free,
@@ -299,7 +300,7 @@ pub const FixedBufferAllocator = struct {
if (new_end_index > self.buffer.len) {
return error.OutOfMemory;
}
- const result = self.buffer[adjusted_index .. new_end_index];
+ const result = self.buffer[adjusted_index..new_end_index];
self.end_index = new_end_index;
return result;
@@ -315,7 +316,7 @@ pub const FixedBufferAllocator = struct {
}
}
- fn free(allocator: &Allocator, bytes: []u8) void { }
+ fn free(allocator: &Allocator, bytes: []u8) void {}
};
/// lock free
@@ -325,8 +326,8 @@ pub const ThreadSafeFixedBufferAllocator = struct {
buffer: []u8,
pub fn init(buffer: []u8) ThreadSafeFixedBufferAllocator {
- return ThreadSafeFixedBufferAllocator {
- .allocator = Allocator {
+ return ThreadSafeFixedBufferAllocator{
+ .allocator = Allocator{
.allocFn = alloc,
.reallocFn = realloc,
.freeFn = free,
@@ -348,8 +349,7 @@ pub const ThreadSafeFixedBufferAllocator = struct {
if (new_end_index > self.buffer.len) {
return error.OutOfMemory;
}
- end_index = @cmpxchgWeak(usize, &self.end_index, end_index, new_end_index,
- builtin.AtomicOrder.SeqCst, builtin.AtomicOrder.SeqCst) ?? return self.buffer[adjusted_index .. new_end_index];
+ end_index = @cmpxchgWeak(usize, &self.end_index, end_index, new_end_index, builtin.AtomicOrder.SeqCst, builtin.AtomicOrder.SeqCst) ?? return self.buffer[adjusted_index..new_end_index];
}
}
@@ -363,11 +363,9 @@ pub const ThreadSafeFixedBufferAllocator = struct {
}
}
- fn free(allocator: &Allocator, bytes: []u8) void { }
+ fn free(allocator: &Allocator, bytes: []u8) void {}
};
-
-
test "c_allocator" {
if (builtin.link_libc) {
var slice = c_allocator.alloc(u8, 50) catch return;
@@ -415,8 +413,8 @@ fn testAllocator(allocator: &mem.Allocator) !void {
var slice = try allocator.alloc(&i32, 100);
for (slice) |*item, i| {
- *item = try allocator.create(i32);
- **item = i32(i);
+ item.* = try allocator.create(i32);
+ item.*.* = i32(i);
}
for (slice) |item, i| {
@@ -434,26 +432,26 @@ fn testAllocator(allocator: &mem.Allocator) !void {
fn testAllocatorLargeAlignment(allocator: &mem.Allocator) mem.Allocator.Error!void {
//Maybe a platform's page_size is actually the same as or
// very near usize?
- if(os.page_size << 2 > @maxValue(usize)) return;
-
+ if (os.page_size << 2 > @maxValue(usize)) return;
+
const USizeShift = @IntType(false, std.math.log2(usize.bit_count));
const large_align = u29(os.page_size << 2);
-
+
var align_mask: usize = undefined;
_ = @shlWithOverflow(usize, ~usize(0), USizeShift(@ctz(large_align)), &align_mask);
-
+
var slice = try allocator.allocFn(allocator, 500, large_align);
debug.assert(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
-
+
slice = try allocator.reallocFn(allocator, slice, 100, large_align);
debug.assert(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
-
+
slice = try allocator.reallocFn(allocator, slice, 5000, large_align);
debug.assert(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
-
+
slice = try allocator.reallocFn(allocator, slice, 10, large_align);
debug.assert(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
-
+
slice = try allocator.reallocFn(allocator, slice, 20000, large_align);
debug.assert(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
std/io.zig
@@ -18,32 +18,17 @@ const is_windows = builtin.os == builtin.Os.windows;
const GetStdIoErrs = os.WindowsGetStdHandleErrs;
pub fn getStdErr() GetStdIoErrs!File {
- const handle = if (is_windows)
- try os.windowsGetStdHandle(os.windows.STD_ERROR_HANDLE)
- else if (is_posix)
- os.posix.STDERR_FILENO
- else
- unreachable;
+ const handle = if (is_windows) try os.windowsGetStdHandle(os.windows.STD_ERROR_HANDLE) else if (is_posix) os.posix.STDERR_FILENO else unreachable;
return File.openHandle(handle);
}
pub fn getStdOut() GetStdIoErrs!File {
- const handle = if (is_windows)
- try os.windowsGetStdHandle(os.windows.STD_OUTPUT_HANDLE)
- else if (is_posix)
- os.posix.STDOUT_FILENO
- else
- unreachable;
+ const handle = if (is_windows) try os.windowsGetStdHandle(os.windows.STD_OUTPUT_HANDLE) else if (is_posix) os.posix.STDOUT_FILENO else unreachable;
return File.openHandle(handle);
}
pub fn getStdIn() GetStdIoErrs!File {
- const handle = if (is_windows)
- try os.windowsGetStdHandle(os.windows.STD_INPUT_HANDLE)
- else if (is_posix)
- os.posix.STDIN_FILENO
- else
- unreachable;
+ const handle = if (is_windows) try os.windowsGetStdHandle(os.windows.STD_INPUT_HANDLE) else if (is_posix) os.posix.STDIN_FILENO else unreachable;
return File.openHandle(handle);
}
@@ -56,11 +41,9 @@ pub const FileInStream = struct {
pub const Stream = InStream(Error);
pub fn init(file: &File) FileInStream {
- return FileInStream {
+ return FileInStream{
.file = file,
- .stream = Stream {
- .readFn = readFn,
- },
+ .stream = Stream{ .readFn = readFn },
};
}
@@ -79,11 +62,9 @@ pub const FileOutStream = struct {
pub const Stream = OutStream(Error);
pub fn init(file: &File) FileOutStream {
- return FileOutStream {
+ return FileOutStream{
.file = file,
- .stream = Stream {
- .writeFn = writeFn,
- },
+ .stream = Stream{ .writeFn = writeFn },
};
}
@@ -121,8 +102,7 @@ pub fn InStream(comptime ReadError: type) type {
}
const new_buf_size = math.min(max_size, actual_buf_len + os.page_size);
- if (new_buf_size == actual_buf_len)
- return error.StreamTooLong;
+ if (new_buf_size == actual_buf_len) return error.StreamTooLong;
try buffer.resize(new_buf_size);
}
}
@@ -165,9 +145,7 @@ pub fn InStream(comptime ReadError: type) type {
/// memory would be greater than `max_size`, returns `error.StreamTooLong`.
/// Caller owns returned memory.
/// If this function returns an error, the contents from the stream read so far are lost.
- pub fn readUntilDelimiterAlloc(self: &Self, allocator: &mem.Allocator,
- delimiter: u8, max_size: usize) ![]u8
- {
+ pub fn readUntilDelimiterAlloc(self: &Self, allocator: &mem.Allocator, delimiter: u8, max_size: usize) ![]u8 {
var buf = Buffer.initNull(allocator);
defer buf.deinit();
@@ -283,7 +261,7 @@ pub fn BufferedInStream(comptime Error: type) type {
pub fn BufferedInStreamCustom(comptime buffer_size: usize, comptime Error: type) type {
return struct {
const Self = this;
- const Stream = InStream(Error);
+ const Stream = InStream(Error);
pub stream: Stream,
@@ -294,7 +272,7 @@ pub fn BufferedInStreamCustom(comptime buffer_size: usize, comptime Error: type)
end_index: usize,
pub fn init(unbuffered_in_stream: &Stream) Self {
- return Self {
+ return Self{
.unbuffered_in_stream = unbuffered_in_stream,
.buffer = undefined,
@@ -305,9 +283,7 @@ pub fn BufferedInStreamCustom(comptime buffer_size: usize, comptime Error: type)
.start_index = buffer_size,
.end_index = buffer_size,
- .stream = Stream {
- .readFn = readFn,
- },
+ .stream = Stream{ .readFn = readFn },
};
}
@@ -368,13 +344,11 @@ pub fn BufferedOutStreamCustom(comptime buffer_size: usize, comptime OutStreamEr
index: usize,
pub fn init(unbuffered_out_stream: &Stream) Self {
- return Self {
+ return Self{
.unbuffered_out_stream = unbuffered_out_stream,
.buffer = undefined,
.index = 0,
- .stream = Stream {
- .writeFn = writeFn,
- },
+ .stream = Stream{ .writeFn = writeFn },
};
}
@@ -416,11 +390,9 @@ pub const BufferOutStream = struct {
pub const Stream = OutStream(Error);
pub fn init(buffer: &Buffer) BufferOutStream {
- return BufferOutStream {
+ return BufferOutStream{
.buffer = buffer,
- .stream = Stream {
- .writeFn = writeFn,
- },
+ .stream = Stream{ .writeFn = writeFn },
};
}
@@ -430,7 +402,6 @@ pub const BufferOutStream = struct {
}
};
-
pub const BufferedAtomicFile = struct {
atomic_file: os.AtomicFile,
file_stream: FileOutStream,
@@ -441,7 +412,7 @@ pub const BufferedAtomicFile = struct {
var self = try allocator.create(BufferedAtomicFile);
errdefer allocator.destroy(self);
- *self = BufferedAtomicFile {
+ self.* = BufferedAtomicFile{
.atomic_file = undefined,
.file_stream = undefined,
.buffered_stream = undefined,
@@ -489,7 +460,7 @@ pub fn readLine(buf: []u8) !usize {
'\r' => {
// trash the following \n
_ = stream.readByte() catch return error.EndOfFile;
- return index;
+ return index;
},
'\n' => return index,
else => {
std/linked_list.zig
@@ -26,10 +26,10 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
data: T,
pub fn init(value: &const T) Node {
- return Node {
+ return Node{
.prev = null,
.next = null,
- .data = *value,
+ .data = value.*,
};
}
@@ -45,18 +45,18 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
};
first: ?&Node,
- last: ?&Node,
- len: usize,
+ last: ?&Node,
+ len: usize,
/// Initialize a linked list.
///
/// Returns:
/// An empty linked list.
pub fn init() Self {
- return Self {
+ return Self{
.first = null,
- .last = null,
- .len = 0,
+ .last = null,
+ .len = 0,
};
}
@@ -131,7 +131,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
} else {
// Empty list.
list.first = new_node;
- list.last = new_node;
+ list.last = new_node;
new_node.prev = null;
new_node.next = null;
@@ -217,7 +217,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
pub fn createNode(list: &Self, data: &const T, allocator: &Allocator) !&Node {
comptime assert(!isIntrusive());
var node = try list.allocateNode(allocator);
- *node = Node.init(data);
+ node.* = Node.init(data);
return node;
}
};
@@ -227,11 +227,11 @@ test "basic linked list test" {
const allocator = debug.global_allocator;
var list = LinkedList(u32).init();
- var one = try list.createNode(1, allocator);
- var two = try list.createNode(2, allocator);
+ var one = try list.createNode(1, allocator);
+ var two = try list.createNode(2, allocator);
var three = try list.createNode(3, allocator);
- var four = try list.createNode(4, allocator);
- var five = try list.createNode(5, allocator);
+ var four = try list.createNode(4, allocator);
+ var five = try list.createNode(5, allocator);
defer {
list.destroyNode(one, allocator);
list.destroyNode(two, allocator);
@@ -240,11 +240,11 @@ test "basic linked list test" {
list.destroyNode(five, allocator);
}
- list.append(two); // {2}
- list.append(five); // {2, 5}
- list.prepend(one); // {1, 2, 5}
- list.insertBefore(five, four); // {1, 2, 4, 5}
- list.insertAfter(two, three); // {1, 2, 3, 4, 5}
+ list.append(two); // {2}
+ list.append(five); // {2, 5}
+ list.prepend(one); // {1, 2, 5}
+ list.insertBefore(five, four); // {1, 2, 4, 5}
+ list.insertAfter(two, three); // {1, 2, 3, 4, 5}
// Traverse forwards.
{
@@ -266,13 +266,13 @@ test "basic linked list test" {
}
}
- var first = list.popFirst(); // {2, 3, 4, 5}
- var last = list.pop(); // {2, 3, 4}
- list.remove(three); // {2, 4}
+ var first = list.popFirst(); // {2, 3, 4, 5}
+ var last = list.pop(); // {2, 3, 4}
+ list.remove(three); // {2, 4}
- assert ((??list.first).data == 2);
- assert ((??list.last ).data == 4);
- assert (list.len == 2);
+ assert((??list.first).data == 2);
+ assert((??list.last).data == 4);
+ assert(list.len == 2);
}
const ElementList = IntrusiveLinkedList(Element, "link");
@@ -285,17 +285,32 @@ test "basic intrusive linked list test" {
const allocator = debug.global_allocator;
var list = ElementList.init();
- var one = Element { .value = 1, .link = ElementList.Node.initIntrusive() };
- var two = Element { .value = 2, .link = ElementList.Node.initIntrusive() };
- var three = Element { .value = 3, .link = ElementList.Node.initIntrusive() };
- var four = Element { .value = 4, .link = ElementList.Node.initIntrusive() };
- var five = Element { .value = 5, .link = ElementList.Node.initIntrusive() };
+ var one = Element{
+ .value = 1,
+ .link = ElementList.Node.initIntrusive(),
+ };
+ var two = Element{
+ .value = 2,
+ .link = ElementList.Node.initIntrusive(),
+ };
+ var three = Element{
+ .value = 3,
+ .link = ElementList.Node.initIntrusive(),
+ };
+ var four = Element{
+ .value = 4,
+ .link = ElementList.Node.initIntrusive(),
+ };
+ var five = Element{
+ .value = 5,
+ .link = ElementList.Node.initIntrusive(),
+ };
- list.append(&two.link); // {2}
- list.append(&five.link); // {2, 5}
- list.prepend(&one.link); // {1, 2, 5}
- list.insertBefore(&five.link, &four.link); // {1, 2, 4, 5}
- list.insertAfter(&two.link, &three.link); // {1, 2, 3, 4, 5}
+ list.append(&two.link); // {2}
+ list.append(&five.link); // {2, 5}
+ list.prepend(&one.link); // {1, 2, 5}
+ list.insertBefore(&five.link, &four.link); // {1, 2, 4, 5}
+ list.insertAfter(&two.link, &three.link); // {1, 2, 3, 4, 5}
// Traverse forwards.
{
@@ -317,11 +332,11 @@ test "basic intrusive linked list test" {
}
}
- var first = list.popFirst(); // {2, 3, 4, 5}
- var last = list.pop(); // {2, 3, 4}
- list.remove(&three.link); // {2, 4}
+ var first = list.popFirst(); // {2, 3, 4, 5}
+ var last = list.pop(); // {2, 3, 4}
+ list.remove(&three.link); // {2, 4}
- assert ((??list.first).toData().value == 2);
- assert ((??list.last ).toData().value == 4);
- assert (list.len == 2);
+ assert((??list.first).toData().value == 2);
+ assert((??list.last).toData().value == 4);
+ assert(list.len == 2);
}
test/cases/cast.zig
@@ -14,7 +14,7 @@ test "integer literal to pointer cast" {
}
test "pointer reinterpret const float to int" {
- const float: f64 = 5.99999999999994648725e - 01;
+ const float: f64 = 5.99999999999994648725e-01;
const float_ptr = &float;
const int_ptr = @ptrCast(&const i32, float_ptr);
const int_val = int_ptr.*;
@@ -121,13 +121,13 @@ test "implicitly cast indirect pointer to maybe-indirect pointer" {
return (p.*).x;
}
fn maybeConstConst(p: ?&const &const Self) u8 {
- return (??p.*).x;
+ return ((??p).*).x;
}
fn constConstConst(p: &const &const &const Self) u8 {
return (p.*.*).x;
}
fn maybeConstConstConst(p: ?&const &const &const Self) u8 {
- return (??p.*.*).x;
+ return ((??p).*.*).x;
}
};
const s = S {
test/cases/generics.zig
@@ -127,7 +127,7 @@ test "generic fn with implicit cast" {
}) == 0);
}
fn getByte(ptr: ?&const u8) u8 {
- return ??ptr.*;
+ return (??ptr).*;
}
fn getFirstByte(comptime T: type, mem: []const T) u8 {
return getByte(@ptrCast(&const u8, &mem[0]));