Skip to content

Pass and return FFI structs by value - #699

Merged
yogthos merged 2 commits into
jolt-lang:mainfrom
casselc:agent/ffi-by-value
Aug 22, 2026
Merged

yogthos merged 2 commits into
jolt-lang:mainfrom
casselc:agent/ffi-by-value

Conversation

@casselc

@casselc casselc commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Summary

  • accept literal [:by-value [:struct ...]] types in foreign-fn and defcfn
  • pass caller-owned pointed-to structs to C by value
  • write aggregate C returns into an explicit caller-owned destination pointer and return that pointer
  • support nested, large, multiple, blocking, and fixed-before-varargs aggregate calls
  • reject null aggregate pointers before native entry and keep callbacks and exports fail-closed
  • preserve lazy, lexically scoped native symbol resolution through the existing Scheme-adapter path

The explicit caller-buffer contract avoids hidden allocation and leaves ownership visible at the Jolt call site.

Stack

This is 2 of 3 and depends on #698. The reviewable commit for this layer is 918f6854 (the range after 62c6fd72).

GitHub native stacks do not support cross-fork branches, so this PR targets main and temporarily includes #698 in its cumulative diff. Once #698 lands, this PR narrows automatically to the by-value aggregate commit.

Validation

  • rebased onto official v0.7.22 (8990efe2)
  • pinned Chez 10.4.1 wrapper preflight
  • focused FFI: bindings 19/19, exact widths 51/51, layouts 25/25, aggregate calls 16/16; public API tests passed
  • layout and aggregate calls passed from source and a rebuilt standalone binary
  • covers nested, large, multiple, blocking, fixed-before-varargs, and null-rejection cases
  • Chez seed reminted to a two-pass fixpoint followed by a byte-stable one-pass remint
  • Gambit seed regenerated and gambitseedcheck passed
  • serial make -j1 test: 82 CI targets and 3 test targets passed
  • unit gate: 1394/1394
  • git diff --check
  • fork CI passed on Linux x86-64 and macOS arm64

@casselc
casselc marked this pull request as ready for review August 22, 2026 18:25
@yogthos
yogthos force-pushed the agent/ffi-by-value branch from 918f685 to cfc54fa Compare August 22, 2026 21:58
@yogthos
yogthos merged commit 94a7ea0 into jolt-lang:main Aug 22, 2026
3 checks passed
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.

2 participants