@zigc/lib 0.17.0-dev.39 → 0.17.0-dev.56

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/std/Io/Uring.zig CHANGED
@@ -779,7 +779,6 @@ pub fn io(ev: *Evented) Io {
779
779
  .netConnectUnix = netConnectUnixUnavailable,
780
780
  .netSocketCreatePair = netSocketCreatePairUnavailable,
781
781
  .netSend = netSendUnavailable,
782
- .netRead = netReadUnavailable,
783
782
  .netWrite = netWriteUnavailable,
784
783
  .netWriteFile = netWriteFileUnavailable,
785
784
  .netClose = netClose,
@@ -2105,6 +2104,12 @@ fn operate(userdata: ?*anyopaque, operation: Io.Operation) Io.Cancelable!Io.Oper
2105
2104
  };
2106
2105
  },
2107
2106
  },
2107
+ .net_read => |o| .{
2108
+ .net_read = r: {
2109
+ _ = o;
2110
+ break :r error.NetworkDown; // TODO
2111
+ },
2112
+ },
2108
2113
  };
2109
2114
  }
2110
2115
 
@@ -2392,6 +2397,10 @@ fn batchDrainSubmitted(
2392
2397
  _ = o;
2393
2398
  @panic("TODO implement batchDrainSubmitted for net_receive");
2394
2399
  },
