@zigc/lib 0.17.0-dev.76 → 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 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
+ }
@@ -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 sf = std.heap.stackFallback(1024, c.comp.gpa);
58
- const allocator = sf.get();
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 sf = std.heap.stackFallback(1024, comp.gpa);
1765
- const allocator = sf.get();
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 stack_fallback = std.heap.stackFallback(path_buf_stack_limit, comp.gpa);
1980
- const sfa = stack_fallback.get();
1981
- const header_path = try std.fmt.allocPrint(sfa, format, args);
1982
- defer sfa.free(header_path);
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 stack_fallback = std.heap.stackFallback(path_buf_stack_limit, comp.gpa);
2072
- const sf_allocator = stack_fallback.get();
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(sf_allocator, &.{ dir, filename });
2078
- defer sf_allocator.free(path);
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(sf_allocator, &.{ embed_dir, filename });
2093
- defer sf_allocator.free(path);
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 sf = std.heap.stackFallback(1024, d.comp.gpa);
951
- var allocating: std.Io.Writer.Allocating = .init(sf.get());
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 sf = std.heap.stackFallback(1024, d.comp.gpa);
960
- var allocating: std.Io.Writer.Allocating = .init(sf.get());
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 sf = std.heap.stackFallback(1024, d.comp.gpa);
1105
- var allocating: std.Io.Writer.Allocating = .init(sf.get());
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;
@@ -215,8 +215,9 @@ fn checkIdentifierCodepointWarnings(p: *Parser, codepoint: u21, loc: Source.Loca
215
215
  assert(codepoint >= 0x80);
216
216
 
217
217
  const prev_total = p.diagnostics.total;
218
- var sf = std.heap.stackFallback(1024, p.comp.gpa);
219
- var allocating: std.Io.Writer.Allocating = .init(sf.get());
218
+ var bfa_buf: [1024]u8 = undefined;
219
+ var bfa: std.heap.BufferFirstAllocator = .init(&bfa_buf, p.comp.gpa);
220
+ var allocating: std.Io.Writer.Allocating = .init(bfa.allocator());
220
221
  defer allocating.deinit();
221
222
 
222
223
  if (!char_info.isC99IdChar(codepoint)) {
@@ -429,8 +430,9 @@ pub fn err(p: *Parser, tok_i: TokenIndex, diagnostic: Diagnostic, args: anytype)
429
430
  if (diagnostic.suppress_unless_version) |some| if (!p.comp.langopts.standard.atLeast(some)) return;
430
431
  if (p.diagnostics.effectiveKind(diagnostic) == .off) return;
431
432
 
432
- var sf = std.heap.stackFallback(1024, p.comp.gpa);
433
- var allocating: std.Io.Writer.Allocating = .init(sf.get());
433
+ var bfa_buf: [1024]u8 = undefined;
434
+ var bfa: std.heap.BufferFirstAllocator = .init(&bfa_buf, p.comp.gpa);
435
+ var allocating: std.Io.Writer.Allocating = .init(bfa.allocator());
434
436
  defer allocating.deinit();
435
437
 
436
438
  p.formatArgs(&allocating.writer, diagnostic.fmt, args) catch return error.OutOfMemory;
@@ -1537,8 +1539,9 @@ fn staticAssert(p: *Parser) Error!bool {
1537
1539
  }
1538
1540
  } else {
1539
1541
  if (!res.val.toBool(p.comp)) {
1540
- var sf = std.heap.stackFallback(1024, gpa);
1541
- var allocating: std.Io.Writer.Allocating = .init(sf.get());
1542
+ var bfa_buf: [1024]u8 = undefined;
1543
+ var bfa: std.heap.BufferFirstAllocator = .init(&bfa_buf, gpa);
1544
+ var allocating: std.Io.Writer.Allocating = .init(bfa.allocator());
1542
1545
  defer allocating.deinit();
1543
1546
 
1544
1547
  if (p.staticAssertMessage(res_node, str, &allocating) catch return error.OutOfMemory) |message| {
@@ -4837,8 +4840,9 @@ fn gnuAsmStmt(p: *Parser, quals: Tree.GNUAssemblyQualifiers, asm_tok: TokenIndex
4837
4840
  const expected_items = 8; // arbitrarily chosen, most assembly will have fewer than 8 inputs/outputs/constraints/names
4838
4841
  const bytes_needed = expected_items * @sizeOf(Tree.Node.AsmStmt.Operand) + expected_items * 2 * @sizeOf(Node.Index);
4839
4842
 
4840
- var stack_fallback = std.heap.stackFallback(bytes_needed, gpa);
4841
- const allocator = stack_fallback.get();
4843
+ var bfa_buf: [bytes_needed]u8 = undefined;
4844
+ var bfa: std.heap.BufferFirstAllocator = .init(&bfa_buf, gpa);
4845
+ const allocator = bfa.allocator();
4842
4846
 
4843
4847
  var operands: std.ArrayList(Tree.Node.AsmStmt.Operand) = .empty;
4844
4848
  defer operands.deinit(allocator);
@@ -9922,8 +9926,9 @@ fn primaryExpr(p: *Parser) Error!?Result {
9922
9926
  if (p.func.pretty_ident) |some| {
9923
9927
  qt = some.qt;
9924
9928
  } else if (p.func.qt) |func_qt| {
9925
- var sf = std.heap.stackFallback(1024, gpa);
9926
- var allocating: std.Io.Writer.Allocating = .init(sf.get());
9929
+ var bfa_buf: [1024]u8 = undefined;
9930
+ var bfa: std.heap.BufferFirstAllocator = .init(&bfa_buf, gpa);
9931
+ var allocating: std.Io.Writer.Allocating = .init(bfa.allocator());
9927
9932
  defer allocating.deinit();
9928
9933
 
9929
9934
  func_qt.printNamed(p.tokSlice(p.func.name), p.comp, &allocating.writer) catch return error.OutOfMemory;
@@ -10212,8 +10217,9 @@ fn charLiteral(p: *Parser) Error!?Result {
10212
10217
  };
10213
10218
 
10214
10219
  const max_chars_expected = 4;
10215
- var sf = std.heap.stackFallback(max_chars_expected * @sizeOf(u32), gpa);
10216
- const allocator = sf.get();
10220
+ var bfa_buf: [max_chars_expected]u32 = undefined;
10221
+ var bfa: std.heap.BufferFirstAllocator = .init(@ptrCast(&bfa_buf), gpa);
10222
+ const allocator = bfa.allocator();
10217
10223
  var chars: std.ArrayList(u32) = .empty;
10218
10224
  defer chars.deinit(allocator);
10219
10225
 
@@ -212,8 +212,9 @@ pub const Diagnostic = struct {
212
212
  };
213
213
 
214
214
  pub fn err(pp: *Preprocessor, tok_i: TokenIndex, diagnostic: Diagnostic, args: anytype) Compilation.Error!void {
215
- var sf = std.heap.stackFallback(1024, pp.comp.gpa);
216
- var allocating: std.Io.Writer.Allocating = .init(sf.get());
215
+ var buf: [1024]u8 = undefined;
216
+ var bfa: std.heap.BufferFirstAllocator = .init(&buf, pp.comp.gpa);
217
+ var allocating: std.Io.Writer.Allocating = .init(bfa.allocator());
217
218
  defer allocating.deinit();
218
219
 
219
220
  Diagnostics.formatArgs(&allocating.writer, diagnostic.fmt, args) catch return error.OutOfMemory;
@@ -1023,8 +1023,9 @@ fn err(pp: *Preprocessor, loc: anytype, diagnostic: Diagnostic, args: anytype) C
1023
1023
  defer pp.diagnostics.state.suppress_system_headers = old_suppress_system;
1024
1024
  if (diagnostic.show_in_system_headers) pp.diagnostics.state.suppress_system_headers = false;
1025
1025
 
1026
- var sf = std.heap.stackFallback(1024, pp.comp.gpa);
1027
- var allocating: std.Io.Writer.Allocating = .init(sf.get());
1026
+ var bfa_buf: [1024]u8 = undefined;
1027
+ var bfa: std.heap.BufferFirstAllocator = .init(&bfa_buf, pp.comp.gpa);
1028
+ var allocating: std.Io.Writer.Allocating = .init(bfa.allocator());
1028
1029
  defer allocating.deinit();
1029
1030
 
1030
1031
  Diagnostics.formatArgs(&allocating.writer, diagnostic.fmt, args) catch return error.OutOfMemory;
@@ -1052,8 +1053,9 @@ fn err(pp: *Preprocessor, loc: anytype, diagnostic: Diagnostic, args: anytype) C
1052
1053
  }
1053
1054
 
1054
1055
  fn fatal(pp: *Preprocessor, raw: RawToken, comptime fmt: []const u8, args: anytype) Compilation.Error {
1055
- var sf = std.heap.stackFallback(1024, pp.comp.gpa);
1056
- var allocating: std.Io.Writer.Allocating = .init(sf.get());
1056
+ var bfa_buf: [1024]u8 = undefined;
1057
+ var bfa: std.heap.BufferFirstAllocator = .init(&bfa_buf, pp.comp.gpa);
1058
+ var allocating: std.Io.Writer.Allocating = .init(bfa.allocator());
1057
1059
  defer allocating.deinit();
1058
1060
 
1059
1061
  Diagnostics.formatArgs(&allocating.writer, fmt, args) catch return error.OutOfMemory;
@@ -1074,8 +1076,9 @@ fn fatalNotFound(pp: *Preprocessor, tok: TokenWithExpansionLocs, filename: []con
1074
1076
  pp.diagnostics.state.fatal_errors = true;
1075
1077
  defer pp.diagnostics.state.fatal_errors = old;
1076
1078
 
1077
- var sf = std.heap.stackFallback(1024, pp.comp.gpa);
1078
- const allocator = sf.get();
1079
+ var bfa_buf: [1024]u8 = undefined;
1080
+ var bfa: std.heap.BufferFirstAllocator = .init(&bfa_buf, pp.comp.gpa);
1081
+ const allocator = bfa.allocator();
1079
1082
  var buf: std.ArrayList(u8) = .empty;
1080
1083
  defer buf.deinit(allocator);
1081
1084
 
@@ -44,8 +44,9 @@ fn preprocessorHandler(_: *Pragma, pp: *Preprocessor, start_idx: TokenIndex) Pra
44
44
 
45
45
  const diagnostic: Pragma.Diagnostic = .pragma_message;
46
46
 
47
- var sf = std.heap.stackFallback(1024, pp.comp.gpa);
48
- var allocating: std.Io.Writer.Allocating = .init(sf.get());
47
+ var bfa_buf: [1024]u8 = undefined;
48
+ var bfa: std.heap.BufferFirstAllocator = .init(&bfa_buf, pp.comp.gpa);
49
+ var allocating: std.Io.Writer.Allocating = .init(bfa.allocator());
49
50
  defer allocating.deinit();
50
51
 
51
52
  Diagnostics.formatArgs(&allocating.writer, diagnostic.fmt, .{str}) catch return error.OutOfMemory;
@@ -315,8 +315,9 @@ pub const Parser = struct {
315
315
  if (p.errored) return;
316
316
  if (p.comp.diagnostics.effectiveKind(diagnostic) == .off) return;
317
317
 
318
- var sf = std.heap.stackFallback(1024, p.comp.gpa);
319
- var allocating: std.Io.Writer.Allocating = .init(sf.get());
318
+ var bfa_buf: [1024]u8 = undefined;
319
+ var bfa: std.heap.BufferFirstAllocator = .init(&bfa_buf, p.comp.gpa);
320
+ var allocating: std.Io.Writer.Allocating = .init(bfa.allocator());
320
321
  defer allocating.deinit();
321
322
 
322
323
  formatArgs(&allocating.writer, diagnostic.fmt, args) catch return error.OutOfMemory;
@@ -68,8 +68,9 @@ fn serializeFloat(comptime T: type, value: T, w: *std.Io.Writer) !void {
68
68
  pub fn todo(c: *AsmCodeGen, msg: []const u8, tok: Tree.TokenIndex) Error {
69
69
  const loc: Source.Location = c.tree.tokens.items(.loc)[tok];
70
70
 
71
- var sf = std.heap.stackFallback(1024, c.comp.gpa);
72
- const allocator = sf.get();
71
+ var bfa_buf: [u8]1024 = undefined;
72
+ var bfa: std.heap.BufferFirstAllocator = .init(&bfa_buf, c.comp.gpa);
73
+ const allocator = bfa.allocator();
73
74
  var buf: std.ArrayList(u8) = .empty;
74
75
  defer buf.deinit(allocator);
75
76
 
@@ -57,9 +57,10 @@ fn fixLastLimb(out_ptr: [*]u64, is_signed: bool, bits: u16) void {
57
57
  if (limb_cnt == true_limb_cnt) return;
58
58
  const true_out = out_ptr[0..true_limb_cnt];
59
59
 
60
- const sign: u64 = if (!is_signed or @as(i64, @bitCast(true_out[limb_cnt - 1])) >= 0) 0 else ~@as(u64, 0);
60
+ const ms = limbGet(true_out, limb_cnt - 1);
61
+ const sign: u64 = if (!is_signed or @as(i64, @bitCast(ms)) >= 0) 0 else ~@as(u64, 0);
61
62
  for (limb_cnt..true_limb_cnt) |i| {
62
- true_out[i] = sign;
63
+ limbSet(true_out, i, sign);
63
64
  }
64
65
  }
65
66
 
@@ -152,10 +153,6 @@ fn test__addo_limb64(comptime T: type, a: T, b: T, expected: struct { T, bool })
152
153
  }
153
154
 
154
155
  test __addo_limb64 {
155
- if (builtin.cpu.arch == .aarch64_be) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31905
156
- if (builtin.cpu.arch == .mips64) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31905
157
- if (builtin.cpu.arch == .powerpc64) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31905
158
-
159
156
  try test__addo_limb64(u64, 1, 2, .{ 3, false });
160
157
  try test__addo_limb64(u64, maxInt(u64), 2, .{ 1, true });
161
158
  try test__addo_limb64(u65, maxInt(u65), 2, .{ 1, true });
@@ -232,10 +229,6 @@ fn test__subo_limb64(comptime T: type, a: T, b: T, expected: struct { T, bool })
232
229
  }
233
230
 
234
231
  test __subo_limb64 {
235
- if (builtin.cpu.arch == .aarch64_be) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31905
236
- if (builtin.cpu.arch == .mips64) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31905
237
- if (builtin.cpu.arch == .powerpc64) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31905
238
-
239
232
  try test__subo_limb64(u64, 3, 2, .{ 1, false });
240
233
  try test__subo_limb64(u64, 0, 1, .{ maxInt(u64), true });
241
234
  try test__subo_limb64(u65, 0, 1, .{ maxInt(u65), true });
@@ -485,10 +478,6 @@ fn test__not_limb64(comptime T: type, a: T, expected: T) !void {
485
478
  }
486
479
 
487
480
  test __not_limb64 {
488
- if (builtin.cpu.arch == .aarch64_be) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31905
489
- if (builtin.cpu.arch == .mips64) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31905
490
- if (builtin.cpu.arch == .powerpc64) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31905
491
-
492
481
  try test__not_limb64(u64, 1, maxInt(u64) - 1);
493
482
  try test__not_limb64(u64, 3, maxInt(u64) - 3);
494
483
  try test__not_limb64(u65, maxInt(u65), 0);
@@ -567,10 +556,6 @@ fn test__shlo_limb64(comptime T: type, a: T, shift: u16, expected: struct { T, b
567
556
  }
568
557
 
569
558
  test __shlo_limb64 {
570
- if (builtin.cpu.arch == .aarch64_be) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31905
571
- if (builtin.cpu.arch == .mips64) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31905
572
- if (builtin.cpu.arch == .powerpc64) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31905
573
-
574
559
  try test__shlo_limb64(u64, 0x1234_5678_9ABC_DEF0, 4, .{ 0x2345_6789_ABCD_EF00, true });
575
560
  try test__shlo_limb64(u64, 0x8000_0000_0000_0001, 63, .{ 0x8000_0000_0000_0000, true });
576
561
  try test__shlo_limb64(u65, 1, 64, .{ 0x1_0000_0000_0000_0000, false });
@@ -647,10 +632,6 @@ fn test__shr_limb64(comptime T: type, a: T, shift: u16, expected: T) !void {
647
632
  }
648
633
 
649
634
  test __shr_limb64 {
650
- if (builtin.cpu.arch == .aarch64_be) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31905
651
- if (builtin.cpu.arch == .mips64) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31905
652
- if (builtin.cpu.arch == .powerpc64) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31905
653
-
654
635
  try test__shr_limb64(u64, 0x1234_5678_9ABC_DEF0, 4, 0x0123_4567_89AB_CDEF);
655
636
  try test__shr_limb64(u64, 0x8000_0000_0000_0001, 63, 1);
656
637
  try test__shr_limb64(u65, 0x1_0000_0000_0000_0000, 64, 1);
@@ -878,10 +859,6 @@ fn test__bitreverse_limb64(comptime T: type, a: T, expected: T) !void {
878
859
  }
879
860
 
880
861
  test __bitreverse_limb64 {
881
- if (builtin.cpu.arch == .aarch64_be) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31905
882
- if (builtin.cpu.arch == .mips64) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31905
883
- if (builtin.cpu.arch == .powerpc64) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31905
884
-
885
862
  try test__bitreverse_limb64(u64, 1 << 7, 1 << 56);
886
863
  try test__bitreverse_limb64(u65, 1 << 64, 1);
887
864
  try test__bitreverse_limb64(u65, 1 << 9, 1 << 55);
@@ -934,10 +911,6 @@ fn test__byteswap_limb64(comptime T: type, a: T, expected: T) !void {
934
911
  }
935
912
 
936
913
  test __byteswap_limb64 {
937
- if (builtin.cpu.arch == .aarch64_be) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31905
938
- if (builtin.cpu.arch == .mips64) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31905
939
- if (builtin.cpu.arch == .powerpc64) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31905
940
-
941
914
  try test__byteswap_limb64(u64, 0x0123_4567_89AB_CDEF, 0xEFCD_AB89_6745_2301);
942
915
  try test__byteswap_limb64(u72, 0x01_23_45_67_89_AB_CD_EF_11, 0x11_EF_CD_AB_89_67_45_23_01);
943
916
  try test__byteswap_limb64(u128, 1 << 72, 1 << 48);
@@ -1064,10 +1037,6 @@ fn test__mulo_limb64(comptime T: type, a: T, b: T, expected: struct { T, bool })
1064
1037
  }
1065
1038
 
1066
1039
  test __mulo_limb64 {
1067
- if (builtin.cpu.arch == .aarch64_be) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31905
1068
- if (builtin.cpu.arch == .mips64) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31905
1069
- if (builtin.cpu.arch == .powerpc64) return error.SkipZigTest; // https://codeberg.org/ziglang/zig/issues/31905
1070
-
1071
1040
  try test__mulo_limb64(u64, 3, 5, .{ 15, false });
1072
1041
  try test__mulo_limb64(u64, maxInt(u64), 2, .{ maxInt(u64) - 1, true });
1073
1042
  try test__mulo_limb64(u65, 1 << 32, 1 << 32, .{ 1 << 64, false });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zigc/lib",
3
- "version": "0.17.0-dev.76",
3
+ "version": "0.17.0-dev.87",
4
4
  "description": "Zig standard library and libc headers (shared across all platforms)",
5
5
  "repository": {
6
6
  "type": "git",
@@ -5484,7 +5484,7 @@ fn dirReadLinux(userdata: ?*anyopaque, dr: *Dir.Reader, buffer: []Dir.Entry) Dir
5484
5484
  }
5485
5485
  const syscall: Syscall = try .start();
5486
5486
  const n = while (true) {
5487
- const rc = linux.getdents64(dr.dir.handle, dr.buffer.ptr, dr.buffer.len);
5487
+ const rc = linux.getdents64(dr.dir.handle, dr.buffer.ptr, @min(dr.buffer.len, std.math.maxInt(c_uint)));
5488
5488
  switch (linux.errno(rc)) {
5489
5489
  .SUCCESS => {
5490
5490
  syscall.finish();
package/std/Io/Uring.zig CHANGED
@@ -3070,7 +3070,7 @@ fn dirRead(userdata: ?*anyopaque, dr: *Dir.Reader, buffer: []Dir.Entry) Dir.Read
3070
3070
  }
3071
3071
  const n = while (true) {
3072
3072
  try sync.cancel_region.await(.nothing);
3073
- const rc = linux.getdents64(dr.dir.handle, dr.buffer.ptr, dr.buffer.len);
3073
+ const rc = linux.getdents64(dr.dir.handle, dr.buffer.ptr, @min(dr.buffer.len, std.math.maxInt(c_uint)));
3074
3074
  switch (linux.errno(rc)) {
3075
3075
  .SUCCESS => break rc,
3076
3076
  .INTR => {},
package/std/debug.zig CHANGED
@@ -1197,8 +1197,9 @@ fn printSourceAtAddress(
1197
1197
 
1198
1198
  // Initialize the symbol array with space for at least one element, allocating this on the stack
1199
1199
  // in the common case where only one element is needed
1200
- var symbol_fallback_allocator = std.heap.stackFallback(@sizeOf(Symbol) + @alignOf(Symbol) - 1, getDebugInfoAllocator());
1201
- const symbol_allocator = symbol_fallback_allocator.get();
1200
+ var buf: [1]Symbol = undefined;
1201
+ var bfa: std.heap.BufferFirstAllocator = .init(@ptrCast(&buf), getDebugInfoAllocator());
1202
+ const symbol_allocator = bfa.allocator();
1202
1203
  var symbols = std.ArrayList(Symbol).initCapacity(symbol_allocator, 1) catch unreachable;
1203
1204
  defer symbols.deinit(symbol_allocator);
1204
1205
 
package/std/fs/path.zig CHANGED
@@ -894,8 +894,9 @@ pub fn resolve(allocator: Allocator, paths: []const []const u8) Allocator.Error!
894
894
  pub fn resolveWindows(allocator: Allocator, paths: []const []const u8) Allocator.Error![]u8 {
895
895
  // Avoid heap allocation when paths.len is <= @bitSizeOf(usize) * 2
896
896
  // (we use `* 3` because stackFallback uses 1 usize as a length)
897
- var bit_set_allocator_state = std.heap.stackFallback(@sizeOf(usize) * 3, allocator);
898
- const bit_set_allocator = bit_set_allocator_state.get();
897
+ var buf: [3]usize = undefined;
898
+ var bit_set_allocator_state: std.heap.BufferFirstAllocator = .init(@ptrCast(&buf), allocator);
899
+ const bit_set_allocator = bit_set_allocator_state.allocator();
899
900
  var relevant_paths = try std.bit_set.DynamicBitSetUnmanaged.initEmpty(bit_set_allocator, paths.len);
900
901
  defer relevant_paths.deinit(bit_set_allocator);
901
902
 
@@ -1642,7 +1643,8 @@ fn windowsResolveAgainstCwd(
1642
1643
  parsed: WindowsPath2(u8),
1643
1644
  ) ![]u8 {
1644
1645
  // Space for 256 WTF-16 code units; potentially 3 WTF-8 bytes per WTF-16 code unit
1645
- var temp_allocator_state = std.heap.stackFallback(256 * 3, gpa);
1646
+ var buf: [256 * 3]u8 = undefined;
1647
+ var temp_allocator_state: std.heap.BufferFirstAllocator = .init(&buf, gpa);
1646
1648
  return switch (parsed.kind) {
1647
1649
  .drive_absolute,
1648
1650
  .unc_absolute,
@@ -1668,7 +1670,7 @@ fn windowsResolveAgainstCwd(
1668
1670
  }
1669
1671
  },
1670
1672
  .drive_relative => blk: {
1671
- const temp_allocator = temp_allocator_state.get();
1673
+ const temp_allocator = temp_allocator_state.allocator();
1672
1674
  const drive_cwd = drive_cwd: {
1673
1675
  const parsed_cwd = parsePathWindows(u8, cwd);
1674
1676
 
@@ -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
@@ -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
- }