Ruby  2.5.0dev(2017-10-22revision60238)
defines.h
Go to the documentation of this file.
1 /************************************************
2 
3  defines.h -
4 
5  $Author$
6  created at: Wed May 18 00:21:44 JST 1994
7 
8 ************************************************/
9 
10 #ifndef RUBY_DEFINES_H
11 #define RUBY_DEFINES_H 1
12 
13 #if defined(__cplusplus)
14 extern "C" {
15 #if 0
16 } /* satisfy cc-mode */
17 #endif
18 #endif
19 
20 #include "ruby/config.h"
21 #ifdef RUBY_EXTCONF_H
22 #include RUBY_EXTCONF_H
23 #endif
24 
25 /* function attributes */
26 #ifndef CONSTFUNC
27 # define CONSTFUNC(x) x
28 #endif
29 #ifndef PUREFUNC
30 # define PUREFUNC(x) x
31 #endif
32 #define NORETURN_STYLE_NEW 1
33 #ifndef NORETURN
34 # define NORETURN(x) x
35 #endif
36 #ifndef DEPRECATED
37 # define DEPRECATED(x) x
38 #endif
39 #ifndef DEPRECATED_BY
40 # define DEPRECATED_BY(n,x) DEPRECATED(x)
41 #endif
42 #ifndef DEPRECATED_TYPE
43 # define DEPRECATED_TYPE(mesg, decl) decl
44 #endif
45 #ifndef NOINLINE
46 # define NOINLINE(x) x
47 #endif
48 #ifndef ALWAYS_INLINE
49 # define ALWAYS_INLINE(x) x
50 #endif
51 #ifndef ERRORFUNC
52 # define HAVE_ATTRIBUTE_ERRORFUNC 0
53 # define ERRORFUNC(mesg, x) x
54 #else
55 # define HAVE_ATTRIBUTE_ERRORFUNC 1
56 #endif
57 #ifndef WARNINGFUNC
58 # define HAVE_ATTRIBUTE_WARNINGFUNC 0
59 # define WARNINGFUNC(mesg, x) x
60 #else
61 # define HAVE_ATTRIBUTE_WARNINGFUNC 1
62 #endif
63 
64 #ifndef GCC_VERSION_SINCE
65 # if defined(__GNUC__) && !defined(__INTEL_COMPILER) && !defined(__clang__)
66 # define GCC_VERSION_SINCE(major, minor, patchlevel) \
67  ((__GNUC__ > (major)) || \
68  ((__GNUC__ == (major) && \
69  ((__GNUC_MINOR__ > (minor)) || \
70  (__GNUC_MINOR__ == (minor) && __GNUC_PATCHLEVEL__ >= (patchlevel))))))
71 # else
72 # define GCC_VERSION_SINCE(major, minor, patchlevel) 0
73 # endif
74 #endif
75 
76 /* likely */
77 #if __GNUC__ >= 3
78 #define RB_LIKELY(x) (__builtin_expect(!!(x), 1))
79 #define RB_UNLIKELY(x) (__builtin_expect(!!(x), 0))
80 #else /* __GNUC__ >= 3 */
81 #define RB_LIKELY(x) (x)
82 #define RB_UNLIKELY(x) (x)
83 #endif /* __GNUC__ >= 3 */
84 
85 #ifdef __GNUC__
86 #define PRINTF_ARGS(decl, string_index, first_to_check) \
87  decl __attribute__((format(printf, string_index, first_to_check)))
88 #else
89 #define PRINTF_ARGS(decl, string_index, first_to_check) decl
90 #endif
91 
92 #ifdef __GNUC__
93 #define RB_GNUC_EXTENSION __extension__
94 #define RB_GNUC_EXTENSION_BLOCK(x) __extension__ ({ x; })
95 #else
96 #define RB_GNUC_EXTENSION
97 #define RB_GNUC_EXTENSION_BLOCK(x) (x)
98 #endif
99 
100 /* AC_INCLUDES_DEFAULT */
101 #include <stdio.h>
102 #ifdef HAVE_SYS_TYPES_H
103 # include <sys/types.h>
104 #endif
105 #ifdef HAVE_SYS_STAT_H
106 # include <sys/stat.h>
107 #endif
108 #ifdef STDC_HEADERS
109 # include <stdlib.h>
110 # include <stddef.h>
111 #else
112 # ifdef HAVE_STDLIB_H
113 # include <stdlib.h>
114 # endif
115 #endif
116 #ifdef HAVE_STRING_H
117 # if !defined STDC_HEADERS && defined HAVE_MEMORY_H
118 # include <memory.h>
119 # endif
120 # include <string.h>
121 #endif
122 #ifdef HAVE_STRINGS_H
123 # include <strings.h>
124 #endif
125 #ifdef HAVE_INTTYPES_H
126 # include <inttypes.h>
127 #endif
128 #ifdef HAVE_STDINT_H
129 # include <stdint.h>
130 #endif
131 #ifdef HAVE_UNISTD_H
132 # include <unistd.h>
133 #endif
134 
135 #ifdef HAVE_SYS_SELECT_H
136 # include <sys/select.h>
137 #endif
138 
139 #ifdef RUBY_USE_SETJMPEX
140 #include <setjmpex.h>
141 #endif
142 
143 #include "ruby/missing.h"
144 
145 #define RUBY
146 
147 #ifdef __cplusplus
148 # ifndef HAVE_PROTOTYPES
149 # define HAVE_PROTOTYPES 1
150 # endif
151 # ifndef HAVE_STDARG_PROTOTYPES
152 # define HAVE_STDARG_PROTOTYPES 1
153 # endif
154 #endif
155 
156 #undef _
157 #ifdef HAVE_PROTOTYPES
158 # define _(args) args
159 #else
160 # define _(args) ()
161 #endif
162 
163 #undef __
164 #ifdef HAVE_STDARG_PROTOTYPES
165 # define __(args) args
166 #else
167 # define __(args) ()
168 #endif
169 
170 #ifdef __cplusplus
171 #define ANYARGS ...
172 #else
173 #define ANYARGS
174 #endif
175 
176 #ifndef RUBY_SYMBOL_EXPORT_BEGIN
177 # define RUBY_SYMBOL_EXPORT_BEGIN /* begin */
178 # define RUBY_SYMBOL_EXPORT_END /* end */
179 #endif
180 
182 
183 #define xmalloc ruby_xmalloc
184 #define xmalloc2 ruby_xmalloc2
185 #define xcalloc ruby_xcalloc
186 #define xrealloc ruby_xrealloc
187 #define xrealloc2 ruby_xrealloc2
188 #define xfree ruby_xfree
189 
190 #if GCC_VERSION_SINCE(4,3,0)
191 # define RUBY_ATTR_ALLOC_SIZE(params) __attribute__ ((alloc_size params))
192 #else
193 # define RUBY_ATTR_ALLOC_SIZE(params)
194 #endif
195 
196 void *xmalloc(size_t) RUBY_ATTR_ALLOC_SIZE((1));
197 void *xmalloc2(size_t,size_t) RUBY_ATTR_ALLOC_SIZE((1,2));
198 void *xcalloc(size_t,size_t) RUBY_ATTR_ALLOC_SIZE((1,2));
199 void *xrealloc(void*,size_t) RUBY_ATTR_ALLOC_SIZE((2));
200 void *xrealloc2(void*,size_t,size_t) RUBY_ATTR_ALLOC_SIZE((2,3));
201 void xfree(void*);
202 
203 #define STRINGIZE(expr) STRINGIZE0(expr)
204 #ifndef STRINGIZE0
205 #define STRINGIZE0(expr) #expr
206 #endif
207 
208 #ifdef HAVE_LONG_LONG
209 # define HAVE_TRUE_LONG_LONG 1
210 #endif
211 
212 #if SIZEOF_LONG_LONG > 0
213 # define LONG_LONG long long
214 #elif SIZEOF___INT64 > 0
215 # define HAVE_LONG_LONG 1
216 # define LONG_LONG __int64
217 # undef SIZEOF_LONG_LONG
218 # define SIZEOF_LONG_LONG SIZEOF___INT64
219 #endif
220 
221 #ifdef __CYGWIN__
222 #undef _WIN32
223 #endif
224 
225 #if defined(_WIN32)
226 /*
227  DOSISH mean MS-Windows style filesystem.
228  But you should use more precise macros like DOSISH_DRIVE_LETTER, PATH_SEP,
229  ENV_IGNORECASE or CASEFOLD_FILESYSTEM.
230  */
231 #define DOSISH 1
232 # define DOSISH_DRIVE_LETTER
233 #endif
234 
235 #ifdef AC_APPLE_UNIVERSAL_BUILD
236 #undef WORDS_BIGENDIAN
237 #ifdef __BIG_ENDIAN__
238 #define WORDS_BIGENDIAN
239 #endif
240 #endif
241 
242 #ifdef _WIN32
243 #include "ruby/win32.h"
244 #endif
245 
246 #ifdef RUBY_EXPORT
247 #undef RUBY_EXTERN
248 
249 #ifndef FALSE
250 # define FALSE 0
251 #elif FALSE
252 # error FALSE must be false
253 #endif
254 #ifndef TRUE
255 # define TRUE 1
256 #elif !TRUE
257 # error TRUE must be true
258 #endif
259 
260 #endif
261 
262 #ifndef RUBY_FUNC_EXPORTED
263 #define RUBY_FUNC_EXPORTED
264 #endif
265 
266 #ifndef RUBY_EXTERN
267 #define RUBY_EXTERN extern
268 #endif
269 
270 #ifndef EXTERN
271 # if defined __GNUC__
272 # define EXTERN _Pragma("message \"EXTERN is deprecated, use RUBY_EXTERN instead\""); \
273  RUBY_EXTERN
274 # elif defined _MSC_VER
275 # define EXTERN __pragma(message(__FILE__"("STRINGIZE(__LINE__)"): warning: "\
276  "EXTERN is deprecated, use RUBY_EXTERN instead")); \
277  RUBY_EXTERN
278 # else
279 # define EXTERN <-<-"EXTERN is deprecated, use RUBY_EXTERN instead"->->
280 # endif
281 #endif
282 
283 #ifndef RUBY_MBCHAR_MAXSIZE
284 #define RUBY_MBCHAR_MAXSIZE INT_MAX
285  /* MB_CUR_MAX will not work well in C locale */
286 #endif
287 
288 #if defined(__sparc)
290 # define FLUSH_REGISTER_WINDOWS rb_sparc_flush_register_windows()
291 #elif defined(__ia64)
292 void *rb_ia64_bsp(void);
293 void rb_ia64_flushrs(void);
294 # define FLUSH_REGISTER_WINDOWS rb_ia64_flushrs()
295 #else
296 # define FLUSH_REGISTER_WINDOWS ((void)0)
297 #endif
298 
299 #if defined(DOSISH)
300 #define PATH_SEP ";"
301 #else
302 #define PATH_SEP ":"
303 #endif
304 #define PATH_SEP_CHAR PATH_SEP[0]
305 
306 #define PATH_ENV "PATH"
307 
308 #if defined(DOSISH)
309 #define ENV_IGNORECASE
310 #endif
311 
312 #ifndef CASEFOLD_FILESYSTEM
313 # if defined DOSISH
314 # define CASEFOLD_FILESYSTEM 1
315 # else
316 # define CASEFOLD_FILESYSTEM 0
317 # endif
318 #endif
319 
320 #ifndef DLEXT_MAXLEN
321 #define DLEXT_MAXLEN 4
322 #endif
323 
324 #ifndef RUBY_PLATFORM
325 #define RUBY_PLATFORM "unknown-unknown"
326 #endif
327 
328 #ifndef FUNC_MINIMIZED
329 #define FUNC_MINIMIZED(x) x
330 #endif
331 #ifndef FUNC_UNOPTIMIZED
332 #define FUNC_UNOPTIMIZED(x) x
333 #endif
334 #ifndef RUBY_ALIAS_FUNCTION_TYPE
335 #define RUBY_ALIAS_FUNCTION_TYPE(type, prot, name, args) \
336  FUNC_MINIMIZED(type prot) {return (type)name args;}
337 #endif
338 #ifndef RUBY_ALIAS_FUNCTION_VOID
339 #define RUBY_ALIAS_FUNCTION_VOID(prot, name, args) \
340  FUNC_MINIMIZED(void prot) {name args;}
341 #endif
342 #ifndef RUBY_ALIAS_FUNCTION
343 #define RUBY_ALIAS_FUNCTION(prot, name, args) \
344  RUBY_ALIAS_FUNCTION_TYPE(VALUE, prot, name, args)
345 #endif
346 
347 #ifndef UNALIGNED_WORD_ACCESS
348 # if defined(__i386) || defined(__i386__) || defined(_M_IX86) || \
349  defined(__x86_64) || defined(__x86_64__) || defined(_M_AMD64) || \
350  defined(__powerpc64__) || \
351  defined(__mc68020__)
352 # define UNALIGNED_WORD_ACCESS 1
353 # else
354 # define UNALIGNED_WORD_ACCESS 0
355 # endif
356 #endif
357 #ifndef PACKED_STRUCT
358 # define PACKED_STRUCT(x) x
359 #endif
360 #ifndef PACKED_STRUCT_UNALIGNED
361 # if UNALIGNED_WORD_ACCESS
362 # define PACKED_STRUCT_UNALIGNED(x) PACKED_STRUCT(x)
363 # else
364 # define PACKED_STRUCT_UNALIGNED(x) x
365 # endif
366 #endif
367 
369 
370 #if defined(__cplusplus)
371 #if 0
372 { /* satisfy cc-mode */
373 #endif
374 } /* extern "C" { */
375 #endif
376 
377 #endif /* RUBY_DEFINES_H */
#define xrealloc2
Definition: defines.h:187
#define xmalloc2
Definition: defines.h:184
#define RUBY_ATTR_ALLOC_SIZE(params)
Definition: defines.h:193
#define RUBY_SYMBOL_EXPORT_END
Definition: missing.h:49
#define RUBY_SYMBOL_EXPORT_BEGIN
Definition: missing.h:48
#define xfree
Definition: defines.h:188
#define xmalloc
Definition: defines.h:183
#define xrealloc
Definition: defines.h:186
void rb_sparc_flush_register_windows(void)
Definition: sparc.c:13
#define xcalloc
Definition: defines.h:185