2400
+ .net_read => |o| {
2401
+ _ = o;
2402
+ @panic("TODO implement batchDrainSubmitted for net_read");
2403
+ },
2395
2404
  })) |result| {
2396
2405
  switch (batch.completed.tail) {
2397
2406
  .none => batch.completed.head = index,
@@ -2493,6 +2502,7 @@ fn batchDrainReady(batch: *Io.Batch) Io.Timeout.Error!void {
2493
2502
  },
2494
2503
  .device_io_control => unreachable,
2495
2504
  .net_receive => @panic("TODO"),
2505
+ .net_read => @panic("TODO"),
2496
2506
  })) |result| {
2497
2507
  switch (batch.completed.tail) {
2498
2508
  .none => batch.completed.head = index,
@@ -5142,18 +5152,6 @@ fn netReceive(
5142
5152
  }
5143
5153
  }
5144
5154
 
5145
- fn netReadUnavailable(
5146
- userdata: ?*anyopaque,
5147
- fd: net.Socket.Handle,
5148
- data: [][]u8,
5149
- ) net.Stream.Reader.Error!usize {
5150
- const ev: *Evented = @ptrCast(@alignCast(userdata));
5151
- _ = ev;
5152
- _ = fd;
5153
- _ = data;
5154
- return error.NetworkDown;
5155
- }
5156
-
5157
5155
  fn netWriteUnavailable(
5158
5156
  userdata: ?*anyopaque,
5159
5157
  handle: net.Socket.Handle,
package/std/Io/net.zig CHANGED
@@ -1245,6 +1245,15 @@ pub const Stream = struct {
1245
1245
 
1246
1246
  const max_iovecs_len = 8;
1247
1247
 
1248
+ /// This is a low-level API that calls the `Io` interface function directly.
1249
+ /// For a higher level API, see `reader`.
1250
+ pub fn read(s: *const Stream, io: Io, data: [][]u8) Reader.Error!usize {
1251
+ return (try io.operate(.{ .net_read = .{
1252
+ .socket_handle = s.socket.handle,
1253
+ .data = data,
1254
+ } })).net_read;
1255
+ }
1256
+
1248
1257
  pub fn close(s: *const Stream, io: Io) void {
1249
1258
  io.vtable.netClose(io.userdata, (&s.socket.handle)[0..1]);
1250
1259
  }
@@ -1259,16 +1268,7 @@ pub const Stream = struct {
1259
1268
  stream: Stream,
1260
1269
  err: ?Error,
1261
1270
 
1262
- pub const Error = error{
1263
- SystemResources,
1264
- ConnectionResetByPeer,
1265
- Timeout,
1266
- SocketUnconnected,
1267
- /// The file descriptor does not hold the required rights to read
1268
- /// from it.
1269
- AccessDenied,
1270
- NetworkDown,
1271
- } || Io.Cancelable || Io.UnexpectedError;
1271
+ pub const Error = Io.Operation.NetRead.Error || Io.Cancelable;
1272
1272
 
1273
1273
  pub fn init(stream: Stream, io: Io, buffer: []u8) Reader {
1274
1274
  return .{
@@ -1302,7 +1302,7 @@ pub const Stream = struct {
1302
1302
  const dest_n, const data_size = try io_r.writableVector(&iovecs_buffer, data);
1303
1303
  const dest = iovecs_buffer[0..dest_n];
1304
1304
  assert(dest[0].len > 0);
1305
- const n = io.vtable.netRead(io.userdata, r.stream.socket.handle, dest) catch |err| {
1305
+ const n = r.stream.read(io, dest) catch |err| {
1306
1306
  r.err = err;
1307
1307
  return error.ReadFailed;
1308
1308
  };
package/std/Io.zig CHANGED
@@ -243,8 +243,6 @@ pub const VTable = struct {
243
243
  netConnectUnix: *const fn (?*anyopaque, *const net.UnixAddress) net.UnixAddress.ConnectError!net.Socket.Handle,
244
244
  netSocketCreatePair: *const fn (?*anyopaque, net.Socket.CreatePairOptions) net.Socket.CreatePairError![2]net.Socket,
245
245
  netSend: *const fn (?*anyopaque, net.Socket.Handle, []net.OutgoingMessage, net.SendFlags) struct { ?net.Socket.SendError, usize },
246
- /// Returns 0 on end of stream.
247
- netRead: *const fn (?*anyopaque, src: net.Socket.Handle, data: [][]u8) net.Stream.Reader.Error!usize,
248
246
  netWrite: *const fn (?*anyopaque, dest: net.Socket.Handle, header: []const u8, data: []const []const u8, splat: usize) net.Stream.Writer.Error!usize,
249
247
  netWriteFile: *const fn (?*anyopaque, net.Socket.Handle, header: []const u8, *Io.File.Reader, Io.Limit) net.Stream.Writer.WriteFileError!usize,
250
248
  netClose: *const fn (?*anyopaque, handle: []const net.Socket.Handle) void,
@@ -261,6 +259,7 @@ pub const Operation = union(enum) {
261
259
  /// other systems this tag is unreachable.
262
260
  device_io_control: DeviceIoControl,
263
261
  net_receive: NetReceive,
262
+ net_read: NetRead,
264
263
 
265
264
  pub const Tag = @typeInfo(Operation).@"union".tag_type.?;
266
265
 
@@ -386,6 +385,23 @@ pub const Operation = union(enum) {
386
385
  pub const Result = struct { ?net.Socket.ReceiveError, usize };
387
386
  };
388
387
 
388
+ pub const NetRead = struct {
389
+ socket_handle: net.Socket.Handle,
390
+ data: [][]u8,
391
+
392
+ pub const Error = error{
393
+ SystemResources,
394
+ ConnectionResetByPeer,
395
+ SocketUnconnected,
396
+ /// The file descriptor does not hold the required rights to read
397
+ /// from it.
398
+ AccessDenied,
399
+ NetworkDown,
400
+ } || Io.UnexpectedError;
401
+
402
+ pub const Result = Error!usize;
403
+ };
404
+
389
405
  pub const Result = Result: {
390
406
  const operation_fields = @typeInfo(Operation).@"union".fields;
391
407
  var field_names: [operation_fields.len][]const u8 = undefined;
@@ -2626,7 +2642,6 @@ pub const failing: std.Io = .{
2626
2642
  .netConnectUnix = failingNetConnectUnix,
2627
2643
  .netSocketCreatePair = failingNetSocketCreatePair,
2628
2644
  .netSend = failingNetSend,
2629
- .netRead = failingNetRead,
2630
2645
  .netWrite = failingNetWrite,
2631
2646
  .netWriteFile = failingNetWriteFile,
2632
2647
  .netClose = unreachableNetClose,
@@ -2774,6 +2789,7 @@ pub fn failingOperate(userdata: ?*anyopaque, operation: Operation) Cancelable!Op
2774
2789
  .file_write_streaming => .{ .file_write_streaming = error.InputOutput },
2775
2790
  .device_io_control => unreachable,
2776
2791
  .net_receive => .{ .net_receive = .{ error.NetworkDown, 0 } },
2792
+ .net_read => .{ .net_read = error.NetworkDown },
2777
2793
  };
2778
2794
  }
2779
2795
 
@@ -3377,13 +3393,6 @@ pub fn failingNetSend(userdata: ?*anyopaque, handle: net.Socket.Handle, messages
3377
3393
  return .{ error.NetworkDown, 0 };
3378
3394
  }
3379
3395
 
3380
- pub fn failingNetRead(userdata: ?*anyopaque, src: net.Socket.Handle, data: [][]u8) net.Stream.Reader.Error!usize {
3381
- _ = userdata;
3382
- _ = src;
3383
- _ = data;
3384
- return error.NetworkDown;
3385
- }
3386
-
3387
3396
  pub fn failingNetWrite(userdata: ?*anyopaque, dest: net.Socket.Handle, header: []const u8, data: []const []const u8, splat: usize) net.Stream.Writer.Error!usize {
3388
3397
  _ = userdata;
3389
3398
  _ = dest;
package/std/Target.zig CHANGED
@@ -68,6 +68,8 @@ pub const Os = struct {
68
68
  opengl,
69
69
  vulkan,
70
70
 
71
+ tios,
72
+
71
73
  // LLVM tags deliberately omitted:
72
74
  // - bridgeos
73
75
  // - cheriotrtos
@@ -207,6 +209,8 @@ pub const Os = struct {
207
209
  .opencl,
208
210
  .opengl,
209
211
  .vulkan,
212
+
213
+ .tios,
210
214
  => .semver,
211
215
 
212
216
  .hurd => .hurd,
@@ -670,6 +674,12 @@ pub const Os = struct {
670
674
  .max = .{ .major = 4, .minor = 6, .patch = 0 },
671
675
  },
672
676
  },
677
+ .tios => .{
678
+ .semver = .{
679
+ .min = .{ .major = 5, .minor = 0, .patch = 0 },
680
+ .max = .{ .major = 5, .minor = 8, .patch = 4 },
681
+ },
682
+ },
673
683
  .vulkan => .{
674
684
  .semver = .{
675
685
  .min = .{ .major = 1, .minor = 2, .patch = 0 },
@@ -758,6 +768,7 @@ pub const wasm = @import("Target/wasm.zig");
758
768
  pub const x86 = @import("Target/x86.zig");
759
769
  pub const xcore = @import("Target/xcore.zig");
760
770
  pub const xtensa = @import("Target/xtensa.zig");
771
+ pub const z80 = @import("Target/generic.zig");
761
772
 
762
773
  pub const Abi = enum {
763
774
  none,
@@ -942,6 +953,7 @@ pub const Abi = enum {
942
953
  .opencl,
943
954
  .opengl,
944
955
  .vulkan,
956
+ .tios,
945
957
  => .none,
946
958
  };
947
959
  }
@@ -1068,6 +1080,7 @@ pub fn toElfMachine(target: *const Target) std.elf.EM {
1068
1080
  .avr => .AVR,
1069
1081
  .bpfeb, .bpfel => .BPF,
1070
1082
  .csky => .CSKY,
1083
+ .ez80 => .Z80,
1071
1084
  .hexagon => .QDSP6,
1072
1085
  .hppa, .hppa64 => .PARISC,
1073
1086
  .kalimba => .CSR_KALIMBA,
@@ -1130,6 +1143,7 @@ pub fn toCoffMachine(target: *const Target) std.coff.IMAGE.FILE.MACHINE {
1130
1143
  .bpfeb,
1131
1144
  .bpfel,
1132
1145
  .csky,
1146
+ .ez80,
1133
1147
  .hexagon,
1134
1148
  .hppa,
1135
1149
  .hppa64,
@@ -1336,6 +1350,7 @@ pub const Cpu = struct {
1336
1350
  bpfeb,
1337
1351
  bpfel,
1338
1352
  csky,
1353
+ ez80,
1339
1354
  hexagon,
1340
1355
  hppa,
1341
1356
  hppa64,
@@ -1437,6 +1452,7 @@ pub const Cpu = struct {
1437
1452
  x86,
1438
1453
  xcore,
1439
1454
  xtensa,
1455
+ z80,
1440
1456
  };
1441
1457
 
1442
1458
  pub inline fn family(arch: Arch) Family {
@@ -1449,6 +1465,7 @@ pub const Cpu = struct {
1449
1465
  .avr => .avr,
1450
1466
  .bpfeb, .bpfel => .bpf,
1451
1467
  .csky => .csky,
1468
+ .ez80 => .z80,
1452
1469
  .hexagon => .hexagon,
1453
1470
  .hppa, .hppa64 => .hppa,
1454
1471
  .kalimba => .kalimba,
@@ -1678,6 +1695,7 @@ pub const Cpu = struct {
1678
1695
  .x86_64,
1679
1696
  .xcore,
1680
1697
  .xtensa,
1698
+ .ez80,
1681
1699
  => .little,
1682
1700
 
1683
1701
  .aarch64_be,
@@ -1948,6 +1966,10 @@ pub const Cpu = struct {
1948
1966
  .spirv_fragment,
1949
1967
  .spirv_vertex,
1950
1968
  => &.{ .spirv32, .spirv64 },
1969
+
1970
+ .ez80_cet,
1971
+ .ez80_tiflags,
1972
+ => &.{.ez80},
1951
1973
  };
1952
1974
  }
1953
1975
  };
@@ -2236,6 +2258,7 @@ pub fn requiresLibC(target: *const Target) bool {
2236
2258
  .plan9,
2237
2259
  .other,
2238
2260
  .@"3ds",
2261
+ .tios,
2239
2262
  => false,
2240
2263
  };
2241
2264
  }
@@ -2398,6 +2421,8 @@ pub const DynamicLinker = struct {
2398
2421
  .ps5,
2399
2422
  .psp,
2400
2423
  .vita,
2424
+
2425
+ .tios,
2401
2426
  => .none,
2402
2427
  };
2403
2428
  }
@@ -2815,6 +2840,8 @@ pub const DynamicLinker = struct {
2815
2840
  .opencl,
2816
2841
  .opengl,
2817
2842
  .vulkan,
2843
+
2844
+ .tios,
2818
2845
  => none,
2819
2846
 
2820
2847
  // TODO go over each item in this list and either move it to the above list, or
@@ -2849,6 +2876,9 @@ pub fn ptrBitWidth_arch_abi(cpu_arch: Cpu.Arch, abi: Abi) u16 {
2849
2876
  .x86_16,
2850
2877
  => 16,
2851
2878
 
2879
+ .ez80,
2880
+ => 24,
2881
+
2852
2882
  .arc,
2853
2883
  .arceb,
2854
2884
  .arm,
@@ -2917,6 +2947,8 @@ pub fn ptrBitWidth(target: *const Target) u16 {
2917
2947
  pub fn stackAlignment(target: *const Target) u16 {
2918
2948
  // Overrides for when the stack alignment is not equal to the pointer width.
2919
2949
  switch (target.cpu.arch) {
2950
+ .ez80,
2951
+ => return 1,
2920
2952
  .m68k,
2921
2953
  => return 2,
2922
2954
  .amdgcn,
@@ -2997,6 +3029,7 @@ pub fn cCharSignedness(target: *const Target) std.builtin.Signedness {
2997
3029
  .arc,
2998
3030
  .arceb,
2999
3031
  .csky,
3032
+ .ez80,
3000
3033
  .hexagon,
3001
3034
  .msp430,
3002
3035
  .powerpc,
@@ -3049,8 +3082,6 @@ pub fn cTypeByteSize(t: *const Target, c_type: CType) u16 {
3049
3082
  => @divExact(cTypeBitSize(t, c_type), 8),
3050
3083
 
3051
3084
  .longdouble => switch (cTypeBitSize(t, c_type)) {
3052
- 16 => 2,
3053
- 32 => 4,
3054
3085
  64 => 8,
3055
3086
  80 => @intCast(std.mem.alignForward(usize, 10, cTypeAlignment(t, .longdouble))),
3056
3087
  128 => 16,
@@ -3364,6 +3395,13 @@ pub fn cTypeBitSize(target: *const Target, c_type: CType) u16 {
3364
3395
  .long, .ulong => return 64,
3365
3396
  .longlong, .ulonglong, .double, .longdouble => return 64,
3366
3397
  },
3398
+ .tios => switch (c_type) {
3399
+ .char => return 8,
3400
+ .short, .ushort => return 16,
3401
+ .int, .uint => return 24,
3402
+ .long, .ulong, .float, .double => return 32,
3403
+ .longlong, .ulonglong, .longdouble => return 64,
3404
+ },
3367
3405
 
3368
3406
  .ps3,
3369
3407
  .contiki,
@@ -3376,7 +3414,7 @@ pub fn cTypeBitSize(target: *const Target, c_type: CType) u16 {
3376
3414
  pub fn cTypeAlignment(target: *const Target, c_type: CType) u16 {
3377
3415
  // Overrides for unusual alignments
3378
3416
  switch (target.cpu.arch) {
3379
- .avr => return 1,
3417
+ .avr, .ez80 => return 1,
3380
3418
  .x86 => switch (target.os.tag) {
3381
3419
  .windows, .uefi => switch (c_type) {
3382
3420
  .longlong, .ulonglong, .double => return 8,
@@ -3406,6 +3444,8 @@ pub fn cTypeAlignment(target: *const Target, c_type: CType) u16 {
3406
3444
  return @min(
3407
3445
  std.math.ceilPowerOfTwoAssert(u16, (cTypeBitSize(target, c_type) + 7) / 8),
3408
3446
  @as(u16, switch (target.cpu.arch) {
3447
+ .ez80 => 1,
3448
+
3409
3449
  .msp430,
3410
3450
  .x86_16,
3411
3451
  => 2,
@@ -3484,7 +3524,7 @@ pub fn cTypePreferredAlignment(target: *const Target, c_type: CType) u16 {
3484
3524
  .longdouble => return 4,
3485
3525
  else => {},
3486
3526
  },
3487
- .avr => return 1,
3527
+ .avr, .ez80 => return 1,
3488
3528
  .x86 => switch (target.os.tag) {
3489
3529
  .windows, .uefi => switch (c_type) {
3490
3530
  .longdouble => switch (target.abi) {
@@ -3516,6 +3556,8 @@ pub fn cTypePreferredAlignment(target: *const Target, c_type: CType) u16 {
3516
3556
  return @min(
3517
3557
  std.math.ceilPowerOfTwoAssert(u16, (cTypeBitSize(target, c_type) + 7) / 8),
3518
3558
  @as(u16, switch (target.cpu.arch) {
3559
+ .ez80 => 1,
3560
+
3519
3561
  .x86_16, .msp430 => 2,
3520
3562
 
3521
3563
  .arc,
@@ -3587,7 +3629,9 @@ pub fn cTypePreferredAlignment(target: *const Target, c_type: CType) u16 {
3587
3629
 
3588
3630
  pub fn cMaxIntAlignment(target: *const Target) u16 {
3589
3631
  return switch (target.cpu.arch) {
3590
- .avr => 1,
3632
+ .avr,
3633
+ .ez80,
3634
+ => 1,
3591
3635
 
3592
3636
  .msp430, .x86_16 => 2,
3593
3637
 
@@ -3726,6 +3770,7 @@ pub fn cCallingConvention(target: *const Target) ?std.builtin.CallingConvention
3726
3770
  .amdgcn => .{ .amdgcn_device = .{} },
3727
3771
  .nvptx, .nvptx64 => .nvptx_device,
3728
3772
  .spirv32, .spirv64 => .spirv_device,
3773
+ .ez80 => .ez80_cet,
3729
3774
  };
3730
3775
  }
3731
3776
 
package/std/builtin.zig CHANGED
@@ -341,6 +341,10 @@ pub const CallingConvention = union(enum(u8)) {
341
341
  spirv_fragment,
342
342
  spirv_vertex,
343
343
 
344
+ // Calling conventions for the `ez80` architecture.
345
+ ez80_cet,
346
+ ez80_tiflags,
347
+
344
348
  /// Options shared across most calling conventions.
345
349
  pub const CommonOptions = struct {
346
350
  /// The boundary the stack is aligned to when the function is called.
package/std/c/haiku.zig CHANGED
@@ -6,6 +6,7 @@ const iovec = std.posix.iovec;
6
6
  const iovec_const = std.posix.iovec_const;
7
7
  const socklen_t = std.c.socklen_t;
8
8
  const fd_t = std.c.fd_t;
9
+ const off_t = std.c.off_t;
9
10
  const PATH_MAX = std.c.PATH_MAX;
10
11
  const uid_t = std.c.uid_t;
11
12
  const gid_t = std.c.gid_t;
@@ -28,6 +29,8 @@ pub extern "root" fn _kern_open_dir(fd: fd_t, path: [*:0]const u8) fd_t;
28
29
  pub extern "root" fn _kern_read_dir(fd: fd_t, buffer: [*]u8, bufferSize: usize, maxCount: u32) isize;
29
30
  pub extern "root" fn _kern_rewind_dir(fd: fd_t) status_t;
30
31
  pub extern "root" fn _kern_read_stat(fd: fd_t, path: [*:0]const u8, traverseLink: bool, stat: *std.c.Stat, statSize: usize) status_t;
32
+ pub extern "root" fn readv_pos(fd: fd_t, pos: off_t, vec: [*]const std.c.iovec, count: i32) isize;
33
+ pub extern "root" fn writev_pos(fd: fd_t, pos: off_t, vec: [*]const std.c.iovec_const, count: i32) isize;
31
34
 
32
35
  pub const area_info = extern struct {
33
36
  area: u32,
package/std/c.zig CHANGED
@@ -3260,8 +3260,8 @@ pub const Sigaction = switch (native_os) {
3260
3260
 
3261
3261
  /// signal handler
3262
3262
  handler: extern union {
3263
- handler: handler_fn,
3264
- sigaction: sigaction_fn,
3263
+ handler: ?handler_fn,
3264
+ sigaction: ?sigaction_fn,
3265
3265
  },
3266
3266
 
3267
3267
  /// signal mask to apply
@@ -11102,6 +11102,14 @@ pub const ioctl = switch (native_os) {
11102
11102
  else => private.ioctl,
11103
11103
  };
11104
11104
 
11105
+ // Math
11106
+ pub extern "c" fn atan(x: f64) callconv(.c) f64;
11107
+ pub extern "c" fn copysign(x: f64, y: f64) callconv(.c) f64;
11108
+ pub extern "c" fn fdim(x: f64, y: f64) callconv(.c) f64;
11109
+ pub extern "c" fn frexp(x: f64, e: *c_int) callconv(.c) f64;
11110
+ pub extern "c" fn hypot(x: f64, y: f64) callconv(.c) f64;
11111
+ pub extern "c" fn modf(x: f64, iptr: *f64) callconv(.c) f64;
11112
+
11105
11113
  // OS-specific bits. These are protected from being used on the wrong OS by
11106
11114
  // comptime assertions inside each OS-specific file.
11107
11115
 
@@ -11142,6 +11150,8 @@ pub const _kern_open_dir = haiku._kern_open_dir;
11142
11150
  pub const _kern_read_dir = haiku._kern_read_dir;
11143
11151
  pub const _kern_read_stat = haiku._kern_read_stat;
11144
11152
  pub const _kern_rewind_dir = haiku._kern_rewind_dir;
11153
+ pub const readv_pos = haiku.readv_pos;
11154
+ pub const writev_pos = haiku.writev_pos;
11145
11155
  pub const area_id = haiku.area_id;
11146
11156
  pub const area_info = haiku.area_info;
11147
11157
  pub const directory_which = haiku.directory_which;
package/std/debug.zig CHANGED
@@ -1576,12 +1576,12 @@ fn handleSegfaultPosix(sig: posix.SIG, info: *const posix.siginfo_t, ctx_ptr: ?*
1576
1576
  .tvos,
1577
1577
  .visionos,
1578
1578
  .watchos,
1579
+ .haiku,
1579
1580
  => @intFromPtr(info.addr),
1580
1581
  .linux,
1581
1582
  => @intFromPtr(info.fields.sigfault.addr),
1582
1583
  .netbsd,
1583
1584
  => @intFromPtr(info.info.reason.fault.addr),
1584
- .haiku,
1585
1585
  .openbsd,
1586
1586
  => @intFromPtr(info.data.fault.addr),
1587
1587
  .illumos,
package/std/fmt.zig CHANGED
@@ -1342,9 +1342,9 @@ pub const hex_charset = "0123456789abcdef";
1342
1342
 
1343
1343
  /// Converts an unsigned integer of any multiple of u8 to an array of lowercase
1344
1344
  /// hex bytes, little endian.
1345
- pub fn hex(x: anytype) [@sizeOf(@TypeOf(x)) * 2]u8 {
1345
+ pub fn hex(x: anytype) [@typeInfo(@TypeOf(x)).int.bits / 4]u8 {
1346
1346
  comptime assert(@typeInfo(@TypeOf(x)).int.signedness == .unsigned);
1347
- var result: [@sizeOf(@TypeOf(x)) * 2]u8 = undefined;
1347
+ var result: [@typeInfo(@TypeOf(x)).int.bits / 4]u8 = undefined;
1348
1348
  var i: usize = 0;
1349
1349
  while (i < result.len / 2) : (i += 1) {
1350
1350
  const byte: u8 = @truncate(x >> @intCast(8 * i));
@@ -1360,6 +1360,11 @@ test hex {
1360
1360
  try std.testing.expect(x.len == 8);
1361
1361
  try std.testing.expectEqualStrings("efbeadde", &x);
1362
1362
  }
1363
+ {
1364
+ const s = "[" ++ hex(@as(u48, 0x12345678_abcd)) ++ "]";
1365
+ try std.testing.expect(s.len == 14);
1366
+ try std.testing.expectEqualStrings("[cdab78563412]", s);
1367
+ }
1363
1368
  {
1364
1369
  const s = "[" ++ hex(@as(u64, 0x12345678_abcdef00)) ++ "]";
1365
1370
  try std.testing.expect(s.len == 18);
@@ -4,8 +4,6 @@
4
4
  //!
5
5
  //! TLS support may be disabled via `std.options.http_disable_tls`.
6
6
  //!
7
- //! TODO all the lockUncancelable in this file should be changed to regular lock and
8
- //! `error.Canceled` added to more error sets.
9
7
  const Client = @This();
10
8
 
11
9
  const builtin = @import("builtin");
@@ -84,8 +82,8 @@ pub const ConnectionPool = struct {
84
82
  /// If no connection is found, null is returned.
85
83
  ///
86
84
  /// Threadsafe.
87
- pub fn findConnection(pool: *ConnectionPool, io: Io, criteria: Criteria) ?*Connection {
88
- pool.mutex.lockUncancelable(io);
85
+ pub fn findConnection(pool: *ConnectionPool, io: Io, criteria: Criteria) Io.Cancelable!?*Connection {
86
+ try pool.mutex.lock(io);
89
87
  defer pool.mutex.unlock(io);
90
88
 
91
89
  var next = pool.free.last;
@@ -113,8 +111,8 @@ pub const ConnectionPool = struct {
113
111
  }
114
112
 
115
113
  /// Acquires an existing connection from the connection pool. This function is threadsafe.
116
- pub fn acquire(pool: *ConnectionPool, io: Io, connection: *Connection) void {
117
- pool.mutex.lockUncancelable(io);
114
+ pub fn acquire(pool: *ConnectionPool, io: Io, connection: *Connection) Io.Cancelable!void {
115
+ try pool.mutex.lock(io);
118
116
  defer pool.mutex.unlock(io);
119
117
 
120
118
  return pool.acquireUnsafe(connection);
@@ -150,8 +148,8 @@ pub const ConnectionPool = struct {
150
148
  }
151
149
 
152
150
  /// Adds a newly created node to the pool of used connections. This function is threadsafe.
153
- pub fn addUsed(pool: *ConnectionPool, io: Io, connection: *Connection) void {
154
- pool.mutex.lockUncancelable(io);
151
+ pub fn addUsed(pool: *ConnectionPool, io: Io, connection: *Connection) Io.Cancelable!void {
152
+ try pool.mutex.lock(io);
155
153
  defer pool.mutex.unlock(io);
156
154
 
157
155
  pool.used.append(&connection.pool_node);
@@ -162,18 +160,15 @@ pub const ConnectionPool = struct {
162
160
  /// If the new size is smaller than the current size, then idle connections will be closed until the pool is the new size.
163
161
  ///
164
162
  /// Threadsafe.
165
- pub fn resize(pool: *ConnectionPool, io: Io, allocator: Allocator, new_size: usize) void {
166
- pool.mutex.lockUncancelable(io);
163
+ pub fn resize(pool: *ConnectionPool, io: Io, new_size: usize) Io.Cancelable!void {
164
+ try pool.mutex.lock(io);
167
165
  defer pool.mutex.unlock(io);
168
166
 
169
- const next = pool.free.first;
170
- _ = next;
171
167
  while (pool.free_len > new_size) {
172
- const popped = pool.free.popFirst() orelse unreachable;
168
+ const popped: *Connection = @alignCast(@fieldParentPtr("pool_node", pool.free.popFirst().?));
173
169
  pool.free_len -= 1;
174
170
 
175
- popped.data.close(allocator);
176
- allocator.destroy(popped);
171
+ popped.destroy(io);
177
172
  }
178
173
 
179
174
  pool.free_size = new_size;
@@ -1323,7 +1318,7 @@ pub fn initDefaultProxies(client: *Client, arena: Allocator, environ_map: *const
1323
1318
  const io = client.io;
1324
1319
 
1325
1320
  // Prevent any new connections from being created.
1326
- client.connection_pool.mutex.lockUncancelable(io);
1321
+ try client.connection_pool.mutex.lock(io);
1327
1322
  defer client.connection_pool.mutex.unlock(io);
1328
1323
 
1329
1324
  assert(client.connection_pool.used.first == null); // There are active requests.
@@ -1418,7 +1413,7 @@ pub const basic_authorization = struct {
1418
1413
 
1419
1414
  pub const ConnectTcpError = error{
1420
1415
  TlsInitializationFailed,
1421
- } || Allocator.Error || HostName.ConnectError;
1416
+ } || Allocator.Error || HostName.ConnectError || Io.Cancelable;
1422
1417
 
1423
1418
  /// Reuses a `Connection` if one matching `host` and `port` is already open.
1424
1419
  ///
@@ -1451,7 +1446,7 @@ pub fn connectTcpOptions(client: *Client, options: ConnectTcpOptions) ConnectTcp
1451
1446
  const proxied_host = options.proxied_host orelse host;
1452
1447
  const proxied_port = options.proxied_port orelse port;
1453
1448
 
1454
- if (client.connection_pool.findConnection(io, .{
1449
+ if (try client.connection_pool.findConnection(io, .{
1455
1450
  .host = proxied_host,
1456
1451
  .port = proxied_port,
1457
1452
  .protocol = protocol,
@@ -1469,18 +1464,20 @@ pub fn connectTcpOptions(client: *Client, options: ConnectTcpOptions) ConnectTcp
1469
1464
  error.Canceled => |e| return e,
1470
1465
  else => return error.TlsInitializationFailed,
1471
1466
  };
1472
- client.connection_pool.addUsed(io, &tc.connection);
1467
+ errdefer tc.destroy();
1468
+ try client.connection_pool.addUsed(io, &tc.connection);
1473
1469
  return &tc.connection;
1474
1470
  },
1475
1471
  .plain => {
1476
1472
  const pc = try Connection.Plain.create(client, proxied_host, proxied_port, stream);
1477
- client.connection_pool.addUsed(io, &pc.connection);
1473
+ errdefer pc.destroy();
1474
+ try client.connection_pool.addUsed(io, &pc.connection);
1478
1475
  return &pc.connection;
1479
1476
  },
1480
1477
  }
1481
1478
  }
1482
1479
 
1483
- pub const ConnectUnixError = Allocator.Error || std.posix.SocketError || error{NameTooLong} || std.posix.ConnectError;
1480
+ pub const ConnectUnixError = Allocator.Error || std.posix.SocketError || error{NameTooLong} || std.posix.ConnectError || Io.Cancelable;
1484
1481
 
1485
1482
  /// Connect to `path` as a unix domain socket. This will reuse a connection if one is already open.
1486
1483
  ///
@@ -1488,7 +1485,7 @@ pub const ConnectUnixError = Allocator.Error || std.posix.SocketError || error{N
1488
1485
  pub fn connectUnix(client: *Client, path: []const u8) ConnectUnixError!*Connection {
1489
1486
  const io = client.io;
1490
1487
 
1491
- if (client.connection_pool.findConnection(io, .{
1488
+ if (try client.connection_pool.findConnection(io, .{
1492
1489
  .host = path,
1493
1490
  .port = 0,
1494
1491
  .protocol = .plain,
@@ -1512,7 +1509,7 @@ pub fn connectUnix(client: *Client, path: []const u8) ConnectUnixError!*Connecti
1512
1509
  };
1513
1510
  errdefer client.allocator.free(conn.data.host);
1514
1511
 
1515
- client.connection_pool.addUsed(conn);
1512
+ try client.connection_pool.addUsed(conn);
1516
1513
 
1517
1514
  return &conn.data;
1518
1515
  }
@@ -1530,7 +1527,7 @@ pub fn connectProxied(
1530
1527
  const io = client.io;
1531
1528
  if (!proxy.supports_connect) return error.TunnelNotSupported;
1532
1529
 
1533
- if (client.connection_pool.findConnection(io, .{
1530
+ if (try client.connection_pool.findConnection(io, .{
1534
1531
  .host = proxied_host,
1535
1532
  .port = proxied_port,
1536
1533
  .protocol = proxy.protocol,
package/std/sort.zig CHANGED
@@ -749,9 +749,9 @@ test partitionPoint {
749
749
 
750
750
  /// Returns a tuple of the lower and upper indices in `items` between which all
751
751
  /// elements return `.eq` when given to `compareFn`.
752
- /// - If no element in `items` returns `.eq`, both indices are the
753
- /// index of the first element in `items` returning `.gt`.
754
- /// - If no element in `items` returns `.gt`, both indices equal `items.len`.
752
+ /// If no element in `items` returns `.eq`, both indices are the index of the
753
+ /// first element in `items` which returns `.gt`, or if no element returns `.gt`,
754
+ /// both indices are `items.len`.
755
755
  ///
756
756
  /// `items` must be sorted in ascending order with respect to `compareFn`:
757
757
  /// ```
@@ -459,6 +459,7 @@ fn findNativeCrtDirPosix(self: *LibCInstallation, gpa: Allocator, io: Io, args:
459
459
 
460
460
  fn findNativeGccDirHaiku(self: *LibCInstallation, gpa: Allocator, io: Io, args: FindNativeOptions) FindError!void {
461
461
  self.gcc_dir = try ccPrintFileName(gpa, io, .{
462
+ .environ_map = args.environ_map,
462
463
  .search_basename = "crtbeginS.o",
463
464
  .want_dirname = .only_dir,
464
465
  .verbose = args.verbose,