@zigc/lib 0.17.0-dev.644 → 0.17.0-dev.657
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/compiler/Maker/ScannedConfig.zig +4 -3
- package/compiler/Maker/Step/FindProgram.zig +2 -2
- package/compiler/Maker/Watch/FsEvents.zig +3 -2
- package/compiler/aro/aro/Attribute.zig +52 -51
- package/compiler/aro/aro/Compilation.zig +5 -5
- package/compiler/aro/aro/Diagnostics.zig +7 -7
- package/compiler/aro/aro/Parser.zig +2 -2
- package/compiler/aro/aro/Tree.zig +11 -11
- package/compiler/aro/aro/features.zig +4 -4
- package/compiler/aro/aro/text_literal.zig +2 -2
- package/compiler/aro/backend/Interner.zig +14 -13
- package/compiler/configurer.zig +2 -2
- package/compiler/resinator/bmp.zig +3 -2
- package/compiler/resinator/code_pages.zig +14 -12
- package/compiler/resinator/cvtres.zig +11 -10
- package/compiler/resinator/errors.zig +18 -22
- package/compiler/resinator/lang.zig +7 -7
- package/compiler/resinator/parse.zig +1 -1
- package/compiler/translate-c/ast.zig +6 -6
- package/docs/wasm/markdown/Document.zig +3 -3
- package/docs/wasm/markdown/Parser.zig +3 -3
- package/package.json +1 -1
- package/std/Build/Cache.zig +2 -2
- package/std/Build/Configuration.zig +19 -16
- package/std/Build/Step/ConfigHeader.zig +3 -2
- package/std/Build/Step/Options.zig +28 -22
- package/std/Build.zig +52 -53
- package/std/Io/Kqueue.zig +2 -2
- package/std/Io/Reader.zig +1 -1
- package/std/Io/Threaded.zig +18 -15
- package/std/Io/Uring.zig +2 -2
- package/std/Io/Writer.zig +18 -18
- package/std/Io/net.zig +3 -1
- package/std/Io.zig +7 -6
- package/std/Progress.zig +2 -2
- package/std/Target/aarch64.zig +2 -2
- package/std/Target/alpha.zig +2 -2
- package/std/Target/amdgcn.zig +2 -2
- package/std/Target/arc.zig +2 -2
- package/std/Target/arm.zig +2 -2
- package/std/Target/avr.zig +2 -2
- package/std/Target/bpf.zig +2 -2
- package/std/Target/csky.zig +2 -2
- package/std/Target/hexagon.zig +2 -2
- package/std/Target/hppa.zig +2 -2
- package/std/Target/kvx.zig +2 -2
- package/std/Target/lanai.zig +2 -2
- package/std/Target/loongarch.zig +2 -2
- package/std/Target/m68k.zig +2 -2
- package/std/Target/mips.zig +2 -2
- package/std/Target/msp430.zig +2 -2
- package/std/Target/nvptx.zig +2 -2
- package/std/Target/powerpc.zig +2 -2
- package/std/Target/propeller.zig +2 -2
- package/std/Target/riscv.zig +2 -2
- package/std/Target/s390x.zig +2 -2
- package/std/Target/sparc.zig +2 -2
- package/std/Target/spirv.zig +2 -2
- package/std/Target/ve.zig +2 -2
- package/std/Target/wasm.zig +2 -2
- package/std/Target/x86.zig +2 -2
- package/std/Target/xcore.zig +2 -2
- package/std/Target/xtensa.zig +2 -2
- package/std/Target.zig +4 -4
- package/std/c/darwin.zig +1 -1
- package/std/coff.zig +1 -1
- package/std/crypto/codecs/asn1/Oid.zig +8 -8
- package/std/crypto/codecs/asn1/der/Decoder.zig +7 -7
- package/std/crypto/codecs/asn1/der/Encoder.zig +10 -8
- package/std/crypto/phc_encoding.zig +23 -20
- package/std/crypto/timing_safe.zig +1 -1
- package/std/crypto/tls/Client.zig +3 -3
- package/std/crypto/tls.zig +1 -1
- package/std/debug/Dwarf/Unwind/VirtualMachine.zig +11 -5
- package/std/debug/ElfFile.zig +12 -8
- package/std/debug/MachOFile.zig +2 -2
- package/std/debug/SelfInfo/MachO.zig +2 -2
- package/std/debug/SelfInfo/Windows.zig +2 -2
- package/std/elf.zig +7 -7
- package/std/enums.zig +66 -67
- package/std/gpu.zig +1 -1
- package/std/hash/auto_hash.zig +8 -8
- package/std/hash/verify.zig +3 -3
- package/std/http/Client.zig +2 -2
- package/std/json/Stringify.zig +14 -14
- package/std/json/static.zig +47 -31
- package/std/lang.zig +65 -97
- package/std/math.zig +2 -2
- package/std/mem/Allocator.zig +9 -9
- package/std/mem.zig +86 -102
- package/std/meta/trailer_flags.zig +26 -19
- package/std/meta.zig +131 -171
- package/std/multi_array_list.zig +49 -57
- package/std/os/uefi/protocol/device_path.zig +8 -7
- package/std/os/uefi/tables/boot_services.zig +1 -1
- package/std/os/windows.zig +9 -15
- package/std/start.zig +6 -6
- package/std/testing/Smith.zig +35 -21
- package/std/testing.zig +15 -15
- package/std/zig/Ast.zig +4 -4
- package/std/zig/AstGen.zig +42 -42
- package/std/zig/ErrorBundle.zig +16 -13
- package/std/zig/LibCInstallation.zig +11 -11
- package/std/zig/Parse.zig +6 -6
- package/std/zig/Zir.zig +10 -10
- package/std/zig/c_translation/helpers.zig +2 -2
- package/std/zig/llvm/BitcodeReader.zig +3 -3
- package/std/zig/llvm/Builder.zig +124 -93
- package/std/zig/llvm/bitcode_writer.zig +4 -4
- package/std/zig/system/windows.zig +11 -11
- package/std/zig/system.zig +4 -4
- package/std/zig.zig +4 -4
- package/std/zon/Serializer.zig +28 -23
- package/std/zon/parse.zig +58 -61
package/std/mem.zig
CHANGED
|
@@ -297,9 +297,13 @@ pub fn zeroes(comptime T: type) T {
|
|
|
297
297
|
return item;
|
|
298
298
|
} else {
|
|
299
299
|
var structure: T = undefined;
|
|
300
|
-
inline for (
|
|
301
|
-
|
|
302
|
-
|
|
300
|
+
inline for (
|
|
301
|
+
struct_info.field_names,
|
|
302
|
+
struct_info.field_types,
|
|
303
|
+
struct_info.field_attrs,
|
|
304
|
+
) |field_name, field_type, field_attrs| {
|
|
305
|
+
if (!field_attrs.@"comptime") {
|
|
306
|
+
@field(structure, field_name) = zeroes(field_type);
|
|
303
307
|
}
|
|
304
308
|
}
|
|
305
309
|
return structure;
|
|
@@ -321,7 +325,7 @@ pub fn zeroes(comptime T: type) T {
|
|
|
321
325
|
return null;
|
|
322
326
|
},
|
|
323
327
|
.one, .many => {
|
|
324
|
-
if (ptr_info.
|
|
328
|
+
if (ptr_info.attrs.@"allowzero") return @ptrFromInt(0);
|
|
325
329
|
@compileError("Only nullable and allowzero pointers can be set to zero.");
|
|
326
330
|
},
|
|
327
331
|
}
|
|
@@ -471,44 +475,49 @@ pub fn zeroInit(comptime T: type, init: anytype) T {
|
|
|
471
475
|
switch (@typeInfo(Init)) {
|
|
472
476
|
.@"struct" => |init_info| {
|
|
473
477
|
if (init_info.is_tuple) {
|
|
474
|
-
if (init_info.
|
|
478
|
+
if (init_info.field_names.len > struct_info.field_names.len) {
|
|
475
479
|
@compileError("Tuple initializer has more elements than there are fields in `" ++ @typeName(T) ++ "`");
|
|
476
480
|
}
|
|
477
481
|
} else {
|
|
478
|
-
inline for (init_info.
|
|
479
|
-
if (!@hasField(T,
|
|
480
|
-
@compileError("Encountered an initializer for `" ++
|
|
482
|
+
inline for (init_info.field_names) |field_name| {
|
|
483
|
+
if (!@hasField(T, field_name)) {
|
|
484
|
+
@compileError("Encountered an initializer for `" ++ field_name ++ "`, but it is not a field of " ++ @typeName(T));
|
|
481
485
|
}
|
|
482
486
|
}
|
|
483
487
|
}
|
|
484
488
|
|
|
485
489
|
var value: T = if (struct_info.layout == .@"extern") zeroes(T) else undefined;
|
|
486
490
|
|
|
487
|
-
inline for (
|
|
488
|
-
|
|
491
|
+
inline for (
|
|
492
|
+
struct_info.field_names,
|
|
493
|
+
struct_info.field_types,
|
|
494
|
+
struct_info.field_attrs,
|
|
495
|
+
0..,
|
|
496
|
+
) |f_name, f_type, f_attr, i| {
|
|
497
|
+
if (f_attr.@"comptime") {
|
|
489
498
|
continue;
|
|
490
499
|
}
|
|
491
500
|
|
|
492
|
-
if (init_info.is_tuple and init_info.
|
|
493
|
-
@field(value,
|
|
494
|
-
} else if (@hasField(@TypeOf(init),
|
|
495
|
-
switch (@typeInfo(
|
|
501
|
+
if (init_info.is_tuple and init_info.field_names.len > i) {
|
|
502
|
+
@field(value, f_name) = @field(init, init_info.field_names[i]);
|
|
503
|
+
} else if (@hasField(@TypeOf(init), f_name)) {
|
|
504
|
+
switch (@typeInfo(f_type)) {
|
|
496
505
|
.@"struct" => {
|
|
497
|
-
@field(value,
|
|
506
|
+
@field(value, f_name) = zeroInit(f_type, @field(init, f_name));
|
|
498
507
|
},
|
|
499
508
|
else => {
|
|
500
|
-
@field(value,
|
|
509
|
+
@field(value, f_name) = @field(init, f_name);
|
|
501
510
|
},
|
|
502
511
|
}
|
|
503
|
-
} else if (
|
|
504
|
-
@field(value,
|
|
512
|
+
} else if (f_attr.defaultValue(f_type)) |val| {
|
|
513
|
+
@field(value, f_name) = val;
|
|
505
514
|
} else {
|
|
506
|
-
switch (@typeInfo(
|
|
515
|
+
switch (@typeInfo(f_type)) {
|
|
507
516
|
.@"struct" => {
|
|
508
|
-
@field(value,
|
|
517
|
+
@field(value, f_name) = std.mem.zeroInit(f_type, .{});
|
|
509
518
|
},
|
|
510
519
|
else => {
|
|
511
|
-
@field(value,
|
|
520
|
+
@field(value, f_name) = std.mem.zeroes(@TypeOf(@field(value, f_name)));
|
|
512
521
|
},
|
|
513
522
|
}
|
|
514
523
|
}
|
|
@@ -867,13 +876,9 @@ fn Span(comptime T: type) type {
|
|
|
867
876
|
.many => ptr_info.sentinel() orelse @compileError("invalid type given to std.mem.span: " ++ @typeName(T)),
|
|
868
877
|
.c => 0,
|
|
869
878
|
};
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
.@"allowzero" = ptr_info.is_allowzero and ptr_info.size != .c,
|
|
874
|
-
.@"align" = ptr_info.alignment,
|
|
875
|
-
.@"addrspace" = ptr_info.address_space,
|
|
876
|
-
}, ptr_info.child, new_sentinel);
|
|
879
|
+
var attrs = ptr_info.attrs;
|
|
880
|
+
attrs.@"allowzero" = attrs.@"allowzero" and ptr_info.size != .c;
|
|
881
|
+
return @Pointer(.slice, attrs, ptr_info.child, new_sentinel);
|
|
877
882
|
},
|
|
878
883
|
else => {},
|
|
879
884
|
}
|
|
@@ -933,13 +938,9 @@ fn SliceTo(comptime T: type, comptime end: std.meta.Elem(T)) type {
|
|
|
933
938
|
.many => if (std.meta.sentinel(T)) |s| s == end else true,
|
|
934
939
|
.c => true,
|
|
935
940
|
};
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
.@"allowzero" = ptr_info.is_allowzero and ptr_info.size != .c,
|
|
940
|
-
.@"align" = ptr_info.alignment,
|
|
941
|
-
.@"addrspace" = ptr_info.address_space,
|
|
942
|
-
}, Elem, if (have_sentinel) end else null);
|
|
941
|
+
var attrs = ptr_info.attrs;
|
|
942
|
+
attrs.@"allowzero" = attrs.@"allowzero" and ptr_info.size != .c;
|
|
943
|
+
return @Pointer(.slice, attrs, Elem, if (have_sentinel) end else null);
|
|
943
944
|
},
|
|
944
945
|
else => {},
|
|
945
946
|
}
|
|
@@ -2210,19 +2211,19 @@ pub fn byteSwapAllFieldsAligned(comptime S: type, comptime a: Alignment, ptr: *a
|
|
|
2210
2211
|
.@"struct" => |struct_info| {
|
|
2211
2212
|
if (struct_info.backing_integer) |Int| {
|
|
2212
2213
|
ptr.* = @bitCast(@byteSwap(@as(Int, @bitCast(ptr.*))));
|
|
2213
|
-
} else inline for (
|
|
2214
|
-
switch (@typeInfo(
|
|
2215
|
-
.@"struct" => byteSwapAllFieldsAligned(
|
|
2216
|
-
.@"union", .array => byteSwapAllFieldsAligned(
|
|
2214
|
+
} else inline for (struct_info.field_types, struct_info.field_names, struct_info.field_attrs) |f_type, f_name, f_attr| {
|
|
2215
|
+
switch (@typeInfo(f_type)) {
|
|
2216
|
+
.@"struct" => byteSwapAllFieldsAligned(f_type, .fromByteUnits(f_attr.@"align" orelse @alignOf(f_type)), &@field(ptr, f_name)),
|
|
2217
|
+
.@"union", .array => byteSwapAllFieldsAligned(f_type, .fromByteUnits(f_attr.@"align" orelse @alignOf(f_type)), &@field(ptr, f_name)),
|
|
2217
2218
|
.@"enum" => {
|
|
2218
|
-
@field(ptr,
|
|
2219
|
+
@field(ptr, f_name) = @enumFromInt(@byteSwap(@intFromEnum(@field(ptr, f_name))));
|
|
2219
2220
|
},
|
|
2220
2221
|
.bool => {},
|
|
2221
2222
|
.float => |float_info| {
|
|
2222
|
-
@field(ptr,
|
|
2223
|
+
@field(ptr, f_name) = @bitCast(@byteSwap(@as(@Int(.unsigned, float_info.bits), @bitCast(@field(ptr, f_name)))));
|
|
2223
2224
|
},
|
|
2224
2225
|
else => {
|
|
2225
|
-
@field(ptr,
|
|
2226
|
+
@field(ptr, f_name) = @byteSwap(@field(ptr, f_name));
|
|
2226
2227
|
},
|
|
2227
2228
|
}
|
|
2228
2229
|
}
|
|
@@ -2232,9 +2233,9 @@ pub fn byteSwapAllFieldsAligned(comptime S: type, comptime a: Alignment, ptr: *a
|
|
|
2232
2233
|
@compileError("byteSwapAllFields expects an untagged union");
|
|
2233
2234
|
}
|
|
2234
2235
|
|
|
2235
|
-
const first_size = @bitSizeOf(union_info.
|
|
2236
|
-
inline for (union_info.
|
|
2237
|
-
if (@bitSizeOf(
|
|
2236
|
+
const first_size = @bitSizeOf(union_info.field_types[0]);
|
|
2237
|
+
inline for (union_info.field_types) |field_type| {
|
|
2238
|
+
if (@bitSizeOf(field_type) != first_size) {
|
|
2238
2239
|
@compileError("Unable to byte-swap unions with varying field sizes");
|
|
2239
2240
|
}
|
|
2240
2241
|
}
|
|
@@ -3940,15 +3941,8 @@ pub fn ReverseIterator(comptime T: type) type {
|
|
|
3940
3941
|
.many, .c => @compileError("expected slice or pointer to array, found '" ++ @typeName(T) ++ "'"),
|
|
3941
3942
|
}
|
|
3942
3943
|
const Element = std.meta.Elem(T);
|
|
3943
|
-
const
|
|
3944
|
-
|
|
3945
|
-
.@"volatile" = ptr.is_volatile,
|
|
3946
|
-
.@"allowzero" = ptr.is_allowzero,
|
|
3947
|
-
.@"align" = ptr.alignment,
|
|
3948
|
-
.@"addrspace" = ptr.address_space,
|
|
3949
|
-
};
|
|
3950
|
-
const Pointer = @Pointer(.many, attrs, Element, std.meta.sentinel(T));
|
|
3951
|
-
const ElementPointer = @Pointer(.one, attrs, Element, null);
|
|
3944
|
+
const Pointer = @Pointer(.many, ptr.attrs, Element, std.meta.sentinel(T));
|
|
3945
|
+
const ElementPointer = @Pointer(.one, ptr.attrs, Element, null);
|
|
3952
3946
|
return struct {
|
|
3953
3947
|
ptr: Pointer,
|
|
3954
3948
|
index: usize,
|
|
@@ -4255,7 +4249,7 @@ pub fn alignPointerOffset(ptr: anytype, align_to: usize) ?usize {
|
|
|
4255
4249
|
@compileError("expected many item pointer, got " ++ @typeName(T));
|
|
4256
4250
|
|
|
4257
4251
|
// Do nothing if the pointer is already well-aligned.
|
|
4258
|
-
if (align_to <= info.pointer.
|
|
4252
|
+
if (align_to <= info.pointer.attrs.@"align" orelse @alignOf(info.pointer.child))
|
|
4259
4253
|
return 0;
|
|
4260
4254
|
|
|
4261
4255
|
// Calculate the aligned base address with an eye out for overflow.
|
|
@@ -4309,17 +4303,14 @@ fn CopyPtrAttrs(
|
|
|
4309
4303
|
comptime child: type,
|
|
4310
4304
|
) type {
|
|
4311
4305
|
const ptr = @typeInfo(source).pointer;
|
|
4312
|
-
|
|
4313
|
-
|
|
4314
|
-
|
|
4315
|
-
|
|
4316
|
-
|
|
4317
|
-
|
|
4318
|
-
|
|
4319
|
-
|
|
4320
|
-
},
|
|
4321
|
-
.@"addrspace" = ptr.address_space,
|
|
4322
|
-
}, child, null);
|
|
4306
|
+
var attrs = ptr.attrs;
|
|
4307
|
+
if (attrs.@"align" == null) {
|
|
4308
|
+
const want = @alignOf(ptr.child);
|
|
4309
|
+
if (@alignOf(child) != want) {
|
|
4310
|
+
attrs.@"align" = want;
|
|
4311
|
+
}
|
|
4312
|
+
}
|
|
4313
|
+
return @Pointer(size, attrs, child, null);
|
|
4323
4314
|
}
|
|
4324
4315
|
|
|
4325
4316
|
fn AsBytesReturnType(comptime P: type) type {
|
|
@@ -4383,10 +4374,13 @@ test "asBytes preserves pointer attributes" {
|
|
|
4383
4374
|
const in = @typeInfo(@TypeOf(inPtr)).pointer;
|
|
4384
4375
|
const out = @typeInfo(@TypeOf(outSlice)).pointer;
|
|
4385
4376
|
|
|
4386
|
-
|
|
4387
|
-
|
|
4388
|
-
|
|
4389
|
-
try testing.expectEqual(
|
|
4377
|
+
const in_attrs = in.attrs;
|
|
4378
|
+
const out_attrs = out.attrs;
|
|
4379
|
+
|
|
4380
|
+
try testing.expectEqual(in_attrs.@"const", out_attrs.@"const");
|
|
4381
|
+
try testing.expectEqual(in_attrs.@"volatile", out_attrs.@"volatile");
|
|
4382
|
+
try testing.expectEqual(in_attrs.@"allowzero", out_attrs.@"allowzero");
|
|
4383
|
+
try testing.expectEqual(in_attrs.@"align", out_attrs.@"align");
|
|
4390
4384
|
}
|
|
4391
4385
|
|
|
4392
4386
|
/// Given any value, returns a copy of its bytes in an array.
|
|
@@ -4463,13 +4457,13 @@ test "bytesAsValue preserves pointer attributes" {
|
|
|
4463
4457
|
const inSlice = @as(*align(16) const volatile [4]u8, @ptrCast(&inArr))[0..];
|
|
4464
4458
|
const outPtr = bytesAsValue(u32, inSlice);
|
|
4465
4459
|
|
|
4466
|
-
const
|
|
4467
|
-
const
|
|
4460
|
+
const in_attrs = @typeInfo(@TypeOf(inSlice)).pointer.attrs;
|
|
4461
|
+
const out_attrs = @typeInfo(@TypeOf(outPtr)).pointer.attrs;
|
|
4468
4462
|
|
|
4469
|
-
try testing.expectEqual(
|
|
4470
|
-
try testing.expectEqual(
|
|
4471
|
-
try testing.expectEqual(
|
|
4472
|
-
try testing.expectEqual(
|
|
4463
|
+
try testing.expectEqual(in_attrs.@"const", out_attrs.@"const");
|
|
4464
|
+
try testing.expectEqual(in_attrs.@"volatile", out_attrs.@"volatile");
|
|
4465
|
+
try testing.expectEqual(in_attrs.@"allowzero", out_attrs.@"allowzero");
|
|
4466
|
+
try testing.expectEqual(in_attrs.@"align", out_attrs.@"align");
|
|
4473
4467
|
}
|
|
4474
4468
|
|
|
4475
4469
|
/// Given a pointer to an array of bytes, returns a value of the specified type backed by a
|
|
@@ -4566,13 +4560,13 @@ test "bytesAsSlice preserves pointer attributes" {
|
|
|
4566
4560
|
const inSlice = @as(*align(16) const volatile [4]u8, @ptrCast(&inArr))[0..];
|
|
4567
4561
|
const outSlice = bytesAsSlice(u16, inSlice);
|
|
4568
4562
|
|
|
4569
|
-
const
|
|
4570
|
-
const
|
|
4563
|
+
const in_attrs = @typeInfo(@TypeOf(inSlice)).pointer.attrs;
|
|
4564
|
+
const out_attrs = @typeInfo(@TypeOf(outSlice)).pointer.attrs;
|
|
4571
4565
|
|
|
4572
|
-
try testing.expectEqual(
|
|
4573
|
-
try testing.expectEqual(
|
|
4574
|
-
try testing.expectEqual(
|
|
4575
|
-
try testing.expectEqual(
|
|
4566
|
+
try testing.expectEqual(in_attrs.@"const", out_attrs.@"const");
|
|
4567
|
+
try testing.expectEqual(in_attrs.@"volatile", out_attrs.@"volatile");
|
|
4568
|
+
try testing.expectEqual(in_attrs.@"allowzero", out_attrs.@"allowzero");
|
|
4569
|
+
try testing.expectEqual(in_attrs.@"align", out_attrs.@"align");
|
|
4576
4570
|
}
|
|
4577
4571
|
|
|
4578
4572
|
test "bytesAsSlice with zero-bit element type" {
|
|
@@ -4678,25 +4672,19 @@ test "sliceAsBytes preserves pointer attributes" {
|
|
|
4678
4672
|
const inSlice = @as(*align(16) const volatile [2]u16, @ptrCast(&inArr))[0..];
|
|
4679
4673
|
const outSlice = sliceAsBytes(inSlice);
|
|
4680
4674
|
|
|
4681
|
-
const
|
|
4682
|
-
const
|
|
4675
|
+
const in_attrs = @typeInfo(@TypeOf(inSlice)).pointer.attrs;
|
|
4676
|
+
const out_attrs = @typeInfo(@TypeOf(outSlice)).pointer.attrs;
|
|
4683
4677
|
|
|
4684
|
-
try testing.expectEqual(
|
|
4685
|
-
try testing.expectEqual(
|
|
4686
|
-
try testing.expectEqual(
|
|
4687
|
-
try testing.expectEqual(
|
|
4678
|
+
try testing.expectEqual(in_attrs.@"const", out_attrs.@"const");
|
|
4679
|
+
try testing.expectEqual(in_attrs.@"volatile", out_attrs.@"volatile");
|
|
4680
|
+
try testing.expectEqual(in_attrs.@"allowzero", out_attrs.@"allowzero");
|
|
4681
|
+
try testing.expectEqual(in_attrs.@"align", out_attrs.@"align");
|
|
4688
4682
|
}
|
|
4689
4683
|
|
|
4690
4684
|
fn AbsorbSentinelReturnType(comptime Slice: type) type {
|
|
4691
4685
|
const info = @typeInfo(Slice).pointer;
|
|
4692
4686
|
assert(info.size == .slice);
|
|
4693
|
-
return @Pointer(.slice, .
|
|
4694
|
-
.@"const" = info.is_const,
|
|
4695
|
-
.@"volatile" = info.is_volatile,
|
|
4696
|
-
.@"allowzero" = info.is_allowzero,
|
|
4697
|
-
.@"addrspace" = info.address_space,
|
|
4698
|
-
.@"align" = info.alignment,
|
|
4699
|
-
}, info.child, null);
|
|
4687
|
+
return @Pointer(.slice, info.attrs, info.child, null);
|
|
4700
4688
|
}
|
|
4701
4689
|
|
|
4702
4690
|
/// If the provided slice is not sentinel terminated, do nothing and return that slice.
|
|
@@ -4949,13 +4937,9 @@ test "freeing empty string with null-terminated sentinel" {
|
|
|
4949
4937
|
/// all other pointer attributes copied from `AttributeSource`.
|
|
4950
4938
|
fn AlignedSlice(comptime AttributeSource: type, comptime new_alignment: usize) type {
|
|
4951
4939
|
const ptr = @typeInfo(AttributeSource).pointer;
|
|
4952
|
-
|
|
4953
|
-
|
|
4954
|
-
|
|
4955
|
-
.@"allowzero" = ptr.is_allowzero,
|
|
4956
|
-
.@"align" = new_alignment,
|
|
4957
|
-
.@"addrspace" = ptr.address_space,
|
|
4958
|
-
}, ptr.child, null);
|
|
4940
|
+
var attrs = ptr.attrs;
|
|
4941
|
+
attrs.@"align" = new_alignment;
|
|
4942
|
+
return @Pointer(.slice, attrs, ptr.child, null);
|
|
4959
4943
|
}
|
|
4960
4944
|
|
|
4961
4945
|
/// Returns the largest slice in the given bytes that conforms to the new alignment,
|
|
@@ -14,7 +14,7 @@ pub fn TrailerFlags(comptime Fields: type) type {
|
|
|
14
14
|
bits: Int,
|
|
15
15
|
|
|
16
16
|
pub const Int = @Int(.unsigned, bit_count);
|
|
17
|
-
pub const bit_count = @typeInfo(Fields).@"struct".
|
|
17
|
+
pub const bit_count = @typeInfo(Fields).@"struct".field_names.len;
|
|
18
18
|
|
|
19
19
|
pub const FieldEnum = std.meta.FieldEnum(Fields);
|
|
20
20
|
|
|
@@ -22,11 +22,18 @@ pub fn TrailerFlags(comptime Fields: type) type {
|
|
|
22
22
|
pub const FieldValues = blk: {
|
|
23
23
|
var field_names: [bit_count][]const u8 = undefined;
|
|
24
24
|
var field_types: [bit_count]type = undefined;
|
|
25
|
-
var field_attrs: [bit_count]std.builtin.Type.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
var field_attrs: [bit_count]std.builtin.Type.Struct.FieldAttributes = undefined;
|
|
26
|
+
const fields_info = @typeInfo(Fields).@"struct";
|
|
27
|
+
for (
|
|
28
|
+
fields_info.field_names,
|
|
29
|
+
fields_info.field_types,
|
|
30
|
+
&field_names,
|
|
31
|
+
&field_types,
|
|
32
|
+
&field_attrs,
|
|
33
|
+
) |field_name, field_type, *new_name, *NewType, *new_attrs| {
|
|
34
|
+
new_name.* = field_name;
|
|
35
|
+
NewType.* = ?field_type;
|
|
36
|
+
const default: ?field_type = null;
|
|
30
37
|
new_attrs.* = .{ .default_value_ptr = &default };
|
|
31
38
|
}
|
|
32
39
|
break :blk @Struct(.auto, null, &field_names, &field_types, &field_attrs);
|
|
@@ -53,8 +60,8 @@ pub fn TrailerFlags(comptime Fields: type) type {
|
|
|
53
60
|
/// `fields` is a boolean struct where each active field is set to `true`
|
|
54
61
|
pub fn init(fields: ActiveFields) Self {
|
|
55
62
|
var self: Self = .{ .bits = 0 };
|
|
56
|
-
inline for (@typeInfo(Fields).@"struct".
|
|
57
|
-
if (@field(fields,
|
|
63
|
+
inline for (@typeInfo(Fields).@"struct".field_names, 0..) |field_name, i| {
|
|
64
|
+
if (@field(fields, field_name))
|
|
58
65
|
self.bits |= 1 << i;
|
|
59
66
|
}
|
|
60
67
|
return self;
|
|
@@ -62,8 +69,8 @@ pub fn TrailerFlags(comptime Fields: type) type {
|
|
|
62
69
|
|
|
63
70
|
/// `fields` is a struct with each field set to an optional value
|
|
64
71
|
pub fn setMany(self: Self, p: [*]align(@alignOf(Fields)) u8, fields: FieldValues) void {
|
|
65
|
-
inline for (@typeInfo(Fields).@"struct".
|
|
66
|
-
if (@field(fields,
|
|
72
|
+
inline for (@typeInfo(Fields).@"struct".field_names, 0..) |field_name, i| {
|
|
73
|
+
if (@field(fields, field_name)) |value|
|
|
67
74
|
self.set(p, @as(FieldEnum, @enumFromInt(i)), value);
|
|
68
75
|
}
|
|
69
76
|
}
|
|
@@ -93,30 +100,30 @@ pub fn TrailerFlags(comptime Fields: type) type {
|
|
|
93
100
|
|
|
94
101
|
pub fn offset(self: Self, comptime field: FieldEnum) usize {
|
|
95
102
|
var off: usize = 0;
|
|
96
|
-
inline for (@typeInfo(Fields).@"struct".
|
|
103
|
+
inline for (@typeInfo(Fields).@"struct".field_types, 0..) |field_type, i| {
|
|
97
104
|
const active = (self.bits & (1 << i)) != 0;
|
|
98
105
|
if (i == @intFromEnum(field)) {
|
|
99
106
|
assert(active);
|
|
100
|
-
return mem.alignForward(usize, off, @alignOf(
|
|
107
|
+
return mem.alignForward(usize, off, @alignOf(field_type));
|
|
101
108
|
} else if (active) {
|
|
102
|
-
off = mem.alignForward(usize, off, @alignOf(
|
|
103
|
-
off += @sizeOf(
|
|
109
|
+
off = mem.alignForward(usize, off, @alignOf(field_type));
|
|
110
|
+
off += @sizeOf(field_type);
|
|
104
111
|
}
|
|
105
112
|
}
|
|
106
113
|
}
|
|
107
114
|
|
|
108
115
|
pub fn Field(comptime field: FieldEnum) type {
|
|
109
|
-
return @typeInfo(Fields).@"struct".
|
|
116
|
+
return @typeInfo(Fields).@"struct".field_types[@intFromEnum(field)];
|
|
110
117
|
}
|
|
111
118
|
|
|
112
119
|
pub fn sizeInBytes(self: Self) usize {
|
|
113
120
|
var off: usize = 0;
|
|
114
|
-
inline for (@typeInfo(Fields).@"struct".
|
|
115
|
-
if (@sizeOf(
|
|
121
|
+
inline for (@typeInfo(Fields).@"struct".field_types, 0..) |field_type, i| {
|
|
122
|
+
if (@sizeOf(field_type) == 0)
|
|
116
123
|
continue;
|
|
117
124
|
if ((self.bits & (1 << i)) != 0) {
|
|
118
|
-
off = mem.alignForward(usize, off, @alignOf(
|
|
119
|
-
off += @sizeOf(
|
|
125
|
+
off = mem.alignForward(usize, off, @alignOf(field_type));
|
|
126
|
+
off += @sizeOf(field_type);
|
|
120
127
|
}
|
|
121
128
|
}
|
|
122
129
|
return off;
|