zig/lib/std
Michael Bartnett 31a2b8c364
std: Handle field struct defaults in std.mem.zeroInit
I originally started monkeying with this because std.mem.zeroes doesn't support sentinel-terminated const slices even with defaults in 0.10.x.

I see that std.mem.zeroes was modified in #13256 to allow setting these slices to "".

That got me partway to where I wanted, but there was still an issue fields whose types are structs, they wouldn't get their defaults.

So when iterating struct fields looking for default values, when there is no default value and the type is .Struct, it will delegate to a call to zeroInit.

* Initialize struct fields in zeroInit exactly once

In my changes, similar to the previous implementation, the priority order for fields being initialized is:

1. If the `init` argument is a tuple, the nth element corresponding to the nth field of the struct.
2. Otherwise, if the `init` argument is not a tuple, try to find a matching field name on `init` and use that field.
3. Is the field has a default value, initalize with that value.
4. Fall back to what the field would have been initialized to via a recursive call to `std.mem.zeroInit`.

But instead of initializing a default instance of the struct and then running multiple passes over it, the init method is chosen per-field and each field is initialized exactly once.
2023-01-16 14:24:47 +02:00
..
atomic
build zig build: add Artifact.installHeadersDirectory 2023-01-11 15:39:49 -08:00
c Merge pull request #13980 from ziglang/std.net 2023-01-03 02:43:50 -05:00
compress water cooler complaint about gzip stream namespace 2023-01-11 15:39:48 -08:00
crypto std.crypto.Certificate.Bundle: add more Linux directories 2023-01-15 15:01:42 -07:00
dwarf
event std: collect all options under one namespace 2023-01-05 02:31:29 -07:00
fmt Fix buffer overflow in fmt when DAZ is set 2023-01-13 16:45:10 +02:00
fs Fix cache-dir specified on the command line (#14076) 2023-01-05 01:37:00 -08:00
hash std.builtin: rename Type.UnionField and Type.StructField's field_type to type 2022-12-17 14:11:33 +01:00
heap Implements std.ArenaAllocator.reset() (#12590) 2023-01-03 15:15:20 -05:00
http fix build failures on 32-bit arm due to u64/usize coercion 2023-01-11 15:39:49 -08:00
io fix std.io.Reader regression 2023-01-11 15:39:49 -08:00
json
math cbe: all behaviour tests now pass on msvc 2023-01-01 16:44:29 -05:00
mem Allocator.zig: minor fixes 2022-12-13 15:04:03 -05:00
meta std.builtin: remove layout field from Type.Enum 2022-12-18 13:31:38 +01:00
net
os UEFI pool allocator changes 2023-01-12 03:46:15 -05:00
rand rand: add pub to next/jump 2022-12-18 01:46:09 -05:00
target
testing
Thread
time
tz
unicode update usages of @call 2022-12-13 13:14:20 +02:00
valgrind
zig parser: add helpful note for missing const/var before container level decl 2023-01-11 21:11:21 +02:00
array_hash_map.zig std.builtin: rename Type.UnionField and Type.StructField's field_type to type 2022-12-17 14:11:33 +01:00
array_list.zig Add fromOwnedSliceSentinel to ArrayList ArrayList and ArrayListUnmanaged, add fromOwnedSlice to ArrayListUnmanaged 2023-01-16 14:22:38 +02:00
ascii.zig std.ascii: more tests 2022-12-09 21:57:17 +01:00
atomic.zig
base64.zig
bit_set.zig std: implement subsetOf and supersetOf for DynamicBitSet 2022-12-12 06:23:56 +02:00
bounded_array.zig
buf_map.zig
buf_set.zig
build.zig zig build: support libraries aware of installed headers 2023-01-11 15:39:49 -08:00
builtin.zig Sema: implement AVR address spaces 2023-01-04 01:26:50 +02:00
c.zig remove the experimental std.x namespace 2023-01-02 16:57:15 -07:00
child_process.zig ChildProcess: fix false positives in windowsCreateProcessSupportsExtension 2022-12-31 20:51:56 -05:00
coff.zig windows: rework DebugInfo to use less file operations and fix some memory management issues 2023-01-08 20:28:42 -05:00
compress.zig
comptime_string_map.zig Re-apply: "std.ComptimeStringMap: use tuple types" 2022-12-08 22:21:46 +02:00
crypto.zig remove std.crypto.der 2023-01-02 16:57:15 -07:00
cstr.zig
debug.zig debug: fixup memory management 2023-01-08 22:16:16 -05:00
dwarf.zig
dynamic_library.zig update usages of @call 2022-12-13 13:14:20 +02:00
elf.zig
enums.zig std.builtin: rename Type.UnionField and Type.StructField's field_type to type 2022-12-17 14:11:33 +01:00
event.zig
fifo.zig
fmt.zig add tests for fixed stage1 bugs 2022-12-31 20:49:02 -05:00
fs.zig std: collect all options under one namespace 2023-01-05 02:31:29 -07:00
hash.zig
hash_map.zig std.builtin: rename Type.Fn's args to params 2022-12-17 14:11:33 +01:00
heap.zig Merge pull request #12586 from MasterQ32/std_memory_pool 2023-01-03 14:53:54 -05:00
http.zig std.http.Client: support transfer-encoding: chunked 2023-01-05 19:57:00 -07:00
Ini.zig add std.Ini for basic .ini file parsing 2023-01-11 15:39:48 -08:00
io.zig expose std.io.bufferedReaderSize 2023-01-11 15:39:48 -08:00
json.zig std.builtin: rename Type.UnionField and Type.StructField's field_type to type 2022-12-17 14:11:33 +01:00
leb128.zig update uses of overflow arithmetic builtins 2022-12-27 15:13:14 +02:00
linked_list.zig
log.zig std: collect all options under one namespace 2023-01-05 02:31:29 -07:00
macho.zig macho: add Zig wrapper for compact unwind encoding on arm64 2022-12-27 15:36:28 +01:00
math.zig math: implement absInt for integer vectors 2023-01-03 13:30:24 +02:00
mem.zig std: Handle field struct defaults in std.mem.zeroInit 2023-01-16 14:24:47 +02:00
meta.zig std: add meta.FieldType 2023-01-03 12:47:48 +02:00
multi_array_list.zig std.builtin: rename Type.UnionField and Type.StructField's field_type to type 2022-12-17 14:11:33 +01:00
net.zig std.net: check for localhost names before asking DNS 2023-01-10 18:09:07 -05:00
once.zig
os.zig Package: handle Windows PathAlreadyExists error code 2023-01-11 17:54:34 -08:00
packed_int_array.zig std: Expose Int parameter in std.PackedInt[Array,Slice] 2022-12-29 19:11:05 +02:00
pdb.zig
priority_dequeue.zig std: Fix update() method in PriorityQueue and PriorityDequeue (#13908) 2022-12-13 14:55:41 -05:00
priority_queue.zig std: Fix update() method in PriorityQueue and PriorityDequeue (#13908) 2022-12-13 14:55:41 -05:00
process.zig Implement some more environment functions for WASI. 2023-01-06 18:40:16 +02:00
Progress.zig fix(terminal): handle some possible errors and resolve TODOs 2022-12-13 09:11:30 +01:00
rand.zig
segmented_list.zig behavior: add test coverage for slicing zero length array field of struct 2022-12-10 12:33:17 +01:00
SemanticVersion.zig api(std.ascii): remove deprecated decls 2022-12-09 21:57:17 +01:00
simd.zig std.simd.iota: make it always called at comptime 2023-01-04 18:37:53 -07:00
sort.zig
start.zig std: collect all options under one namespace 2023-01-05 02:31:29 -07:00
start_windows_tls.zig
std.zig add std.tar for tar file unpacking 2023-01-11 15:39:48 -08:00
tar.zig fix build failures on 32-bit arm due to u64/usize coercion 2023-01-11 15:39:49 -08:00
target.zig Sema: implement AVR address spaces 2023-01-04 01:26:50 +02:00
testing.zig std.builtin: rename Type.UnionField and Type.StructField's field_type to type 2022-12-17 14:11:33 +01:00
Thread.zig std.Thread: make Id smaller where possible 2023-01-16 14:20:57 +02:00
time.zig
treap.zig
tz.zig
unicode.zig
Uri.zig std.Uri: make scheme non-optional 2023-01-06 18:52:39 -07:00
valgrind.zig
wasm.zig wasm: refactor extended instructions 2022-12-21 17:02:53 +01:00
zig.zig std: add object format extension for dxcontainer 2022-12-13 15:06:55 -05:00