Skip to content

Commit

Permalink
Fix struct args (Rainer Orth)
Browse files Browse the repository at this point in the history
  • Loading branch information
atgreen committed Jun 28, 2024
1 parent 9c9e836 commit 8e3ef96
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/sparc/ffi.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ ffi_call_int (ffi_cif *cif, void (*fn)(void), void *rvalue,
void **avalue, void *closure)
{
size_t bytes = cif->bytes;
size_t i, nargs = cif->nargs;
ffi_type **arg_types = cif->arg_types;

FFI_ASSERT (cif->abi == FFI_V8);

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

/* If we have any structure arguments, make a copy so we are passing
by value. */
for (i = 0; i < nargs; i++)
{
ffi_type *at = arg_types[i];
int size = at->size;
if (at->type == FFI_TYPE_STRUCT)
{
char *argcopy = alloca (size);
memcpy (argcopy, avalue[i], size);
avalue[i] = argcopy;
}
}

ffi_call_v8(cif, fn, rvalue, avalue, -bytes, closure);
}

Expand Down

0 comments on commit 8e3ef96

Please sign in to comment.