Skip to content

Modeled C: no facade clause for a buffer with an element count (const int *values, int count); D64 pairs a buffer with a byte length only, so examples/c-interop tally_range/tally_total stay unsafe #1643

Description

@ehartford

Found respelling examples/c-interop to the facade surface (PR #1640, branch examples-c-interop).

The vendored library vendor/tally.h declares

TallyRange tally_range(const int *values, int count);
int tally_total(const int *values, int count);
void tally_each(const int *values, int count, void (*visit)(void *context, int value), void *context);

The pointer and the count are one []i32 on the With side, and the program already spells them that way (fn data(values: []i32) -> *const i32 + values.len() as i32) — inside unsafe, because no facade clause can state the pairing:

  • fn tally_range / lend is refused, correctly: a lend would make the call safe, but param 0: *const i32 values is a caller-owned buffer that needs a length contract, and no clause states one yet (#1621); a safe call over a raw pointer with no bounds is the partial model §16.2b.3 forbids — leave the call raw (§16.2b.5, §16.2b.8).
  • D64 (buffer param P len param L) renders []u8 and its length counts bytes; the decision says the T * + count form is deliberately not generalized "until it is decided whether the integer means bytes, elements, code units or structs".

What the example needs is the element form: a pairing that renders []i32 (or []T for the pointee) and supplies count = slice.len(); the wrong-pairing hazard D64 names (handing C a wrong length) is the same, so it is a stated clause, never inferred from int * + int. Until it lands, examples/c-interop/src/tally.w keeps three unsafe calls and with build :user-programs-safe counts them (the gate is already red on #1376's fixtures). src/facades/tally.w in the example names this gap beside each declaration.

Spec: §16.2b.8 "Buffers", D64. Related: #1621 (byte buffers), #1624 (fixed arguments).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions