@zigc/lib 0.17.0-dev.9 → 0.17.0-dev.93
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 +6 -1
- package/c/inttypes.zig +0 -10
- package/c/math.zig +46 -122
- 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/build_runner.zig +0 -2
- package/compiler/test_runner.zig +1 -1
- package/compiler/translate-c/Translator.zig +4 -0
- package/compiler_rt/cos.zig +0 -2
- package/compiler_rt/divmodei4.zig +40 -17
- package/compiler_rt/exp.zig +1 -6
- package/compiler_rt/exp2.zig +1 -6
- package/compiler_rt/exp_f128.zig +377 -0
- package/compiler_rt/fabs.zig +0 -2
- package/compiler_rt/fma.zig +0 -2
- package/compiler_rt/fmax.zig +0 -2
- package/compiler_rt/fmin.zig +0 -2
- package/compiler_rt/fmod.zig +0 -2
- package/compiler_rt/limb64.zig +876 -15
- package/compiler_rt/log.zig +0 -2
- package/compiler_rt/log10.zig +0 -2
- package/compiler_rt/log2.zig +0 -2
- package/compiler_rt/mulXi3.zig +1 -1
- package/compiler_rt/round.zig +0 -2
- package/compiler_rt/sin.zig +0 -2
- package/compiler_rt/sincos.zig +0 -2
- package/compiler_rt/sqrt.zig +0 -2
- package/compiler_rt/ssp.zig +1 -1
- package/compiler_rt/tan.zig +0 -2
- package/compiler_rt/trunc.zig +0 -2
- package/compiler_rt/udivmodei4.zig +28 -0
- package/fuzzer.zig +2 -0
- package/libc/musl/arch/mipsn32/syscall_arch.h +35 -32
- package/package.json +1 -1
- package/std/Build/Step/Compile.zig +0 -1
- package/std/Build.zig +0 -3
- package/std/Io/Dispatch.zig +3 -13
- package/std/Io/Semaphore.zig +112 -17
- package/std/Io/Threaded.zig +167 -33
- package/std/Io/Uring.zig +12 -14
- package/std/Io/Writer.zig +46 -42
- package/std/Io/net.zig +11 -11
- package/std/Io.zig +89 -25
- package/std/Target.zig +50 -5
- package/std/builtin.zig +4 -0
- package/std/c/haiku.zig +3 -0
- package/std/c/serenity.zig +1 -6
- package/std/c.zig +59 -6
- package/std/debug.zig +4 -3
- package/std/fmt.zig +7 -2
- package/std/fs/path.zig +6 -4
- package/std/heap/BufferFirstAllocator.zig +165 -0
- package/std/heap.zig +2 -126
- package/std/http/Client.zig +21 -24
- package/std/os/linux/aarch64.zig +41 -12
- package/std/os/linux/arc.zig +41 -12
- package/std/os/linux/arm.zig +41 -12
- package/std/os/linux/hexagon.zig +33 -11
- package/std/os/linux/loongarch32.zig +41 -13
- package/std/os/linux/loongarch64.zig +41 -12
- package/std/os/linux/m68k.zig +41 -13
- package/std/os/linux/mips.zig +67 -36
- package/std/os/linux/mips64.zig +60 -29
- package/std/os/linux/mipsn32.zig +60 -29
- package/std/os/linux/or1k.zig +41 -12
- package/std/os/linux/powerpc.zig +41 -12
- package/std/os/linux/powerpc64.zig +41 -12
- package/std/os/linux/riscv32.zig +41 -12
- package/std/os/linux/riscv64.zig +41 -12
- package/std/os/linux/s390x.zig +44 -7
- package/std/os/linux/sparc64.zig +83 -52
- package/std/os/linux/thumb.zig +52 -36
- package/std/os/linux/x32.zig +41 -12
- package/std/os/linux/x86.zig +42 -13
- package/std/os/linux/x86_64.zig +41 -12
- package/std/os/linux.zig +398 -434
- package/std/os.zig +41 -0
- package/std/sort.zig +3 -3
- package/std/zig/AstGen.zig +22 -92
- package/std/zig/AstRlAnnotate.zig +0 -11
- package/std/zig/BuiltinFn.zig +0 -32
- package/std/zig/LibCInstallation.zig +1 -0
- package/std/zig/Zir.zig +50 -63
- package/std/zig/ZonGen.zig +5 -4
- package/std/zig/llvm/Builder.zig +12 -12
- package/std/zig.zig +0 -10
- package/zig.h +340 -1
- package/libc/mingw/math/fdiml.c +0 -24
- package/libc/musl/src/linux/tee.c +0 -8
- package/libc/musl/src/math/fdimf.c +0 -10
- package/libc/musl/src/math/fdiml.c +0 -18
- package/libc/musl/src/unistd/dup2.c +0 -20
- package/libc/musl/src/unistd/dup3.c +0 -26
package/c/fcntl.zig
CHANGED
|
@@ -12,11 +12,12 @@ 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
|
|
|
18
19
|
fn fallocateLinux(fd: c_int, mode: c_int, offset: off_t, len: off_t) callconv(.c) c_int {
|
|
19
|
-
return errno(linux.fallocate(fd, mode, offset, len));
|
|
20
|
+
return errno(linux.fallocate(fd, @bitCast(mode), offset, len));
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
fn posix_fadviseLinux(fd: c_int, offset: off_t, len: off_t, advice: c_int) callconv(.c) c_int {
|
|
@@ -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
|
|
|
@@ -45,6 +41,7 @@ comptime {
|
|
|
45
41
|
if ((builtin.target.isMinGW() and @sizeOf(f64) != @sizeOf(c_longdouble)) or builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) {
|
|
46
42
|
symbol(&atanl, "atanl");
|
|
47
43
|
symbol(©signl, "copysignl");
|
|
44
|
+
symbol(&fdiml, "fdiml");
|
|
48
45
|
symbol(&nanl, "nanl");
|
|
49
46
|
}
|
|
50
47
|
|
|
@@ -67,6 +64,7 @@ comptime {
|
|
|
67
64
|
symbol(&exp10, "exp10");
|
|
68
65
|
symbol(&exp10f, "exp10f");
|
|
69
66
|
symbol(&fdim, "fdim");
|
|
67
|
+
symbol(&fdimf, "fdimf");
|
|
70
68
|
symbol(&finite, "finite");
|
|
71
69
|
symbol(&finitef, "finitef");
|
|
72
70
|
symbol(&frexp, "frexp");
|
|
@@ -114,13 +112,9 @@ fn atanf(x: f32) callconv(.c) f32 {
|
|
|
114
112
|
}
|
|
115
113
|
|
|
116
114
|
fn atanl(x: c_longdouble) callconv(.c) c_longdouble {
|
|
117
|
-
return switch (@typeInfo(
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
64 => math.atan(@as(f64, @floatCast(x))),
|
|
121
|
-
80 => math.atan(@as(f80, @floatCast(x))),
|
|
122
|
-
128 => math.atan(@as(f128, @floatCast(x))),
|
|
123
|
-
else => unreachable,
|
|
115
|
+
return switch (@typeInfo(c_longdouble).float.bits) {
|
|
116
|
+
64 => std.c.atan(x),
|
|
117
|
+
else => math.atan(x),
|
|
124
118
|
};
|
|
125
119
|
}
|
|
126
120
|
|
|
@@ -141,7 +135,10 @@ fn copysignf(x: f32, y: f32) callconv(.c) f32 {
|
|
|
141
135
|
}
|
|
142
136
|
|
|
143
137
|
fn copysignl(x: c_longdouble, y: c_longdouble) callconv(.c) c_longdouble {
|
|
144
|
-
return
|
|
138
|
+
return switch (@typeInfo(c_longdouble).float.bits) {
|
|
139
|
+
64 => std.c.copysign(x, y),
|
|
140
|
+
else => math.copysign(x, y),
|
|
141
|
+
};
|
|
145
142
|
}
|
|
146
143
|
|
|
147
144
|
fn cosh(x: f64) callconv(.c) f64 {
|
|
@@ -160,25 +157,39 @@ fn exp10f(x: f32) callconv(.c) f32 {
|
|
|
160
157
|
return math.pow(f32, 10.0, x);
|
|
161
158
|
}
|
|
162
159
|
|
|
163
|
-
fn
|
|
164
|
-
if (math.isNan(x))
|
|
160
|
+
fn fdimGeneric(comptime T: type, x: T, y: T) T {
|
|
161
|
+
if (math.isNan(x))
|
|
165
162
|
return x;
|
|
166
|
-
|
|
167
|
-
if (math.isNan(y))
|
|
163
|
+
|
|
164
|
+
if (math.isNan(y))
|
|
168
165
|
return y;
|
|
169
|
-
|
|
170
|
-
if (x > y)
|
|
166
|
+
|
|
167
|
+
if (x > y)
|
|
171
168
|
return x - y;
|
|
172
|
-
}
|
|
173
169
|
return 0;
|
|
174
170
|
}
|
|
175
171
|
|
|
172
|
+
fn fdim(x: f64, y: f64) callconv(.c) f64 {
|
|
173
|
+
return fdimGeneric(f64, x, y);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
fn fdimf(x: f32, y: f32) callconv(.c) f32 {
|
|
177
|
+
return fdimGeneric(f32, x, y);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
fn fdiml(x: c_longdouble, y: c_longdouble) callconv(.c) c_longdouble {
|
|
181
|
+
return switch (@typeInfo(c_longdouble).float.bits) {
|
|
182
|
+
64 => std.c.fdim(x, y),
|
|
183
|
+
else => fdimGeneric(c_longdouble, x, y),
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
|
|
176
187
|
fn finite(x: f64) callconv(.c) c_int {
|
|
177
|
-
return
|
|
188
|
+
return @intFromBool(math.isFinite(x));
|
|
178
189
|
}
|
|
179
190
|
|
|
180
191
|
fn finitef(x: f32) callconv(.c) c_int {
|
|
181
|
-
return
|
|
192
|
+
return @intFromBool(math.isFinite(x));
|
|
182
193
|
}
|
|
183
194
|
|
|
184
195
|
fn frexpGeneric(comptime T: type, x: T, e: *c_int) T {
|
|
@@ -209,7 +220,10 @@ fn frexpf(x: f32, e: *c_int) callconv(.c) f32 {
|
|
|
209
220
|
}
|
|
210
221
|
|
|
211
222
|
fn frexpl(x: c_longdouble, e: *c_int) callconv(.c) c_longdouble {
|
|
212
|
-
return
|
|
223
|
+
return switch (@typeInfo(c_longdouble).float.bits) {
|
|
224
|
+
64 => std.c.frexp(x, e),
|
|
225
|
+
else => frexpGeneric(c_longdouble, x, e),
|
|
226
|
+
};
|
|
213
227
|
}
|
|
214
228
|
|
|
215
229
|
fn hypot(x: f64, y: f64) callconv(.c) f64 {
|
|
@@ -221,19 +235,22 @@ fn hypotf(x: f32, y: f32) callconv(.c) f32 {
|
|
|
221
235
|
}
|
|
222
236
|
|
|
223
237
|
fn hypotl(x: c_longdouble, y: c_longdouble) callconv(.c) c_longdouble {
|
|
224
|
-
return
|
|
238
|
+
return switch (@typeInfo(c_longdouble).float.bits) {
|
|
239
|
+
64 => std.c.hypot(x, y),
|
|
240
|
+
else => math.hypot(x, y),
|
|
241
|
+
};
|
|
225
242
|
}
|
|
226
243
|
|
|
227
244
|
fn isnan(x: f64) callconv(.c) c_int {
|
|
228
|
-
return
|
|
245
|
+
return @intFromBool(math.isNan(x));
|
|
229
246
|
}
|
|
230
247
|
|
|
231
248
|
fn isnanf(x: f32) callconv(.c) c_int {
|
|
232
|
-
return
|
|
249
|
+
return @intFromBool(math.isNan(x));
|
|
233
250
|
}
|
|
234
251
|
|
|
235
252
|
fn isnanl(x: c_longdouble) callconv(.c) c_int {
|
|
236
|
-
return
|
|
253
|
+
return @intFromBool(math.isNan(x));
|
|
237
254
|
}
|
|
238
255
|
|
|
239
256
|
fn lrint(x: f64) callconv(.c) c_long {
|
|
@@ -277,60 +294,10 @@ fn modff(x: f32, iptr: *f32) callconv(.c) f32 {
|
|
|
277
294
|
}
|
|
278
295
|
|
|
279
296
|
fn modfl(x: c_longdouble, iptr: *c_longdouble) callconv(.c) c_longdouble {
|
|
280
|
-
return
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
fn testModf(comptime T: type) !void {
|
|
284
|
-
// Choose the appropriate `modf` impl to test based on type
|
|
285
|
-
const f = switch (T) {
|
|
286
|
-
f32 => modff,
|
|
287
|
-
f64 => modf,
|
|
288
|
-
c_longdouble => modfl,
|
|
289
|
-
else => @compileError("modf not implemented for " ++ @typeName(T)),
|
|
297
|
+
return switch (@typeInfo(c_longdouble).float.bits) {
|
|
298
|
+
64 => std.c.modf(x, iptr),
|
|
299
|
+
else => modfGeneric(c_longdouble, x, iptr),
|
|
290
300
|
};
|
|
291
|
-
|
|
292
|
-
var int: T = undefined;
|
|
293
|
-
const iptr = ∫
|
|
294
|
-
const eps_val: comptime_float = @max(1e-6, math.floatEps(T));
|
|
295
|
-
|
|
296
|
-
const normal_frac = f(@as(T, 1234.567), iptr);
|
|
297
|
-
// Account for precision error
|
|
298
|
-
const expected = 1234.567 - @as(T, 1234);
|
|
299
|
-
try expectApproxEqAbs(expected, normal_frac, eps_val);
|
|
300
|
-
try expectApproxEqRel(@as(T, 1234.0), iptr.*, eps_val);
|
|
301
|
-
|
|
302
|
-
// When `x` is a NaN, NaN is returned and `*iptr` is set to NaN
|
|
303
|
-
const nan_frac = f(math.nan(T), iptr);
|
|
304
|
-
try expect(math.isNan(nan_frac));
|
|
305
|
-
try expect(math.isNan(iptr.*));
|
|
306
|
-
|
|
307
|
-
// When `x` is positive infinity, +0 is returned and `*iptr` is set to
|
|
308
|
-
// positive infinity
|
|
309
|
-
const pos_zero_frac = f(math.inf(T), iptr);
|
|
310
|
-
try expect(math.isPositiveZero(pos_zero_frac));
|
|
311
|
-
try expect(math.isPositiveInf(iptr.*));
|
|
312
|
-
|
|
313
|
-
// When `x` is negative infinity, -0 is returned and `*iptr` is set to
|
|
314
|
-
// negative infinity
|
|
315
|
-
const neg_zero_frac = f(-math.inf(T), iptr);
|
|
316
|
-
try expect(math.isNegativeZero(neg_zero_frac));
|
|
317
|
-
try expect(math.isNegativeInf(iptr.*));
|
|
318
|
-
|
|
319
|
-
// Return -0 when `x` is a negative integer
|
|
320
|
-
const nz_frac = f(@as(T, -1000.0), iptr);
|
|
321
|
-
try expect(math.isNegativeZero(nz_frac));
|
|
322
|
-
try expectEqual(@as(T, -1000.0), iptr.*);
|
|
323
|
-
|
|
324
|
-
// Return +0 when `x` is a positive integer
|
|
325
|
-
const pz_frac = f(@as(T, 1000.0), iptr);
|
|
326
|
-
try expect(math.isPositiveZero(pz_frac));
|
|
327
|
-
try expectEqual(@as(T, 1000.0), iptr.*);
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
test "modf" {
|
|
331
|
-
try testModf(f32);
|
|
332
|
-
try testModf(f64);
|
|
333
|
-
try testModf(c_longdouble);
|
|
334
301
|
}
|
|
335
302
|
|
|
336
303
|
fn nan(_: [*:0]const c_char) callconv(.c) f64 {
|
|
@@ -397,49 +364,6 @@ fn rintf(x: f32) callconv(.c) f32 {
|
|
|
397
364
|
return y;
|
|
398
365
|
}
|
|
399
366
|
|
|
400
|
-
fn testRint(comptime T: type) !void {
|
|
401
|
-
const f = switch (T) {
|
|
402
|
-
f32 => rintf,
|
|
403
|
-
f64 => rint,
|
|
404
|
-
else => @compileError("rint not implemented for" ++ @typeName(T)),
|
|
405
|
-
};
|
|
406
|
-
|
|
407
|
-
// Positive numbers round correctly
|
|
408
|
-
try expectEqual(@as(T, 42.0), f(42.2));
|
|
409
|
-
try expectEqual(@as(T, 42.0), f(41.8));
|
|
410
|
-
|
|
411
|
-
// Negative numbers round correctly
|
|
412
|
-
try expectEqual(@as(T, -6.0), f(-5.9));
|
|
413
|
-
try expectEqual(@as(T, -6.0), f(-6.1));
|
|
414
|
-
|
|
415
|
-
// No rounding needed test
|
|
416
|
-
try expectEqual(@as(T, 5.0), f(5.0));
|
|
417
|
-
try expectEqual(@as(T, -10.0), f(-10.0));
|
|
418
|
-
try expectEqual(@as(T, 0.0), f(0.0));
|
|
419
|
-
|
|
420
|
-
// Very large numbers return unchanged
|
|
421
|
-
const large: T = 9007199254740992.0; // 2^53
|
|
422
|
-
try expectEqual(large, f(large));
|
|
423
|
-
try expectEqual(-large, f(-large));
|
|
424
|
-
|
|
425
|
-
// Small positive numbers round to zero
|
|
426
|
-
const pos_result = f(0.3);
|
|
427
|
-
try expect(math.isPositiveZero(pos_result));
|
|
428
|
-
|
|
429
|
-
// Small negative numbers round to negative zero
|
|
430
|
-
const neg_result = f(-0.3);
|
|
431
|
-
try expect(math.isNegativeZero(neg_result));
|
|
432
|
-
|
|
433
|
-
// Exact half rounds to nearest even (banker's rounding)
|
|
434
|
-
try expectEqual(@as(T, 2.0), f(2.5));
|
|
435
|
-
try expectEqual(@as(T, 4.0), f(3.5));
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
test "rint" {
|
|
439
|
-
try testRint(f32);
|
|
440
|
-
try testRint(f64);
|
|
441
|
-
}
|
|
442
|
-
|
|
443
367
|
fn tanh(x: f64) callconv(.c) f64 {
|
|
444
368
|
return math.tanh(x);
|
|
445
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
|
|