Commit 6b8114e
committed
convention sweep: drive-to-clean across the entire codebase
Fifteen rounds of audit-and-fix passes against `CODING-CONVENTIONS.md`,
verified clean by an independent reviewer and end-to-end on Linux
(gcc, 104/104) and Mac (clang, 99/99).
Stack-init scopes:
- `StrInitStack(name, ne) { body }` and `VecInitStack(T, name, ne) { body }`
are the for-chain idioms; no allocator, `_Alignas(T)` backing storage,
scope-exit zeroes the handle so any subsequent use trips `validate_vec`.
- `reserve_vec` / `deinit_vec` / `reduce_space_vec` recognise the
NULL-allocator stack-init signal and abort with the dedicated
"vector not growable, no allocator assigned, probably stack inited"
trap.
- `IterInitFromVec*` falls back to alignment 1 on NULL allocator so a
`StrIter` over a stack-init Str works.
- `IterTruncate` is the legitimate Iter mutator; `IterLength` and the
Vec / Map / List / BitVec / Graph length / capacity / allocator
accessors are rvalue-only via `((void)0, (c)->field)` so
`Accessor(c) = X` no longer compiles.
`_Generic` dispatch:
- Every site with a `Zstr:` arm now carries an inline `char *:`
synonym arm with an identical body, restoring MSVC C portability.
`/Zc:strictStrings` is documented as a C++-only no-op and removed
from the MSVC branch of meson.build.
Sub-range iteration:
- `Sys/Dns.c::parse_hosts_table` / `parse_resolv_conf` rewritten from
`Zstr p / Zstr end` to `StrIter`, matching the `Parsers/JSON.c` /
`Parsers/KvConfig.c` precedent.
- `Sys/ProcMaps.c` parser rewritten to `StrIter`; chunked-read append
now goes through `StrReserve` + `StrEnd` + `StrResize`.
- `Std/Io.c` float / int / hex / octal / binary parsers, plus the
format-write parsers, migrated to `StrIter`.
- Smaller cursor walks in `Parsers/Dns.c::encode_qname`, `ArgParse.c`,
`Parsers/Dwarf*` family migrated to `StrIter` / `StrPushBackMany`.
- The dual-cursor `Io.c::str_read_fmt` and the past-the-end-pointer
`Container/Str.c::StrSplit` / `strip_str` carry inline-justified
pointer-pair semantics that StrIter can't express; left as-is.
Typing + naming:
- `u8 *` for raw byte-arithmetic in allocator internals (Heap.c,
Slab.c, Page.c, Vec.c, List.c).
- `Zstr` everywhere in declarations / params / fields. `MachoCache`,
`PdbCache`, `Backtrace`, `Sys/Dns`, `Bench/Allocator` updated.
- `MISRA_SIG*` -> `BEAM_*` to avoid libc-signal-macro collision.
- `SetAbortCallback` -> `OnAbort` (forbidden `Set*` shape).
- `BufReadCstr` / `BufWriteCstr` -> `BufReadZstr` / `BufWriteZstr`
(wire format is plain Zstr, not the `(Zstr, size)` `Cstr` shape).
- `Tests/Std/Vec.Complex.c::CreateComplexItem` -> `InitComplexItem`.
- `is_tty` (was `misra_is_tty`); `Zstr exe = _dyld_get_image_name(0)`;
`Zstr nm = de->d_name`.
Accessors added (the field-read sites the tests + tree needed):
- `VecCopyInit` / `VecCopyDeinit`; `ListCopyInit` / `ListCopyDeinit`;
`ListNodeData`; `MapKeyCopyInit` / `MapKeyCopyDeinit` /
`MapValueCopyInit` / `MapValueCopyDeinit`; `GraphAllocator` /
`GraphCopyInit` / `GraphCopyDeinit` / `GraphMutationEpoch`.
- Public `zstr_hash` / `zstr_compare` (FNV-1a + three-way wrapper)
so `Tests/Std/Map.Ops.c` and any future `Map<Zstr, ...>` callers
can register the canonical callbacks without redefining them.
Direct field-access cleanup:
- Replaced `Vec.length` / `Vec.data` / `Str.data` / `Str.length` /
`Map.allocator` / `Buf.length` reads from outside the container's
`.c` with the matching accessor across `Sys/PdbCache`, `MachoCache`,
`SymbolResolver`, `Socket`, `Backtrace`, `Proc`, `Dir`, `Dns`,
`Std/Io`, `Std/Log`, `Std/ArgParse`, `Std/Allocator/Debug`,
`Std/Container/{Graph,BitVec,Int,Float}`, `Parsers/{Elf,Dwarf,
DwarfInfo,DwarfUnwind,Pdb,Http,JSON,KvConfig,Dns}`, `Tests/Std/{*}`.
- `copy.length = data_size` blocks in `MachO.c`, `Pe.c`, `Elf.c`,
`Pdb.c` go through `BufResize`. `path.length = 0` in
`SymbolResolver.c` goes through `StrResize`. `Pdb.c::name_pool`
ownership-steal block is the only remaining bypass and now carries
an explicit comment naming the missing `StrTakeBuffer` primitive.
Bugs picked up along the way:
- `Std/Io.c::write_char_internal` produced `\x\HH` instead of `\xHH`
for non-printable bytes; matches the sibling pattern at line 1216
now.
- `Sys/Dns.c::DnsResolverDeinit` no longer aborts on a zero-init or
partially-failed-init struct.
- `Sys/Proc.c::sys_proc_read_internal` stages reads in an
`StrInitStack` + `StrMergeR` pipeline (was `char tmpbuf[1024]` +
`StrPushBackMany`).
- `Parsers/Dns.c::deinit_record_list` uses `VecBegin(list)` instead
of `list->data` so the uninit guard goes through the accessor.
Documentation:
- ~500+ doc blocks added / upgraded: TAGS lines for accessor
surfaces, full `SUCCESS:` / `FAILURE:` blocks for Math.h overflow
helpers, Buf.h binary read / write family, Map / List foreach
variants, ArgParse registration macros, Iter init variants,
StrIter constructors, Container `Math.h` / `Compare.h` /
`Convert.h` / `Memory.h` surfaces.
- `CODING-CONVENTIONS.md` grows: dedicated "Stack-init APIs"
section; `_Generic` `char *` synonym arm rule; clarified
syscall-prefix carve-out for `_Syscall.h` and `Beam.c`;
carve-out for libc usage in `Fuzz/` and `Benchmark/`.
- Alias macros (`StrForeach*`, `StrPopBack`, `StrRemove*`,
`VecInsert`, `VecPushBack`, `VecPushFront`, `ListInsert`,
`ListPushBack`, `MapInsert`, `MapSet`, `GraphAddNode`, `StrIter*`)
reframed in the namespace's vocabulary plus a "See `<UnderlyingL>`
for the full contract" pointer, instead of "alias for VecX".
- Stale legacy headers / proprietary-license blocks in
`Std/Utility.h` and `Std/Utility/Pair.h` replaced with the
canonical public-domain three-line header.
Tests:
- `Tests/Std/{Vec.Type,Vec.Insert,Vec.Complex,List.Access,List.Foreach,
List.Init,List.Insert,List.Ops,List.Remove,List.Type,Graph.Init,
Graph.Type,Int.{Type,Convert},Float.{Type,Convert},BitVec.{Memory,
Convert,Type,Init,Foreach},Allocator.{Heap,Arena,Page,Slab,Budget},
AllocDebug,Str.Access,Str.Convert,Str.Init,Io.Read}.c` updated to
use public accessors instead of direct field reads.
- `Vec.Init` test grows an `AlignedItem { i32 a; f64 b; }` check
that asserts the `_Alignas(T)` backing-buffer alignment plus a
`break`-exit verification.
- `size_t` -> `size` swept across Str.Convert, Str.Init, Io.Read,
BitVec.Convert test bodies.
Locked design questions (documented bypasses or carve-outs --
deferred to future commits when the underlying primitive is added):
`Tests/Util/TestRunner` snake_case public API rename;
`Map.allocator` mutator in `Allocator/Debug.c`; `StrTakeBuffer`
ownership-extract for `Pdb.c::name_pool`; libc-verb naming in
`Sys/Dir.c::DirCreate*`/`DirRemoveAll`; `ARG_TARGET` / `IOFMT`
`default:` runtime sentinels; `STDIN_FILENO FILENO(stdin)` polyfill;
`Sys/Socket.c` and `Sys/Backtrace.c` `char *` C-string output
parameters; `EnvGet(Zstr)` Str overload.
Verified clean by an independent whole-codebase reviewer across
every CODING-CONVENTIONS.md section.
169 files changed, +4649 / -1758.1 parent a704368 commit 6b8114e
169 files changed
Lines changed: 4649 additions & 1758 deletions
File tree
- Benchmark/Source
- Bin
- Include/Misra
- Parsers
- Std
- Container
- BitVec
- Float
- Graph
- Int
- List
- Map
- Str
- Vec
- Utility
- Iter
- Sys
- Source/Misra
- Parsers
- Std
- Allocator
- Container
- Sys
- Tests
- Std
- Util
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
| 23 | + | |
22 | 24 | | |
23 | 25 | | |
24 | 26 | | |
25 | 27 | | |
26 | 28 | | |
27 | | - | |
| 29 | + | |
28 | 30 | | |
29 | 31 | | |
30 | 32 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
| 45 | + | |
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | | - | |
| 61 | + | |
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
89 | | - | |
| 89 | + | |
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
| |||
227 | 227 | | |
228 | 228 | | |
229 | 229 | | |
230 | | - | |
231 | | - | |
| 230 | + | |
| 231 | + | |
232 | 232 | | |
233 | 233 | | |
234 | | - | |
| 234 | + | |
235 | 235 | | |
236 | 236 | | |
237 | 237 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | | - | |
21 | | - | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
22 | 25 | | |
23 | 26 | | |
24 | 27 | | |
| |||
278 | 281 | | |
279 | 282 | | |
280 | 283 | | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
281 | 290 | | |
282 | 291 | | |
283 | 292 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
| 121 | + | |
| 122 | + | |
121 | 123 | | |
122 | 124 | | |
123 | 125 | | |
| |||
225 | 227 | | |
226 | 228 | | |
227 | 229 | | |
| 230 | + | |
| 231 | + | |
228 | 232 | | |
229 | 233 | | |
230 | 234 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
287 | 287 | | |
288 | 288 | | |
289 | 289 | | |
| 290 | + | |
| 291 | + | |
290 | 292 | | |
291 | 293 | | |
292 | 294 | | |
| |||
0 commit comments