Skip to content

Sweep: four-branch (Str*/Zstr/char*/(Zstr,len)) dispatch for remaining string-input APIs #46

Description

@brightprogrammer

Every string-input API should expose the four effective branches of the
StrCmp shape:

  1. Str * — owned string
  2. Zstr — NUL-terminated const char *
  3. char * — MSVC string-literal synonym for Zstr (kept deliberately; see Zstr.h)
  4. (Zstr, len) — fixed-length view, as a separate OVERLOAD arity → a _cstr worker

Implementation rule for the (Zstr, len) worker

Make a transient copy only if required:

  • byte compare / scan callee → thread the bound via ZstrCompareN (or a
    length-bounded loop) with an exact-length guard — no copy.
  • Str-taking callee → the existing StrInitFromCstr(ptr, len, alloc)
    transient-copy idiom (mirror the _zstr sibling) — never a hand-built
    Str / __magic internals poke.
  • NUL-terminating syscall (open/mkdir/…) → bounded stack-buffer copy
    (file_open_n template).

Private snake_case workers live in each module's Private.h.

Done (PR #44)

File (FileOpen, FileReadAndClose), Elf (ElfOpen), ProcMaps; and Dir,
Dns, KvConfig, MachO, Http, Pe, Pdb, Socket.

Remaining — the sweep this issue tracks

  • Std/Container/Str/OpsStrSplit, StrSplitToIters (no length form)
  • Std/Container/Str/Insert — has _4 counted forms; audit for the full shape
  • Std/Container/Int/ConvertIntFromStr / IntTryFromStr families
  • Std/Container/Float/Convert
  • Std/Container/BitVec/Convert — partial; complete + audit
  • Std/Io
  • Std/FileFileWriteAndClose (from_buf / from_str / from_bytes)
  • Parsers/ElfElfFindSection

Audit path (run per module after adding)

Str-taking macro → four effective branches → correct expansion → transient copies only if required. This caught a real prefix false-match bug in
macho_find_section_cstr during the first batch, so audit the untested
_cstr forms line by line.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions