jnr / jnr-ffi

Java Abstracted Foreign Function Layer
Other
1.23k stars 154 forks source link

Adapt variadic logic for new support in jffi #292

Closed headius closed 2 years ago

headius commented 2 years ago

This PR improves support for variadic functions by providing the fixed argument count to jffi. The new jffi, in turn, uses this count to properly set up the FFI context, allowing libffi to properly pass fixed and variadic arguments according to the current platform's ABI.

This PR introduces a new Variadic annotation to specify that a non-varargs Java binding is calling a variadic C function. On platforms where fixed and variadic arguments are passed differently, bindings must either use this annotation or Java varargs so jnr-ffi can determine a proper fixed argument count.

This work has been done primarily to support Apple Silicon, which passes variadic arguments differently than other platforms.

See https://github.com/jnr/jffi/pull/121