Redesign EWAD as a hash-indexed, mmap-friendly pack format #2

Merged
fputs merged 2 commits from ewad into master 2026-11-08 13:39:14 -08:00
Owner

Summary

Redesigns EWAD into the pack format the research in docs/research/2026-11-08-pack-formats.md recommends, and adds a zero-copy reader for it.

  • Format. 64-byte header carrying a per-archive hash seed, alignment, and offsets to a contiguous directory and string table. 56-byte entries sorted by seeded XXH64 key with 64-bit offset, stored size, raw size, content hash, fourcc type, schema version, flags, and a strippable name offset. Lump data is aligned (default 16) so a mapped file hands out aligned pointers.
  • Reader. struct WAD_View borrows a buffer, validates every range once, and binary-searches by name or key. No allocation. wad_view_verify checks a lump's content hash on demand.
  • Writer. wad_write_data_ex / wad_write_file_ex take alignment, starting seed and strip-names options. Duplicate names are rejected; two different names that collide under a seed trigger a reseed. Output is deterministic and independent of insertion order.
  • LZ4 is an opaque flag plus raw size. spitwad links no codec; the caller compresses and decompresses.
  • SPITWAD_NAME_MAX goes from 63 to 255. Two new status codes: SPITWAD_ERR_DUPLICATE_NAME, SPITWAD_ERR_HASH_COLLISION.

Behaviour changes worth knowing: lumps loaded from an EWAD come back in key order, not insertion order; stripped archives load only through a view; the previous EWAD layout is not read (it was never used).

Testing

  • 37 tests, all passing, in the Debug build with -Wall -Wextra -Wpedantic -Wconversion and no warnings.
  • Same 37 under ASan + UBSan. detect_leaks is unsupported by Apple clang, so leaks were checked locally with macOS leaks --atExit on the EWAD tests (zero). CI's Alpine GCC runs LeakSanitizer as before.
  • XXH64 cross-checked against python-xxhash on 12 vectors plus a 768-byte input; the fixture constants are frozen from those.
  • Wrote a 4096-aligned archive, mmap'd it, confirmed wad_view_find returns a page-aligned pointer with matching bytes.

🤖 Generated with Claude Code

## Summary Redesigns EWAD into the pack format the research in `docs/research/2026-11-08-pack-formats.md` recommends, and adds a zero-copy reader for it. - **Format.** 64-byte header carrying a per-archive hash seed, alignment, and offsets to a contiguous directory and string table. 56-byte entries sorted by seeded XXH64 key with 64-bit offset, stored size, raw size, content hash, fourcc type, schema version, flags, and a strippable name offset. Lump data is aligned (default 16) so a mapped file hands out aligned pointers. - **Reader.** `struct WAD_View` borrows a buffer, validates every range once, and binary-searches by name or key. No allocation. `wad_view_verify` checks a lump's content hash on demand. - **Writer.** `wad_write_data_ex` / `wad_write_file_ex` take alignment, starting seed and strip-names options. Duplicate names are rejected; two different names that collide under a seed trigger a reseed. Output is deterministic and independent of insertion order. - **LZ4** is an opaque flag plus raw size. spitwad links no codec; the caller compresses and decompresses. - `SPITWAD_NAME_MAX` goes from 63 to 255. Two new status codes: `SPITWAD_ERR_DUPLICATE_NAME`, `SPITWAD_ERR_HASH_COLLISION`. Behaviour changes worth knowing: lumps loaded from an EWAD come back in key order, not insertion order; stripped archives load only through a view; the previous EWAD layout is not read (it was never used). ## Testing - 37 tests, all passing, in the Debug build with `-Wall -Wextra -Wpedantic -Wconversion` and no warnings. - Same 37 under ASan + UBSan. `detect_leaks` is unsupported by Apple clang, so leaks were checked locally with macOS `leaks --atExit` on the EWAD tests (zero). CI's Alpine GCC runs LeakSanitizer as before. - XXH64 cross-checked against python-xxhash on 12 vectors plus a 768-byte input; the fixture constants are frozen from those. - Wrote a 4096-aligned archive, mmap'd it, confirmed `wad_view_find` returns a page-aligned pointer with matching bytes. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Add EWAD format, status codes and embeddable build
All checks were successful
test / test (pull_request) Successful in 9s
55e5a88f14
Add the EWAD type with 63-byte names, duplicate lumps and strict
validation on load. Replace stderr output with distinct status codes
and wad_status_name.

Make loading transactional and free any previous lumps, so wad_init
is now required before wad_load_file and wad_load_data. Compare whole
names in lookup and removal, use 64-bit range checks, refuse output
past the u32 range and unknown types, and check fseek, ftell and
fclose.

Lower the CMake minimum to 3.17, build the library as C11, add
SPITWAD_SANITIZE, and only build tests when top-level. Add the MIT
license.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fix review findings, add real WAD2/WAD3 layout and docs
Some checks failed
test / sanitize (push) Failing after 10s
test / test (push) Successful in 12s
f6cb20b14d
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Pin CI to alpine:3.24
All checks were successful
test / test (push) Successful in 11s
test / test (pull_request) Successful in 14s
test / sanitize (pull_request) Successful in 14s
test / sanitize (push) Successful in 9s
4898c6e876
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Redesign EWAD as a hash-indexed, mmap-friendly pack format
All checks were successful
test / test (push) Successful in 15s
test / test (pull_request) Successful in 15s
test / sanitize (pull_request) Successful in 16s
test / sanitize (push) Successful in 10s
9c40105b5b
Replace the long-name-only EWAD layout with the design from the pack
format research: 64-byte header with a per-archive hash seed, 56-byte
entries sorted by seeded XXH64 key for binary search, 64-bit offsets
and sizes, a strippable string table, per-lump content hash, fourcc
type and schema version, an LZ4 flag the caller fills, and aligned
lump data for zero-copy mapping.

Add a borrowing WAD_View API (open, get, find, find_key, verify) that
validates once and returns pointers into the buffer, wad_hash, and
wad_write_data_ex with alignment, seed and strip options. Raise
SPITWAD_NAME_MAX to 255. The EWAD writer now rejects duplicate names
and reseeds on key collisions.

Rewrite the EWAD tests against a hand-built fixture with reference
XXH64 constants and add tests for the view, sorting, stripping, flags,
alignment, content hashes and metadata. Update the docs and check in
the research that motivated the design.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Document legacy WAD2/WAD3 incompatibility as a known issue
All checks were successful
test / test (push) Successful in 14s
test / test (pull_request) Successful in 14s
test / sanitize (push) Successful in 15s
test / sanitize (pull_request) Successful in 10s
39e905b4fa
Files written with the WAD2 or WAD3 signature before f6cb20b used the
classic 16-byte directory layout and no longer load. Record the fix a
future change should make and the test it needs.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
fputs force-pushed ewad from 39e905b4fa
All checks were successful
test / test (push) Successful in 14s
test / test (pull_request) Successful in 14s
test / sanitize (push) Successful in 15s
test / sanitize (pull_request) Successful in 10s
to f337e4d16c
All checks were successful
test / test (pull_request) Successful in 14s
test / test (push) Successful in 14s
test / sanitize (push) Successful in 15s
test / sanitize (pull_request) Successful in 10s
2026-11-08 13:38:56 -08:00
Compare
fputs merged commit 2d296e909e into master 2026-11-08 13:39:14 -08:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
fputs/spitwad!2
No description provided.