1/* { dg-do run } */
2
3#include "ffitest.h"
4
5static int
6base_func(void* self, void* args, void* kwds)
7{
8  printf("%ld %ld %ld\n", (long)self, (long)args, (long)kwds);
9  return -42;
10}
11
12
13static void
14closure_test_fn7(ffi_cif* cif,void* resp,void** args, void* userdata)
15{
16   *(int*)resp = base_func(*(void**)args[0], *(void**)args[1], *(void**)args[2]);
17}
18
19typedef int (*closure_test_type7)(void*, void*, void*);
20
21int main (void)
22{
23  ffi_cif cif;
24#ifndef USING_MMAP
25  static ffi_closure cl;
26#endif
27  ffi_closure *pcl;
28  ffi_type * cl_arg_types[3];
29  int i, res;
30#ifdef USING_MMAP
31  pcl = allocate_mmap (sizeof(ffi_closure));
32#else
33  //pcl = &cl;
34  pcl = malloc(sizeof(*pcl));
35
36#endif
37
38  cl_arg_types[0] = &ffi_type_pointer;
39  cl_arg_types[1] = &ffi_type_pointer;
40  cl_arg_types[2] = &ffi_type_pointer;
41
42  /* Initialize the cif */
43  CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 3,
44		     &ffi_type_sint, cl_arg_types) == FFI_OK);
45
46  CHECK(ffi_prep_closure(pcl, &cif, closure_test_fn7,
47			 (void *) 99 /* userdata */) == FFI_OK);
48
49  base_func(4, 5, 6);
50  /* { dg-output "4 5 6\n" } */
51
52  (*((closure_test_type7)pcl))((void*)1, (void*)2, (void*)3);
53  /* { dg-output "1 2 3\n" } */
54
55  exit(0);
56}
57