ffi 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +1 -27
- data/Rakefile +9 -12
- data/ext/ffi_c/AbstractMemory.c +11 -8
- data/ext/ffi_c/AbstractMemory.h +23 -21
- data/ext/ffi_c/AutoPointer.c +0 -1
- data/ext/ffi_c/Buffer.c +24 -8
- data/ext/ffi_c/Call.c +28 -0
- data/ext/ffi_c/Call.h +8 -4
- data/ext/ffi_c/ClosurePool.c +7 -5
- data/ext/ffi_c/DynamicLibrary.c +0 -1
- data/ext/ffi_c/Function.c +19 -2
- data/ext/ffi_c/MemoryPointer.c +3 -3
- data/ext/ffi_c/MethodHandle.c +1 -1
- data/ext/ffi_c/Pointer.c +23 -9
- data/ext/ffi_c/Struct.c +142 -69
- data/ext/ffi_c/Struct.h +16 -7
- data/ext/ffi_c/StructLayout.c +92 -55
- data/ext/ffi_c/Type.c +5 -22
- data/ext/ffi_c/Type.h +1 -1
- data/ext/ffi_c/Types.c +8 -2
- data/ext/ffi_c/Types.h +2 -0
- data/ext/ffi_c/Variadic.c +7 -19
- data/ext/ffi_c/endian.h +1 -1
- data/ext/ffi_c/extconf.rb +20 -11
- data/ext/ffi_c/libffi/ChangeLog +900 -84
- data/ext/ffi_c/libffi/ChangeLog.libffi +311 -0
- data/ext/ffi_c/libffi/LICENSE +1 -1
- data/ext/ffi_c/libffi/Makefile.am +14 -4
- data/ext/ffi_c/libffi/Makefile.in +362 -211
- data/ext/ffi_c/libffi/README +70 -92
- data/ext/ffi_c/libffi/aclocal.m4 +6068 -4586
- data/ext/ffi_c/libffi/config.guess +125 -143
- data/ext/ffi_c/libffi/config.sub +103 -27
- data/ext/ffi_c/libffi/configure +11364 -18497
- data/ext/ffi_c/libffi/configure.ac +43 -4
- data/ext/ffi_c/libffi/doc/libffi.info +15 -15
- data/ext/ffi_c/libffi/doc/libffi.texi +1 -1
- data/ext/ffi_c/libffi/doc/stamp-vti +4 -4
- data/ext/ffi_c/libffi/doc/version.texi +4 -4
- data/ext/ffi_c/libffi/fficonfig.h.in +24 -3
- data/ext/ffi_c/libffi/include/Makefile.am +1 -1
- data/ext/ffi_c/libffi/include/Makefile.in +97 -50
- data/ext/ffi_c/libffi/include/ffi.h.in +8 -2
- data/ext/ffi_c/libffi/include/ffi_common.h +24 -0
- data/ext/ffi_c/libffi/libtool-version +1 -1
- data/ext/ffi_c/libffi/ltmain.sh +7346 -5870
- data/ext/ffi_c/libffi/m4/libtool.m4 +7360 -0
- data/ext/ffi_c/libffi/m4/ltoptions.m4 +368 -0
- data/ext/ffi_c/libffi/m4/ltsugar.m4 +123 -0
- data/ext/ffi_c/libffi/m4/ltversion.m4 +23 -0
- data/ext/ffi_c/libffi/m4/lt~obsolete.m4 +92 -0
- data/ext/ffi_c/libffi/man/Makefile.in +115 -62
- data/ext/ffi_c/libffi/man/ffi_call.3 +3 -3
- data/ext/ffi_c/libffi/missing +15 -8
- data/ext/ffi_c/libffi/src/arm/sysv.S +15 -8
- data/ext/ffi_c/libffi/src/avr32/ffi.c +421 -0
- data/ext/ffi_c/libffi/src/avr32/ffitarget.h +50 -0
- data/ext/ffi_c/libffi/src/avr32/sysv.S +208 -0
- data/ext/ffi_c/libffi/src/closures.c +47 -10
- data/ext/ffi_c/libffi/src/frv/ffi.c +1 -1
- data/ext/ffi_c/libffi/src/java_raw_api.c +0 -3
- data/ext/ffi_c/libffi/src/mips/ffi.c +135 -32
- data/ext/ffi_c/libffi/src/mips/ffitarget.h +37 -4
- data/ext/ffi_c/libffi/src/mips/n32.S +67 -10
- data/ext/ffi_c/libffi/src/mips/o32.S +8 -8
- data/ext/ffi_c/libffi/src/pa/ffi.c +7 -0
- data/ext/ffi_c/libffi/src/powerpc/aix.S +163 -64
- data/ext/ffi_c/libffi/src/powerpc/aix_closure.S +308 -112
- data/ext/ffi_c/libffi/src/powerpc/ffi.c +20 -7
- data/ext/ffi_c/libffi/src/powerpc/ffi_darwin.c +208 -80
- data/ext/ffi_c/libffi/src/powerpc/ffitarget.h +11 -3
- data/ext/ffi_c/libffi/src/powerpc/sysv.S +12 -23
- data/ext/ffi_c/libffi/src/s390/sysv.S +1 -1
- data/ext/ffi_c/libffi/src/sh/sysv.S +9 -9
- data/ext/ffi_c/libffi/src/sh64/ffi.c +37 -22
- data/ext/ffi_c/libffi/src/sh64/sysv.S +23 -14
- data/ext/ffi_c/libffi/src/sparc/ffi.c +21 -6
- data/ext/ffi_c/libffi/src/sparc/v8.S +55 -14
- data/ext/ffi_c/libffi/src/x86/darwin.S +10 -9
- data/ext/ffi_c/libffi/src/x86/ffi.c +293 -86
- data/ext/ffi_c/libffi/src/x86/ffi64.c +73 -19
- data/ext/ffi_c/libffi/src/x86/ffitarget.h +30 -0
- data/ext/ffi_c/libffi/src/x86/sysv.S +21 -4
- data/ext/ffi_c/libffi/src/x86/unix64.S +8 -4
- data/ext/ffi_c/libffi/src/x86/win32.S +633 -147
- data/ext/ffi_c/libffi/src/x86/win64.S +460 -0
- data/ext/ffi_c/libffi/testsuite/Makefile.am +63 -54
- data/ext/ffi_c/libffi/testsuite/Makefile.in +112 -77
- data/ext/ffi_c/libffi/testsuite/lib/libffi-dg.exp +12 -1
- data/ext/ffi_c/libffi/testsuite/libffi.call/call.exp +4 -4
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn0.c +7 -15
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn1.c +7 -15
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn2.c +7 -15
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn3.c +7 -15
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn4.c +7 -15
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn5.c +7 -14
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_fn6.c +7 -15
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_loc_fn0.c +95 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/closure_stdcall.c +6 -14
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_12byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_16byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_18byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_19byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_1_1byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_20byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_20byte1.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_24byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_2byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3_1byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3byte1.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_3byte2.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_4_1byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_4byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_5_1_byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_5byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_64byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_6_1_byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_6byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_7_1_byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_7byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_8byte.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_9byte1.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_9byte2.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_double.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_float.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble_split.c +134 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_longdouble_split2.c +117 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_pointer.c +11 -17
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint16.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint32.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_sint64.c +7 -15
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint16.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint32.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_align_uint64.c +7 -15
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_dbls_struct.c +66 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_double.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_double_va.c +57 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_float.c +4 -13
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_longdouble.c +105 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_longdouble_va.c +57 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_schar.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_sshort.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_sshortchar.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_uchar.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_ushort.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_multi_ushortchar.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_pointer.c +74 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_pointer_stack.c +140 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_schar.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_sint.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_sshort.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_uchar.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_uint.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ulonglong.c +8 -16
- data/ext/ffi_c/libffi/testsuite/libffi.call/cls_ushort.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/err_bad_abi.c +37 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/err_bad_typedef.c +25 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/ffitest.h +31 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/float2.c +2 -1
- data/ext/ffi_c/libffi/testsuite/libffi.call/huge_struct.c +342 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct1.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct10.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct2.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct3.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct4.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct5.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct6.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct7.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct8.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/nested_struct9.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/problem1.c +4 -12
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_ldl.c +1 -1
- data/ext/ffi_c/libffi/testsuite/libffi.call/return_ll1.c +1 -1
- data/ext/ffi_c/libffi/testsuite/libffi.call/stret_large.c +145 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/stret_large2.c +148 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/stret_medium.c +124 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/stret_medium2.c +124 -0
- data/ext/ffi_c/libffi/testsuite/libffi.call/testclosure.c +70 -0
- data/ext/ffi_c/libffi/testsuite/libffi.special/ffitestcxx.h +10 -0
- data/ext/ffi_c/libffi/testsuite/libffi.special/special.exp +4 -5
- data/ext/ffi_c/libffi/testsuite/libffi.special/unwindtest.cc +17 -16
- data/ext/ffi_c/libffi/texinfo.tex +155 -427
- data/ext/ffi_c/libffi.bsd.mk +1 -1
- data/lib/ffi/autopointer.rb +79 -20
- data/lib/ffi/buffer.rb +4 -0
- data/lib/ffi/callback.rb +4 -10
- data/lib/ffi/enum.rb +28 -0
- data/lib/ffi/ffi.rb +0 -1
- data/lib/ffi/io.rb +28 -0
- data/lib/ffi/library.rb +237 -182
- data/lib/ffi/memorypointer.rb +28 -62
- data/lib/ffi/platform.rb +27 -0
- data/lib/ffi/pointer.rb +28 -0
- data/lib/ffi/struct.rb +55 -1
- data/lib/ffi/types.rb +29 -0
- data/lib/ffi/variadic.rb +29 -0
- data/spec/ffi/library_spec.rb +31 -5
- data/spec/ffi/managed_struct_spec.rb +1 -1
- data/spec/ffi/pointer_spec.rb +1 -1
- data/spec/ffi/rbx/attach_function_spec.rb +2 -1
- data/spec/ffi/rbx/memory_pointer_spec.rb +2 -1
- data/spec/ffi/spec_helper.rb +5 -1
- data/spec/ffi/struct_spec.rb +77 -0
- metadata +28 -18
- data/ext/ffi_c/libffi/TODO +0 -1
- data/ext/ffi_c/libffi/ltcf-c.sh +0 -861
- data/ext/ffi_c/libffi/ltcf-cxx.sh +0 -1069
- data/ext/ffi_c/libffi/ltcf-gcj.sh +0 -700
- data/ext/ffi_c/libffi/ltconfig +0 -2862
- data/ext/ffi_c/libffi/mkinstalldirs +0 -158
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/* Area: ffi_call, closure_call
|
|
2
|
+
Purpose: Test doubles passed in variable argument lists.
|
|
3
|
+
Limitations: none.
|
|
4
|
+
PR: none.
|
|
5
|
+
Originator: Blake Chaffin 6/6/2007 */
|
|
6
|
+
|
|
7
|
+
/* { dg-do run { xfail strongarm*-*-* xscale*-*-* } } */
|
|
8
|
+
/* { dg-output "" { xfail avr32*-*-* } } */
|
|
9
|
+
#include "ffitest.h"
|
|
10
|
+
|
|
11
|
+
static void
|
|
12
|
+
cls_double_va_fn(ffi_cif* cif __UNUSED__, void* resp,
|
|
13
|
+
void** args, void* userdata __UNUSED__)
|
|
14
|
+
{
|
|
15
|
+
char* format = *(char**)args[0];
|
|
16
|
+
double doubleValue = *(double*)args[1];
|
|
17
|
+
|
|
18
|
+
*(ffi_arg*)resp = printf(format, doubleValue);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
int main (void)
|
|
22
|
+
{
|
|
23
|
+
ffi_cif cif;
|
|
24
|
+
void *code;
|
|
25
|
+
ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
|
|
26
|
+
void* args[3];
|
|
27
|
+
ffi_type* arg_types[3];
|
|
28
|
+
|
|
29
|
+
char* format = "%.1f\n";
|
|
30
|
+
double doubleArg = 7;
|
|
31
|
+
ffi_arg res = 0;
|
|
32
|
+
|
|
33
|
+
arg_types[0] = &ffi_type_pointer;
|
|
34
|
+
arg_types[1] = &ffi_type_double;
|
|
35
|
+
arg_types[2] = NULL;
|
|
36
|
+
|
|
37
|
+
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &ffi_type_sint,
|
|
38
|
+
arg_types) == FFI_OK);
|
|
39
|
+
|
|
40
|
+
args[0] = &format;
|
|
41
|
+
args[1] = &doubleArg;
|
|
42
|
+
args[2] = NULL;
|
|
43
|
+
|
|
44
|
+
ffi_call(&cif, FFI_FN(printf), &res, args);
|
|
45
|
+
// { dg-output "7.0" }
|
|
46
|
+
printf("res: %d\n", (int) res);
|
|
47
|
+
// { dg-output "\nres: 4" }
|
|
48
|
+
|
|
49
|
+
CHECK(ffi_prep_closure_loc(pcl, &cif, cls_double_va_fn, NULL, code) == FFI_OK);
|
|
50
|
+
|
|
51
|
+
res = ((int(*)(char*, double))(code))(format, doubleArg);
|
|
52
|
+
// { dg-output "\n7.0" }
|
|
53
|
+
printf("res: %d\n", (int) res);
|
|
54
|
+
// { dg-output "\nres: 4" }
|
|
55
|
+
|
|
56
|
+
exit(0);
|
|
57
|
+
}
|
|
@@ -21,20 +21,11 @@ typedef float (*cls_ret_float)(float);
|
|
|
21
21
|
int main (void)
|
|
22
22
|
{
|
|
23
23
|
ffi_cif cif;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
#endif
|
|
27
|
-
ffi_closure *pcl;
|
|
24
|
+
void *code;
|
|
25
|
+
ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
|
|
28
26
|
ffi_type * cl_arg_types[2];
|
|
29
27
|
float res;
|
|
30
28
|
|
|
31
|
-
#ifdef USING_MMAP
|
|
32
|
-
pcl = allocate_mmap (sizeof(ffi_closure));
|
|
33
|
-
#else
|
|
34
|
-
pcl = &cl;
|
|
35
|
-
#endif
|
|
36
|
-
|
|
37
|
-
|
|
38
29
|
cl_arg_types[0] = &ffi_type_float;
|
|
39
30
|
cl_arg_types[1] = NULL;
|
|
40
31
|
|
|
@@ -42,8 +33,8 @@ int main (void)
|
|
|
42
33
|
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
|
|
43
34
|
&ffi_type_float, cl_arg_types) == FFI_OK);
|
|
44
35
|
|
|
45
|
-
CHECK(
|
|
46
|
-
res = ((((cls_ret_float)
|
|
36
|
+
CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_float_fn, NULL, code) == FFI_OK);
|
|
37
|
+
res = ((((cls_ret_float)code)(-2122.12)));
|
|
47
38
|
/* { dg-output "\\-2122.12: \\-2122.12" } */
|
|
48
39
|
printf("res: %.6f\n", res);
|
|
49
40
|
/* { dg-output "\nres: \-2122.120117" } */
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/* Area: ffi_call, closure_call
|
|
2
|
+
Purpose: Check long double arguments.
|
|
3
|
+
Limitations: none.
|
|
4
|
+
PR: none.
|
|
5
|
+
Originator: Blake Chaffin */
|
|
6
|
+
|
|
7
|
+
/* { dg-excess-errors "no long double format" { xfail x86_64-*-mingw* x86_64-*-cygwin* } } */
|
|
8
|
+
/* { dg-do run { xfail strongarm*-*-* xscale*-*-* } } */
|
|
9
|
+
/* { dg-options -mlong-double-128 { target powerpc64*-*-* } } */
|
|
10
|
+
/* { dg-output "" { xfail x86_64-*-mingw* x86_64-*-cygwin* } } */
|
|
11
|
+
|
|
12
|
+
#include "ffitest.h"
|
|
13
|
+
|
|
14
|
+
long double cls_ldouble_fn(
|
|
15
|
+
long double a1,
|
|
16
|
+
long double a2,
|
|
17
|
+
long double a3,
|
|
18
|
+
long double a4,
|
|
19
|
+
long double a5,
|
|
20
|
+
long double a6,
|
|
21
|
+
long double a7,
|
|
22
|
+
long double a8)
|
|
23
|
+
{
|
|
24
|
+
long double r = a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8;
|
|
25
|
+
|
|
26
|
+
printf("%Lg %Lg %Lg %Lg %Lg %Lg %Lg %Lg: %Lg\n",
|
|
27
|
+
a1, a2, a3, a4, a5, a6, a7, a8, r);
|
|
28
|
+
|
|
29
|
+
return r;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static void
|
|
33
|
+
cls_ldouble_gn(ffi_cif* cif __UNUSED__, void* resp,
|
|
34
|
+
void** args, void* userdata __UNUSED__)
|
|
35
|
+
{
|
|
36
|
+
long double a1 = *(long double*)args[0];
|
|
37
|
+
long double a2 = *(long double*)args[1];
|
|
38
|
+
long double a3 = *(long double*)args[2];
|
|
39
|
+
long double a4 = *(long double*)args[3];
|
|
40
|
+
long double a5 = *(long double*)args[4];
|
|
41
|
+
long double a6 = *(long double*)args[5];
|
|
42
|
+
long double a7 = *(long double*)args[6];
|
|
43
|
+
long double a8 = *(long double*)args[7];
|
|
44
|
+
|
|
45
|
+
*(long double*)resp = cls_ldouble_fn(
|
|
46
|
+
a1, a2, a3, a4, a5, a6, a7, a8);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
int main(void)
|
|
50
|
+
{
|
|
51
|
+
ffi_cif cif;
|
|
52
|
+
void* code;
|
|
53
|
+
ffi_closure* pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
|
|
54
|
+
void* args[9];
|
|
55
|
+
ffi_type* arg_types[9];
|
|
56
|
+
long double res = 0;
|
|
57
|
+
|
|
58
|
+
long double arg1 = 1;
|
|
59
|
+
long double arg2 = 2;
|
|
60
|
+
long double arg3 = 3;
|
|
61
|
+
long double arg4 = 4;
|
|
62
|
+
long double arg5 = 5;
|
|
63
|
+
long double arg6 = 6;
|
|
64
|
+
long double arg7 = 7;
|
|
65
|
+
long double arg8 = 8;
|
|
66
|
+
|
|
67
|
+
arg_types[0] = &ffi_type_longdouble;
|
|
68
|
+
arg_types[1] = &ffi_type_longdouble;
|
|
69
|
+
arg_types[2] = &ffi_type_longdouble;
|
|
70
|
+
arg_types[3] = &ffi_type_longdouble;
|
|
71
|
+
arg_types[4] = &ffi_type_longdouble;
|
|
72
|
+
arg_types[5] = &ffi_type_longdouble;
|
|
73
|
+
arg_types[6] = &ffi_type_longdouble;
|
|
74
|
+
arg_types[7] = &ffi_type_longdouble;
|
|
75
|
+
arg_types[8] = NULL;
|
|
76
|
+
|
|
77
|
+
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 8, &ffi_type_longdouble,
|
|
78
|
+
arg_types) == FFI_OK);
|
|
79
|
+
|
|
80
|
+
args[0] = &arg1;
|
|
81
|
+
args[1] = &arg2;
|
|
82
|
+
args[2] = &arg3;
|
|
83
|
+
args[3] = &arg4;
|
|
84
|
+
args[4] = &arg5;
|
|
85
|
+
args[5] = &arg6;
|
|
86
|
+
args[6] = &arg7;
|
|
87
|
+
args[7] = &arg8;
|
|
88
|
+
args[8] = NULL;
|
|
89
|
+
|
|
90
|
+
ffi_call(&cif, FFI_FN(cls_ldouble_fn), &res, args);
|
|
91
|
+
/* { dg-output "1 2 3 4 5 6 7 8: 36" } */
|
|
92
|
+
printf("res: %Lg\n", res);
|
|
93
|
+
/* { dg-output "\nres: 36" } */
|
|
94
|
+
|
|
95
|
+
CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ldouble_gn, NULL, code) == FFI_OK);
|
|
96
|
+
|
|
97
|
+
res = ((long double(*)(long double, long double, long double, long double,
|
|
98
|
+
long double, long double, long double, long double))(code))(arg1, arg2,
|
|
99
|
+
arg3, arg4, arg5, arg6, arg7, arg8);
|
|
100
|
+
/* { dg-output "\n1 2 3 4 5 6 7 8: 36" } */
|
|
101
|
+
printf("res: %Lg\n", res);
|
|
102
|
+
/* { dg-output "\nres: 36" } */
|
|
103
|
+
|
|
104
|
+
return 0;
|
|
105
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/* Area: ffi_call, closure_call
|
|
2
|
+
Purpose: Test long doubles passed in variable argument lists.
|
|
3
|
+
Limitations: none.
|
|
4
|
+
PR: none.
|
|
5
|
+
Originator: Blake Chaffin 6/6/2007 */
|
|
6
|
+
|
|
7
|
+
/* { dg-do run { xfail strongarm*-*-* xscale*-*-* } } */
|
|
8
|
+
/* { dg-output "" { xfail avr32*-*-* x86_64-*-mingw* } } */
|
|
9
|
+
#include "ffitest.h"
|
|
10
|
+
|
|
11
|
+
static void
|
|
12
|
+
cls_longdouble_va_fn(ffi_cif* cif __UNUSED__, void* resp,
|
|
13
|
+
void** args, void* userdata __UNUSED__)
|
|
14
|
+
{
|
|
15
|
+
char* format = *(char**)args[0];
|
|
16
|
+
long double ldValue = *(long double*)args[1];
|
|
17
|
+
|
|
18
|
+
*(ffi_arg*)resp = printf(format, ldValue);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
int main (void)
|
|
22
|
+
{
|
|
23
|
+
ffi_cif cif;
|
|
24
|
+
void *code;
|
|
25
|
+
ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
|
|
26
|
+
void* args[3];
|
|
27
|
+
ffi_type* arg_types[3];
|
|
28
|
+
|
|
29
|
+
char* format = "%.1Lf\n";
|
|
30
|
+
long double ldArg = 7;
|
|
31
|
+
ffi_arg res = 0;
|
|
32
|
+
|
|
33
|
+
arg_types[0] = &ffi_type_pointer;
|
|
34
|
+
arg_types[1] = &ffi_type_longdouble;
|
|
35
|
+
arg_types[2] = NULL;
|
|
36
|
+
|
|
37
|
+
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &ffi_type_sint,
|
|
38
|
+
arg_types) == FFI_OK);
|
|
39
|
+
|
|
40
|
+
args[0] = &format;
|
|
41
|
+
args[1] = &ldArg;
|
|
42
|
+
args[2] = NULL;
|
|
43
|
+
|
|
44
|
+
ffi_call(&cif, FFI_FN(printf), &res, args);
|
|
45
|
+
// { dg-output "7.0" }
|
|
46
|
+
printf("res: %d\n", (int) res);
|
|
47
|
+
// { dg-output "\nres: 4" }
|
|
48
|
+
|
|
49
|
+
CHECK(ffi_prep_closure_loc(pcl, &cif, cls_longdouble_va_fn, NULL, code) == FFI_OK);
|
|
50
|
+
|
|
51
|
+
res = ((int(*)(char*, long double))(code))(format, ldArg);
|
|
52
|
+
// { dg-output "\n7.0" }
|
|
53
|
+
printf("res: %d\n", (int) res);
|
|
54
|
+
// { dg-output "\nres: 4" }
|
|
55
|
+
|
|
56
|
+
exit(0);
|
|
57
|
+
}
|
|
@@ -36,21 +36,13 @@ typedef signed char (*test_type)(signed char, signed char);
|
|
|
36
36
|
int main (void)
|
|
37
37
|
{
|
|
38
38
|
ffi_cif cif;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
#endif
|
|
42
|
-
ffi_closure *pcl;
|
|
39
|
+
void *code;
|
|
40
|
+
ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
|
|
43
41
|
void * args_dbl[3];
|
|
44
42
|
ffi_type * cl_arg_types[3];
|
|
45
43
|
ffi_arg res_call;
|
|
46
44
|
signed char a, b, res_closure;
|
|
47
45
|
|
|
48
|
-
#ifdef USING_MMAP
|
|
49
|
-
pcl = allocate_mmap (sizeof(ffi_closure));
|
|
50
|
-
#else
|
|
51
|
-
pcl = &cl;
|
|
52
|
-
#endif
|
|
53
|
-
|
|
54
46
|
a = 2;
|
|
55
47
|
b = 125;
|
|
56
48
|
|
|
@@ -71,9 +63,9 @@ int main (void)
|
|
|
71
63
|
printf("res: %d\n", (signed char)res_call);
|
|
72
64
|
/* { dg-output "\nres: 127" } */
|
|
73
65
|
|
|
74
|
-
CHECK(
|
|
66
|
+
CHECK(ffi_prep_closure_loc(pcl, &cif, test_func_gn, NULL, code) == FFI_OK);
|
|
75
67
|
|
|
76
|
-
res_closure = (*((test_type)
|
|
68
|
+
res_closure = (*((test_type)code))(2, 125);
|
|
77
69
|
/* { dg-output "\n2 125: 127" } */
|
|
78
70
|
printf("res: %d\n", res_closure);
|
|
79
71
|
/* { dg-output "\nres: 127" } */
|
|
@@ -36,21 +36,13 @@ typedef signed short (*test_type)(signed short, signed short);
|
|
|
36
36
|
int main (void)
|
|
37
37
|
{
|
|
38
38
|
ffi_cif cif;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
#endif
|
|
42
|
-
ffi_closure *pcl;
|
|
39
|
+
void *code;
|
|
40
|
+
ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
|
|
43
41
|
void * args_dbl[3];
|
|
44
42
|
ffi_type * cl_arg_types[3];
|
|
45
43
|
ffi_arg res_call;
|
|
46
44
|
unsigned short a, b, res_closure;
|
|
47
45
|
|
|
48
|
-
#ifdef USING_MMAP
|
|
49
|
-
pcl = allocate_mmap (sizeof(ffi_closure));
|
|
50
|
-
#else
|
|
51
|
-
pcl = &cl;
|
|
52
|
-
#endif
|
|
53
|
-
|
|
54
46
|
a = 2;
|
|
55
47
|
b = 32765;
|
|
56
48
|
|
|
@@ -71,9 +63,9 @@ int main (void)
|
|
|
71
63
|
printf("res: %d\n", (unsigned short)res_call);
|
|
72
64
|
/* { dg-output "\nres: 32767" } */
|
|
73
65
|
|
|
74
|
-
CHECK(
|
|
66
|
+
CHECK(ffi_prep_closure_loc(pcl, &cif, test_func_gn, NULL, code) == FFI_OK);
|
|
75
67
|
|
|
76
|
-
res_closure = (*((test_type)
|
|
68
|
+
res_closure = (*((test_type)code))(2, 32765);
|
|
77
69
|
/* { dg-output "\n2 32765: 32767" } */
|
|
78
70
|
printf("res: %d\n", res_closure);
|
|
79
71
|
/* { dg-output "\nres: 32767" } */
|
|
@@ -41,22 +41,14 @@ typedef signed short (*test_type)(signed char, signed short,
|
|
|
41
41
|
int main (void)
|
|
42
42
|
{
|
|
43
43
|
ffi_cif cif;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
#endif
|
|
47
|
-
ffi_closure *pcl;
|
|
44
|
+
void *code;
|
|
45
|
+
ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
|
|
48
46
|
void * args_dbl[5];
|
|
49
47
|
ffi_type * cl_arg_types[5];
|
|
50
48
|
ffi_arg res_call;
|
|
51
49
|
signed char a, c;
|
|
52
50
|
signed short b, d, res_closure;
|
|
53
51
|
|
|
54
|
-
#ifdef USING_MMAP
|
|
55
|
-
pcl = allocate_mmap (sizeof(ffi_closure));
|
|
56
|
-
#else
|
|
57
|
-
pcl = &cl;
|
|
58
|
-
#endif
|
|
59
|
-
|
|
60
52
|
a = 1;
|
|
61
53
|
b = 32765;
|
|
62
54
|
c = 127;
|
|
@@ -83,9 +75,9 @@ int main (void)
|
|
|
83
75
|
printf("res: %d\n", (signed short)res_call);
|
|
84
76
|
/* { dg-output "\nres: 32765" } */
|
|
85
77
|
|
|
86
|
-
CHECK(
|
|
78
|
+
CHECK(ffi_prep_closure_loc(pcl, &cif, test_func_gn, NULL, code) == FFI_OK);
|
|
87
79
|
|
|
88
|
-
res_closure = (*((test_type)
|
|
80
|
+
res_closure = (*((test_type)code))(1, 32765, 127, -128);
|
|
89
81
|
/* { dg-output "\n1 32765 127 -128: 32765" } */
|
|
90
82
|
printf("res: %d\n", res_closure);
|
|
91
83
|
/* { dg-output "\nres: 32765" } */
|
|
@@ -47,21 +47,13 @@ void test_func(ffi_cif *cif __UNUSED__, void *rval __UNUSED__, void **avals,
|
|
|
47
47
|
int main (void)
|
|
48
48
|
{
|
|
49
49
|
ffi_cif cif;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
#endif
|
|
53
|
-
ffi_closure *pcl;
|
|
50
|
+
void *code;
|
|
51
|
+
ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
|
|
54
52
|
void * args_dbl[5];
|
|
55
53
|
ffi_type * cl_arg_types[5];
|
|
56
54
|
ffi_arg res_call;
|
|
57
55
|
unsigned char a, b, c, d, res_closure;
|
|
58
56
|
|
|
59
|
-
#ifdef USING_MMAP
|
|
60
|
-
pcl = allocate_mmap (sizeof(ffi_closure));
|
|
61
|
-
#else
|
|
62
|
-
pcl = &cl;
|
|
63
|
-
#endif
|
|
64
|
-
|
|
65
57
|
a = 1;
|
|
66
58
|
b = 2;
|
|
67
59
|
c = 127;
|
|
@@ -88,9 +80,9 @@ int main (void)
|
|
|
88
80
|
printf("res: %d\n", (unsigned char)res_call);
|
|
89
81
|
/* { dg-output "\nres: 255" } */
|
|
90
82
|
|
|
91
|
-
CHECK(
|
|
83
|
+
CHECK(ffi_prep_closure_loc(pcl, &cif, test_func_gn, NULL, code) == FFI_OK);
|
|
92
84
|
|
|
93
|
-
res_closure = (*((test_type)
|
|
85
|
+
res_closure = (*((test_type)code))(1, 2, 127, 125);
|
|
94
86
|
/* { dg-output "\n1 2 127 125: 255" } */
|
|
95
87
|
printf("res: %d\n", res_closure);
|
|
96
88
|
/* { dg-output "\nres: 255" } */
|
|
@@ -36,21 +36,13 @@ typedef unsigned short (*test_type)(unsigned short, unsigned short);
|
|
|
36
36
|
int main (void)
|
|
37
37
|
{
|
|
38
38
|
ffi_cif cif;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
#endif
|
|
42
|
-
ffi_closure *pcl;
|
|
39
|
+
void *code;
|
|
40
|
+
ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
|
|
43
41
|
void * args_dbl[3];
|
|
44
42
|
ffi_type * cl_arg_types[3];
|
|
45
43
|
ffi_arg res_call;
|
|
46
44
|
unsigned short a, b, res_closure;
|
|
47
45
|
|
|
48
|
-
#ifdef USING_MMAP
|
|
49
|
-
pcl = allocate_mmap (sizeof(ffi_closure));
|
|
50
|
-
#else
|
|
51
|
-
pcl = &cl;
|
|
52
|
-
#endif
|
|
53
|
-
|
|
54
46
|
a = 2;
|
|
55
47
|
b = 32765;
|
|
56
48
|
|
|
@@ -71,9 +63,9 @@ int main (void)
|
|
|
71
63
|
printf("res: %d\n", (unsigned short)res_call);
|
|
72
64
|
/* { dg-output "\nres: 32767" } */
|
|
73
65
|
|
|
74
|
-
CHECK(
|
|
66
|
+
CHECK(ffi_prep_closure_loc(pcl, &cif, test_func_gn, NULL, code) == FFI_OK);
|
|
75
67
|
|
|
76
|
-
res_closure = (*((test_type)
|
|
68
|
+
res_closure = (*((test_type)code))(2, 32765);
|
|
77
69
|
/* { dg-output "\n2 32765: 32767" } */
|
|
78
70
|
printf("res: %d\n", res_closure);
|
|
79
71
|
/* { dg-output "\nres: 32767" } */
|
|
@@ -41,22 +41,14 @@ typedef unsigned short (*test_type)(unsigned char, unsigned short,
|
|
|
41
41
|
int main (void)
|
|
42
42
|
{
|
|
43
43
|
ffi_cif cif;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
#endif
|
|
47
|
-
ffi_closure *pcl;
|
|
44
|
+
void *code;
|
|
45
|
+
ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
|
|
48
46
|
void * args_dbl[5];
|
|
49
47
|
ffi_type * cl_arg_types[5];
|
|
50
48
|
ffi_arg res_call;
|
|
51
49
|
unsigned char a, c;
|
|
52
50
|
unsigned short b, d, res_closure;
|
|
53
51
|
|
|
54
|
-
#ifdef USING_MMAP
|
|
55
|
-
pcl = allocate_mmap (sizeof(ffi_closure));
|
|
56
|
-
#else
|
|
57
|
-
pcl = &cl;
|
|
58
|
-
#endif
|
|
59
|
-
|
|
60
52
|
a = 1;
|
|
61
53
|
b = 2;
|
|
62
54
|
c = 127;
|
|
@@ -83,9 +75,9 @@ int main (void)
|
|
|
83
75
|
printf("res: %d\n", (unsigned short)res_call);
|
|
84
76
|
/* { dg-output "\nres: 258" } */
|
|
85
77
|
|
|
86
|
-
CHECK(
|
|
78
|
+
CHECK(ffi_prep_closure_loc(pcl, &cif, test_func_gn, NULL, code) == FFI_OK);
|
|
87
79
|
|
|
88
|
-
res_closure = (*((test_type)
|
|
80
|
+
res_closure = (*((test_type)code))(1, 2, 127, 128);
|
|
89
81
|
/* { dg-output "\n1 2 127 128: 258" } */
|
|
90
82
|
printf("res: %d\n", res_closure);
|
|
91
83
|
/* { dg-output "\nres: 258" } */
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/* Area: ffi_call, closure_call
|
|
2
|
+
Purpose: Check pointer arguments.
|
|
3
|
+
Limitations: none.
|
|
4
|
+
PR: none.
|
|
5
|
+
Originator: Blake Chaffin 6/6/2007 */
|
|
6
|
+
|
|
7
|
+
/* { dg-do run { xfail strongarm*-*-* xscale*-*-* } } */
|
|
8
|
+
#include "ffitest.h"
|
|
9
|
+
|
|
10
|
+
void* cls_pointer_fn(void* a1, void* a2)
|
|
11
|
+
{
|
|
12
|
+
void* result = (void*)((intptr_t)a1 + (intptr_t)a2);
|
|
13
|
+
|
|
14
|
+
printf("0x%08x 0x%08x: 0x%08x\n",
|
|
15
|
+
(unsigned int)(uintptr_t) a1,
|
|
16
|
+
(unsigned int)(uintptr_t) a2,
|
|
17
|
+
(unsigned int)(uintptr_t) result);
|
|
18
|
+
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
static void
|
|
23
|
+
cls_pointer_gn(ffi_cif* cif __UNUSED__, void* resp,
|
|
24
|
+
void** args, void* userdata __UNUSED__)
|
|
25
|
+
{
|
|
26
|
+
void* a1 = *(void**)(args[0]);
|
|
27
|
+
void* a2 = *(void**)(args[1]);
|
|
28
|
+
|
|
29
|
+
*(void**)resp = cls_pointer_fn(a1, a2);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
int main (void)
|
|
33
|
+
{
|
|
34
|
+
ffi_cif cif;
|
|
35
|
+
void *code;
|
|
36
|
+
ffi_closure* pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
|
|
37
|
+
void* args[3];
|
|
38
|
+
// ffi_type cls_pointer_type;
|
|
39
|
+
ffi_type* arg_types[3];
|
|
40
|
+
|
|
41
|
+
/* cls_pointer_type.size = sizeof(void*);
|
|
42
|
+
cls_pointer_type.alignment = 0;
|
|
43
|
+
cls_pointer_type.type = FFI_TYPE_POINTER;
|
|
44
|
+
cls_pointer_type.elements = NULL;*/
|
|
45
|
+
|
|
46
|
+
void* arg1 = (void*)0x12345678;
|
|
47
|
+
void* arg2 = (void*)0x89abcdef;
|
|
48
|
+
ffi_arg res = 0;
|
|
49
|
+
|
|
50
|
+
arg_types[0] = &ffi_type_pointer;
|
|
51
|
+
arg_types[1] = &ffi_type_pointer;
|
|
52
|
+
arg_types[2] = NULL;
|
|
53
|
+
|
|
54
|
+
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &ffi_type_pointer,
|
|
55
|
+
arg_types) == FFI_OK);
|
|
56
|
+
|
|
57
|
+
args[0] = &arg1;
|
|
58
|
+
args[1] = &arg2;
|
|
59
|
+
args[2] = NULL;
|
|
60
|
+
|
|
61
|
+
ffi_call(&cif, FFI_FN(cls_pointer_fn), &res, args);
|
|
62
|
+
/* { dg-output "0x12345678 0x89abcdef: 0x9be02467" } */
|
|
63
|
+
printf("res: 0x%08x\n", (unsigned int) res);
|
|
64
|
+
/* { dg-output "\nres: 0x9be02467" } */
|
|
65
|
+
|
|
66
|
+
CHECK(ffi_prep_closure_loc(pcl, &cif, cls_pointer_gn, NULL, code) == FFI_OK);
|
|
67
|
+
|
|
68
|
+
res = (ffi_arg)((void*(*)(void*, void*))(code))(arg1, arg2);
|
|
69
|
+
/* { dg-output "\n0x12345678 0x89abcdef: 0x9be02467" } */
|
|
70
|
+
printf("res: 0x%08x\n", (unsigned int) res);
|
|
71
|
+
/* { dg-output "\nres: 0x9be02467" } */
|
|
72
|
+
|
|
73
|
+
exit(0);
|
|
74
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/* Area: ffi_call, closure_call
|
|
2
|
+
Purpose: Check pointer arguments across multiple hideous stack frames.
|
|
3
|
+
Limitations: none.
|
|
4
|
+
PR: none.
|
|
5
|
+
Originator: Blake Chaffin 6/7/2007 */
|
|
6
|
+
|
|
7
|
+
/* { dg-do run { xfail strongarm*-*-* xscale*-*-* } } */
|
|
8
|
+
#include "ffitest.h"
|
|
9
|
+
|
|
10
|
+
static long dummyVar;
|
|
11
|
+
|
|
12
|
+
long dummy_func(
|
|
13
|
+
long double a1, char b1,
|
|
14
|
+
long double a2, char b2,
|
|
15
|
+
long double a3, char b3,
|
|
16
|
+
long double a4, char b4)
|
|
17
|
+
{
|
|
18
|
+
return a1 + b1 + a2 + b2 + a3 + b3 + a4 + b4;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
void* cls_pointer_fn2(void* a1, void* a2)
|
|
22
|
+
{
|
|
23
|
+
long double trample1 = (intptr_t)a1 + (intptr_t)a2;
|
|
24
|
+
char trample2 = ((char*)&a1)[0] + ((char*)&a2)[0];
|
|
25
|
+
long double trample3 = (intptr_t)trample1 + (intptr_t)a1;
|
|
26
|
+
char trample4 = trample2 + ((char*)&a1)[1];
|
|
27
|
+
long double trample5 = (intptr_t)trample3 + (intptr_t)a2;
|
|
28
|
+
char trample6 = trample4 + ((char*)&a2)[1];
|
|
29
|
+
long double trample7 = (intptr_t)trample5 + (intptr_t)trample1;
|
|
30
|
+
char trample8 = trample6 + trample2;
|
|
31
|
+
|
|
32
|
+
dummyVar = dummy_func(trample1, trample2, trample3, trample4,
|
|
33
|
+
trample5, trample6, trample7, trample8);
|
|
34
|
+
|
|
35
|
+
void* result = (void*)((intptr_t)a1 + (intptr_t)a2);
|
|
36
|
+
|
|
37
|
+
printf("0x%08x 0x%08x: 0x%08x\n",
|
|
38
|
+
(unsigned int)(uintptr_t) a1,
|
|
39
|
+
(unsigned int)(uintptr_t) a2,
|
|
40
|
+
(unsigned int)(uintptr_t) result);
|
|
41
|
+
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
void* cls_pointer_fn1(void* a1, void* a2)
|
|
46
|
+
{
|
|
47
|
+
long double trample1 = (intptr_t)a1 + (intptr_t)a2;
|
|
48
|
+
char trample2 = ((char*)&a1)[0] + ((char*)&a2)[0];
|
|
49
|
+
long double trample3 = (intptr_t)trample1 + (intptr_t)a1;
|
|
50
|
+
char trample4 = trample2 + ((char*)&a1)[1];
|
|
51
|
+
long double trample5 = (intptr_t)trample3 + (intptr_t)a2;
|
|
52
|
+
char trample6 = trample4 + ((char*)&a2)[1];
|
|
53
|
+
long double trample7 = (intptr_t)trample5 + (intptr_t)trample1;
|
|
54
|
+
char trample8 = trample6 + trample2;
|
|
55
|
+
|
|
56
|
+
dummyVar = dummy_func(trample1, trample2, trample3, trample4,
|
|
57
|
+
trample5, trample6, trample7, trample8);
|
|
58
|
+
|
|
59
|
+
void* result = (void*)((intptr_t)a1 + (intptr_t)a2);
|
|
60
|
+
|
|
61
|
+
printf("0x%08x 0x%08x: 0x%08x\n",
|
|
62
|
+
(unsigned int)(intptr_t) a1,
|
|
63
|
+
(unsigned int)(intptr_t) a2,
|
|
64
|
+
(unsigned int)(intptr_t) result);
|
|
65
|
+
|
|
66
|
+
result = cls_pointer_fn2(result, a1);
|
|
67
|
+
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
static void
|
|
72
|
+
cls_pointer_gn(ffi_cif* cif __UNUSED__, void* resp,
|
|
73
|
+
void** args, void* userdata __UNUSED__)
|
|
74
|
+
{
|
|
75
|
+
void* a1 = *(void**)(args[0]);
|
|
76
|
+
void* a2 = *(void**)(args[1]);
|
|
77
|
+
|
|
78
|
+
long double trample1 = (intptr_t)a1 + (intptr_t)a2;
|
|
79
|
+
char trample2 = ((char*)&a1)[0] + ((char*)&a2)[0];
|
|
80
|
+
long double trample3 = (intptr_t)trample1 + (intptr_t)a1;
|
|
81
|
+
char trample4 = trample2 + ((char*)&a1)[1];
|
|
82
|
+
long double trample5 = (intptr_t)trample3 + (intptr_t)a2;
|
|
83
|
+
char trample6 = trample4 + ((char*)&a2)[1];
|
|
84
|
+
long double trample7 = (intptr_t)trample5 + (intptr_t)trample1;
|
|
85
|
+
char trample8 = trample6 + trample2;
|
|
86
|
+
|
|
87
|
+
dummyVar = dummy_func(trample1, trample2, trample3, trample4,
|
|
88
|
+
trample5, trample6, trample7, trample8);
|
|
89
|
+
|
|
90
|
+
*(void**)resp = cls_pointer_fn1(a1, a2);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
int main (void)
|
|
94
|
+
{
|
|
95
|
+
ffi_cif cif;
|
|
96
|
+
void *code;
|
|
97
|
+
ffi_closure* pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
|
|
98
|
+
void* args[3];
|
|
99
|
+
// ffi_type cls_pointer_type;
|
|
100
|
+
ffi_type* arg_types[3];
|
|
101
|
+
|
|
102
|
+
/* cls_pointer_type.size = sizeof(void*);
|
|
103
|
+
cls_pointer_type.alignment = 0;
|
|
104
|
+
cls_pointer_type.type = FFI_TYPE_POINTER;
|
|
105
|
+
cls_pointer_type.elements = NULL;*/
|
|
106
|
+
|
|
107
|
+
void* arg1 = (void*)0x01234567;
|
|
108
|
+
void* arg2 = (void*)0x89abcdef;
|
|
109
|
+
ffi_arg res = 0;
|
|
110
|
+
|
|
111
|
+
arg_types[0] = &ffi_type_pointer;
|
|
112
|
+
arg_types[1] = &ffi_type_pointer;
|
|
113
|
+
arg_types[2] = NULL;
|
|
114
|
+
|
|
115
|
+
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &ffi_type_pointer,
|
|
116
|
+
arg_types) == FFI_OK);
|
|
117
|
+
|
|
118
|
+
args[0] = &arg1;
|
|
119
|
+
args[1] = &arg2;
|
|
120
|
+
args[2] = NULL;
|
|
121
|
+
|
|
122
|
+
printf("\n");
|
|
123
|
+
ffi_call(&cif, FFI_FN(cls_pointer_fn1), &res, args);
|
|
124
|
+
|
|
125
|
+
printf("res: 0x%08x\n", (unsigned int) res);
|
|
126
|
+
// { dg-output "\n0x01234567 0x89abcdef: 0x8acf1356" }
|
|
127
|
+
// { dg-output "\n0x8acf1356 0x01234567: 0x8bf258bd" }
|
|
128
|
+
// { dg-output "\nres: 0x8bf258bd" }
|
|
129
|
+
|
|
130
|
+
CHECK(ffi_prep_closure_loc(pcl, &cif, cls_pointer_gn, NULL, code) == FFI_OK);
|
|
131
|
+
|
|
132
|
+
res = (ffi_arg)((void*(*)(void*, void*))(code))(arg1, arg2);
|
|
133
|
+
|
|
134
|
+
printf("res: 0x%08x\n", (unsigned int) res);
|
|
135
|
+
// { dg-output "\n0x01234567 0x89abcdef: 0x8acf1356" }
|
|
136
|
+
// { dg-output "\n0x8acf1356 0x01234567: 0x8bf258bd" }
|
|
137
|
+
// { dg-output "\nres: 0x8bf258bd" }
|
|
138
|
+
|
|
139
|
+
exit(0);
|
|
140
|
+
}
|