authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-05-01 01:53:04-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-05-01 01:53:04-04:00
logac4d55dec1e32ddef945bfa246eb78f20f31ec44
tree31e91383c77a6b19f77e76096c38f5976161b9dd
parenta35b366eb64272c6d4646aedc035a837ed0c3cb0

behavior tests passing with new pointer deref syntax


19 files changed, 1132 insertions(+), 631 deletions(-)

std/array_list.zig+33-21
...@@ -8,7 +8,7 @@ pub fn ArrayList(comptime T: type) type {...@@ -8,7 +8,7 @@ pub fn ArrayList(comptime T: type) type {
8 return AlignedArrayList(T, @alignOf(T));8 return AlignedArrayList(T, @alignOf(T));
9}9}
1010
11pub fn AlignedArrayList(comptime T: type, comptime A: u29) type{11pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
12 return struct {12 return struct {
13 const Self = this;13 const Self = this;
1414
...@@ -21,7 +21,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type{...@@ -21,7 +21,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type{
2121
22 /// Deinitialize with `deinit` or use `toOwnedSlice`.22 /// Deinitialize with `deinit` or use `toOwnedSlice`.
23 pub fn init(allocator: &Allocator) Self {23 pub fn init(allocator: &Allocator) Self {
24 return Self {24 return Self{
25 .items = []align(A) T{},25 .items = []align(A) T{},
26 .len = 0,26 .len = 0,
27 .allocator = allocator,27 .allocator = allocator,
...@@ -48,7 +48,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type{...@@ -48,7 +48,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type{
48 /// allocated with `allocator`.48 /// allocated with `allocator`.
49 /// Deinitialize with `deinit` or use `toOwnedSlice`.49 /// Deinitialize with `deinit` or use `toOwnedSlice`.
50 pub fn fromOwnedSlice(allocator: &Allocator, slice: []align(A) T) Self {50 pub fn fromOwnedSlice(allocator: &Allocator, slice: []align(A) T) Self {
51 return Self {51 return Self{
52 .items = slice,52 .items = slice,
53 .len = slice.len,53 .len = slice.len,
54 .allocator = allocator,54 .allocator = allocator,
...@@ -59,7 +59,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type{...@@ -59,7 +59,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type{
59 pub fn toOwnedSlice(self: &Self) []align(A) T {59 pub fn toOwnedSlice(self: &Self) []align(A) T {
60 const allocator = self.allocator;60 const allocator = self.allocator;
61 const result = allocator.alignedShrink(T, A, self.items, self.len);61 const result = allocator.alignedShrink(T, A, self.items, self.len);
62 *self = init(allocator);62 self.* = init(allocator);
63 return result;63 return result;
64 }64 }
6565
...@@ -67,21 +67,21 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type{...@@ -67,21 +67,21 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type{
67 try l.ensureCapacity(l.len + 1);67 try l.ensureCapacity(l.len + 1);
68 l.len += 1;68 l.len += 1;
6969
70 mem.copy(T, l.items[n+1..l.len], l.items[n..l.len-1]);70 mem.copy(T, l.items[n + 1..l.len], l.items[n..l.len - 1]);
71 l.items[n] = *item;71 l.items[n] = item.*;
72 }72 }
7373
74 pub fn insertSlice(l: &Self, n: usize, items: []align(A) const T) !void {74 pub fn insertSlice(l: &Self, n: usize, items: []align(A) const T) !void {
75 try l.ensureCapacity(l.len + items.len);75 try l.ensureCapacity(l.len + items.len);
76 l.len += items.len;76 l.len += items.len;
7777
78 mem.copy(T, l.items[n+items.len..l.len], l.items[n..l.len-items.len]);78 mem.copy(T, l.items[n + items.len..l.len], l.items[n..l.len - items.len]);
79 mem.copy(T, l.items[n..n+items.len], items);79 mem.copy(T, l.items[n..n + items.len], items);
80 }80 }
8181
82 pub fn append(l: &Self, item: &const T) !void {82 pub fn append(l: &Self, item: &const T) !void {
83 const new_item_ptr = try l.addOne();83 const new_item_ptr = try l.addOne();
84 *new_item_ptr = *item;84 new_item_ptr.* = item.*;
85 }85 }
8686
87 pub fn appendSlice(l: &Self, items: []align(A) const T) !void {87 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{...@@ -124,8 +124,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type{
124 }124 }
125125
126 pub fn popOrNull(self: &Self) ?T {126 pub fn popOrNull(self: &Self) ?T {
127 if (self.len == 0)127 if (self.len == 0) return null;
128 return null;
129 return self.pop();128 return self.pop();
130 }129 }
131 };130 };
...@@ -135,25 +134,35 @@ test "basic ArrayList test" {...@@ -135,25 +134,35 @@ test "basic ArrayList test" {
135 var list = ArrayList(i32).init(debug.global_allocator);134 var list = ArrayList(i32).init(debug.global_allocator);
136 defer list.deinit();135 defer list.deinit();
137136
138 {var i: usize = 0; while (i < 10) : (i += 1) {137 {
139 list.append(i32(i + 1)) catch unreachable;138 var i: usize = 0;
140 }}139 while (i < 10) : (i += 1) {
140 list.append(i32(i + 1)) catch unreachable;
141 }
142 }
141143
142 {var i: usize = 0; while (i < 10) : (i += 1) {144 {
143 assert(list.items[i] == i32(i + 1));145 var i: usize = 0;
144 }}146 while (i < 10) : (i += 1) {
147 assert(list.items[i] == i32(i + 1));
148 }
149 }
145150
146 assert(list.pop() == 10);151 assert(list.pop() == 10);
147 assert(list.len == 9);152 assert(list.len == 9);
148153
149 list.appendSlice([]const i32 { 1, 2, 3 }) catch unreachable;154 list.appendSlice([]const i32{
155 1,
156 2,
157 3,
158 }) catch unreachable;
150 assert(list.len == 12);159 assert(list.len == 12);
151 assert(list.pop() == 3);160 assert(list.pop() == 3);
152 assert(list.pop() == 2);161 assert(list.pop() == 2);
153 assert(list.pop() == 1);162 assert(list.pop() == 1);
154 assert(list.len == 9);163 assert(list.len == 9);
155164
156 list.appendSlice([]const i32 {}) catch unreachable;165 list.appendSlice([]const i32{}) catch unreachable;
157 assert(list.len == 9);166 assert(list.len == 9);
158}167}
159168
...@@ -166,12 +175,15 @@ test "insert ArrayList test" {...@@ -166,12 +175,15 @@ test "insert ArrayList test" {
166 assert(list.items[0] == 5);175 assert(list.items[0] == 5);
167 assert(list.items[1] == 1);176 assert(list.items[1] == 1);
168177
169 try list.insertSlice(1, []const i32 { 9, 8 });178 try list.insertSlice(1, []const i32{
179 9,
180 8,
181 });
170 assert(list.items[0] == 5);182 assert(list.items[0] == 5);
171 assert(list.items[1] == 9);183 assert(list.items[1] == 9);
172 assert(list.items[2] == 8);184 assert(list.items[2] == 8);
173185
174 const items = []const i32 { 1 };186 const items = []const i32{1};
175 try list.insertSlice(0, items[0..0]);187 try list.insertSlice(0, items[0..0]);
176 assert(list.items[0] == 5);188 assert(list.items[0] == 5);
177}189}
std/fmt/index.zig+38-55
...@@ -11,9 +11,7 @@ const max_int_digits = 65;...@@ -11,9 +11,7 @@ const max_int_digits = 65;
11/// Renders fmt string with args, calling output with slices of bytes.11/// Renders fmt string with args, calling output with slices of bytes.
12/// If `output` returns an error, the error is returned from `format` and12/// If `output` returns an error, the error is returned from `format` and
13/// `output` is not called again.13/// `output` is not called again.
14pub fn format(context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void,14pub fn format(context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void, comptime fmt: []const u8, args: ...) Errors!void {
15 comptime fmt: []const u8, args: ...) Errors!void
16{
17 const State = enum {15 const State = enum {
18 Start,16 Start,
19 OpenBrace,17 OpenBrace,
...@@ -221,7 +219,7 @@ pub fn format(context: var, comptime Errors: type, output: fn(@typeOf(context),...@@ -221,7 +219,7 @@ pub fn format(context: var, comptime Errors: type, output: fn(@typeOf(context),
221 }219 }
222}220}
223221
224pub fn formatValue(value: var, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8)Errors!void) Errors!void {222pub fn formatValue(value: var, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void {
225 const T = @typeOf(value);223 const T = @typeOf(value);
226 switch (@typeId(T)) {224 switch (@typeId(T)) {
227 builtin.TypeId.Int => {225 builtin.TypeId.Int => {
...@@ -256,7 +254,7 @@ pub fn formatValue(value: var, context: var, comptime Errors: type, output: fn(@...@@ -256,7 +254,7 @@ pub fn formatValue(value: var, context: var, comptime Errors: type, output: fn(@
256 },254 },
257 builtin.TypeId.Pointer => {255 builtin.TypeId.Pointer => {
258 if (@typeId(T.Child) == builtin.TypeId.Array and T.Child.Child == u8) {256 if (@typeId(T.Child) == builtin.TypeId.Array and T.Child.Child == u8) {
259 return output(context, (*value)[0..]);257 return output(context, (value.*)[0..]);
260 } else {258 } else {
261 return format(context, Errors, output, "{}@{x}", @typeName(T.Child), @ptrToInt(value));259 return format(context, Errors, output, "{}@{x}", @typeName(T.Child), @ptrToInt(value));
262 }260 }
...@@ -270,13 +268,11 @@ pub fn formatValue(value: var, context: var, comptime Errors: type, output: fn(@...@@ -270,13 +268,11 @@ pub fn formatValue(value: var, context: var, comptime Errors: type, output: fn(@
270 }268 }
271}269}
272270
273pub fn formatAsciiChar(c: u8, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8)Errors!void) Errors!void {271pub fn formatAsciiChar(c: u8, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void {
274 return output(context, (&c)[0..1]);272 return output(context, (&c)[0..1]);
275}273}
276274
277pub fn formatBuf(buf: []const u8, width: usize,275pub fn formatBuf(buf: []const u8, width: usize, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void {
278 context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8)Errors!void) Errors!void
279{
280 try output(context, buf);276 try output(context, buf);
281277
282 var leftover_padding = if (width > buf.len) (width - buf.len) else return;278 var leftover_padding = if (width > buf.len) (width - buf.len) else return;
...@@ -289,7 +285,7 @@ pub fn formatBuf(buf: []const u8, width: usize,...@@ -289,7 +285,7 @@ pub fn formatBuf(buf: []const u8, width: usize,
289// Print a float in scientific notation to the specified precision. Null uses full precision.285// Print a float in scientific notation to the specified precision. Null uses full precision.
290// It should be the case that every full precision, printed value can be re-parsed back to the286// It should be the case that every full precision, printed value can be re-parsed back to the
291// same type unambiguously.287// same type unambiguously.
292pub fn formatFloatScientific(value: var, maybe_precision: ?usize, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8)Errors!void) Errors!void {288pub fn formatFloatScientific(value: var, maybe_precision: ?usize, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void {
293 var x = f64(value);289 var x = f64(value);
294290
295 // Errol doesn't handle these special cases.291 // Errol doesn't handle these special cases.
...@@ -338,7 +334,7 @@ pub fn formatFloatScientific(value: var, maybe_precision: ?usize, context: var,...@@ -338,7 +334,7 @@ pub fn formatFloatScientific(value: var, maybe_precision: ?usize, context: var,
338 var printed: usize = 0;334 var printed: usize = 0;
339 if (float_decimal.digits.len > 1) {335 if (float_decimal.digits.len > 1) {
340 const num_digits = math.min(float_decimal.digits.len, precision + 1);336 const num_digits = math.min(float_decimal.digits.len, precision + 1);
341 try output(context, float_decimal.digits[1 .. num_digits]);337 try output(context, float_decimal.digits[1..num_digits]);
342 printed += num_digits - 1;338 printed += num_digits - 1;
343 }339 }
344340
...@@ -350,12 +346,9 @@ pub fn formatFloatScientific(value: var, maybe_precision: ?usize, context: var,...@@ -350,12 +346,9 @@ pub fn formatFloatScientific(value: var, maybe_precision: ?usize, context: var,
350 try output(context, float_decimal.digits[0..1]);346 try output(context, float_decimal.digits[0..1]);
351 try output(context, ".");347 try output(context, ".");
352 if (float_decimal.digits.len > 1) {348 if (float_decimal.digits.len > 1) {
353 const num_digits = if (@typeOf(value) == f32)349 const num_digits = if (@typeOf(value) == f32) math.min(usize(9), float_decimal.digits.len) else float_decimal.digits.len;
354 math.min(usize(9), float_decimal.digits.len)
355 else
356 float_decimal.digits.len;
357350
358 try output(context, float_decimal.digits[1 .. num_digits]);351 try output(context, float_decimal.digits[1..num_digits]);
359 } else {352 } else {
360 try output(context, "0");353 try output(context, "0");
361 }354 }
...@@ -381,7 +374,7 @@ pub fn formatFloatScientific(value: var, maybe_precision: ?usize, context: var,...@@ -381,7 +374,7 @@ pub fn formatFloatScientific(value: var, maybe_precision: ?usize, context: var,
381374
382// Print a float of the format x.yyyyy where the number of y is specified by the precision argument.375// Print a float of the format x.yyyyy where the number of y is specified by the precision argument.
383// By default floats are printed at full precision (no rounding).376// By default floats are printed at full precision (no rounding).
384pub fn formatFloatDecimal(value: var, maybe_precision: ?usize, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8)Errors!void) Errors!void {377pub fn formatFloatDecimal(value: var, maybe_precision: ?usize, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void {
385 var x = f64(value);378 var x = f64(value);
386379
387 // Errol doesn't handle these special cases.380 // Errol doesn't handle these special cases.
...@@ -431,14 +424,14 @@ pub fn formatFloatDecimal(value: var, maybe_precision: ?usize, context: var, com...@@ -431,14 +424,14 @@ pub fn formatFloatDecimal(value: var, maybe_precision: ?usize, context: var, com
431424
432 if (num_digits_whole > 0) {425 if (num_digits_whole > 0) {
433 // We may have to zero pad, for instance 1e4 requires zero padding.426 // We may have to zero pad, for instance 1e4 requires zero padding.
434 try output(context, float_decimal.digits[0 .. num_digits_whole_no_pad]);427 try output(context, float_decimal.digits[0..num_digits_whole_no_pad]);
435428
436 var i = num_digits_whole_no_pad;429 var i = num_digits_whole_no_pad;
437 while (i < num_digits_whole) : (i += 1) {430 while (i < num_digits_whole) : (i += 1) {
438 try output(context, "0");431 try output(context, "0");
439 }432 }
440 } else {433 } else {
441 try output(context , "0");434 try output(context, "0");
442 }435 }
443436
444 // {.0} special case doesn't want a trailing '.'437 // {.0} special case doesn't want a trailing '.'
...@@ -470,10 +463,10 @@ pub fn formatFloatDecimal(value: var, maybe_precision: ?usize, context: var, com...@@ -470,10 +463,10 @@ pub fn formatFloatDecimal(value: var, maybe_precision: ?usize, context: var, com
470 // Remaining fractional portion, zero-padding if insufficient.463 // Remaining fractional portion, zero-padding if insufficient.
471 debug.assert(precision >= printed);464 debug.assert(precision >= printed);
472 if (num_digits_whole_no_pad + precision - printed < float_decimal.digits.len) {465 if (num_digits_whole_no_pad + precision - printed < float_decimal.digits.len) {
473 try output(context, float_decimal.digits[num_digits_whole_no_pad .. num_digits_whole_no_pad + precision - printed]);466 try output(context, float_decimal.digits[num_digits_whole_no_pad..num_digits_whole_no_pad + precision - printed]);
474 return;467 return;
475 } else {468 } else {
476 try output(context, float_decimal.digits[num_digits_whole_no_pad ..]);469 try output(context, float_decimal.digits[num_digits_whole_no_pad..]);
477 printed += float_decimal.digits.len - num_digits_whole_no_pad;470 printed += float_decimal.digits.len - num_digits_whole_no_pad;
478471
479 while (printed < precision) : (printed += 1) {472 while (printed < precision) : (printed += 1) {
...@@ -489,14 +482,14 @@ pub fn formatFloatDecimal(value: var, maybe_precision: ?usize, context: var, com...@@ -489,14 +482,14 @@ pub fn formatFloatDecimal(value: var, maybe_precision: ?usize, context: var, com
489482
490 if (num_digits_whole > 0) {483 if (num_digits_whole > 0) {
491 // We may have to zero pad, for instance 1e4 requires zero padding.484 // We may have to zero pad, for instance 1e4 requires zero padding.
492 try output(context, float_decimal.digits[0 .. num_digits_whole_no_pad]);485 try output(context, float_decimal.digits[0..num_digits_whole_no_pad]);
493486
494 var i = num_digits_whole_no_pad;487 var i = num_digits_whole_no_pad;
495 while (i < num_digits_whole) : (i += 1) {488 while (i < num_digits_whole) : (i += 1) {
496 try output(context, "0");489 try output(context, "0");
497 }490 }
498 } else {491 } else {
499 try output(context , "0");492 try output(context, "0");
500 }493 }
501494
502 // Omit `.` if no fractional portion495 // Omit `.` if no fractional portion
...@@ -516,14 +509,11 @@ pub fn formatFloatDecimal(value: var, maybe_precision: ?usize, context: var, com...@@ -516,14 +509,11 @@ pub fn formatFloatDecimal(value: var, maybe_precision: ?usize, context: var, com
516 }509 }
517 }510 }
518511
519 try output(context, float_decimal.digits[num_digits_whole_no_pad ..]);512 try output(context, float_decimal.digits[num_digits_whole_no_pad..]);
520 }513 }
521}514}
522515
523516pub 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 {
524pub fn formatInt(value: var, base: u8, uppercase: bool, width: usize,
525 context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8)Errors!void) Errors!void
526{
527 if (@typeOf(value).is_signed) {517 if (@typeOf(value).is_signed) {
528 return formatIntSigned(value, base, uppercase, width, context, Errors, output);518 return formatIntSigned(value, base, uppercase, width, context, Errors, output);
529 } else {519 } else {
...@@ -531,9 +521,7 @@ pub fn formatInt(value: var, base: u8, uppercase: bool, width: usize,...@@ -531,9 +521,7 @@ pub fn formatInt(value: var, base: u8, uppercase: bool, width: usize,
531 }521 }
532}522}
533523
534fn formatIntSigned(value: var, base: u8, uppercase: bool, width: usize,524fn formatIntSigned(value: var, base: u8, uppercase: bool, width: usize, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void {
535 context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8)Errors!void) Errors!void
536{
537 const uint = @IntType(false, @typeOf(value).bit_count);525 const uint = @IntType(false, @typeOf(value).bit_count);
538 if (value < 0) {526 if (value < 0) {
539 const minus_sign: u8 = '-';527 const minus_sign: u8 = '-';
...@@ -552,9 +540,7 @@ fn formatIntSigned(value: var, base: u8, uppercase: bool, width: usize,...@@ -552,9 +540,7 @@ fn formatIntSigned(value: var, base: u8, uppercase: bool, width: usize,
552 }540 }
553}541}
554542
555fn formatIntUnsigned(value: var, base: u8, uppercase: bool, width: usize,543fn formatIntUnsigned(value: var, base: u8, uppercase: bool, width: usize, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void {
556 context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8)Errors!void) Errors!void
557{
558 // max_int_digits accounts for the minus sign. when printing an unsigned544 // max_int_digits accounts for the minus sign. when printing an unsigned
559 // number we don't need to do that.545 // number we don't need to do that.
560 var buf: [max_int_digits - 1]u8 = undefined;546 var buf: [max_int_digits - 1]u8 = undefined;
...@@ -566,8 +552,7 @@ fn formatIntUnsigned(value: var, base: u8, uppercase: bool, width: usize,...@@ -566,8 +552,7 @@ fn formatIntUnsigned(value: var, base: u8, uppercase: bool, width: usize,
566 index -= 1;552 index -= 1;
567 buf[index] = digitToChar(u8(digit), uppercase);553 buf[index] = digitToChar(u8(digit), uppercase);
568 a /= base;554 a /= base;
569 if (a == 0)555 if (a == 0) break;
570 break;
571 }556 }
572557
573 const digits_buf = buf[index..];558 const digits_buf = buf[index..];
...@@ -579,8 +564,7 @@ fn formatIntUnsigned(value: var, base: u8, uppercase: bool, width: usize,...@@ -579,8 +564,7 @@ fn formatIntUnsigned(value: var, base: u8, uppercase: bool, width: usize,
579 while (true) {564 while (true) {
580 try output(context, (&zero_byte)[0..1]);565 try output(context, (&zero_byte)[0..1]);
581 leftover_padding -= 1;566 leftover_padding -= 1;
582 if (leftover_padding == 0)567 if (leftover_padding == 0) break;
583 break;
584 }568 }
585 mem.set(u8, buf[0..index], '0');569 mem.set(u8, buf[0..index], '0');
586 return output(context, buf);570 return output(context, buf);
...@@ -592,7 +576,7 @@ fn formatIntUnsigned(value: var, base: u8, uppercase: bool, width: usize,...@@ -592,7 +576,7 @@ fn formatIntUnsigned(value: var, base: u8, uppercase: bool, width: usize,
592}576}
593577
594pub fn formatIntBuf(out_buf: []u8, value: var, base: u8, uppercase: bool, width: usize) usize {578pub fn formatIntBuf(out_buf: []u8, value: var, base: u8, uppercase: bool, width: usize) usize {
595 var context = FormatIntBuf {579 var context = FormatIntBuf{
596 .out_buf = out_buf,580 .out_buf = out_buf,
597 .index = 0,581 .index = 0,
598 };582 };
...@@ -609,10 +593,8 @@ fn formatIntCallback(context: &FormatIntBuf, bytes: []const u8) (error{}!void) {...@@ -609,10 +593,8 @@ fn formatIntCallback(context: &FormatIntBuf, bytes: []const u8) (error{}!void) {
609}593}
610594
611pub fn parseInt(comptime T: type, buf: []const u8, radix: u8) !T {595pub fn parseInt(comptime T: type, buf: []const u8, radix: u8) !T {
612 if (!T.is_signed)596 if (!T.is_signed) return parseUnsigned(T, buf, radix);
613 return parseUnsigned(T, buf, radix);597 if (buf.len == 0) return T(0);
614 if (buf.len == 0)
615 return T(0);
616 if (buf[0] == '-') {598 if (buf[0] == '-') {
617 return math.negate(try parseUnsigned(T, buf[1..], radix));599 return math.negate(try parseUnsigned(T, buf[1..], radix));
618 } else if (buf[0] == '+') {600 } else if (buf[0] == '+') {
...@@ -632,9 +614,10 @@ test "fmt.parseInt" {...@@ -632,9 +614,10 @@ test "fmt.parseInt" {
632 assert(if (parseInt(u8, "256", 10)) |_| false else |err| err == error.Overflow);614 assert(if (parseInt(u8, "256", 10)) |_| false else |err| err == error.Overflow);
633}615}
634616
635const ParseUnsignedError = error {617const ParseUnsignedError = error{
636 /// The result cannot fit in the type specified618 /// The result cannot fit in the type specified
637 Overflow,619 Overflow,
620
638 /// The input had a byte that was not a digit621 /// The input had a byte that was not a digit
639 InvalidCharacter,622 InvalidCharacter,
640};623};
...@@ -659,8 +642,7 @@ pub fn charToDigit(c: u8, radix: u8) (error{InvalidCharacter}!u8) {...@@ -659,8 +642,7 @@ pub fn charToDigit(c: u8, radix: u8) (error{InvalidCharacter}!u8) {
659 else => return error.InvalidCharacter,642 else => return error.InvalidCharacter,
660 };643 };
661644
662 if (value >= radix)645 if (value >= radix) return error.InvalidCharacter;
663 return error.InvalidCharacter;
664646
665 return value;647 return value;
666}648}
...@@ -684,20 +666,21 @@ fn bufPrintWrite(context: &BufPrintContext, bytes: []const u8) !void {...@@ -684,20 +666,21 @@ fn bufPrintWrite(context: &BufPrintContext, bytes: []const u8) !void {
684}666}
685667
686pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: ...) ![]u8 {668pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: ...) ![]u8 {
687 var context = BufPrintContext { .remaining = buf, };669 var context = BufPrintContext{ .remaining = buf };
688 try format(&context, error{BufferTooSmall}, bufPrintWrite, fmt, args);670 try format(&context, error{BufferTooSmall}, bufPrintWrite, fmt, args);
689 return buf[0..buf.len - context.remaining.len];671 return buf[0..buf.len - context.remaining.len];
690}672}
691673
692pub fn allocPrint(allocator: &mem.Allocator, comptime fmt: []const u8, args: ...) ![]u8 {674pub fn allocPrint(allocator: &mem.Allocator, comptime fmt: []const u8, args: ...) ![]u8 {
693 var size: usize = 0;675 var size: usize = 0;
694 format(&size, error{}, countSize, fmt, args) catch |err| switch (err) {};676 format(&size, error{}, countSize, fmt, args) catch |err| switch (err) {
677 };
695 const buf = try allocator.alloc(u8, size);678 const buf = try allocator.alloc(u8, size);
696 return bufPrint(buf, fmt, args);679 return bufPrint(buf, fmt, args);
697}680}
698681
699fn countSize(size: &usize, bytes: []const u8) (error{}!void) {682fn countSize(size: &usize, bytes: []const u8) (error{}!void) {
700 *size += bytes.len;683 size.* += bytes.len;
701}684}
702685
703test "buf print int" {686test "buf print int" {
...@@ -773,9 +756,7 @@ test "fmt.format" {...@@ -773,9 +756,7 @@ test "fmt.format" {
773 unused: u8,756 unused: u8,
774 };757 };
775 var buf1: [32]u8 = undefined;758 var buf1: [32]u8 = undefined;
776 const value = Struct {759 const value = Struct{ .unused = 42 };
777 .unused = 42,
778 };
779 const result = try bufPrint(buf1[0..], "pointer: {}\n", &value);760 const result = try bufPrint(buf1[0..], "pointer: {}\n", &value);
780 assert(mem.startsWith(u8, result, "pointer: Struct@"));761 assert(mem.startsWith(u8, result, "pointer: Struct@"));
781 }762 }
...@@ -988,7 +969,7 @@ test "fmt.format" {...@@ -988,7 +969,7 @@ test "fmt.format" {
988969
989pub fn trim(buf: []const u8) []const u8 {970pub fn trim(buf: []const u8) []const u8 {
990 var start: usize = 0;971 var start: usize = 0;
991 while (start < buf.len and isWhiteSpace(buf[start])) : (start += 1) { }972 while (start < buf.len and isWhiteSpace(buf[start])) : (start += 1) {}
992973
993 var end: usize = buf.len;974 var end: usize = buf.len;
994 while (true) {975 while (true) {
...@@ -1000,7 +981,6 @@ pub fn trim(buf: []const u8) []const u8 {...@@ -1000,7 +981,6 @@ pub fn trim(buf: []const u8) []const u8 {
1000 }981 }
1001 }982 }
1002 break;983 break;
1003
1004 }984 }
1005 return buf[start..end];985 return buf[start..end];
1006}986}
...@@ -1015,7 +995,10 @@ test "fmt.trim" {...@@ -1015,7 +995,10 @@ test "fmt.trim" {
1015995
1016pub fn isWhiteSpace(byte: u8) bool {996pub fn isWhiteSpace(byte: u8) bool {
1017 return switch (byte) {997 return switch (byte) {
1018 ' ', '\t', '\n', '\r' => true,998 ' ',
999 '\t',
1000 '\n',
1001 '\r' => true,
1019 else => false,1002 else => false,
1020 };1003 };
1021}1004}
std/heap.zig+52-54
...@@ -10,7 +10,7 @@ const c = std.c;...@@ -10,7 +10,7 @@ const c = std.c;
10const Allocator = mem.Allocator;10const Allocator = mem.Allocator;
1111
12pub const c_allocator = &c_allocator_state;12pub const c_allocator = &c_allocator_state;
13var c_allocator_state = Allocator {13var c_allocator_state = Allocator{
14 .allocFn = cAlloc,14 .allocFn = cAlloc,
15 .reallocFn = cRealloc,15 .reallocFn = cRealloc,
16 .freeFn = cFree,16 .freeFn = cFree,
...@@ -18,10 +18,7 @@ var c_allocator_state = Allocator {...@@ -18,10 +18,7 @@ var c_allocator_state = Allocator {
1818
19fn cAlloc(self: &Allocator, n: usize, alignment: u29) ![]u8 {19fn cAlloc(self: &Allocator, n: usize, alignment: u29) ![]u8 {
20 assert(alignment <= @alignOf(c_longdouble));20 assert(alignment <= @alignOf(c_longdouble));
21 return if (c.malloc(n)) |buf|21 return if (c.malloc(n)) |buf| @ptrCast(&u8, buf)[0..n] else error.OutOfMemory;
22 @ptrCast(&u8, buf)[0..n]
23 else
24 error.OutOfMemory;
25}22}
2623
27fn cRealloc(self: &Allocator, old_mem: []u8, new_size: usize, alignment: u29) ![]u8 {24fn cRealloc(self: &Allocator, old_mem: []u8, new_size: usize, alignment: u29) ![]u8 {
...@@ -48,8 +45,8 @@ pub const DirectAllocator = struct {...@@ -48,8 +45,8 @@ pub const DirectAllocator = struct {
48 const HeapHandle = if (builtin.os == Os.windows) os.windows.HANDLE else void;45 const HeapHandle = if (builtin.os == Os.windows) os.windows.HANDLE else void;
4946
50 pub fn init() DirectAllocator {47 pub fn init() DirectAllocator {
51 return DirectAllocator {48 return DirectAllocator{
52 .allocator = Allocator {49 .allocator = Allocator{
53 .allocFn = alloc,50 .allocFn = alloc,
54 .reallocFn = realloc,51 .reallocFn = realloc,
55 .freeFn = free,52 .freeFn = free,
...@@ -71,39 +68,39 @@ pub const DirectAllocator = struct {...@@ -71,39 +68,39 @@ pub const DirectAllocator = struct {
71 const self = @fieldParentPtr(DirectAllocator, "allocator", allocator);68 const self = @fieldParentPtr(DirectAllocator, "allocator", allocator);
7269
73 switch (builtin.os) {70 switch (builtin.os) {
74 Os.linux, Os.macosx, Os.ios => {71 Os.linux,
72 Os.macosx,
73 Os.ios => {
75 const p = os.posix;74 const p = os.posix;
76 const alloc_size = if(alignment <= os.page_size) n else n + alignment;75 const alloc_size = if (alignment <= os.page_size) n else n + alignment;
77 const addr = p.mmap(null, alloc_size, p.PROT_READ|p.PROT_WRITE, 76 const addr = p.mmap(null, alloc_size, p.PROT_READ | p.PROT_WRITE, p.MAP_PRIVATE | p.MAP_ANONYMOUS, -1, 0);
78 p.MAP_PRIVATE|p.MAP_ANONYMOUS, -1, 0);77 if (addr == p.MAP_FAILED) return error.OutOfMemory;
79 if(addr == p.MAP_FAILED) return error.OutOfMemory;78
80 79 if (alloc_size == n) return @intToPtr(&u8, addr)[0..n];
81 if(alloc_size == n) return @intToPtr(&u8, addr)[0..n];80
82
83 var aligned_addr = addr & ~usize(alignment - 1);81 var aligned_addr = addr & ~usize(alignment - 1);
84 aligned_addr += alignment;82 aligned_addr += alignment;
85 83
86 //We can unmap the unused portions of our mmap, but we must only84 //We can unmap the unused portions of our mmap, but we must only
87 // pass munmap bytes that exist outside our allocated pages or it85 // pass munmap bytes that exist outside our allocated pages or it
88 // will happily eat us too86 // will happily eat us too
89 87
90 //Since alignment > page_size, we are by definition on a page boundry88 //Since alignment > page_size, we are by definition on a page boundry
91 const unused_start = addr;89 const unused_start = addr;
92 const unused_len = aligned_addr - 1 - unused_start;90 const unused_len = aligned_addr - 1 - unused_start;
9391
94 var err = p.munmap(unused_start, unused_len);92 var err = p.munmap(unused_start, unused_len);
95 debug.assert(p.getErrno(err) == 0);93 debug.assert(p.getErrno(err) == 0);
96 94
97 //It is impossible that there is an unoccupied page at the top of our95 //It is impossible that there is an unoccupied page at the top of our
98 // mmap.96 // mmap.
99 97
100 return @intToPtr(&u8, aligned_addr)[0..n];98 return @intToPtr(&u8, aligned_addr)[0..n];
101 },99 },
102 Os.windows => {100 Os.windows => {
103 const amt = n + alignment + @sizeOf(usize);101 const amt = n + alignment + @sizeOf(usize);
104 const heap_handle = self.heap_handle ?? blk: {102 const heap_handle = self.heap_handle ?? blk: {
105 const hh = os.windows.HeapCreate(os.windows.HEAP_NO_SERIALIZE, amt, 0)103 const hh = os.windows.HeapCreate(os.windows.HEAP_NO_SERIALIZE, amt, 0) ?? return error.OutOfMemory;
106 ?? return error.OutOfMemory;
107 self.heap_handle = hh;104 self.heap_handle = hh;
108 break :blk hh;105 break :blk hh;
109 };106 };
...@@ -113,7 +110,7 @@ pub const DirectAllocator = struct {...@@ -113,7 +110,7 @@ pub const DirectAllocator = struct {
113 const march_forward_bytes = if (rem == 0) 0 else (alignment - rem);110 const march_forward_bytes = if (rem == 0) 0 else (alignment - rem);
114 const adjusted_addr = root_addr + march_forward_bytes;111 const adjusted_addr = root_addr + march_forward_bytes;
115 const record_addr = adjusted_addr + n;112 const record_addr = adjusted_addr + n;
116 *@intToPtr(&align(1) usize, record_addr) = root_addr;113 @intToPtr(&align(1) usize, record_addr).* = root_addr;
117 return @intToPtr(&u8, adjusted_addr)[0..n];114 return @intToPtr(&u8, adjusted_addr)[0..n];
118 },115 },
119 else => @compileError("Unsupported OS"),116 else => @compileError("Unsupported OS"),
...@@ -124,7 +121,9 @@ pub const DirectAllocator = struct {...@@ -124,7 +121,9 @@ pub const DirectAllocator = struct {
124 const self = @fieldParentPtr(DirectAllocator, "allocator", allocator);121 const self = @fieldParentPtr(DirectAllocator, "allocator", allocator);
125122
126 switch (builtin.os) {123 switch (builtin.os) {
127 Os.linux, Os.macosx, Os.ios => {124 Os.linux,
125 Os.macosx,
126 Os.ios => {
128 if (new_size <= old_mem.len) {127 if (new_size <= old_mem.len) {
129 const base_addr = @ptrToInt(old_mem.ptr);128 const base_addr = @ptrToInt(old_mem.ptr);
130 const old_addr_end = base_addr + old_mem.len;129 const old_addr_end = base_addr + old_mem.len;
...@@ -144,13 +143,13 @@ pub const DirectAllocator = struct {...@@ -144,13 +143,13 @@ pub const DirectAllocator = struct {
144 Os.windows => {143 Os.windows => {
145 const old_adjusted_addr = @ptrToInt(old_mem.ptr);144 const old_adjusted_addr = @ptrToInt(old_mem.ptr);
146 const old_record_addr = old_adjusted_addr + old_mem.len;145 const old_record_addr = old_adjusted_addr + old_mem.len;
147 const root_addr = *@intToPtr(&align(1) usize, old_record_addr);146 const root_addr = @intToPtr(&align(1) usize, old_record_addr).*;
148 const old_ptr = @intToPtr(os.windows.LPVOID, root_addr);147 const old_ptr = @intToPtr(os.windows.LPVOID, root_addr);
149 const amt = new_size + alignment + @sizeOf(usize);148 const amt = new_size + alignment + @sizeOf(usize);
150 const new_ptr = os.windows.HeapReAlloc(??self.heap_handle, 0, old_ptr, amt) ?? blk: {149 const new_ptr = os.windows.HeapReAlloc(??self.heap_handle, 0, old_ptr, amt) ?? blk: {
151 if (new_size > old_mem.len) return error.OutOfMemory;150 if (new_size > old_mem.len) return error.OutOfMemory;
152 const new_record_addr = old_record_addr - new_size + old_mem.len;151 const new_record_addr = old_record_addr - new_size + old_mem.len;
153 *@intToPtr(&align(1) usize, new_record_addr) = root_addr;152 @intToPtr(&align(1) usize, new_record_addr).* = root_addr;
154 return old_mem[0..new_size];153 return old_mem[0..new_size];
155 };154 };
156 const offset = old_adjusted_addr - root_addr;155 const offset = old_adjusted_addr - root_addr;
...@@ -158,7 +157,7 @@ pub const DirectAllocator = struct {...@@ -158,7 +157,7 @@ pub const DirectAllocator = struct {
158 const new_adjusted_addr = new_root_addr + offset;157 const new_adjusted_addr = new_root_addr + offset;
159 assert(new_adjusted_addr % alignment == 0);158 assert(new_adjusted_addr % alignment == 0);
160 const new_record_addr = new_adjusted_addr + new_size;159 const new_record_addr = new_adjusted_addr + new_size;
161 *@intToPtr(&align(1) usize, new_record_addr) = new_root_addr;160 @intToPtr(&align(1) usize, new_record_addr).* = new_root_addr;
162 return @intToPtr(&u8, new_adjusted_addr)[0..new_size];161 return @intToPtr(&u8, new_adjusted_addr)[0..new_size];
163 },162 },
164 else => @compileError("Unsupported OS"),163 else => @compileError("Unsupported OS"),
...@@ -169,12 +168,14 @@ pub const DirectAllocator = struct {...@@ -169,12 +168,14 @@ pub const DirectAllocator = struct {
169 const self = @fieldParentPtr(DirectAllocator, "allocator", allocator);168 const self = @fieldParentPtr(DirectAllocator, "allocator", allocator);
170169
171 switch (builtin.os) {170 switch (builtin.os) {
172 Os.linux, Os.macosx, Os.ios => {171 Os.linux,
172 Os.macosx,
173 Os.ios => {
173 _ = os.posix.munmap(@ptrToInt(bytes.ptr), bytes.len);174 _ = os.posix.munmap(@ptrToInt(bytes.ptr), bytes.len);
174 },175 },
175 Os.windows => {176 Os.windows => {
176 const record_addr = @ptrToInt(bytes.ptr) + bytes.len;177 const record_addr = @ptrToInt(bytes.ptr) + bytes.len;
177 const root_addr = *@intToPtr(&align(1) usize, record_addr);178 const root_addr = @intToPtr(&align(1) usize, record_addr).*;
178 const ptr = @intToPtr(os.windows.LPVOID, root_addr);179 const ptr = @intToPtr(os.windows.LPVOID, root_addr);
179 _ = os.windows.HeapFree(??self.heap_handle, 0, ptr);180 _ = os.windows.HeapFree(??self.heap_handle, 0, ptr);
180 },181 },
...@@ -195,8 +196,8 @@ pub const ArenaAllocator = struct {...@@ -195,8 +196,8 @@ pub const ArenaAllocator = struct {
195 const BufNode = std.LinkedList([]u8).Node;196 const BufNode = std.LinkedList([]u8).Node;
196197
197 pub fn init(child_allocator: &Allocator) ArenaAllocator {198 pub fn init(child_allocator: &Allocator) ArenaAllocator {
198 return ArenaAllocator {199 return ArenaAllocator{
199 .allocator = Allocator {200 .allocator = Allocator{
200 .allocFn = alloc,201 .allocFn = alloc,
201 .reallocFn = realloc,202 .reallocFn = realloc,
202 .freeFn = free,203 .freeFn = free,
...@@ -228,7 +229,7 @@ pub const ArenaAllocator = struct {...@@ -228,7 +229,7 @@ pub const ArenaAllocator = struct {
228 const buf = try self.child_allocator.alignedAlloc(u8, @alignOf(BufNode), len);229 const buf = try self.child_allocator.alignedAlloc(u8, @alignOf(BufNode), len);
229 const buf_node_slice = ([]BufNode)(buf[0..@sizeOf(BufNode)]);230 const buf_node_slice = ([]BufNode)(buf[0..@sizeOf(BufNode)]);
230 const buf_node = &buf_node_slice[0];231 const buf_node = &buf_node_slice[0];
231 *buf_node = BufNode {232 buf_node.* = BufNode{
232 .data = buf,233 .data = buf,
233 .prev = null,234 .prev = null,
234 .next = null,235 .next = null,
...@@ -253,7 +254,7 @@ pub const ArenaAllocator = struct {...@@ -253,7 +254,7 @@ pub const ArenaAllocator = struct {
253 cur_node = try self.createNode(cur_buf.len, n + alignment);254 cur_node = try self.createNode(cur_buf.len, n + alignment);
254 continue;255 continue;
255 }256 }
256 const result = cur_buf[adjusted_index .. new_end_index];257 const result = cur_buf[adjusted_index..new_end_index];
257 self.end_index = new_end_index;258 self.end_index = new_end_index;
258 return result;259 return result;
259 }260 }
...@@ -269,7 +270,7 @@ pub const ArenaAllocator = struct {...@@ -269,7 +270,7 @@ pub const ArenaAllocator = struct {
269 }270 }
270 }271 }
271272
272 fn free(allocator: &Allocator, bytes: []u8) void { }273 fn free(allocator: &Allocator, bytes: []u8) void {}
273};274};
274275
275pub const FixedBufferAllocator = struct {276pub const FixedBufferAllocator = struct {
...@@ -278,8 +279,8 @@ pub const FixedBufferAllocator = struct {...@@ -278,8 +279,8 @@ pub const FixedBufferAllocator = struct {
278 buffer: []u8,279 buffer: []u8,
279280
280 pub fn init(buffer: []u8) FixedBufferAllocator {281 pub fn init(buffer: []u8) FixedBufferAllocator {
281 return FixedBufferAllocator {282 return FixedBufferAllocator{
282 .allocator = Allocator {283 .allocator = Allocator{
283 .allocFn = alloc,284 .allocFn = alloc,
284 .reallocFn = realloc,285 .reallocFn = realloc,
285 .freeFn = free,286 .freeFn = free,
...@@ -299,7 +300,7 @@ pub const FixedBufferAllocator = struct {...@@ -299,7 +300,7 @@ pub const FixedBufferAllocator = struct {
299 if (new_end_index > self.buffer.len) {300 if (new_end_index > self.buffer.len) {
300 return error.OutOfMemory;301 return error.OutOfMemory;
301 }302 }
302 const result = self.buffer[adjusted_index .. new_end_index];303 const result = self.buffer[adjusted_index..new_end_index];
303 self.end_index = new_end_index;304 self.end_index = new_end_index;
304305
305 return result;306 return result;
...@@ -315,7 +316,7 @@ pub const FixedBufferAllocator = struct {...@@ -315,7 +316,7 @@ pub const FixedBufferAllocator = struct {
315 }316 }
316 }317 }
317318
318 fn free(allocator: &Allocator, bytes: []u8) void { }319 fn free(allocator: &Allocator, bytes: []u8) void {}
319};320};
320321
321/// lock free322/// lock free
...@@ -325,8 +326,8 @@ pub const ThreadSafeFixedBufferAllocator = struct {...@@ -325,8 +326,8 @@ pub const ThreadSafeFixedBufferAllocator = struct {
325 buffer: []u8,326 buffer: []u8,
326327
327 pub fn init(buffer: []u8) ThreadSafeFixedBufferAllocator {328 pub fn init(buffer: []u8) ThreadSafeFixedBufferAllocator {
328 return ThreadSafeFixedBufferAllocator {329 return ThreadSafeFixedBufferAllocator{
329 .allocator = Allocator {330 .allocator = Allocator{
330 .allocFn = alloc,331 .allocFn = alloc,
331 .reallocFn = realloc,332 .reallocFn = realloc,
332 .freeFn = free,333 .freeFn = free,
...@@ -348,8 +349,7 @@ pub const ThreadSafeFixedBufferAllocator = struct {...@@ -348,8 +349,7 @@ pub const ThreadSafeFixedBufferAllocator = struct {
348 if (new_end_index > self.buffer.len) {349 if (new_end_index > self.buffer.len) {
349 return error.OutOfMemory;350 return error.OutOfMemory;
350 }351 }
351 end_index = @cmpxchgWeak(usize, &self.end_index, end_index, new_end_index,352 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];
352 builtin.AtomicOrder.SeqCst, builtin.AtomicOrder.SeqCst) ?? return self.buffer[adjusted_index .. new_end_index];
353 }353 }
354 }354 }
355355
...@@ -363,11 +363,9 @@ pub const ThreadSafeFixedBufferAllocator = struct {...@@ -363,11 +363,9 @@ pub const ThreadSafeFixedBufferAllocator = struct {
363 }363 }
364 }364 }
365365
366 fn free(allocator: &Allocator, bytes: []u8) void { }366 fn free(allocator: &Allocator, bytes: []u8) void {}
367};367};
368368
369
370
371test "c_allocator" {369test "c_allocator" {
372 if (builtin.link_libc) {370 if (builtin.link_libc) {
373 var slice = c_allocator.alloc(u8, 50) catch return;371 var slice = c_allocator.alloc(u8, 50) catch return;
...@@ -415,8 +413,8 @@ fn testAllocator(allocator: &mem.Allocator) !void {...@@ -415,8 +413,8 @@ fn testAllocator(allocator: &mem.Allocator) !void {
415 var slice = try allocator.alloc(&i32, 100);413 var slice = try allocator.alloc(&i32, 100);
416414
417 for (slice) |*item, i| {415 for (slice) |*item, i| {
418 *item = try allocator.create(i32);416 item.* = try allocator.create(i32);
419 **item = i32(i);417 item.*.* = i32(i);
420 }418 }
421419
422 for (slice) |item, i| {420 for (slice) |item, i| {
...@@ -434,26 +432,26 @@ fn testAllocator(allocator: &mem.Allocator) !void {...@@ -434,26 +432,26 @@ fn testAllocator(allocator: &mem.Allocator) !void {
434fn testAllocatorLargeAlignment(allocator: &mem.Allocator) mem.Allocator.Error!void {432fn testAllocatorLargeAlignment(allocator: &mem.Allocator) mem.Allocator.Error!void {
435 //Maybe a platform's page_size is actually the same as or 433 //Maybe a platform's page_size is actually the same as or
436 // very near usize?434 // very near usize?
437 if(os.page_size << 2 > @maxValue(usize)) return;435 if (os.page_size << 2 > @maxValue(usize)) return;
438 436
439 const USizeShift = @IntType(false, std.math.log2(usize.bit_count));437 const USizeShift = @IntType(false, std.math.log2(usize.bit_count));
440 const large_align = u29(os.page_size << 2);438 const large_align = u29(os.page_size << 2);
441 439
442 var align_mask: usize = undefined;440 var align_mask: usize = undefined;
443 _ = @shlWithOverflow(usize, ~usize(0), USizeShift(@ctz(large_align)), &align_mask);441 _ = @shlWithOverflow(usize, ~usize(0), USizeShift(@ctz(large_align)), &align_mask);
444 442
445 var slice = try allocator.allocFn(allocator, 500, large_align);443 var slice = try allocator.allocFn(allocator, 500, large_align);
446 debug.assert(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));444 debug.assert(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
447 445
448 slice = try allocator.reallocFn(allocator, slice, 100, large_align);446 slice = try allocator.reallocFn(allocator, slice, 100, large_align);
449 debug.assert(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));447 debug.assert(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
450 448
451 slice = try allocator.reallocFn(allocator, slice, 5000, large_align);449 slice = try allocator.reallocFn(allocator, slice, 5000, large_align);
452 debug.assert(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));450 debug.assert(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
453 451
454 slice = try allocator.reallocFn(allocator, slice, 10, large_align);452 slice = try allocator.reallocFn(allocator, slice, 10, large_align);
455 debug.assert(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));453 debug.assert(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
456 454
457 slice = try allocator.reallocFn(allocator, slice, 20000, large_align);455 slice = try allocator.reallocFn(allocator, slice, 20000, large_align);
458 debug.assert(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));456 debug.assert(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr));
459457
std/io.zig+18-47
...@@ -18,32 +18,17 @@ const is_windows = builtin.os == builtin.Os.windows;...@@ -18,32 +18,17 @@ const is_windows = builtin.os == builtin.Os.windows;
18const GetStdIoErrs = os.WindowsGetStdHandleErrs;18const GetStdIoErrs = os.WindowsGetStdHandleErrs;
1919
20pub fn getStdErr() GetStdIoErrs!File {20pub fn getStdErr() GetStdIoErrs!File {
21 const handle = if (is_windows)21 const handle = if (is_windows) try os.windowsGetStdHandle(os.windows.STD_ERROR_HANDLE) else if (is_posix) os.posix.STDERR_FILENO else unreachable;
22 try os.windowsGetStdHandle(os.windows.STD_ERROR_HANDLE)
23 else if (is_posix)
24 os.posix.STDERR_FILENO
25 else
26 unreachable;
27 return File.openHandle(handle);22 return File.openHandle(handle);
28}23}
2924
30pub fn getStdOut() GetStdIoErrs!File {25pub fn getStdOut() GetStdIoErrs!File {
31 const handle = if (is_windows)26 const handle = if (is_windows) try os.windowsGetStdHandle(os.windows.STD_OUTPUT_HANDLE) else if (is_posix) os.posix.STDOUT_FILENO else unreachable;
32 try os.windowsGetStdHandle(os.windows.STD_OUTPUT_HANDLE)
33 else if (is_posix)
34 os.posix.STDOUT_FILENO
35 else
36 unreachable;
37 return File.openHandle(handle);27 return File.openHandle(handle);
38}28}
3929
40pub fn getStdIn() GetStdIoErrs!File {30pub fn getStdIn() GetStdIoErrs!File {
41 const handle = if (is_windows)31 const handle = if (is_windows) try os.windowsGetStdHandle(os.windows.STD_INPUT_HANDLE) else if (is_posix) os.posix.STDIN_FILENO else unreachable;
42 try os.windowsGetStdHandle(os.windows.STD_INPUT_HANDLE)
43 else if (is_posix)
44 os.posix.STDIN_FILENO
45 else
46 unreachable;
47 return File.openHandle(handle);32 return File.openHandle(handle);
48}33}
4934
...@@ -56,11 +41,9 @@ pub const FileInStream = struct {...@@ -56,11 +41,9 @@ pub const FileInStream = struct {
56 pub const Stream = InStream(Error);41 pub const Stream = InStream(Error);
5742
58 pub fn init(file: &File) FileInStream {43 pub fn init(file: &File) FileInStream {
59 return FileInStream {44 return FileInStream{
60 .file = file,45 .file = file,
61 .stream = Stream {46 .stream = Stream{ .readFn = readFn },
62 .readFn = readFn,
63 },
64 };47 };
65 }48 }
6649
...@@ -79,11 +62,9 @@ pub const FileOutStream = struct {...@@ -79,11 +62,9 @@ pub const FileOutStream = struct {
79 pub const Stream = OutStream(Error);62 pub const Stream = OutStream(Error);
8063
81 pub fn init(file: &File) FileOutStream {64 pub fn init(file: &File) FileOutStream {
82 return FileOutStream {65 return FileOutStream{
83 .file = file,66 .file = file,
84 .stream = Stream {67 .stream = Stream{ .writeFn = writeFn },
85 .writeFn = writeFn,
86 },
87 };68 };
88 }69 }
8970
...@@ -121,8 +102,7 @@ pub fn InStream(comptime ReadError: type) type {...@@ -121,8 +102,7 @@ pub fn InStream(comptime ReadError: type) type {
121 }102 }
122103
123 const new_buf_size = math.min(max_size, actual_buf_len + os.page_size);104 const new_buf_size = math.min(max_size, actual_buf_len + os.page_size);
124 if (new_buf_size == actual_buf_len)105 if (new_buf_size == actual_buf_len) return error.StreamTooLong;
125 return error.StreamTooLong;
126 try buffer.resize(new_buf_size);106 try buffer.resize(new_buf_size);
127 }107 }
128 }108 }
...@@ -165,9 +145,7 @@ pub fn InStream(comptime ReadError: type) type {...@@ -165,9 +145,7 @@ pub fn InStream(comptime ReadError: type) type {
165 /// memory would be greater than `max_size`, returns `error.StreamTooLong`.145 /// memory would be greater than `max_size`, returns `error.StreamTooLong`.
166 /// Caller owns returned memory.146 /// Caller owns returned memory.
167 /// If this function returns an error, the contents from the stream read so far are lost.147 /// If this function returns an error, the contents from the stream read so far are lost.
168 pub fn readUntilDelimiterAlloc(self: &Self, allocator: &mem.Allocator,148 pub fn readUntilDelimiterAlloc(self: &Self, allocator: &mem.Allocator, delimiter: u8, max_size: usize) ![]u8 {
169 delimiter: u8, max_size: usize) ![]u8
170 {
171 var buf = Buffer.initNull(allocator);149 var buf = Buffer.initNull(allocator);
172 defer buf.deinit();150 defer buf.deinit();
173151
...@@ -283,7 +261,7 @@ pub fn BufferedInStream(comptime Error: type) type {...@@ -283,7 +261,7 @@ pub fn BufferedInStream(comptime Error: type) type {
283pub fn BufferedInStreamCustom(comptime buffer_size: usize, comptime Error: type) type {261pub fn BufferedInStreamCustom(comptime buffer_size: usize, comptime Error: type) type {
284 return struct {262 return struct {
285 const Self = this;263 const Self = this;
286 const Stream = InStream(Error); 264 const Stream = InStream(Error);
287265
288 pub stream: Stream,266 pub stream: Stream,
289267
...@@ -294,7 +272,7 @@ pub fn BufferedInStreamCustom(comptime buffer_size: usize, comptime Error: type)...@@ -294,7 +272,7 @@ pub fn BufferedInStreamCustom(comptime buffer_size: usize, comptime Error: type)
294 end_index: usize,272 end_index: usize,
295273
296 pub fn init(unbuffered_in_stream: &Stream) Self {274 pub fn init(unbuffered_in_stream: &Stream) Self {
297 return Self {275 return Self{
298 .unbuffered_in_stream = unbuffered_in_stream,276 .unbuffered_in_stream = unbuffered_in_stream,
299 .buffer = undefined,277 .buffer = undefined,
300278
...@@ -305,9 +283,7 @@ pub fn BufferedInStreamCustom(comptime buffer_size: usize, comptime Error: type)...@@ -305,9 +283,7 @@ pub fn BufferedInStreamCustom(comptime buffer_size: usize, comptime Error: type)
305 .start_index = buffer_size,283 .start_index = buffer_size,
306 .end_index = buffer_size,284 .end_index = buffer_size,
307285
308 .stream = Stream {286 .stream = Stream{ .readFn = readFn },
309 .readFn = readFn,
310 },
311 };287 };
312 }288 }
313289
...@@ -368,13 +344,11 @@ pub fn BufferedOutStreamCustom(comptime buffer_size: usize, comptime OutStreamEr...@@ -368,13 +344,11 @@ pub fn BufferedOutStreamCustom(comptime buffer_size: usize, comptime OutStreamEr
368 index: usize,344 index: usize,
369345
370 pub fn init(unbuffered_out_stream: &Stream) Self {346 pub fn init(unbuffered_out_stream: &Stream) Self {
371 return Self {347 return Self{
372 .unbuffered_out_stream = unbuffered_out_stream,348 .unbuffered_out_stream = unbuffered_out_stream,
373 .buffer = undefined,349 .buffer = undefined,
374 .index = 0,350 .index = 0,
375 .stream = Stream {351 .stream = Stream{ .writeFn = writeFn },
376 .writeFn = writeFn,
377 },
378 };352 };
379 }353 }
380354
...@@ -416,11 +390,9 @@ pub const BufferOutStream = struct {...@@ -416,11 +390,9 @@ pub const BufferOutStream = struct {
416 pub const Stream = OutStream(Error);390 pub const Stream = OutStream(Error);
417391
418 pub fn init(buffer: &Buffer) BufferOutStream {392 pub fn init(buffer: &Buffer) BufferOutStream {
419 return BufferOutStream {393 return BufferOutStream{
420 .buffer = buffer,394 .buffer = buffer,
421 .stream = Stream {395 .stream = Stream{ .writeFn = writeFn },
422 .writeFn = writeFn,
423 },
424 };396 };
425 }397 }
426398
...@@ -430,7 +402,6 @@ pub const BufferOutStream = struct {...@@ -430,7 +402,6 @@ pub const BufferOutStream = struct {
430 }402 }
431};403};
432404
433
434pub const BufferedAtomicFile = struct {405pub const BufferedAtomicFile = struct {
435 atomic_file: os.AtomicFile,406 atomic_file: os.AtomicFile,
436 file_stream: FileOutStream,407 file_stream: FileOutStream,
...@@ -441,7 +412,7 @@ pub const BufferedAtomicFile = struct {...@@ -441,7 +412,7 @@ pub const BufferedAtomicFile = struct {
441 var self = try allocator.create(BufferedAtomicFile);412 var self = try allocator.create(BufferedAtomicFile);
442 errdefer allocator.destroy(self);413 errdefer allocator.destroy(self);
443414
444 *self = BufferedAtomicFile {415 self.* = BufferedAtomicFile{
445 .atomic_file = undefined,416 .atomic_file = undefined,
446 .file_stream = undefined,417 .file_stream = undefined,
447 .buffered_stream = undefined,418 .buffered_stream = undefined,
...@@ -489,7 +460,7 @@ pub fn readLine(buf: []u8) !usize {...@@ -489,7 +460,7 @@ pub fn readLine(buf: []u8) !usize {
489 '\r' => {460 '\r' => {
490 // trash the following \n461 // trash the following \n
491 _ = stream.readByte() catch return error.EndOfFile;462 _ = stream.readByte() catch return error.EndOfFile;
492 return index;463 return index;
493 },464 },
494 '\n' => return index,465 '\n' => return index,
495 else => {466 else => {
std/linked_list.zig+55-40
...@@ -26,10 +26,10 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na...@@ -26,10 +26,10 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
26 data: T,26 data: T,
2727
28 pub fn init(value: &const T) Node {28 pub fn init(value: &const T) Node {
29 return Node {29 return Node{
30 .prev = null,30 .prev = null,
31 .next = null,31 .next = null,
32 .data = *value,32 .data = value.*,
33 };33 };
34 }34 }
3535
...@@ -45,18 +45,18 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na...@@ -45,18 +45,18 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
45 };45 };
4646
47 first: ?&Node,47 first: ?&Node,
48 last: ?&Node,48 last: ?&Node,
49 len: usize,49 len: usize,
5050
51 /// Initialize a linked list.51 /// Initialize a linked list.
52 ///52 ///
53 /// Returns:53 /// Returns:
54 /// An empty linked list.54 /// An empty linked list.
55 pub fn init() Self {55 pub fn init() Self {
56 return Self {56 return Self{
57 .first = null,57 .first = null,
58 .last = null,58 .last = null,
59 .len = 0,59 .len = 0,
60 };60 };
61 }61 }
6262
...@@ -131,7 +131,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na...@@ -131,7 +131,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
131 } else {131 } else {
132 // Empty list.132 // Empty list.
133 list.first = new_node;133 list.first = new_node;
134 list.last = new_node;134 list.last = new_node;
135 new_node.prev = null;135 new_node.prev = null;
136 new_node.next = null;136 new_node.next = null;
137137
...@@ -217,7 +217,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na...@@ -217,7 +217,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na
217 pub fn createNode(list: &Self, data: &const T, allocator: &Allocator) !&Node {217 pub fn createNode(list: &Self, data: &const T, allocator: &Allocator) !&Node {
218 comptime assert(!isIntrusive());218 comptime assert(!isIntrusive());
219 var node = try list.allocateNode(allocator);219 var node = try list.allocateNode(allocator);
220 *node = Node.init(data);220 node.* = Node.init(data);
221 return node;221 return node;
222 }222 }
223 };223 };
...@@ -227,11 +227,11 @@ test "basic linked list test" {...@@ -227,11 +227,11 @@ test "basic linked list test" {
227 const allocator = debug.global_allocator;227 const allocator = debug.global_allocator;
228 var list = LinkedList(u32).init();228 var list = LinkedList(u32).init();
229229
230 var one = try list.createNode(1, allocator);230 var one = try list.createNode(1, allocator);
231 var two = try list.createNode(2, allocator);231 var two = try list.createNode(2, allocator);
232 var three = try list.createNode(3, allocator);232 var three = try list.createNode(3, allocator);
233 var four = try list.createNode(4, allocator);233 var four = try list.createNode(4, allocator);
234 var five = try list.createNode(5, allocator);234 var five = try list.createNode(5, allocator);
235 defer {235 defer {
236 list.destroyNode(one, allocator);236 list.destroyNode(one, allocator);
237 list.destroyNode(two, allocator);237 list.destroyNode(two, allocator);
...@@ -240,11 +240,11 @@ test "basic linked list test" {...@@ -240,11 +240,11 @@ test "basic linked list test" {
240 list.destroyNode(five, allocator);240 list.destroyNode(five, allocator);
241 }241 }
242242
243 list.append(two); // {2}243 list.append(two); // {2}
244 list.append(five); // {2, 5}244 list.append(five); // {2, 5}
245 list.prepend(one); // {1, 2, 5}245 list.prepend(one); // {1, 2, 5}
246 list.insertBefore(five, four); // {1, 2, 4, 5}246 list.insertBefore(five, four); // {1, 2, 4, 5}
247 list.insertAfter(two, three); // {1, 2, 3, 4, 5}247 list.insertAfter(two, three); // {1, 2, 3, 4, 5}
248248
249 // Traverse forwards.249 // Traverse forwards.
250 {250 {
...@@ -266,13 +266,13 @@ test "basic linked list test" {...@@ -266,13 +266,13 @@ test "basic linked list test" {
266 }266 }
267 }267 }
268268
269 var first = list.popFirst(); // {2, 3, 4, 5}269 var first = list.popFirst(); // {2, 3, 4, 5}
270 var last = list.pop(); // {2, 3, 4}270 var last = list.pop(); // {2, 3, 4}
271 list.remove(three); // {2, 4}271 list.remove(three); // {2, 4}
272272
273 assert ((??list.first).data == 2);273 assert((??list.first).data == 2);
274 assert ((??list.last ).data == 4);274 assert((??list.last).data == 4);
275 assert (list.len == 2);275 assert(list.len == 2);
276}276}
277277
278const ElementList = IntrusiveLinkedList(Element, "link");278const ElementList = IntrusiveLinkedList(Element, "link");
...@@ -285,17 +285,32 @@ test "basic intrusive linked list test" {...@@ -285,17 +285,32 @@ test "basic intrusive linked list test" {
285 const allocator = debug.global_allocator;285 const allocator = debug.global_allocator;
286 var list = ElementList.init();286 var list = ElementList.init();
287287
288 var one = Element { .value = 1, .link = ElementList.Node.initIntrusive() };288 var one = Element{
289 var two = Element { .value = 2, .link = ElementList.Node.initIntrusive() };289 .value = 1,
290 var three = Element { .value = 3, .link = ElementList.Node.initIntrusive() };290 .link = ElementList.Node.initIntrusive(),
291 var four = Element { .value = 4, .link = ElementList.Node.initIntrusive() };291 };
292 var five = Element { .value = 5, .link = ElementList.Node.initIntrusive() };292 var two = Element{
293 .value = 2,
294 .link = ElementList.Node.initIntrusive(),
295 };
296 var three = Element{
297 .value = 3,
298 .link = ElementList.Node.initIntrusive(),
299 };
300 var four = Element{
301 .value = 4,
302 .link = ElementList.Node.initIntrusive(),
303 };
304 var five = Element{
305 .value = 5,
306 .link = ElementList.Node.initIntrusive(),
307 };
293308
294 list.append(&two.link); // {2}309 list.append(&two.link); // {2}
295 list.append(&five.link); // {2, 5}310 list.append(&five.link); // {2, 5}
296 list.prepend(&one.link); // {1, 2, 5}311 list.prepend(&one.link); // {1, 2, 5}
297 list.insertBefore(&five.link, &four.link); // {1, 2, 4, 5}312 list.insertBefore(&five.link, &four.link); // {1, 2, 4, 5}
298 list.insertAfter(&two.link, &three.link); // {1, 2, 3, 4, 5}313 list.insertAfter(&two.link, &three.link); // {1, 2, 3, 4, 5}
299314
300 // Traverse forwards.315 // Traverse forwards.
301 {316 {
...@@ -317,11 +332,11 @@ test "basic intrusive linked list test" {...@@ -317,11 +332,11 @@ test "basic intrusive linked list test" {
317 }332 }
318 }333 }
319334
320 var first = list.popFirst(); // {2, 3, 4, 5}335 var first = list.popFirst(); // {2, 3, 4, 5}
321 var last = list.pop(); // {2, 3, 4}336 var last = list.pop(); // {2, 3, 4}
322 list.remove(&three.link); // {2, 4}337 list.remove(&three.link); // {2, 4}
323338
324 assert ((??list.first).toData().value == 2);339 assert((??list.first).toData().value == 2);
325 assert ((??list.last ).toData().value == 4);340 assert((??list.last).toData().value == 4);
326 assert (list.len == 2);341 assert(list.len == 2);
327}342}
std/os/index.zig+38-42
...@@ -137,7 +137,7 @@ pub fn getRandomBytes(buf: []u8) !void {...@@ -137,7 +137,7 @@ pub fn getRandomBytes(buf: []u8) !void {
137 }137 }
138 },138 },
139 Os.zen => {139 Os.zen => {
140 const randomness = []u8 {140 const randomness = []u8{
141 42,141 42,
142 1,142 1,
143 7,143 7,
...@@ -265,7 +265,7 @@ pub fn posixRead(fd: i32, buf: []u8) !void {...@@ -265,7 +265,7 @@ pub fn posixRead(fd: i32, buf: []u8) !void {
265 }265 }
266}266}
267267
268pub const PosixWriteError = error {268pub const PosixWriteError = error{
269 WouldBlock,269 WouldBlock,
270 FileClosed,270 FileClosed,
271 DestinationAddressRequired,271 DestinationAddressRequired,
...@@ -310,7 +310,7 @@ pub fn posixWrite(fd: i32, bytes: []const u8) !void {...@@ -310,7 +310,7 @@ pub fn posixWrite(fd: i32, bytes: []const u8) !void {
310 }310 }
311}311}
312312
313pub const PosixOpenError = error {313pub const PosixOpenError = error{
314 OutOfMemory,314 OutOfMemory,
315 AccessDenied,315 AccessDenied,
316 FileTooBig,316 FileTooBig,
...@@ -477,7 +477,7 @@ pub fn posixExecve(argv: []const []const u8, env_map: &const BufMap, allocator:...@@ -477,7 +477,7 @@ pub fn posixExecve(argv: []const []const u8, env_map: &const BufMap, allocator:
477 return posixExecveErrnoToErr(err);477 return posixExecveErrnoToErr(err);
478}478}
479479
480pub const PosixExecveError = error {480pub const PosixExecveError = error{
481 SystemResources,481 SystemResources,
482 AccessDenied,482 AccessDenied,
483 InvalidExe,483 InvalidExe,
...@@ -512,7 +512,7 @@ fn posixExecveErrnoToErr(err: usize) PosixExecveError {...@@ -512,7 +512,7 @@ fn posixExecveErrnoToErr(err: usize) PosixExecveError {
512 };512 };
513}513}
514514
515pub var linux_aux_raw = []usize {0} ** 38;515pub var linux_aux_raw = []usize{0} ** 38;
516pub var posix_environ_raw: []&u8 = undefined;516pub var posix_environ_raw: []&u8 = undefined;
517517
518/// Caller must free result when done.518/// Caller must free result when done.
...@@ -667,7 +667,7 @@ pub fn symLink(allocator: &Allocator, existing_path: []const u8, new_path: []con...@@ -667,7 +667,7 @@ pub fn symLink(allocator: &Allocator, existing_path: []const u8, new_path: []con
667 }667 }
668}668}
669669
670pub const WindowsSymLinkError = error {670pub const WindowsSymLinkError = error{
671 OutOfMemory,671 OutOfMemory,
672 Unexpected,672 Unexpected,
673};673};
...@@ -686,7 +686,7 @@ pub fn symLinkWindows(allocator: &Allocator, existing_path: []const u8, new_path...@@ -686,7 +686,7 @@ pub fn symLinkWindows(allocator: &Allocator, existing_path: []const u8, new_path
686 }686 }
687}687}
688688
689pub const PosixSymLinkError = error {689pub const PosixSymLinkError = error{
690 OutOfMemory,690 OutOfMemory,
691 AccessDenied,691 AccessDenied,
692 DiskQuota,692 DiskQuota,
...@@ -895,7 +895,7 @@ pub const AtomicFile = struct {...@@ -895,7 +895,7 @@ pub const AtomicFile = struct {
895 else => return err,895 else => return err,
896 };896 };
897897
898 return AtomicFile {898 return AtomicFile{
899 .allocator = allocator,899 .allocator = allocator,
900 .file = file,900 .file = file,
901 .tmp_path = tmp_path,901 .tmp_path = tmp_path,
...@@ -1087,7 +1087,7 @@ pub fn deleteDir(allocator: &Allocator, dir_path: []const u8) !void {...@@ -1087,7 +1087,7 @@ pub fn deleteDir(allocator: &Allocator, dir_path: []const u8) !void {
1087/// removes it. If it cannot be removed because it is a non-empty directory,1087/// removes it. If it cannot be removed because it is a non-empty directory,
1088/// this function recursively removes its entries and then tries again.1088/// this function recursively removes its entries and then tries again.
1089/// TODO non-recursive implementation1089/// TODO non-recursive implementation
1090const DeleteTreeError = error {1090const DeleteTreeError = error{
1091 OutOfMemory,1091 OutOfMemory,
1092 AccessDenied,1092 AccessDenied,
1093 FileTooBig,1093 FileTooBig,
...@@ -1217,7 +1217,7 @@ pub const Dir = struct {...@@ -1217,7 +1217,7 @@ pub const Dir = struct {
1217 Os.ios => 0,1217 Os.ios => 0,
1218 else => {},1218 else => {},
1219 };1219 };
1220 return Dir {1220 return Dir{
1221 .allocator = allocator,1221 .allocator = allocator,
1222 .fd = fd,1222 .fd = fd,
1223 .darwin_seek = darwin_seek_init,1223 .darwin_seek = darwin_seek_init,
...@@ -1294,7 +1294,7 @@ pub const Dir = struct {...@@ -1294,7 +1294,7 @@ pub const Dir = struct {
1294 posix.DT_WHT => Entry.Kind.Whiteout,1294 posix.DT_WHT => Entry.Kind.Whiteout,
1295 else => Entry.Kind.Unknown,1295 else => Entry.Kind.Unknown,
1296 };1296 };
1297 return Entry {1297 return Entry{
1298 .name = name,1298 .name = name,
1299 .kind = entry_kind,1299 .kind = entry_kind,
1300 };1300 };
...@@ -1355,7 +1355,7 @@ pub const Dir = struct {...@@ -1355,7 +1355,7 @@ pub const Dir = struct {
1355 posix.DT_SOCK => Entry.Kind.UnixDomainSocket,1355 posix.DT_SOCK => Entry.Kind.UnixDomainSocket,
1356 else => Entry.Kind.Unknown,1356 else => Entry.Kind.Unknown,
1357 };1357 };
1358 return Entry {1358 return Entry{
1359 .name = name,1359 .name = name,
1360 .kind = entry_kind,1360 .kind = entry_kind,
1361 };1361 };
...@@ -1465,7 +1465,7 @@ pub fn posix_setregid(rgid: u32, egid: u32) !void {...@@ -1465,7 +1465,7 @@ pub fn posix_setregid(rgid: u32, egid: u32) !void {
1465 };1465 };
1466}1466}
14671467
1468pub const WindowsGetStdHandleErrs = error {1468pub const WindowsGetStdHandleErrs = error{
1469 NoStdHandles,1469 NoStdHandles,
1470 Unexpected,1470 Unexpected,
1471};1471};
...@@ -1489,7 +1489,7 @@ pub const ArgIteratorPosix = struct {...@@ -1489,7 +1489,7 @@ pub const ArgIteratorPosix = struct {
1489 count: usize,1489 count: usize,
14901490
1491 pub fn init() ArgIteratorPosix {1491 pub fn init() ArgIteratorPosix {
1492 return ArgIteratorPosix {1492 return ArgIteratorPosix{
1493 .index = 0,1493 .index = 0,
1494 .count = raw.len,1494 .count = raw.len,
1495 };1495 };
...@@ -1522,16 +1522,14 @@ pub const ArgIteratorWindows = struct {...@@ -1522,16 +1522,14 @@ pub const ArgIteratorWindows = struct {
1522 quote_count: usize,1522 quote_count: usize,
1523 seen_quote_count: usize,1523 seen_quote_count: usize,
15241524
1525 pub const NextError = error {1525 pub const NextError = error{OutOfMemory};
1526 OutOfMemory,
1527 };
15281526
1529 pub fn init() ArgIteratorWindows {1527 pub fn init() ArgIteratorWindows {
1530 return initWithCmdLine(windows.GetCommandLineA());1528 return initWithCmdLine(windows.GetCommandLineA());
1531 }1529 }
15321530
1533 pub fn initWithCmdLine(cmd_line: &const u8) ArgIteratorWindows {1531 pub fn initWithCmdLine(cmd_line: &const u8) ArgIteratorWindows {
1534 return ArgIteratorWindows {1532 return ArgIteratorWindows{
1535 .index = 0,1533 .index = 0,
1536 .cmd_line = cmd_line,1534 .cmd_line = cmd_line,
1537 .in_quote = false,1535 .in_quote = false,
...@@ -1676,9 +1674,7 @@ pub const ArgIterator = struct {...@@ -1676,9 +1674,7 @@ pub const ArgIterator = struct {
1676 inner: InnerType,1674 inner: InnerType,
16771675
1678 pub fn init() ArgIterator {1676 pub fn init() ArgIterator {
1679 return ArgIterator {1677 return ArgIterator{ .inner = InnerType.init() };
1680 .inner = InnerType.init(),
1681 };
1682 }1678 }
16831679
1684 pub const NextError = ArgIteratorWindows.NextError;1680 pub const NextError = ArgIteratorWindows.NextError;
...@@ -1757,33 +1753,33 @@ pub fn argsFree(allocator: &mem.Allocator, args_alloc: []const []u8) void {...@@ -1757,33 +1753,33 @@ pub fn argsFree(allocator: &mem.Allocator, args_alloc: []const []u8) void {
1757}1753}
17581754
1759test "windows arg parsing" {1755test "windows arg parsing" {
1760 testWindowsCmdLine(c"a b\tc d", [][]const u8 {1756 testWindowsCmdLine(c"a b\tc d", [][]const u8{
1761 "a",1757 "a",
1762 "b",1758 "b",
1763 "c",1759 "c",
1764 "d",1760 "d",
1765 });1761 });
1766 testWindowsCmdLine(c"\"abc\" d e", [][]const u8 {1762 testWindowsCmdLine(c"\"abc\" d e", [][]const u8{
1767 "abc",1763 "abc",
1768 "d",1764 "d",
1769 "e",1765 "e",
1770 });1766 });
1771 testWindowsCmdLine(c"a\\\\\\b d\"e f\"g h", [][]const u8 {1767 testWindowsCmdLine(c"a\\\\\\b d\"e f\"g h", [][]const u8{
1772 "a\\\\\\b",1768 "a\\\\\\b",
1773 "de fg",1769 "de fg",
1774 "h",1770 "h",
1775 });1771 });
1776 testWindowsCmdLine(c"a\\\\\\\"b c d", [][]const u8 {1772 testWindowsCmdLine(c"a\\\\\\\"b c d", [][]const u8{
1777 "a\\\"b",1773 "a\\\"b",
1778 "c",1774 "c",
1779 "d",1775 "d",
1780 });1776 });
1781 testWindowsCmdLine(c"a\\\\\\\\\"b c\" d e", [][]const u8 {1777 testWindowsCmdLine(c"a\\\\\\\\\"b c\" d e", [][]const u8{
1782 "a\\\\b c",1778 "a\\\\b c",
1783 "d",1779 "d",
1784 "e",1780 "e",
1785 });1781 });
1786 testWindowsCmdLine(c"a b\tc \"d f", [][]const u8 {1782 testWindowsCmdLine(c"a b\tc \"d f", [][]const u8{
1787 "a",1783 "a",
1788 "b",1784 "b",
1789 "c",1785 "c",
...@@ -1791,7 +1787,7 @@ test "windows arg parsing" {...@@ -1791,7 +1787,7 @@ test "windows arg parsing" {
1791 "f",1787 "f",
1792 });1788 });
17931789
1794 testWindowsCmdLine(c"\".\\..\\zig-cache\\build\" \"bin\\zig.exe\" \".\\..\" \".\\..\\zig-cache\" \"--help\"", [][]const u8 {1790 testWindowsCmdLine(c"\".\\..\\zig-cache\\build\" \"bin\\zig.exe\" \".\\..\" \".\\..\\zig-cache\" \"--help\"", [][]const u8{
1795 ".\\..\\zig-cache\\build",1791 ".\\..\\zig-cache\\build",
1796 "bin\\zig.exe",1792 "bin\\zig.exe",
1797 ".\\..",1793 ".\\..",
...@@ -1811,7 +1807,7 @@ fn testWindowsCmdLine(input_cmd_line: &const u8, expected_args: []const []const...@@ -1811,7 +1807,7 @@ fn testWindowsCmdLine(input_cmd_line: &const u8, expected_args: []const []const
18111807
1812// TODO make this a build variable that you can set1808// TODO make this a build variable that you can set
1813const unexpected_error_tracing = false;1809const unexpected_error_tracing = false;
1814const UnexpectedError = error {1810const UnexpectedError = error{
1815 /// The Operating System returned an undocumented error code.1811 /// The Operating System returned an undocumented error code.
1816 Unexpected,1812 Unexpected,
1817};1813};
...@@ -1950,7 +1946,7 @@ pub fn isTty(handle: FileHandle) bool {...@@ -1950,7 +1946,7 @@ pub fn isTty(handle: FileHandle) bool {
1950 }1946 }
1951}1947}
19521948
1953pub const PosixSocketError = error {1949pub const PosixSocketError = error{
1954 /// Permission to create a socket of the specified type and/or1950 /// Permission to create a socket of the specified type and/or
1955 /// pro‐tocol is denied.1951 /// pro‐tocol is denied.
1956 PermissionDenied,1952 PermissionDenied,
...@@ -1992,7 +1988,7 @@ pub fn posixSocket(domain: u32, socket_type: u32, protocol: u32) !i32 {...@@ -1992,7 +1988,7 @@ pub fn posixSocket(domain: u32, socket_type: u32, protocol: u32) !i32 {
1992 }1988 }
1993}1989}
19941990
1995pub const PosixBindError = error {1991pub const PosixBindError = error{
1996 /// The address is protected, and the user is not the superuser.1992 /// The address is protected, and the user is not the superuser.
1997 /// For UNIX domain sockets: Search permission is denied on a component 1993 /// For UNIX domain sockets: Search permission is denied on a component
1998 /// of the path prefix.1994 /// of the path prefix.
...@@ -2065,7 +2061,7 @@ pub fn posixBind(fd: i32, addr: &const posix.sockaddr) PosixBindError!void {...@@ -2065,7 +2061,7 @@ pub fn posixBind(fd: i32, addr: &const posix.sockaddr) PosixBindError!void {
2065 }2061 }
2066}2062}
20672063
2068const PosixListenError = error {2064const PosixListenError = error{
2069 /// Another socket is already listening on the same port.2065 /// Another socket is already listening on the same port.
2070 /// For Internet domain sockets, the socket referred to by sockfd had not previously2066 /// For Internet domain sockets, the socket referred to by sockfd had not previously
2071 /// been bound to an address and, upon attempting to bind it to an ephemeral port, it2067 /// 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 {...@@ -2098,7 +2094,7 @@ pub fn posixListen(sockfd: i32, backlog: u32) PosixListenError!void {
2098 }2094 }
2099}2095}
21002096
2101pub const PosixAcceptError = error {2097pub const PosixAcceptError = error{
2102 /// The socket is marked nonblocking and no connections are present to be accepted.2098 /// The socket is marked nonblocking and no connections are present to be accepted.
2103 WouldBlock,2099 WouldBlock,
21042100
...@@ -2165,7 +2161,7 @@ pub fn posixAccept(fd: i32, addr: &posix.sockaddr, flags: u32) PosixAcceptError!...@@ -2165,7 +2161,7 @@ pub fn posixAccept(fd: i32, addr: &posix.sockaddr, flags: u32) PosixAcceptError!
2165 }2161 }
2166}2162}
21672163
2168pub const LinuxEpollCreateError = error {2164pub const LinuxEpollCreateError = error{
2169 /// Invalid value specified in flags.2165 /// Invalid value specified in flags.
2170 InvalidSyscall,2166 InvalidSyscall,
21712167
...@@ -2198,7 +2194,7 @@ pub fn linuxEpollCreate(flags: u32) LinuxEpollCreateError!i32 {...@@ -2198,7 +2194,7 @@ pub fn linuxEpollCreate(flags: u32) LinuxEpollCreateError!i32 {
2198 }2194 }
2199}2195}
22002196
2201pub const LinuxEpollCtlError = error {2197pub const LinuxEpollCtlError = error{
2202 /// epfd or fd is not a valid file descriptor.2198 /// epfd or fd is not a valid file descriptor.
2203 InvalidFileDescriptor,2199 InvalidFileDescriptor,
22042200
...@@ -2271,7 +2267,7 @@ pub fn linuxEpollWait(epfd: i32, events: []linux.epoll_event, timeout: i32) usiz...@@ -2271,7 +2267,7 @@ pub fn linuxEpollWait(epfd: i32, events: []linux.epoll_event, timeout: i32) usiz
2271 }2267 }
2272}2268}
22732269
2274pub const PosixGetSockNameError = error {2270pub const PosixGetSockNameError = error{
2275 /// Insufficient resources were available in the system to perform the operation.2271 /// Insufficient resources were available in the system to perform the operation.
2276 SystemResources,2272 SystemResources,
22772273
...@@ -2295,7 +2291,7 @@ pub fn posixGetSockName(sockfd: i32) PosixGetSockNameError!posix.sockaddr {...@@ -2295,7 +2291,7 @@ pub fn posixGetSockName(sockfd: i32) PosixGetSockNameError!posix.sockaddr {
2295 }2291 }
2296}2292}
22972293
2298pub const PosixConnectError = error {2294pub const PosixConnectError = error{
2299 /// For UNIX domain sockets, which are identified by pathname: Write permission is denied on the socket2295 /// For UNIX domain sockets, which are identified by pathname: Write permission is denied on the socket
2300 /// file, or search permission is denied for one of the directories in the path prefix.2296 /// file, or search permission is denied for one of the directories in the path prefix.
2301 /// or2297 /// or
...@@ -2484,7 +2480,7 @@ pub const Thread = struct {...@@ -2484,7 +2480,7 @@ pub const Thread = struct {
2484 }2480 }
2485};2481};
24862482
2487pub const SpawnThreadError = error {2483pub const SpawnThreadError = error{
2488 /// A system-imposed limit on the number of threads was encountered.2484 /// A system-imposed limit on the number of threads was encountered.
2489 /// There are a number of limits that may trigger this error:2485 /// There are a number of limits that may trigger this error:
2490 /// * the RLIMIT_NPROC soft resource limit (set via setrlimit(2)),2486 /// * the RLIMIT_NPROC soft resource limit (set via setrlimit(2)),
...@@ -2532,7 +2528,7 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!&Thread...@@ -2532,7 +2528,7 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!&Thread
2532 if (@sizeOf(Context) == 0) {2528 if (@sizeOf(Context) == 0) {
2533 return startFn({});2529 return startFn({});
2534 } else {2530 } else {
2535 return startFn(*@ptrCast(&Context, @alignCast(@alignOf(Context), arg)));2531 return startFn(@ptrCast(&Context, @alignCast(@alignOf(Context), arg)).*);
2536 }2532 }
2537 }2533 }
2538 };2534 };
...@@ -2562,7 +2558,7 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!&Thread...@@ -2562,7 +2558,7 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!&Thread
2562 if (@sizeOf(Context) == 0) {2558 if (@sizeOf(Context) == 0) {
2563 return startFn({});2559 return startFn({});
2564 } else {2560 } else {
2565 return startFn(*@intToPtr(&const Context, ctx_addr));2561 return startFn(@intToPtr(&const Context, ctx_addr).*);
2566 }2562 }
2567 }2563 }
2568 extern fn posixThreadMain(ctx: ?&c_void) ?&c_void {2564 extern fn posixThreadMain(ctx: ?&c_void) ?&c_void {
...@@ -2570,7 +2566,7 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!&Thread...@@ -2570,7 +2566,7 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!&Thread
2570 _ = startFn({});2566 _ = startFn({});
2571 return null;2567 return null;
2572 } else {2568 } else {
2573 _ = startFn(*@ptrCast(&const Context, @alignCast(@alignOf(Context), ctx)));2569 _ = startFn(@ptrCast(&const Context, @alignCast(@alignOf(Context), ctx)).*);
2574 return null;2570 return null;
2575 }2571 }
2576 }2572 }
...@@ -2590,7 +2586,7 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!&Thread...@@ -2590,7 +2586,7 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!&Thread
2590 stack_end -= stack_end % @alignOf(Context);2586 stack_end -= stack_end % @alignOf(Context);
2591 assert(stack_end >= stack_addr);2587 assert(stack_end >= stack_addr);
2592 const context_ptr = @alignCast(@alignOf(Context), @intToPtr(&Context, stack_end));2588 const context_ptr = @alignCast(@alignOf(Context), @intToPtr(&Context, stack_end));
2593 *context_ptr = context;2589 context_ptr.* = context;
2594 arg = stack_end;2590 arg = stack_end;
2595 }2591 }
25962592
std/os/linux/index.zig+189-190
...@@ -30,96 +30,95 @@ pub const FUTEX_PRIVATE_FLAG = 128;...@@ -30,96 +30,95 @@ pub const FUTEX_PRIVATE_FLAG = 128;
3030
31pub const FUTEX_CLOCK_REALTIME = 256;31pub const FUTEX_CLOCK_REALTIME = 256;
3232
3333pub const PROT_NONE = 0;
34pub const PROT_NONE = 0;34pub const PROT_READ = 1;
35pub const PROT_READ = 1;35pub const PROT_WRITE = 2;
36pub const PROT_WRITE = 2;36pub const PROT_EXEC = 4;
37pub const PROT_EXEC = 4;
38pub const PROT_GROWSDOWN = 0x01000000;37pub const PROT_GROWSDOWN = 0x01000000;
39pub const PROT_GROWSUP = 0x02000000;38pub const PROT_GROWSUP = 0x02000000;
4039
41pub const MAP_FAILED = @maxValue(usize);40pub const MAP_FAILED = @maxValue(usize);
42pub const MAP_SHARED = 0x01;41pub const MAP_SHARED = 0x01;
43pub const MAP_PRIVATE = 0x02;42pub const MAP_PRIVATE = 0x02;
44pub const MAP_TYPE = 0x0f;43pub const MAP_TYPE = 0x0f;
45pub const MAP_FIXED = 0x10;44pub const MAP_FIXED = 0x10;
46pub const MAP_ANONYMOUS = 0x20;45pub const MAP_ANONYMOUS = 0x20;
47pub const MAP_NORESERVE = 0x4000;46pub const MAP_NORESERVE = 0x4000;
48pub const MAP_GROWSDOWN = 0x0100;47pub const MAP_GROWSDOWN = 0x0100;
49pub const MAP_DENYWRITE = 0x0800;48pub const MAP_DENYWRITE = 0x0800;
50pub const MAP_EXECUTABLE = 0x1000;49pub const MAP_EXECUTABLE = 0x1000;
51pub const MAP_LOCKED = 0x2000;50pub const MAP_LOCKED = 0x2000;
52pub const MAP_POPULATE = 0x8000;51pub const MAP_POPULATE = 0x8000;
53pub const MAP_NONBLOCK = 0x10000;52pub const MAP_NONBLOCK = 0x10000;
54pub const MAP_STACK = 0x20000;53pub const MAP_STACK = 0x20000;
55pub const MAP_HUGETLB = 0x40000;54pub const MAP_HUGETLB = 0x40000;
56pub const MAP_FILE = 0;55pub const MAP_FILE = 0;
5756
58pub const F_OK = 0;57pub const F_OK = 0;
59pub const X_OK = 1;58pub const X_OK = 1;
60pub const W_OK = 2;59pub const W_OK = 2;
61pub const R_OK = 4;60pub const R_OK = 4;
6261
63pub const WNOHANG = 1;62pub const WNOHANG = 1;
64pub const WUNTRACED = 2;63pub const WUNTRACED = 2;
65pub const WSTOPPED = 2;64pub const WSTOPPED = 2;
66pub const WEXITED = 4;65pub const WEXITED = 4;
67pub const WCONTINUED = 8;66pub const WCONTINUED = 8;
68pub const WNOWAIT = 0x1000000;67pub const WNOWAIT = 0x1000000;
6968
70pub const SA_NOCLDSTOP = 1;69pub const SA_NOCLDSTOP = 1;
71pub const SA_NOCLDWAIT = 2;70pub const SA_NOCLDWAIT = 2;
72pub const SA_SIGINFO = 4;71pub const SA_SIGINFO = 4;
73pub const SA_ONSTACK = 0x08000000;72pub const SA_ONSTACK = 0x08000000;
74pub const SA_RESTART = 0x10000000;73pub const SA_RESTART = 0x10000000;
75pub const SA_NODEFER = 0x40000000;74pub const SA_NODEFER = 0x40000000;
76pub const SA_RESETHAND = 0x80000000;75pub const SA_RESETHAND = 0x80000000;
77pub const SA_RESTORER = 0x04000000;76pub const SA_RESTORER = 0x04000000;
7877
79pub const SIGHUP = 1;78pub const SIGHUP = 1;
80pub const SIGINT = 2;79pub const SIGINT = 2;
81pub const SIGQUIT = 3;80pub const SIGQUIT = 3;
82pub const SIGILL = 4;81pub const SIGILL = 4;
83pub const SIGTRAP = 5;82pub const SIGTRAP = 5;
84pub const SIGABRT = 6;83pub const SIGABRT = 6;
85pub const SIGIOT = SIGABRT;84pub const SIGIOT = SIGABRT;
86pub const SIGBUS = 7;85pub const SIGBUS = 7;
87pub const SIGFPE = 8;86pub const SIGFPE = 8;
88pub const SIGKILL = 9;87pub const SIGKILL = 9;
89pub const SIGUSR1 = 10;88pub const SIGUSR1 = 10;
90pub const SIGSEGV = 11;89pub const SIGSEGV = 11;
91pub const SIGUSR2 = 12;90pub const SIGUSR2 = 12;
92pub const SIGPIPE = 13;91pub const SIGPIPE = 13;
93pub const SIGALRM = 14;92pub const SIGALRM = 14;
94pub const SIGTERM = 15;93pub const SIGTERM = 15;
95pub const SIGSTKFLT = 16;94pub const SIGSTKFLT = 16;
96pub const SIGCHLD = 17;95pub const SIGCHLD = 17;
97pub const SIGCONT = 18;96pub const SIGCONT = 18;
98pub const SIGSTOP = 19;97pub const SIGSTOP = 19;
99pub const SIGTSTP = 20;98pub const SIGTSTP = 20;
100pub const SIGTTIN = 21;99pub const SIGTTIN = 21;
101pub const SIGTTOU = 22;100pub const SIGTTOU = 22;
102pub const SIGURG = 23;101pub const SIGURG = 23;
103pub const SIGXCPU = 24;102pub const SIGXCPU = 24;
104pub const SIGXFSZ = 25;103pub const SIGXFSZ = 25;
105pub const SIGVTALRM = 26;104pub const SIGVTALRM = 26;
106pub const SIGPROF = 27;105pub const SIGPROF = 27;
107pub const SIGWINCH = 28;106pub const SIGWINCH = 28;
108pub const SIGIO = 29;107pub const SIGIO = 29;
109pub const SIGPOLL = 29;108pub const SIGPOLL = 29;
110pub const SIGPWR = 30;109pub const SIGPWR = 30;
111pub const SIGSYS = 31;110pub const SIGSYS = 31;
112pub const SIGUNUSED = SIGSYS;111pub const SIGUNUSED = SIGSYS;
113112
114pub const O_RDONLY = 0o0;113pub const O_RDONLY = 0o0;
115pub const O_WRONLY = 0o1;114pub const O_WRONLY = 0o1;
116pub const O_RDWR = 0o2;115pub const O_RDWR = 0o2;
117116
118pub const SEEK_SET = 0;117pub const SEEK_SET = 0;
119pub const SEEK_CUR = 1;118pub const SEEK_CUR = 1;
120pub const SEEK_END = 2;119pub const SEEK_END = 2;
121120
122pub const SIG_BLOCK = 0;121pub const SIG_BLOCK = 0;
123pub const SIG_UNBLOCK = 1;122pub const SIG_UNBLOCK = 1;
124pub const SIG_SETMASK = 2;123pub const SIG_SETMASK = 2;
125124
...@@ -408,7 +407,6 @@ pub const DT_LNK = 10;...@@ -408,7 +407,6 @@ pub const DT_LNK = 10;
408pub const DT_SOCK = 12;407pub const DT_SOCK = 12;
409pub const DT_WHT = 14;408pub const DT_WHT = 14;
410409
411
412pub const TCGETS = 0x5401;410pub const TCGETS = 0x5401;
413pub const TCSETS = 0x5402;411pub const TCSETS = 0x5402;
414pub const TCSETSW = 0x5403;412pub const TCSETSW = 0x5403;
...@@ -539,23 +537,23 @@ pub const MS_BIND = 4096;...@@ -539,23 +537,23 @@ pub const MS_BIND = 4096;
539pub const MS_MOVE = 8192;537pub const MS_MOVE = 8192;
540pub const MS_REC = 16384;538pub const MS_REC = 16384;
541pub const MS_SILENT = 32768;539pub const MS_SILENT = 32768;
542pub const MS_POSIXACL = (1<<16);540pub const MS_POSIXACL = (1 << 16);
543pub const MS_UNBINDABLE = (1<<17);541pub const MS_UNBINDABLE = (1 << 17);
544pub const MS_PRIVATE = (1<<18);542pub const MS_PRIVATE = (1 << 18);
545pub const MS_SLAVE = (1<<19);543pub const MS_SLAVE = (1 << 19);
546pub const MS_SHARED = (1<<20);544pub const MS_SHARED = (1 << 20);
547pub const MS_RELATIME = (1<<21);545pub const MS_RELATIME = (1 << 21);
548pub const MS_KERNMOUNT = (1<<22);546pub const MS_KERNMOUNT = (1 << 22);
549pub const MS_I_VERSION = (1<<23);547pub const MS_I_VERSION = (1 << 23);
550pub const MS_STRICTATIME = (1<<24);548pub const MS_STRICTATIME = (1 << 24);
551pub const MS_LAZYTIME = (1<<25);549pub const MS_LAZYTIME = (1 << 25);
552pub const MS_NOREMOTELOCK = (1<<27);550pub const MS_NOREMOTELOCK = (1 << 27);
553pub const MS_NOSEC = (1<<28);551pub const MS_NOSEC = (1 << 28);
554pub const MS_BORN = (1<<29);552pub const MS_BORN = (1 << 29);
555pub const MS_ACTIVE = (1<<30);553pub const MS_ACTIVE = (1 << 30);
556pub const MS_NOUSER = (1<<31);554pub const MS_NOUSER = (1 << 31);
557555
558pub const MS_RMT_MASK = (MS_RDONLY|MS_SYNCHRONOUS|MS_MANDLOCK|MS_I_VERSION|MS_LAZYTIME);556pub const MS_RMT_MASK = (MS_RDONLY | MS_SYNCHRONOUS | MS_MANDLOCK | MS_I_VERSION | MS_LAZYTIME);
559557
560pub const MS_MGC_VAL = 0xc0ed0000;558pub const MS_MGC_VAL = 0xc0ed0000;
561pub const MS_MGC_MSK = 0xffff0000;559pub const MS_MGC_MSK = 0xffff0000;
...@@ -565,7 +563,6 @@ pub const MNT_DETACH = 2;...@@ -565,7 +563,6 @@ pub const MNT_DETACH = 2;
565pub const MNT_EXPIRE = 4;563pub const MNT_EXPIRE = 4;
566pub const UMOUNT_NOFOLLOW = 8;564pub const UMOUNT_NOFOLLOW = 8;
567565
568
569pub const S_IFMT = 0o170000;566pub const S_IFMT = 0o170000;
570567
571pub const S_IFDIR = 0o040000;568pub const S_IFDIR = 0o040000;
...@@ -626,15 +623,30 @@ pub const TFD_CLOEXEC = O_CLOEXEC;...@@ -626,15 +623,30 @@ pub const TFD_CLOEXEC = O_CLOEXEC;
626pub const TFD_TIMER_ABSTIME = 1;623pub const TFD_TIMER_ABSTIME = 1;
627pub const TFD_TIMER_CANCEL_ON_SET = (1 << 1);624pub const TFD_TIMER_CANCEL_ON_SET = (1 << 1);
628625
629fn unsigned(s: i32) u32 { return @bitCast(u32, s); }626fn unsigned(s: i32) u32 {
630fn signed(s: u32) i32 { return @bitCast(i32, s); }627 return @bitCast(u32, s);
631pub fn WEXITSTATUS(s: i32) i32 { return signed((unsigned(s) & 0xff00) >> 8); }628}
632pub fn WTERMSIG(s: i32) i32 { return signed(unsigned(s) & 0x7f); }629fn signed(s: u32) i32 {
633pub fn WSTOPSIG(s: i32) i32 { return WEXITSTATUS(s); }630 return @bitCast(i32, s);
634pub fn WIFEXITED(s: i32) bool { return WTERMSIG(s) == 0; }631}
635pub fn WIFSTOPPED(s: i32) bool { return (u16)(((unsigned(s)&0xffff)*%0x10001)>>8) > 0x7f00; }632pub fn WEXITSTATUS(s: i32) i32 {
636pub fn WIFSIGNALED(s: i32) bool { return (unsigned(s)&0xffff)-%1 < 0xff; }633 return signed((unsigned(s) & 0xff00) >> 8);
637634}
635pub fn WTERMSIG(s: i32) i32 {
636 return signed(unsigned(s) & 0x7f);
637}
638pub fn WSTOPSIG(s: i32) i32 {
639 return WEXITSTATUS(s);
640}
641pub fn WIFEXITED(s: i32) bool {
642 return WTERMSIG(s) == 0;
643}
644pub fn WIFSTOPPED(s: i32) bool {
645 return (u16)(((unsigned(s) & 0xffff) *% 0x10001) >> 8) > 0x7f00;
646}
647pub fn WIFSIGNALED(s: i32) bool {
648 return (unsigned(s) & 0xffff) -% 1 < 0xff;
649}
638650
639pub const winsize = extern struct {651pub const winsize = extern struct {
640 ws_row: u16,652 ws_row: u16,
...@@ -707,8 +719,7 @@ pub fn umount2(special: &const u8, flags: u32) usize {...@@ -707,8 +719,7 @@ pub fn umount2(special: &const u8, flags: u32) usize {
707}719}
708720
709pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: u32, fd: i32, offset: isize) usize {721pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: u32, fd: i32, offset: isize) usize {
710 return syscall6(SYS_mmap, @ptrToInt(address), length, prot, flags, usize(fd),722 return syscall6(SYS_mmap, @ptrToInt(address), length, prot, flags, usize(fd), @bitCast(usize, offset));
711 @bitCast(usize, offset));
712}723}
713724
714pub fn munmap(address: usize, length: usize) usize {725pub fn munmap(address: usize, length: usize) usize {
...@@ -812,7 +823,8 @@ pub fn clock_gettime(clk_id: i32, tp: &timespec) usize {...@@ -812,7 +823,8 @@ pub fn clock_gettime(clk_id: i32, tp: &timespec) usize {
812 if (@ptrToInt(f) != 0) {823 if (@ptrToInt(f) != 0) {
813 const rc = f(clk_id, tp);824 const rc = f(clk_id, tp);
814 switch (rc) {825 switch (rc) {
815 0, @bitCast(usize, isize(-EINVAL)) => return rc,826 0,
827 @bitCast(usize, isize(-EINVAL)) => return rc,
816 else => {},828 else => {},
817 }829 }
818 }830 }
...@@ -823,8 +835,7 @@ var vdso_clock_gettime = init_vdso_clock_gettime;...@@ -823,8 +835,7 @@ var vdso_clock_gettime = init_vdso_clock_gettime;
823extern fn init_vdso_clock_gettime(clk: i32, ts: &timespec) usize {835extern fn init_vdso_clock_gettime(clk: i32, ts: &timespec) usize {
824 const addr = vdso.lookup(VDSO_CGT_VER, VDSO_CGT_SYM);836 const addr = vdso.lookup(VDSO_CGT_VER, VDSO_CGT_SYM);
825 var f = @intToPtr(@typeOf(init_vdso_clock_gettime), addr);837 var f = @intToPtr(@typeOf(init_vdso_clock_gettime), addr);
826 _ = @cmpxchgStrong(@typeOf(init_vdso_clock_gettime), &vdso_clock_gettime, init_vdso_clock_gettime, f,838 _ = @cmpxchgStrong(@typeOf(init_vdso_clock_gettime), &vdso_clock_gettime, init_vdso_clock_gettime, f, builtin.AtomicOrder.Monotonic, builtin.AtomicOrder.Monotonic);
827 builtin.AtomicOrder.Monotonic, builtin.AtomicOrder.Monotonic);
828 if (@ptrToInt(f) == 0) return @bitCast(usize, isize(-ENOSYS));839 if (@ptrToInt(f) == 0) return @bitCast(usize, isize(-ENOSYS));
829 return f(clk, ts);840 return f(clk, ts);
830}841}
...@@ -918,18 +929,18 @@ pub fn getpid() i32 {...@@ -918,18 +929,18 @@ pub fn getpid() i32 {
918}929}
919930
920pub fn sigprocmask(flags: u32, noalias set: &const sigset_t, noalias oldset: ?&sigset_t) usize {931pub fn sigprocmask(flags: u32, noalias set: &const sigset_t, noalias oldset: ?&sigset_t) usize {
921 return syscall4(SYS_rt_sigprocmask, flags, @ptrToInt(set), @ptrToInt(oldset), NSIG/8);932 return syscall4(SYS_rt_sigprocmask, flags, @ptrToInt(set), @ptrToInt(oldset), NSIG / 8);
922}933}
923934
924pub fn sigaction(sig: u6, noalias act: &const Sigaction, noalias oact: ?&Sigaction) usize {935pub fn sigaction(sig: u6, noalias act: &const Sigaction, noalias oact: ?&Sigaction) usize {
925 assert(sig >= 1);936 assert(sig >= 1);
926 assert(sig != SIGKILL);937 assert(sig != SIGKILL);
927 assert(sig != SIGSTOP);938 assert(sig != SIGSTOP);
928 var ksa = k_sigaction {939 var ksa = k_sigaction{
929 .handler = act.handler,940 .handler = act.handler,
930 .flags = act.flags | SA_RESTORER,941 .flags = act.flags | SA_RESTORER,
931 .mask = undefined,942 .mask = undefined,
932 .restorer = @ptrCast(extern fn()void, restore_rt),943 .restorer = @ptrCast(extern fn() void, restore_rt),
933 };944 };
934 var ksa_old: k_sigaction = undefined;945 var ksa_old: k_sigaction = undefined;
935 @memcpy(@ptrCast(&u8, &ksa.mask), @ptrCast(&const u8, &act.mask), 8);946 @memcpy(@ptrCast(&u8, &ksa.mask), @ptrCast(&const u8, &act.mask), 8);
...@@ -952,22 +963,22 @@ const all_mask = []usize{@maxValue(usize)};...@@ -952,22 +963,22 @@ const all_mask = []usize{@maxValue(usize)};
952const app_mask = []usize{0xfffffffc7fffffff};963const app_mask = []usize{0xfffffffc7fffffff};
953964
954const k_sigaction = extern struct {965const k_sigaction = extern struct {
955 handler: extern fn(i32)void,966 handler: extern fn(i32) void,
956 flags: usize,967 flags: usize,
957 restorer: extern fn()void,968 restorer: extern fn() void,
958 mask: [2]u32,969 mask: [2]u32,
959};970};
960971
961/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.972/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
962pub const Sigaction = struct {973pub const Sigaction = struct {
963 handler: extern fn(i32)void,974 handler: extern fn(i32) void,
964 mask: sigset_t,975 mask: sigset_t,
965 flags: u32,976 flags: u32,
966};977};
967978
968pub const SIG_ERR = @intToPtr(extern fn(i32)void, @maxValue(usize));979pub const SIG_ERR = @intToPtr(extern fn(i32) void, @maxValue(usize));
969pub const SIG_DFL = @intToPtr(extern fn(i32)void, 0);980pub const SIG_DFL = @intToPtr(extern fn(i32) void, 0);
970pub const SIG_IGN = @intToPtr(extern fn(i32)void, 1);981pub const SIG_IGN = @intToPtr(extern fn(i32) void, 1);
971pub const empty_sigset = []usize{0} ** sigset_t.len;982pub const empty_sigset = []usize{0} ** sigset_t.len;
972983
973pub fn raise(sig: i32) usize {984pub fn raise(sig: i32) usize {
...@@ -980,25 +991,25 @@ pub fn raise(sig: i32) usize {...@@ -980,25 +991,25 @@ pub fn raise(sig: i32) usize {
980}991}
981992
982fn blockAllSignals(set: &sigset_t) void {993fn blockAllSignals(set: &sigset_t) void {
983 _ = syscall4(SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&all_mask), @ptrToInt(set), NSIG/8);994 _ = syscall4(SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&all_mask), @ptrToInt(set), NSIG / 8);
984}995}
985996
986fn blockAppSignals(set: &sigset_t) void {997fn blockAppSignals(set: &sigset_t) void {
987 _ = syscall4(SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&app_mask), @ptrToInt(set), NSIG/8);998 _ = syscall4(SYS_rt_sigprocmask, SIG_BLOCK, @ptrToInt(&app_mask), @ptrToInt(set), NSIG / 8);
988}999}
9891000
990fn restoreSignals(set: &sigset_t) void {1001fn restoreSignals(set: &sigset_t) void {
991 _ = syscall4(SYS_rt_sigprocmask, SIG_SETMASK, @ptrToInt(set), 0, NSIG/8);1002 _ = syscall4(SYS_rt_sigprocmask, SIG_SETMASK, @ptrToInt(set), 0, NSIG / 8);
992}1003}
9931004
994pub fn sigaddset(set: &sigset_t, sig: u6) void {1005pub fn sigaddset(set: &sigset_t, sig: u6) void {
995 const s = sig - 1;1006 const s = sig - 1;
996 (*set)[usize(s) / usize.bit_count] |= usize(1) << (s & (usize.bit_count - 1));1007 (set.*)[usize(s) / usize.bit_count] |= usize(1) << (s & (usize.bit_count - 1));
997}1008}
9981009
999pub fn sigismember(set: &const sigset_t, sig: u6) bool {1010pub fn sigismember(set: &const sigset_t, sig: u6) bool {
1000 const s = sig - 1;1011 const s = sig - 1;
1001 return ((*set)[usize(s) / usize.bit_count] & (usize(1) << (s & (usize.bit_count - 1)))) != 0;1012 return ((set.*)[usize(s) / usize.bit_count] & (usize(1) << (s & (usize.bit_count - 1)))) != 0;
1002}1013}
10031014
1004pub const in_port_t = u16;1015pub const in_port_t = u16;
...@@ -1062,9 +1073,7 @@ pub fn recvmsg(fd: i32, msg: &msghdr, flags: u32) usize {...@@ -1062,9 +1073,7 @@ pub fn recvmsg(fd: i32, msg: &msghdr, flags: u32) usize {
1062 return syscall3(SYS_recvmsg, usize(fd), @ptrToInt(msg), flags);1073 return syscall3(SYS_recvmsg, usize(fd), @ptrToInt(msg), flags);
1063}1074}
10641075
1065pub fn recvfrom(fd: i32, noalias buf: &u8, len: usize, flags: u32,1076pub fn recvfrom(fd: i32, noalias buf: &u8, len: usize, flags: u32, noalias addr: ?&sockaddr, noalias alen: ?&socklen_t) usize {
1066 noalias addr: ?&sockaddr, noalias alen: ?&socklen_t) usize
1067{
1068 return syscall6(SYS_recvfrom, usize(fd), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen));1077 return syscall6(SYS_recvfrom, usize(fd), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen));
1069}1078}
10701079
...@@ -1132,25 +1141,16 @@ pub fn fgetxattr(fd: usize, name: &const u8, value: &void, size: usize) usize {...@@ -1132,25 +1141,16 @@ pub fn fgetxattr(fd: usize, name: &const u8, value: &void, size: usize) usize {
1132 return syscall4(SYS_lgetxattr, fd, @ptrToInt(name), @ptrToInt(value), size);1141 return syscall4(SYS_lgetxattr, fd, @ptrToInt(name), @ptrToInt(value), size);
1133}1142}
11341143
1135pub fn setxattr(path: &const u8, name: &const u8, value: &const void,1144pub fn setxattr(path: &const u8, name: &const u8, value: &const void, size: usize, flags: usize) usize {
1136 size: usize, flags: usize) usize {1145 return syscall5(SYS_setxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size, flags);
1137
1138 return syscall5(SYS_setxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value),
1139 size, flags);
1140}1146}
11411147
1142pub fn lsetxattr(path: &const u8, name: &const u8, value: &const void,1148pub fn lsetxattr(path: &const u8, name: &const u8, value: &const void, size: usize, flags: usize) usize {
1143 size: usize, flags: usize) usize {1149 return syscall5(SYS_lsetxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size, flags);
1144
1145 return syscall5(SYS_lsetxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value),
1146 size, flags);
1147}1150}
11481151
1149pub fn fsetxattr(fd: usize, name: &const u8, value: &const void,1152pub fn fsetxattr(fd: usize, name: &const u8, value: &const void, size: usize, flags: usize) usize {
1150 size: usize, flags: usize) usize {1153 return syscall5(SYS_fsetxattr, fd, @ptrToInt(name), @ptrToInt(value), size, flags);
1151
1152 return syscall5(SYS_fsetxattr, fd, @ptrToInt(name), @ptrToInt(value),
1153 size, flags);
1154}1154}
11551155
1156pub fn removexattr(path: &const u8, name: &const u8) usize {1156pub fn removexattr(path: &const u8, name: &const u8) usize {
...@@ -1199,7 +1199,7 @@ pub fn timerfd_create(clockid: i32, flags: u32) usize {...@@ -1199,7 +1199,7 @@ pub fn timerfd_create(clockid: i32, flags: u32) usize {
11991199
1200pub const itimerspec = extern struct {1200pub const itimerspec = extern struct {
1201 it_interval: timespec,1201 it_interval: timespec,
1202 it_value: timespec1202 it_value: timespec,
1203};1203};
12041204
1205pub fn timerfd_gettime(fd: i32, curr_value: &itimerspec) usize {1205pub 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...@@ -1211,30 +1211,30 @@ pub fn timerfd_settime(fd: i32, flags: u32, new_value: &const itimerspec, old_va
1211}1211}
12121212
1213pub const _LINUX_CAPABILITY_VERSION_1 = 0x19980330;1213pub const _LINUX_CAPABILITY_VERSION_1 = 0x19980330;
1214pub const _LINUX_CAPABILITY_U32S_1 = 1;1214pub const _LINUX_CAPABILITY_U32S_1 = 1;
12151215
1216pub const _LINUX_CAPABILITY_VERSION_2 = 0x20071026;1216pub const _LINUX_CAPABILITY_VERSION_2 = 0x20071026;
1217pub const _LINUX_CAPABILITY_U32S_2 = 2;1217pub const _LINUX_CAPABILITY_U32S_2 = 2;
12181218
1219pub const _LINUX_CAPABILITY_VERSION_3 = 0x20080522;1219pub const _LINUX_CAPABILITY_VERSION_3 = 0x20080522;
1220pub const _LINUX_CAPABILITY_U32S_3 = 2;1220pub const _LINUX_CAPABILITY_U32S_3 = 2;
12211221
1222pub const VFS_CAP_REVISION_MASK = 0xFF000000;1222pub const VFS_CAP_REVISION_MASK = 0xFF000000;
1223pub const VFS_CAP_REVISION_SHIFT = 24;1223pub const VFS_CAP_REVISION_SHIFT = 24;
1224pub const VFS_CAP_FLAGS_MASK = ~VFS_CAP_REVISION_MASK;1224pub const VFS_CAP_FLAGS_MASK = ~VFS_CAP_REVISION_MASK;
1225pub const VFS_CAP_FLAGS_EFFECTIVE = 0x000001;1225pub const VFS_CAP_FLAGS_EFFECTIVE = 0x000001;
12261226
1227pub const VFS_CAP_REVISION_1 = 0x01000000;1227pub const VFS_CAP_REVISION_1 = 0x01000000;
1228pub const VFS_CAP_U32_1 = 1;1228pub const VFS_CAP_U32_1 = 1;
1229pub const XATTR_CAPS_SZ_1 = @sizeOf(u32)*(1 + 2*VFS_CAP_U32_1);1229pub const XATTR_CAPS_SZ_1 = @sizeOf(u32) * (1 + 2 * VFS_CAP_U32_1);
12301230
1231pub const VFS_CAP_REVISION_2 = 0x02000000;1231pub const VFS_CAP_REVISION_2 = 0x02000000;
1232pub const VFS_CAP_U32_2 = 2;1232pub const VFS_CAP_U32_2 = 2;
1233pub const XATTR_CAPS_SZ_2 = @sizeOf(u32)*(1 + 2*VFS_CAP_U32_2);1233pub const XATTR_CAPS_SZ_2 = @sizeOf(u32) * (1 + 2 * VFS_CAP_U32_2);
12341234
1235pub const XATTR_CAPS_SZ = XATTR_CAPS_SZ_2;1235pub const XATTR_CAPS_SZ = XATTR_CAPS_SZ_2;
1236pub const VFS_CAP_U32 = VFS_CAP_U32_2;1236pub const VFS_CAP_U32 = VFS_CAP_U32_2;
1237pub const VFS_CAP_REVISION = VFS_CAP_REVISION_2;1237pub const VFS_CAP_REVISION = VFS_CAP_REVISION_2;
12381238
1239pub const vfs_cap_data = extern struct {1239pub const vfs_cap_data = extern struct {
1240 //all of these are mandated as little endian1240 //all of these are mandated as little endian
...@@ -1245,49 +1245,48 @@ pub const vfs_cap_data = extern struct {...@@ -1245,49 +1245,48 @@ pub const vfs_cap_data = extern struct {
1245 };1245 };
12461246
1247 magic_etc: u32,1247 magic_etc: u32,
1248 data: [VFS_CAP_U32]Data,1248 data: [VFS_CAP_U32]Data,
1249};1249};
12501250
12511251pub const CAP_CHOWN = 0;
1252pub const CAP_CHOWN = 0;1252pub const CAP_DAC_OVERRIDE = 1;
1253pub const CAP_DAC_OVERRIDE = 1;1253pub const CAP_DAC_READ_SEARCH = 2;
1254pub const CAP_DAC_READ_SEARCH = 2;1254pub const CAP_FOWNER = 3;
1255pub const CAP_FOWNER = 3;1255pub const CAP_FSETID = 4;
1256pub const CAP_FSETID = 4;1256pub const CAP_KILL = 5;
1257pub const CAP_KILL = 5;1257pub const CAP_SETGID = 6;
1258pub const CAP_SETGID = 6;1258pub const CAP_SETUID = 7;
1259pub const CAP_SETUID = 7;1259pub const CAP_SETPCAP = 8;
1260pub const CAP_SETPCAP = 8;1260pub const CAP_LINUX_IMMUTABLE = 9;
1261pub const CAP_LINUX_IMMUTABLE = 9;1261pub const CAP_NET_BIND_SERVICE = 10;
1262pub const CAP_NET_BIND_SERVICE = 10;1262pub const CAP_NET_BROADCAST = 11;
1263pub const CAP_NET_BROADCAST = 11;1263pub const CAP_NET_ADMIN = 12;
1264pub const CAP_NET_ADMIN = 12;1264pub const CAP_NET_RAW = 13;
1265pub const CAP_NET_RAW = 13;1265pub const CAP_IPC_LOCK = 14;
1266pub const CAP_IPC_LOCK = 14;1266pub const CAP_IPC_OWNER = 15;
1267pub const CAP_IPC_OWNER = 15;1267pub const CAP_SYS_MODULE = 16;
1268pub const CAP_SYS_MODULE = 16;1268pub const CAP_SYS_RAWIO = 17;
1269pub const CAP_SYS_RAWIO = 17;1269pub const CAP_SYS_CHROOT = 18;
1270pub const CAP_SYS_CHROOT = 18;1270pub const CAP_SYS_PTRACE = 19;
1271pub const CAP_SYS_PTRACE = 19;1271pub const CAP_SYS_PACCT = 20;
1272pub const CAP_SYS_PACCT = 20;1272pub const CAP_SYS_ADMIN = 21;
1273pub const CAP_SYS_ADMIN = 21;1273pub const CAP_SYS_BOOT = 22;
1274pub const CAP_SYS_BOOT = 22;1274pub const CAP_SYS_NICE = 23;
1275pub const CAP_SYS_NICE = 23;1275pub const CAP_SYS_RESOURCE = 24;
1276pub const CAP_SYS_RESOURCE = 24;1276pub const CAP_SYS_TIME = 25;
1277pub const CAP_SYS_TIME = 25;1277pub const CAP_SYS_TTY_CONFIG = 26;
1278pub const CAP_SYS_TTY_CONFIG = 26;1278pub const CAP_MKNOD = 27;
1279pub const CAP_MKNOD = 27;1279pub const CAP_LEASE = 28;
1280pub const CAP_LEASE = 28;1280pub const CAP_AUDIT_WRITE = 29;
1281pub const CAP_AUDIT_WRITE = 29;1281pub const CAP_AUDIT_CONTROL = 30;
1282pub const CAP_AUDIT_CONTROL = 30;1282pub const CAP_SETFCAP = 31;
1283pub const CAP_SETFCAP = 31;1283pub const CAP_MAC_OVERRIDE = 32;
1284pub const CAP_MAC_OVERRIDE = 32;1284pub const CAP_MAC_ADMIN = 33;
1285pub const CAP_MAC_ADMIN = 33;1285pub const CAP_SYSLOG = 34;
1286pub const CAP_SYSLOG = 34;1286pub const CAP_WAKE_ALARM = 35;
1287pub const CAP_WAKE_ALARM = 35;1287pub const CAP_BLOCK_SUSPEND = 36;
1288pub const CAP_BLOCK_SUSPEND = 36;1288pub const CAP_AUDIT_READ = 37;
1289pub const CAP_AUDIT_READ = 37;1289pub const CAP_LAST_CAP = CAP_AUDIT_READ;
1290pub const CAP_LAST_CAP = CAP_AUDIT_READ;
12911290
1292pub fn cap_valid(u8: x) bool {1291pub fn cap_valid(u8: x) bool {
1293 return x >= 0 and x <= CAP_LAST_CAP;1292 return x >= 0 and x <= CAP_LAST_CAP;
std/special/bootstrap.zig+4-4
...@@ -27,10 +27,10 @@ extern fn zen_start() noreturn {...@@ -27,10 +27,10 @@ extern fn zen_start() noreturn {
27nakedcc fn _start() noreturn {27nakedcc fn _start() noreturn {
28 switch (builtin.arch) {28 switch (builtin.arch) {
29 builtin.Arch.x86_64 => {29 builtin.Arch.x86_64 => {
30 argc_ptr = asm("lea (%%rsp), %[argc]": [argc] "=r" (-> &usize));30 argc_ptr = asm ("lea (%%rsp), %[argc]" : [argc] "=r" (-> &usize));
31 },31 },
32 builtin.Arch.i386 => {32 builtin.Arch.i386 => {
33 argc_ptr = asm("lea (%%esp), %[argc]": [argc] "=r" (-> &usize));33 argc_ptr = asm ("lea (%%esp), %[argc]" : [argc] "=r" (-> &usize));
34 },34 },
35 else => @compileError("unsupported arch"),35 else => @compileError("unsupported arch"),
36 }36 }
...@@ -46,7 +46,7 @@ extern fn WinMainCRTStartup() noreturn {...@@ -46,7 +46,7 @@ extern fn WinMainCRTStartup() noreturn {
46}46}
4747
48fn posixCallMainAndExit() noreturn {48fn posixCallMainAndExit() noreturn {
49 const argc = *argc_ptr;49 const argc = argc_ptr.*;
50 const argv = @ptrCast(&&u8, &argc_ptr[1]);50 const argv = @ptrCast(&&u8, &argc_ptr[1]);
51 const envp_nullable = @ptrCast(&?&u8, &argv[argc + 1]);51 const envp_nullable = @ptrCast(&?&u8, &argv[argc + 1]);
52 var envp_count: usize = 0;52 var envp_count: usize = 0;
...@@ -56,7 +56,7 @@ fn posixCallMainAndExit() noreturn {...@@ -56,7 +56,7 @@ fn posixCallMainAndExit() noreturn {
56 const auxv = &@ptrCast(&usize, envp.ptr)[envp_count + 1];56 const auxv = &@ptrCast(&usize, envp.ptr)[envp_count + 1];
57 var i: usize = 0;57 var i: usize = 0;
58 while (auxv[i] != 0) : (i += 2) {58 while (auxv[i] != 0) : (i += 2) {
59 if (auxv[i] < std.os.linux_aux_raw.len) std.os.linux_aux_raw[auxv[i]] = auxv[i+1];59 if (auxv[i] < std.os.linux_aux_raw.len) std.os.linux_aux_raw[auxv[i]] = auxv[i + 1];
60 }60 }
61 std.debug.assert(std.os.linux_aux_raw[std.elf.AT_PAGESZ] == std.os.page_size);61 std.debug.assert(std.os.linux_aux_raw[std.elf.AT_PAGESZ] == std.os.page_size);
62 }62 }
std/special/compiler_rt/fixuint.zig+2-4
...@@ -36,12 +36,10 @@ pub fn fixuint(comptime fp_t: type, comptime fixuint_t: type, a: fp_t) fixuint_t...@@ -36,12 +36,10 @@ pub fn fixuint(comptime fp_t: type, comptime fixuint_t: type, a: fp_t) fixuint_t
36 const significand: rep_t = (aAbs & significandMask) | implicitBit;36 const significand: rep_t = (aAbs & significandMask) | implicitBit;
3737
38 // If either the value or the exponent is negative, the result is zero.38 // If either the value or the exponent is negative, the result is zero.
39 if (sign == -1 or exponent < 0)39 if (sign == -1 or exponent < 0) return 0;
40 return 0;
4140
42 // If the value is too large for the integer type, saturate.41 // If the value is too large for the integer type, saturate.
43 if (c_uint(exponent) >= fixuint_t.bit_count)42 if (c_uint(exponent) >= fixuint_t.bit_count) return ~fixuint_t(0);
44 return ~fixuint_t(0);
4543
46 // If 0 <= exponent < significandBits, right shift to get the result.44 // If 0 <= exponent < significandBits, right shift to get the result.
47 // Otherwise, shift left.45 // Otherwise, shift left.
std/special/compiler_rt/fixunsdfdi.zig-1
...@@ -9,4 +9,3 @@ pub extern fn __fixunsdfdi(a: f64) u64 {...@@ -9,4 +9,3 @@ pub extern fn __fixunsdfdi(a: f64) u64 {
9test "import fixunsdfdi" {9test "import fixunsdfdi" {
10 _ = @import("fixunsdfdi_test.zig");10 _ = @import("fixunsdfdi_test.zig");
11}11}
12
std/special/compiler_rt/fixunsdfsi.zig-1
...@@ -9,4 +9,3 @@ pub extern fn __fixunsdfsi(a: f64) u32 {...@@ -9,4 +9,3 @@ pub extern fn __fixunsdfsi(a: f64) u32 {
9test "import fixunsdfsi" {9test "import fixunsdfsi" {
10 _ = @import("fixunsdfsi_test.zig");10 _ = @import("fixunsdfsi_test.zig");
11}11}
12
std/special/compiler_rt/fixunssfti.zig-1
...@@ -9,4 +9,3 @@ pub extern fn __fixunssfti(a: f32) u128 {...@@ -9,4 +9,3 @@ pub extern fn __fixunssfti(a: f32) u128 {
9test "import fixunssfti" {9test "import fixunssfti" {
10 _ = @import("fixunssfti_test.zig");10 _ = @import("fixunssfti_test.zig");
11}11}
12
std/special/compiler_rt/fixunstfti.zig-1
...@@ -9,4 +9,3 @@ pub extern fn __fixunstfti(a: f128) u128 {...@@ -9,4 +9,3 @@ pub extern fn __fixunstfti(a: f128) u128 {
9test "import fixunstfti" {9test "import fixunstfti" {
10 _ = @import("fixunstfti_test.zig");10 _ = @import("fixunstfti_test.zig");
11}11}
12
std/special/compiler_rt/index.zig+674-144
...@@ -91,9 +91,10 @@ pub fn setXmm0(comptime T: type, value: T) void {...@@ -91,9 +91,10 @@ pub fn setXmm0(comptime T: type, value: T) void {
91 const aligned_value: T align(16) = value;91 const aligned_value: T align(16) = value;
92 asm volatile (92 asm volatile (
93 \\movaps (%[ptr]), %%xmm093 \\movaps (%[ptr]), %%xmm0
94 :94
95 : [ptr] "r" (&aligned_value)95 :
96 : "xmm0");96 : [ptr] "r" (&aligned_value)
97 : "xmm0");
97}98}
9899
99extern fn __udivdi3(a: u64, b: u64) u64 {100extern fn __udivdi3(a: u64, b: u64) u64 {
...@@ -282,26 +283,27 @@ extern fn __udivmodsi4(a: u32, b: u32, rem: &u32) u32 {...@@ -282,26 +283,27 @@ extern fn __udivmodsi4(a: u32, b: u32, rem: &u32) u32 {
282 @setRuntimeSafety(is_test);283 @setRuntimeSafety(is_test);
283284
284 const d = __udivsi3(a, b);285 const d = __udivsi3(a, b);
285 *rem = u32(i32(a) -% (i32(d) * i32(b)));286 rem.* = u32(i32(a) -% (i32(d) * i32(b)));
286 return d;287 return d;
287}288}
288289
289
290extern fn __udivsi3(n: u32, d: u32) u32 {290extern fn __udivsi3(n: u32, d: u32) u32 {
291 @setRuntimeSafety(is_test);291 @setRuntimeSafety(is_test);
292292
293 const n_uword_bits: c_uint = u32.bit_count;293 const n_uword_bits: c_uint = u32.bit_count;
294 // special cases294 // special cases
295 if (d == 0)295 if (d == 0) return 0; // ?!
296 return 0; // ?!296 if (n == 0) return 0;
297 if (n == 0)
298 return 0;
299 var sr = @bitCast(c_uint, c_int(@clz(d)) - c_int(@clz(n)));297 var sr = @bitCast(c_uint, c_int(@clz(d)) - c_int(@clz(n)));
300 // 0 <= sr <= n_uword_bits - 1 or sr large298 // 0 <= sr <= n_uword_bits - 1 or sr large
301 if (sr > n_uword_bits - 1) // d > r299 if (sr > n_uword_bits - 1) {
300 // d > r
302 return 0;301 return 0;
303 if (sr == n_uword_bits - 1) // d == 1302 }
303 if (sr == n_uword_bits - 1) {
304 // d == 1
304 return n;305 return n;
306 }
305 sr += 1;307 sr += 1;
306 // 1 <= sr <= n_uword_bits - 1308 // 1 <= sr <= n_uword_bits - 1
307 // Not a special case309 // Not a special case
...@@ -340,139 +342,667 @@ fn test_one_umoddi3(a: u64, b: u64, expected_r: u64) void {...@@ -340,139 +342,667 @@ fn test_one_umoddi3(a: u64, b: u64, expected_r: u64) void {
340}342}
341343
342test "test_udivsi3" {344test "test_udivsi3" {
343 const cases = [][3]u32 {345 const cases = [][3]u32{
344 []u32{0x00000000, 0x00000001, 0x00000000},346 []u32{
345 []u32{0x00000000, 0x00000002, 0x00000000},347 0x00000000,
346 []u32{0x00000000, 0x00000003, 0x00000000},348 0x00000001,
347 []u32{0x00000000, 0x00000010, 0x00000000},349 0x00000000,
348 []u32{0x00000000, 0x078644FA, 0x00000000},350 },
349 []u32{0x00000000, 0x0747AE14, 0x00000000},351 []u32{
350 []u32{0x00000000, 0x7FFFFFFF, 0x00000000},352 0x00000000,
351 []u32{0x00000000, 0x80000000, 0x00000000},353 0x00000002,
352 []u32{0x00000000, 0xFFFFFFFD, 0x00000000},354 0x00000000,
353 []u32{0x00000000, 0xFFFFFFFE, 0x00000000},355 },
354 []u32{0x00000000, 0xFFFFFFFF, 0x00000000},356 []u32{
355 []u32{0x00000001, 0x00000001, 0x00000001},357 0x00000000,
356 []u32{0x00000001, 0x00000002, 0x00000000},358 0x00000003,
357 []u32{0x00000001, 0x00000003, 0x00000000},359 0x00000000,
358 []u32{0x00000001, 0x00000010, 0x00000000},360 },
359 []u32{0x00000001, 0x078644FA, 0x00000000},361 []u32{
360 []u32{0x00000001, 0x0747AE14, 0x00000000},362 0x00000000,
361 []u32{0x00000001, 0x7FFFFFFF, 0x00000000},363 0x00000010,
362 []u32{0x00000001, 0x80000000, 0x00000000},364 0x00000000,
363 []u32{0x00000001, 0xFFFFFFFD, 0x00000000},365 },
364 []u32{0x00000001, 0xFFFFFFFE, 0x00000000},366 []u32{
365 []u32{0x00000001, 0xFFFFFFFF, 0x00000000},367 0x00000000,
366 []u32{0x00000002, 0x00000001, 0x00000002},368 0x078644FA,
367 []u32{0x00000002, 0x00000002, 0x00000001},369 0x00000000,
368 []u32{0x00000002, 0x00000003, 0x00000000},370 },
369 []u32{0x00000002, 0x00000010, 0x00000000},371 []u32{
370 []u32{0x00000002, 0x078644FA, 0x00000000},372 0x00000000,
371 []u32{0x00000002, 0x0747AE14, 0x00000000},373 0x0747AE14,
372 []u32{0x00000002, 0x7FFFFFFF, 0x00000000},374 0x00000000,
373 []u32{0x00000002, 0x80000000, 0x00000000},375 },
374 []u32{0x00000002, 0xFFFFFFFD, 0x00000000},376 []u32{
375 []u32{0x00000002, 0xFFFFFFFE, 0x00000000},377 0x00000000,
376 []u32{0x00000002, 0xFFFFFFFF, 0x00000000},378 0x7FFFFFFF,
377 []u32{0x00000003, 0x00000001, 0x00000003},379 0x00000000,
378 []u32{0x00000003, 0x00000002, 0x00000001},380 },
379 []u32{0x00000003, 0x00000003, 0x00000001},381 []u32{
380 []u32{0x00000003, 0x00000010, 0x00000000},382 0x00000000,
381 []u32{0x00000003, 0x078644FA, 0x00000000},383 0x80000000,
382 []u32{0x00000003, 0x0747AE14, 0x00000000},384 0x00000000,
383 []u32{0x00000003, 0x7FFFFFFF, 0x00000000},385 },
384 []u32{0x00000003, 0x80000000, 0x00000000},386 []u32{
385 []u32{0x00000003, 0xFFFFFFFD, 0x00000000},387 0x00000000,
386 []u32{0x00000003, 0xFFFFFFFE, 0x00000000},388 0xFFFFFFFD,
387 []u32{0x00000003, 0xFFFFFFFF, 0x00000000},389 0x00000000,
388 []u32{0x00000010, 0x00000001, 0x00000010},390 },
389 []u32{0x00000010, 0x00000002, 0x00000008},391 []u32{
390 []u32{0x00000010, 0x00000003, 0x00000005},392 0x00000000,
391 []u32{0x00000010, 0x00000010, 0x00000001},393 0xFFFFFFFE,
392 []u32{0x00000010, 0x078644FA, 0x00000000},394 0x00000000,
393 []u32{0x00000010, 0x0747AE14, 0x00000000},395 },
394 []u32{0x00000010, 0x7FFFFFFF, 0x00000000},396 []u32{
395 []u32{0x00000010, 0x80000000, 0x00000000},397 0x00000000,
396 []u32{0x00000010, 0xFFFFFFFD, 0x00000000},398 0xFFFFFFFF,
397 []u32{0x00000010, 0xFFFFFFFE, 0x00000000},399 0x00000000,
398 []u32{0x00000010, 0xFFFFFFFF, 0x00000000},400 },
399 []u32{0x078644FA, 0x00000001, 0x078644FA},401 []u32{
400 []u32{0x078644FA, 0x00000002, 0x03C3227D},402 0x00000001,
401 []u32{0x078644FA, 0x00000003, 0x028216FE},403 0x00000001,
402 []u32{0x078644FA, 0x00000010, 0x0078644F},404 0x00000001,
403 []u32{0x078644FA, 0x078644FA, 0x00000001},405 },
404 []u32{0x078644FA, 0x0747AE14, 0x00000001},406 []u32{
405 []u32{0x078644FA, 0x7FFFFFFF, 0x00000000},407 0x00000001,
406 []u32{0x078644FA, 0x80000000, 0x00000000},408 0x00000002,
407 []u32{0x078644FA, 0xFFFFFFFD, 0x00000000},409 0x00000000,
408 []u32{0x078644FA, 0xFFFFFFFE, 0x00000000},410 },
409 []u32{0x078644FA, 0xFFFFFFFF, 0x00000000},411 []u32{
410 []u32{0x0747AE14, 0x00000001, 0x0747AE14},412 0x00000001,
411 []u32{0x0747AE14, 0x00000002, 0x03A3D70A},413 0x00000003,
412 []u32{0x0747AE14, 0x00000003, 0x026D3A06},414 0x00000000,
413 []u32{0x0747AE14, 0x00000010, 0x00747AE1},415 },
414 []u32{0x0747AE14, 0x078644FA, 0x00000000},416 []u32{
415 []u32{0x0747AE14, 0x0747AE14, 0x00000001},417 0x00000001,
416 []u32{0x0747AE14, 0x7FFFFFFF, 0x00000000},418 0x00000010,
417 []u32{0x0747AE14, 0x80000000, 0x00000000},419 0x00000000,
418 []u32{0x0747AE14, 0xFFFFFFFD, 0x00000000},420 },
419 []u32{0x0747AE14, 0xFFFFFFFE, 0x00000000},421 []u32{
420 []u32{0x0747AE14, 0xFFFFFFFF, 0x00000000},422 0x00000001,
421 []u32{0x7FFFFFFF, 0x00000001, 0x7FFFFFFF},423 0x078644FA,
422 []u32{0x7FFFFFFF, 0x00000002, 0x3FFFFFFF},424 0x00000000,
423 []u32{0x7FFFFFFF, 0x00000003, 0x2AAAAAAA},425 },
424 []u32{0x7FFFFFFF, 0x00000010, 0x07FFFFFF},426 []u32{
425 []u32{0x7FFFFFFF, 0x078644FA, 0x00000011},427 0x00000001,
426 []u32{0x7FFFFFFF, 0x0747AE14, 0x00000011},428 0x0747AE14,
427 []u32{0x7FFFFFFF, 0x7FFFFFFF, 0x00000001},429 0x00000000,
428 []u32{0x7FFFFFFF, 0x80000000, 0x00000000},430 },
429 []u32{0x7FFFFFFF, 0xFFFFFFFD, 0x00000000},431 []u32{
430 []u32{0x7FFFFFFF, 0xFFFFFFFE, 0x00000000},432 0x00000001,
431 []u32{0x7FFFFFFF, 0xFFFFFFFF, 0x00000000},433 0x7FFFFFFF,
432 []u32{0x80000000, 0x00000001, 0x80000000},434 0x00000000,
433 []u32{0x80000000, 0x00000002, 0x40000000},435 },
434 []u32{0x80000000, 0x00000003, 0x2AAAAAAA},436 []u32{
435 []u32{0x80000000, 0x00000010, 0x08000000},437 0x00000001,
436 []u32{0x80000000, 0x078644FA, 0x00000011},438 0x80000000,
437 []u32{0x80000000, 0x0747AE14, 0x00000011},439 0x00000000,
438 []u32{0x80000000, 0x7FFFFFFF, 0x00000001},440 },
439 []u32{0x80000000, 0x80000000, 0x00000001},441 []u32{
440 []u32{0x80000000, 0xFFFFFFFD, 0x00000000},442 0x00000001,
441 []u32{0x80000000, 0xFFFFFFFE, 0x00000000},443 0xFFFFFFFD,
442 []u32{0x80000000, 0xFFFFFFFF, 0x00000000},444 0x00000000,
443 []u32{0xFFFFFFFD, 0x00000001, 0xFFFFFFFD},445 },
444 []u32{0xFFFFFFFD, 0x00000002, 0x7FFFFFFE},446 []u32{
445 []u32{0xFFFFFFFD, 0x00000003, 0x55555554},447 0x00000001,
446 []u32{0xFFFFFFFD, 0x00000010, 0x0FFFFFFF},448 0xFFFFFFFE,
447 []u32{0xFFFFFFFD, 0x078644FA, 0x00000022},449 0x00000000,
448 []u32{0xFFFFFFFD, 0x0747AE14, 0x00000023},450 },
449 []u32{0xFFFFFFFD, 0x7FFFFFFF, 0x00000001},451 []u32{
450 []u32{0xFFFFFFFD, 0x80000000, 0x00000001},452 0x00000001,
451 []u32{0xFFFFFFFD, 0xFFFFFFFD, 0x00000001},453 0xFFFFFFFF,
452 []u32{0xFFFFFFFD, 0xFFFFFFFE, 0x00000000},454 0x00000000,
453 []u32{0xFFFFFFFD, 0xFFFFFFFF, 0x00000000},455 },
454 []u32{0xFFFFFFFE, 0x00000001, 0xFFFFFFFE},456 []u32{
455 []u32{0xFFFFFFFE, 0x00000002, 0x7FFFFFFF},457 0x00000002,
456 []u32{0xFFFFFFFE, 0x00000003, 0x55555554},458 0x00000001,
457 []u32{0xFFFFFFFE, 0x00000010, 0x0FFFFFFF},459 0x00000002,
458 []u32{0xFFFFFFFE, 0x078644FA, 0x00000022},460 },
459 []u32{0xFFFFFFFE, 0x0747AE14, 0x00000023},461 []u32{
460 []u32{0xFFFFFFFE, 0x7FFFFFFF, 0x00000002},462 0x00000002,
461 []u32{0xFFFFFFFE, 0x80000000, 0x00000001},463 0x00000002,
462 []u32{0xFFFFFFFE, 0xFFFFFFFD, 0x00000001},464 0x00000001,
463 []u32{0xFFFFFFFE, 0xFFFFFFFE, 0x00000001},465 },
464 []u32{0xFFFFFFFE, 0xFFFFFFFF, 0x00000000},466 []u32{
465 []u32{0xFFFFFFFF, 0x00000001, 0xFFFFFFFF},467 0x00000002,
466 []u32{0xFFFFFFFF, 0x00000002, 0x7FFFFFFF},468 0x00000003,
467 []u32{0xFFFFFFFF, 0x00000003, 0x55555555},469 0x00000000,
468 []u32{0xFFFFFFFF, 0x00000010, 0x0FFFFFFF},470 },
469 []u32{0xFFFFFFFF, 0x078644FA, 0x00000022},471 []u32{
470 []u32{0xFFFFFFFF, 0x0747AE14, 0x00000023},472 0x00000002,
471 []u32{0xFFFFFFFF, 0x7FFFFFFF, 0x00000002},473 0x00000010,
472 []u32{0xFFFFFFFF, 0x80000000, 0x00000001},474 0x00000000,
473 []u32{0xFFFFFFFF, 0xFFFFFFFD, 0x00000001},475 },
474 []u32{0xFFFFFFFF, 0xFFFFFFFE, 0x00000001},476 []u32{
475 []u32{0xFFFFFFFF, 0xFFFFFFFF, 0x00000001},477 0x00000002,
478 0x078644FA,
479 0x00000000,
480 },
481 []u32{
482 0x00000002,
483 0x0747AE14,
484 0x00000000,
485 },
486 []u32{
487 0x00000002,
488 0x7FFFFFFF,
489 0x00000000,
490 },
491 []u32{
492 0x00000002,
493 0x80000000,
494 0x00000000,
495 },
496 []u32{
497 0x00000002,
498 0xFFFFFFFD,
499 0x00000000,
500 },
501 []u32{
502 0x00000002,
503 0xFFFFFFFE,
504 0x00000000,
505 },
506 []u32{
507 0x00000002,
508 0xFFFFFFFF,
509 0x00000000,
510 },
511 []u32{
512 0x00000003,
513 0x00000001,
514 0x00000003,
515 },
516 []u32{
517 0x00000003,
518 0x00000002,
519 0x00000001,
520 },
521 []u32{
522 0x00000003,
523 0x00000003,
524 0x00000001,
525 },
526 []u32{
527 0x00000003,
528 0x00000010,
529 0x00000000,
530 },
531 []u32{
532 0x00000003,
533 0x078644FA,
534 0x00000000,
535 },
536 []u32{
537 0x00000003,
538 0x0747AE14,
539 0x00000000,
540 },
541 []u32{
542 0x00000003,
543 0x7FFFFFFF,
544 0x00000000,
545 },
546 []u32{
547 0x00000003,
548 0x80000000,
549 0x00000000,
550 },
551 []u32{
552 0x00000003,
553 0xFFFFFFFD,
554 0x00000000,
555 },
556 []u32{
557 0x00000003,
558 0xFFFFFFFE,
559 0x00000000,
560 },
561 []u32{
562 0x00000003,
563 0xFFFFFFFF,
564 0x00000000,
565 },
566 []u32{
567 0x00000010,
568 0x00000001,
569 0x00000010,
570 },
571 []u32{
572 0x00000010,
573 0x00000002,
574 0x00000008,
575 },
576 []u32{
577 0x00000010,
578 0x00000003,
579 0x00000005,
580 },
581 []u32{
582 0x00000010,
583 0x00000010,
584 0x00000001,
585 },
586 []u32{
587 0x00000010,
588 0x078644FA,
589 0x00000000,
590 },
591 []u32{
592 0x00000010,
593 0x0747AE14,
594 0x00000000,
595 },
596 []u32{
597 0x00000010,
598 0x7FFFFFFF,
599 0x00000000,
600 },
601 []u32{
602 0x00000010,
603 0x80000000,
604 0x00000000,
605 },
606 []u32{
607 0x00000010,
608 0xFFFFFFFD,
609 0x00000000,
610 },
611 []u32{
612 0x00000010,
613 0xFFFFFFFE,
614 0x00000000,
615 },
616 []u32{
617 0x00000010,
618 0xFFFFFFFF,
619 0x00000000,
620 },
621 []u32{
622 0x078644FA,
623 0x00000001,
624 0x078644FA,
625 },
626 []u32{
627 0x078644FA,
628 0x00000002,
629 0x03C3227D,
630 },
631 []u32{
632 0x078644FA,
633 0x00000003,
634 0x028216FE,
635 },
636 []u32{
637 0x078644FA,
638 0x00000010,
639 0x0078644F,
640 },
641 []u32{
642 0x078644FA,
643 0x078644FA,
644 0x00000001,
645 },
646 []u32{
647 0x078644FA,
648 0x0747AE14,
649 0x00000001,
650 },
651 []u32{
652 0x078644FA,
653 0x7FFFFFFF,
654 0x00000000,
655 },
656 []u32{
657 0x078644FA,
658 0x80000000,
659 0x00000000,
660 },
661 []u32{
662 0x078644FA,
663 0xFFFFFFFD,
664 0x00000000,
665 },
666 []u32{
667 0x078644FA,
668 0xFFFFFFFE,
669 0x00000000,
670 },
671 []u32{
672 0x078644FA,
673 0xFFFFFFFF,
674 0x00000000,
675 },
676 []u32{
677 0x0747AE14,
678 0x00000001,
679 0x0747AE14,
680 },
681 []u32{
682 0x0747AE14,
683 0x00000002,
684 0x03A3D70A,
685 },
686 []u32{
687 0x0747AE14,
688 0x00000003,
689 0x026D3A06,
690 },
691 []u32{
692 0x0747AE14,
693 0x00000010,
694 0x00747AE1,
695 },
696 []u32{
697 0x0747AE14,
698 0x078644FA,
699 0x00000000,
700 },
701 []u32{
702 0x0747AE14,
703 0x0747AE14,
704 0x00000001,
705 },
706 []u32{
707 0x0747AE14,
708 0x7FFFFFFF,
709 0x00000000,
710 },
711 []u32{
712 0x0747AE14,
713 0x80000000,
714 0x00000000,
715 },
716 []u32{
717 0x0747AE14,
718 0xFFFFFFFD,
719 0x00000000,
720 },
721 []u32{
722 0x0747AE14,
723 0xFFFFFFFE,
724 0x00000000,
725 },
726 []u32{
727 0x0747AE14,
728 0xFFFFFFFF,
729 0x00000000,
730 },
731 []u32{
732 0x7FFFFFFF,
733 0x00000001,
734 0x7FFFFFFF,
735 },
736 []u32{
737 0x7FFFFFFF,
738 0x00000002,
739 0x3FFFFFFF,
740 },
741 []u32{
742 0x7FFFFFFF,
743 0x00000003,
744 0x2AAAAAAA,
745 },
746 []u32{
747 0x7FFFFFFF,
748 0x00000010,
749 0x07FFFFFF,
750 },
751 []u32{
752 0x7FFFFFFF,
753 0x078644FA,
754 0x00000011,
755 },
756 []u32{
757 0x7FFFFFFF,
758 0x0747AE14,
759 0x00000011,
760 },
761 []u32{
762 0x7FFFFFFF,
763 0x7FFFFFFF,
764 0x00000001,
765 },
766 []u32{
767 0x7FFFFFFF,
768 0x80000000,
769 0x00000000,
770 },
771 []u32{
772 0x7FFFFFFF,
773 0xFFFFFFFD,
774 0x00000000,
775 },
776 []u32{
777 0x7FFFFFFF,
778 0xFFFFFFFE,
779 0x00000000,
780 },
781 []u32{
782 0x7FFFFFFF,
783 0xFFFFFFFF,
784 0x00000000,
785 },
786 []u32{
787 0x80000000,
788 0x00000001,
789 0x80000000,
790 },
791 []u32{
792 0x80000000,
793 0x00000002,
794 0x40000000,
795 },
796 []u32{
797 0x80000000,
798 0x00000003,
799 0x2AAAAAAA,
800 },
801 []u32{
802 0x80000000,
803 0x00000010,
804 0x08000000,
805 },
806 []u32{
807 0x80000000,
808 0x078644FA,
809 0x00000011,
810 },
811 []u32{
812 0x80000000,
813 0x0747AE14,
814 0x00000011,
815 },
816 []u32{
817 0x80000000,
818 0x7FFFFFFF,
819 0x00000001,
820 },
821 []u32{
822 0x80000000,
823 0x80000000,
824 0x00000001,
825 },
826 []u32{
827 0x80000000,
828 0xFFFFFFFD,
829 0x00000000,
830 },
831 []u32{
832 0x80000000,
833 0xFFFFFFFE,
834 0x00000000,
835 },
836 []u32{
837 0x80000000,
838 0xFFFFFFFF,
839 0x00000000,
840 },
841 []u32{
842 0xFFFFFFFD,
843 0x00000001,
844 0xFFFFFFFD,
845 },
846 []u32{
847 0xFFFFFFFD,
848 0x00000002,
849 0x7FFFFFFE,
850 },
851 []u32{
852 0xFFFFFFFD,
853 0x00000003,
854 0x55555554,
855 },
856 []u32{
857 0xFFFFFFFD,
858 0x00000010,
859 0x0FFFFFFF,
860 },
861 []u32{
862 0xFFFFFFFD,
863 0x078644FA,
864 0x00000022,
865 },
866 []u32{
867 0xFFFFFFFD,
868 0x0747AE14,
869 0x00000023,
870 },
871 []u32{
872 0xFFFFFFFD,
873 0x7FFFFFFF,
874 0x00000001,
875 },
876 []u32{
877 0xFFFFFFFD,
878 0x80000000,
879 0x00000001,
880 },
881 []u32{
882 0xFFFFFFFD,
883 0xFFFFFFFD,
884 0x00000001,
885 },
886 []u32{
887 0xFFFFFFFD,
888 0xFFFFFFFE,
889 0x00000000,
890 },
891 []u32{
892 0xFFFFFFFD,
893 0xFFFFFFFF,
894 0x00000000,
895 },
896 []u32{
897 0xFFFFFFFE,
898 0x00000001,
899 0xFFFFFFFE,
900 },
901 []u32{
902 0xFFFFFFFE,
903 0x00000002,
904 0x7FFFFFFF,
905 },
906 []u32{
907 0xFFFFFFFE,
908 0x00000003,
909 0x55555554,
910 },
911 []u32{
912 0xFFFFFFFE,
913 0x00000010,
914 0x0FFFFFFF,
915 },
916 []u32{
917 0xFFFFFFFE,
918 0x078644FA,
919 0x00000022,
920 },
921 []u32{
922 0xFFFFFFFE,
923 0x0747AE14,
924 0x00000023,
925 },
926 []u32{
927 0xFFFFFFFE,
928 0x7FFFFFFF,
929 0x00000002,
930 },
931 []u32{
932 0xFFFFFFFE,
933 0x80000000,
934 0x00000001,
935 },
936 []u32{
937 0xFFFFFFFE,
938 0xFFFFFFFD,
939 0x00000001,
940 },
941 []u32{
942 0xFFFFFFFE,
943 0xFFFFFFFE,
944 0x00000001,
945 },
946 []u32{
947 0xFFFFFFFE,
948 0xFFFFFFFF,
949 0x00000000,
950 },
951 []u32{
952 0xFFFFFFFF,
953 0x00000001,
954 0xFFFFFFFF,
955 },
956 []u32{
957 0xFFFFFFFF,
958 0x00000002,
959 0x7FFFFFFF,
960 },
961 []u32{
962 0xFFFFFFFF,
963 0x00000003,
964 0x55555555,
965 },
966 []u32{
967 0xFFFFFFFF,
968 0x00000010,
969 0x0FFFFFFF,
970 },
971 []u32{
972 0xFFFFFFFF,
973 0x078644FA,
974 0x00000022,
975 },
976 []u32{
977 0xFFFFFFFF,
978 0x0747AE14,
979 0x00000023,
980 },
981 []u32{
982 0xFFFFFFFF,
983 0x7FFFFFFF,
984 0x00000002,
985 },
986 []u32{
987 0xFFFFFFFF,
988 0x80000000,
989 0x00000001,
990 },
991 []u32{
992 0xFFFFFFFF,
993 0xFFFFFFFD,
994 0x00000001,
995 },
996 []u32{
997 0xFFFFFFFF,
998 0xFFFFFFFE,
999 0x00000001,
1000 },
1001 []u32{
1002 0xFFFFFFFF,
1003 0xFFFFFFFF,
1004 0x00000001,
1005 },
476 };1006 };
4771007
478 for (cases) |case| {1008 for (cases) |case| {
std/special/compiler_rt/udivmod.zig+23-20
...@@ -1,7 +1,10 @@...@@ -1,7 +1,10 @@
1const builtin = @import("builtin");1const builtin = @import("builtin");
2const is_test = builtin.is_test;2const is_test = builtin.is_test;
33
4const low = switch (builtin.endian) { builtin.Endian.Big => 1, builtin.Endian.Little => 0 };4const low = switch (builtin.endian) {
5 builtin.Endian.Big => 1,
6 builtin.Endian.Little => 0,
7};
5const high = 1 - low;8const high = 1 - low;
69
7pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: ?&DoubleInt) DoubleInt {10pub 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:...@@ -11,8 +14,8 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
11 const SignedDoubleInt = @IntType(true, DoubleInt.bit_count);14 const SignedDoubleInt = @IntType(true, DoubleInt.bit_count);
12 const Log2SingleInt = @import("../../math/index.zig").Log2Int(SingleInt);15 const Log2SingleInt = @import("../../math/index.zig").Log2Int(SingleInt);
1316
14 const n = *@ptrCast(&const [2]SingleInt, &a); // TODO issue #42117 const n = @ptrCast(&const [2]SingleInt, &a).*; // TODO issue #421
15 const d = *@ptrCast(&const [2]SingleInt, &b); // TODO issue #42118 const d = @ptrCast(&const [2]SingleInt, &b).*; // TODO issue #421
16 var q: [2]SingleInt = undefined;19 var q: [2]SingleInt = undefined;
17 var r: [2]SingleInt = undefined;20 var r: [2]SingleInt = undefined;
18 var sr: c_uint = undefined;21 var sr: c_uint = undefined;
...@@ -23,7 +26,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:...@@ -23,7 +26,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
23 // ---26 // ---
24 // 0 X27 // 0 X
25 if (maybe_rem) |rem| {28 if (maybe_rem) |rem| {
26 *rem = n[low] % d[low];29 rem.* = n[low] % d[low];
27 }30 }
28 return n[low] / d[low];31 return n[low] / d[low];
29 }32 }
...@@ -31,7 +34,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:...@@ -31,7 +34,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
31 // ---34 // ---
32 // K X35 // K X
33 if (maybe_rem) |rem| {36 if (maybe_rem) |rem| {
34 *rem = n[low];37 rem.* = n[low];
35 }38 }
36 return 0;39 return 0;
37 }40 }
...@@ -42,7 +45,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:...@@ -42,7 +45,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
42 // ---45 // ---
43 // 0 046 // 0 0
44 if (maybe_rem) |rem| {47 if (maybe_rem) |rem| {
45 *rem = n[high] % d[low];48 rem.* = n[high] % d[low];
46 }49 }
47 return n[high] / d[low];50 return n[high] / d[low];
48 }51 }
...@@ -54,7 +57,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:...@@ -54,7 +57,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
54 if (maybe_rem) |rem| {57 if (maybe_rem) |rem| {
55 r[high] = n[high] % d[high];58 r[high] = n[high] % d[high];
56 r[low] = 0;59 r[low] = 0;
57 *rem = *@ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &r[0]); // TODO issue #42160 rem.* = @ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &r[0]).*; // TODO issue #421
58 }61 }
59 return n[high] / d[high];62 return n[high] / d[high];
60 }63 }
...@@ -66,7 +69,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:...@@ -66,7 +69,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
66 if (maybe_rem) |rem| {69 if (maybe_rem) |rem| {
67 r[low] = n[low];70 r[low] = n[low];
68 r[high] = n[high] & (d[high] - 1);71 r[high] = n[high] & (d[high] - 1);
69 *rem = *@ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &r[0]); // TODO issue #42172 rem.* = @ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &r[0]).*; // TODO issue #421
70 }73 }
71 return n[high] >> Log2SingleInt(@ctz(d[high]));74 return n[high] >> Log2SingleInt(@ctz(d[high]));
72 }75 }
...@@ -77,7 +80,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:...@@ -77,7 +80,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
77 // 0 <= sr <= SingleInt.bit_count - 2 or sr large80 // 0 <= sr <= SingleInt.bit_count - 2 or sr large
78 if (sr > SingleInt.bit_count - 2) {81 if (sr > SingleInt.bit_count - 2) {
79 if (maybe_rem) |rem| {82 if (maybe_rem) |rem| {
80 *rem = a;83 rem.* = a;
81 }84 }
82 return 0;85 return 0;
83 }86 }
...@@ -98,7 +101,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:...@@ -98,7 +101,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
98 if ((d[low] & (d[low] - 1)) == 0) {101 if ((d[low] & (d[low] - 1)) == 0) {
99 // d is a power of 2102 // d is a power of 2
100 if (maybe_rem) |rem| {103 if (maybe_rem) |rem| {
101 *rem = n[low] & (d[low] - 1);104 rem.* = n[low] & (d[low] - 1);
102 }105 }
103 if (d[low] == 1) {106 if (d[low] == 1) {
104 return a;107 return a;
...@@ -106,7 +109,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:...@@ -106,7 +109,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
106 sr = @ctz(d[low]);109 sr = @ctz(d[low]);
107 q[high] = n[high] >> Log2SingleInt(sr);110 q[high] = n[high] >> Log2SingleInt(sr);
108 q[low] = (n[high] << Log2SingleInt(SingleInt.bit_count - sr)) | (n[low] >> Log2SingleInt(sr));111 q[low] = (n[high] << Log2SingleInt(SingleInt.bit_count - sr)) | (n[low] >> Log2SingleInt(sr));
109 return *@ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &q[0]); // TODO issue #421112 return @ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &q[0]).*; // TODO issue #421
110 }113 }
111 // K X114 // K X
112 // ---115 // ---
...@@ -141,7 +144,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:...@@ -141,7 +144,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
141 // 0 <= sr <= SingleInt.bit_count - 1 or sr large144 // 0 <= sr <= SingleInt.bit_count - 1 or sr large
142 if (sr > SingleInt.bit_count - 1) {145 if (sr > SingleInt.bit_count - 1) {
143 if (maybe_rem) |rem| {146 if (maybe_rem) |rem| {
144 *rem = a;147 rem.* = a;
145 }148 }
146 return 0;149 return 0;
147 }150 }
...@@ -170,25 +173,25 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:...@@ -170,25 +173,25 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
170 var r_all: DoubleInt = undefined;173 var r_all: DoubleInt = undefined;
171 while (sr > 0) : (sr -= 1) {174 while (sr > 0) : (sr -= 1) {
172 // r:q = ((r:q) << 1) | carry175 // r:q = ((r:q) << 1) | carry
173 r[high] = (r[high] << 1) | (r[low] >> (SingleInt.bit_count - 1));176 r[high] = (r[high] << 1) | (r[low] >> (SingleInt.bit_count - 1));
174 r[low] = (r[low] << 1) | (q[high] >> (SingleInt.bit_count - 1));177 r[low] = (r[low] << 1) | (q[high] >> (SingleInt.bit_count - 1));
175 q[high] = (q[high] << 1) | (q[low] >> (SingleInt.bit_count - 1));178 q[high] = (q[high] << 1) | (q[low] >> (SingleInt.bit_count - 1));
176 q[low] = (q[low] << 1) | carry;179 q[low] = (q[low] << 1) | carry;
177 // carry = 0;180 // carry = 0;
178 // if (r.all >= b)181 // if (r.all >= b)
179 // {182 // {
180 // r.all -= b;183 // r.all -= b;
181 // carry = 1;184 // carry = 1;
182 // }185 // }
183 r_all = *@ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &r[0]); // TODO issue #421186 r_all = @ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &r[0]).*; // TODO issue #421
184 const s: SignedDoubleInt = SignedDoubleInt(b -% r_all -% 1) >> (DoubleInt.bit_count - 1);187 const s: SignedDoubleInt = SignedDoubleInt(b -% r_all -% 1) >> (DoubleInt.bit_count - 1);
185 carry = u32(s & 1);188 carry = u32(s & 1);
186 r_all -= b & @bitCast(DoubleInt, s);189 r_all -= b & @bitCast(DoubleInt, s);
187 r = *@ptrCast(&[2]SingleInt, &r_all); // TODO issue #421190 r = @ptrCast(&[2]SingleInt, &r_all).*; // TODO issue #421
188 }191 }
189 const q_all = ((*@ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &q[0])) << 1) | carry; // TODO issue #421192 const q_all = ((@ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &q[0]).*) << 1) | carry; // TODO issue #421
190 if (maybe_rem) |rem| {193 if (maybe_rem) |rem| {
191 *rem = r_all;194 rem.* = r_all;
192 }195 }
193 return q_all;196 return q_all;
194}197}
std/special/compiler_rt/udivmodti4.zig+1-1
...@@ -9,7 +9,7 @@ pub extern fn __udivmodti4(a: u128, b: u128, maybe_rem: ?&u128) u128 {...@@ -9,7 +9,7 @@ pub extern fn __udivmodti4(a: u128, b: u128, maybe_rem: ?&u128) u128 {
99
10pub extern fn __udivmodti4_windows_x86_64(a: &const u128, b: &const u128, maybe_rem: ?&u128) void {10pub extern fn __udivmodti4_windows_x86_64(a: &const u128, b: &const u128, maybe_rem: ?&u128) void {
11 @setRuntimeSafety(builtin.is_test);11 @setRuntimeSafety(builtin.is_test);
12 compiler_rt.setXmm0(u128, udivmod(u128, *a, *b, maybe_rem));12 compiler_rt.setXmm0(u128, udivmod(u128, a.*, b.*, maybe_rem));
13}13}
1414
15test "import udivmodti4" {15test "import udivmodti4" {
std/special/compiler_rt/umodti3.zig+1-1
...@@ -11,5 +11,5 @@ pub extern fn __umodti3(a: u128, b: u128) u128 {...@@ -11,5 +11,5 @@ pub extern fn __umodti3(a: u128, b: u128) u128 {
1111
12pub extern fn __umodti3_windows_x86_64(a: &const u128, b: &const u128) void {12pub extern fn __umodti3_windows_x86_64(a: &const u128, b: &const u128) void {
13 @setRuntimeSafety(builtin.is_test);13 @setRuntimeSafety(builtin.is_test);
14 compiler_rt.setXmm0(u128, __umodti3(*a, *b));14 compiler_rt.setXmm0(u128, __umodti3(a.*, b.*));
15}15}
test/cases/cast.zig+3-3
...@@ -14,7 +14,7 @@ test "integer literal to pointer cast" {...@@ -14,7 +14,7 @@ test "integer literal to pointer cast" {
14}14}
1515
16test "pointer reinterpret const float to int" {16test "pointer reinterpret const float to int" {
17 const float: f64 = 5.99999999999994648725e - 01;17 const float: f64 = 5.99999999999994648725e-01;
18 const float_ptr = &float;18 const float_ptr = &float;
19 const int_ptr = @ptrCast(&const i32, float_ptr);19 const int_ptr = @ptrCast(&const i32, float_ptr);
20 const int_val = int_ptr.*;20 const int_val = int_ptr.*;
...@@ -121,13 +121,13 @@ test "implicitly cast indirect pointer to maybe-indirect pointer" {...@@ -121,13 +121,13 @@ test "implicitly cast indirect pointer to maybe-indirect pointer" {
121 return (p.*).x;121 return (p.*).x;
122 }122 }
123 fn maybeConstConst(p: ?&const &const Self) u8 {123 fn maybeConstConst(p: ?&const &const Self) u8 {
124 return (??p.*).x;124 return ((??p).*).x;
125 }125 }
126 fn constConstConst(p: &const &const &const Self) u8 {126 fn constConstConst(p: &const &const &const Self) u8 {
127 return (p.*.*).x;127 return (p.*.*).x;
128 }128 }
129 fn maybeConstConstConst(p: ?&const &const &const Self) u8 {129 fn maybeConstConstConst(p: ?&const &const &const Self) u8 {
130 return (??p.*.*).x;130 return ((??p).*.*).x;
131 }131 }
132 };132 };
133 const s = S {133 const s = S {
test/cases/generics.zig+1-1
...@@ -127,7 +127,7 @@ test "generic fn with implicit cast" {...@@ -127,7 +127,7 @@ test "generic fn with implicit cast" {
127 }) == 0);127 }) == 0);
128}128}
129fn getByte(ptr: ?&const u8) u8 {129fn getByte(ptr: ?&const u8) u8 {
130 return ??ptr.*;130 return (??ptr).*;
131}131}
132fn getFirstByte(comptime T: type, mem: []const T) u8 {132fn getFirstByte(comptime T: type, mem: []const T) u8 {
133 return getByte(@ptrCast(&const u8, &mem[0]));133 return getByte(@ptrCast(&const u8, &mem[0]));