@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.
@@ -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/os/linux.zig CHANGED
@@ -887,21 +887,21 @@ pub fn getcwd(buf: [*]u8, size: usize) usize {
887
887
  return syscall2(.getcwd, @intFromPtr(buf), size);
888
888
  }
889
889
 
890
- pub fn getdents(fd: fd_t, dirp: [*]u8, len: usize) usize {
890
+ pub fn getdents(fd: fd_t, dirp: [*]u8, len: c_uint) usize {
891
891
  return syscall3(
892
892
  .getdents,
893
893
  @as(u32, @bitCast(fd)),
894
894
  @intFromPtr(dirp),
895
- @min(len, maxInt(c_int)),
895
+ len,
896
896
  );
897
897
  }
898
898
 
899
- pub fn getdents64(fd: fd_t, dirp: [*]u8, len: usize) usize {
899
+ pub fn getdents64(fd: fd_t, dirp: [*]u8, len: c_uint) usize {
900
900
  return syscall3(
901
901
  .getdents64,
902
902
  @as(u32, @bitCast(fd)),
903
903
  @intFromPtr(dirp),
904
- @min(len, maxInt(c_int)),
904
+ len,
905
905
  );
906
906
  }
907
907
 
@@ -2981,6 +2981,16 @@ pub fn map_shadow_stack(addr: usize, size: usize, flags: u32) usize {
2981
2981
  return syscall3(.map_shadow_stack, addr, size, flags);
2982
2982
  }
2983
2983
 
2984
+ pub fn tee(src: fd_t, dest: fd_t, len: usize, flags: u32) usize {
2985
+ return syscall4(
2986
+ .tee,
2987
+ @as(u32, @bitCast(src)),
2988
+ @as(u32, @bitCast(dest)),
2989
+ len,
2990
+ flags,
2991
+ );
2992
+ }
2993
+
2984
2994
  pub const Sysinfo = switch (native_abi) {
2985
2995
  .gnux32, .muslx32 => extern struct {
2986
2996
  /// Seconds since boot
package/std/os.zig CHANGED
@@ -1,4 +1,5 @@
1
1
  const builtin = @import("builtin");
2
+ const std = @import("std.zig");
2
3
  const native_os = builtin.os.tag;
3
4
 
4
5
  pub const linux = @import("os/linux.zig");
@@ -8,6 +9,46 @@ pub const wasi = @import("os/wasi.zig");
8
9
  pub const emscripten = @import("os/emscripten.zig");
9
10
  pub const windows = @import("os/windows.zig");
10
11
 
12
+ /// Returns whether the Zig standard library requires libc in order to interface
13
+ /// with the operating system on the given target.
14
+ pub fn targetRequiresLibC(target: *const std.Target) bool {
15
+ if (target.requiresLibC()) return true;
16
+ return switch (target.os.tag) {
17
+ .linux => switch (target.cpu.arch) {
18
+ // https://codeberg.org/ziglang/zig/issues/30940
19
+ .alpha,
20
+ // https://codeberg.org/ziglang/zig/issues/30942
21
+ .csky,
22
+ // https://codeberg.org/ziglang/zig/issues/30943
23
+ .hppa,
24
+ .hppa64,
25
+ // https://codeberg.org/ziglang/zig/issues/30944
26
+ .microblaze,
27
+ .microblazeel,
28
+ // https://codeberg.org/ziglang/zig/issues/30946
29
+ .sh,
30
+ .sheb,
31
+ // https://codeberg.org/ziglang/zig/issues/30945
32
+ .sparc,
33
+ // https://codeberg.org/ziglang/zig/issues/30947
34
+ .xtensa,
35
+ .xtensaeb,
36
+ => true,
37
+ else => false,
38
+ },
39
+ .freebsd => true, // https://codeberg.org/ziglang/zig/issues/30981
40
+ .netbsd => true, // https://codeberg.org/ziglang/zig/issues/30980
41
+ .openbsd => true, // https://codeberg.org/ziglang/zig/issues/30982
42
+ else => false,
43
+ };
44
+ }
45
+
46
+ /// Returns whether the Zig standard library requires libc in order to interface
47
+ /// with the operating system on the current target.
48
+ pub fn requiresLibC() bool {
49
+ return targetRequiresLibC(&builtin.target);
50
+ }
51
+
11
52
  test {
12
53
  _ = linux;
13
54
  if (native_os == .uefi) _ = uefi;
@@ -1776,11 +1776,12 @@ fn structInitExpr(
1776
1776
  }
1777
1777
 
1778
1778
  {
1779
- var sfba = std.heap.stackFallback(256, astgen.arena);
1780
- const sfba_allocator = sfba.get();
1779
+ var bfa_buf: [256]u8 = undefined;
1780
+ var bfa_state: std.heap.BufferFirstAllocator = .init(&bfa_buf, astgen.arena);
1781
+ const bfa = bfa_state.allocator();
1781
1782
 
1782
1783
  var duplicate_names: std.array_hash_map.Auto(Zir.NullTerminatedString, ArrayList(Ast.TokenIndex)) = .empty;
1783
- try duplicate_names.ensureTotalCapacity(sfba_allocator, @intCast(struct_init.ast.fields.len));
1784
+ try duplicate_names.ensureTotalCapacity(bfa, @intCast(struct_init.ast.fields.len));
1784
1785
 
1785
1786
  // When there aren't errors, use this to avoid a second iteration.
1786
1787
  var any_duplicate = false;
@@ -1789,14 +1790,14 @@ fn structInitExpr(
1789
1790
  const name_token = tree.firstToken(field) - 2;
1790
1791
  const name_index = try astgen.identAsString(name_token);
1791
1792
 
1792
- const gop = try duplicate_names.getOrPut(sfba_allocator, name_index);
1793
+ const gop = try duplicate_names.getOrPut(bfa, name_index);
1793
1794
 
1794
1795
  if (gop.found_existing) {
1795
- try gop.value_ptr.append(sfba_allocator, name_token);
1796
+ try gop.value_ptr.append(bfa, name_token);
1796
1797
  any_duplicate = true;
1797
1798
  } else {
1798
1799
  gop.value_ptr.* = .empty;
1799
- try gop.value_ptr.append(sfba_allocator, name_token);
1800
+ try gop.value_ptr.append(bfa, name_token);
1800
1801
  }
1801
1802
  }
1802
1803
 
@@ -8404,9 +8405,10 @@ fn tunnelThroughClosure(
8404
8405
 
8405
8406
  // Otherwise we need a tunnel. First, figure out the path of namespaces we
8406
8407
  // are tunneling through. This is usually only going to be one or two, so
8407
- // use an SFBA to optimize for the common case.
8408
- var sfba = std.heap.stackFallback(@sizeOf(usize) * 2, astgen.arena);
8409
- var intermediate_tunnels = try sfba.get().alloc(*Scope.Namespace, num_tunnels - 1);
8408
+ // use an BFA to optimize for the common case.
8409
+ var bfa_buf: [2]usize = undefined;
8410
+ var bfa: std.heap.BufferFirstAllocator = .init(@ptrCast(&bfa_buf), astgen.arena);
8411
+ var intermediate_tunnels = try bfa.allocator().alloc(*Scope.Namespace, num_tunnels - 1);
8410
8412
 
8411
8413
  const root_ns = ns: {
8412
8414
  var i: usize = num_tunnels - 1;
@@ -12926,17 +12928,18 @@ fn scanContainer(
12926
12928
  next: ?*@This(),
12927
12929
  };
12928
12930
 
12929
- // The maps below are allocated into this SFBA to avoid using the GPA for small namespaces.
12930
- var sfba_state = std.heap.stackFallback(512, astgen.gpa);
12931
- const sfba = sfba_state.get();
12931
+ // The maps below are allocated into this BFA to avoid using the GPA for small namespaces.
12932
+ var bfa_buf: [512]u8 = undefined;
12933
+ var bfa_state: std.heap.BufferFirstAllocator = .init(&bfa_buf, astgen.gpa);
12934
+ const bfa = bfa_state.allocator();
12932
12935
 
12933
12936
  var names: std.AutoArrayHashMapUnmanaged(Zir.NullTerminatedString, NameEntry) = .empty;
12934
12937
  var test_names: std.AutoArrayHashMapUnmanaged(Zir.NullTerminatedString, NameEntry) = .empty;
12935
12938
  var decltest_names: std.AutoArrayHashMapUnmanaged(Zir.NullTerminatedString, NameEntry) = .empty;
12936
12939
  defer {
12937
- names.deinit(sfba);
12938
- test_names.deinit(sfba);
12939
- decltest_names.deinit(sfba);
12940
+ names.deinit(bfa);
12941
+ test_names.deinit(bfa);
12942
+ decltest_names.deinit(bfa);
12940
12943
  }
12941
12944
 
12942
12945
  var any_duplicates = false;
@@ -13008,7 +13011,7 @@ fn scanContainer(
13008
13011
  else => {}, // unnamed test
13009
13012
  .string_literal => {
13010
13013
  const name = try astgen.strLitAsString(test_name_token);
13011
- const gop = try test_names.getOrPut(sfba, name.index);
13014
+ const gop = try test_names.getOrPut(bfa, name.index);
13012
13015
  if (gop.found_existing) {
13013
13016
  var e = gop.value_ptr;
13014
13017
  while (e.next) |n| e = n;
@@ -13021,7 +13024,7 @@ fn scanContainer(
13021
13024
  },
13022
13025
  .identifier => {
13023
13026
  const name = try astgen.identAsString(test_name_token);
13024
- const gop = try decltest_names.getOrPut(sfba, name);
13027
+ const gop = try decltest_names.getOrPut(bfa, name);
13025
13028
  if (gop.found_existing) {
13026
13029
  var e = gop.value_ptr;
13027
13030
  while (e.next) |n| e = n;
@@ -13048,7 +13051,7 @@ fn scanContainer(
13048
13051
  }
13049
13052
 
13050
13053
  {
13051
- const gop = try names.getOrPut(sfba, name_str_index);
13054
+ const gop = try names.getOrPut(bfa, name_str_index);
13052
13055
  const new_ent: NameEntry = .{
13053
13056
  .tok = name_token,
13054
13057
  .next = null,
@@ -427,10 +427,11 @@ fn expr(zg: *ZonGen, node: Ast.Node.Index, dest_node: Zoir.Node.Index) Allocator
427
427
  });
428
428
 
429
429
  // For short initializers, track the names on the stack rather than going through gpa.
430
- var sfba_state = std.heap.stackFallback(256, gpa);
431
- const sfba = sfba_state.get();
430
+ var bfa_buf: [256]u8 = undefined;
431
+ var bfa_state: std.heap.BufferFirstAllocator = .init(&bfa_buf, gpa);
432
+ const bfa = bfa_state.allocator();
432
433
  var field_names: std.AutoHashMapUnmanaged(Zoir.NullTerminatedString, Ast.TokenIndex) = .empty;
433
- defer field_names.deinit(sfba);
434
+ defer field_names.deinit(bfa);
434
435
 
435
436
  var reported_any_duplicate = false;
436
437
 
@@ -438,7 +439,7 @@ fn expr(zg: *ZonGen, node: Ast.Node.Index, dest_node: Zoir.Node.Index) Allocator
438
439
  const name_token = tree.firstToken(elem_node) - 2;
439
440
  if (zg.identAsString(name_token)) |name_str| {
440
441
  zg.extra.items[extra_name_idx] = @intFromEnum(name_str);
441
- const gop = try field_names.getOrPut(sfba, name_str);
442
+ const gop = try field_names.getOrPut(bfa, name_str);
442
443
  if (gop.found_existing and !reported_any_duplicate) {
443
444
  reported_any_duplicate = true;
444
445
  const earlier_token = gop.value_ptr.*;
@@ -7638,9 +7638,9 @@ pub const Constant = enum(u32) {
7638
7638
  std.math.big.int.calcToStringLimbsBufferLen(expected_limbs, 10)
7639
7639
  ]std.math.big.Limb,
7640
7640
  };
7641
- var stack align(@alignOf(ExpectedContents)) =
7642
- std.heap.stackFallback(@sizeOf(ExpectedContents), data.builder.gpa);
7643
- const allocator = stack.get();
7641
+ var bfa_buf: ExpectedContents = undefined;
7642
+ var bfa: std.heap.BufferFirstAllocator = .init(@ptrCast(&bfa_buf), data.builder.gpa);
7643
+ const allocator = bfa.allocator();
7644
7644
  const str = bigint.toStringAlloc(allocator, 10, undefined) catch return error.WriteFailed;
7645
7645
  defer allocator.free(str);
7646
7646
  try w.writeAll(str);
@@ -9209,9 +9209,9 @@ pub fn getIntrinsic(
9209
9209
  fields: [expected_fields_len]Type,
9210
9210
  },
9211
9211
  };
9212
- var stack align(@max(@alignOf(std.heap.StackFallbackAllocator(0)), @alignOf(ExpectedContents))) =
9213
- std.heap.stackFallback(@sizeOf(ExpectedContents), self.gpa);
9214
- const allocator = stack.get();
9212
+ var bfa_buf: ExpectedContents = undefined;
9213
+ var bfa: std.heap.BufferFirstAllocator = .init(@ptrCast(&bfa_buf), self.gpa);
9214
+ const allocator = bfa.allocator();
9215
9215
 
9216
9216
  const name = name: {
9217
9217
  {
@@ -10607,9 +10607,9 @@ pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void
10607
10607
  std.math.big.int.calcToStringLimbsBufferLen(expected_limbs, 10)
10608
10608
  ]std.math.big.Limb,
10609
10609
  };
10610
- var stack align(@alignOf(ExpectedContents)) =
10611
- std.heap.stackFallback(@sizeOf(ExpectedContents), self.gpa);
10612
- const allocator = stack.get();
10610
+ var bfa_buf: ExpectedContents = undefined;
10611
+ var bfa: std.heap.BufferFirstAllocator = .init(@ptrCast(&bfa_buf), self.gpa);
10612
+ const allocator = bfa.allocator();
10613
10613
 
10614
10614
  const limbs = self.metadata_limbs.items[extra.limbs_index..][0..extra.limbs_len];
10615
10615
  const bigint: std.math.big.int.Const = .{
@@ -11129,9 +11129,9 @@ fn bigIntConstAssumeCapacity(
11129
11129
  const bits = type_item.data;
11130
11130
 
11131
11131
  const ExpectedContents = [64 / @sizeOf(std.math.big.Limb)]std.math.big.Limb;
11132
- var stack align(@alignOf(ExpectedContents)) =
11133
- std.heap.stackFallback(@sizeOf(ExpectedContents), self.gpa);
11134
- const allocator = stack.get();
11132
+ var bfa_buf: ExpectedContents = undefined;
11133
+ var bfa: std.heap.BufferFirstAllocator = .init(@ptrCast(&bfa_buf), self.gpa);
11134
+ const allocator = bfa.allocator();
11135
11135
 
11136
11136
  var limbs: []std.math.big.Limb = &.{};
11137
11137
  defer allocator.free(limbs);
@@ -1,8 +0,0 @@
1
- #define _GNU_SOURCE
2
- #include <fcntl.h>
3
- #include "syscall.h"
4
-
5
- ssize_t tee(int src, int dest, size_t len, unsigned flags)
6
- {
7
- return syscall(SYS_tee, src, dest, len, flags);
8
- }
@@ -1,20 +0,0 @@
1
- #include <unistd.h>
2
- #include <errno.h>
3
- #include <fcntl.h>
4
- #include "syscall.h"
5
-
6
- int dup2(int old, int new)
7
- {
8
- int r;
9
- #ifdef SYS_dup2
10
- while ((r=__syscall(SYS_dup2, old, new))==-EBUSY);
11
- #else
12
- if (old==new) {
13
- r = __syscall(SYS_fcntl, old, F_GETFD);
14
- if (r >= 0) return old;
15
- } else {
16
- while ((r=__syscall(SYS_dup3, old, new, 0))==-EBUSY);
17
- }
18
- #endif
19
- return __syscall_ret(r);
20
- }
@@ -1,26 +0,0 @@
1
- #define _GNU_SOURCE
2
- #include <unistd.h>
3
- #include <errno.h>
4
- #include <fcntl.h>
5
- #include "syscall.h"
6
-
7
- int __dup3(int old, int new, int flags)
8
- {
9
- int r;
10
- #ifdef SYS_dup2
11
- if (old==new) return __syscall_ret(-EINVAL);
12
- if (flags) {
13
- while ((r=__syscall(SYS_dup3, old, new, flags))==-EBUSY);
14
- if (r!=-ENOSYS) return __syscall_ret(r);
15
- if (flags & ~O_CLOEXEC) return __syscall_ret(-EINVAL);
16
- }
17
- while ((r=__syscall(SYS_dup2, old, new))==-EBUSY);
18
- if (r >= 0 && (flags & O_CLOEXEC))
19
- __syscall(SYS_fcntl, new, F_SETFD, FD_CLOEXEC);
20
- #else
21
- while ((r=__syscall(SYS_dup3, old, new, flags))==-EBUSY);
22
- #endif
23
- return __syscall_ret(r);
24
- }
25
-
26
- weak_alias(__dup3, dup3);