Skip to content

Commit 8e3ef96

Browse files
committed
Fix struct args (Rainer Orth)
1 parent 9c9e836 commit 8e3ef96

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/sparc/ffi.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ ffi_call_int (ffi_cif *cif, void (*fn)(void), void *rvalue,
286286
void **avalue, void *closure)
287287
{
288288
size_t bytes = cif->bytes;
289+
size_t i, nargs = cif->nargs;
290+
ffi_type **arg_types = cif->arg_types;
289291

290292
FFI_ASSERT (cif->abi == FFI_V8);
291293

@@ -295,6 +297,20 @@ ffi_call_int (ffi_cif *cif, void (*fn)(void), void *rvalue,
295297
&& (cif->flags & SPARC_FLAG_RET_MASK) == SPARC_RET_STRUCT)
296298
bytes += FFI_ALIGN (cif->rtype->size, 8);
297299

300+
/* If we have any structure arguments, make a copy so we are passing
301+
by value. */
302+
for (i = 0; i < nargs; i++)
303+
{
304+
ffi_type *at = arg_types[i];
305+
int size = at->size;
306+
if (at->type == FFI_TYPE_STRUCT)
307+
{
308+
char *argcopy = alloca (size);
309+
memcpy (argcopy, avalue[i], size);
310+
avalue[i] = argcopy;
311+
}
312+
}
313+
298314
ffi_call_v8(cif, fn, rvalue, avalue, -bytes, closure);
299315
}
300316

0 commit comments

Comments
 (0)