Debian Codegraph @

testsuite/libffi.call/ffitest.h

raw
1 #undef __USE_MINGW_ANSI_STDIO
2 #define __USE_MINGW_ANSI_STDIO 1
3
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <string.h>
7 #include <fcntl.h>
8 #include <ffi.h>
9 #include "fficonfig.h"
10
11 #include <float.h>
12 #include <math.h>
13
14 #if defined HAVE_STDINT_H
15 #include <stdint.h>
16 #endif
17
18 #if defined HAVE_INTTYPES_H
19 #include <inttypes.h>
20 #endif
21
22 #define MAX_ARGS 256
23
24 #define CHECK(x) \
25 do { \
26 if(!(x)){ \
27 printf("Check failed:\n%s\n", #x); \
28 abort(); \
29 } \
30 } while(0)
31
32 #define CHECK_FLOAT_EQ(x, y) \
33 do { \
34 if(fabs((x) - (y)) > FLT_EPSILON){ \
35 printf("Check failed CHECK_FLOAT_EQ(%s, %s)\n", #x, #y); \
36 abort(); \
37 } \
38 } while(0)
39
40 #define CHECK_DOUBLE_EQ(x, y) \
41 do { \
42 if(fabs((x) - (y)) > DBL_EPSILON){ \
43 printf("Check failed CHECK_FLOAT_EQ(%s, %s)\n", #x, #y); \
44 abort(); \
45 } \
46 } while(0)
47
48 /* Define macros so that compilers other than gcc can run the tests. */
49 #undef __UNUSED__
50 #if defined(__GNUC__)
51 #define __UNUSED__ __attribute__((__unused__))
52 #define __STDCALL__ __attribute__((stdcall))
53 #define __THISCALL__ __attribute__((thiscall))
54 #define __FASTCALL__ __attribute__((fastcall))
55 #define __MSABI__ __attribute__((ms_abi))
56 #else
57 #define __UNUSED__
58 #define __STDCALL__ __stdcall
59 #define __THISCALL__ __thiscall
60 #define __FASTCALL__ __fastcall
61 #endif
62
63 #ifndef ABI_NUM
64 #define ABI_NUM FFI_DEFAULT_ABI
65 #define ABI_ATTR
66 #endif
67
68 /* Prefer MAP_ANON(YMOUS) to /dev/zero, since we don't need to keep a
69 file open. */
70 #ifdef HAVE_MMAP_ANON
71 # undef HAVE_MMAP_DEV_ZERO
72
73 # include <sys/mman.h>
74 # ifndef MAP_FAILED
75 # define MAP_FAILED -1
76 # endif
77 # if !defined (MAP_ANONYMOUS) && defined (MAP_ANON)
78 # define MAP_ANONYMOUS MAP_ANON
79 # endif
80 # define USING_MMAP
81
82 #endif
83
84 #ifdef HAVE_MMAP_DEV_ZERO
85
86 # include <sys/mman.h>
87 # ifndef MAP_FAILED
88 # define MAP_FAILED -1
89 # endif
90 # define USING_MMAP
91
92 #endif
93
94 /* msvc kludge. */
95 #if defined(_MSC_VER)
96 #define PRIdLL "I64d"
97 #define PRIuLL "I64u"
98 #else
99 #define PRIdLL "lld"
100 #define PRIuLL "llu"
101 #endif
102
103 /* Tru64 UNIX kludge. */
104 #if defined(__alpha__) && defined(__osf__)
105 /* Tru64 UNIX V4.0 doesn't support %lld/%lld, but long is 64-bit. */
106 #undef PRIdLL
107 #define PRIdLL "ld"
108 #undef PRIuLL
109 #define PRIuLL "lu"
110 #define PRId8 "hd"
111 #define PRIu8 "hu"
112 #define PRId64 "ld"
113 #define PRIu64 "lu"
114 #define PRIuPTR "lu"
115 #endif
116
117 /* PA HP-UX kludge. */
118 #if defined(__hppa__) && defined(__hpux__) && !defined(PRIuPTR)
119 #define PRIuPTR "lu"
120 #endif
121
122 /* IRIX kludge. */
123 #if defined(__sgi)
124 /* IRIX 6.5 <inttypes.h> provides all definitions, but only for C99
125 compilations. */
126 #define PRId8 "hhd"
127 #define PRIu8 "hhu"
128 #if (_MIPS_SZLONG == 32)
129 #define PRId64 "lld"
130 #define PRIu64 "llu"
131 #endif
132 /* This doesn't match <inttypes.h>, which always has "lld" here, but the
133 arguments are uint64_t, int64_t, which are unsigned long, long for
134 64-bit in <sgidefs.h>. */
135 #if (_MIPS_SZLONG == 64)
136 #define PRId64 "ld"
137 #define PRIu64 "lu"
138 #endif
139 /* This doesn't match <inttypes.h>, which has "u" here, but the arguments
140 are uintptr_t, which is always unsigned long. */
141 #define PRIuPTR "lu"
142 #endif
143
144 /* Solaris < 10 kludge. */
145 #if defined(__sun__) && defined(__svr4__) && !defined(PRIuPTR)
146 #if defined(__arch64__) || defined (__x86_64__)
147 #define PRIuPTR "lu"
148 #else
149 #define PRIuPTR "u"
150 #endif
151 #endif
152
153 /* MSVC kludge. */
154 #if defined _MSC_VER
155 #if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS)
156 #define PRIuPTR "lu"
157 #define PRIu8 "u"
158 #define PRId8 "d"
159 #define PRIu64 "I64u"
160 #define PRId64 "I64d"
161 #endif
162 #endif
163
164 #ifndef PRIuPTR
165 #define PRIuPTR "u"
166 #endif