~ubuntu-branches/ubuntu/lucid/gauche-c-wrapper/lucid

« back to all changes in this revision

Viewing changes to libffi/testsuite/libffi.call/cls_multi_sshortchar.c

  • Committer: Bazaar Package Importer
  • Author(s): NIIBE Yutaka
  • Date: 2008-04-07 09:15:03 UTC
  • Revision ID: james.westby@ubuntu.com-20080407091503-wu0h414koe95kj4i
Tags: upstream-0.5.2
ImportĀ upstreamĀ versionĀ 0.5.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Area:        ffi_call, closure_call
 
2
   Purpose:     Check passing of multiple signed short/char values.
 
3
   Limitations: none.
 
4
   PR:          PR13221.
 
5
   Originator:  <andreast@gcc.gnu.org> 20031129  */
 
6
 
 
7
/* { dg-do run { xfail mips64*-*-* arm*-*-* strongarm*-*-* xscale*-*-* } } */
 
8
#include "ffitest.h"
 
9
 
 
10
signed short test_func_fn(signed char a1, signed short a2,
 
11
                          signed char a3, signed short a4)
 
12
{
 
13
  signed short result;
 
14
 
 
15
  result = a1 + a2 + a3 + a4;
 
16
 
 
17
  printf("%d %d %d %d: %d\n", a1, a2, a3, a4, result);
 
18
 
 
19
  return result;
 
20
 
 
21
}
 
22
 
 
23
static void test_func_gn(ffi_cif *cif, void *rval, void **avals, void *data)
 
24
{
 
25
  signed char a1, a3;
 
26
  signed short a2, a4;
 
27
 
 
28
  a1 = *(signed char *)avals[0];
 
29
  a2 = *(signed short *)avals[1];
 
30
  a3 = *(signed char *)avals[2];
 
31
  a4 = *(signed short *)avals[3];
 
32
 
 
33
  *(ffi_arg *)rval = test_func_fn(a1, a2, a3, a4);
 
34
 
 
35
}
 
36
 
 
37
typedef signed short (*test_type)(signed char, signed short,
 
38
                                  signed char, signed short);
 
39
 
 
40
int main (void)
 
41
{
 
42
  ffi_cif cif;
 
43
#ifndef USING_MMAP
 
44
  static ffi_closure cl;
 
45
#endif
 
46
  ffi_closure *pcl;
 
47
  void * args_dbl[5];
 
48
  ffi_type * cl_arg_types[5];
 
49
  ffi_arg res_call;
 
50
  signed char a, c;
 
51
  signed short b, d, res_closure;
 
52
 
 
53
#ifdef USING_MMAP
 
54
  pcl = allocate_mmap (sizeof(ffi_closure));
 
55
#else
 
56
  pcl = &cl;
 
57
#endif
 
58
 
 
59
  a = 1;
 
60
  b = 32765;
 
61
  c = 127;
 
62
  d = -128;
 
63
 
 
64
  args_dbl[0] = &a;
 
65
  args_dbl[1] = &b;
 
66
  args_dbl[2] = &c;
 
67
  args_dbl[3] = &d;
 
68
  args_dbl[4] = NULL;
 
69
 
 
70
  cl_arg_types[0] = &ffi_type_schar;
 
71
  cl_arg_types[1] = &ffi_type_sshort;
 
72
  cl_arg_types[2] = &ffi_type_schar;
 
73
  cl_arg_types[3] = &ffi_type_sshort;
 
74
  cl_arg_types[4] = NULL;
 
75
 
 
76
  /* Initialize the cif */
 
77
  CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 4,
 
78
                     &ffi_type_sshort, cl_arg_types) == FFI_OK);
 
79
 
 
80
  ffi_call(&cif, FFI_FN(test_func_fn), &res_call, args_dbl);
 
81
  /* { dg-output "1 32765 127 -128: 32765" } */
 
82
  printf("res: %d\n", res_call);
 
83
  /* { dg-output "\nres: 32765" } */
 
84
 
 
85
  CHECK(ffi_prep_closure(pcl, &cif, test_func_gn, NULL)  == FFI_OK);
 
86
 
 
87
  res_closure = (*((test_type)pcl))(1, 32765, 127, -128);
 
88
  /* { dg-output "\n1 32765 127 -128: 32765" } */
 
89
  printf("res: %d\n", res_closure);
 
90
  /* { dg-output "\nres: 32765" } */
 
91
 
 
92
  exit(0);
 
93
}