Ruby 2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)

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