Skip to content

examples/c-interop: the rewritten example, recovered from an unpushed 2026-09-20 branch; to be respelled to the facade surface - #1640

Merged
ehartford merged 4 commits into
mainfrom
examples-c-interop
Sep 24, 2026
Merged

ehartford merged 4 commits into
mainfrom
examples-c-interop

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Recovered from the local branch c-interop-example (2026-09-20, never pushed): its compiler fixes landed in be767c0 ("Five defects the c-interop example exposed … the old example removed"), but the rewritten example itself — examples/c-interop as a project over the system sqlite3 and a vendored tally.c (build.w, src/{main,database,tally}.w, tests, vendor/) — never did, so main has no examples/c-interop at all.

This is the example as written on 09-20, before the facade language (D51 stages 5–13), so it will not pass :user-programs-safe as-is. The follow-up commit on this layer respells it to the facade surface (use facades.sqlite3; a project-local c facade for the vendored tally per §16.2b.1) with zero unsafe, and the README describes the program that is there. Layer on the modeled-C batch stack (base modeled-c-uat-rewrite).

@ehartford

Copy link
Copy Markdown
Contributor Author

Battery green — stack #1646 (main → #1636 → #1641 → #1630 → #1628 → #1625 → #1645 → #1640), top 3e298d3 on main c18fdfe, pinned seed, cold c_import cache, audits included:

build        rc=0
:fixpoint    rc=0
:drop-audit  rc=0
:move-audit  rc=0
:test        rc=0   (no red targets)
:test-green  rc=0
:last-green  rc=0

Contents: the build-runner unblock (#1636) and the #1635 compiler fix (#1641); 12b's facade gaps (#1630: optional callbacks, valid on failed, library-prefix presentation); stage 11 convention profiles (#1628); the §66 UAT/docs rewrite (#1625, sqlite3 11 → 0 unsafe); D64 buffer pairing + fixed arguments + zlib/bzip2 facades (#1645, zlib/bzip2 UAT 3 → 0 each); the recovered examples/c-interop on the facade surface (#1640, 21 → 4 unsafe, the 4 are filed gaps #1643/#1644). The top carries one fold-reconciliation commit (refusal scoped to c_import translations; snapshot; three fixture spellings; regenerated src/InitTemplates.w).

Ready to merge: gh stack merge 1640 --squash. After it lands: main battery + reseed, then a seed cut from that build (its compiler drives the runner; #1631 stage1 divergence retires with the new seed).

@ehartford
ehartford marked this pull request as ready for review September 24, 2026 18:50
Base automatically changed from modeled-c-d64-buffers to main September 24, 2026 18:51
Eric Hartford added 4 commits September 24, 2026 14:51
…brary and a vendored one) and its README — recovered from the unpushed 2026-09-20 branch c-interop-example (its compiler fixes landed in be767c0, the example did not)
…es, a project-local facade for the vendored tally; zero unsafe in the program

The example is respelled to the modeled-C facade surface (ruling §66,
spec §16.2b). src/database.w (16 unsafe, the hand-written owning wrapper)
is gone: the project carries its own verbatim copy of lib/facades/sqlite3.w
as src/facades/sqlite3.w (§16.2b.1: a facade is the importing project's
own until the package ships it), and src/main.w and the tests use the
rendered surface — Database.open, db.exec(sql, None, None, null),
db.prepare, stmt.bind_int, stmt.step, stmt.column_int/column_text as
Option[&CStr], db.errcode/errmsg, and FailedWithResource on a failed open
with its errmsg still readable. No Drop impls, no raw pointer, no unsafe.

src/facades/tally.w is the project-local facade for the vendored library:
one contract per header declaration, quoted from tally.h; the by-value
tally_widen is a lend. tally has no resource. Three calls stay raw in
src/tally.w (4 unsafe, was 5), each named in the facade: tally_range and
tally_total take a buffer with an element count, which D64's byte-length
pairing does not cover; tally_each is a callback with userdata on a
function whose first parameter is not a resource, which the callback
contract cannot be stated on. sqlite3_bind_text needs `param 4 fixed
SQLITE_TRANSIENT` (D64 fixed arguments, #1624), so the example binds an
integer. The README says all of this.

build.w links tally once (the c_import link hint, not link_system_lib as
well): no duplicate-library warning. Output is unchanged line for line;
12 tests pass over the real libraries.
…yte, pzTail and errmsg are the facade's fixed arguments (D64 §16.2b.11); the facade copy tracks lib/facades/sqlite3.w
…ies to c_import translations only (read from decl_is_c_import — facade facts are collected before ci_syms exists; stage 13's runtime rows render nothing); the contract snapshot records 12b's library-prefix presentation; three debug-alloc z_stream fixtures spell Stream.init; src/InitTemplates.w regenerated from the rewritten guide (tools/gen_init_templates.w moved to std.fs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant