Skip to content

Commit

Permalink
Apply input from @joshtriplett on more general stdcall handling
Browse files Browse the repository at this point in the history
  • Loading branch information
twall committed Apr 19, 2015
1 parent 951de1a commit 4e8c935
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 45 deletions.
5 changes: 2 additions & 3 deletions native/libffi/src/x86/ffi.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ ffi_status ffi_prep_cif_machdep(ffi_cif *cif)

for (ptr = cif->arg_types, i = cif->nargs; i > 0; i--, ptr++)
{
#ifdef X86_WIN32
if (cif->abi != FFI_STDCALL)
#ifndef X86_WIN64
if (cif->abi != FFI_STDCALL && cif->abi != FFI_FASTCALL && cif->abi != FFI_THISCALL)
#endif
if (((*ptr)->alignment - 1) & cif->bytes)
cif->bytes = ALIGN(cif->bytes, (*ptr)->alignment);
Expand All @@ -332,7 +332,6 @@ ffi_status ffi_prep_cif_machdep(ffi_cif *cif)
#ifndef X86_WIN64
if (cif->abi == FFI_SYSV || cif->abi == FFI_UNIX64)
#endif
if (cif->abi != FFI_STDCALL)
cif->bytes = (cif->bytes + 15) & ~0xF;
#endif

Expand Down
42 changes: 42 additions & 0 deletions native/libffi/testsuite/libffi.call/align_mixed.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* Area: ffi_call
Purpose: Check for proper argument alignment.
Limitations: none.
PR: none.
Originator: <twalljava@java.net> (from many_win32.c) */

/* { dg-do run } */

#include "ffitest.h"
#include <float.h>

static float ABI_ATTR align_arguments(int i1,
double f2,
int i3,
double f4)
{
return i1+f2+i3+f4;
}

int main (void)
{
ffi_cif cif;
ffi_type *args[4] = {&ffi_type_int, &ffi_type_double, &ffi_type_int, &ffi_type_double};
float fa[2] = {1,2};
int ia[2] = {1,2};
void *values[4] = {&ia[0], &fa[0], &ia[1], &fa[1]};
float f, ff;

/* Initialize the cif */
CHECK(ffi_prep_cif(&cif, ABI_NUM, 4,
&ffi_type_float, args) == FFI_OK);

ff = align_arguments(ia[0], fa[0], ia[1], fa[1]);

ffi_call(&cif, FFI_FN(align_arguments), &f, values);

if (f - ff < FLT_EPSILON)
printf("align arguments tests ok!\n");
else
CHECK(0);
exit(0);
}
42 changes: 0 additions & 42 deletions native/libffi/testsuite/libffi.call/align_stdcall.c

This file was deleted.

0 comments on commit 4e8c935

Please sign in to comment.