◐ Shell
clean mode source ↗

bpo-41100: ctypes: use the correct ABI for variadic functions by lawrence-danna-apple · Pull Request #21242 · python/cpython

@lawrence-danna-apple

On arm64 the calling convention for variardic functions is different
than the convention for fixed-arg functions of the same arg types.

ctypes needs to use ffi_prep_cif_var to tell libffi which calling
convention to use.

This patch adds a new attribute "f.variadic" for ctypes function
pointers, so users can specify which functions are variadic.

It will also auto-detect varargs when a function is called with more
arguments than f.argtypes specifies.   Since this is a new option
and it only matters on arm64 on apple platforms, lots of existing code
will not set f.variadic.   This will do the right thing in most
situations.