@zigc/lib 0.15.1 → 0.15.2-test.99
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +19 -0
- package/build-web/fuzz.zig +6 -6
- package/build-web/time_report.zig +14 -13
- package/compiler/reduce/Walk.zig +10 -9
- package/compiler/reduce.zig +19 -20
- package/compiler/resinator/compile.zig +1 -1
- package/compiler_rt/arm.zig +1 -1
- package/init/build.zig +1 -1
- package/libc/include/generic-glibc/arpa/inet.h +3 -0
- package/libc/musl/src/fenv/loongarch64/fenv-sf.c +3 -0
- package/package.json +1 -1
- package/std/Build/Step/Compile.zig +20 -1
- package/std/Build/Step/TranslateC.zig +6 -0
- package/std/Build/WebServer.zig +1 -1
- package/std/Build.zig +4 -1
- package/std/Io/Reader/Limited.zig +44 -0
- package/std/Io/Reader.zig +128 -28
- package/std/Io/Writer.zig +31 -6
- package/std/Target.zig +8 -0
- package/std/Thread.zig +3 -4
- package/std/c.zig +87 -26
- package/std/crypto/aes_ocb.zig +32 -3
- package/std/crypto/tls/Client.zig +19 -8
- package/std/debug.zig +1 -1
- package/std/fs/Dir.zig +2 -1
- package/std/fs/File.zig +105 -104
- package/std/http/Client.zig +3 -2
- package/std/json/static.zig +3 -3
- package/std/math/big/int.zig +3 -4
- package/std/math/powi.zig +1 -0
- package/std/mem/Allocator.zig +3 -1
- package/std/mem.zig +3 -1
- package/std/net.zig +3 -2
- package/std/os/linux/bpf.zig +2 -2
- package/std/os/linux/powerpc.zig +74 -12
- package/std/os/linux/powerpc64.zig +74 -12
- package/std/os/linux.zig +7 -2
- package/std/os/uefi/protocol/service_binding.zig +1 -1
- package/std/os/uefi/tables.zig +1 -1
- package/std/pie.zig +1 -1
- package/std/posix.zig +6 -4
- package/std/process/Child.zig +5 -1
- package/std/process.zig +16 -2
- package/std/sort/pdq.zig +48 -1
- package/std/testing.zig +60 -0
- package/std/zig/llvm/BitcodeReader.zig +5 -1
- package/std/zig/system/linux.zig +1 -4
- package/std/zig/system.zig +3 -2
- package/std/zon/parse.zig +1 -0
- package/ubsan_rt.zig +3 -3
package/std/Io/Reader.zig
CHANGED
|
@@ -400,10 +400,11 @@ pub fn defaultReadVec(r: *Reader, data: [][]u8) Error!usize {
|
|
|
400
400
|
.vtable = &.{ .drain = Writer.fixedDrain },
|
|
401
401
|
};
|
|
402
402
|
const limit: Limit = .limited(writer.buffer.len - writer.end);
|
|
403
|
-
|
|
403
|
+
const n = r.vtable.stream(r, &writer, limit) catch |err| switch (err) {
|
|
404
404
|
error.WriteFailed => unreachable,
|
|
405
405
|
else => |e| return e,
|
|
406
406
|
};
|
|
407
|
+
r.end += n;
|
|
407
408
|
return 0;
|
|
408
409
|
}
|
|
409
410
|
|
|
@@ -448,7 +449,6 @@ pub fn readVecAll(r: *Reader, data: [][]u8) Error!void {
|
|
|
448
449
|
/// is returned instead.
|
|
449
450
|
///
|
|
450
451
|
/// See also:
|
|
451
|
-
/// * `peek`
|
|
452
452
|
/// * `toss`
|
|
453
453
|
pub fn peek(r: *Reader, n: usize) Error![]u8 {
|
|
454
454
|
try r.fill(n);
|
|
@@ -699,7 +699,7 @@ pub const DelimiterError = error{
|
|
|
699
699
|
};
|
|
700
700
|
|
|
701
701
|
/// Returns a slice of the next bytes of buffered data from the stream until
|
|
702
|
-
/// `sentinel` is found, advancing the seek position.
|
|
702
|
+
/// `sentinel` is found, advancing the seek position past the sentinel.
|
|
703
703
|
///
|
|
704
704
|
/// Returned slice has a sentinel.
|
|
705
705
|
///
|
|
@@ -732,7 +732,7 @@ pub fn peekSentinel(r: *Reader, comptime sentinel: u8) DelimiterError![:sentinel
|
|
|
732
732
|
}
|
|
733
733
|
|
|
734
734
|
/// Returns a slice of the next bytes of buffered data from the stream until
|
|
735
|
-
/// `delimiter` is found, advancing the seek position.
|
|
735
|
+
/// `delimiter` is found, advancing the seek position past the delimiter.
|
|
736
736
|
///
|
|
737
737
|
/// Returned slice includes the delimiter as the last byte.
|
|
738
738
|
///
|
|
@@ -760,31 +760,42 @@ pub fn takeDelimiterInclusive(r: *Reader, delimiter: u8) DelimiterError![]u8 {
|
|
|
760
760
|
/// * `peekDelimiterExclusive`
|
|
761
761
|
/// * `takeDelimiterInclusive`
|
|
762
762
|
pub fn peekDelimiterInclusive(r: *Reader, delimiter: u8) DelimiterError![]u8 {
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
763
|
+
{
|
|
764
|
+
const contents = r.buffer[0..r.end];
|
|
765
|
+
const seek = r.seek;
|
|
766
|
+
if (std.mem.indexOfScalarPos(u8, contents, seek, delimiter)) |end| {
|
|
767
|
+
@branchHint(.likely);
|
|
768
|
+
return contents[seek .. end + 1];
|
|
769
|
+
}
|
|
768
770
|
}
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
const
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
};
|
|
778
|
-
r.end += n;
|
|
779
|
-
if (std.mem.indexOfScalarPos(u8, end_cap[0..n], 0, delimiter)) |end| {
|
|
780
|
-
return r.buffer[0 .. r.end - n + end + 1];
|
|
771
|
+
while (true) {
|
|
772
|
+
const content_len = r.end - r.seek;
|
|
773
|
+
if (r.buffer.len - content_len == 0) break;
|
|
774
|
+
try fillMore(r);
|
|
775
|
+
const seek = r.seek;
|
|
776
|
+
const contents = r.buffer[0..r.end];
|
|
777
|
+
if (std.mem.indexOfScalarPos(u8, contents, seek + content_len, delimiter)) |end| {
|
|
778
|
+
return contents[seek .. end + 1];
|
|
781
779
|
}
|
|
782
780
|
}
|
|
783
|
-
|
|
781
|
+
// It might or might not be end of stream. There is no more buffer space
|
|
782
|
+
// left to disambiguate. If `StreamTooLong` was added to `RebaseError` then
|
|
783
|
+
// this logic could be replaced by removing the exit condition from the
|
|
784
|
+
// above while loop. That error code would represent when `buffer` capacity
|
|
785
|
+
// is too small for an operation, replacing the current use of asserts.
|
|
786
|
+
var failing_writer = Writer.failing;
|
|
787
|
+
while (r.vtable.stream(r, &failing_writer, .limited(1))) |n| {
|
|
788
|
+
assert(n == 0);
|
|
789
|
+
} else |err| switch (err) {
|
|
790
|
+
error.WriteFailed => return error.StreamTooLong,
|
|
791
|
+
error.ReadFailed => |e| return e,
|
|
792
|
+
error.EndOfStream => |e| return e,
|
|
793
|
+
}
|
|
784
794
|
}
|
|
785
795
|
|
|
786
796
|
/// Returns a slice of the next bytes of buffered data from the stream until
|
|
787
|
-
/// `delimiter` is found, advancing the seek position
|
|
797
|
+
/// `delimiter` is found, advancing the seek position up to (but not past)
|
|
798
|
+
/// the delimiter.
|
|
788
799
|
///
|
|
789
800
|
/// Returned slice excludes the delimiter. End-of-stream is treated equivalent
|
|
790
801
|
/// to a delimiter, unless it would result in a length 0 return value, in which
|
|
@@ -798,20 +809,44 @@ pub fn peekDelimiterInclusive(r: *Reader, delimiter: u8) DelimiterError![]u8 {
|
|
|
798
809
|
/// Invalidates previously returned values from `peek`.
|
|
799
810
|
///
|
|
800
811
|
/// See also:
|
|
812
|
+
/// * `takeDelimiter`
|
|
801
813
|
/// * `takeDelimiterInclusive`
|
|
802
814
|
/// * `peekDelimiterExclusive`
|
|
803
815
|
pub fn takeDelimiterExclusive(r: *Reader, delimiter: u8) DelimiterError![]u8 {
|
|
804
|
-
const result = r.
|
|
816
|
+
const result = try r.peekDelimiterExclusive(delimiter);
|
|
817
|
+
r.toss(result.len);
|
|
818
|
+
return result;
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
/// Returns a slice of the next bytes of buffered data from the stream until
|
|
822
|
+
/// `delimiter` is found, advancing the seek position past the delimiter.
|
|
823
|
+
///
|
|
824
|
+
/// Returned slice excludes the delimiter. End-of-stream is treated equivalent
|
|
825
|
+
/// to a delimiter, unless it would result in a length 0 return value, in which
|
|
826
|
+
/// case `null` is returned instead.
|
|
827
|
+
///
|
|
828
|
+
/// If the delimiter is not found within a number of bytes matching the
|
|
829
|
+
/// capacity of this `Reader`, `error.StreamTooLong` is returned. In
|
|
830
|
+
/// such case, the stream state is unmodified as if this function was never
|
|
831
|
+
/// called.
|
|
832
|
+
///
|
|
833
|
+
/// Invalidates previously returned values from `peek`.
|
|
834
|
+
///
|
|
835
|
+
/// See also:
|
|
836
|
+
/// * `takeDelimiterInclusive`
|
|
837
|
+
/// * `takeDelimiterExclusive`
|
|
838
|
+
pub fn takeDelimiter(r: *Reader, delimiter: u8) error{ ReadFailed, StreamTooLong }!?[]u8 {
|
|
839
|
+
const inclusive = r.peekDelimiterInclusive(delimiter) catch |err| switch (err) {
|
|
805
840
|
error.EndOfStream => {
|
|
806
841
|
const remaining = r.buffer[r.seek..r.end];
|
|
807
|
-
if (remaining.len == 0) return
|
|
842
|
+
if (remaining.len == 0) return null;
|
|
808
843
|
r.toss(remaining.len);
|
|
809
844
|
return remaining;
|
|
810
845
|
},
|
|
811
846
|
else => |e| return e,
|
|
812
847
|
};
|
|
813
|
-
r.toss(
|
|
814
|
-
return
|
|
848
|
+
r.toss(inclusive.len);
|
|
849
|
+
return inclusive[0 .. inclusive.len - 1];
|
|
815
850
|
}
|
|
816
851
|
|
|
817
852
|
/// Returns a slice of the next bytes of buffered data from the stream until
|
|
@@ -1334,6 +1369,9 @@ test peekSentinel {
|
|
|
1334
1369
|
var r: Reader = .fixed("ab\nc");
|
|
1335
1370
|
try testing.expectEqualStrings("ab", try r.peekSentinel('\n'));
|
|
1336
1371
|
try testing.expectEqualStrings("ab", try r.peekSentinel('\n'));
|
|
1372
|
+
r.toss(3);
|
|
1373
|
+
try testing.expectError(error.EndOfStream, r.peekSentinel('\n'));
|
|
1374
|
+
try testing.expectEqualStrings("c", try r.peek(1));
|
|
1337
1375
|
}
|
|
1338
1376
|
|
|
1339
1377
|
test takeDelimiterInclusive {
|
|
@@ -1348,22 +1386,52 @@ test peekDelimiterInclusive {
|
|
|
1348
1386
|
try testing.expectEqualStrings("ab\n", try r.peekDelimiterInclusive('\n'));
|
|
1349
1387
|
r.toss(3);
|
|
1350
1388
|
try testing.expectError(error.EndOfStream, r.peekDelimiterInclusive('\n'));
|
|
1389
|
+
try testing.expectEqualStrings("c", try r.peek(1));
|
|
1351
1390
|
}
|
|
1352
1391
|
|
|
1353
1392
|
test takeDelimiterExclusive {
|
|
1354
1393
|
var r: Reader = .fixed("ab\nc");
|
|
1394
|
+
|
|
1355
1395
|
try testing.expectEqualStrings("ab", try r.takeDelimiterExclusive('\n'));
|
|
1396
|
+
try testing.expectEqualStrings("", try r.takeDelimiterExclusive('\n'));
|
|
1397
|
+
try testing.expectEqualStrings("", try r.takeDelimiterExclusive('\n'));
|
|
1398
|
+
try testing.expectEqualStrings("\n", try r.take(1));
|
|
1399
|
+
|
|
1356
1400
|
try testing.expectEqualStrings("c", try r.takeDelimiterExclusive('\n'));
|
|
1357
1401
|
try testing.expectError(error.EndOfStream, r.takeDelimiterExclusive('\n'));
|
|
1358
1402
|
}
|
|
1359
1403
|
|
|
1360
1404
|
test peekDelimiterExclusive {
|
|
1361
1405
|
var r: Reader = .fixed("ab\nc");
|
|
1406
|
+
|
|
1362
1407
|
try testing.expectEqualStrings("ab", try r.peekDelimiterExclusive('\n'));
|
|
1363
1408
|
try testing.expectEqualStrings("ab", try r.peekDelimiterExclusive('\n'));
|
|
1364
|
-
r.toss(
|
|
1409
|
+
r.toss(2);
|
|
1410
|
+
try testing.expectEqualStrings("", try r.peekDelimiterExclusive('\n'));
|
|
1411
|
+
try testing.expectEqualStrings("\n", try r.take(1));
|
|
1412
|
+
|
|
1365
1413
|
try testing.expectEqualStrings("c", try r.peekDelimiterExclusive('\n'));
|
|
1366
1414
|
try testing.expectEqualStrings("c", try r.peekDelimiterExclusive('\n'));
|
|
1415
|
+
r.toss(1);
|
|
1416
|
+
try testing.expectError(error.EndOfStream, r.peekDelimiterExclusive('\n'));
|
|
1417
|
+
}
|
|
1418
|
+
|
|
1419
|
+
test takeDelimiter {
|
|
1420
|
+
var r: Reader = .fixed("ab\nc\n\nd");
|
|
1421
|
+
try testing.expectEqualStrings("ab", (try r.takeDelimiter('\n')).?);
|
|
1422
|
+
try testing.expectEqualStrings("c", (try r.takeDelimiter('\n')).?);
|
|
1423
|
+
try testing.expectEqualStrings("", (try r.takeDelimiter('\n')).?);
|
|
1424
|
+
try testing.expectEqualStrings("d", (try r.takeDelimiter('\n')).?);
|
|
1425
|
+
try testing.expectEqual(null, try r.takeDelimiter('\n'));
|
|
1426
|
+
try testing.expectEqual(null, try r.takeDelimiter('\n'));
|
|
1427
|
+
|
|
1428
|
+
r = .fixed("ab\nc\n\nd\n"); // one trailing newline does not affect behavior
|
|
1429
|
+
try testing.expectEqualStrings("ab", (try r.takeDelimiter('\n')).?);
|
|
1430
|
+
try testing.expectEqualStrings("c", (try r.takeDelimiter('\n')).?);
|
|
1431
|
+
try testing.expectEqualStrings("", (try r.takeDelimiter('\n')).?);
|
|
1432
|
+
try testing.expectEqualStrings("d", (try r.takeDelimiter('\n')).?);
|
|
1433
|
+
try testing.expectEqual(null, try r.takeDelimiter('\n'));
|
|
1434
|
+
try testing.expectEqual(null, try r.takeDelimiter('\n'));
|
|
1367
1435
|
}
|
|
1368
1436
|
|
|
1369
1437
|
test streamDelimiter {
|
|
@@ -1533,6 +1601,18 @@ test "readSliceShort with smaller buffer than Reader" {
|
|
|
1533
1601
|
try testing.expectEqualStrings(str, &buf);
|
|
1534
1602
|
}
|
|
1535
1603
|
|
|
1604
|
+
test "readSliceShort with indirect reader" {
|
|
1605
|
+
var r: Reader = .fixed("HelloFren");
|
|
1606
|
+
var ri_buf: [3]u8 = undefined;
|
|
1607
|
+
var ri: std.testing.ReaderIndirect = .init(&r, &ri_buf);
|
|
1608
|
+
var buf: [5]u8 = undefined;
|
|
1609
|
+
try testing.expectEqual(5, try ri.interface.readSliceShort(&buf));
|
|
1610
|
+
try testing.expectEqualStrings("Hello", buf[0..5]);
|
|
1611
|
+
try testing.expectEqual(4, try ri.interface.readSliceShort(&buf));
|
|
1612
|
+
try testing.expectEqualStrings("Fren", buf[0..4]);
|
|
1613
|
+
try testing.expectEqual(0, try ri.interface.readSliceShort(&buf));
|
|
1614
|
+
}
|
|
1615
|
+
|
|
1536
1616
|
test readVec {
|
|
1537
1617
|
var r: Reader = .fixed(std.ascii.letters);
|
|
1538
1618
|
var flat_buffer: [52]u8 = undefined;
|
|
@@ -1642,6 +1722,26 @@ test "takeDelimiterInclusive when it rebases" {
|
|
|
1642
1722
|
}
|
|
1643
1723
|
}
|
|
1644
1724
|
|
|
1725
|
+
test "takeDelimiterInclusive on an indirect reader when it rebases" {
|
|
1726
|
+
const written_line = "ABCDEFGHIJKLMNOPQRSTUVWXYZ\n";
|
|
1727
|
+
var buffer: [128]u8 = undefined;
|
|
1728
|
+
var tr: std.testing.Reader = .init(&buffer, &.{
|
|
1729
|
+
.{ .buffer = written_line[0..4] },
|
|
1730
|
+
.{ .buffer = written_line[4..] },
|
|
1731
|
+
.{ .buffer = written_line },
|
|
1732
|
+
.{ .buffer = written_line },
|
|
1733
|
+
.{ .buffer = written_line },
|
|
1734
|
+
.{ .buffer = written_line },
|
|
1735
|
+
.{ .buffer = written_line },
|
|
1736
|
+
});
|
|
1737
|
+
var indirect_buffer: [128]u8 = undefined;
|
|
1738
|
+
var tri: std.testing.ReaderIndirect = .init(&tr.interface, &indirect_buffer);
|
|
1739
|
+
const r = &tri.interface;
|
|
1740
|
+
for (0..6) |_| {
|
|
1741
|
+
try std.testing.expectEqualStrings(written_line, try r.takeDelimiterInclusive('\n'));
|
|
1742
|
+
}
|
|
1743
|
+
}
|
|
1744
|
+
|
|
1645
1745
|
test "takeStruct and peekStruct packed" {
|
|
1646
1746
|
var r: Reader = .fixed(&.{ 0b11110000, 0b00110011 });
|
|
1647
1747
|
const S = packed struct(u16) { a: u2, b: u6, c: u7, d: u1 };
|
package/std/Io/Writer.zig
CHANGED
|
@@ -917,10 +917,12 @@ pub fn sendFileHeader(
|
|
|
917
917
|
return n;
|
|
918
918
|
}
|
|
919
919
|
|
|
920
|
-
/// Asserts nonzero buffer capacity
|
|
920
|
+
/// Asserts nonzero buffer capacity and nonzero `limit`.
|
|
921
921
|
pub fn sendFileReading(w: *Writer, file_reader: *File.Reader, limit: Limit) FileReadingError!usize {
|
|
922
|
+
assert(limit != .nothing);
|
|
922
923
|
const dest = limit.slice(try w.writableSliceGreedy(1));
|
|
923
|
-
const n = try file_reader.
|
|
924
|
+
const n = try file_reader.interface.readSliceShort(dest);
|
|
925
|
+
if (n == 0) return error.EndOfStream;
|
|
924
926
|
w.advance(n);
|
|
925
927
|
return n;
|
|
926
928
|
}
|
|
@@ -2655,7 +2657,8 @@ pub const Allocating = struct {
|
|
|
2655
2657
|
if (additional == 0) return error.EndOfStream;
|
|
2656
2658
|
list.ensureUnusedCapacity(gpa, limit.minInt64(additional)) catch return error.WriteFailed;
|
|
2657
2659
|
const dest = limit.slice(list.unusedCapacitySlice());
|
|
2658
|
-
const n = try file_reader.
|
|
2660
|
+
const n = try file_reader.interface.readSliceShort(dest);
|
|
2661
|
+
if (n == 0) return error.EndOfStream;
|
|
2659
2662
|
list.items.len += n;
|
|
2660
2663
|
return n;
|
|
2661
2664
|
}
|
|
@@ -2714,18 +2717,40 @@ test "allocating sendFile" {
|
|
|
2714
2717
|
|
|
2715
2718
|
const file = try tmp_dir.dir.createFile("input.txt", .{ .read = true });
|
|
2716
2719
|
defer file.close();
|
|
2717
|
-
var r_buffer: [
|
|
2720
|
+
var r_buffer: [2]u8 = undefined;
|
|
2718
2721
|
var file_writer: std.fs.File.Writer = .init(file, &r_buffer);
|
|
2719
|
-
try file_writer.interface.
|
|
2722
|
+
try file_writer.interface.writeAll("abcd");
|
|
2720
2723
|
try file_writer.interface.flush();
|
|
2721
2724
|
|
|
2722
2725
|
var file_reader = file_writer.moveToReader();
|
|
2723
2726
|
try file_reader.seekTo(0);
|
|
2727
|
+
try file_reader.interface.fill(2);
|
|
2724
2728
|
|
|
2725
2729
|
var allocating: Writer.Allocating = .init(testing.allocator);
|
|
2726
2730
|
defer allocating.deinit();
|
|
2731
|
+
try allocating.ensureUnusedCapacity(1);
|
|
2732
|
+
try testing.expectEqual(4, allocating.writer.sendFileAll(&file_reader, .unlimited));
|
|
2733
|
+
try testing.expectEqualStrings("abcd", allocating.writer.buffered());
|
|
2734
|
+
}
|
|
2735
|
+
|
|
2736
|
+
test sendFileReading {
|
|
2737
|
+
var tmp_dir = testing.tmpDir(.{});
|
|
2738
|
+
defer tmp_dir.cleanup();
|
|
2739
|
+
|
|
2740
|
+
const file = try tmp_dir.dir.createFile("input.txt", .{ .read = true });
|
|
2741
|
+
defer file.close();
|
|
2742
|
+
var r_buffer: [2]u8 = undefined;
|
|
2743
|
+
var file_writer: std.fs.File.Writer = .init(file, &r_buffer);
|
|
2744
|
+
try file_writer.interface.writeAll("abcd");
|
|
2745
|
+
try file_writer.interface.flush();
|
|
2727
2746
|
|
|
2728
|
-
|
|
2747
|
+
var file_reader = file_writer.moveToReader();
|
|
2748
|
+
try file_reader.seekTo(0);
|
|
2749
|
+
try file_reader.interface.fill(2);
|
|
2750
|
+
|
|
2751
|
+
var w_buffer: [1]u8 = undefined;
|
|
2752
|
+
var discarding: Writer.Discarding = .init(&w_buffer);
|
|
2753
|
+
try testing.expectEqual(4, discarding.writer.sendFileReadingAll(&file_reader, .unlimited));
|
|
2729
2754
|
}
|
|
2730
2755
|
|
|
2731
2756
|
test writeStruct {
|
package/std/Target.zig
CHANGED
|
@@ -3075,6 +3075,10 @@ pub fn cTypeAlignment(target: *const Target, c_type: CType) u16 {
|
|
|
3075
3075
|
},
|
|
3076
3076
|
else => {},
|
|
3077
3077
|
},
|
|
3078
|
+
.m68k => switch (c_type) {
|
|
3079
|
+
.int, .uint, .long, .ulong => return 2,
|
|
3080
|
+
else => {},
|
|
3081
|
+
},
|
|
3078
3082
|
.powerpc, .powerpcle, .powerpc64, .powerpc64le => switch (target.os.tag) {
|
|
3079
3083
|
.aix => switch (c_type) {
|
|
3080
3084
|
.double, .longdouble => return 4,
|
|
@@ -3175,6 +3179,10 @@ pub fn cTypePreferredAlignment(target: *const Target, c_type: CType) u16 {
|
|
|
3175
3179
|
else => {},
|
|
3176
3180
|
},
|
|
3177
3181
|
},
|
|
3182
|
+
.m68k => switch (c_type) {
|
|
3183
|
+
.int, .uint, .long, .ulong => return 2,
|
|
3184
|
+
else => {},
|
|
3185
|
+
},
|
|
3178
3186
|
.wasm32, .wasm64 => switch (target.os.tag) {
|
|
3179
3187
|
.emscripten => switch (c_type) {
|
|
3180
3188
|
.longdouble => return 8,
|
package/std/Thread.zig
CHANGED
package/std/c.zig
CHANGED
|
@@ -2235,40 +2235,70 @@ pub const S = switch (native_os) {
|
|
|
2235
2235
|
}
|
|
2236
2236
|
},
|
|
2237
2237
|
.dragonfly => struct {
|
|
2238
|
+
pub const IFMT = 0o170000;
|
|
2239
|
+
|
|
2240
|
+
pub const IFIFO = 0o010000;
|
|
2241
|
+
pub const IFCHR = 0o020000;
|
|
2242
|
+
pub const IFDIR = 0o040000;
|
|
2243
|
+
pub const IFBLK = 0o060000;
|
|
2244
|
+
pub const IFREG = 0o100000;
|
|
2245
|
+
pub const IFLNK = 0o120000;
|
|
2246
|
+
pub const IFSOCK = 0o140000;
|
|
2247
|
+
pub const IFWHT = 0o160000;
|
|
2248
|
+
|
|
2249
|
+
pub const ISUID = 0o4000;
|
|
2250
|
+
pub const ISGID = 0o2000;
|
|
2251
|
+
pub const ISVTX = 0o1000;
|
|
2252
|
+
pub const IRWXU = 0o700;
|
|
2253
|
+
pub const IRUSR = 0o400;
|
|
2254
|
+
pub const IWUSR = 0o200;
|
|
2255
|
+
pub const IXUSR = 0o100;
|
|
2256
|
+
pub const IRWXG = 0o070;
|
|
2257
|
+
pub const IRGRP = 0o040;
|
|
2258
|
+
pub const IWGRP = 0o020;
|
|
2259
|
+
pub const IXGRP = 0o010;
|
|
2260
|
+
pub const IRWXO = 0o007;
|
|
2261
|
+
pub const IROTH = 0o004;
|
|
2262
|
+
pub const IWOTH = 0o002;
|
|
2263
|
+
pub const IXOTH = 0o001;
|
|
2264
|
+
|
|
2238
2265
|
pub const IREAD = IRUSR;
|
|
2239
2266
|
pub const IEXEC = IXUSR;
|
|
2240
2267
|
pub const IWRITE = IWUSR;
|
|
2241
|
-
pub const IXOTH = 1;
|
|
2242
|
-
pub const IWOTH = 2;
|
|
2243
|
-
pub const IROTH = 4;
|
|
2244
|
-
pub const IRWXO = 7;
|
|
2245
|
-
pub const IXGRP = 8;
|
|
2246
|
-
pub const IWGRP = 16;
|
|
2247
|
-
pub const IRGRP = 32;
|
|
2248
|
-
pub const IRWXG = 56;
|
|
2249
|
-
pub const IXUSR = 64;
|
|
2250
|
-
pub const IWUSR = 128;
|
|
2251
|
-
pub const IRUSR = 256;
|
|
2252
|
-
pub const IRWXU = 448;
|
|
2253
2268
|
pub const ISTXT = 512;
|
|
2254
2269
|
pub const BLKSIZE = 512;
|
|
2255
|
-
|
|
2256
|
-
pub
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
pub const IFCHR = 8192;
|
|
2260
|
-
pub const IFDIR = 16384;
|
|
2261
|
-
pub const IFBLK = 24576;
|
|
2262
|
-
pub const IFREG = 32768;
|
|
2263
|
-
pub const IFDB = 36864;
|
|
2264
|
-
pub const IFLNK = 40960;
|
|
2265
|
-
pub const IFSOCK = 49152;
|
|
2266
|
-
pub const IFWHT = 57344;
|
|
2267
|
-
pub const IFMT = 61440;
|
|
2270
|
+
|
|
2271
|
+
pub fn ISFIFO(m: u32) bool {
|
|
2272
|
+
return m & IFMT == IFIFO;
|
|
2273
|
+
}
|
|
2268
2274
|
|
|
2269
2275
|
pub fn ISCHR(m: u32) bool {
|
|
2270
2276
|
return m & IFMT == IFCHR;
|
|
2271
2277
|
}
|
|
2278
|
+
|
|
2279
|
+
pub fn ISDIR(m: u32) bool {
|
|
2280
|
+
return m & IFMT == IFDIR;
|
|
2281
|
+
}
|
|
2282
|
+
|
|
2283
|
+
pub fn ISBLK(m: u32) bool {
|
|
2284
|
+
return m & IFMT == IFBLK;
|
|
2285
|
+
}
|
|
2286
|
+
|
|
2287
|
+
pub fn ISREG(m: u32) bool {
|
|
2288
|
+
return m & IFMT == IFREG;
|
|
2289
|
+
}
|
|
2290
|
+
|
|
2291
|
+
pub fn ISLNK(m: u32) bool {
|
|
2292
|
+
return m & IFMT == IFLNK;
|
|
2293
|
+
}
|
|
2294
|
+
|
|
2295
|
+
pub fn ISSOCK(m: u32) bool {
|
|
2296
|
+
return m & IFMT == IFSOCK;
|
|
2297
|
+
}
|
|
2298
|
+
|
|
2299
|
+
pub fn IWHT(m: u32) bool {
|
|
2300
|
+
return m & IFMT == IFWHT;
|
|
2301
|
+
}
|
|
2272
2302
|
},
|
|
2273
2303
|
.haiku => struct {
|
|
2274
2304
|
pub const IFMT = 0o170000;
|
|
@@ -3091,8 +3121,17 @@ pub const SIG = switch (native_os) {
|
|
|
3091
3121
|
pub const UNBLOCK = 2;
|
|
3092
3122
|
pub const SETMASK = 3;
|
|
3093
3123
|
},
|
|
3124
|
+
// https://github.com/SerenityOS/serenity/blob/046c23f567a17758d762a33bdf04bacbfd088f9f/Kernel/API/POSIX/signal.h
|
|
3094
3125
|
// https://github.com/SerenityOS/serenity/blob/046c23f567a17758d762a33bdf04bacbfd088f9f/Kernel/API/POSIX/signal_numbers.h
|
|
3095
3126
|
.serenity => struct {
|
|
3127
|
+
pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
|
|
3128
|
+
pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
|
|
3129
|
+
pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
|
|
3130
|
+
|
|
3131
|
+
pub const BLOCK = 1;
|
|
3132
|
+
pub const UNBLOCK = 2;
|
|
3133
|
+
pub const SETMASK = 3;
|
|
3134
|
+
|
|
3096
3135
|
pub const INVAL = 0;
|
|
3097
3136
|
pub const HUP = 1;
|
|
3098
3137
|
pub const INT = 2;
|
|
@@ -5685,6 +5724,23 @@ pub const MSG = switch (native_os) {
|
|
|
5685
5724
|
pub const WAITFORONE = 0x2000;
|
|
5686
5725
|
pub const NOTIFICATION = 0x4000;
|
|
5687
5726
|
},
|
|
5727
|
+
// https://github.com/openbsd/src/blob/42a7be81bef70c04732f45ec573622effe56b563/sys/sys/socket.h#L506
|
|
5728
|
+
.openbsd => struct {
|
|
5729
|
+
pub const OOB = 0x1;
|
|
5730
|
+
pub const PEEK = 0x2;
|
|
5731
|
+
pub const DONTROUTE = 0x4;
|
|
5732
|
+
pub const EOR = 0x8;
|
|
5733
|
+
pub const TRUNC = 0x10;
|
|
5734
|
+
pub const CTRUNC = 0x20;
|
|
5735
|
+
pub const WAITALL = 0x40;
|
|
5736
|
+
pub const DONTWAIT = 0x80;
|
|
5737
|
+
pub const BCAST = 0x100;
|
|
5738
|
+
pub const MCAST = 0x200;
|
|
5739
|
+
pub const NOSIGNAL = 0x400;
|
|
5740
|
+
pub const CMSG_CLOEXEC = 0x800;
|
|
5741
|
+
pub const WAITFORONE = 0x1000;
|
|
5742
|
+
pub const CMSG_CLOFORK = 0x2000;
|
|
5743
|
+
},
|
|
5688
5744
|
else => void,
|
|
5689
5745
|
};
|
|
5690
5746
|
pub const SOCK = switch (native_os) {
|
|
@@ -6664,7 +6720,12 @@ pub const SOMAXCONN = switch (native_os) {
|
|
|
6664
6720
|
.windows => ws2_32.SOMAXCONN,
|
|
6665
6721
|
// https://github.com/SerenityOS/serenity/blob/ac44ec5ebc707f9dd0c3d4759a1e17e91db5d74f/Kernel/API/POSIX/sys/socket.h#L128
|
|
6666
6722
|
.solaris, .illumos, .serenity => 128,
|
|
6667
|
-
.
|
|
6723
|
+
// https://github.com/freebsd/freebsd-src/blob/9ab31f821ad1c6bad474510447387c50bef2c24c/sys/sys/socket.h#L434
|
|
6724
|
+
// https://github.com/DragonFlyBSD/DragonFlyBSD/blob/fd3d1949d526ffa646e57037770acd6f2f3bb617/sys/sys/socket.h#L393
|
|
6725
|
+
// https://github.com/NetBSD/src/blob/a673fb3f8487e974c669216064f7588207229fea/sys/sys/socket.h#L472
|
|
6726
|
+
// https://github.com/openbsd/src/blob/8ba9cd88f10123fef7af805b8e5ccc2463ad8fa4/sys/sys/socket.h#L483
|
|
6727
|
+
// https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/bsd/sys/socket.h#L815
|
|
6728
|
+
.freebsd, .dragonfly, .netbsd, .openbsd, .driverkit, .macos, .ios, .tvos, .watchos, .visionos => 128,
|
|
6668
6729
|
else => void,
|
|
6669
6730
|
};
|
|
6670
6731
|
pub const IFNAMESIZE = switch (native_os) {
|
package/std/crypto/aes_ocb.zig
CHANGED
|
@@ -155,12 +155,12 @@ fn AesOcb(comptime Aes: anytype) type {
|
|
|
155
155
|
xorWith(&offset, lx.star);
|
|
156
156
|
var pad = offset;
|
|
157
157
|
aes_enc_ctx.encrypt(&pad, &pad);
|
|
158
|
-
for (m[i * 16 ..], 0..) |x, j| {
|
|
159
|
-
c[i * 16 + j] = pad[j] ^ x;
|
|
160
|
-
}
|
|
161
158
|
var e = [_]u8{0} ** 16;
|
|
162
159
|
@memcpy(e[0..leftover], m[i * 16 ..][0..leftover]);
|
|
163
160
|
e[leftover] = 0x80;
|
|
161
|
+
for (m[i * 16 ..], 0..) |x, j| {
|
|
162
|
+
c[i * 16 + j] = pad[j] ^ x;
|
|
163
|
+
}
|
|
164
164
|
xorWith(&sum, e);
|
|
165
165
|
}
|
|
166
166
|
var e = xorBlocks(xorBlocks(sum, offset), lx.dol);
|
|
@@ -354,3 +354,32 @@ test "AesOcb test vector 4" {
|
|
|
354
354
|
try Aes128Ocb.decrypt(&m2, &c, tag, &ad, nonce, k);
|
|
355
355
|
assert(mem.eql(u8, &m, &m2));
|
|
356
356
|
}
|
|
357
|
+
|
|
358
|
+
test "AesOcb in-place encryption-decryption" {
|
|
359
|
+
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
|
|
360
|
+
|
|
361
|
+
var k: [Aes128Ocb.key_length]u8 = undefined;
|
|
362
|
+
var nonce: [Aes128Ocb.nonce_length]u8 = undefined;
|
|
363
|
+
var tag: [Aes128Ocb.tag_length]u8 = undefined;
|
|
364
|
+
var m: [40]u8 = undefined;
|
|
365
|
+
var original_m: [m.len]u8 = undefined;
|
|
366
|
+
_ = try hexToBytes(&k, "000102030405060708090A0B0C0D0E0F");
|
|
367
|
+
_ = try hexToBytes(&m, "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F2021222324252627");
|
|
368
|
+
_ = try hexToBytes(&nonce, "BBAA9988776655443322110D");
|
|
369
|
+
const ad = m;
|
|
370
|
+
|
|
371
|
+
@memcpy(&original_m, &m);
|
|
372
|
+
|
|
373
|
+
Aes128Ocb.encrypt(&m, &tag, &m, &ad, nonce, k);
|
|
374
|
+
|
|
375
|
+
var expected_c: [m.len]u8 = undefined;
|
|
376
|
+
var expected_tag: [tag.len]u8 = undefined;
|
|
377
|
+
_ = try hexToBytes(&expected_tag, "ED07BA06A4A69483A7035490C5769E60");
|
|
378
|
+
_ = try hexToBytes(&expected_c, "D5CA91748410C1751FF8A2F618255B68A0A12E093FF454606E59F9C1D0DDC54B65E8628E568BAD7A");
|
|
379
|
+
|
|
380
|
+
try testing.expectEqualSlices(u8, &expected_tag, &tag);
|
|
381
|
+
try testing.expectEqualSlices(u8, &expected_c, &m);
|
|
382
|
+
try Aes128Ocb.decrypt(&m, &m, tag, &ad, nonce, k);
|
|
383
|
+
|
|
384
|
+
try testing.expectEqualSlices(u8, &original_m, &m);
|
|
385
|
+
}
|
|
@@ -320,6 +320,7 @@ pub fn init(input: *Reader, output: *Writer, options: Options) InitError!Client
|
|
|
320
320
|
var handshake_state: HandshakeState = .hello;
|
|
321
321
|
var handshake_cipher: tls.HandshakeCipher = undefined;
|
|
322
322
|
var main_cert_pub_key: CertificatePublicKey = undefined;
|
|
323
|
+
var tls12_negotiated_group: ?tls.NamedGroup = null;
|
|
323
324
|
const now_sec = std.time.timestamp();
|
|
324
325
|
|
|
325
326
|
var cleartext_fragment_start: usize = 0;
|
|
@@ -679,6 +680,7 @@ pub fn init(input: *Reader, output: *Writer, options: Options) InitError!Client
|
|
|
679
680
|
const curve_type = hsd.decode(u8);
|
|
680
681
|
if (curve_type != 0x03) return error.TlsIllegalParameter; // named_curve
|
|
681
682
|
const named_group = hsd.decode(tls.NamedGroup);
|
|
683
|
+
tls12_negotiated_group = named_group;
|
|
682
684
|
const key_size = hsd.decode(u8);
|
|
683
685
|
try hsd.ensure(key_size);
|
|
684
686
|
const server_pub_key = hsd.slice(key_size);
|
|
@@ -691,10 +693,19 @@ pub fn init(input: *Reader, output: *Writer, options: Options) InitError!Client
|
|
|
691
693
|
if (cipher_state != .cleartext) return error.TlsUnexpectedMessage;
|
|
692
694
|
if (handshake_state != .server_hello_done) return error.TlsUnexpectedMessage;
|
|
693
695
|
|
|
694
|
-
const
|
|
696
|
+
const public_key_bytes: []const u8 = switch (tls12_negotiated_group orelse .secp256r1) {
|
|
697
|
+
.secp256r1 => &key_share.secp256r1_kp.public_key.toUncompressedSec1(),
|
|
698
|
+
.secp384r1 => &key_share.secp384r1_kp.public_key.toUncompressedSec1(),
|
|
699
|
+
.x25519 => &key_share.x25519_kp.public_key,
|
|
700
|
+
else => return error.TlsIllegalParameter,
|
|
701
|
+
};
|
|
702
|
+
|
|
703
|
+
const client_key_exchange_prefix = .{@intFromEnum(tls.ContentType.handshake)} ++
|
|
695
704
|
int(u16, @intFromEnum(tls.ProtocolVersion.tls_1_2)) ++
|
|
696
|
-
|
|
697
|
-
|
|
705
|
+
int(u16, @intCast(public_key_bytes.len + 5)) ++ // record length
|
|
706
|
+
.{@intFromEnum(tls.HandshakeType.client_key_exchange)} ++
|
|
707
|
+
int(u24, @intCast(public_key_bytes.len + 1)) ++ // handshake message length
|
|
708
|
+
.{@as(u8, @intCast(public_key_bytes.len))}; // public key length
|
|
698
709
|
const client_change_cipher_spec_msg = .{@intFromEnum(tls.ContentType.change_cipher_spec)} ++
|
|
699
710
|
int(u16, @intFromEnum(tls.ProtocolVersion.tls_1_2)) ++
|
|
700
711
|
array(u16, tls.ChangeCipherSpecType, .{.change_cipher_spec});
|
|
@@ -703,7 +714,8 @@ pub fn init(input: *Reader, output: *Writer, options: Options) InitError!Client
|
|
|
703
714
|
inline else => |*p| {
|
|
704
715
|
const P = @TypeOf(p.*).A;
|
|
705
716
|
p.transcript_hash.update(wrapped_handshake);
|
|
706
|
-
p.transcript_hash.update(
|
|
717
|
+
p.transcript_hash.update(client_key_exchange_prefix[tls.record_header_len..]);
|
|
718
|
+
p.transcript_hash.update(public_key_bytes);
|
|
707
719
|
const master_secret = hmacExpandLabel(P.Hmac, pre_master_secret, &.{
|
|
708
720
|
"master secret",
|
|
709
721
|
&client_hello_rand,
|
|
@@ -757,8 +769,9 @@ pub fn init(input: *Reader, output: *Writer, options: Options) InitError!Client
|
|
|
757
769
|
nonce,
|
|
758
770
|
pv.app_cipher.client_write_key,
|
|
759
771
|
);
|
|
760
|
-
var all_msgs_vec: [
|
|
761
|
-
&
|
|
772
|
+
var all_msgs_vec: [4][]const u8 = .{
|
|
773
|
+
&client_key_exchange_prefix,
|
|
774
|
+
public_key_bytes,
|
|
762
775
|
&client_change_cipher_spec_msg,
|
|
763
776
|
&client_verify_msg,
|
|
764
777
|
};
|
|
@@ -929,7 +942,6 @@ fn drain(w: *Writer, data: []const []const u8, splat: usize) Writer.Error!usize
|
|
|
929
942
|
if (prepared.cleartext_len < buf.len) break :done;
|
|
930
943
|
}
|
|
931
944
|
for (data[0 .. data.len - 1]) |buf| {
|
|
932
|
-
if (buf.len < min_buffer_len) break :done;
|
|
933
945
|
const prepared = prepareCiphertextRecord(c, ciphertext_buf[ciphertext_end..], buf, .application_data);
|
|
934
946
|
total_clear += prepared.cleartext_len;
|
|
935
947
|
ciphertext_end += prepared.ciphertext_end;
|
|
@@ -937,7 +949,6 @@ fn drain(w: *Writer, data: []const []const u8, splat: usize) Writer.Error!usize
|
|
|
937
949
|
}
|
|
938
950
|
const buf = data[data.len - 1];
|
|
939
951
|
for (0..splat) |_| {
|
|
940
|
-
if (buf.len < min_buffer_len) break :done;
|
|
941
952
|
const prepared = prepareCiphertextRecord(c, ciphertext_buf[ciphertext_end..], buf, .application_data);
|
|
942
953
|
total_clear += prepared.cleartext_len;
|
|
943
954
|
ciphertext_end += prepared.ciphertext_end;
|
package/std/debug.zig
CHANGED
|
@@ -569,7 +569,7 @@ pub fn assertReadable(slice: []const volatile u8) void {
|
|
|
569
569
|
/// Invokes detectable illegal behavior when the provided array is not aligned
|
|
570
570
|
/// to the provided amount.
|
|
571
571
|
pub fn assertAligned(ptr: anytype, comptime alignment: std.mem.Alignment) void {
|
|
572
|
-
const aligned_ptr: *align(alignment.toByteUnits()) anyopaque = @ptrCast(@alignCast(ptr));
|
|
572
|
+
const aligned_ptr: *align(alignment.toByteUnits()) const anyopaque = @ptrCast(@alignCast(ptr));
|
|
573
573
|
_ = aligned_ptr;
|
|
574
574
|
}
|
|
575
575
|
|
package/std/fs/Dir.zig
CHANGED
|
@@ -2583,8 +2583,9 @@ pub fn updateFile(
|
|
|
2583
2583
|
error.ReadFailed => return src_reader.err.?,
|
|
2584
2584
|
error.WriteFailed => return atomic_file.file_writer.err.?,
|
|
2585
2585
|
};
|
|
2586
|
+
try atomic_file.flush();
|
|
2586
2587
|
try atomic_file.file_writer.file.updateTimes(src_stat.atime, src_stat.mtime);
|
|
2587
|
-
try atomic_file.
|
|
2588
|
+
try atomic_file.renameIntoPlace();
|
|
2588
2589
|
return .stale;
|
|
2589
2590
|
}
|
|
2590
2591
|
|