re PR libffi/13221 (libffi's closure couldn't pass sequence of char and/or short arguments.)
2003-12-01 Andreas Tobler <a.tobler@schweiz.ch> PR other/13221 * testsuite/libffi.call/cls_multi_sshort.c: New test case. * testsuite/libffi.call/cls_multi_sshortchar.c: Likewise. * testsuite/libffi.call/cls_multi_uchar.c: Likewise. * testsuite/libffi.call/cls_multi_schar.c: Likewise. * testsuite/libffi.call/cls_multi_ushortchar.c: Likewise. * testsuite/libffi.call/cls_multi_ushort.c: Likewise. * testsuite/libffi.special/unwindtest.cc: Cosmetics. From-SVN: r74093
This commit is contained in:
parent
e82407b5bb
commit
d18c338615
8 changed files with 538 additions and 1 deletions
|
@ -1,3 +1,15 @@
|
||||||
|
2003-12-01 Andreas Tobler <a.tobler@schweiz.ch>
|
||||||
|
|
||||||
|
PR other/13221
|
||||||
|
* testsuite/libffi.call/cls_multi_sshort.c: New test case.
|
||||||
|
* testsuite/libffi.call/cls_multi_sshortchar.c: Likewise.
|
||||||
|
* testsuite/libffi.call/cls_multi_uchar.c: Likewise.
|
||||||
|
* testsuite/libffi.call/cls_multi_schar.c: Likewise.
|
||||||
|
* testsuite/libffi.call/cls_multi_ushortchar.c: Likewise.
|
||||||
|
* testsuite/libffi.call/cls_multi_ushort.c: Likewise.
|
||||||
|
|
||||||
|
* testsuite/libffi.special/unwindtest.cc: Cosmetics.
|
||||||
|
|
||||||
2003-11-26 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
|
2003-11-26 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
|
||||||
|
|
||||||
* testsuite/libffi.call/ffitest.h: Include <fcntl.h>.
|
* testsuite/libffi.call/ffitest.h: Include <fcntl.h>.
|
||||||
|
|
81
libffi/testsuite/libffi.call/cls_multi_schar.c
Normal file
81
libffi/testsuite/libffi.call/cls_multi_schar.c
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
/* Area: ffi_call, closure_call
|
||||||
|
Purpose: Check passing of multiple signed char values.
|
||||||
|
Limitations: none.
|
||||||
|
PR: PR13221.
|
||||||
|
Originator: <hos@tamanegi.org> 20031129 */
|
||||||
|
|
||||||
|
/* { dg-do run { xfail mips*-*-* arm*-*-* strongarm*-*-* xscale*-*-* } } */
|
||||||
|
#include "ffitest.h"
|
||||||
|
|
||||||
|
signed char test_func_fn(signed char a1, signed char a2)
|
||||||
|
{
|
||||||
|
signed char result;
|
||||||
|
|
||||||
|
result = a1 + a2;
|
||||||
|
|
||||||
|
printf("%d %d: %d\n", a1, a2, result);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_func_gn(ffi_cif *cif, void *rval, void **avals, void *data)
|
||||||
|
{
|
||||||
|
signed char a1, a2;
|
||||||
|
|
||||||
|
a1 = *(signed char *)avals[0];
|
||||||
|
a2 = *(signed char *)avals[1];
|
||||||
|
|
||||||
|
*(ffi_arg *)rval = test_func_fn(a1, a2);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef signed char (*test_type)(signed char, signed char);
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
ffi_cif cif;
|
||||||
|
#ifndef USING_MMAP
|
||||||
|
static ffi_closure cl;
|
||||||
|
#endif
|
||||||
|
ffi_closure *pcl;
|
||||||
|
void * args_dbl[3];
|
||||||
|
ffi_type * cl_arg_types[3];
|
||||||
|
ffi_arg res_call;
|
||||||
|
signed char a, b, res_closure;
|
||||||
|
|
||||||
|
#ifdef USING_MMAP
|
||||||
|
pcl = allocate_mmap (sizeof(ffi_closure));
|
||||||
|
#else
|
||||||
|
pcl = &cl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
a = 2;
|
||||||
|
b = 125;
|
||||||
|
|
||||||
|
args_dbl[0] = &a;
|
||||||
|
args_dbl[1] = &b;
|
||||||
|
args_dbl[3] = NULL;
|
||||||
|
|
||||||
|
cl_arg_types[0] = &ffi_type_schar;
|
||||||
|
cl_arg_types[1] = &ffi_type_schar;
|
||||||
|
cl_arg_types[2] = NULL;
|
||||||
|
|
||||||
|
/* Initialize the cif */
|
||||||
|
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2,
|
||||||
|
&ffi_type_schar, cl_arg_types) == FFI_OK);
|
||||||
|
|
||||||
|
ffi_call(&cif, FFI_FN(test_func_fn), &res_call, args_dbl);
|
||||||
|
/* { dg-output "2 125: 127" } */
|
||||||
|
printf("res: %d\n", res_call);
|
||||||
|
/* { dg-output "\nres: 127" } */
|
||||||
|
|
||||||
|
CHECK(ffi_prep_closure(pcl, &cif, test_func_gn, NULL) == FFI_OK);
|
||||||
|
|
||||||
|
res_closure = (*((test_type)pcl))(2, 125);
|
||||||
|
/* { dg-output "\n2 125: 127" } */
|
||||||
|
printf("res: %d\n", res_closure);
|
||||||
|
/* { dg-output "\nres: 127" } */
|
||||||
|
|
||||||
|
exit(0);
|
||||||
|
}
|
81
libffi/testsuite/libffi.call/cls_multi_sshort.c
Normal file
81
libffi/testsuite/libffi.call/cls_multi_sshort.c
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
/* Area: ffi_call, closure_call
|
||||||
|
Purpose: Check passing of multiple signed short values.
|
||||||
|
Limitations: none.
|
||||||
|
PR: PR13221.
|
||||||
|
Originator: <andreast@gcc.gnu.org> 20031129 */
|
||||||
|
|
||||||
|
/* { dg-do run { xfail mips*-*-* arm*-*-* strongarm*-*-* xscale*-*-* } } */
|
||||||
|
#include "ffitest.h"
|
||||||
|
|
||||||
|
signed short test_func_fn(signed short a1, signed short a2)
|
||||||
|
{
|
||||||
|
signed short result;
|
||||||
|
|
||||||
|
result = a1 + a2;
|
||||||
|
|
||||||
|
printf("%d %d: %d\n", a1, a2, result);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_func_gn(ffi_cif *cif, void *rval, void **avals, void *data)
|
||||||
|
{
|
||||||
|
signed short a1, a2;
|
||||||
|
|
||||||
|
a1 = *(signed short *)avals[0];
|
||||||
|
a2 = *(signed short *)avals[1];
|
||||||
|
|
||||||
|
*(ffi_arg *)rval = test_func_fn(a1, a2);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef signed short (*test_type)(signed short, signed short);
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
ffi_cif cif;
|
||||||
|
#ifndef USING_MMAP
|
||||||
|
static ffi_closure cl;
|
||||||
|
#endif
|
||||||
|
ffi_closure *pcl;
|
||||||
|
void * args_dbl[3];
|
||||||
|
ffi_type * cl_arg_types[3];
|
||||||
|
ffi_arg res_call;
|
||||||
|
unsigned short a, b, res_closure;
|
||||||
|
|
||||||
|
#ifdef USING_MMAP
|
||||||
|
pcl = allocate_mmap (sizeof(ffi_closure));
|
||||||
|
#else
|
||||||
|
pcl = &cl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
a = 2;
|
||||||
|
b = 32765;
|
||||||
|
|
||||||
|
args_dbl[0] = &a;
|
||||||
|
args_dbl[1] = &b;
|
||||||
|
args_dbl[3] = NULL;
|
||||||
|
|
||||||
|
cl_arg_types[0] = &ffi_type_sshort;
|
||||||
|
cl_arg_types[1] = &ffi_type_sshort;
|
||||||
|
cl_arg_types[2] = NULL;
|
||||||
|
|
||||||
|
/* Initialize the cif */
|
||||||
|
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2,
|
||||||
|
&ffi_type_sshort, cl_arg_types) == FFI_OK);
|
||||||
|
|
||||||
|
ffi_call(&cif, FFI_FN(test_func_fn), &res_call, args_dbl);
|
||||||
|
/* { dg-output "2 32765: 32767" } */
|
||||||
|
printf("res: %d\n", res_call);
|
||||||
|
/* { dg-output "\nres: 32767" } */
|
||||||
|
|
||||||
|
CHECK(ffi_prep_closure(pcl, &cif, test_func_gn, NULL) == FFI_OK);
|
||||||
|
|
||||||
|
res_closure = (*((test_type)pcl))(2, 32765);
|
||||||
|
/* { dg-output "\n2 32765: 32767" } */
|
||||||
|
printf("res: %d\n", res_closure);
|
||||||
|
/* { dg-output "\nres: 32767" } */
|
||||||
|
|
||||||
|
exit(0);
|
||||||
|
}
|
93
libffi/testsuite/libffi.call/cls_multi_sshortchar.c
Normal file
93
libffi/testsuite/libffi.call/cls_multi_sshortchar.c
Normal file
|
@ -0,0 +1,93 @@
|
||||||
|
/* Area: ffi_call, closure_call
|
||||||
|
Purpose: Check passing of multiple signed short/char values.
|
||||||
|
Limitations: none.
|
||||||
|
PR: PR13221.
|
||||||
|
Originator: <andreast@gcc.gnu.org> 20031129 */
|
||||||
|
|
||||||
|
/* { dg-do run { xfail mips*-*-* arm*-*-* strongarm*-*-* xscale*-*-* } } */
|
||||||
|
#include "ffitest.h"
|
||||||
|
|
||||||
|
signed short test_func_fn(signed char a1, signed short a2,
|
||||||
|
signed char a3, signed short a4)
|
||||||
|
{
|
||||||
|
signed short result;
|
||||||
|
|
||||||
|
result = a1 + a2 + a3 + a4;
|
||||||
|
|
||||||
|
printf("%d %d %d %d: %d\n", a1, a2, a3, a4, result);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_func_gn(ffi_cif *cif, void *rval, void **avals, void *data)
|
||||||
|
{
|
||||||
|
signed char a1, a3;
|
||||||
|
signed short a2, a4;
|
||||||
|
|
||||||
|
a1 = *(signed char *)avals[0];
|
||||||
|
a2 = *(signed short *)avals[1];
|
||||||
|
a3 = *(signed char *)avals[2];
|
||||||
|
a4 = *(signed short *)avals[3];
|
||||||
|
|
||||||
|
*(ffi_arg *)rval = test_func_fn(a1, a2, a3, a4);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef signed short (*test_type)(signed char, signed short,
|
||||||
|
signed char, signed short);
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
ffi_cif cif;
|
||||||
|
#ifndef USING_MMAP
|
||||||
|
static ffi_closure cl;
|
||||||
|
#endif
|
||||||
|
ffi_closure *pcl;
|
||||||
|
void * args_dbl[5];
|
||||||
|
ffi_type * cl_arg_types[5];
|
||||||
|
ffi_arg res_call;
|
||||||
|
signed char a, c;
|
||||||
|
signed short b, d, res_closure;
|
||||||
|
|
||||||
|
#ifdef USING_MMAP
|
||||||
|
pcl = allocate_mmap (sizeof(ffi_closure));
|
||||||
|
#else
|
||||||
|
pcl = &cl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
a = 1;
|
||||||
|
b = 32765;
|
||||||
|
c = 127;
|
||||||
|
d = -128;
|
||||||
|
|
||||||
|
args_dbl[0] = &a;
|
||||||
|
args_dbl[1] = &b;
|
||||||
|
args_dbl[2] = &c;
|
||||||
|
args_dbl[3] = &d;
|
||||||
|
args_dbl[4] = NULL;
|
||||||
|
|
||||||
|
cl_arg_types[0] = &ffi_type_schar;
|
||||||
|
cl_arg_types[1] = &ffi_type_sshort;
|
||||||
|
cl_arg_types[2] = &ffi_type_schar;
|
||||||
|
cl_arg_types[3] = &ffi_type_sshort;
|
||||||
|
cl_arg_types[4] = NULL;
|
||||||
|
|
||||||
|
/* Initialize the cif */
|
||||||
|
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 4,
|
||||||
|
&ffi_type_sshort, cl_arg_types) == FFI_OK);
|
||||||
|
|
||||||
|
ffi_call(&cif, FFI_FN(test_func_fn), &res_call, args_dbl);
|
||||||
|
/* { dg-output "1 32765 127 -128: 32765" } */
|
||||||
|
printf("res: %d\n", res_call);
|
||||||
|
/* { dg-output "\nres: 32765" } */
|
||||||
|
|
||||||
|
CHECK(ffi_prep_closure(pcl, &cif, test_func_gn, NULL) == FFI_OK);
|
||||||
|
|
||||||
|
res_closure = (*((test_type)pcl))(1, 32765, 127, -128);
|
||||||
|
/* { dg-output "\n1 32765 127 -128: 32765" } */
|
||||||
|
printf("res: %d\n", res_closure);
|
||||||
|
/* { dg-output "\nres: 32765" } */
|
||||||
|
|
||||||
|
exit(0);
|
||||||
|
}
|
96
libffi/testsuite/libffi.call/cls_multi_uchar.c
Normal file
96
libffi/testsuite/libffi.call/cls_multi_uchar.c
Normal file
|
@ -0,0 +1,96 @@
|
||||||
|
/* Area: ffi_call, closure_call
|
||||||
|
Purpose: Check passing of multiple unsigned char values.
|
||||||
|
Limitations: none.
|
||||||
|
PR: PR13221.
|
||||||
|
Originator: <andreast@gcc.gnu.org> 20031129 */
|
||||||
|
|
||||||
|
/* { dg-do run { xfail mips*-*-* arm*-*-* strongarm*-*-* xscale*-*-* } } */
|
||||||
|
#include "ffitest.h"
|
||||||
|
|
||||||
|
unsigned char test_func_fn(unsigned char a1, unsigned char a2,
|
||||||
|
unsigned char a3, unsigned char a4)
|
||||||
|
{
|
||||||
|
unsigned char result;
|
||||||
|
|
||||||
|
result = a1 + a2 + a3 + a4;
|
||||||
|
|
||||||
|
printf("%d %d %d %d: %d\n", a1, a2, a3, a4, result);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_func_gn(ffi_cif *cif, void *rval, void **avals, void *data)
|
||||||
|
{
|
||||||
|
unsigned char a1, a2, a3, a4;
|
||||||
|
|
||||||
|
a1 = *(unsigned char *)avals[0];
|
||||||
|
a2 = *(unsigned char *)avals[1];
|
||||||
|
a3 = *(unsigned char *)avals[2];
|
||||||
|
a4 = *(unsigned char *)avals[3];
|
||||||
|
|
||||||
|
*(ffi_arg *)rval = test_func_fn(a1, a2, a3, a4);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef unsigned char (*test_type)(unsigned char, unsigned char,
|
||||||
|
unsigned char, unsigned char);
|
||||||
|
void test_func(ffi_cif *cif, void *rval, void **avals, void *data)
|
||||||
|
{
|
||||||
|
printf("%d %d %d %d\n", *(unsigned char *)avals[0],
|
||||||
|
*(unsigned char *)avals[1], *(unsigned char *)avals[2],
|
||||||
|
*(unsigned char *)avals[3]);
|
||||||
|
}
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
ffi_cif cif;
|
||||||
|
#ifndef USING_MMAP
|
||||||
|
static ffi_closure cl;
|
||||||
|
#endif
|
||||||
|
ffi_closure *pcl;
|
||||||
|
void * args_dbl[5];
|
||||||
|
ffi_type * cl_arg_types[5];
|
||||||
|
ffi_arg res_call;
|
||||||
|
unsigned char a, b, c, d, res_closure;
|
||||||
|
|
||||||
|
#ifdef USING_MMAP
|
||||||
|
pcl = allocate_mmap (sizeof(ffi_closure));
|
||||||
|
#else
|
||||||
|
pcl = &cl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
a = 1;
|
||||||
|
b = 2;
|
||||||
|
c = 127;
|
||||||
|
d = 125;
|
||||||
|
|
||||||
|
args_dbl[0] = &a;
|
||||||
|
args_dbl[1] = &b;
|
||||||
|
args_dbl[2] = &c;
|
||||||
|
args_dbl[3] = &d;
|
||||||
|
args_dbl[4] = NULL;
|
||||||
|
|
||||||
|
cl_arg_types[0] = &ffi_type_uchar;
|
||||||
|
cl_arg_types[1] = &ffi_type_uchar;
|
||||||
|
cl_arg_types[2] = &ffi_type_uchar;
|
||||||
|
cl_arg_types[3] = &ffi_type_uchar;
|
||||||
|
cl_arg_types[4] = NULL;
|
||||||
|
|
||||||
|
/* Initialize the cif */
|
||||||
|
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 4,
|
||||||
|
&ffi_type_uchar, cl_arg_types) == FFI_OK);
|
||||||
|
|
||||||
|
ffi_call(&cif, FFI_FN(test_func_fn), &res_call, args_dbl);
|
||||||
|
/* { dg-output "1 2 127 125: 255" } */
|
||||||
|
printf("res: %d\n", res_call);
|
||||||
|
/* { dg-output "\nres: 255" } */
|
||||||
|
|
||||||
|
CHECK(ffi_prep_closure(pcl, &cif, test_func_gn, NULL) == FFI_OK);
|
||||||
|
|
||||||
|
res_closure = (*((test_type)pcl))(1, 2, 127, 125);
|
||||||
|
/* { dg-output "\n1 2 127 125: 255" } */
|
||||||
|
printf("res: %d\n", res_closure);
|
||||||
|
/* { dg-output "\nres: 255" } */
|
||||||
|
|
||||||
|
exit(0);
|
||||||
|
}
|
81
libffi/testsuite/libffi.call/cls_multi_ushort.c
Normal file
81
libffi/testsuite/libffi.call/cls_multi_ushort.c
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
/* Area: ffi_call, closure_call
|
||||||
|
Purpose: Check passing of multiple unsigned short values.
|
||||||
|
Limitations: none.
|
||||||
|
PR: PR13221.
|
||||||
|
Originator: <andreast@gcc.gnu.org> 20031129 */
|
||||||
|
|
||||||
|
/* { dg-do run { xfail mips*-*-* arm*-*-* strongarm*-*-* xscale*-*-* } } */
|
||||||
|
#include "ffitest.h"
|
||||||
|
|
||||||
|
unsigned short test_func_fn(unsigned short a1, unsigned short a2)
|
||||||
|
{
|
||||||
|
unsigned short result;
|
||||||
|
|
||||||
|
result = a1 + a2;
|
||||||
|
|
||||||
|
printf("%d %d: %d\n", a1, a2, result);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_func_gn(ffi_cif *cif, void *rval, void **avals, void *data)
|
||||||
|
{
|
||||||
|
unsigned short a1, a2;
|
||||||
|
|
||||||
|
a1 = *(unsigned short *)avals[0];
|
||||||
|
a2 = *(unsigned short *)avals[1];
|
||||||
|
|
||||||
|
*(ffi_arg *)rval = test_func_fn(a1, a2);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef unsigned short (*test_type)(unsigned short, unsigned short);
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
ffi_cif cif;
|
||||||
|
#ifndef USING_MMAP
|
||||||
|
static ffi_closure cl;
|
||||||
|
#endif
|
||||||
|
ffi_closure *pcl;
|
||||||
|
void * args_dbl[3];
|
||||||
|
ffi_type * cl_arg_types[3];
|
||||||
|
ffi_arg res_call;
|
||||||
|
unsigned short a, b, res_closure;
|
||||||
|
|
||||||
|
#ifdef USING_MMAP
|
||||||
|
pcl = allocate_mmap (sizeof(ffi_closure));
|
||||||
|
#else
|
||||||
|
pcl = &cl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
a = 2;
|
||||||
|
b = 32765;
|
||||||
|
|
||||||
|
args_dbl[0] = &a;
|
||||||
|
args_dbl[1] = &b;
|
||||||
|
args_dbl[3] = NULL;
|
||||||
|
|
||||||
|
cl_arg_types[0] = &ffi_type_ushort;
|
||||||
|
cl_arg_types[1] = &ffi_type_ushort;
|
||||||
|
cl_arg_types[2] = NULL;
|
||||||
|
|
||||||
|
/* Initialize the cif */
|
||||||
|
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2,
|
||||||
|
&ffi_type_ushort, cl_arg_types) == FFI_OK);
|
||||||
|
|
||||||
|
ffi_call(&cif, FFI_FN(test_func_fn), &res_call, args_dbl);
|
||||||
|
/* { dg-output "2 32765: 32767" } */
|
||||||
|
printf("res: %d\n", res_call);
|
||||||
|
/* { dg-output "\nres: 32767" } */
|
||||||
|
|
||||||
|
CHECK(ffi_prep_closure(pcl, &cif, test_func_gn, NULL) == FFI_OK);
|
||||||
|
|
||||||
|
res_closure = (*((test_type)pcl))(2, 32765);
|
||||||
|
/* { dg-output "\n2 32765: 32767" } */
|
||||||
|
printf("res: %d\n", res_closure);
|
||||||
|
/* { dg-output "\nres: 32767" } */
|
||||||
|
|
||||||
|
exit(0);
|
||||||
|
}
|
93
libffi/testsuite/libffi.call/cls_multi_ushortchar.c
Normal file
93
libffi/testsuite/libffi.call/cls_multi_ushortchar.c
Normal file
|
@ -0,0 +1,93 @@
|
||||||
|
/* Area: ffi_call, closure_call
|
||||||
|
Purpose: Check passing of multiple unsigned short/char values.
|
||||||
|
Limitations: none.
|
||||||
|
PR: PR13221.
|
||||||
|
Originator: <andreast@gcc.gnu.org> 20031129 */
|
||||||
|
|
||||||
|
/* { dg-do run { xfail mips*-*-* arm*-*-* strongarm*-*-* xscale*-*-* } } */
|
||||||
|
#include "ffitest.h"
|
||||||
|
|
||||||
|
unsigned short test_func_fn(unsigned char a1, unsigned short a2,
|
||||||
|
unsigned char a3, unsigned short a4)
|
||||||
|
{
|
||||||
|
unsigned short result;
|
||||||
|
|
||||||
|
result = a1 + a2 + a3 + a4;
|
||||||
|
|
||||||
|
printf("%d %d %d %d: %d\n", a1, a2, a3, a4, result);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_func_gn(ffi_cif *cif, void *rval, void **avals, void *data)
|
||||||
|
{
|
||||||
|
unsigned char a1, a3;
|
||||||
|
unsigned short a2, a4;
|
||||||
|
|
||||||
|
a1 = *(unsigned char *)avals[0];
|
||||||
|
a2 = *(unsigned short *)avals[1];
|
||||||
|
a3 = *(unsigned char *)avals[2];
|
||||||
|
a4 = *(unsigned short *)avals[3];
|
||||||
|
|
||||||
|
*(ffi_arg *)rval = test_func_fn(a1, a2, a3, a4);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef unsigned short (*test_type)(unsigned char, unsigned short,
|
||||||
|
unsigned char, unsigned short);
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
ffi_cif cif;
|
||||||
|
#ifndef USING_MMAP
|
||||||
|
static ffi_closure cl;
|
||||||
|
#endif
|
||||||
|
ffi_closure *pcl;
|
||||||
|
void * args_dbl[5];
|
||||||
|
ffi_type * cl_arg_types[5];
|
||||||
|
ffi_arg res_call;
|
||||||
|
unsigned char a, c;
|
||||||
|
unsigned short b, d, res_closure;
|
||||||
|
|
||||||
|
#ifdef USING_MMAP
|
||||||
|
pcl = allocate_mmap (sizeof(ffi_closure));
|
||||||
|
#else
|
||||||
|
pcl = &cl;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
a = 1;
|
||||||
|
b = 2;
|
||||||
|
c = 127;
|
||||||
|
d = 128;
|
||||||
|
|
||||||
|
args_dbl[0] = &a;
|
||||||
|
args_dbl[1] = &b;
|
||||||
|
args_dbl[2] = &c;
|
||||||
|
args_dbl[3] = &d;
|
||||||
|
args_dbl[4] = NULL;
|
||||||
|
|
||||||
|
cl_arg_types[0] = &ffi_type_uchar;
|
||||||
|
cl_arg_types[1] = &ffi_type_ushort;
|
||||||
|
cl_arg_types[2] = &ffi_type_uchar;
|
||||||
|
cl_arg_types[3] = &ffi_type_ushort;
|
||||||
|
cl_arg_types[4] = NULL;
|
||||||
|
|
||||||
|
/* Initialize the cif */
|
||||||
|
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 4,
|
||||||
|
&ffi_type_ushort, cl_arg_types) == FFI_OK);
|
||||||
|
|
||||||
|
ffi_call(&cif, FFI_FN(test_func_fn), &res_call, args_dbl);
|
||||||
|
/* { dg-output "1 2 127 128: 258" } */
|
||||||
|
printf("res: %d\n", res_call);
|
||||||
|
/* { dg-output "\nres: 258" } */
|
||||||
|
|
||||||
|
CHECK(ffi_prep_closure(pcl, &cif, test_func_gn, NULL) == FFI_OK);
|
||||||
|
|
||||||
|
res_closure = (*((test_type)pcl))(1, 2, 127, 128);
|
||||||
|
/* { dg-output "\n1 2 127 128: 258" } */
|
||||||
|
printf("res: %d\n", res_closure);
|
||||||
|
/* { dg-output "\nres: 258" } */
|
||||||
|
|
||||||
|
exit(0);
|
||||||
|
}
|
|
@ -56,7 +56,7 @@ int main (void)
|
||||||
ffi_type * cl_arg_types[17];
|
ffi_type * cl_arg_types[17];
|
||||||
int res;
|
int res;
|
||||||
#ifdef USING_MMAP
|
#ifdef USING_MMAP
|
||||||
pcl = (ffi_closure*) allocate_mmap (sizeof(ffi_closure));
|
pcl = (ffi_closure *) allocate_mmap (sizeof(ffi_closure));
|
||||||
#else
|
#else
|
||||||
pcl = &cl;
|
pcl = &cl;
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue