Skip to content
Next Next commit
host_env: add unified high-level call foreign-call API
Add a libffi-hiding foreign-call entry point that takes ctypes type codes
and recursive layouts plus raw buffers instead of libffi `Type`/`Arg`, to
become the single call path for the VM `_ctypes` (a later change) and other
consumers. Also bring in the `callproc_simple` helper so this host_env copy
stays byte-identical to the pyre-dev copy during the migration.

- `CTypeLayout` (Simple/Pointer/Struct/Union/Array/Opaque) with `size()` and
  an internal libffi-type lowering built on `ffi_type_for_layout`.
- `CallArg` (Typed/Int/Double/Pointer/Aggregate), `CallRet`
  (Void/Code/Pointer/Aggregate), `CallOptions` (use_errno/use_last_error),
  `CallValue` (Void/Scalar/Pointer/Aggregate), and `CallError`.
- `call(addr, &[CallArg], CallRet, CallOptions) -> Result<CallValue,
  CallError>`, built on the existing `Cif`/`ffi_*` primitives: the errno /
  last-error swap wraps only the raw call, and by-value aggregate arguments
  and returns go through `Cif::call_return_into`.
- 16 ABI unit tests over local `extern "C"` functions: scalar parity,
  by-value struct / nested / array-in-struct / {f32,f32} / large-struct
  arguments, small / odd / large struct returns, union size, the errno
  window, and the null-pointer / unknown-code / short-buffer errors.

`callproc` and `callproc_simple` are left in place; both are removed once the
migration onto `call` completes.

Assisted-by: Claude
  • Loading branch information
youknowone committed Jul 7, 2026
commit 1c5b1135d227e40e475f9395fb67396acc74d572
Loading