@zigc/lib 0.17.0-dev.56 → 0.17.0-dev.87
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/c/fcntl.zig +5 -0
- package/c/inttypes.zig +0 -10
- package/c/math.zig +0 -100
- package/c/search.zig +1 -27
- package/c/stdlib/drand48.zig +0 -57
- package/c/stdlib.zig +0 -100
- package/c/string.zig +0 -7
- package/c/strings.zig +0 -38
- package/c/unistd.zig +27 -26
- package/c.zig +1 -2
- package/compiler/aro/aro/CodeGen.zig +3 -2
- package/compiler/aro/aro/Compilation.zig +15 -12
- package/compiler/aro/aro/Driver.zig +9 -6
- package/compiler/aro/aro/Parser.zig +18 -12
- package/compiler/aro/aro/Pragma.zig +3 -2
- package/compiler/aro/aro/Preprocessor.zig +9 -6
- package/compiler/aro/aro/pragmas/message.zig +3 -2
- package/compiler/aro/aro/text_literal.zig +3 -2
- package/compiler/aro/assembly_backend/x86_64.zig +3 -2
- package/compiler_rt/limb64.zig +3 -2
- package/package.json +1 -1
- package/std/Io/Semaphore.zig +112 -17
- package/std/Io/Threaded.zig +2 -2
- package/std/Io/Uring.zig +1 -1
- package/std/Io.zig +70 -15
- package/std/c/serenity.zig +1 -6
- package/std/c.zig +53 -10
- package/std/debug.zig +3 -2
- package/std/fs/path.zig +6 -4
- package/std/heap/BufferFirstAllocator.zig +165 -0
- package/std/heap.zig +2 -126
- package/std/os/linux.zig +14 -4
- package/std/os.zig +41 -0
- package/std/zig/AstGen.zig +21 -18
- package/std/zig/ZonGen.zig +5 -4
- package/std/zig/llvm/Builder.zig +12 -12
- package/libc/musl/src/linux/tee.c +0 -8
- package/libc/musl/src/unistd/dup2.c +0 -20
- package/libc/musl/src/unistd/dup3.c +0 -26
package/c/fcntl.zig
CHANGED
|
@@ -12,6 +12,7 @@ comptime {
|
|
|
12
12
|
symbol(&fallocateLinux, "fallocate");
|
|
13
13
|
symbol(&posix_fadviseLinux, "posix_fadvise");
|
|
14
14
|
symbol(&posix_fallocateLinux, "posix_fallocate");
|
|
15
|
+
symbol(&teeLinux, "tee");
|
|
15
16
|
}
|
|
16
17
|
}
|
|
17
18
|
|
|
@@ -26,3 +27,7 @@ fn posix_fadviseLinux(fd: c_int, offset: off_t, len: off_t, advice: c_int) callc
|
|
|
26
27
|
fn posix_fallocateLinux(fd: c_int, offset: off_t, len: off_t) callconv(.c) c_int {
|
|
27
28
|
return errno(linux.fallocate(fd, 0, offset, len));
|
|
28
29
|
}
|
|
30
|
+
|
|
31
|
+
fn teeLinux(src: c_int, dest: c_int, len: usize, flags: c_uint) callconv(.c) isize {
|
|
32
|
+
return errno(linux.tee(src, dest, len, flags));
|
|
33
|
+
}
|
package/c/inttypes.zig
CHANGED
|
@@ -24,13 +24,3 @@ fn imaxdiv(a: intmax_t, b: intmax_t) callconv(.c) imaxdiv_t {
|
|
|
24
24
|
.rem = @rem(a, b),
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
|
-
|
|
28
|
-
test imaxabs {
|
|
29
|
-
const val: intmax_t = -10;
|
|
30
|
-
try std.testing.expectEqual(10, imaxabs(val));
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
test imaxdiv {
|
|
34
|
-
const expected: imaxdiv_t = .{ .quot = 9, .rem = 0 };
|
|
35
|
-
try std.testing.expectEqual(expected, imaxdiv(9, 1));
|
|
36
|
-
}
|
package/c/math.zig
CHANGED
|
@@ -2,10 +2,6 @@ const builtin = @import("builtin");
|
|
|
2
2
|
|
|
3
3
|
const std = @import("std");
|
|
4
4
|
const math = std.math;
|
|
5
|
-
const expect = std.testing.expect;
|
|
6
|
-
const expectEqual = std.testing.expectEqual;
|
|
7
|
-
const expectApproxEqAbs = std.testing.expectApproxEqAbs;
|
|
8
|
-
const expectApproxEqRel = std.testing.expectApproxEqRel;
|
|
9
5
|
|
|
10
6
|
const symbol = @import("../c.zig").symbol;
|
|
11
7
|
|
|
@@ -304,59 +300,6 @@ fn modfl(x: c_longdouble, iptr: *c_longdouble) callconv(.c) c_longdouble {
|
|
|
304
300
|
};
|
|
305
301
|
}
|
|
306
302
|
|
|
307
|
-
fn testModf(comptime T: type) !void {
|
|
308
|
-
// Choose the appropriate `modf` impl to test based on type
|
|
309
|
-
const f = switch (T) {
|
|
310
|
-
f32 => modff,
|
|
311
|
-
f64 => modf,
|
|
312
|
-
c_longdouble => modfl,
|
|
313
|
-
else => @compileError("modf not implemented for " ++ @typeName(T)),
|
|
314
|
-
};
|
|
315
|
-
|
|
316
|
-
var int: T = undefined;
|
|
317
|
-
const iptr = ∫
|
|
318
|
-
const eps_val: comptime_float = @max(1e-6, math.floatEps(T));
|
|
319
|
-
|
|
320
|
-
const normal_frac = f(@as(T, 1234.567), iptr);
|
|
321
|
-
// Account for precision error
|
|
322
|
-
const expected = 1234.567 - @as(T, 1234);
|
|
323
|
-
try expectApproxEqAbs(expected, normal_frac, eps_val);
|
|
324
|
-
try expectApproxEqRel(@as(T, 1234.0), iptr.*, eps_val);
|
|
325
|
-
|
|
326
|
-
// When `x` is a NaN, NaN is returned and `*iptr` is set to NaN
|
|
327
|
-
const nan_frac = f(math.nan(T), iptr);
|
|
328
|
-
try expect(math.isNan(nan_frac));
|
|
329
|
-
try expect(math.isNan(iptr.*));
|
|
330
|
-
|
|
331
|
-
// When `x` is positive infinity, +0 is returned and `*iptr` is set to
|
|
332
|
-
// positive infinity
|
|
333
|
-
const pos_zero_frac = f(math.inf(T), iptr);
|
|
334
|
-
try expect(math.isPositiveZero(pos_zero_frac));
|
|
335
|
-
try expect(math.isPositiveInf(iptr.*));
|
|
336
|
-
|
|
337
|
-
// When `x` is negative infinity, -0 is returned and `*iptr` is set to
|
|
338
|
-
// negative infinity
|
|
339
|
-
const neg_zero_frac = f(-math.inf(T), iptr);
|
|
340
|
-
try expect(math.isNegativeZero(neg_zero_frac));
|
|
341
|
-
try expect(math.isNegativeInf(iptr.*));
|
|
342
|
-
|
|
343
|
-
// Return -0 when `x` is a negative integer
|
|
344
|
-
const nz_frac = f(@as(T, -1000.0), iptr);
|
|
345
|
-
try expect(math.isNegativeZero(nz_frac));
|
|
346
|
-
try expectEqual(@as(T, -1000.0), iptr.*);
|
|
347
|
-
|
|
348
|
-
// Return +0 when `x` is a positive integer
|
|
349
|
-
const pz_frac = f(@as(T, 1000.0), iptr);
|
|
350
|
-
try expect(math.isPositiveZero(pz_frac));
|
|
351
|
-
try expectEqual(@as(T, 1000.0), iptr.*);
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
test "modf" {
|
|
355
|
-
try testModf(f32);
|
|
356
|
-
try testModf(f64);
|
|
357
|
-
try testModf(c_longdouble);
|
|
358
|
-
}
|
|
359
|
-
|
|
360
303
|
fn nan(_: [*:0]const c_char) callconv(.c) f64 {
|
|
361
304
|
return math.nan(f64);
|
|
362
305
|
}
|
|
@@ -421,49 +364,6 @@ fn rintf(x: f32) callconv(.c) f32 {
|
|
|
421
364
|
return y;
|
|
422
365
|
}
|
|
423
366
|
|
|
424
|
-
fn testRint(comptime T: type) !void {
|
|
425
|
-
const f = switch (T) {
|
|
426
|
-
f32 => rintf,
|
|
427
|
-
f64 => rint,
|
|
428
|
-
else => @compileError("rint not implemented for" ++ @typeName(T)),
|
|
429
|
-
};
|
|
430
|
-
|
|
431
|
-
// Positive numbers round correctly
|
|
432
|
-
try expectEqual(@as(T, 42.0), f(42.2));
|
|
433
|
-
try expectEqual(@as(T, 42.0), f(41.8));
|
|
434
|
-
|
|
435
|
-
// Negative numbers round correctly
|
|
436
|
-
try expectEqual(@as(T, -6.0), f(-5.9));
|
|
437
|
-
try expectEqual(@as(T, -6.0), f(-6.1));
|
|
438
|
-
|
|
439
|
-
// No rounding needed test
|
|
440
|
-
try expectEqual(@as(T, 5.0), f(5.0));
|
|
441
|
-
try expectEqual(@as(T, -10.0), f(-10.0));
|
|
442
|
-
try expectEqual(@as(T, 0.0), f(0.0));
|
|
443
|
-
|
|
444
|
-
// Very large numbers return unchanged
|
|
445
|
-
const large: T = 9007199254740992.0; // 2^53
|
|
446
|
-
try expectEqual(large, f(large));
|
|
447
|
-
try expectEqual(-large, f(-large));
|
|
448
|
-
|
|
449
|
-
// Small positive numbers round to zero
|
|
450
|
-
const pos_result = f(0.3);
|
|
451
|
-
try expect(math.isPositiveZero(pos_result));
|
|
452
|
-
|
|
453
|
-
// Small negative numbers round to negative zero
|
|
454
|
-
const neg_result = f(-0.3);
|
|
455
|
-
try expect(math.isNegativeZero(neg_result));
|
|
456
|
-
|
|
457
|
-
// Exact half rounds to nearest even (banker's rounding)
|
|
458
|
-
try expectEqual(@as(T, 2.0), f(2.5));
|
|
459
|
-
try expectEqual(@as(T, 4.0), f(3.5));
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
test "rint" {
|
|
463
|
-
try testRint(f32);
|
|
464
|
-
try testRint(f64);
|
|
465
|
-
}
|
|
466
|
-
|
|
467
367
|
fn tanh(x: f64) callconv(.c) f64 {
|
|
468
368
|
return math.tanh(x);
|
|
469
369
|
}
|
package/c/search.zig
CHANGED
|
@@ -9,6 +9,7 @@ comptime {
|
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
/// Not defined in `std.c` because C headers don't either.
|
|
12
13
|
const Node = extern struct {
|
|
13
14
|
next: ?*Node,
|
|
14
15
|
prev: ?*Node,
|
|
@@ -38,30 +39,3 @@ fn remque(element: *anyopaque) callconv(.c) void {
|
|
|
38
39
|
if (e.next) |next| next.prev = e.prev;
|
|
39
40
|
if (e.prev) |prev| prev.next = e.next;
|
|
40
41
|
}
|
|
41
|
-
|
|
42
|
-
test "insque and remque" {
|
|
43
|
-
var first = Node{ .next = null, .prev = null };
|
|
44
|
-
var second = Node{ .next = null, .prev = null };
|
|
45
|
-
var third = Node{ .next = null, .prev = null };
|
|
46
|
-
|
|
47
|
-
insque(&first, null);
|
|
48
|
-
try std.testing.expectEqual(@as(?*Node, null), first.next);
|
|
49
|
-
try std.testing.expectEqual(@as(?*Node, null), first.prev);
|
|
50
|
-
|
|
51
|
-
insque(&second, &first);
|
|
52
|
-
try std.testing.expectEqual(@as(?*Node, &second), first.next);
|
|
53
|
-
try std.testing.expectEqual(@as(?*Node, &first), second.prev);
|
|
54
|
-
|
|
55
|
-
insque(&third, &first);
|
|
56
|
-
try std.testing.expectEqual(@as(?*Node, &third), first.next);
|
|
57
|
-
try std.testing.expectEqual(@as(?*Node, &second), third.next);
|
|
58
|
-
try std.testing.expectEqual(@as(?*Node, &first), third.prev);
|
|
59
|
-
try std.testing.expectEqual(@as(?*Node, &third), second.prev);
|
|
60
|
-
|
|
61
|
-
remque(&third);
|
|
62
|
-
try std.testing.expectEqual(@as(?*Node, &second), first.next);
|
|
63
|
-
try std.testing.expectEqual(@as(?*Node, &first), second.prev);
|
|
64
|
-
|
|
65
|
-
remque(&second);
|
|
66
|
-
try std.testing.expectEqual(@as(?*Node, null), first.next);
|
|
67
|
-
}
|
package/c/stdlib/drand48.zig
CHANGED
|
@@ -90,60 +90,3 @@ fn srand48(seedval: c_long) callconv(.c) void {
|
|
|
90
90
|
const xi = (@as(u32, @truncate(@as(c_ulong, @bitCast(seedval)))) << 16) | 0x330E;
|
|
91
91
|
lcg = .init(xi, default_multiplier, default_addend);
|
|
92
92
|
}
|
|
93
|
-
|
|
94
|
-
test erand48 {
|
|
95
|
-
var xsubi: [3]c_ushort = .{ 37174, 64810, 11603 };
|
|
96
|
-
|
|
97
|
-
try std.testing.expectApproxEqAbs(0.8965, erand48(&xsubi), 0.0005);
|
|
98
|
-
try std.testing.expectEqualSlices(c_ushort, &.{ 22537, 47966, 58735 }, &xsubi);
|
|
99
|
-
|
|
100
|
-
try std.testing.expectApproxEqAbs(0.3375, erand48(&xsubi), 0.0005);
|
|
101
|
-
try std.testing.expectEqualSlices(c_ushort, &.{ 37344, 32911, 22119 }, &xsubi);
|
|
102
|
-
|
|
103
|
-
try std.testing.expectApproxEqAbs(0.6475, erand48(&xsubi), 0.0005);
|
|
104
|
-
try std.testing.expectEqualSlices(c_ushort, &.{ 23659, 29872, 42445 }, &xsubi);
|
|
105
|
-
|
|
106
|
-
try std.testing.expectApproxEqAbs(0.5005, erand48(&xsubi), 0.0005);
|
|
107
|
-
try std.testing.expectEqualSlices(c_ushort, &.{ 31642, 7875, 32802 }, &xsubi);
|
|
108
|
-
|
|
109
|
-
try std.testing.expectApproxEqAbs(0.5065, erand48(&xsubi), 0.0005);
|
|
110
|
-
try std.testing.expectEqualSlices(c_ushort, &.{ 64669, 14399, 33170 }, &xsubi);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
test jrand48 {
|
|
114
|
-
var xsubi: [3]c_ushort = .{ 25175, 11052, 45015 };
|
|
115
|
-
|
|
116
|
-
try std.testing.expectEqual(1699503220, jrand48(&xsubi));
|
|
117
|
-
try std.testing.expectEqualSlices(c_ushort, &.{ 2326, 23668, 25932 }, &xsubi);
|
|
118
|
-
|
|
119
|
-
try std.testing.expectEqual(-992276007, jrand48(&xsubi));
|
|
120
|
-
try std.testing.expectEqualSlices(c_ushort, &.{ 41577, 4569, 50395 }, &xsubi);
|
|
121
|
-
|
|
122
|
-
try std.testing.expectEqual(-19535776, jrand48(&xsubi));
|
|
123
|
-
try std.testing.expectEqualSlices(c_ushort, &.{ 31936, 59488, 65237 }, &xsubi);
|
|
124
|
-
|
|
125
|
-
try std.testing.expectEqual(79438377, jrand48(&xsubi));
|
|
126
|
-
try std.testing.expectEqualSlices(c_ushort, &.{ 40395, 8745, 1212 }, &xsubi);
|
|
127
|
-
|
|
128
|
-
try std.testing.expectEqual(-1258917728, jrand48(&xsubi));
|
|
129
|
-
try std.testing.expectEqualSlices(c_ushort, &.{ 37242, 28832, 46326 }, &xsubi);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
test nrand48 {
|
|
133
|
-
var xsubi: [3]c_ushort = .{ 546, 33817, 23389 };
|
|
134
|
-
|
|
135
|
-
try std.testing.expectEqual(914920692, nrand48(&xsubi));
|
|
136
|
-
try std.testing.expectEqualSlices(c_ushort, &.{ 29829, 10728, 27921 }, &xsubi);
|
|
137
|
-
|
|
138
|
-
try std.testing.expectEqual(754104482, nrand48(&xsubi));
|
|
139
|
-
try std.testing.expectEqualSlices(c_ushort, &.{ 6828, 28997, 23013 }, &xsubi);
|
|
140
|
-
|
|
141
|
-
try std.testing.expectEqual(609453945, nrand48(&xsubi));
|
|
142
|
-
try std.testing.expectEqualSlices(c_ushort, &.{ 58183, 3826, 18599 }, &xsubi);
|
|
143
|
-
|
|
144
|
-
try std.testing.expectEqual(1878644360, nrand48(&xsubi));
|
|
145
|
-
try std.testing.expectEqualSlices(c_ushort, &.{ 36678, 44304, 57331 }, &xsubi);
|
|
146
|
-
|
|
147
|
-
try std.testing.expectEqual(2114923686, nrand48(&xsubi));
|
|
148
|
-
try std.testing.expectEqualSlices(c_ushort, &.{ 58585, 22861, 64542 }, &xsubi);
|
|
149
|
-
}
|
package/c/stdlib.zig
CHANGED
|
@@ -294,103 +294,3 @@ fn bsearch(key: *const anyopaque, base: *const anyopaque, n: usize, size: usize,
|
|
|
294
294
|
}
|
|
295
295
|
return null;
|
|
296
296
|
}
|
|
297
|
-
|
|
298
|
-
test abs {
|
|
299
|
-
const val: c_int = -10;
|
|
300
|
-
try std.testing.expectEqual(10, abs(val));
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
test labs {
|
|
304
|
-
const val: c_long = -10;
|
|
305
|
-
try std.testing.expectEqual(10, labs(val));
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
test llabs {
|
|
309
|
-
const val: c_longlong = -10;
|
|
310
|
-
try std.testing.expectEqual(10, llabs(val));
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
test div {
|
|
314
|
-
const expected: div_t = .{ .quot = 5, .rem = 5 };
|
|
315
|
-
try std.testing.expectEqual(expected, div(55, 10));
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
test ldiv {
|
|
319
|
-
const expected: ldiv_t = .{ .quot = -6, .rem = 2 };
|
|
320
|
-
try std.testing.expectEqual(expected, ldiv(38, -6));
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
test lldiv {
|
|
324
|
-
const expected: lldiv_t = .{ .quot = 1, .rem = 2 };
|
|
325
|
-
try std.testing.expectEqual(expected, lldiv(5, 3));
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
test atoi {
|
|
329
|
-
try std.testing.expectEqual(0, atoi(@ptrCast("stop42true")));
|
|
330
|
-
try std.testing.expectEqual(42, atoi(@ptrCast("42true")));
|
|
331
|
-
try std.testing.expectEqual(-1, atoi(@ptrCast("-01")));
|
|
332
|
-
try std.testing.expectEqual(1, atoi(@ptrCast("+001")));
|
|
333
|
-
try std.testing.expectEqual(100, atoi(@ptrCast(" 100")));
|
|
334
|
-
try std.testing.expectEqual(500, atoi(@ptrCast("000000000000500")));
|
|
335
|
-
try std.testing.expectEqual(1111, atoi(@ptrCast("0000000000001111_0000")));
|
|
336
|
-
try std.testing.expectEqual(0, atoi(@ptrCast("0xAA")));
|
|
337
|
-
try std.testing.expectEqual(700, atoi(@ptrCast("700B")));
|
|
338
|
-
try std.testing.expectEqual(32453, atoi(@ptrCast("+32453more")));
|
|
339
|
-
try std.testing.expectEqual(std.math.maxInt(c_int), atoi(@ptrCast(std.fmt.comptimePrint("{d}", .{std.math.maxInt(c_int)}))));
|
|
340
|
-
try std.testing.expectEqual(std.math.minInt(c_int), atoi(@ptrCast(std.fmt.comptimePrint("{d}", .{std.math.minInt(c_int)}))));
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
test atol {
|
|
344
|
-
try std.testing.expectEqual(0, atol(@ptrCast("stop42true")));
|
|
345
|
-
try std.testing.expectEqual(42, atol(@ptrCast("42true")));
|
|
346
|
-
try std.testing.expectEqual(-1, atol(@ptrCast("-01")));
|
|
347
|
-
try std.testing.expectEqual(1, atol(@ptrCast("+001")));
|
|
348
|
-
try std.testing.expectEqual(100, atol(@ptrCast(" 100")));
|
|
349
|
-
try std.testing.expectEqual(500, atol(@ptrCast("000000000000500")));
|
|
350
|
-
try std.testing.expectEqual(1111, atol(@ptrCast("0000000000001111_0000")));
|
|
351
|
-
try std.testing.expectEqual(0, atol(@ptrCast("0xAA")));
|
|
352
|
-
try std.testing.expectEqual(700, atol(@ptrCast("700B")));
|
|
353
|
-
try std.testing.expectEqual(32453, atol(@ptrCast("+32453more")));
|
|
354
|
-
try std.testing.expectEqual(std.math.maxInt(c_long), atol(@ptrCast(std.fmt.comptimePrint("{d}", .{std.math.maxInt(c_long)}))));
|
|
355
|
-
try std.testing.expectEqual(std.math.minInt(c_long), atol(@ptrCast(std.fmt.comptimePrint("{d}", .{std.math.minInt(c_long)}))));
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
test atoll {
|
|
359
|
-
try std.testing.expectEqual(0, atoll(@ptrCast("stop42true")));
|
|
360
|
-
try std.testing.expectEqual(42, atoll(@ptrCast("42true")));
|
|
361
|
-
try std.testing.expectEqual(-1, atoll(@ptrCast("-01")));
|
|
362
|
-
try std.testing.expectEqual(1, atoll(@ptrCast("+001")));
|
|
363
|
-
try std.testing.expectEqual(100, atoll(@ptrCast(" 100")));
|
|
364
|
-
try std.testing.expectEqual(500, atoll(@ptrCast("000000000000500")));
|
|
365
|
-
try std.testing.expectEqual(1111, atoll(@ptrCast("0000000000001111_0000")));
|
|
366
|
-
try std.testing.expectEqual(0, atoll(@ptrCast("0xAA")));
|
|
367
|
-
try std.testing.expectEqual(700, atoll(@ptrCast("700B")));
|
|
368
|
-
try std.testing.expectEqual(32453, atoll(@ptrCast(" +32453more")));
|
|
369
|
-
try std.testing.expectEqual(std.math.maxInt(c_longlong), atoll(@ptrCast(std.fmt.comptimePrint("{d}", .{std.math.maxInt(c_longlong)}))));
|
|
370
|
-
try std.testing.expectEqual(std.math.minInt(c_longlong), atoll(@ptrCast(std.fmt.comptimePrint("{d}", .{std.math.minInt(c_longlong)}))));
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
// FIXME: We cannot test strtol, strtoll, strtoul, etc.. here as it must modify errno and libc is not linked in tests
|
|
374
|
-
|
|
375
|
-
test bsearch {
|
|
376
|
-
const Comparison = struct {
|
|
377
|
-
pub fn compare(a: *const anyopaque, b: *const anyopaque) callconv(.c) c_int {
|
|
378
|
-
const a_u16: *const u16 = @ptrCast(@alignCast(a));
|
|
379
|
-
const b_u16: *const u16 = @ptrCast(@alignCast(b));
|
|
380
|
-
|
|
381
|
-
return switch (std.math.order(a_u16.*, b_u16.*)) {
|
|
382
|
-
.gt => 1,
|
|
383
|
-
.eq => 0,
|
|
384
|
-
.lt => -1,
|
|
385
|
-
};
|
|
386
|
-
}
|
|
387
|
-
};
|
|
388
|
-
|
|
389
|
-
const items: []const u16 = &.{ 0, 5, 7, 9, 10, 200, 512, 768 };
|
|
390
|
-
|
|
391
|
-
try std.testing.expectEqual(@as(?*anyopaque, null), bsearch(&@as(u16, 2000), items.ptr, items.len, @sizeOf(u16), Comparison.compare));
|
|
392
|
-
|
|
393
|
-
for (items) |*value| {
|
|
394
|
-
try std.testing.expectEqual(@as(*const anyopaque, value), bsearch(value, items.ptr, items.len, @sizeOf(u16), Comparison.compare));
|
|
395
|
-
}
|
|
396
|
-
}
|
package/c/string.zig
CHANGED
|
@@ -290,10 +290,3 @@ fn mempcpy(noalias dst: *anyopaque, noalias src: *const anyopaque, len: usize) c
|
|
|
290
290
|
@memcpy(dst_bytes[0..len], src_bytes[0..len]);
|
|
291
291
|
return dst_bytes + len;
|
|
292
292
|
}
|
|
293
|
-
|
|
294
|
-
test strncmp {
|
|
295
|
-
try std.testing.expect(strncmp(@ptrCast("a"), @ptrCast("b"), 1) < 0);
|
|
296
|
-
try std.testing.expect(strncmp(@ptrCast("a"), @ptrCast("c"), 1) < 0);
|
|
297
|
-
try std.testing.expect(strncmp(@ptrCast("b"), @ptrCast("a"), 1) > 0);
|
|
298
|
-
try std.testing.expect(strncmp(@ptrCast("\xff"), @ptrCast("\x02"), 1) > 0);
|
|
299
|
-
}
|
package/c/strings.zig
CHANGED
|
@@ -81,41 +81,3 @@ fn __strncasecmp_l(a: [*:0]const c_char, b: [*:0]const c_char, n: usize, locale:
|
|
|
81
81
|
_ = locale;
|
|
82
82
|
return strncasecmp(a, b, n);
|
|
83
83
|
}
|
|
84
|
-
|
|
85
|
-
test bzero {
|
|
86
|
-
var array: [10]u8 = [_]u8{ '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' };
|
|
87
|
-
var a = std.mem.zeroes([array.len]u8);
|
|
88
|
-
a[9] = '0';
|
|
89
|
-
bzero(&array[0], 9);
|
|
90
|
-
try std.testing.expect(std.mem.eql(u8, &array, &a));
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
test firstBitSet {
|
|
94
|
-
try std.testing.expectEqual(0, firstBitSet(usize, 0));
|
|
95
|
-
|
|
96
|
-
for (0..@bitSizeOf(usize)) |i| {
|
|
97
|
-
const bit = @as(usize, 1) << @intCast(i);
|
|
98
|
-
|
|
99
|
-
try std.testing.expectEqual(i + 1, firstBitSet(usize, bit));
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
test strcasecmp {
|
|
104
|
-
try std.testing.expect(strcasecmp(@ptrCast("a"), @ptrCast("b")) < 0);
|
|
105
|
-
try std.testing.expect(strcasecmp(@ptrCast("b"), @ptrCast("a")) > 0);
|
|
106
|
-
try std.testing.expect(strcasecmp(@ptrCast("A"), @ptrCast("b")) < 0);
|
|
107
|
-
try std.testing.expect(strcasecmp(@ptrCast("b"), @ptrCast("A")) > 0);
|
|
108
|
-
try std.testing.expect(strcasecmp(@ptrCast("A"), @ptrCast("A")) == 0);
|
|
109
|
-
try std.testing.expect(strcasecmp(@ptrCast("B"), @ptrCast("b")) == 0);
|
|
110
|
-
try std.testing.expect(strcasecmp(@ptrCast("bb"), @ptrCast("AA")) > 0);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
test strncasecmp {
|
|
114
|
-
try std.testing.expect(strncasecmp(@ptrCast("a"), @ptrCast("b"), 1) < 0);
|
|
115
|
-
try std.testing.expect(strncasecmp(@ptrCast("b"), @ptrCast("a"), 1) > 0);
|
|
116
|
-
try std.testing.expect(strncasecmp(@ptrCast("A"), @ptrCast("b"), 1) < 0);
|
|
117
|
-
try std.testing.expect(strncasecmp(@ptrCast("b"), @ptrCast("A"), 1) > 0);
|
|
118
|
-
try std.testing.expect(strncasecmp(@ptrCast("A"), @ptrCast("A"), 1) == 0);
|
|
119
|
-
try std.testing.expect(strncasecmp(@ptrCast("B"), @ptrCast("b"), 1) == 0);
|
|
120
|
-
try std.testing.expect(strncasecmp(@ptrCast("bb"), @ptrCast("AA"), 2) > 0);
|
|
121
|
-
}
|
package/c/unistd.zig
CHANGED
|
@@ -21,6 +21,8 @@ comptime {
|
|
|
21
21
|
symbol(&chrootLinux, "chroot");
|
|
22
22
|
symbol(&ctermidLinux, "ctermid");
|
|
23
23
|
symbol(&dupLinux, "dup");
|
|
24
|
+
symbol(&dup2Linux, "dup2");
|
|
25
|
+
symbol(&dup3Linux, "dup3");
|
|
24
26
|
|
|
25
27
|
symbol(&getegidLinux, "getegid");
|
|
26
28
|
symbol(&geteuidLinux, "geteuid");
|
|
@@ -101,6 +103,31 @@ fn dupLinux(fd: c_int) callconv(.c) c_int {
|
|
|
101
103
|
return errno(linux.dup(fd));
|
|
102
104
|
}
|
|
103
105
|
|
|
106
|
+
fn dup2Linux(old: c_int, new: c_int) callconv(.c) c_int {
|
|
107
|
+
const busy: usize = @bitCast(-@as(isize, @intFromEnum(linux.E.BUSY)));
|
|
108
|
+
var res = busy;
|
|
109
|
+
while (res == busy) res = linux.dup2(old, new);
|
|
110
|
+
return errno(res);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
fn dup3Linux(old: c_int, new: c_int, flags: c_int) callconv(.c) c_int {
|
|
114
|
+
const busy: usize = @bitCast(-@as(isize, @intFromEnum(linux.E.BUSY)));
|
|
115
|
+
var res = busy;
|
|
116
|
+
|
|
117
|
+
if (@hasField(linux.SYS, "dup3")) {
|
|
118
|
+
while (res == busy) res = linux.dup3(old, new, @intCast(flags));
|
|
119
|
+
} else if (@hasField(linux.SYS, "dup2")) {
|
|
120
|
+
const cloexec: c_int = @bitCast(linux.O{ .CLOEXEC = true });
|
|
121
|
+
const inval: usize = @bitCast(-@as(isize, @intFromEnum(linux.E.INVAL)));
|
|
122
|
+
if (old == new or (flags & ~cloexec != 0)) return errno(inval);
|
|
123
|
+
while (res == busy) res = linux.dup2(old, new);
|
|
124
|
+
_ = if (res >= 0 and (flags & cloexec == cloexec)) linux.fcntl(new, linux.F.SETFD, linux.FD_CLOEXEC);
|
|
125
|
+
} else {
|
|
126
|
+
return errno(@bitCast(-@as(isize, @intFromEnum(linux.E.NOSYS))));
|
|
127
|
+
}
|
|
128
|
+
return errno(res);
|
|
129
|
+
}
|
|
130
|
+
|
|
104
131
|
fn getegidLinux() callconv(.c) linux.gid_t {
|
|
105
132
|
return linux.getegid();
|
|
106
133
|
}
|
|
@@ -206,32 +233,6 @@ fn swab(noalias src_ptr: *const anyopaque, noalias dest_ptr: *anyopaque, n: isiz
|
|
|
206
233
|
}
|
|
207
234
|
}
|
|
208
235
|
|
|
209
|
-
test swab {
|
|
210
|
-
var a: [4]u8 = undefined;
|
|
211
|
-
@memset(a[0..], '\x00');
|
|
212
|
-
swab("abcd", &a, 4);
|
|
213
|
-
try std.testing.expectEqualSlices(u8, "badc", &a);
|
|
214
|
-
|
|
215
|
-
// Partial copy
|
|
216
|
-
@memset(a[0..], '\x00');
|
|
217
|
-
swab("abcd", &a, 2);
|
|
218
|
-
try std.testing.expectEqualSlices(u8, "ba\x00\x00", &a);
|
|
219
|
-
|
|
220
|
-
// n < 1
|
|
221
|
-
@memset(a[0..], '\x00');
|
|
222
|
-
swab("abcd", &a, 0);
|
|
223
|
-
try std.testing.expectEqualSlices(u8, "\x00" ** 4, &a);
|
|
224
|
-
swab("abcd", &a, -1);
|
|
225
|
-
try std.testing.expectEqualSlices(u8, "\x00" ** 4, &a);
|
|
226
|
-
|
|
227
|
-
// Odd n
|
|
228
|
-
@memset(a[0..], '\x00');
|
|
229
|
-
swab("abcd", &a, 1);
|
|
230
|
-
try std.testing.expectEqualSlices(u8, "\x00" ** 4, &a);
|
|
231
|
-
swab("abcd", &a, 3);
|
|
232
|
-
try std.testing.expectEqualSlices(u8, "ba\x00\x00", &a);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
236
|
fn close(fd: std.c.fd_t) callconv(.c) c_int {
|
|
236
237
|
const signed: isize = @bitCast(linux.close(fd));
|
|
237
238
|
if (signed < 0) {
|
package/c.zig
CHANGED
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
//! bundled libcs.
|
|
3
3
|
//!
|
|
4
4
|
//! mingw-w64 libc is not fully statically linked, so some symbols don't need
|
|
5
|
-
//! to be exported.
|
|
6
|
-
//! dependency on msvcrt dll even when linking libc and targeting Windows.
|
|
5
|
+
//! to be exported.
|
|
7
6
|
|
|
8
7
|
const builtin = @import("builtin");
|
|
9
8
|
const std = @import("std");
|
|
@@ -54,8 +54,9 @@ return_label: Ir.Ref = undefined,
|
|
|
54
54
|
compound_assign_dummy: ?Ir.Ref = null,
|
|
55
55
|
|
|
56
56
|
fn fail(c: *CodeGen, comptime fmt: []const u8, args: anytype) error{ FatalError, OutOfMemory } {
|
|
57
|
-
var
|
|
58
|
-
|
|
57
|
+
var bfa_buf: [u8]1024 = undefined;
|
|
58
|
+
var bfa: std.heap.BufferFirstAllocator = .init(&bfa_buf, c.comp.gpa);
|
|
59
|
+
const allocator = bfa.allocator();
|
|
59
60
|
var buf: std.ArrayList(u8) = .empty;
|
|
60
61
|
defer buf.deinit(allocator);
|
|
61
62
|
|
|
@@ -1761,8 +1761,9 @@ fn addToSearchPath(comp: *Compilation, include: Include, verbose: bool) !void {
|
|
|
1761
1761
|
try comp.search_path.append(comp.gpa, include);
|
|
1762
1762
|
}
|
|
1763
1763
|
fn removeDuplicateSearchPaths(comp: *Compilation, start: usize, verbose: bool) !void {
|
|
1764
|
-
var
|
|
1765
|
-
|
|
1764
|
+
var bfa_buf: [1024]u8 = undefined;
|
|
1765
|
+
var bfa: std.heap.BufferFirstAllocator = .init(&bfa_buf, comp.gpa);
|
|
1766
|
+
const allocator = bfa.allocator();
|
|
1766
1767
|
var seen_includes: std.StringHashMapUnmanaged(void) = .empty;
|
|
1767
1768
|
defer seen_includes.deinit(allocator);
|
|
1768
1769
|
var seen_frameworks: std.StringHashMapUnmanaged(void) = .empty;
|
|
@@ -1976,10 +1977,11 @@ const FindInclude = struct {
|
|
|
1976
1977
|
) Allocator.Error!?Result {
|
|
1977
1978
|
const comp = find.comp;
|
|
1978
1979
|
|
|
1979
|
-
var
|
|
1980
|
-
|
|
1981
|
-
const
|
|
1982
|
-
|
|
1980
|
+
var bfa_buf: [path_buf_stack_limit]u8 = undefined;
|
|
1981
|
+
var bfa_state: std.heap.BufferFirstAllocator = .init(&bfa_buf, comp.gpa);
|
|
1982
|
+
const bfa = bfa_state.allocator();
|
|
1983
|
+
const header_path = try std.fmt.allocPrint(bfa, format, args);
|
|
1984
|
+
defer bfa.free(header_path);
|
|
1983
1985
|
find.comp.normalizePath(header_path);
|
|
1984
1986
|
|
|
1985
1987
|
const source = comp.addSourceFromPathExtra(header_path, kind) catch |err| switch (err) {
|
|
@@ -2068,14 +2070,15 @@ pub fn findEmbed(
|
|
|
2068
2070
|
}
|
|
2069
2071
|
}
|
|
2070
2072
|
|
|
2071
|
-
var
|
|
2072
|
-
|
|
2073
|
+
var bfa_buf: [path_buf_stack_limit]u8 = undefined;
|
|
2074
|
+
var bfa_state: std.heap.BufferFirstAllocator = .init(&bfa_buf, comp.gpa);
|
|
2075
|
+
const bfa = bfa_state.allocator();
|
|
2073
2076
|
|
|
2074
2077
|
switch (include_type) {
|
|
2075
2078
|
.quotes, .cli => {
|
|
2076
2079
|
const dir = std.fs.path.dirname(comp.getSource(includer_token_source).path) orelse ".";
|
|
2077
|
-
const path = try std.fs.path.join(
|
|
2078
|
-
defer
|
|
2080
|
+
const path = try std.fs.path.join(bfa, &.{ dir, filename });
|
|
2081
|
+
defer bfa.free(path);
|
|
2079
2082
|
comp.normalizePath(path);
|
|
2080
2083
|
if (comp.getPathContents(path, limit)) |some| {
|
|
2081
2084
|
errdefer comp.gpa.free(some);
|
|
@@ -2089,8 +2092,8 @@ pub fn findEmbed(
|
|
|
2089
2092
|
.angle_brackets => {},
|
|
2090
2093
|
}
|
|
2091
2094
|
for (comp.embed_dirs.items) |embed_dir| {
|
|
2092
|
-
const path = try std.fs.path.join(
|
|
2093
|
-
defer
|
|
2095
|
+
const path = try std.fs.path.join(bfa, &.{ embed_dir, filename });
|
|
2096
|
+
defer bfa.free(path);
|
|
2094
2097
|
comp.normalizePath(path);
|
|
2095
2098
|
if (comp.getPathContents(path, limit)) |some| {
|
|
2096
2099
|
errdefer comp.gpa.free(some);
|
|
@@ -947,8 +947,9 @@ fn addImacros(d: *Driver, path: []const u8) !void {
|
|
|
947
947
|
}
|
|
948
948
|
|
|
949
949
|
pub fn err(d: *Driver, fmt: []const u8, args: anytype) Compilation.Error!void {
|
|
950
|
-
var
|
|
951
|
-
var
|
|
950
|
+
var bfa_buf: [1024]u8 = undefined;
|
|
951
|
+
var bfa: std.heap.BufferFirstAllocator = .init(&bfa_buf, d.comp.gpa);
|
|
952
|
+
var allocating: std.Io.Writer.Allocating = .init(bfa.allocator());
|
|
952
953
|
defer allocating.deinit();
|
|
953
954
|
|
|
954
955
|
Diagnostics.formatArgs(&allocating.writer, fmt, args) catch return error.OutOfMemory;
|
|
@@ -956,8 +957,9 @@ pub fn err(d: *Driver, fmt: []const u8, args: anytype) Compilation.Error!void {
|
|
|
956
957
|
}
|
|
957
958
|
|
|
958
959
|
pub fn warn(d: *Driver, fmt: []const u8, args: anytype) Compilation.Error!void {
|
|
959
|
-
var
|
|
960
|
-
var
|
|
960
|
+
var bfa_buf: [1024]u8 = undefined;
|
|
961
|
+
var bfa: std.heap.BufferFirstAllocator = .init(&bfa_buf, d.comp.gpa);
|
|
962
|
+
var allocating: std.Io.Writer.Allocating = .init(bfa.allocator());
|
|
961
963
|
defer allocating.deinit();
|
|
962
964
|
|
|
963
965
|
Diagnostics.formatArgs(&allocating.writer, fmt, args) catch return error.OutOfMemory;
|
|
@@ -1101,8 +1103,9 @@ fn parseTarget(d: *Driver, arch_os_abi: []const u8, opt_cpu_features: ?[]const u
|
|
|
1101
1103
|
}
|
|
1102
1104
|
|
|
1103
1105
|
pub fn fatal(d: *Driver, comptime fmt: []const u8, args: anytype) error{ FatalError, OutOfMemory } {
|
|
1104
|
-
var
|
|
1105
|
-
var
|
|
1106
|
+
var bfa_buf: [1024]u8 = undefined;
|
|
1107
|
+
var bfa: std.heap.BufferFirstAllocator = .init(&bfa_buf, d.comp.gpa);
|
|
1108
|
+
var allocating: std.Io.Writer.Allocating = .init(bfa.allocator());
|
|
1106
1109
|
defer allocating.deinit();
|
|
1107
1110
|
|
|
1108
1111
|
Diagnostics.formatArgs(&allocating.writer, fmt, args) catch return error.OutOfMemory;
|