| author | |
| committer | |
| log | ac4d55dec1e32ddef945bfa246eb78f20f31ec44 |
| tree | 31e91383c77a6b19f77e76096c38f5976161b9dd |
| parent | a35b366eb64272c6d4646aedc035a837ed0c3cb0 |
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 | 8 | return AlignedArrayList(T, @alignOf(T)); |
| 9 | 9 | } |
| 10 | 10 | |
| 11 | pub fn AlignedArrayList(comptime T: type, comptime A: u29) type{ | |
| 11 | pub fn AlignedArrayList(comptime T: type, comptime A: u29) type { | |
| 12 | 12 | return struct { |
| 13 | 13 | const Self = this; |
| 14 | 14 | |
| ... | ... | @@ -21,7 +21,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type{ |
| 21 | 21 | |
| 22 | 22 | /// Deinitialize with `deinit` or use `toOwnedSlice`. |
| 23 | 23 | pub fn init(allocator: &Allocator) Self { |
| 24 | return Self { | |
| 24 | return Self{ | |
| 25 | 25 | .items = []align(A) T{}, |
| 26 | 26 | .len = 0, |
| 27 | 27 | .allocator = allocator, |
| ... | ... | @@ -48,7 +48,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type{ |
| 48 | 48 | /// allocated with `allocator`. |
| 49 | 49 | /// Deinitialize with `deinit` or use `toOwnedSlice`. |
| 50 | 50 | pub fn fromOwnedSlice(allocator: &Allocator, slice: []align(A) T) Self { |
| 51 | return Self { | |
| 51 | return Self{ | |
| 52 | 52 | .items = slice, |
| 53 | 53 | .len = slice.len, |
| 54 | 54 | .allocator = allocator, |
| ... | ... | @@ -59,7 +59,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type{ |
| 59 | 59 | pub fn toOwnedSlice(self: &Self) []align(A) T { |
| 60 | 60 | const allocator = self.allocator; |
| 61 | 61 | const result = allocator.alignedShrink(T, A, self.items, self.len); |
| 62 | *self = init(allocator); | |
| 62 | self.* = init(allocator); | |
| 63 | 63 | return result; |
| 64 | 64 | } |
| 65 | 65 | |
| ... | ... | @@ -67,21 +67,21 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type{ |
| 67 | 67 | try l.ensureCapacity(l.len + 1); |
| 68 | 68 | l.len += 1; |
| 69 | 69 | |
| 70 | mem.copy(T, l.items[n+1..l.len], l.items[n..l.len-1]); | |
| 71 | l.items[n] = *item; | |
| 70 | mem.copy(T, l.items[n + 1..l.len], l.items[n..l.len - 1]); | |
| 71 | l.items[n] = item.*; | |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | pub fn insertSlice(l: &Self, n: usize, items: []align(A) const T) !void { |
| 75 | 75 | try l.ensureCapacity(l.len + items.len); |
| 76 | 76 | l.len += items.len; |
| 77 | 77 | |
| 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); | |
| 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); | |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | pub fn append(l: &Self, item: &const T) !void { |
| 83 | 83 | const new_item_ptr = try l.addOne(); |
| 84 | *new_item_ptr = *item; | |
| 84 | new_item_ptr.* = item.*; | |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 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 | 124 | } |
| 125 | 125 | |
| 126 | 126 | pub fn popOrNull(self: &Self) ?T { |
| 127 | if (self.len == 0) | |
| 128 | return null; | |
| 127 | if (self.len == 0) return null; | |
| 129 | 128 | return self.pop(); |
| 130 | 129 | } |
| 131 | 130 | }; |
| ... | ... | @@ -135,25 +134,35 @@ test "basic ArrayList test" { |
| 135 | 134 | var list = ArrayList(i32).init(debug.global_allocator); |
| 136 | 135 | defer list.deinit(); |
| 137 | 136 | |
| 138 | {var i: usize = 0; while (i < 10) : (i += 1) { | |
| 139 | list.append(i32(i + 1)) catch unreachable; | |
| 140 | }} | |
| 137 | { | |
| 138 | var i: usize = 0; | |
| 139 | while (i < 10) : (i += 1) { | |
| 140 | list.append(i32(i + 1)) catch unreachable; | |
| 141 | } | |
| 142 | } | |
| 141 | 143 | |
| 142 | {var i: usize = 0; while (i < 10) : (i += 1) { | |
| 143 | assert(list.items[i] == i32(i + 1)); | |
| 144 | }} | |
| 144 | { | |
| 145 | var i: usize = 0; | |
| 146 | while (i < 10) : (i += 1) { | |
| 147 | assert(list.items[i] == i32(i + 1)); | |
| 148 | } | |
| 149 | } | |
| 145 | 150 | |
| 146 | 151 | assert(list.pop() == 10); |
| 147 | 152 | assert(list.len == 9); |
| 148 | 153 | |
| 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 | 159 | assert(list.len == 12); |
| 151 | 160 | assert(list.pop() == 3); |
| 152 | 161 | assert(list.pop() == 2); |
| 153 | 162 | assert(list.pop() == 1); |
| 154 | 163 | assert(list.len == 9); |
| 155 | 164 | |
| 156 | list.appendSlice([]const i32 {}) catch unreachable; | |
| 165 | list.appendSlice([]const i32{}) catch unreachable; | |
| 157 | 166 | assert(list.len == 9); |
| 158 | 167 | } |
| 159 | 168 | |
| ... | ... | @@ -166,12 +175,15 @@ test "insert ArrayList test" { |
| 166 | 175 | assert(list.items[0] == 5); |
| 167 | 176 | assert(list.items[1] == 1); |
| 168 | 177 | |
| 169 | try list.insertSlice(1, []const i32 { 9, 8 }); | |
| 178 | try list.insertSlice(1, []const i32{ | |
| 179 | 9, | |
| 180 | 8, | |
| 181 | }); | |
| 170 | 182 | assert(list.items[0] == 5); |
| 171 | 183 | assert(list.items[1] == 9); |
| 172 | 184 | assert(list.items[2] == 8); |
| 173 | 185 | |
| 174 | const items = []const i32 { 1 }; | |
| 186 | const items = []const i32{1}; | |
| 175 | 187 | try list.insertSlice(0, items[0..0]); |
| 176 | 188 | assert(list.items[0] == 5); |
| 177 | 189 | } |
std/fmt/index.zig+38-55| ... | ... | @@ -11,9 +11,7 @@ const max_int_digits = 65; |
| 11 | 11 | /// Renders fmt string with args, calling output with slices of bytes. |
| 12 | 12 | /// If `output` returns an error, the error is returned from `format` and |
| 13 | 13 | /// `output` is not called again. |
| 14 | pub fn format(context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void, | |
| 15 | comptime fmt: []const u8, args: ...) Errors!void | |
| 16 | { | |
| 14 | pub fn format(context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void, comptime fmt: []const u8, args: ...) Errors!void { | |
| 17 | 15 | const State = enum { |
| 18 | 16 | Start, |
| 19 | 17 | OpenBrace, |
| ... | ... | @@ -221,7 +219,7 @@ pub fn format(context: var, comptime Errors: type, output: fn(@typeOf(context), |
| 221 | 219 | } |
| 222 | 220 | } |
| 223 | 221 | |
| 224 | pub fn formatValue(value: var, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8)Errors!void) Errors!void { | |
| 222 | pub fn formatValue(value: var, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void { | |
| 225 | 223 | const T = @typeOf(value); |
| 226 | 224 | switch (@typeId(T)) { |
| 227 | 225 | builtin.TypeId.Int => { |
| ... | ... | @@ -256,7 +254,7 @@ pub fn formatValue(value: var, context: var, comptime Errors: type, output: fn(@ |
| 256 | 254 | }, |
| 257 | 255 | builtin.TypeId.Pointer => { |
| 258 | 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 | 258 | } else { |
| 261 | 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 | 268 | } |
| 271 | 269 | } |
| 272 | 270 | |
| 273 | pub fn formatAsciiChar(c: u8, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8)Errors!void) Errors!void { | |
| 271 | pub fn formatAsciiChar(c: u8, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void { | |
| 274 | 272 | return output(context, (&c)[0..1]); |
| 275 | 273 | } |
| 276 | 274 | |
| 277 | pub fn formatBuf(buf: []const u8, width: usize, | |
| 278 | context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8)Errors!void) Errors!void | |
| 279 | { | |
| 275 | pub fn formatBuf(buf: []const u8, width: usize, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void { | |
| 280 | 276 | try output(context, buf); |
| 281 | 277 | |
| 282 | 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 | 285 | // Print a float in scientific notation to the specified precision. Null uses full precision. |
| 290 | 286 | // It should be the case that every full precision, printed value can be re-parsed back to the |
| 291 | 287 | // same type unambiguously. |
| 292 | pub fn formatFloatScientific(value: var, maybe_precision: ?usize, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8)Errors!void) Errors!void { | |
| 288 | pub fn formatFloatScientific(value: var, maybe_precision: ?usize, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void { | |
| 293 | 289 | var x = f64(value); |
| 294 | 290 | |
| 295 | 291 | // Errol doesn't handle these special cases. |
| ... | ... | @@ -338,7 +334,7 @@ pub fn formatFloatScientific(value: var, maybe_precision: ?usize, context: var, |
| 338 | 334 | var printed: usize = 0; |
| 339 | 335 | if (float_decimal.digits.len > 1) { |
| 340 | 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 | 338 | printed += num_digits - 1; |
| 343 | 339 | } |
| 344 | 340 | |
| ... | ... | @@ -350,12 +346,9 @@ pub fn formatFloatScientific(value: var, maybe_precision: ?usize, context: var, |
| 350 | 346 | try output(context, float_decimal.digits[0..1]); |
| 351 | 347 | try output(context, "."); |
| 352 | 348 | if (float_decimal.digits.len > 1) { |
| 353 | const num_digits = if (@typeOf(value) == f32) | |
| 354 | math.min(usize(9), float_decimal.digits.len) | |
| 355 | else | |
| 356 | float_decimal.digits.len; | |
| 349 | const num_digits = if (@typeOf(value) == f32) math.min(usize(9), float_decimal.digits.len) else float_decimal.digits.len; | |
| 357 | 350 | |
| 358 | try output(context, float_decimal.digits[1 .. num_digits]); | |
| 351 | try output(context, float_decimal.digits[1..num_digits]); | |
| 359 | 352 | } else { |
| 360 | 353 | try output(context, "0"); |
| 361 | 354 | } |
| ... | ... | @@ -381,7 +374,7 @@ pub fn formatFloatScientific(value: var, maybe_precision: ?usize, context: var, |
| 381 | 374 | |
| 382 | 375 | // Print a float of the format x.yyyyy where the number of y is specified by the precision argument. |
| 383 | 376 | // By default floats are printed at full precision (no rounding). |
| 384 | pub fn formatFloatDecimal(value: var, maybe_precision: ?usize, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8)Errors!void) Errors!void { | |
| 377 | pub fn formatFloatDecimal(value: var, maybe_precision: ?usize, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void { | |
| 385 | 378 | var x = f64(value); |
| 386 | 379 | |
| 387 | 380 | // Errol doesn't handle these special cases. |
| ... | ... | @@ -431,14 +424,14 @@ pub fn formatFloatDecimal(value: var, maybe_precision: ?usize, context: var, com |
| 431 | 424 | |
| 432 | 425 | if (num_digits_whole > 0) { |
| 433 | 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]); | |
| 435 | 428 | |
| 436 | 429 | var i = num_digits_whole_no_pad; |
| 437 | 430 | while (i < num_digits_whole) : (i += 1) { |
| 438 | 431 | try output(context, "0"); |
| 439 | 432 | } |
| 440 | 433 | } else { |
| 441 | try output(context , "0"); | |
| 434 | try output(context, "0"); | |
| 442 | 435 | } |
| 443 | 436 | |
| 444 | 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 | 463 | // Remaining fractional portion, zero-padding if insufficient. |
| 471 | 464 | debug.assert(precision >= printed); |
| 472 | 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 | 467 | return; |
| 475 | 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 | 470 | printed += float_decimal.digits.len - num_digits_whole_no_pad; |
| 478 | 471 | |
| 479 | 472 | while (printed < precision) : (printed += 1) { |
| ... | ... | @@ -489,14 +482,14 @@ pub fn formatFloatDecimal(value: var, maybe_precision: ?usize, context: var, com |
| 489 | 482 | |
| 490 | 483 | if (num_digits_whole > 0) { |
| 491 | 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]); | |
| 493 | 486 | |
| 494 | 487 | var i = num_digits_whole_no_pad; |
| 495 | 488 | while (i < num_digits_whole) : (i += 1) { |
| 496 | 489 | try output(context, "0"); |
| 497 | 490 | } |
| 498 | 491 | } else { |
| 499 | try output(context , "0"); | |
| 492 | try output(context, "0"); | |
| 500 | 493 | } |
| 501 | 494 | |
| 502 | 495 | // Omit `.` if no fractional portion |
| ... | ... | @@ -516,14 +509,11 @@ pub fn formatFloatDecimal(value: var, maybe_precision: ?usize, context: var, com |
| 516 | 509 | } |
| 517 | 510 | } |
| 518 | 511 | |
| 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 | } |
| 522 | 515 | |
| 523 | ||
| 524 | pub 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 | { | |
| 516 | pub fn formatInt(value: var, base: u8, uppercase: bool, width: usize, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void { | |
| 527 | 517 | if (@typeOf(value).is_signed) { |
| 528 | 518 | return formatIntSigned(value, base, uppercase, width, context, Errors, output); |
| 529 | 519 | } else { |
| ... | ... | @@ -531,9 +521,7 @@ pub fn formatInt(value: var, base: u8, uppercase: bool, width: usize, |
| 531 | 521 | } |
| 532 | 522 | } |
| 533 | 523 | |
| 534 | fn formatIntSigned(value: var, base: u8, uppercase: bool, width: usize, | |
| 535 | context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8)Errors!void) Errors!void | |
| 536 | { | |
| 524 | fn formatIntSigned(value: var, base: u8, uppercase: bool, width: usize, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void { | |
| 537 | 525 | const uint = @IntType(false, @typeOf(value).bit_count); |
| 538 | 526 | if (value < 0) { |
| 539 | 527 | const minus_sign: u8 = '-'; |
| ... | ... | @@ -552,9 +540,7 @@ fn formatIntSigned(value: var, base: u8, uppercase: bool, width: usize, |
| 552 | 540 | } |
| 553 | 541 | } |
| 554 | 542 | |
| 555 | fn formatIntUnsigned(value: var, base: u8, uppercase: bool, width: usize, | |
| 556 | context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8)Errors!void) Errors!void | |
| 557 | { | |
| 543 | fn formatIntUnsigned(value: var, base: u8, uppercase: bool, width: usize, context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8) Errors!void) Errors!void { | |
| 558 | 544 | // max_int_digits accounts for the minus sign. when printing an unsigned |
| 559 | 545 | // number we don't need to do that. |
| 560 | 546 | var buf: [max_int_digits - 1]u8 = undefined; |
| ... | ... | @@ -566,8 +552,7 @@ fn formatIntUnsigned(value: var, base: u8, uppercase: bool, width: usize, |
| 566 | 552 | index -= 1; |
| 567 | 553 | buf[index] = digitToChar(u8(digit), uppercase); |
| 568 | 554 | a /= base; |
| 569 | if (a == 0) | |
| 570 | break; | |
| 555 | if (a == 0) break; | |
| 571 | 556 | } |
| 572 | 557 | |
| 573 | 558 | const digits_buf = buf[index..]; |
| ... | ... | @@ -579,8 +564,7 @@ fn formatIntUnsigned(value: var, base: u8, uppercase: bool, width: usize, |
| 579 | 564 | while (true) { |
| 580 | 565 | try output(context, (&zero_byte)[0..1]); |
| 581 | 566 | leftover_padding -= 1; |
| 582 | if (leftover_padding == 0) | |
| 583 | break; | |
| 567 | if (leftover_padding == 0) break; | |
| 584 | 568 | } |
| 585 | 569 | mem.set(u8, buf[0..index], '0'); |
| 586 | 570 | return output(context, buf); |
| ... | ... | @@ -592,7 +576,7 @@ fn formatIntUnsigned(value: var, base: u8, uppercase: bool, width: usize, |
| 592 | 576 | } |
| 593 | 577 | |
| 594 | 578 | pub fn formatIntBuf(out_buf: []u8, value: var, base: u8, uppercase: bool, width: usize) usize { |
| 595 | var context = FormatIntBuf { | |
| 579 | var context = FormatIntBuf{ | |
| 596 | 580 | .out_buf = out_buf, |
| 597 | 581 | .index = 0, |
| 598 | 582 | }; |
| ... | ... | @@ -609,10 +593,8 @@ fn formatIntCallback(context: &FormatIntBuf, bytes: []const u8) (error{}!void) { |
| 609 | 593 | } |
| 610 | 594 | |
| 611 | 595 | pub fn parseInt(comptime T: type, buf: []const u8, radix: u8) !T { |
| 612 | if (!T.is_signed) | |
| 613 | return parseUnsigned(T, buf, radix); | |
| 614 | if (buf.len == 0) | |
| 615 | return T(0); | |
| 596 | if (!T.is_signed) return parseUnsigned(T, buf, radix); | |
| 597 | if (buf.len == 0) return T(0); | |
| 616 | 598 | if (buf[0] == '-') { |
| 617 | 599 | return math.negate(try parseUnsigned(T, buf[1..], radix)); |
| 618 | 600 | } else if (buf[0] == '+') { |
| ... | ... | @@ -632,9 +614,10 @@ test "fmt.parseInt" { |
| 632 | 614 | assert(if (parseInt(u8, "256", 10)) |_| false else |err| err == error.Overflow); |
| 633 | 615 | } |
| 634 | 616 | |
| 635 | const ParseUnsignedError = error { | |
| 617 | const ParseUnsignedError = error{ | |
| 636 | 618 | /// The result cannot fit in the type specified |
| 637 | 619 | Overflow, |
| 620 | ||
| 638 | 621 | /// The input had a byte that was not a digit |
| 639 | 622 | InvalidCharacter, |
| 640 | 623 | }; |
| ... | ... | @@ -659,8 +642,7 @@ pub fn charToDigit(c: u8, radix: u8) (error{InvalidCharacter}!u8) { |
| 659 | 642 | else => return error.InvalidCharacter, |
| 660 | 643 | }; |
| 661 | 644 | |
| 662 | if (value >= radix) | |
| 663 | return error.InvalidCharacter; | |
| 645 | if (value >= radix) return error.InvalidCharacter; | |
| 664 | 646 | |
| 665 | 647 | return value; |
| 666 | 648 | } |
| ... | ... | @@ -684,20 +666,21 @@ fn bufPrintWrite(context: &BufPrintContext, bytes: []const u8) !void { |
| 684 | 666 | } |
| 685 | 667 | |
| 686 | 668 | pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: ...) ![]u8 { |
| 687 | var context = BufPrintContext { .remaining = buf, }; | |
| 669 | var context = BufPrintContext{ .remaining = buf }; | |
| 688 | 670 | try format(&context, error{BufferTooSmall}, bufPrintWrite, fmt, args); |
| 689 | 671 | return buf[0..buf.len - context.remaining.len]; |
| 690 | 672 | } |
| 691 | 673 | |
| 692 | 674 | pub fn allocPrint(allocator: &mem.Allocator, comptime fmt: []const u8, args: ...) ![]u8 { |
| 693 | 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 | 678 | const buf = try allocator.alloc(u8, size); |
| 696 | 679 | return bufPrint(buf, fmt, args); |
| 697 | 680 | } |
| 698 | 681 | |
| 699 | 682 | fn countSize(size: &usize, bytes: []const u8) (error{}!void) { |
| 700 | *size += bytes.len; | |
| 683 | size.* += bytes.len; | |
| 701 | 684 | } |
| 702 | 685 | |
| 703 | 686 | test "buf print int" { |
| ... | ... | @@ -773,9 +756,7 @@ test "fmt.format" { |
| 773 | 756 | unused: u8, |
| 774 | 757 | }; |
| 775 | 758 | var buf1: [32]u8 = undefined; |
| 776 | const value = Struct { | |
| 777 | .unused = 42, | |
| 778 | }; | |
| 759 | const value = Struct{ .unused = 42 }; | |
| 779 | 760 | const result = try bufPrint(buf1[0..], "pointer: {}\n", &value); |
| 780 | 761 | assert(mem.startsWith(u8, result, "pointer: Struct@")); |
| 781 | 762 | } |
| ... | ... | @@ -988,7 +969,7 @@ test "fmt.format" { |
| 988 | 969 | |
| 989 | 970 | pub fn trim(buf: []const u8) []const u8 { |
| 990 | 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) {} | |
| 992 | 973 | |
| 993 | 974 | var end: usize = buf.len; |
| 994 | 975 | while (true) { |
| ... | ... | @@ -1000,7 +981,6 @@ pub fn trim(buf: []const u8) []const u8 { |
| 1000 | 981 | } |
| 1001 | 982 | } |
| 1002 | 983 | break; |
| 1003 | ||
| 1004 | 984 | } |
| 1005 | 985 | return buf[start..end]; |
| 1006 | 986 | } |
| ... | ... | @@ -1015,7 +995,10 @@ test "fmt.trim" { |
| 1015 | 995 | |
| 1016 | 996 | pub fn isWhiteSpace(byte: u8) bool { |
| 1017 | 997 | return switch (byte) { |
| 1018 | ' ', '\t', '\n', '\r' => true, | |
| 998 | ' ', | |
| 999 | '\t', | |
| 1000 | '\n', | |
| 1001 | '\r' => true, | |
| 1019 | 1002 | else => false, |
| 1020 | 1003 | }; |
| 1021 | 1004 | } |
std/heap.zig+52-54| ... | ... | @@ -10,7 +10,7 @@ const c = std.c; |
| 10 | 10 | const Allocator = mem.Allocator; |
| 11 | 11 | |
| 12 | 12 | pub const c_allocator = &c_allocator_state; |
| 13 | var c_allocator_state = Allocator { | |
| 13 | var c_allocator_state = Allocator{ | |
| 14 | 14 | .allocFn = cAlloc, |
| 15 | 15 | .reallocFn = cRealloc, |
| 16 | 16 | .freeFn = cFree, |
| ... | ... | @@ -18,10 +18,7 @@ var c_allocator_state = Allocator { |
| 18 | 18 | |
| 19 | 19 | fn cAlloc(self: &Allocator, n: usize, alignment: u29) ![]u8 { |
| 20 | 20 | assert(alignment <= @alignOf(c_longdouble)); |
| 21 | return if (c.malloc(n)) |buf| | |
| 22 | @ptrCast(&u8, buf)[0..n] | |
| 23 | else | |
| 24 | error.OutOfMemory; | |
| 21 | return if (c.malloc(n)) |buf| @ptrCast(&u8, buf)[0..n] else error.OutOfMemory; | |
| 25 | 22 | } |
| 26 | 23 | |
| 27 | 24 | fn cRealloc(self: &Allocator, old_mem: []u8, new_size: usize, alignment: u29) ![]u8 { |
| ... | ... | @@ -48,8 +45,8 @@ pub const DirectAllocator = struct { |
| 48 | 45 | const HeapHandle = if (builtin.os == Os.windows) os.windows.HANDLE else void; |
| 49 | 46 | |
| 50 | 47 | pub fn init() DirectAllocator { |
| 51 | return DirectAllocator { | |
| 52 | .allocator = Allocator { | |
| 48 | return DirectAllocator{ | |
| 49 | .allocator = Allocator{ | |
| 53 | 50 | .allocFn = alloc, |
| 54 | 51 | .reallocFn = realloc, |
| 55 | 52 | .freeFn = free, |
| ... | ... | @@ -71,39 +68,39 @@ pub const DirectAllocator = struct { |
| 71 | 68 | const self = @fieldParentPtr(DirectAllocator, "allocator", allocator); |
| 72 | 69 | |
| 73 | 70 | switch (builtin.os) { |
| 74 | Os.linux, Os.macosx, Os.ios => { | |
| 71 | Os.linux, | |
| 72 | Os.macosx, | |
| 73 | Os.ios => { | |
| 75 | 74 | const p = os.posix; |
| 76 | 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, | |
| 78 | p.MAP_PRIVATE|p.MAP_ANONYMOUS, -1, 0); | |
| 79 | if(addr == p.MAP_FAILED) return error.OutOfMemory; | |
| 80 | ||
| 81 | if(alloc_size == n) return @intToPtr(&u8, addr)[0..n]; | |
| 82 | ||
| 75 | const alloc_size = if (alignment <= os.page_size) n else n + alignment; | |
| 76 | const addr = p.mmap(null, alloc_size, p.PROT_READ | p.PROT_WRITE, p.MAP_PRIVATE | p.MAP_ANONYMOUS, -1, 0); | |
| 77 | if (addr == p.MAP_FAILED) return error.OutOfMemory; | |
| 78 | ||
| 79 | if (alloc_size == n) return @intToPtr(&u8, addr)[0..n]; | |
| 80 | ||
| 83 | 81 | var aligned_addr = addr & ~usize(alignment - 1); |
| 84 | 82 | aligned_addr += alignment; |
| 85 | ||
| 83 | ||
| 86 | 84 | //We can unmap the unused portions of our mmap, but we must only |
| 87 | 85 | // pass munmap bytes that exist outside our allocated pages or it |
| 88 | 86 | // will happily eat us too |
| 89 | ||
| 87 | ||
| 90 | 88 | //Since alignment > page_size, we are by definition on a page boundry |
| 91 | 89 | const unused_start = addr; |
| 92 | 90 | const unused_len = aligned_addr - 1 - unused_start; |
| 93 | 91 | |
| 94 | 92 | var err = p.munmap(unused_start, unused_len); |
| 95 | 93 | debug.assert(p.getErrno(err) == 0); |
| 96 | ||
| 94 | ||
| 97 | 95 | //It is impossible that there is an unoccupied page at the top of our |
| 98 | 96 | // mmap. |
| 99 | ||
| 97 | ||
| 100 | 98 | return @intToPtr(&u8, aligned_addr)[0..n]; |
| 101 | 99 | }, |
| 102 | 100 | Os.windows => { |
| 103 | 101 | const amt = n + alignment + @sizeOf(usize); |
| 104 | 102 | const heap_handle = self.heap_handle ?? blk: { |
| 105 | const hh = os.windows.HeapCreate(os.windows.HEAP_NO_SERIALIZE, amt, 0) | |
| 106 | ?? return error.OutOfMemory; | |
| 103 | const hh = os.windows.HeapCreate(os.windows.HEAP_NO_SERIALIZE, amt, 0) ?? return error.OutOfMemory; | |
| 107 | 104 | self.heap_handle = hh; |
| 108 | 105 | break :blk hh; |
| 109 | 106 | }; |
| ... | ... | @@ -113,7 +110,7 @@ pub const DirectAllocator = struct { |
| 113 | 110 | const march_forward_bytes = if (rem == 0) 0 else (alignment - rem); |
| 114 | 111 | const adjusted_addr = root_addr + march_forward_bytes; |
| 115 | 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 | 114 | return @intToPtr(&u8, adjusted_addr)[0..n]; |
| 118 | 115 | }, |
| 119 | 116 | else => @compileError("Unsupported OS"), |
| ... | ... | @@ -124,7 +121,9 @@ pub const DirectAllocator = struct { |
| 124 | 121 | const self = @fieldParentPtr(DirectAllocator, "allocator", allocator); |
| 125 | 122 | |
| 126 | 123 | switch (builtin.os) { |
| 127 | Os.linux, Os.macosx, Os.ios => { | |
| 124 | Os.linux, | |
| 125 | Os.macosx, | |
| 126 | Os.ios => { | |
| 128 | 127 | if (new_size <= old_mem.len) { |
| 129 | 128 | const base_addr = @ptrToInt(old_mem.ptr); |
| 130 | 129 | const old_addr_end = base_addr + old_mem.len; |
| ... | ... | @@ -144,13 +143,13 @@ pub const DirectAllocator = struct { |
| 144 | 143 | Os.windows => { |
| 145 | 144 | const old_adjusted_addr = @ptrToInt(old_mem.ptr); |
| 146 | 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 | 147 | const old_ptr = @intToPtr(os.windows.LPVOID, root_addr); |
| 149 | 148 | const amt = new_size + alignment + @sizeOf(usize); |
| 150 | 149 | const new_ptr = os.windows.HeapReAlloc(??self.heap_handle, 0, old_ptr, amt) ?? blk: { |
| 151 | 150 | if (new_size > old_mem.len) return error.OutOfMemory; |
| 152 | 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 | 153 | return old_mem[0..new_size]; |
| 155 | 154 | }; |
| 156 | 155 | const offset = old_adjusted_addr - root_addr; |
| ... | ... | @@ -158,7 +157,7 @@ pub const DirectAllocator = struct { |
| 158 | 157 | const new_adjusted_addr = new_root_addr + offset; |
| 159 | 158 | assert(new_adjusted_addr % alignment == 0); |
| 160 | 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 | 161 | return @intToPtr(&u8, new_adjusted_addr)[0..new_size]; |
| 163 | 162 | }, |
| 164 | 163 | else => @compileError("Unsupported OS"), |
| ... | ... | @@ -169,12 +168,14 @@ pub const DirectAllocator = struct { |
| 169 | 168 | const self = @fieldParentPtr(DirectAllocator, "allocator", allocator); |
| 170 | 169 | |
| 171 | 170 | switch (builtin.os) { |
| 172 | Os.linux, Os.macosx, Os.ios => { | |
| 171 | Os.linux, | |
| 172 | Os.macosx, | |
| 173 | Os.ios => { | |
| 173 | 174 | _ = os.posix.munmap(@ptrToInt(bytes.ptr), bytes.len); |
| 174 | 175 | }, |
| 175 | 176 | Os.windows => { |
| 176 | 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 | 179 | const ptr = @intToPtr(os.windows.LPVOID, root_addr); |
| 179 | 180 | _ = os.windows.HeapFree(??self.heap_handle, 0, ptr); |
| 180 | 181 | }, |
| ... | ... | @@ -195,8 +196,8 @@ pub const ArenaAllocator = struct { |
| 195 | 196 | const BufNode = std.LinkedList([]u8).Node; |
| 196 | 197 | |
| 197 | 198 | pub fn init(child_allocator: &Allocator) ArenaAllocator { |
| 198 | return ArenaAllocator { | |
| 199 | .allocator = Allocator { | |
| 199 | return ArenaAllocator{ | |
| 200 | .allocator = Allocator{ | |
| 200 | 201 | .allocFn = alloc, |
| 201 | 202 | .reallocFn = realloc, |
| 202 | 203 | .freeFn = free, |
| ... | ... | @@ -228,7 +229,7 @@ pub const ArenaAllocator = struct { |
| 228 | 229 | const buf = try self.child_allocator.alignedAlloc(u8, @alignOf(BufNode), len); |
| 229 | 230 | const buf_node_slice = ([]BufNode)(buf[0..@sizeOf(BufNode)]); |
| 230 | 231 | const buf_node = &buf_node_slice[0]; |
| 231 | *buf_node = BufNode { | |
| 232 | buf_node.* = BufNode{ | |
| 232 | 233 | .data = buf, |
| 233 | 234 | .prev = null, |
| 234 | 235 | .next = null, |
| ... | ... | @@ -253,7 +254,7 @@ pub const ArenaAllocator = struct { |
| 253 | 254 | cur_node = try self.createNode(cur_buf.len, n + alignment); |
| 254 | 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 | 258 | self.end_index = new_end_index; |
| 258 | 259 | return result; |
| 259 | 260 | } |
| ... | ... | @@ -269,7 +270,7 @@ pub const ArenaAllocator = struct { |
| 269 | 270 | } |
| 270 | 271 | } |
| 271 | 272 | |
| 272 | fn free(allocator: &Allocator, bytes: []u8) void { } | |
| 273 | fn free(allocator: &Allocator, bytes: []u8) void {} | |
| 273 | 274 | }; |
| 274 | 275 | |
| 275 | 276 | pub const FixedBufferAllocator = struct { |
| ... | ... | @@ -278,8 +279,8 @@ pub const FixedBufferAllocator = struct { |
| 278 | 279 | buffer: []u8, |
| 279 | 280 | |
| 280 | 281 | pub fn init(buffer: []u8) FixedBufferAllocator { |
| 281 | return FixedBufferAllocator { | |
| 282 | .allocator = Allocator { | |
| 282 | return FixedBufferAllocator{ | |
| 283 | .allocator = Allocator{ | |
| 283 | 284 | .allocFn = alloc, |
| 284 | 285 | .reallocFn = realloc, |
| 285 | 286 | .freeFn = free, |
| ... | ... | @@ -299,7 +300,7 @@ pub const FixedBufferAllocator = struct { |
| 299 | 300 | if (new_end_index > self.buffer.len) { |
| 300 | 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 | 304 | self.end_index = new_end_index; |
| 304 | 305 | |
| 305 | 306 | return result; |
| ... | ... | @@ -315,7 +316,7 @@ pub const FixedBufferAllocator = struct { |
| 315 | 316 | } |
| 316 | 317 | } |
| 317 | 318 | |
| 318 | fn free(allocator: &Allocator, bytes: []u8) void { } | |
| 319 | fn free(allocator: &Allocator, bytes: []u8) void {} | |
| 319 | 320 | }; |
| 320 | 321 | |
| 321 | 322 | /// lock free |
| ... | ... | @@ -325,8 +326,8 @@ pub const ThreadSafeFixedBufferAllocator = struct { |
| 325 | 326 | buffer: []u8, |
| 326 | 327 | |
| 327 | 328 | pub fn init(buffer: []u8) ThreadSafeFixedBufferAllocator { |
| 328 | return ThreadSafeFixedBufferAllocator { | |
| 329 | .allocator = Allocator { | |
| 329 | return ThreadSafeFixedBufferAllocator{ | |
| 330 | .allocator = Allocator{ | |
| 330 | 331 | .allocFn = alloc, |
| 331 | 332 | .reallocFn = realloc, |
| 332 | 333 | .freeFn = free, |
| ... | ... | @@ -348,8 +349,7 @@ pub const ThreadSafeFixedBufferAllocator = struct { |
| 348 | 349 | if (new_end_index > self.buffer.len) { |
| 349 | 350 | return error.OutOfMemory; |
| 350 | 351 | } |
| 351 | end_index = @cmpxchgWeak(usize, &self.end_index, end_index, new_end_index, | |
| 352 | builtin.AtomicOrder.SeqCst, builtin.AtomicOrder.SeqCst) ?? return self.buffer[adjusted_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]; | |
| 353 | 353 | } |
| 354 | 354 | } |
| 355 | 355 | |
| ... | ... | @@ -363,11 +363,9 @@ pub const ThreadSafeFixedBufferAllocator = struct { |
| 363 | 363 | } |
| 364 | 364 | } |
| 365 | 365 | |
| 366 | fn free(allocator: &Allocator, bytes: []u8) void { } | |
| 366 | fn free(allocator: &Allocator, bytes: []u8) void {} | |
| 367 | 367 | }; |
| 368 | 368 | |
| 369 | ||
| 370 | ||
| 371 | 369 | test "c_allocator" { |
| 372 | 370 | if (builtin.link_libc) { |
| 373 | 371 | var slice = c_allocator.alloc(u8, 50) catch return; |
| ... | ... | @@ -415,8 +413,8 @@ fn testAllocator(allocator: &mem.Allocator) !void { |
| 415 | 413 | var slice = try allocator.alloc(&i32, 100); |
| 416 | 414 | |
| 417 | 415 | for (slice) |*item, i| { |
| 418 | *item = try allocator.create(i32); | |
| 419 | **item = i32(i); | |
| 416 | item.* = try allocator.create(i32); | |
| 417 | item.*.* = i32(i); | |
| 420 | 418 | } |
| 421 | 419 | |
| 422 | 420 | for (slice) |item, i| { |
| ... | ... | @@ -434,26 +432,26 @@ fn testAllocator(allocator: &mem.Allocator) !void { |
| 434 | 432 | fn testAllocatorLargeAlignment(allocator: &mem.Allocator) mem.Allocator.Error!void { |
| 435 | 433 | //Maybe a platform's page_size is actually the same as or |
| 436 | 434 | // very near usize? |
| 437 | if(os.page_size << 2 > @maxValue(usize)) return; | |
| 438 | ||
| 435 | if (os.page_size << 2 > @maxValue(usize)) return; | |
| 436 | ||
| 439 | 437 | const USizeShift = @IntType(false, std.math.log2(usize.bit_count)); |
| 440 | 438 | const large_align = u29(os.page_size << 2); |
| 441 | ||
| 439 | ||
| 442 | 440 | var align_mask: usize = undefined; |
| 443 | 441 | _ = @shlWithOverflow(usize, ~usize(0), USizeShift(@ctz(large_align)), &align_mask); |
| 444 | ||
| 442 | ||
| 445 | 443 | var slice = try allocator.allocFn(allocator, 500, large_align); |
| 446 | 444 | debug.assert(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr)); |
| 447 | ||
| 445 | ||
| 448 | 446 | slice = try allocator.reallocFn(allocator, slice, 100, large_align); |
| 449 | 447 | debug.assert(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr)); |
| 450 | ||
| 448 | ||
| 451 | 449 | slice = try allocator.reallocFn(allocator, slice, 5000, large_align); |
| 452 | 450 | debug.assert(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr)); |
| 453 | ||
| 451 | ||
| 454 | 452 | slice = try allocator.reallocFn(allocator, slice, 10, large_align); |
| 455 | 453 | debug.assert(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr)); |
| 456 | ||
| 454 | ||
| 457 | 455 | slice = try allocator.reallocFn(allocator, slice, 20000, large_align); |
| 458 | 456 | debug.assert(@ptrToInt(slice.ptr) & align_mask == @ptrToInt(slice.ptr)); |
| 459 | 457 |
std/io.zig+18-47| ... | ... | @@ -18,32 +18,17 @@ const is_windows = builtin.os == builtin.Os.windows; |
| 18 | 18 | const GetStdIoErrs = os.WindowsGetStdHandleErrs; |
| 19 | 19 | |
| 20 | 20 | pub fn getStdErr() GetStdIoErrs!File { |
| 21 | const handle = if (is_windows) | |
| 22 | try os.windowsGetStdHandle(os.windows.STD_ERROR_HANDLE) | |
| 23 | else if (is_posix) | |
| 24 | os.posix.STDERR_FILENO | |
| 25 | else | |
| 26 | unreachable; | |
| 21 | const handle = if (is_windows) try os.windowsGetStdHandle(os.windows.STD_ERROR_HANDLE) else if (is_posix) os.posix.STDERR_FILENO else unreachable; | |
| 27 | 22 | return File.openHandle(handle); |
| 28 | 23 | } |
| 29 | 24 | |
| 30 | 25 | pub fn getStdOut() GetStdIoErrs!File { |
| 31 | const handle = if (is_windows) | |
| 32 | try os.windowsGetStdHandle(os.windows.STD_OUTPUT_HANDLE) | |
| 33 | else if (is_posix) | |
| 34 | os.posix.STDOUT_FILENO | |
| 35 | else | |
| 36 | unreachable; | |
| 26 | const handle = if (is_windows) try os.windowsGetStdHandle(os.windows.STD_OUTPUT_HANDLE) else if (is_posix) os.posix.STDOUT_FILENO else unreachable; | |
| 37 | 27 | return File.openHandle(handle); |
| 38 | 28 | } |
| 39 | 29 | |
| 40 | 30 | pub fn getStdIn() GetStdIoErrs!File { |
| 41 | const handle = if (is_windows) | |
| 42 | try os.windowsGetStdHandle(os.windows.STD_INPUT_HANDLE) | |
| 43 | else if (is_posix) | |
| 44 | os.posix.STDIN_FILENO | |
| 45 | else | |
| 46 | unreachable; | |
| 31 | const handle = if (is_windows) try os.windowsGetStdHandle(os.windows.STD_INPUT_HANDLE) else if (is_posix) os.posix.STDIN_FILENO else unreachable; | |
| 47 | 32 | return File.openHandle(handle); |
| 48 | 33 | } |
| 49 | 34 | |
| ... | ... | @@ -56,11 +41,9 @@ pub const FileInStream = struct { |
| 56 | 41 | pub const Stream = InStream(Error); |
| 57 | 42 | |
| 58 | 43 | pub fn init(file: &File) FileInStream { |
| 59 | return FileInStream { | |
| 44 | return FileInStream{ | |
| 60 | 45 | .file = file, |
| 61 | .stream = Stream { | |
| 62 | .readFn = readFn, | |
| 63 | }, | |
| 46 | .stream = Stream{ .readFn = readFn }, | |
| 64 | 47 | }; |
| 65 | 48 | } |
| 66 | 49 | |
| ... | ... | @@ -79,11 +62,9 @@ pub const FileOutStream = struct { |
| 79 | 62 | pub const Stream = OutStream(Error); |
| 80 | 63 | |
| 81 | 64 | pub fn init(file: &File) FileOutStream { |
| 82 | return FileOutStream { | |
| 65 | return FileOutStream{ | |
| 83 | 66 | .file = file, |
| 84 | .stream = Stream { | |
| 85 | .writeFn = writeFn, | |
| 86 | }, | |
| 67 | .stream = Stream{ .writeFn = writeFn }, | |
| 87 | 68 | }; |
| 88 | 69 | } |
| 89 | 70 | |
| ... | ... | @@ -121,8 +102,7 @@ pub fn InStream(comptime ReadError: type) type { |
| 121 | 102 | } |
| 122 | 103 | |
| 123 | 104 | const new_buf_size = math.min(max_size, actual_buf_len + os.page_size); |
| 124 | if (new_buf_size == actual_buf_len) | |
| 125 | return error.StreamTooLong; | |
| 105 | if (new_buf_size == actual_buf_len) return error.StreamTooLong; | |
| 126 | 106 | try buffer.resize(new_buf_size); |
| 127 | 107 | } |
| 128 | 108 | } |
| ... | ... | @@ -165,9 +145,7 @@ pub fn InStream(comptime ReadError: type) type { |
| 165 | 145 | /// memory would be greater than `max_size`, returns `error.StreamTooLong`. |
| 166 | 146 | /// Caller owns returned memory. |
| 167 | 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, | |
| 169 | delimiter: u8, max_size: usize) ![]u8 | |
| 170 | { | |
| 148 | pub fn readUntilDelimiterAlloc(self: &Self, allocator: &mem.Allocator, delimiter: u8, max_size: usize) ![]u8 { | |
| 171 | 149 | var buf = Buffer.initNull(allocator); |
| 172 | 150 | defer buf.deinit(); |
| 173 | 151 | |
| ... | ... | @@ -283,7 +261,7 @@ pub fn BufferedInStream(comptime Error: type) type { |
| 283 | 261 | pub fn BufferedInStreamCustom(comptime buffer_size: usize, comptime Error: type) type { |
| 284 | 262 | return struct { |
| 285 | 263 | const Self = this; |
| 286 | const Stream = InStream(Error); | |
| 264 | const Stream = InStream(Error); | |
| 287 | 265 | |
| 288 | 266 | pub stream: Stream, |
| 289 | 267 | |
| ... | ... | @@ -294,7 +272,7 @@ pub fn BufferedInStreamCustom(comptime buffer_size: usize, comptime Error: type) |
| 294 | 272 | end_index: usize, |
| 295 | 273 | |
| 296 | 274 | pub fn init(unbuffered_in_stream: &Stream) Self { |
| 297 | return Self { | |
| 275 | return Self{ | |
| 298 | 276 | .unbuffered_in_stream = unbuffered_in_stream, |
| 299 | 277 | .buffer = undefined, |
| 300 | 278 | |
| ... | ... | @@ -305,9 +283,7 @@ pub fn BufferedInStreamCustom(comptime buffer_size: usize, comptime Error: type) |
| 305 | 283 | .start_index = buffer_size, |
| 306 | 284 | .end_index = buffer_size, |
| 307 | 285 | |
| 308 | .stream = Stream { | |
| 309 | .readFn = readFn, | |
| 310 | }, | |
| 286 | .stream = Stream{ .readFn = readFn }, | |
| 311 | 287 | }; |
| 312 | 288 | } |
| 313 | 289 | |
| ... | ... | @@ -368,13 +344,11 @@ pub fn BufferedOutStreamCustom(comptime buffer_size: usize, comptime OutStreamEr |
| 368 | 344 | index: usize, |
| 369 | 345 | |
| 370 | 346 | pub fn init(unbuffered_out_stream: &Stream) Self { |
| 371 | return Self { | |
| 347 | return Self{ | |
| 372 | 348 | .unbuffered_out_stream = unbuffered_out_stream, |
| 373 | 349 | .buffer = undefined, |
| 374 | 350 | .index = 0, |
| 375 | .stream = Stream { | |
| 376 | .writeFn = writeFn, | |
| 377 | }, | |
| 351 | .stream = Stream{ .writeFn = writeFn }, | |
| 378 | 352 | }; |
| 379 | 353 | } |
| 380 | 354 | |
| ... | ... | @@ -416,11 +390,9 @@ pub const BufferOutStream = struct { |
| 416 | 390 | pub const Stream = OutStream(Error); |
| 417 | 391 | |
| 418 | 392 | pub fn init(buffer: &Buffer) BufferOutStream { |
| 419 | return BufferOutStream { | |
| 393 | return BufferOutStream{ | |
| 420 | 394 | .buffer = buffer, |
| 421 | .stream = Stream { | |
| 422 | .writeFn = writeFn, | |
| 423 | }, | |
| 395 | .stream = Stream{ .writeFn = writeFn }, | |
| 424 | 396 | }; |
| 425 | 397 | } |
| 426 | 398 | |
| ... | ... | @@ -430,7 +402,6 @@ pub const BufferOutStream = struct { |
| 430 | 402 | } |
| 431 | 403 | }; |
| 432 | 404 | |
| 433 | ||
| 434 | 405 | pub const BufferedAtomicFile = struct { |
| 435 | 406 | atomic_file: os.AtomicFile, |
| 436 | 407 | file_stream: FileOutStream, |
| ... | ... | @@ -441,7 +412,7 @@ pub const BufferedAtomicFile = struct { |
| 441 | 412 | var self = try allocator.create(BufferedAtomicFile); |
| 442 | 413 | errdefer allocator.destroy(self); |
| 443 | 414 | |
| 444 | *self = BufferedAtomicFile { | |
| 415 | self.* = BufferedAtomicFile{ | |
| 445 | 416 | .atomic_file = undefined, |
| 446 | 417 | .file_stream = undefined, |
| 447 | 418 | .buffered_stream = undefined, |
| ... | ... | @@ -489,7 +460,7 @@ pub fn readLine(buf: []u8) !usize { |
| 489 | 460 | '\r' => { |
| 490 | 461 | // trash the following \n |
| 491 | 462 | _ = stream.readByte() catch return error.EndOfFile; |
| 492 | return index; | |
| 463 | return index; | |
| 493 | 464 | }, |
| 494 | 465 | '\n' => return index, |
| 495 | 466 | else => { |
std/linked_list.zig+55-40| ... | ... | @@ -26,10 +26,10 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na |
| 26 | 26 | data: T, |
| 27 | 27 | |
| 28 | 28 | pub fn init(value: &const T) Node { |
| 29 | return Node { | |
| 29 | return Node{ | |
| 30 | 30 | .prev = null, |
| 31 | 31 | .next = null, |
| 32 | .data = *value, | |
| 32 | .data = value.*, | |
| 33 | 33 | }; |
| 34 | 34 | } |
| 35 | 35 | |
| ... | ... | @@ -45,18 +45,18 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na |
| 45 | 45 | }; |
| 46 | 46 | |
| 47 | 47 | first: ?&Node, |
| 48 | last: ?&Node, | |
| 49 | len: usize, | |
| 48 | last: ?&Node, | |
| 49 | len: usize, | |
| 50 | 50 | |
| 51 | 51 | /// Initialize a linked list. |
| 52 | 52 | /// |
| 53 | 53 | /// Returns: |
| 54 | 54 | /// An empty linked list. |
| 55 | 55 | pub fn init() Self { |
| 56 | return Self { | |
| 56 | return Self{ | |
| 57 | 57 | .first = null, |
| 58 | .last = null, | |
| 59 | .len = 0, | |
| 58 | .last = null, | |
| 59 | .len = 0, | |
| 60 | 60 | }; |
| 61 | 61 | } |
| 62 | 62 | |
| ... | ... | @@ -131,7 +131,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na |
| 131 | 131 | } else { |
| 132 | 132 | // Empty list. |
| 133 | 133 | list.first = new_node; |
| 134 | list.last = new_node; | |
| 134 | list.last = new_node; | |
| 135 | 135 | new_node.prev = null; |
| 136 | 136 | new_node.next = null; |
| 137 | 137 | |
| ... | ... | @@ -217,7 +217,7 @@ fn BaseLinkedList(comptime T: type, comptime ParentType: type, comptime field_na |
| 217 | 217 | pub fn createNode(list: &Self, data: &const T, allocator: &Allocator) !&Node { |
| 218 | 218 | comptime assert(!isIntrusive()); |
| 219 | 219 | var node = try list.allocateNode(allocator); |
| 220 | *node = Node.init(data); | |
| 220 | node.* = Node.init(data); | |
| 221 | 221 | return node; |
| 222 | 222 | } |
| 223 | 223 | }; |
| ... | ... | @@ -227,11 +227,11 @@ test "basic linked list test" { |
| 227 | 227 | const allocator = debug.global_allocator; |
| 228 | 228 | var list = LinkedList(u32).init(); |
| 229 | 229 | |
| 230 | var one = try list.createNode(1, allocator); | |
| 231 | var two = try list.createNode(2, allocator); | |
| 230 | var one = try list.createNode(1, allocator); | |
| 231 | var two = try list.createNode(2, allocator); | |
| 232 | 232 | var three = try list.createNode(3, allocator); |
| 233 | var four = try list.createNode(4, allocator); | |
| 234 | var five = try list.createNode(5, allocator); | |
| 233 | var four = try list.createNode(4, allocator); | |
| 234 | var five = try list.createNode(5, allocator); | |
| 235 | 235 | defer { |
| 236 | 236 | list.destroyNode(one, allocator); |
| 237 | 237 | list.destroyNode(two, allocator); |
| ... | ... | @@ -240,11 +240,11 @@ test "basic linked list test" { |
| 240 | 240 | list.destroyNode(five, allocator); |
| 241 | 241 | } |
| 242 | 242 | |
| 243 | list.append(two); // {2} | |
| 244 | list.append(five); // {2, 5} | |
| 245 | list.prepend(one); // {1, 2, 5} | |
| 246 | list.insertBefore(five, four); // {1, 2, 4, 5} | |
| 247 | list.insertAfter(two, three); // {1, 2, 3, 4, 5} | |
| 243 | list.append(two); // {2} | |
| 244 | list.append(five); // {2, 5} | |
| 245 | list.prepend(one); // {1, 2, 5} | |
| 246 | list.insertBefore(five, four); // {1, 2, 4, 5} | |
| 247 | list.insertAfter(two, three); // {1, 2, 3, 4, 5} | |
| 248 | 248 | |
| 249 | 249 | // Traverse forwards. |
| 250 | 250 | { |
| ... | ... | @@ -266,13 +266,13 @@ test "basic linked list test" { |
| 266 | 266 | } |
| 267 | 267 | } |
| 268 | 268 | |
| 269 | var first = list.popFirst(); // {2, 3, 4, 5} | |
| 270 | var last = list.pop(); // {2, 3, 4} | |
| 271 | list.remove(three); // {2, 4} | |
| 269 | var first = list.popFirst(); // {2, 3, 4, 5} | |
| 270 | var last = list.pop(); // {2, 3, 4} | |
| 271 | list.remove(three); // {2, 4} | |
| 272 | 272 | |
| 273 | assert ((??list.first).data == 2); | |
| 274 | assert ((??list.last ).data == 4); | |
| 275 | assert (list.len == 2); | |
| 273 | assert((??list.first).data == 2); | |
| 274 | assert((??list.last).data == 4); | |
| 275 | assert(list.len == 2); | |
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | const ElementList = IntrusiveLinkedList(Element, "link"); |
| ... | ... | @@ -285,17 +285,32 @@ test "basic intrusive linked list test" { |
| 285 | 285 | const allocator = debug.global_allocator; |
| 286 | 286 | var list = ElementList.init(); |
| 287 | 287 | |
| 288 | var one = Element { .value = 1, .link = ElementList.Node.initIntrusive() }; | |
| 289 | var two = Element { .value = 2, .link = ElementList.Node.initIntrusive() }; | |
| 290 | var three = Element { .value = 3, .link = ElementList.Node.initIntrusive() }; | |
| 291 | var four = Element { .value = 4, .link = ElementList.Node.initIntrusive() }; | |
| 292 | var five = Element { .value = 5, .link = ElementList.Node.initIntrusive() }; | |
| 288 | var one = Element{ | |
| 289 | .value = 1, | |
| 290 | .link = ElementList.Node.initIntrusive(), | |
| 291 | }; | |
| 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 | }; | |
| 293 | 308 | |
| 294 | list.append(&two.link); // {2} | |
| 295 | list.append(&five.link); // {2, 5} | |
| 296 | list.prepend(&one.link); // {1, 2, 5} | |
| 297 | list.insertBefore(&five.link, &four.link); // {1, 2, 4, 5} | |
| 298 | list.insertAfter(&two.link, &three.link); // {1, 2, 3, 4, 5} | |
| 309 | list.append(&two.link); // {2} | |
| 310 | list.append(&five.link); // {2, 5} | |
| 311 | list.prepend(&one.link); // {1, 2, 5} | |
| 312 | list.insertBefore(&five.link, &four.link); // {1, 2, 4, 5} | |
| 313 | list.insertAfter(&two.link, &three.link); // {1, 2, 3, 4, 5} | |
| 299 | 314 | |
| 300 | 315 | // Traverse forwards. |
| 301 | 316 | { |
| ... | ... | @@ -317,11 +332,11 @@ test "basic intrusive linked list test" { |
| 317 | 332 | } |
| 318 | 333 | } |
| 319 | 334 | |
| 320 | var first = list.popFirst(); // {2, 3, 4, 5} | |
| 321 | var last = list.pop(); // {2, 3, 4} | |
| 322 | list.remove(&three.link); // {2, 4} | |
| 335 | var first = list.popFirst(); // {2, 3, 4, 5} | |
| 336 | var last = list.pop(); // {2, 3, 4} | |
| 337 | list.remove(&three.link); // {2, 4} | |
| 323 | 338 | |
| 324 | assert ((??list.first).toData().value == 2); | |
| 325 | assert ((??list.last ).toData().value == 4); | |
| 326 | assert (list.len == 2); | |
| 339 | assert((??list.first).toData().value == 2); | |
| 340 | assert((??list.last).toData().value == 4); | |
| 341 | assert(list.len == 2); | |
| 327 | 342 | } |
std/os/index.zig+38-42| ... | ... | @@ -137,7 +137,7 @@ pub fn getRandomBytes(buf: []u8) !void { |
| 137 | 137 | } |
| 138 | 138 | }, |
| 139 | 139 | Os.zen => { |
| 140 | const randomness = []u8 { | |
| 140 | const randomness = []u8{ | |
| 141 | 141 | 42, |
| 142 | 142 | 1, |
| 143 | 143 | 7, |
| ... | ... | @@ -265,7 +265,7 @@ pub fn posixRead(fd: i32, buf: []u8) !void { |
| 265 | 265 | } |
| 266 | 266 | } |
| 267 | 267 | |
| 268 | pub const PosixWriteError = error { | |
| 268 | pub const PosixWriteError = error{ | |
| 269 | 269 | WouldBlock, |
| 270 | 270 | FileClosed, |
| 271 | 271 | DestinationAddressRequired, |
| ... | ... | @@ -310,7 +310,7 @@ pub fn posixWrite(fd: i32, bytes: []const u8) !void { |
| 310 | 310 | } |
| 311 | 311 | } |
| 312 | 312 | |
| 313 | pub const PosixOpenError = error { | |
| 313 | pub const PosixOpenError = error{ | |
| 314 | 314 | OutOfMemory, |
| 315 | 315 | AccessDenied, |
| 316 | 316 | FileTooBig, |
| ... | ... | @@ -477,7 +477,7 @@ pub fn posixExecve(argv: []const []const u8, env_map: &const BufMap, allocator: |
| 477 | 477 | return posixExecveErrnoToErr(err); |
| 478 | 478 | } |
| 479 | 479 | |
| 480 | pub const PosixExecveError = error { | |
| 480 | pub const PosixExecveError = error{ | |
| 481 | 481 | SystemResources, |
| 482 | 482 | AccessDenied, |
| 483 | 483 | InvalidExe, |
| ... | ... | @@ -512,7 +512,7 @@ fn posixExecveErrnoToErr(err: usize) PosixExecveError { |
| 512 | 512 | }; |
| 513 | 513 | } |
| 514 | 514 | |
| 515 | pub var linux_aux_raw = []usize {0} ** 38; | |
| 515 | pub var linux_aux_raw = []usize{0} ** 38; | |
| 516 | 516 | pub var posix_environ_raw: []&u8 = undefined; |
| 517 | 517 | |
| 518 | 518 | /// Caller must free result when done. |
| ... | ... | @@ -667,7 +667,7 @@ pub fn symLink(allocator: &Allocator, existing_path: []const u8, new_path: []con |
| 667 | 667 | } |
| 668 | 668 | } |
| 669 | 669 | |
| 670 | pub const WindowsSymLinkError = error { | |
| 670 | pub const WindowsSymLinkError = error{ | |
| 671 | 671 | OutOfMemory, |
| 672 | 672 | Unexpected, |
| 673 | 673 | }; |
| ... | ... | @@ -686,7 +686,7 @@ pub fn symLinkWindows(allocator: &Allocator, existing_path: []const u8, new_path |
| 686 | 686 | } |
| 687 | 687 | } |
| 688 | 688 | |
| 689 | pub const PosixSymLinkError = error { | |
| 689 | pub const PosixSymLinkError = error{ | |
| 690 | 690 | OutOfMemory, |
| 691 | 691 | AccessDenied, |
| 692 | 692 | DiskQuota, |
| ... | ... | @@ -895,7 +895,7 @@ pub const AtomicFile = struct { |
| 895 | 895 | else => return err, |
| 896 | 896 | }; |
| 897 | 897 | |
| 898 | return AtomicFile { | |
| 898 | return AtomicFile{ | |
| 899 | 899 | .allocator = allocator, |
| 900 | 900 | .file = file, |
| 901 | 901 | .tmp_path = tmp_path, |
| ... | ... | @@ -1087,7 +1087,7 @@ pub fn deleteDir(allocator: &Allocator, dir_path: []const u8) !void { |
| 1087 | 1087 | /// removes it. If it cannot be removed because it is a non-empty directory, |
| 1088 | 1088 | /// this function recursively removes its entries and then tries again. |
| 1089 | 1089 | /// TODO non-recursive implementation |
| 1090 | const DeleteTreeError = error { | |
| 1090 | const DeleteTreeError = error{ | |
| 1091 | 1091 | OutOfMemory, |
| 1092 | 1092 | AccessDenied, |
| 1093 | 1093 | FileTooBig, |
| ... | ... | @@ -1217,7 +1217,7 @@ pub const Dir = struct { |
| 1217 | 1217 | Os.ios => 0, |
| 1218 | 1218 | else => {}, |
| 1219 | 1219 | }; |
| 1220 | return Dir { | |
| 1220 | return Dir{ | |
| 1221 | 1221 | .allocator = allocator, |
| 1222 | 1222 | .fd = fd, |
| 1223 | 1223 | .darwin_seek = darwin_seek_init, |
| ... | ... | @@ -1294,7 +1294,7 @@ pub const Dir = struct { |
| 1294 | 1294 | posix.DT_WHT => Entry.Kind.Whiteout, |
| 1295 | 1295 | else => Entry.Kind.Unknown, |
| 1296 | 1296 | }; |
| 1297 | return Entry { | |
| 1297 | return Entry{ | |
| 1298 | 1298 | .name = name, |
| 1299 | 1299 | .kind = entry_kind, |
| 1300 | 1300 | }; |
| ... | ... | @@ -1355,7 +1355,7 @@ pub const Dir = struct { |
| 1355 | 1355 | posix.DT_SOCK => Entry.Kind.UnixDomainSocket, |
| 1356 | 1356 | else => Entry.Kind.Unknown, |
| 1357 | 1357 | }; |
| 1358 | return Entry { | |
| 1358 | return Entry{ | |
| 1359 | 1359 | .name = name, |
| 1360 | 1360 | .kind = entry_kind, |
| 1361 | 1361 | }; |
| ... | ... | @@ -1465,7 +1465,7 @@ pub fn posix_setregid(rgid: u32, egid: u32) !void { |
| 1465 | 1465 | }; |
| 1466 | 1466 | } |
| 1467 | 1467 | |
| 1468 | pub const WindowsGetStdHandleErrs = error { | |
| 1468 | pub const WindowsGetStdHandleErrs = error{ | |
| 1469 | 1469 | NoStdHandles, |
| 1470 | 1470 | Unexpected, |
| 1471 | 1471 | }; |
| ... | ... | @@ -1489,7 +1489,7 @@ pub const ArgIteratorPosix = struct { |
| 1489 | 1489 | count: usize, |
| 1490 | 1490 | |
| 1491 | 1491 | pub fn init() ArgIteratorPosix { |
| 1492 | return ArgIteratorPosix { | |
| 1492 | return ArgIteratorPosix{ | |
| 1493 | 1493 | .index = 0, |
| 1494 | 1494 | .count = raw.len, |
| 1495 | 1495 | }; |
| ... | ... | @@ -1522,16 +1522,14 @@ pub const ArgIteratorWindows = struct { |
| 1522 | 1522 | quote_count: usize, |
| 1523 | 1523 | seen_quote_count: usize, |
| 1524 | 1524 | |
| 1525 | pub const NextError = error { | |
| 1526 | OutOfMemory, | |
| 1527 | }; | |
| 1525 | pub const NextError = error{OutOfMemory}; | |
| 1528 | 1526 | |
| 1529 | 1527 | pub fn init() ArgIteratorWindows { |
| 1530 | 1528 | return initWithCmdLine(windows.GetCommandLineA()); |
| 1531 | 1529 | } |
| 1532 | 1530 | |
| 1533 | 1531 | pub fn initWithCmdLine(cmd_line: &const u8) ArgIteratorWindows { |
| 1534 | return ArgIteratorWindows { | |
| 1532 | return ArgIteratorWindows{ | |
| 1535 | 1533 | .index = 0, |
| 1536 | 1534 | .cmd_line = cmd_line, |
| 1537 | 1535 | .in_quote = false, |
| ... | ... | @@ -1676,9 +1674,7 @@ pub const ArgIterator = struct { |
| 1676 | 1674 | inner: InnerType, |
| 1677 | 1675 | |
| 1678 | 1676 | pub fn init() ArgIterator { |
| 1679 | return ArgIterator { | |
| 1680 | .inner = InnerType.init(), | |
| 1681 | }; | |
| 1677 | return ArgIterator{ .inner = InnerType.init() }; | |
| 1682 | 1678 | } |
| 1683 | 1679 | |
| 1684 | 1680 | pub const NextError = ArgIteratorWindows.NextError; |
| ... | ... | @@ -1757,33 +1753,33 @@ pub fn argsFree(allocator: &mem.Allocator, args_alloc: []const []u8) void { |
| 1757 | 1753 | } |
| 1758 | 1754 | |
| 1759 | 1755 | test "windows arg parsing" { |
| 1760 | testWindowsCmdLine(c"a b\tc d", [][]const u8 { | |
| 1756 | testWindowsCmdLine(c"a b\tc d", [][]const u8{ | |
| 1761 | 1757 | "a", |
| 1762 | 1758 | "b", |
| 1763 | 1759 | "c", |
| 1764 | 1760 | "d", |
| 1765 | 1761 | }); |
| 1766 | testWindowsCmdLine(c"\"abc\" d e", [][]const u8 { | |
| 1762 | testWindowsCmdLine(c"\"abc\" d e", [][]const u8{ | |
| 1767 | 1763 | "abc", |
| 1768 | 1764 | "d", |
| 1769 | 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 | 1768 | "a\\\\\\b", |
| 1773 | 1769 | "de fg", |
| 1774 | 1770 | "h", |
| 1775 | 1771 | }); |
| 1776 | testWindowsCmdLine(c"a\\\\\\\"b c d", [][]const u8 { | |
| 1772 | testWindowsCmdLine(c"a\\\\\\\"b c d", [][]const u8{ | |
| 1777 | 1773 | "a\\\"b", |
| 1778 | 1774 | "c", |
| 1779 | 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 | 1778 | "a\\\\b c", |
| 1783 | 1779 | "d", |
| 1784 | 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 | 1783 | "a", |
| 1788 | 1784 | "b", |
| 1789 | 1785 | "c", |
| ... | ... | @@ -1791,7 +1787,7 @@ test "windows arg parsing" { |
| 1791 | 1787 | "f", |
| 1792 | 1788 | }); |
| 1793 | 1789 | |
| 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 | 1791 | ".\\..\\zig-cache\\build", |
| 1796 | 1792 | "bin\\zig.exe", |
| 1797 | 1793 | ".\\..", |
| ... | ... | @@ -1811,7 +1807,7 @@ fn testWindowsCmdLine(input_cmd_line: &const u8, expected_args: []const []const |
| 1811 | 1807 | |
| 1812 | 1808 | // TODO make this a build variable that you can set |
| 1813 | 1809 | const unexpected_error_tracing = false; |
| 1814 | const UnexpectedError = error { | |
| 1810 | const UnexpectedError = error{ | |
| 1815 | 1811 | /// The Operating System returned an undocumented error code. |
| 1816 | 1812 | Unexpected, |
| 1817 | 1813 | }; |
| ... | ... | @@ -1950,7 +1946,7 @@ pub fn isTty(handle: FileHandle) bool { |
| 1950 | 1946 | } |
| 1951 | 1947 | } |
| 1952 | 1948 | |
| 1953 | pub const PosixSocketError = error { | |
| 1949 | pub const PosixSocketError = error{ | |
| 1954 | 1950 | /// Permission to create a socket of the specified type and/or |
| 1955 | 1951 | /// pro‐tocol is denied. |
| 1956 | 1952 | PermissionDenied, |
| ... | ... | @@ -1992,7 +1988,7 @@ pub fn posixSocket(domain: u32, socket_type: u32, protocol: u32) !i32 { |
| 1992 | 1988 | } |
| 1993 | 1989 | } |
| 1994 | 1990 | |
| 1995 | pub const PosixBindError = error { | |
| 1991 | pub const PosixBindError = error{ | |
| 1996 | 1992 | /// The address is protected, and the user is not the superuser. |
| 1997 | 1993 | /// For UNIX domain sockets: Search permission is denied on a component |
| 1998 | 1994 | /// of the path prefix. |
| ... | ... | @@ -2065,7 +2061,7 @@ pub fn posixBind(fd: i32, addr: &const posix.sockaddr) PosixBindError!void { |
| 2065 | 2061 | } |
| 2066 | 2062 | } |
| 2067 | 2063 | |
| 2068 | const PosixListenError = error { | |
| 2064 | const PosixListenError = error{ | |
| 2069 | 2065 | /// Another socket is already listening on the same port. |
| 2070 | 2066 | /// For Internet domain sockets, the socket referred to by sockfd had not previously |
| 2071 | 2067 | /// 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 | 2094 | } |
| 2099 | 2095 | } |
| 2100 | 2096 | |
| 2101 | pub const PosixAcceptError = error { | |
| 2097 | pub const PosixAcceptError = error{ | |
| 2102 | 2098 | /// The socket is marked nonblocking and no connections are present to be accepted. |
| 2103 | 2099 | WouldBlock, |
| 2104 | 2100 | |
| ... | ... | @@ -2165,7 +2161,7 @@ pub fn posixAccept(fd: i32, addr: &posix.sockaddr, flags: u32) PosixAcceptError! |
| 2165 | 2161 | } |
| 2166 | 2162 | } |
| 2167 | 2163 | |
| 2168 | pub const LinuxEpollCreateError = error { | |
| 2164 | pub const LinuxEpollCreateError = error{ | |
| 2169 | 2165 | /// Invalid value specified in flags. |
| 2170 | 2166 | InvalidSyscall, |
| 2171 | 2167 | |
| ... | ... | @@ -2198,7 +2194,7 @@ pub fn linuxEpollCreate(flags: u32) LinuxEpollCreateError!i32 { |
| 2198 | 2194 | } |
| 2199 | 2195 | } |
| 2200 | 2196 | |
| 2201 | pub const LinuxEpollCtlError = error { | |
| 2197 | pub const LinuxEpollCtlError = error{ | |
| 2202 | 2198 | /// epfd or fd is not a valid file descriptor. |
| 2203 | 2199 | InvalidFileDescriptor, |
| 2204 | 2200 | |
| ... | ... | @@ -2271,7 +2267,7 @@ pub fn linuxEpollWait(epfd: i32, events: []linux.epoll_event, timeout: i32) usiz |
| 2271 | 2267 | } |
| 2272 | 2268 | } |
| 2273 | 2269 | |
| 2274 | pub const PosixGetSockNameError = error { | |
| 2270 | pub const PosixGetSockNameError = error{ | |
| 2275 | 2271 | /// Insufficient resources were available in the system to perform the operation. |
| 2276 | 2272 | SystemResources, |
| 2277 | 2273 | |
| ... | ... | @@ -2295,7 +2291,7 @@ pub fn posixGetSockName(sockfd: i32) PosixGetSockNameError!posix.sockaddr { |
| 2295 | 2291 | } |
| 2296 | 2292 | } |
| 2297 | 2293 | |
| 2298 | pub const PosixConnectError = error { | |
| 2294 | pub const PosixConnectError = error{ | |
| 2299 | 2295 | /// For UNIX domain sockets, which are identified by pathname: Write permission is denied on the socket |
| 2300 | 2296 | /// file, or search permission is denied for one of the directories in the path prefix. |
| 2301 | 2297 | /// or |
| ... | ... | @@ -2484,7 +2480,7 @@ pub const Thread = struct { |
| 2484 | 2480 | } |
| 2485 | 2481 | }; |
| 2486 | 2482 | |
| 2487 | pub const SpawnThreadError = error { | |
| 2483 | pub const SpawnThreadError = error{ | |
| 2488 | 2484 | /// A system-imposed limit on the number of threads was encountered. |
| 2489 | 2485 | /// There are a number of limits that may trigger this error: |
| 2490 | 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 | 2528 | if (@sizeOf(Context) == 0) { |
| 2533 | 2529 | return startFn({}); |
| 2534 | 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 | 2558 | if (@sizeOf(Context) == 0) { |
| 2563 | 2559 | return startFn({}); |
| 2564 | 2560 | } else { |
| 2565 | return startFn(*@intToPtr(&const Context, ctx_addr)); | |
| 2561 | return startFn(@intToPtr(&const Context, ctx_addr).*); | |
| 2566 | 2562 | } |
| 2567 | 2563 | } |
| 2568 | 2564 | extern fn posixThreadMain(ctx: ?&c_void) ?&c_void { |
| ... | ... | @@ -2570,7 +2566,7 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!&Thread |
| 2570 | 2566 | _ = startFn({}); |
| 2571 | 2567 | return null; |
| 2572 | 2568 | } else { |
| 2573 | _ = startFn(*@ptrCast(&const Context, @alignCast(@alignOf(Context), ctx))); | |
| 2569 | _ = startFn(@ptrCast(&const Context, @alignCast(@alignOf(Context), ctx)).*); | |
| 2574 | 2570 | return null; |
| 2575 | 2571 | } |
| 2576 | 2572 | } |
| ... | ... | @@ -2590,7 +2586,7 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!&Thread |
| 2590 | 2586 | stack_end -= stack_end % @alignOf(Context); |
| 2591 | 2587 | assert(stack_end >= stack_addr); |
| 2592 | 2588 | const context_ptr = @alignCast(@alignOf(Context), @intToPtr(&Context, stack_end)); |
| 2593 | *context_ptr = context; | |
| 2589 | context_ptr.* = context; | |
| 2594 | 2590 | arg = stack_end; |
| 2595 | 2591 | } |
| 2596 | 2592 |
std/os/linux/index.zig+189-190| ... | ... | @@ -30,96 +30,95 @@ pub const FUTEX_PRIVATE_FLAG = 128; |
| 30 | 30 | |
| 31 | 31 | pub const FUTEX_CLOCK_REALTIME = 256; |
| 32 | 32 | |
| 33 | ||
| 34 | pub const PROT_NONE = 0; | |
| 35 | pub const PROT_READ = 1; | |
| 36 | pub const PROT_WRITE = 2; | |
| 37 | pub const PROT_EXEC = 4; | |
| 33 | pub const PROT_NONE = 0; | |
| 34 | pub const PROT_READ = 1; | |
| 35 | pub const PROT_WRITE = 2; | |
| 36 | pub const PROT_EXEC = 4; | |
| 38 | 37 | pub const PROT_GROWSDOWN = 0x01000000; |
| 39 | pub const PROT_GROWSUP = 0x02000000; | |
| 40 | ||
| 41 | pub const MAP_FAILED = @maxValue(usize); | |
| 42 | pub const MAP_SHARED = 0x01; | |
| 43 | pub const MAP_PRIVATE = 0x02; | |
| 44 | pub const MAP_TYPE = 0x0f; | |
| 45 | pub const MAP_FIXED = 0x10; | |
| 46 | pub const MAP_ANONYMOUS = 0x20; | |
| 47 | pub const MAP_NORESERVE = 0x4000; | |
| 48 | pub const MAP_GROWSDOWN = 0x0100; | |
| 49 | pub const MAP_DENYWRITE = 0x0800; | |
| 38 | pub const PROT_GROWSUP = 0x02000000; | |
| 39 | ||
| 40 | pub const MAP_FAILED = @maxValue(usize); | |
| 41 | pub const MAP_SHARED = 0x01; | |
| 42 | pub const MAP_PRIVATE = 0x02; | |
| 43 | pub const MAP_TYPE = 0x0f; | |
| 44 | pub const MAP_FIXED = 0x10; | |
| 45 | pub const MAP_ANONYMOUS = 0x20; | |
| 46 | pub const MAP_NORESERVE = 0x4000; | |
| 47 | pub const MAP_GROWSDOWN = 0x0100; | |
| 48 | pub const MAP_DENYWRITE = 0x0800; | |
| 50 | 49 | pub const MAP_EXECUTABLE = 0x1000; |
| 51 | pub const MAP_LOCKED = 0x2000; | |
| 52 | pub const MAP_POPULATE = 0x8000; | |
| 53 | pub const MAP_NONBLOCK = 0x10000; | |
| 54 | pub const MAP_STACK = 0x20000; | |
| 55 | pub const MAP_HUGETLB = 0x40000; | |
| 56 | pub const MAP_FILE = 0; | |
| 50 | pub const MAP_LOCKED = 0x2000; | |
| 51 | pub const MAP_POPULATE = 0x8000; | |
| 52 | pub const MAP_NONBLOCK = 0x10000; | |
| 53 | pub const MAP_STACK = 0x20000; | |
| 54 | pub const MAP_HUGETLB = 0x40000; | |
| 55 | pub const MAP_FILE = 0; | |
| 57 | 56 | |
| 58 | 57 | pub const F_OK = 0; |
| 59 | 58 | pub const X_OK = 1; |
| 60 | 59 | pub const W_OK = 2; |
| 61 | 60 | pub const R_OK = 4; |
| 62 | 61 | |
| 63 | pub const WNOHANG = 1; | |
| 64 | pub const WUNTRACED = 2; | |
| 65 | pub const WSTOPPED = 2; | |
| 66 | pub const WEXITED = 4; | |
| 62 | pub const WNOHANG = 1; | |
| 63 | pub const WUNTRACED = 2; | |
| 64 | pub const WSTOPPED = 2; | |
| 65 | pub const WEXITED = 4; | |
| 67 | 66 | pub const WCONTINUED = 8; |
| 68 | pub const WNOWAIT = 0x1000000; | |
| 69 | ||
| 70 | pub const SA_NOCLDSTOP = 1; | |
| 71 | pub const SA_NOCLDWAIT = 2; | |
| 72 | pub const SA_SIGINFO = 4; | |
| 73 | pub const SA_ONSTACK = 0x08000000; | |
| 74 | pub const SA_RESTART = 0x10000000; | |
| 75 | pub const SA_NODEFER = 0x40000000; | |
| 76 | pub const SA_RESETHAND = 0x80000000; | |
| 77 | pub const SA_RESTORER = 0x04000000; | |
| 78 | ||
| 79 | pub const SIGHUP = 1; | |
| 80 | pub const SIGINT = 2; | |
| 81 | pub const SIGQUIT = 3; | |
| 82 | pub const SIGILL = 4; | |
| 83 | pub const SIGTRAP = 5; | |
| 84 | pub const SIGABRT = 6; | |
| 85 | pub const SIGIOT = SIGABRT; | |
| 86 | pub const SIGBUS = 7; | |
| 87 | pub const SIGFPE = 8; | |
| 88 | pub const SIGKILL = 9; | |
| 89 | pub const SIGUSR1 = 10; | |
| 90 | pub const SIGSEGV = 11; | |
| 91 | pub const SIGUSR2 = 12; | |
| 92 | pub const SIGPIPE = 13; | |
| 93 | pub const SIGALRM = 14; | |
| 94 | pub const SIGTERM = 15; | |
| 67 | pub const WNOWAIT = 0x1000000; | |
| 68 | ||
| 69 | pub const SA_NOCLDSTOP = 1; | |
| 70 | pub const SA_NOCLDWAIT = 2; | |
| 71 | pub const SA_SIGINFO = 4; | |
| 72 | pub const SA_ONSTACK = 0x08000000; | |
| 73 | pub const SA_RESTART = 0x10000000; | |
| 74 | pub const SA_NODEFER = 0x40000000; | |
| 75 | pub const SA_RESETHAND = 0x80000000; | |
| 76 | pub const SA_RESTORER = 0x04000000; | |
| 77 | ||
| 78 | pub const SIGHUP = 1; | |
| 79 | pub const SIGINT = 2; | |
| 80 | pub const SIGQUIT = 3; | |
| 81 | pub const SIGILL = 4; | |
| 82 | pub const SIGTRAP = 5; | |
| 83 | pub const SIGABRT = 6; | |
| 84 | pub const SIGIOT = SIGABRT; | |
| 85 | pub const SIGBUS = 7; | |
| 86 | pub const SIGFPE = 8; | |
| 87 | pub const SIGKILL = 9; | |
| 88 | pub const SIGUSR1 = 10; | |
| 89 | pub const SIGSEGV = 11; | |
| 90 | pub const SIGUSR2 = 12; | |
| 91 | pub const SIGPIPE = 13; | |
| 92 | pub const SIGALRM = 14; | |
| 93 | pub const SIGTERM = 15; | |
| 95 | 94 | pub const SIGSTKFLT = 16; |
| 96 | pub const SIGCHLD = 17; | |
| 97 | pub const SIGCONT = 18; | |
| 98 | pub const SIGSTOP = 19; | |
| 99 | pub const SIGTSTP = 20; | |
| 100 | pub const SIGTTIN = 21; | |
| 101 | pub const SIGTTOU = 22; | |
| 102 | pub const SIGURG = 23; | |
| 103 | pub const SIGXCPU = 24; | |
| 104 | pub const SIGXFSZ = 25; | |
| 95 | pub const SIGCHLD = 17; | |
| 96 | pub const SIGCONT = 18; | |
| 97 | pub const SIGSTOP = 19; | |
| 98 | pub const SIGTSTP = 20; | |
| 99 | pub const SIGTTIN = 21; | |
| 100 | pub const SIGTTOU = 22; | |
| 101 | pub const SIGURG = 23; | |
| 102 | pub const SIGXCPU = 24; | |
| 103 | pub const SIGXFSZ = 25; | |
| 105 | 104 | pub const SIGVTALRM = 26; |
| 106 | pub const SIGPROF = 27; | |
| 107 | pub const SIGWINCH = 28; | |
| 108 | pub const SIGIO = 29; | |
| 109 | pub const SIGPOLL = 29; | |
| 110 | pub const SIGPWR = 30; | |
| 111 | pub const SIGSYS = 31; | |
| 105 | pub const SIGPROF = 27; | |
| 106 | pub const SIGWINCH = 28; | |
| 107 | pub const SIGIO = 29; | |
| 108 | pub const SIGPOLL = 29; | |
| 109 | pub const SIGPWR = 30; | |
| 110 | pub const SIGSYS = 31; | |
| 112 | 111 | pub const SIGUNUSED = SIGSYS; |
| 113 | 112 | |
| 114 | 113 | pub const O_RDONLY = 0o0; |
| 115 | 114 | pub const O_WRONLY = 0o1; |
| 116 | pub const O_RDWR = 0o2; | |
| 115 | pub const O_RDWR = 0o2; | |
| 117 | 116 | |
| 118 | 117 | pub const SEEK_SET = 0; |
| 119 | 118 | pub const SEEK_CUR = 1; |
| 120 | 119 | pub const SEEK_END = 2; |
| 121 | 120 | |
| 122 | pub const SIG_BLOCK = 0; | |
| 121 | pub const SIG_BLOCK = 0; | |
| 123 | 122 | pub const SIG_UNBLOCK = 1; |
| 124 | 123 | pub const SIG_SETMASK = 2; |
| 125 | 124 | |
| ... | ... | @@ -408,7 +407,6 @@ pub const DT_LNK = 10; |
| 408 | 407 | pub const DT_SOCK = 12; |
| 409 | 408 | pub const DT_WHT = 14; |
| 410 | 409 | |
| 411 | ||
| 412 | 410 | pub const TCGETS = 0x5401; |
| 413 | 411 | pub const TCSETS = 0x5402; |
| 414 | 412 | pub const TCSETSW = 0x5403; |
| ... | ... | @@ -539,23 +537,23 @@ pub const MS_BIND = 4096; |
| 539 | 537 | pub const MS_MOVE = 8192; |
| 540 | 538 | pub const MS_REC = 16384; |
| 541 | 539 | pub const MS_SILENT = 32768; |
| 542 | pub const MS_POSIXACL = (1<<16); | |
| 543 | pub const MS_UNBINDABLE = (1<<17); | |
| 544 | pub const MS_PRIVATE = (1<<18); | |
| 545 | pub const MS_SLAVE = (1<<19); | |
| 546 | pub const MS_SHARED = (1<<20); | |
| 547 | pub const MS_RELATIME = (1<<21); | |
| 548 | pub const MS_KERNMOUNT = (1<<22); | |
| 549 | pub const MS_I_VERSION = (1<<23); | |
| 550 | pub const MS_STRICTATIME = (1<<24); | |
| 551 | pub const MS_LAZYTIME = (1<<25); | |
| 552 | pub const MS_NOREMOTELOCK = (1<<27); | |
| 553 | pub const MS_NOSEC = (1<<28); | |
| 554 | pub const MS_BORN = (1<<29); | |
| 555 | pub const MS_ACTIVE = (1<<30); | |
| 556 | pub const MS_NOUSER = (1<<31); | |
| 557 | ||
| 558 | pub const MS_RMT_MASK = (MS_RDONLY|MS_SYNCHRONOUS|MS_MANDLOCK|MS_I_VERSION|MS_LAZYTIME); | |
| 540 | pub const MS_POSIXACL = (1 << 16); | |
| 541 | pub const MS_UNBINDABLE = (1 << 17); | |
| 542 | pub const MS_PRIVATE = (1 << 18); | |
| 543 | pub const MS_SLAVE = (1 << 19); | |
| 544 | pub const MS_SHARED = (1 << 20); | |
| 545 | pub const MS_RELATIME = (1 << 21); | |
| 546 | pub const MS_KERNMOUNT = (1 << 22); | |
| 547 | pub const MS_I_VERSION = (1 << 23); | |
| 548 | pub const MS_STRICTATIME = (1 << 24); | |
| 549 | pub const MS_LAZYTIME = (1 << 25); | |
| 550 | pub const MS_NOREMOTELOCK = (1 << 27); | |
| 551 | pub const MS_NOSEC = (1 << 28); | |
| 552 | pub const MS_BORN = (1 << 29); | |
| 553 | pub const MS_ACTIVE = (1 << 30); | |
| 554 | pub const MS_NOUSER = (1 << 31); | |
| 555 | ||
| 556 | pub const MS_RMT_MASK = (MS_RDONLY | MS_SYNCHRONOUS | MS_MANDLOCK | MS_I_VERSION | MS_LAZYTIME); | |
| 559 | 557 | |
| 560 | 558 | pub const MS_MGC_VAL = 0xc0ed0000; |
| 561 | 559 | pub const MS_MGC_MSK = 0xffff0000; |
| ... | ... | @@ -565,7 +563,6 @@ pub const MNT_DETACH = 2; |
| 565 | 563 | pub const MNT_EXPIRE = 4; |
| 566 | 564 | pub const UMOUNT_NOFOLLOW = 8; |
| 567 | 565 | |
| 568 | ||
| 569 | 566 | pub const S_IFMT = 0o170000; |
| 570 | 567 | |
| 571 | 568 | pub const S_IFDIR = 0o040000; |
| ... | ... | @@ -626,15 +623,30 @@ pub const TFD_CLOEXEC = O_CLOEXEC; |
| 626 | 623 | pub const TFD_TIMER_ABSTIME = 1; |
| 627 | 624 | pub const TFD_TIMER_CANCEL_ON_SET = (1 << 1); |
| 628 | 625 | |
| 629 | fn unsigned(s: i32) u32 { return @bitCast(u32, s); } | |
| 630 | fn signed(s: u32) i32 { return @bitCast(i32, s); } | |
| 631 | pub fn WEXITSTATUS(s: i32) i32 { return signed((unsigned(s) & 0xff00) >> 8); } | |
| 632 | pub fn WTERMSIG(s: i32) i32 { return signed(unsigned(s) & 0x7f); } | |
| 633 | pub fn WSTOPSIG(s: i32) i32 { return WEXITSTATUS(s); } | |
| 634 | pub fn WIFEXITED(s: i32) bool { return WTERMSIG(s) == 0; } | |
| 635 | pub fn WIFSTOPPED(s: i32) bool { return (u16)(((unsigned(s)&0xffff)*%0x10001)>>8) > 0x7f00; } | |
| 636 | pub fn WIFSIGNALED(s: i32) bool { return (unsigned(s)&0xffff)-%1 < 0xff; } | |
| 637 | ||
| 626 | fn unsigned(s: i32) u32 { | |
| 627 | return @bitCast(u32, s); | |
| 628 | } | |
| 629 | fn signed(s: u32) i32 { | |
| 630 | return @bitCast(i32, s); | |
| 631 | } | |
| 632 | pub fn WEXITSTATUS(s: i32) i32 { | |
| 633 | return signed((unsigned(s) & 0xff00) >> 8); | |
| 634 | } | |
| 635 | pub fn WTERMSIG(s: i32) i32 { | |
| 636 | return signed(unsigned(s) & 0x7f); | |
| 637 | } | |
| 638 | pub fn WSTOPSIG(s: i32) i32 { | |
| 639 | return WEXITSTATUS(s); | |
| 640 | } | |
| 641 | pub fn WIFEXITED(s: i32) bool { | |
| 642 | return WTERMSIG(s) == 0; | |
| 643 | } | |
| 644 | pub fn WIFSTOPPED(s: i32) bool { | |
| 645 | return (u16)(((unsigned(s) & 0xffff) *% 0x10001) >> 8) > 0x7f00; | |
| 646 | } | |
| 647 | pub fn WIFSIGNALED(s: i32) bool { | |
| 648 | return (unsigned(s) & 0xffff) -% 1 < 0xff; | |
| 649 | } | |
| 638 | 650 | |
| 639 | 651 | pub const winsize = extern struct { |
| 640 | 652 | ws_row: u16, |
| ... | ... | @@ -707,8 +719,7 @@ pub fn umount2(special: &const u8, flags: u32) usize { |
| 707 | 719 | } |
| 708 | 720 | |
| 709 | 721 | pub 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), | |
| 711 | @bitCast(usize, offset)); | |
| 722 | return syscall6(SYS_mmap, @ptrToInt(address), length, prot, flags, usize(fd), @bitCast(usize, offset)); | |
| 712 | 723 | } |
| 713 | 724 | |
| 714 | 725 | pub fn munmap(address: usize, length: usize) usize { |
| ... | ... | @@ -812,7 +823,8 @@ pub fn clock_gettime(clk_id: i32, tp: &timespec) usize { |
| 812 | 823 | if (@ptrToInt(f) != 0) { |
| 813 | 824 | const rc = f(clk_id, tp); |
| 814 | 825 | switch (rc) { |
| 815 | 0, @bitCast(usize, isize(-EINVAL)) => return rc, | |
| 826 | 0, | |
| 827 | @bitCast(usize, isize(-EINVAL)) => return rc, | |
| 816 | 828 | else => {}, |
| 817 | 829 | } |
| 818 | 830 | } |
| ... | ... | @@ -823,8 +835,7 @@ var vdso_clock_gettime = init_vdso_clock_gettime; |
| 823 | 835 | extern fn init_vdso_clock_gettime(clk: i32, ts: &timespec) usize { |
| 824 | 836 | const addr = vdso.lookup(VDSO_CGT_VER, VDSO_CGT_SYM); |
| 825 | 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, | |
| 827 | builtin.AtomicOrder.Monotonic, builtin.AtomicOrder.Monotonic); | |
| 838 | _ = @cmpxchgStrong(@typeOf(init_vdso_clock_gettime), &vdso_clock_gettime, init_vdso_clock_gettime, f, builtin.AtomicOrder.Monotonic, builtin.AtomicOrder.Monotonic); | |
| 828 | 839 | if (@ptrToInt(f) == 0) return @bitCast(usize, isize(-ENOSYS)); |
| 829 | 840 | return f(clk, ts); |
| 830 | 841 | } |
| ... | ... | @@ -918,18 +929,18 @@ pub fn getpid() i32 { |
| 918 | 929 | } |
| 919 | 930 | |
| 920 | 931 | pub 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 | } |
| 923 | 934 | |
| 924 | 935 | pub fn sigaction(sig: u6, noalias act: &const Sigaction, noalias oact: ?&Sigaction) usize { |
| 925 | 936 | assert(sig >= 1); |
| 926 | 937 | assert(sig != SIGKILL); |
| 927 | 938 | assert(sig != SIGSTOP); |
| 928 | var ksa = k_sigaction { | |
| 939 | var ksa = k_sigaction{ | |
| 929 | 940 | .handler = act.handler, |
| 930 | 941 | .flags = act.flags | SA_RESTORER, |
| 931 | 942 | .mask = undefined, |
| 932 | .restorer = @ptrCast(extern fn()void, restore_rt), | |
| 943 | .restorer = @ptrCast(extern fn() void, restore_rt), | |
| 933 | 944 | }; |
| 934 | 945 | var ksa_old: k_sigaction = undefined; |
| 935 | 946 | @memcpy(@ptrCast(&u8, &ksa.mask), @ptrCast(&const u8, &act.mask), 8); |
| ... | ... | @@ -952,22 +963,22 @@ const all_mask = []usize{@maxValue(usize)}; |
| 952 | 963 | const app_mask = []usize{0xfffffffc7fffffff}; |
| 953 | 964 | |
| 954 | 965 | const k_sigaction = extern struct { |
| 955 | handler: extern fn(i32)void, | |
| 966 | handler: extern fn(i32) void, | |
| 956 | 967 | flags: usize, |
| 957 | restorer: extern fn()void, | |
| 968 | restorer: extern fn() void, | |
| 958 | 969 | mask: [2]u32, |
| 959 | 970 | }; |
| 960 | 971 | |
| 961 | 972 | /// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall. |
| 962 | 973 | pub const Sigaction = struct { |
| 963 | handler: extern fn(i32)void, | |
| 974 | handler: extern fn(i32) void, | |
| 964 | 975 | mask: sigset_t, |
| 965 | 976 | flags: u32, |
| 966 | 977 | }; |
| 967 | 978 | |
| 968 | pub const SIG_ERR = @intToPtr(extern fn(i32)void, @maxValue(usize)); | |
| 969 | pub const SIG_DFL = @intToPtr(extern fn(i32)void, 0); | |
| 970 | pub const SIG_IGN = @intToPtr(extern fn(i32)void, 1); | |
| 979 | pub const SIG_ERR = @intToPtr(extern fn(i32) void, @maxValue(usize)); | |
| 980 | pub const SIG_DFL = @intToPtr(extern fn(i32) void, 0); | |
| 981 | pub const SIG_IGN = @intToPtr(extern fn(i32) void, 1); | |
| 971 | 982 | pub const empty_sigset = []usize{0} ** sigset_t.len; |
| 972 | 983 | |
| 973 | 984 | pub fn raise(sig: i32) usize { |
| ... | ... | @@ -980,25 +991,25 @@ pub fn raise(sig: i32) usize { |
| 980 | 991 | } |
| 981 | 992 | |
| 982 | 993 | fn 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 | } |
| 985 | 996 | |
| 986 | 997 | fn 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 | } |
| 989 | 1000 | |
| 990 | 1001 | fn 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 | } |
| 993 | 1004 | |
| 994 | 1005 | pub fn sigaddset(set: &sigset_t, sig: u6) void { |
| 995 | 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 | } |
| 998 | 1009 | |
| 999 | 1010 | pub fn sigismember(set: &const sigset_t, sig: u6) bool { |
| 1000 | 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 | } |
| 1003 | 1014 | |
| 1004 | 1015 | pub const in_port_t = u16; |
| ... | ... | @@ -1062,9 +1073,7 @@ pub fn recvmsg(fd: i32, msg: &msghdr, flags: u32) usize { |
| 1062 | 1073 | return syscall3(SYS_recvmsg, usize(fd), @ptrToInt(msg), flags); |
| 1063 | 1074 | } |
| 1064 | 1075 | |
| 1065 | pub fn recvfrom(fd: i32, noalias buf: &u8, len: usize, flags: u32, | |
| 1066 | noalias addr: ?&sockaddr, noalias alen: ?&socklen_t) usize | |
| 1067 | { | |
| 1076 | pub fn recvfrom(fd: i32, noalias buf: &u8, len: usize, flags: u32, noalias addr: ?&sockaddr, noalias alen: ?&socklen_t) usize { | |
| 1068 | 1077 | return syscall6(SYS_recvfrom, usize(fd), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen)); |
| 1069 | 1078 | } |
| 1070 | 1079 | |
| ... | ... | @@ -1132,25 +1141,16 @@ pub fn fgetxattr(fd: usize, name: &const u8, value: &void, size: usize) usize { |
| 1132 | 1141 | return syscall4(SYS_lgetxattr, fd, @ptrToInt(name), @ptrToInt(value), size); |
| 1133 | 1142 | } |
| 1134 | 1143 | |
| 1135 | pub fn setxattr(path: &const u8, name: &const u8, value: &const void, | |
| 1136 | size: usize, flags: usize) usize { | |
| 1137 | ||
| 1138 | return syscall5(SYS_setxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), | |
| 1139 | size, flags); | |
| 1144 | pub fn setxattr(path: &const u8, name: &const u8, value: &const void, size: usize, flags: usize) usize { | |
| 1145 | return syscall5(SYS_setxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size, flags); | |
| 1140 | 1146 | } |
| 1141 | 1147 | |
| 1142 | pub fn lsetxattr(path: &const u8, name: &const u8, value: &const void, | |
| 1143 | size: usize, flags: usize) usize { | |
| 1144 | ||
| 1145 | return syscall5(SYS_lsetxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), | |
| 1146 | size, flags); | |
| 1148 | pub fn lsetxattr(path: &const u8, name: &const u8, value: &const void, size: usize, flags: usize) usize { | |
| 1149 | return syscall5(SYS_lsetxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size, flags); | |
| 1147 | 1150 | } |
| 1148 | 1151 | |
| 1149 | pub fn fsetxattr(fd: usize, name: &const u8, value: &const void, | |
| 1150 | size: usize, flags: usize) usize { | |
| 1151 | ||
| 1152 | return syscall5(SYS_fsetxattr, fd, @ptrToInt(name), @ptrToInt(value), | |
| 1153 | size, flags); | |
| 1152 | pub fn fsetxattr(fd: usize, name: &const u8, value: &const void, size: usize, flags: usize) usize { | |
| 1153 | return syscall5(SYS_fsetxattr, fd, @ptrToInt(name), @ptrToInt(value), size, flags); | |
| 1154 | 1154 | } |
| 1155 | 1155 | |
| 1156 | 1156 | pub fn removexattr(path: &const u8, name: &const u8) usize { |
| ... | ... | @@ -1199,7 +1199,7 @@ pub fn timerfd_create(clockid: i32, flags: u32) usize { |
| 1199 | 1199 | |
| 1200 | 1200 | pub const itimerspec = extern struct { |
| 1201 | 1201 | it_interval: timespec, |
| 1202 | it_value: timespec | |
| 1202 | it_value: timespec, | |
| 1203 | 1203 | }; |
| 1204 | 1204 | |
| 1205 | 1205 | pub fn timerfd_gettime(fd: i32, curr_value: &itimerspec) usize { |
| ... | ... | @@ -1211,30 +1211,30 @@ pub fn timerfd_settime(fd: i32, flags: u32, new_value: &const itimerspec, old_va |
| 1211 | 1211 | } |
| 1212 | 1212 | |
| 1213 | 1213 | pub const _LINUX_CAPABILITY_VERSION_1 = 0x19980330; |
| 1214 | pub const _LINUX_CAPABILITY_U32S_1 = 1; | |
| 1214 | pub const _LINUX_CAPABILITY_U32S_1 = 1; | |
| 1215 | 1215 | |
| 1216 | 1216 | pub const _LINUX_CAPABILITY_VERSION_2 = 0x20071026; |
| 1217 | pub const _LINUX_CAPABILITY_U32S_2 = 2; | |
| 1217 | pub const _LINUX_CAPABILITY_U32S_2 = 2; | |
| 1218 | 1218 | |
| 1219 | 1219 | pub const _LINUX_CAPABILITY_VERSION_3 = 0x20080522; |
| 1220 | pub const _LINUX_CAPABILITY_U32S_3 = 2; | |
| 1220 | pub const _LINUX_CAPABILITY_U32S_3 = 2; | |
| 1221 | 1221 | |
| 1222 | pub const VFS_CAP_REVISION_MASK = 0xFF000000; | |
| 1223 | pub const VFS_CAP_REVISION_SHIFT = 24; | |
| 1224 | pub const VFS_CAP_FLAGS_MASK = ~VFS_CAP_REVISION_MASK; | |
| 1222 | pub const VFS_CAP_REVISION_MASK = 0xFF000000; | |
| 1223 | pub const VFS_CAP_REVISION_SHIFT = 24; | |
| 1224 | pub const VFS_CAP_FLAGS_MASK = ~VFS_CAP_REVISION_MASK; | |
| 1225 | 1225 | pub const VFS_CAP_FLAGS_EFFECTIVE = 0x000001; |
| 1226 | 1226 | |
| 1227 | 1227 | pub const VFS_CAP_REVISION_1 = 0x01000000; |
| 1228 | pub const VFS_CAP_U32_1 = 1; | |
| 1229 | pub const XATTR_CAPS_SZ_1 = @sizeOf(u32)*(1 + 2*VFS_CAP_U32_1); | |
| 1228 | pub const VFS_CAP_U32_1 = 1; | |
| 1229 | pub const XATTR_CAPS_SZ_1 = @sizeOf(u32) * (1 + 2 * VFS_CAP_U32_1); | |
| 1230 | 1230 | |
| 1231 | 1231 | pub const VFS_CAP_REVISION_2 = 0x02000000; |
| 1232 | pub const VFS_CAP_U32_2 = 2; | |
| 1233 | pub const XATTR_CAPS_SZ_2 = @sizeOf(u32)*(1 + 2*VFS_CAP_U32_2); | |
| 1232 | pub const VFS_CAP_U32_2 = 2; | |
| 1233 | pub const XATTR_CAPS_SZ_2 = @sizeOf(u32) * (1 + 2 * VFS_CAP_U32_2); | |
| 1234 | 1234 | |
| 1235 | pub const XATTR_CAPS_SZ = XATTR_CAPS_SZ_2; | |
| 1236 | pub const VFS_CAP_U32 = VFS_CAP_U32_2; | |
| 1237 | pub const VFS_CAP_REVISION = VFS_CAP_REVISION_2; | |
| 1235 | pub const XATTR_CAPS_SZ = XATTR_CAPS_SZ_2; | |
| 1236 | pub const VFS_CAP_U32 = VFS_CAP_U32_2; | |
| 1237 | pub const VFS_CAP_REVISION = VFS_CAP_REVISION_2; | |
| 1238 | 1238 | |
| 1239 | 1239 | pub const vfs_cap_data = extern struct { |
| 1240 | 1240 | //all of these are mandated as little endian |
| ... | ... | @@ -1245,49 +1245,48 @@ pub const vfs_cap_data = extern struct { |
| 1245 | 1245 | }; |
| 1246 | 1246 | |
| 1247 | 1247 | magic_etc: u32, |
| 1248 | data: [VFS_CAP_U32]Data, | |
| 1248 | data: [VFS_CAP_U32]Data, | |
| 1249 | 1249 | }; |
| 1250 | 1250 | |
| 1251 | ||
| 1252 | pub const CAP_CHOWN = 0; | |
| 1253 | pub const CAP_DAC_OVERRIDE = 1; | |
| 1254 | pub const CAP_DAC_READ_SEARCH = 2; | |
| 1255 | pub const CAP_FOWNER = 3; | |
| 1256 | pub const CAP_FSETID = 4; | |
| 1257 | pub const CAP_KILL = 5; | |
| 1258 | pub const CAP_SETGID = 6; | |
| 1259 | pub const CAP_SETUID = 7; | |
| 1260 | pub const CAP_SETPCAP = 8; | |
| 1261 | pub const CAP_LINUX_IMMUTABLE = 9; | |
| 1262 | pub const CAP_NET_BIND_SERVICE = 10; | |
| 1263 | pub const CAP_NET_BROADCAST = 11; | |
| 1264 | pub const CAP_NET_ADMIN = 12; | |
| 1265 | pub const CAP_NET_RAW = 13; | |
| 1266 | pub const CAP_IPC_LOCK = 14; | |
| 1267 | pub const CAP_IPC_OWNER = 15; | |
| 1268 | pub const CAP_SYS_MODULE = 16; | |
| 1269 | pub const CAP_SYS_RAWIO = 17; | |
| 1270 | pub const CAP_SYS_CHROOT = 18; | |
| 1271 | pub const CAP_SYS_PTRACE = 19; | |
| 1272 | pub const CAP_SYS_PACCT = 20; | |
| 1273 | pub const CAP_SYS_ADMIN = 21; | |
| 1274 | pub const CAP_SYS_BOOT = 22; | |
| 1275 | pub const CAP_SYS_NICE = 23; | |
| 1276 | pub const CAP_SYS_RESOURCE = 24; | |
| 1277 | pub const CAP_SYS_TIME = 25; | |
| 1278 | pub const CAP_SYS_TTY_CONFIG = 26; | |
| 1279 | pub const CAP_MKNOD = 27; | |
| 1280 | pub const CAP_LEASE = 28; | |
| 1281 | pub const CAP_AUDIT_WRITE = 29; | |
| 1282 | pub const CAP_AUDIT_CONTROL = 30; | |
| 1283 | pub const CAP_SETFCAP = 31; | |
| 1284 | pub const CAP_MAC_OVERRIDE = 32; | |
| 1285 | pub const CAP_MAC_ADMIN = 33; | |
| 1286 | pub const CAP_SYSLOG = 34; | |
| 1287 | pub const CAP_WAKE_ALARM = 35; | |
| 1288 | pub const CAP_BLOCK_SUSPEND = 36; | |
| 1289 | pub const CAP_AUDIT_READ = 37; | |
| 1290 | pub const CAP_LAST_CAP = CAP_AUDIT_READ; | |
| 1251 | pub const CAP_CHOWN = 0; | |
| 1252 | pub const CAP_DAC_OVERRIDE = 1; | |
| 1253 | pub const CAP_DAC_READ_SEARCH = 2; | |
| 1254 | pub const CAP_FOWNER = 3; | |
| 1255 | pub const CAP_FSETID = 4; | |
| 1256 | pub const CAP_KILL = 5; | |
| 1257 | pub const CAP_SETGID = 6; | |
| 1258 | pub const CAP_SETUID = 7; | |
| 1259 | pub const CAP_SETPCAP = 8; | |
| 1260 | pub const CAP_LINUX_IMMUTABLE = 9; | |
| 1261 | pub const CAP_NET_BIND_SERVICE = 10; | |
| 1262 | pub const CAP_NET_BROADCAST = 11; | |
| 1263 | pub const CAP_NET_ADMIN = 12; | |
| 1264 | pub const CAP_NET_RAW = 13; | |
| 1265 | pub const CAP_IPC_LOCK = 14; | |
| 1266 | pub const CAP_IPC_OWNER = 15; | |
| 1267 | pub const CAP_SYS_MODULE = 16; | |
| 1268 | pub const CAP_SYS_RAWIO = 17; | |
| 1269 | pub const CAP_SYS_CHROOT = 18; | |
| 1270 | pub const CAP_SYS_PTRACE = 19; | |
| 1271 | pub const CAP_SYS_PACCT = 20; | |
| 1272 | pub const CAP_SYS_ADMIN = 21; | |
| 1273 | pub const CAP_SYS_BOOT = 22; | |
| 1274 | pub const CAP_SYS_NICE = 23; | |
| 1275 | pub const CAP_SYS_RESOURCE = 24; | |
| 1276 | pub const CAP_SYS_TIME = 25; | |
| 1277 | pub const CAP_SYS_TTY_CONFIG = 26; | |
| 1278 | pub const CAP_MKNOD = 27; | |
| 1279 | pub const CAP_LEASE = 28; | |
| 1280 | pub const CAP_AUDIT_WRITE = 29; | |
| 1281 | pub const CAP_AUDIT_CONTROL = 30; | |
| 1282 | pub const CAP_SETFCAP = 31; | |
| 1283 | pub const CAP_MAC_OVERRIDE = 32; | |
| 1284 | pub const CAP_MAC_ADMIN = 33; | |
| 1285 | pub const CAP_SYSLOG = 34; | |
| 1286 | pub const CAP_WAKE_ALARM = 35; | |
| 1287 | pub const CAP_BLOCK_SUSPEND = 36; | |
| 1288 | pub const CAP_AUDIT_READ = 37; | |
| 1289 | pub const CAP_LAST_CAP = CAP_AUDIT_READ; | |
| 1291 | 1290 | |
| 1292 | 1291 | pub fn cap_valid(u8: x) bool { |
| 1293 | 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 | 27 | nakedcc fn _start() noreturn { |
| 28 | 28 | switch (builtin.arch) { |
| 29 | 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 | 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 | 35 | else => @compileError("unsupported arch"), |
| 36 | 36 | } |
| ... | ... | @@ -46,7 +46,7 @@ extern fn WinMainCRTStartup() noreturn { |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | fn posixCallMainAndExit() noreturn { |
| 49 | const argc = *argc_ptr; | |
| 49 | const argc = argc_ptr.*; | |
| 50 | 50 | const argv = @ptrCast(&&u8, &argc_ptr[1]); |
| 51 | 51 | const envp_nullable = @ptrCast(&?&u8, &argv[argc + 1]); |
| 52 | 52 | var envp_count: usize = 0; |
| ... | ... | @@ -56,7 +56,7 @@ fn posixCallMainAndExit() noreturn { |
| 56 | 56 | const auxv = &@ptrCast(&usize, envp.ptr)[envp_count + 1]; |
| 57 | 57 | var i: usize = 0; |
| 58 | 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 | 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 | 36 | const significand: rep_t = (aAbs & significandMask) | implicitBit; |
| 37 | 37 | |
| 38 | 38 | // If either the value or the exponent is negative, the result is zero. |
| 39 | if (sign == -1 or exponent < 0) | |
| 40 | return 0; | |
| 39 | if (sign == -1 or exponent < 0) return 0; | |
| 41 | 40 | |
| 42 | 41 | // If the value is too large for the integer type, saturate. |
| 43 | if (c_uint(exponent) >= fixuint_t.bit_count) | |
| 44 | return ~fixuint_t(0); | |
| 42 | if (c_uint(exponent) >= fixuint_t.bit_count) return ~fixuint_t(0); | |
| 45 | 43 | |
| 46 | 44 | // If 0 <= exponent < significandBits, right shift to get the result. |
| 47 | 45 | // Otherwise, shift left. |
std/special/compiler_rt/fixunsdfdi.zig-1| ... | ... | @@ -9,4 +9,3 @@ pub extern fn __fixunsdfdi(a: f64) u64 { |
| 9 | 9 | test "import fixunsdfdi" { |
| 10 | 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 | 9 | test "import fixunsdfsi" { |
| 10 | 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 | 9 | test "import fixunssfti" { |
| 10 | 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 | 9 | test "import fixunstfti" { |
| 10 | 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 | 91 | const aligned_value: T align(16) = value; |
| 92 | 92 | asm volatile ( |
| 93 | 93 | \\movaps (%[ptr]), %%xmm0 |
| 94 | : | |
| 95 | : [ptr] "r" (&aligned_value) | |
| 96 | : "xmm0"); | |
| 94 | ||
| 95 | : | |
| 96 | : [ptr] "r" (&aligned_value) | |
| 97 | : "xmm0"); | |
| 97 | 98 | } |
| 98 | 99 | |
| 99 | 100 | extern fn __udivdi3(a: u64, b: u64) u64 { |
| ... | ... | @@ -282,26 +283,27 @@ extern fn __udivmodsi4(a: u32, b: u32, rem: &u32) u32 { |
| 282 | 283 | @setRuntimeSafety(is_test); |
| 283 | 284 | |
| 284 | 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 | 287 | return d; |
| 287 | 288 | } |
| 288 | 289 | |
| 289 | ||
| 290 | 290 | extern fn __udivsi3(n: u32, d: u32) u32 { |
| 291 | 291 | @setRuntimeSafety(is_test); |
| 292 | 292 | |
| 293 | 293 | const n_uword_bits: c_uint = u32.bit_count; |
| 294 | 294 | // special cases |
| 295 | if (d == 0) | |
| 296 | return 0; // ?! | |
| 297 | if (n == 0) | |
| 298 | return 0; | |
| 295 | if (d == 0) return 0; // ?! | |
| 296 | if (n == 0) return 0; | |
| 299 | 297 | var sr = @bitCast(c_uint, c_int(@clz(d)) - c_int(@clz(n))); |
| 300 | 298 | // 0 <= sr <= n_uword_bits - 1 or sr large |
| 301 | if (sr > n_uword_bits - 1) // d > r | |
| 299 | if (sr > n_uword_bits - 1) { | |
| 300 | // d > r | |
| 302 | 301 | return 0; |
| 303 | if (sr == n_uword_bits - 1) // d == 1 | |
| 302 | } | |
| 303 | if (sr == n_uword_bits - 1) { | |
| 304 | // d == 1 | |
| 304 | 305 | return n; |
| 306 | } | |
| 305 | 307 | sr += 1; |
| 306 | 308 | // 1 <= sr <= n_uword_bits - 1 |
| 307 | 309 | // Not a special case |
| ... | ... | @@ -340,139 +342,667 @@ fn test_one_umoddi3(a: u64, b: u64, expected_r: u64) void { |
| 340 | 342 | } |
| 341 | 343 | |
| 342 | 344 | test "test_udivsi3" { |
| 343 | const cases = [][3]u32 { | |
| 344 | []u32{0x00000000, 0x00000001, 0x00000000}, | |
| 345 | []u32{0x00000000, 0x00000002, 0x00000000}, | |
| 346 | []u32{0x00000000, 0x00000003, 0x00000000}, | |
| 347 | []u32{0x00000000, 0x00000010, 0x00000000}, | |
| 348 | []u32{0x00000000, 0x078644FA, 0x00000000}, | |
| 349 | []u32{0x00000000, 0x0747AE14, 0x00000000}, | |
| 350 | []u32{0x00000000, 0x7FFFFFFF, 0x00000000}, | |
| 351 | []u32{0x00000000, 0x80000000, 0x00000000}, | |
| 352 | []u32{0x00000000, 0xFFFFFFFD, 0x00000000}, | |
| 353 | []u32{0x00000000, 0xFFFFFFFE, 0x00000000}, | |
| 354 | []u32{0x00000000, 0xFFFFFFFF, 0x00000000}, | |
| 355 | []u32{0x00000001, 0x00000001, 0x00000001}, | |
| 356 | []u32{0x00000001, 0x00000002, 0x00000000}, | |
| 357 | []u32{0x00000001, 0x00000003, 0x00000000}, | |
| 358 | []u32{0x00000001, 0x00000010, 0x00000000}, | |
| 359 | []u32{0x00000001, 0x078644FA, 0x00000000}, | |
| 360 | []u32{0x00000001, 0x0747AE14, 0x00000000}, | |
| 361 | []u32{0x00000001, 0x7FFFFFFF, 0x00000000}, | |
| 362 | []u32{0x00000001, 0x80000000, 0x00000000}, | |
| 363 | []u32{0x00000001, 0xFFFFFFFD, 0x00000000}, | |
| 364 | []u32{0x00000001, 0xFFFFFFFE, 0x00000000}, | |
| 365 | []u32{0x00000001, 0xFFFFFFFF, 0x00000000}, | |
| 366 | []u32{0x00000002, 0x00000001, 0x00000002}, | |
| 367 | []u32{0x00000002, 0x00000002, 0x00000001}, | |
| 368 | []u32{0x00000002, 0x00000003, 0x00000000}, | |
| 369 | []u32{0x00000002, 0x00000010, 0x00000000}, | |
| 370 | []u32{0x00000002, 0x078644FA, 0x00000000}, | |
| 371 | []u32{0x00000002, 0x0747AE14, 0x00000000}, | |
| 372 | []u32{0x00000002, 0x7FFFFFFF, 0x00000000}, | |
| 373 | []u32{0x00000002, 0x80000000, 0x00000000}, | |
| 374 | []u32{0x00000002, 0xFFFFFFFD, 0x00000000}, | |
| 375 | []u32{0x00000002, 0xFFFFFFFE, 0x00000000}, | |
| 376 | []u32{0x00000002, 0xFFFFFFFF, 0x00000000}, | |
| 377 | []u32{0x00000003, 0x00000001, 0x00000003}, | |
| 378 | []u32{0x00000003, 0x00000002, 0x00000001}, | |
| 379 | []u32{0x00000003, 0x00000003, 0x00000001}, | |
| 380 | []u32{0x00000003, 0x00000010, 0x00000000}, | |
| 381 | []u32{0x00000003, 0x078644FA, 0x00000000}, | |
| 382 | []u32{0x00000003, 0x0747AE14, 0x00000000}, | |
| 383 | []u32{0x00000003, 0x7FFFFFFF, 0x00000000}, | |
| 384 | []u32{0x00000003, 0x80000000, 0x00000000}, | |
| 385 | []u32{0x00000003, 0xFFFFFFFD, 0x00000000}, | |
| 386 | []u32{0x00000003, 0xFFFFFFFE, 0x00000000}, | |
| 387 | []u32{0x00000003, 0xFFFFFFFF, 0x00000000}, | |
| 388 | []u32{0x00000010, 0x00000001, 0x00000010}, | |
| 389 | []u32{0x00000010, 0x00000002, 0x00000008}, | |
| 390 | []u32{0x00000010, 0x00000003, 0x00000005}, | |
| 391 | []u32{0x00000010, 0x00000010, 0x00000001}, | |
| 392 | []u32{0x00000010, 0x078644FA, 0x00000000}, | |
| 393 | []u32{0x00000010, 0x0747AE14, 0x00000000}, | |
| 394 | []u32{0x00000010, 0x7FFFFFFF, 0x00000000}, | |
| 395 | []u32{0x00000010, 0x80000000, 0x00000000}, | |
| 396 | []u32{0x00000010, 0xFFFFFFFD, 0x00000000}, | |
| 397 | []u32{0x00000010, 0xFFFFFFFE, 0x00000000}, | |
| 398 | []u32{0x00000010, 0xFFFFFFFF, 0x00000000}, | |
| 399 | []u32{0x078644FA, 0x00000001, 0x078644FA}, | |
| 400 | []u32{0x078644FA, 0x00000002, 0x03C3227D}, | |
| 401 | []u32{0x078644FA, 0x00000003, 0x028216FE}, | |
| 402 | []u32{0x078644FA, 0x00000010, 0x0078644F}, | |
| 403 | []u32{0x078644FA, 0x078644FA, 0x00000001}, | |
| 404 | []u32{0x078644FA, 0x0747AE14, 0x00000001}, | |
| 405 | []u32{0x078644FA, 0x7FFFFFFF, 0x00000000}, | |
| 406 | []u32{0x078644FA, 0x80000000, 0x00000000}, | |
| 407 | []u32{0x078644FA, 0xFFFFFFFD, 0x00000000}, | |
| 408 | []u32{0x078644FA, 0xFFFFFFFE, 0x00000000}, | |
| 409 | []u32{0x078644FA, 0xFFFFFFFF, 0x00000000}, | |
| 410 | []u32{0x0747AE14, 0x00000001, 0x0747AE14}, | |
| 411 | []u32{0x0747AE14, 0x00000002, 0x03A3D70A}, | |
| 412 | []u32{0x0747AE14, 0x00000003, 0x026D3A06}, | |
| 413 | []u32{0x0747AE14, 0x00000010, 0x00747AE1}, | |
| 414 | []u32{0x0747AE14, 0x078644FA, 0x00000000}, | |
| 415 | []u32{0x0747AE14, 0x0747AE14, 0x00000001}, | |
| 416 | []u32{0x0747AE14, 0x7FFFFFFF, 0x00000000}, | |
| 417 | []u32{0x0747AE14, 0x80000000, 0x00000000}, | |
| 418 | []u32{0x0747AE14, 0xFFFFFFFD, 0x00000000}, | |
| 419 | []u32{0x0747AE14, 0xFFFFFFFE, 0x00000000}, | |
| 420 | []u32{0x0747AE14, 0xFFFFFFFF, 0x00000000}, | |
| 421 | []u32{0x7FFFFFFF, 0x00000001, 0x7FFFFFFF}, | |
| 422 | []u32{0x7FFFFFFF, 0x00000002, 0x3FFFFFFF}, | |
| 423 | []u32{0x7FFFFFFF, 0x00000003, 0x2AAAAAAA}, | |
| 424 | []u32{0x7FFFFFFF, 0x00000010, 0x07FFFFFF}, | |
| 425 | []u32{0x7FFFFFFF, 0x078644FA, 0x00000011}, | |
| 426 | []u32{0x7FFFFFFF, 0x0747AE14, 0x00000011}, | |
| 427 | []u32{0x7FFFFFFF, 0x7FFFFFFF, 0x00000001}, | |
| 428 | []u32{0x7FFFFFFF, 0x80000000, 0x00000000}, | |
| 429 | []u32{0x7FFFFFFF, 0xFFFFFFFD, 0x00000000}, | |
| 430 | []u32{0x7FFFFFFF, 0xFFFFFFFE, 0x00000000}, | |
| 431 | []u32{0x7FFFFFFF, 0xFFFFFFFF, 0x00000000}, | |
| 432 | []u32{0x80000000, 0x00000001, 0x80000000}, | |
| 433 | []u32{0x80000000, 0x00000002, 0x40000000}, | |
| 434 | []u32{0x80000000, 0x00000003, 0x2AAAAAAA}, | |
| 435 | []u32{0x80000000, 0x00000010, 0x08000000}, | |
| 436 | []u32{0x80000000, 0x078644FA, 0x00000011}, | |
| 437 | []u32{0x80000000, 0x0747AE14, 0x00000011}, | |
| 438 | []u32{0x80000000, 0x7FFFFFFF, 0x00000001}, | |
| 439 | []u32{0x80000000, 0x80000000, 0x00000001}, | |
| 440 | []u32{0x80000000, 0xFFFFFFFD, 0x00000000}, | |
| 441 | []u32{0x80000000, 0xFFFFFFFE, 0x00000000}, | |
| 442 | []u32{0x80000000, 0xFFFFFFFF, 0x00000000}, | |
| 443 | []u32{0xFFFFFFFD, 0x00000001, 0xFFFFFFFD}, | |
| 444 | []u32{0xFFFFFFFD, 0x00000002, 0x7FFFFFFE}, | |
| 445 | []u32{0xFFFFFFFD, 0x00000003, 0x55555554}, | |
| 446 | []u32{0xFFFFFFFD, 0x00000010, 0x0FFFFFFF}, | |
| 447 | []u32{0xFFFFFFFD, 0x078644FA, 0x00000022}, | |
| 448 | []u32{0xFFFFFFFD, 0x0747AE14, 0x00000023}, | |
| 449 | []u32{0xFFFFFFFD, 0x7FFFFFFF, 0x00000001}, | |
| 450 | []u32{0xFFFFFFFD, 0x80000000, 0x00000001}, | |
| 451 | []u32{0xFFFFFFFD, 0xFFFFFFFD, 0x00000001}, | |
| 452 | []u32{0xFFFFFFFD, 0xFFFFFFFE, 0x00000000}, | |
| 453 | []u32{0xFFFFFFFD, 0xFFFFFFFF, 0x00000000}, | |
| 454 | []u32{0xFFFFFFFE, 0x00000001, 0xFFFFFFFE}, | |
| 455 | []u32{0xFFFFFFFE, 0x00000002, 0x7FFFFFFF}, | |
| 456 | []u32{0xFFFFFFFE, 0x00000003, 0x55555554}, | |
| 457 | []u32{0xFFFFFFFE, 0x00000010, 0x0FFFFFFF}, | |
| 458 | []u32{0xFFFFFFFE, 0x078644FA, 0x00000022}, | |
| 459 | []u32{0xFFFFFFFE, 0x0747AE14, 0x00000023}, | |
| 460 | []u32{0xFFFFFFFE, 0x7FFFFFFF, 0x00000002}, | |
| 461 | []u32{0xFFFFFFFE, 0x80000000, 0x00000001}, | |
| 462 | []u32{0xFFFFFFFE, 0xFFFFFFFD, 0x00000001}, | |
| 463 | []u32{0xFFFFFFFE, 0xFFFFFFFE, 0x00000001}, | |
| 464 | []u32{0xFFFFFFFE, 0xFFFFFFFF, 0x00000000}, | |
| 465 | []u32{0xFFFFFFFF, 0x00000001, 0xFFFFFFFF}, | |
| 466 | []u32{0xFFFFFFFF, 0x00000002, 0x7FFFFFFF}, | |
| 467 | []u32{0xFFFFFFFF, 0x00000003, 0x55555555}, | |
| 468 | []u32{0xFFFFFFFF, 0x00000010, 0x0FFFFFFF}, | |
| 469 | []u32{0xFFFFFFFF, 0x078644FA, 0x00000022}, | |
| 470 | []u32{0xFFFFFFFF, 0x0747AE14, 0x00000023}, | |
| 471 | []u32{0xFFFFFFFF, 0x7FFFFFFF, 0x00000002}, | |
| 472 | []u32{0xFFFFFFFF, 0x80000000, 0x00000001}, | |
| 473 | []u32{0xFFFFFFFF, 0xFFFFFFFD, 0x00000001}, | |
| 474 | []u32{0xFFFFFFFF, 0xFFFFFFFE, 0x00000001}, | |
| 475 | []u32{0xFFFFFFFF, 0xFFFFFFFF, 0x00000001}, | |
| 345 | const cases = [][3]u32{ | |
| 346 | []u32{ | |
| 347 | 0x00000000, | |
| 348 | 0x00000001, | |
| 349 | 0x00000000, | |
| 350 | }, | |
| 351 | []u32{ | |
| 352 | 0x00000000, | |
| 353 | 0x00000002, | |
| 354 | 0x00000000, | |
| 355 | }, | |
| 356 | []u32{ | |
| 357 | 0x00000000, | |
| 358 | 0x00000003, | |
| 359 | 0x00000000, | |
| 360 | }, | |
| 361 | []u32{ | |
| 362 | 0x00000000, | |
| 363 | 0x00000010, | |
| 364 | 0x00000000, | |
| 365 | }, | |
| 366 | []u32{ | |
| 367 | 0x00000000, | |
| 368 | 0x078644FA, | |
| 369 | 0x00000000, | |
| 370 | }, | |
| 371 | []u32{ | |
| 372 | 0x00000000, | |
| 373 | 0x0747AE14, | |
| 374 | 0x00000000, | |
| 375 | }, | |
| 376 | []u32{ | |
| 377 | 0x00000000, | |
| 378 | 0x7FFFFFFF, | |
| 379 | 0x00000000, | |
| 380 | }, | |
| 381 | []u32{ | |
| 382 | 0x00000000, | |
| 383 | 0x80000000, | |
| 384 | 0x00000000, | |
| 385 | }, | |
| 386 | []u32{ | |
| 387 | 0x00000000, | |
| 388 | 0xFFFFFFFD, | |
| 389 | 0x00000000, | |
| 390 | }, | |
| 391 | []u32{ | |
| 392 | 0x00000000, | |
| 393 | 0xFFFFFFFE, | |
| 394 | 0x00000000, | |
| 395 | }, | |
| 396 | []u32{ | |
| 397 | 0x00000000, | |
| 398 | 0xFFFFFFFF, | |
| 399 | 0x00000000, | |
| 400 | }, | |
| 401 | []u32{ | |
| 402 | 0x00000001, | |
| 403 | 0x00000001, | |
| 404 | 0x00000001, | |
| 405 | }, | |
| 406 | []u32{ | |
| 407 | 0x00000001, | |
| 408 | 0x00000002, | |
| 409 | 0x00000000, | |
| 410 | }, | |
| 411 | []u32{ | |
| 412 | 0x00000001, | |
| 413 | 0x00000003, | |
| 414 | 0x00000000, | |
| 415 | }, | |
| 416 | []u32{ | |
| 417 | 0x00000001, | |
| 418 | 0x00000010, | |
| 419 | 0x00000000, | |
| 420 | }, | |
| 421 | []u32{ | |
| 422 | 0x00000001, | |
| 423 | 0x078644FA, | |
| 424 | 0x00000000, | |
| 425 | }, | |
| 426 | []u32{ | |
| 427 | 0x00000001, | |
| 428 | 0x0747AE14, | |
| 429 | 0x00000000, | |
| 430 | }, | |
| 431 | []u32{ | |
| 432 | 0x00000001, | |
| 433 | 0x7FFFFFFF, | |
| 434 | 0x00000000, | |
| 435 | }, | |
| 436 | []u32{ | |
| 437 | 0x00000001, | |
| 438 | 0x80000000, | |
| 439 | 0x00000000, | |
| 440 | }, | |
| 441 | []u32{ | |
| 442 | 0x00000001, | |
| 443 | 0xFFFFFFFD, | |
| 444 | 0x00000000, | |
| 445 | }, | |
| 446 | []u32{ | |
| 447 | 0x00000001, | |
| 448 | 0xFFFFFFFE, | |
| 449 | 0x00000000, | |
| 450 | }, | |
| 451 | []u32{ | |
| 452 | 0x00000001, | |
| 453 | 0xFFFFFFFF, | |
| 454 | 0x00000000, | |
| 455 | }, | |
| 456 | []u32{ | |
| 457 | 0x00000002, | |
| 458 | 0x00000001, | |
| 459 | 0x00000002, | |
| 460 | }, | |
| 461 | []u32{ | |
| 462 | 0x00000002, | |
| 463 | 0x00000002, | |
| 464 | 0x00000001, | |
| 465 | }, | |
| 466 | []u32{ | |
| 467 | 0x00000002, | |
| 468 | 0x00000003, | |
| 469 | 0x00000000, | |
| 470 | }, | |
| 471 | []u32{ | |
| 472 | 0x00000002, | |
| 473 | 0x00000010, | |
| 474 | 0x00000000, | |
| 475 | }, | |
| 476 | []u32{ | |
| 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 | }; |
| 477 | 1007 | |
| 478 | 1008 | for (cases) |case| { |
std/special/compiler_rt/udivmod.zig+23-20| ... | ... | @@ -1,7 +1,10 @@ |
| 1 | 1 | const builtin = @import("builtin"); |
| 2 | 2 | const is_test = builtin.is_test; |
| 3 | 3 | |
| 4 | const low = switch (builtin.endian) { builtin.Endian.Big => 1, builtin.Endian.Little => 0 }; | |
| 4 | const low = switch (builtin.endian) { | |
| 5 | builtin.Endian.Big => 1, | |
| 6 | builtin.Endian.Little => 0, | |
| 7 | }; | |
| 5 | 8 | const high = 1 - low; |
| 6 | 9 | |
| 7 | 10 | pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: ?&DoubleInt) DoubleInt { |
| ... | ... | @@ -11,8 +14,8 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: |
| 11 | 14 | const SignedDoubleInt = @IntType(true, DoubleInt.bit_count); |
| 12 | 15 | const Log2SingleInt = @import("../../math/index.zig").Log2Int(SingleInt); |
| 13 | 16 | |
| 14 | const n = *@ptrCast(&const [2]SingleInt, &a); // TODO issue #421 | |
| 15 | const d = *@ptrCast(&const [2]SingleInt, &b); // TODO issue #421 | |
| 17 | const n = @ptrCast(&const [2]SingleInt, &a).*; // TODO issue #421 | |
| 18 | const d = @ptrCast(&const [2]SingleInt, &b).*; // TODO issue #421 | |
| 16 | 19 | var q: [2]SingleInt = undefined; |
| 17 | 20 | var r: [2]SingleInt = undefined; |
| 18 | 21 | var sr: c_uint = undefined; |
| ... | ... | @@ -23,7 +26,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: |
| 23 | 26 | // --- |
| 24 | 27 | // 0 X |
| 25 | 28 | if (maybe_rem) |rem| { |
| 26 | *rem = n[low] % d[low]; | |
| 29 | rem.* = n[low] % d[low]; | |
| 27 | 30 | } |
| 28 | 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 | 34 | // --- |
| 32 | 35 | // K X |
| 33 | 36 | if (maybe_rem) |rem| { |
| 34 | *rem = n[low]; | |
| 37 | rem.* = n[low]; | |
| 35 | 38 | } |
| 36 | 39 | return 0; |
| 37 | 40 | } |
| ... | ... | @@ -42,7 +45,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: |
| 42 | 45 | // --- |
| 43 | 46 | // 0 0 |
| 44 | 47 | if (maybe_rem) |rem| { |
| 45 | *rem = n[high] % d[low]; | |
| 48 | rem.* = n[high] % d[low]; | |
| 46 | 49 | } |
| 47 | 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 | 57 | if (maybe_rem) |rem| { |
| 55 | 58 | r[high] = n[high] % d[high]; |
| 56 | 59 | r[low] = 0; |
| 57 | *rem = *@ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &r[0]); // TODO issue #421 | |
| 60 | rem.* = @ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &r[0]).*; // TODO issue #421 | |
| 58 | 61 | } |
| 59 | 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 | 69 | if (maybe_rem) |rem| { |
| 67 | 70 | r[low] = n[low]; |
| 68 | 71 | r[high] = n[high] & (d[high] - 1); |
| 69 | *rem = *@ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &r[0]); // TODO issue #421 | |
| 72 | rem.* = @ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &r[0]).*; // TODO issue #421 | |
| 70 | 73 | } |
| 71 | 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 | 80 | // 0 <= sr <= SingleInt.bit_count - 2 or sr large |
| 78 | 81 | if (sr > SingleInt.bit_count - 2) { |
| 79 | 82 | if (maybe_rem) |rem| { |
| 80 | *rem = a; | |
| 83 | rem.* = a; | |
| 81 | 84 | } |
| 82 | 85 | return 0; |
| 83 | 86 | } |
| ... | ... | @@ -98,7 +101,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: |
| 98 | 101 | if ((d[low] & (d[low] - 1)) == 0) { |
| 99 | 102 | // d is a power of 2 |
| 100 | 103 | if (maybe_rem) |rem| { |
| 101 | *rem = n[low] & (d[low] - 1); | |
| 104 | rem.* = n[low] & (d[low] - 1); | |
| 102 | 105 | } |
| 103 | 106 | if (d[low] == 1) { |
| 104 | 107 | return a; |
| ... | ... | @@ -106,7 +109,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: |
| 106 | 109 | sr = @ctz(d[low]); |
| 107 | 110 | q[high] = n[high] >> Log2SingleInt(sr); |
| 108 | 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 #421 | |
| 112 | return @ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &q[0]).*; // TODO issue #421 | |
| 110 | 113 | } |
| 111 | 114 | // K X |
| 112 | 115 | // --- |
| ... | ... | @@ -141,7 +144,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: |
| 141 | 144 | // 0 <= sr <= SingleInt.bit_count - 1 or sr large |
| 142 | 145 | if (sr > SingleInt.bit_count - 1) { |
| 143 | 146 | if (maybe_rem) |rem| { |
| 144 | *rem = a; | |
| 147 | rem.* = a; | |
| 145 | 148 | } |
| 146 | 149 | return 0; |
| 147 | 150 | } |
| ... | ... | @@ -170,25 +173,25 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: |
| 170 | 173 | var r_all: DoubleInt = undefined; |
| 171 | 174 | while (sr > 0) : (sr -= 1) { |
| 172 | 175 | // r:q = ((r:q) << 1) | carry |
| 173 | r[high] = (r[high] << 1) | (r[low] >> (SingleInt.bit_count - 1)); | |
| 174 | r[low] = (r[low] << 1) | (q[high] >> (SingleInt.bit_count - 1)); | |
| 175 | q[high] = (q[high] << 1) | (q[low] >> (SingleInt.bit_count - 1)); | |
| 176 | q[low] = (q[low] << 1) | carry; | |
| 176 | r[high] = (r[high] << 1) | (r[low] >> (SingleInt.bit_count - 1)); | |
| 177 | r[low] = (r[low] << 1) | (q[high] >> (SingleInt.bit_count - 1)); | |
| 178 | q[high] = (q[high] << 1) | (q[low] >> (SingleInt.bit_count - 1)); | |
| 179 | q[low] = (q[low] << 1) | carry; | |
| 177 | 180 | // carry = 0; |
| 178 | 181 | // if (r.all >= b) |
| 179 | 182 | // { |
| 180 | 183 | // r.all -= b; |
| 181 | 184 | // carry = 1; |
| 182 | 185 | // } |
| 183 | r_all = *@ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &r[0]); // TODO issue #421 | |
| 186 | r_all = @ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &r[0]).*; // TODO issue #421 | |
| 184 | 187 | const s: SignedDoubleInt = SignedDoubleInt(b -% r_all -% 1) >> (DoubleInt.bit_count - 1); |
| 185 | 188 | carry = u32(s & 1); |
| 186 | 189 | r_all -= b & @bitCast(DoubleInt, s); |
| 187 | r = *@ptrCast(&[2]SingleInt, &r_all); // TODO issue #421 | |
| 190 | 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 #421 | |
| 192 | const q_all = ((@ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &q[0]).*) << 1) | carry; // TODO issue #421 | |
| 190 | 193 | if (maybe_rem) |rem| { |
| 191 | *rem = r_all; | |
| 194 | rem.* = r_all; | |
| 192 | 195 | } |
| 193 | 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 | 9 | |
| 10 | 10 | pub extern fn __udivmodti4_windows_x86_64(a: &const u128, b: &const u128, maybe_rem: ?&u128) void { |
| 11 | 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 | } |
| 14 | 14 | |
| 15 | 15 | test "import udivmodti4" { |
std/special/compiler_rt/umodti3.zig+1-1| ... | ... | @@ -11,5 +11,5 @@ pub extern fn __umodti3(a: u128, b: u128) u128 { |
| 11 | 11 | |
| 12 | 12 | pub extern fn __umodti3_windows_x86_64(a: &const u128, b: &const u128) void { |
| 13 | 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 | 14 | } |
| 15 | 15 | |
| 16 | 16 | test "pointer reinterpret const float to int" { |
| 17 | const float: f64 = 5.99999999999994648725e - 01; | |
| 17 | const float: f64 = 5.99999999999994648725e-01; | |
| 18 | 18 | const float_ptr = &float; |
| 19 | 19 | const int_ptr = @ptrCast(&const i32, float_ptr); |
| 20 | 20 | const int_val = int_ptr.*; |
| ... | ... | @@ -121,13 +121,13 @@ test "implicitly cast indirect pointer to maybe-indirect pointer" { |
| 121 | 121 | return (p.*).x; |
| 122 | 122 | } |
| 123 | 123 | fn maybeConstConst(p: ?&const &const Self) u8 { |
| 124 | return (??p.*).x; | |
| 124 | return ((??p).*).x; | |
| 125 | 125 | } |
| 126 | 126 | fn constConstConst(p: &const &const &const Self) u8 { |
| 127 | 127 | return (p.*.*).x; |
| 128 | 128 | } |
| 129 | 129 | fn maybeConstConstConst(p: ?&const &const &const Self) u8 { |
| 130 | return (??p.*.*).x; | |
| 130 | return ((??p).*.*).x; | |
| 131 | 131 | } |
| 132 | 132 | }; |
| 133 | 133 | const s = S { |
test/cases/generics.zig+1-1| ... | ... | @@ -127,7 +127,7 @@ test "generic fn with implicit cast" { |
| 127 | 127 | }) == 0); |
| 128 | 128 | } |
| 129 | 129 | fn getByte(ptr: ?&const u8) u8 { |
| 130 | return ??ptr.*; | |
| 130 | return (??ptr).*; | |
| 131 | 131 | } |
| 132 | 132 | fn getFirstByte(comptime T: type, mem: []const T) u8 { |
| 133 | 133 | return getByte(@ptrCast(&const u8, &mem[0])); |