From 494d677fbaf8977d0c6a2f165df0a69f0339077e Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 10 May 2022 19:41:27 -0700 Subject: ffi: fix broken on RISC-V. * ffi.c (pad_retval): Remove the special case of zero mapping to zero, which occurs when the return type is void. It's not clear whether this is correct at all, on any platform. It hasn't showed up as a problem until now, but on RISC-V, we have hit a situation in which ffi_call writes a value into that zero-byte space for the void return value, causing that to overwrite values[0]: the first element of the argument array. For reasons not understood, this happens in the qsort test cases in which which the callback function performs a block return. It is strange because the block return is handled entirely in the closure dispatching function. --- ffi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ffi.c b/ffi.c index 2bb52d29..636db408 100644 --- a/ffi.c +++ b/ffi.c @@ -75,7 +75,7 @@ #define alignof(type) offsetof(struct {char x; type y;}, y) -#define pad_retval(size) (!(size) || convert(size_t, size) > sizeof (ffi_arg) \ +#define pad_retval(size) (convert(size_t, size) > sizeof (ffi_arg) \ ? convert(size_t, size) \ : sizeof (ffi_arg)) -- cgit v1.2.3