Skip to content

FFI: fix return of large bitvectors#150

Merged
alastairreid merged 2 commits into
masterfrom
areid-fix-ffi-bitvectors
Jun 22, 2026
Merged

FFI: fix return of large bitvectors#150
alastairreid merged 2 commits into
masterfrom
areid-fix-ffi-bitvectors

Conversation

@alastairreid

Copy link
Copy Markdown

For FFI imported functions that return more than 64 bits, like this

function F() -> (Bits(512), Boolean);

We need to generate an FFI wrapper that includes a line like this

uint64_t c_r0[8];
bool c_r1;
F(c_r0, &c_r1);

Note that c_r1 requires '&' to pass a pointer while c_r0 must not have '&' because C/C++ compilers will promote the array to a pointer.

For FFI imported functions that return more than 64 bits, like this

   function F() -> (Bits(512), Boolean);

We need to generate an FFI wrapper that includes a line like this

   uint64_t c_r0[8];
   bool c_r1;
   F(c_r0, &c_r1);

Note that c_r1 requires '&' to pass a pointer while c_r0 must not
have '&' because C/C++ compilers will promote the array to a pointer.
Comment thread tests/backends/ffi_import_03.c Outdated
Co-authored-by: Nikolay Kosarev <nikolay.kosarev@intel.com>
Signed-off-by: Alastair Reid <alastair.d.reid@gmail.com>
@alastairreid alastairreid merged commit 4a47ae2 into master Jun 22, 2026
@alastairreid alastairreid deleted the areid-fix-ffi-bitvectors branch June 22, 2026 11:39
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