• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /macosx-10.9.5/pyobjc-42/2.5/pyobjc/pyobjc-core/libffi-src/tests/testsuite/libffi.call/
1/* Area:		ffi_call, closure_call
2   Purpose:		Check double arguments in structs.
3   Limitations:	none.
4   PR:			none.
5   Originator:	Blake Chaffin 6/23/2007	*/
6
7/* { dg-do run } */
8
9#include "ffitest.h"
10
11typedef struct Dbls {
12	double x;
13	double y;
14} Dbls;
15
16void
17closure_test_fn(Dbls p)
18{
19	printf("%.1f %.1f\n", p.x, p.y);
20}
21
22void
23closure_test_gn(ffi_cif* cif,void* resp,void** args, void* userdata)
24{
25	closure_test_fn(*(Dbls*)args[0]);
26}
27
28int main(int argc, char** argv)
29{
30	ffi_cif cif;
31
32#ifndef USING_MMAP
33	static ffi_closure cl;
34#endif
35
36	ffi_closure*	pcl;
37	ffi_type*		cl_arg_types[1];
38
39#ifdef USING_MMAP
40	pcl = allocate_mmap(sizeof(ffi_closure));
41#else
42	pcl = &cl;
43#endif
44
45	ffi_type	ts1_type;
46	ffi_type*	ts1_type_elements[4];
47
48	ts1_type.size = 0;
49	ts1_type.alignment = 0;
50	ts1_type.type = FFI_TYPE_STRUCT;
51	ts1_type.elements = ts1_type_elements;
52
53	ts1_type_elements[0] = &ffi_type_double;
54	ts1_type_elements[1] = &ffi_type_double;
55	ts1_type_elements[2] = NULL;
56
57	cl_arg_types[0] = &ts1_type;
58
59	Dbls arg = { 1.0, 2.0 };
60
61	/* Initialize the cif */
62	CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
63				 &ffi_type_void, cl_arg_types) == FFI_OK);
64
65	CHECK(ffi_prep_closure(pcl, &cif, closure_test_gn, NULL) == FFI_OK);
66
67	((void*(*)(Dbls))(pcl))(arg);
68	/* { dg-output "1.0 2.0\n" } */
69
70	closure_test_fn(arg);
71	/* { dg-output "1.0 2.0\n" } */
72
73	return 0;
74}
75