• 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/* { dg-do run } */
2
3#include "ffitest.h"
4
5struct P {
6	double x;
7	double y;
8};
9
10static void
11base_func(struct P p)
12{
13  printf("%.1f %.1f\n",  p.x, p.y);
14}
15
16
17static void
18closure_test_fn6(ffi_cif* cif,void* resp,void** args, void* userdata)
19{
20   base_func(*(struct P*)args[0]);
21}
22
23typedef void (*closure_test_type0)(struct P);
24
25int main (void)
26{
27  ffi_cif cif;
28#ifndef USING_MMAP
29  static ffi_closure cl;
30#endif
31  ffi_closure *pcl;
32  ffi_type * cl_arg_types[1];
33  int i, res;
34#ifdef USING_MMAP
35  pcl = allocate_mmap (sizeof(ffi_closure));
36#else
37  pcl = &cl;
38#endif
39  ffi_type ts1_type;
40  ffi_type *ts1_type_elements[3];
41  ts1_type.size = 0;
42  ts1_type.alignment = 0;
43  ts1_type.type = FFI_TYPE_STRUCT;
44  ts1_type.elements = ts1_type_elements;
45  ts1_type_elements[0] = &ffi_type_double;
46  ts1_type_elements[1] = &ffi_type_double;
47  ts1_type_elements[2] = NULL;
48
49  cl_arg_types[0] = &ts1_type;
50
51  struct P value = { 1.0, 2.0 };
52
53  /* Initialize the cif */
54  CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
55		     &ffi_type_void, cl_arg_types) == FFI_OK);
56
57  CHECK(ffi_prep_closure(pcl, &cif, closure_test_fn6,
58			 (void *) 3 /* userdata */) == FFI_OK);
59
60  (*((closure_test_type0)pcl))(value);
61  /* { dg-output "1.0 2.0\n" } */
62
63  base_func(value);
64  /* { dg-output "1.0 2.0\n" } */
65
66  exit(0);
67}
68