@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
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
//! An allocator that attempts to allocate from the given buffer, falling back to
|
|
2
|
+
//! `fallback_allocator` if this fails.
|
|
3
|
+
|
|
4
|
+
const std = @import("../std.zig");
|
|
5
|
+
const heap = std.heap;
|
|
6
|
+
const testing = std.testing;
|
|
7
|
+
|
|
8
|
+
const Alignment = std.mem.Alignment;
|
|
9
|
+
const Allocator = std.mem.Allocator;
|
|
10
|
+
const FixedBufferAllocator = std.heap.FixedBufferAllocator;
|
|
11
|
+
|
|
12
|
+
const BufferFirstAllocator = @This();
|
|
13
|
+
|
|
14
|
+
fallback_allocator: Allocator,
|
|
15
|
+
fixed_buffer_allocator: FixedBufferAllocator,
|
|
16
|
+
|
|
17
|
+
pub fn init(buffer: []u8, fallback_allocator: Allocator) BufferFirstAllocator {
|
|
18
|
+
return .{
|
|
19
|
+
.fallback_allocator = fallback_allocator,
|
|
20
|
+
.fixed_buffer_allocator = .init(buffer),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
pub fn allocator(self: *BufferFirstAllocator) Allocator {
|
|
25
|
+
return .{
|
|
26
|
+
.ptr = self,
|
|
27
|
+
.vtable = &.{
|
|
28
|
+
.alloc = alloc,
|
|
29
|
+
.resize = resize,
|
|
30
|
+
.remap = remap,
|
|
31
|
+
.free = free,
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
fn alloc(
|
|
37
|
+
ctx: *anyopaque,
|
|
38
|
+
len: usize,
|
|
39
|
+
alignment: Alignment,
|
|
40
|
+
ra: usize,
|
|
41
|
+
) ?[*]u8 {
|
|
42
|
+
const self: *BufferFirstAllocator = @ptrCast(@alignCast(ctx));
|
|
43
|
+
return FixedBufferAllocator.alloc(&self.fixed_buffer_allocator, len, alignment, ra) orelse
|
|
44
|
+
return self.fallback_allocator.rawAlloc(len, alignment, ra);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
fn resize(
|
|
48
|
+
ctx: *anyopaque,
|
|
49
|
+
buf: []u8,
|
|
50
|
+
alignment: Alignment,
|
|
51
|
+
new_len: usize,
|
|
52
|
+
ra: usize,
|
|
53
|
+
) bool {
|
|
54
|
+
const self: *BufferFirstAllocator = @ptrCast(@alignCast(ctx));
|
|
55
|
+
if (self.fixed_buffer_allocator.ownsPtr(buf.ptr)) {
|
|
56
|
+
return FixedBufferAllocator.resize(&self.fixed_buffer_allocator, buf, alignment, new_len, ra);
|
|
57
|
+
} else {
|
|
58
|
+
return self.fallback_allocator.rawResize(buf, alignment, new_len, ra);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
fn remap(
|
|
63
|
+
context: *anyopaque,
|
|
64
|
+
memory: []u8,
|
|
65
|
+
alignment: Alignment,
|
|
66
|
+
new_len: usize,
|
|
67
|
+
return_address: usize,
|
|
68
|
+
) ?[*]u8 {
|
|
69
|
+
const self: *BufferFirstAllocator = @ptrCast(@alignCast(context));
|
|
70
|
+
if (self.fixed_buffer_allocator.ownsPtr(memory.ptr)) {
|
|
71
|
+
return FixedBufferAllocator.remap(&self.fixed_buffer_allocator, memory, alignment, new_len, return_address);
|
|
72
|
+
} else {
|
|
73
|
+
return self.fallback_allocator.rawRemap(memory, alignment, new_len, return_address);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
fn free(
|
|
78
|
+
ctx: *anyopaque,
|
|
79
|
+
buf: []u8,
|
|
80
|
+
alignment: Alignment,
|
|
81
|
+
ra: usize,
|
|
82
|
+
) void {
|
|
83
|
+
const self: *BufferFirstAllocator = @ptrCast(@alignCast(ctx));
|
|
84
|
+
if (self.fixed_buffer_allocator.ownsPtr(buf.ptr)) {
|
|
85
|
+
return FixedBufferAllocator.free(&self.fixed_buffer_allocator, buf, alignment, ra);
|
|
86
|
+
} else {
|
|
87
|
+
return self.fallback_allocator.rawFree(buf, alignment, ra);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
test "BufferFirstAllocator" {
|
|
92
|
+
// Buffer first specific tests
|
|
93
|
+
{
|
|
94
|
+
var buffer: [10]u8 = undefined;
|
|
95
|
+
var bfa_state: BufferFirstAllocator = .init(&buffer, std.testing.allocator);
|
|
96
|
+
const bfa = bfa_state.allocator();
|
|
97
|
+
|
|
98
|
+
// We're under the limit, so we should be allocated in the buffer
|
|
99
|
+
const txt0 = "hellowrld";
|
|
100
|
+
const buf0 = try bfa.create(@TypeOf(txt0.*));
|
|
101
|
+
buf0.* = txt0.*;
|
|
102
|
+
try testing.expect(bfa_state.fixed_buffer_allocator.ownsPtr(buf0.ptr));
|
|
103
|
+
|
|
104
|
+
// We're now over the limit, so we should be allocated from the fallback
|
|
105
|
+
const txt1 = "test!";
|
|
106
|
+
const buf1 = try bfa.create(@TypeOf(txt1.*));
|
|
107
|
+
buf1.* = txt1.*;
|
|
108
|
+
try testing.expect(!bfa_state.fixed_buffer_allocator.ownsPtr(buf1.ptr));
|
|
109
|
+
|
|
110
|
+
// Free the allocation that took up space in the buffer
|
|
111
|
+
try testing.expectEqualStrings(txt0, buf0);
|
|
112
|
+
bfa.destroy(buf0);
|
|
113
|
+
|
|
114
|
+
// The next allocation would go in the buffer, but it's too big so it doesn't
|
|
115
|
+
const txt2 = "qwertyqwerty";
|
|
116
|
+
const buf2 = try bfa.create(@TypeOf(txt2.*));
|
|
117
|
+
buf2.* = txt2.*;
|
|
118
|
+
try testing.expect(!bfa_state.fixed_buffer_allocator.ownsPtr(buf2.ptr));
|
|
119
|
+
|
|
120
|
+
// The next allocation is smaller and fits in the buffer
|
|
121
|
+
const txt3 = "dvorak";
|
|
122
|
+
const buf3 = try bfa.create(@TypeOf(txt3.*));
|
|
123
|
+
buf3.* = txt3.*;
|
|
124
|
+
try testing.expect(bfa_state.fixed_buffer_allocator.ownsPtr(buf3.ptr));
|
|
125
|
+
|
|
126
|
+
// The remainder in the buffer is too small for the following allocation so it falls back
|
|
127
|
+
const txt4 = "moretext";
|
|
128
|
+
const buf4 = try bfa.create(@TypeOf(txt4.*));
|
|
129
|
+
buf4.* = txt4.*;
|
|
130
|
+
try testing.expect(!bfa_state.fixed_buffer_allocator.ownsPtr(buf4.ptr));
|
|
131
|
+
|
|
132
|
+
// Check equality on the remaining buffers and free them
|
|
133
|
+
try testing.expectEqualStrings(txt1, buf1);
|
|
134
|
+
bfa.destroy(buf1);
|
|
135
|
+
try testing.expectEqualStrings(txt2, buf2);
|
|
136
|
+
bfa.destroy(buf2);
|
|
137
|
+
try testing.expectEqualStrings(txt3, buf3);
|
|
138
|
+
bfa.destroy(buf3);
|
|
139
|
+
try testing.expectEqualStrings(txt4, buf4);
|
|
140
|
+
bfa.destroy(buf4);
|
|
141
|
+
|
|
142
|
+
try testing.expectEqual(0, bfa_state.fixed_buffer_allocator.end_index);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Standard allocator tests
|
|
146
|
+
{
|
|
147
|
+
var buf: [4096]u8 = undefined;
|
|
148
|
+
{
|
|
149
|
+
var bfa: BufferFirstAllocator = .init(&buf, std.testing.allocator);
|
|
150
|
+
try heap.testAllocator(bfa.allocator());
|
|
151
|
+
}
|
|
152
|
+
{
|
|
153
|
+
var bfa: BufferFirstAllocator = .init(&buf, std.testing.allocator);
|
|
154
|
+
try heap.testAllocatorAligned(bfa.allocator());
|
|
155
|
+
}
|
|
156
|
+
{
|
|
157
|
+
var bfa: BufferFirstAllocator = .init(&buf, std.testing.allocator);
|
|
158
|
+
try heap.testAllocatorLargeAlignment(bfa.allocator());
|
|
159
|
+
}
|
|
160
|
+
{
|
|
161
|
+
var bfa: BufferFirstAllocator = .init(&buf, std.testing.allocator);
|
|
162
|
+
try heap.testAllocatorAlignedShrink(bfa.allocator());
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
package/std/heap.zig
CHANGED
|
@@ -12,6 +12,7 @@ const Alignment = std.mem.Alignment;
|
|
|
12
12
|
pub const ArenaAllocator = @import("heap/ArenaAllocator.zig");
|
|
13
13
|
pub const SmpAllocator = @import("heap/SmpAllocator.zig");
|
|
14
14
|
pub const FixedBufferAllocator = @import("heap/FixedBufferAllocator.zig");
|
|
15
|
+
pub const BufferFirstAllocator = @import("heap/BufferFirstAllocator.zig");
|
|
15
16
|
pub const PageAllocator = @import("heap/PageAllocator.zig");
|
|
16
17
|
pub const WasmAllocator = if (builtin.single_threaded) BrkAllocator else @compileError("unimplemented");
|
|
17
18
|
pub const BrkAllocator = @import("heap/BrkAllocator.zig");
|
|
@@ -367,113 +368,6 @@ pub const brk_allocator: Allocator = .{
|
|
|
367
368
|
.vtable = &BrkAllocator.vtable,
|
|
368
369
|
};
|
|
369
370
|
|
|
370
|
-
/// Returns a `StackFallbackAllocator` allocating using either a
|
|
371
|
-
/// `FixedBufferAllocator` on an array of size `size` and falling back to
|
|
372
|
-
/// `fallback_allocator` if that fails.
|
|
373
|
-
pub fn stackFallback(comptime size: usize, fallback_allocator: Allocator) StackFallbackAllocator(size) {
|
|
374
|
-
return StackFallbackAllocator(size){
|
|
375
|
-
.buffer = undefined,
|
|
376
|
-
.fallback_allocator = fallback_allocator,
|
|
377
|
-
.fixed_buffer_allocator = undefined,
|
|
378
|
-
};
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
/// An allocator that attempts to allocate using a
|
|
382
|
-
/// `FixedBufferAllocator` using an array of size `size`. If the
|
|
383
|
-
/// allocation fails, it will fall back to using
|
|
384
|
-
/// `fallback_allocator`. Easily created with `stackFallback`.
|
|
385
|
-
pub fn StackFallbackAllocator(comptime size: usize) type {
|
|
386
|
-
return struct {
|
|
387
|
-
const Self = @This();
|
|
388
|
-
|
|
389
|
-
buffer: [size]u8,
|
|
390
|
-
fallback_allocator: Allocator,
|
|
391
|
-
fixed_buffer_allocator: FixedBufferAllocator,
|
|
392
|
-
get_called: if (std.debug.runtime_safety) bool else void =
|
|
393
|
-
if (std.debug.runtime_safety) false else {},
|
|
394
|
-
|
|
395
|
-
/// This function both fetches a `Allocator` interface to this
|
|
396
|
-
/// allocator *and* resets the internal buffer allocator.
|
|
397
|
-
pub fn get(self: *Self) Allocator {
|
|
398
|
-
if (std.debug.runtime_safety) {
|
|
399
|
-
assert(!self.get_called); // `get` called multiple times; instead use `const allocator = stackFallback(N).get();`
|
|
400
|
-
self.get_called = true;
|
|
401
|
-
}
|
|
402
|
-
self.fixed_buffer_allocator = FixedBufferAllocator.init(self.buffer[0..]);
|
|
403
|
-
return .{
|
|
404
|
-
.ptr = self,
|
|
405
|
-
.vtable = &.{
|
|
406
|
-
.alloc = alloc,
|
|
407
|
-
.resize = resize,
|
|
408
|
-
.remap = remap,
|
|
409
|
-
.free = free,
|
|
410
|
-
},
|
|
411
|
-
};
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
/// Unlike most std allocators `StackFallbackAllocator` modifies
|
|
415
|
-
/// its internal state before returning an implementation of
|
|
416
|
-
/// the`Allocator` interface and therefore also doesn't use
|
|
417
|
-
/// the usual `.allocator()` method.
|
|
418
|
-
pub const allocator = @compileError("use 'const allocator = stackFallback(N).get();' instead");
|
|
419
|
-
|
|
420
|
-
fn alloc(
|
|
421
|
-
ctx: *anyopaque,
|
|
422
|
-
len: usize,
|
|
423
|
-
alignment: Alignment,
|
|
424
|
-
ra: usize,
|
|
425
|
-
) ?[*]u8 {
|
|
426
|
-
const self: *Self = @ptrCast(@alignCast(ctx));
|
|
427
|
-
return FixedBufferAllocator.alloc(&self.fixed_buffer_allocator, len, alignment, ra) orelse
|
|
428
|
-
return self.fallback_allocator.rawAlloc(len, alignment, ra);
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
fn resize(
|
|
432
|
-
ctx: *anyopaque,
|
|
433
|
-
buf: []u8,
|
|
434
|
-
alignment: Alignment,
|
|
435
|
-
new_len: usize,
|
|
436
|
-
ra: usize,
|
|
437
|
-
) bool {
|
|
438
|
-
const self: *Self = @ptrCast(@alignCast(ctx));
|
|
439
|
-
if (self.fixed_buffer_allocator.ownsPtr(buf.ptr)) {
|
|
440
|
-
return FixedBufferAllocator.resize(&self.fixed_buffer_allocator, buf, alignment, new_len, ra);
|
|
441
|
-
} else {
|
|
442
|
-
return self.fallback_allocator.rawResize(buf, alignment, new_len, ra);
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
fn remap(
|
|
447
|
-
context: *anyopaque,
|
|
448
|
-
memory: []u8,
|
|
449
|
-
alignment: Alignment,
|
|
450
|
-
new_len: usize,
|
|
451
|
-
return_address: usize,
|
|
452
|
-
) ?[*]u8 {
|
|
453
|
-
const self: *Self = @ptrCast(@alignCast(context));
|
|
454
|
-
if (self.fixed_buffer_allocator.ownsPtr(memory.ptr)) {
|
|
455
|
-
return FixedBufferAllocator.remap(&self.fixed_buffer_allocator, memory, alignment, new_len, return_address);
|
|
456
|
-
} else {
|
|
457
|
-
return self.fallback_allocator.rawRemap(memory, alignment, new_len, return_address);
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
fn free(
|
|
462
|
-
ctx: *anyopaque,
|
|
463
|
-
buf: []u8,
|
|
464
|
-
alignment: Alignment,
|
|
465
|
-
ra: usize,
|
|
466
|
-
) void {
|
|
467
|
-
const self: *Self = @ptrCast(@alignCast(ctx));
|
|
468
|
-
if (self.fixed_buffer_allocator.ownsPtr(buf.ptr)) {
|
|
469
|
-
return FixedBufferAllocator.free(&self.fixed_buffer_allocator, buf, alignment, ra);
|
|
470
|
-
} else {
|
|
471
|
-
return self.fallback_allocator.rawFree(buf, alignment, ra);
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
};
|
|
475
|
-
}
|
|
476
|
-
|
|
477
371
|
test c_allocator {
|
|
478
372
|
if (builtin.link_libc) {
|
|
479
373
|
try testAllocator(c_allocator);
|
|
@@ -524,25 +418,6 @@ test ArenaAllocator {
|
|
|
524
418
|
try testAllocatorAlignedShrink(allocator);
|
|
525
419
|
}
|
|
526
420
|
|
|
527
|
-
test "StackFallbackAllocator" {
|
|
528
|
-
{
|
|
529
|
-
var stack_allocator = stackFallback(4096, std.testing.allocator);
|
|
530
|
-
try testAllocator(stack_allocator.get());
|
|
531
|
-
}
|
|
532
|
-
{
|
|
533
|
-
var stack_allocator = stackFallback(4096, std.testing.allocator);
|
|
534
|
-
try testAllocatorAligned(stack_allocator.get());
|
|
535
|
-
}
|
|
536
|
-
{
|
|
537
|
-
var stack_allocator = stackFallback(4096, std.testing.allocator);
|
|
538
|
-
try testAllocatorLargeAlignment(stack_allocator.get());
|
|
539
|
-
}
|
|
540
|
-
{
|
|
541
|
-
var stack_allocator = stackFallback(4096, std.testing.allocator);
|
|
542
|
-
try testAllocatorAlignedShrink(stack_allocator.get());
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
|
|
546
421
|
/// This one should not try alignments that exceed what C malloc can handle.
|
|
547
422
|
pub fn testAllocator(base_allocator: mem.Allocator) !void {
|
|
548
423
|
var validationAllocator = mem.validationWrap(base_allocator);
|
|
@@ -1011,6 +886,7 @@ test {
|
|
|
1011
886
|
_ = ArenaAllocator;
|
|
1012
887
|
_ = DebugAllocator(.{});
|
|
1013
888
|
_ = FixedBufferAllocator;
|
|
889
|
+
_ = BufferFirstAllocator;
|
|
1014
890
|
if (builtin.single_threaded) {
|
|
1015
891
|
if (builtin.cpu.arch.isWasm() or (builtin.os.tag == .linux and !builtin.link_libc)) {
|
|
1016
892
|
_ = brk_allocator;
|
package/std/http/Client.zig
CHANGED
|
@@ -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)
|
|
88
|
-
pool.mutex.
|
|
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.
|
|
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.
|
|
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,
|
|
166
|
-
pool.mutex.
|
|
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()
|
|
168
|
+
const popped: *Connection = @alignCast(@fieldParentPtr("pool_node", pool.free.popFirst().?));
|
|
173
169
|
pool.free_len -= 1;
|
|
174
170
|
|
|
175
|
-
popped.
|
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
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/os/linux/aarch64.zig
CHANGED
|
@@ -2,14 +2,21 @@ const builtin = @import("builtin");
|
|
|
2
2
|
const std = @import("../../std.zig");
|
|
3
3
|
const SYS = std.os.linux.SYS;
|
|
4
4
|
|
|
5
|
-
pub
|
|
5
|
+
pub const syscall_arg_t = u64;
|
|
6
|
+
|
|
7
|
+
pub fn syscall0(
|
|
8
|
+
number: SYS,
|
|
9
|
+
) u64 {
|
|
6
10
|
return asm volatile ("svc #0"
|
|
7
11
|
: [ret] "={x0}" (-> u64),
|
|
8
12
|
: [number] "{x8}" (@intFromEnum(number)),
|
|
9
13
|
: .{ .memory = true });
|
|
10
14
|
}
|
|
11
15
|
|
|
12
|
-
pub fn syscall1(
|
|
16
|
+
pub fn syscall1(
|
|
17
|
+
number: SYS,
|
|
18
|
+
arg1: syscall_arg_t,
|
|
19
|
+
) u64 {
|
|
13
20
|
return asm volatile ("svc #0"
|
|
14
21
|
: [ret] "={x0}" (-> u64),
|
|
15
22
|
: [number] "{x8}" (@intFromEnum(number)),
|
|
@@ -17,7 +24,11 @@ pub fn syscall1(number: SYS, arg1: u64) u64 {
|
|
|
17
24
|
: .{ .memory = true });
|
|
18
25
|
}
|
|
19
26
|
|
|
20
|
-
pub fn syscall2(
|
|
27
|
+
pub fn syscall2(
|
|
28
|
+
number: SYS,
|
|
29
|
+
arg1: syscall_arg_t,
|
|
30
|
+
arg2: syscall_arg_t,
|
|
31
|
+
) u64 {
|
|
21
32
|
return asm volatile ("svc #0"
|
|
22
33
|
: [ret] "={x0}" (-> u64),
|
|
23
34
|
: [number] "{x8}" (@intFromEnum(number)),
|
|
@@ -26,7 +37,12 @@ pub fn syscall2(number: SYS, arg1: u64, arg2: u64) u64 {
|
|
|
26
37
|
: .{ .memory = true });
|
|
27
38
|
}
|
|
28
39
|
|
|
29
|
-
pub fn syscall3(
|
|
40
|
+
pub fn syscall3(
|
|
41
|
+
number: SYS,
|
|
42
|
+
arg1: syscall_arg_t,
|
|
43
|
+
arg2: syscall_arg_t,
|
|
44
|
+
arg3: syscall_arg_t,
|
|
45
|
+
) u64 {
|
|
30
46
|
return asm volatile ("svc #0"
|
|
31
47
|
: [ret] "={x0}" (-> u64),
|
|
32
48
|
: [number] "{x8}" (@intFromEnum(number)),
|
|
@@ -36,7 +52,13 @@ pub fn syscall3(number: SYS, arg1: u64, arg2: u64, arg3: u64) u64 {
|
|
|
36
52
|
: .{ .memory = true });
|
|
37
53
|
}
|
|
38
54
|
|
|
39
|
-
pub fn syscall4(
|
|
55
|
+
pub fn syscall4(
|
|
56
|
+
number: SYS,
|
|
57
|
+
arg1: syscall_arg_t,
|
|
58
|
+
arg2: syscall_arg_t,
|
|
59
|
+
arg3: syscall_arg_t,
|
|
60
|
+
arg4: syscall_arg_t,
|
|
61
|
+
) u64 {
|
|
40
62
|
return asm volatile ("svc #0"
|
|
41
63
|
: [ret] "={x0}" (-> u64),
|
|
42
64
|
: [number] "{x8}" (@intFromEnum(number)),
|
|
@@ -47,7 +69,14 @@ pub fn syscall4(number: SYS, arg1: u64, arg2: u64, arg3: u64, arg4: u64) u64 {
|
|
|
47
69
|
: .{ .memory = true });
|
|
48
70
|
}
|
|
49
71
|
|
|
50
|
-
pub fn syscall5(
|
|
72
|
+
pub fn syscall5(
|
|
73
|
+
number: SYS,
|
|
74
|
+
arg1: syscall_arg_t,
|
|
75
|
+
arg2: syscall_arg_t,
|
|
76
|
+
arg3: syscall_arg_t,
|
|
77
|
+
arg4: syscall_arg_t,
|
|
78
|
+
arg5: syscall_arg_t,
|
|
79
|
+
) u64 {
|
|
51
80
|
return asm volatile ("svc #0"
|
|
52
81
|
: [ret] "={x0}" (-> u64),
|
|
53
82
|
: [number] "{x8}" (@intFromEnum(number)),
|
|
@@ -61,12 +90,12 @@ pub fn syscall5(number: SYS, arg1: u64, arg2: u64, arg3: u64, arg4: u64, arg5: u
|
|
|
61
90
|
|
|
62
91
|
pub fn syscall6(
|
|
63
92
|
number: SYS,
|
|
64
|
-
arg1:
|
|
65
|
-
arg2:
|
|
66
|
-
arg3:
|
|
67
|
-
arg4:
|
|
68
|
-
arg5:
|
|
69
|
-
arg6:
|
|
93
|
+
arg1: syscall_arg_t,
|
|
94
|
+
arg2: syscall_arg_t,
|
|
95
|
+
arg3: syscall_arg_t,
|
|
96
|
+
arg4: syscall_arg_t,
|
|
97
|
+
arg5: syscall_arg_t,
|
|
98
|
+
arg6: syscall_arg_t,
|
|
70
99
|
) u64 {
|
|
71
100
|
return asm volatile ("svc #0"
|
|
72
101
|
: [ret] "={x0}" (-> u64),
|
package/std/os/linux/arc.zig
CHANGED
|
@@ -2,14 +2,21 @@ const builtin = @import("builtin");
|
|
|
2
2
|
const std = @import("../../std.zig");
|
|
3
3
|
const SYS = std.os.linux.SYS;
|
|
4
4
|
|
|
5
|
-
pub
|
|
5
|
+
pub const syscall_arg_t = u32;
|
|
6
|
+
|
|
7
|
+
pub fn syscall0(
|
|
8
|
+
number: SYS,
|
|
9
|
+
) u32 {
|
|
6
10
|
return asm volatile ("trap_s 0"
|
|
7
11
|
: [ret] "={r0}" (-> u32),
|
|
8
12
|
: [number] "{r8}" (@intFromEnum(number)),
|
|
9
13
|
: .{ .memory = true });
|
|
10
14
|
}
|
|
11
15
|
|
|
12
|
-
pub fn syscall1(
|
|
16
|
+
pub fn syscall1(
|
|
17
|
+
number: SYS,
|
|
18
|
+
arg1: syscall_arg_t,
|
|
19
|
+
) u32 {
|
|
13
20
|
return asm volatile ("trap_s 0"
|
|
14
21
|
: [ret] "={r0}" (-> u32),
|
|
15
22
|
: [number] "{r8}" (@intFromEnum(number)),
|
|
@@ -17,7 +24,11 @@ pub fn syscall1(number: SYS, arg1: u32) u32 {
|
|
|
17
24
|
: .{ .memory = true });
|
|
18
25
|
}
|
|
19
26
|
|
|
20
|
-
pub fn syscall2(
|
|
27
|
+
pub fn syscall2(
|
|
28
|
+
number: SYS,
|
|
29
|
+
arg1: syscall_arg_t,
|
|
30
|
+
arg2: syscall_arg_t,
|
|
31
|
+
) u32 {
|
|
21
32
|
return asm volatile ("trap_s 0"
|
|
22
33
|
: [ret] "={r0}" (-> u32),
|
|
23
34
|
: [number] "{r8}" (@intFromEnum(number)),
|
|
@@ -26,7 +37,12 @@ pub fn syscall2(number: SYS, arg1: u32, arg2: u32) u32 {
|
|
|
26
37
|
: .{ .memory = true });
|
|
27
38
|
}
|
|
28
39
|
|
|
29
|
-
pub fn syscall3(
|
|
40
|
+
pub fn syscall3(
|
|
41
|
+
number: SYS,
|
|
42
|
+
arg1: syscall_arg_t,
|
|
43
|
+
arg2: syscall_arg_t,
|
|
44
|
+
arg3: syscall_arg_t,
|
|
45
|
+
) u32 {
|
|
30
46
|
return asm volatile ("trap_s 0"
|
|
31
47
|
: [ret] "={r0}" (-> u32),
|
|
32
48
|
: [number] "{r8}" (@intFromEnum(number)),
|
|
@@ -36,7 +52,13 @@ pub fn syscall3(number: SYS, arg1: u32, arg2: u32, arg3: u32) u32 {
|
|
|
36
52
|
: .{ .memory = true });
|
|
37
53
|
}
|
|
38
54
|
|
|
39
|
-
pub fn syscall4(
|
|
55
|
+
pub fn syscall4(
|
|
56
|
+
number: SYS,
|
|
57
|
+
arg1: syscall_arg_t,
|
|
58
|
+
arg2: syscall_arg_t,
|
|
59
|
+
arg3: syscall_arg_t,
|
|
60
|
+
arg4: syscall_arg_t,
|
|
61
|
+
) u32 {
|
|
40
62
|
return asm volatile ("trap_s 0"
|
|
41
63
|
: [ret] "={r0}" (-> u32),
|
|
42
64
|
: [number] "{r8}" (@intFromEnum(number)),
|
|
@@ -47,7 +69,14 @@ pub fn syscall4(number: SYS, arg1: u32, arg2: u32, arg3: u32, arg4: u32) u32 {
|
|
|
47
69
|
: .{ .memory = true });
|
|
48
70
|
}
|
|
49
71
|
|
|
50
|
-
pub fn syscall5(
|
|
72
|
+
pub fn syscall5(
|
|
73
|
+
number: SYS,
|
|
74
|
+
arg1: syscall_arg_t,
|
|
75
|
+
arg2: syscall_arg_t,
|
|
76
|
+
arg3: syscall_arg_t,
|
|
77
|
+
arg4: syscall_arg_t,
|
|
78
|
+
arg5: syscall_arg_t,
|
|
79
|
+
) u32 {
|
|
51
80
|
return asm volatile ("trap_s 0"
|
|
52
81
|
: [ret] "={r0}" (-> u32),
|
|
53
82
|
: [number] "{r8}" (@intFromEnum(number)),
|
|
@@ -61,12 +90,12 @@ pub fn syscall5(number: SYS, arg1: u32, arg2: u32, arg3: u32, arg4: u32, arg5: u
|
|
|
61
90
|
|
|
62
91
|
pub fn syscall6(
|
|
63
92
|
number: SYS,
|
|
64
|
-
arg1:
|
|
65
|
-
arg2:
|
|
66
|
-
arg3:
|
|
67
|
-
arg4:
|
|
68
|
-
arg5:
|
|
69
|
-
arg6:
|
|
93
|
+
arg1: syscall_arg_t,
|
|
94
|
+
arg2: syscall_arg_t,
|
|
95
|
+
arg3: syscall_arg_t,
|
|
96
|
+
arg4: syscall_arg_t,
|
|
97
|
+
arg5: syscall_arg_t,
|
|
98
|
+
arg6: syscall_arg_t,
|
|
70
99
|
) u32 {
|
|
71
100
|
return asm volatile ("trap_s 0"
|
|
72
101
|
: [ret] "={r0}" (-> u32),
|