Ruby  2.7.1p83(2020-03-31revisiona0c7c23c9cec0d0ffcba012279cd652d28ad5bf3)
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 #ifndef DEPRECATED
33 # define DEPRECATED(x) x
34 #endif
35 #ifndef DEPRECATED_BY
36 # define DEPRECATED_BY(n,x) DEPRECATED(x)
37 #endif
38 #ifndef DEPRECATED_TYPE
39 # define DEPRECATED_TYPE(mesg, decl) decl
40 #endif
41 #ifndef RUBY_CXX_DEPRECATED
42 # define RUBY_CXX_DEPRECATED(mesg) /* nothing */
43 #endif
44 #ifndef NOINLINE
45 # define NOINLINE(x) x
46 #endif
47 #ifndef ALWAYS_INLINE
48 # define ALWAYS_INLINE(x) x
49 #endif
50 #ifndef ERRORFUNC
51 # define HAVE_ATTRIBUTE_ERRORFUNC 0
52 # define ERRORFUNC(mesg, x) x
53 #else
54 # define HAVE_ATTRIBUTE_ERRORFUNC 1
55 #endif
56 #ifndef WARNINGFUNC
57 # define HAVE_ATTRIBUTE_WARNINGFUNC 0
58 # define WARNINGFUNC(mesg, x) x
59 #else
60 # define HAVE_ATTRIBUTE_WARNINGFUNC 1
61 #endif
62 
63 #ifndef GCC_VERSION_SINCE
64 # if defined(__GNUC__) && !defined(__INTEL_COMPILER) && !defined(__clang__)
65 # define GCC_VERSION_SINCE(major, minor, patchlevel) \
66  ((__GNUC__ > (major)) || \
67  ((__GNUC__ == (major) && \
68  ((__GNUC_MINOR__ > (minor)) || \
69  (__GNUC_MINOR__ == (minor) && __GNUC_PATCHLEVEL__ >= (patchlevel))))))
70 # else
71 # define GCC_VERSION_SINCE(major, minor, patchlevel) 0
72 # endif
73 #endif
74 #ifndef GCC_VERSION_BEFORE
75 # if defined(__GNUC__) && !defined(__INTEL_COMPILER) && !defined(__clang__)
76 # define GCC_VERSION_BEFORE(major, minor, patchlevel) \
77  ((__GNUC__ < (major)) || \
78  ((__GNUC__ == (major) && \
79  ((__GNUC_MINOR__ < (minor)) || \
80  (__GNUC_MINOR__ == (minor) && __GNUC_PATCHLEVEL__ <= (patchlevel))))))
81 # else
82 # define GCC_VERSION_BEFORE(major, minor, patchlevel) 0
83 # endif
84 #endif
85 
86 /* likely */
87 #if __GNUC__ >= 3
88 #define RB_LIKELY(x) (__builtin_expect(!!(x), 1))
89 #define RB_UNLIKELY(x) (__builtin_expect(!!(x), 0))
90 #else /* __GNUC__ >= 3 */
91 #define RB_LIKELY(x) (x)
92 #define RB_UNLIKELY(x) (x)
93 #endif /* __GNUC__ >= 3 */
94 
95 /*
96  cold attribute for code layout improvements
97  RUBY_FUNC_ATTRIBUTE not used because MSVC does not like nested func macros
98  */
99 #if defined(__clang__) || GCC_VERSION_SINCE(4, 3, 0)
100 #define COLDFUNC __attribute__((cold))
101 #else
102 #define COLDFUNC
103 #endif
104 
105 #ifdef __GNUC__
106 #if defined __MINGW_PRINTF_FORMAT
107 #define PRINTF_ARGS(decl, string_index, first_to_check) \
108  decl __attribute__((format(__MINGW_PRINTF_FORMAT, string_index, first_to_check)))
109 #else
110 #define PRINTF_ARGS(decl, string_index, first_to_check) \
111  decl __attribute__((format(printf, string_index, first_to_check)))
112 #endif
113 #else
114 #define PRINTF_ARGS(decl, string_index, first_to_check) decl
115 #endif
116 
117 #ifdef __GNUC__
118 #define RB_GNUC_EXTENSION __extension__
119 #define RB_GNUC_EXTENSION_BLOCK(x) __extension__ ({ x; })
120 #else
121 #define RB_GNUC_EXTENSION
122 #define RB_GNUC_EXTENSION_BLOCK(x) (x)
123 #endif
124 
125 /* AC_INCLUDES_DEFAULT */
126 #include <stdio.h>
127 #ifdef HAVE_SYS_TYPES_H
128 # include <sys/types.h>
129 #endif
130 #ifdef HAVE_SYS_STAT_H
131 # include <sys/stat.h>
132 #endif
133 #ifdef STDC_HEADERS
134 # include <stdlib.h>
135 # include <stddef.h>
136 #else
137 # ifdef HAVE_STDLIB_H
138 # include <stdlib.h>
139 # endif
140 #endif
141 #ifdef HAVE_STRING_H
142 # if !defined STDC_HEADERS && defined HAVE_MEMORY_H
143 # include <memory.h>
144 # endif
145 # include <string.h>
146 #endif
147 #ifdef HAVE_STRINGS_H
148 # include <strings.h>
149 #endif
150 #ifdef HAVE_INTTYPES_H
151 # include <inttypes.h>
152 #endif
153 #ifdef HAVE_STDINT_H
154 # include <stdint.h>
155 #endif
156 #ifdef HAVE_STDALIGN_H
157 # include <stdalign.h>
158 #endif
159 #ifdef HAVE_UNISTD_H
160 # include <unistd.h>
161 #endif
162 
163 #ifdef HAVE_SYS_SELECT_H
164 # include <sys/select.h>
165 #endif
166 
167 #ifdef RUBY_USE_SETJMPEX
168 #include <setjmpex.h>
169 #endif
170 
171 #include "ruby/missing.h"
172 
173 #define RUBY
174 
175 #ifdef __cplusplus
176 # ifndef HAVE_PROTOTYPES
177 # define HAVE_PROTOTYPES 1
178 # endif
179 # ifndef HAVE_STDARG_PROTOTYPES
180 # define HAVE_STDARG_PROTOTYPES 1
181 # endif
182 #endif
183 
184 #undef _
185 #ifdef HAVE_PROTOTYPES
186 # define _(args) args
187 #else
188 # define _(args) ()
189 #endif
190 
191 #undef __
192 #ifdef HAVE_STDARG_PROTOTYPES
193 # define __(args) args
194 #else
195 # define __(args) ()
196 #endif
197 
198 #ifdef __cplusplus
199 #define ANYARGS ...
200 #else
201 #define ANYARGS
202 #endif
203 
204 #ifndef RUBY_SYMBOL_EXPORT_BEGIN
205 # define RUBY_SYMBOL_EXPORT_BEGIN /* begin */
206 # define RUBY_SYMBOL_EXPORT_END /* end */
207 #endif
208 
210 
211 #define xmalloc ruby_xmalloc
212 #define xmalloc2 ruby_xmalloc2
213 #define xcalloc ruby_xcalloc
214 #define xrealloc ruby_xrealloc
215 #define xrealloc2 ruby_xrealloc2
216 #define xfree ruby_xfree
217 
218 #if GCC_VERSION_SINCE(4,3,0)
219 # define RUBY_ATTR_ALLOC_SIZE(params) __attribute__ ((alloc_size params))
220 #elif defined(__has_attribute)
221 # if __has_attribute(alloc_size)
222 # define RUBY_ATTR_ALLOC_SIZE(params) __attribute__((__alloc_size__ params))
223 # endif
224 #endif
225 #ifndef RUBY_ATTR_ALLOC_SIZE
226 # define RUBY_ATTR_ALLOC_SIZE(params)
227 #endif
228 
229 #ifdef __has_attribute
230 # if __has_attribute(malloc)
231 # define RUBY_ATTR_MALLOC __attribute__((__malloc__))
232 # endif
233 #endif
234 #ifndef RUBY_ATTR_MALLOC
235 # define RUBY_ATTR_MALLOC
236 #endif
237 
238 #ifdef __has_attribute
239 # if __has_attribute(returns_nonnull)
240 # define RUBY_ATTR_RETURNS_NONNULL __attribute__((__returns_nonnull__))
241 # endif
242 #endif
243 #ifndef RUBY_ATTR_RETURNS_NONNULL
244 # define RUBY_ATTR_RETURNS_NONNULL
245 #endif
246 
251 void *ruby_xrealloc2(void*,size_t,size_t) RUBY_ATTR_RETURNS_NONNULL RUBY_ATTR_ALLOC_SIZE((2,3));
252 void ruby_xfree(void*);
253 
254 #ifndef USE_GC_MALLOC_OBJ_INFO_DETAILS
255 #define USE_GC_MALLOC_OBJ_INFO_DETAILS 0
256 #endif
257 
258 #if USE_GC_MALLOC_OBJ_INFO_DETAILS
259 
264 void *ruby_xrealloc2_body(void*,size_t,size_t) RUBY_ATTR_RETURNS_NONNULL RUBY_ATTR_ALLOC_SIZE((2,3));
265 
266 #define ruby_xmalloc(s1) ruby_xmalloc_with_location(s1, __FILE__, __LINE__)
267 #define ruby_xmalloc2(s1, s2) ruby_xmalloc2_with_location(s1, s2, __FILE__, __LINE__)
268 #define ruby_xcalloc(s1, s2) ruby_xcalloc_with_location(s1, s2, __FILE__, __LINE__)
269 #define ruby_xrealloc(ptr, s1) ruby_xrealloc_with_location(ptr, s1, __FILE__, __LINE__)
270 #define ruby_xrealloc2(ptr, s1, s2) ruby_xrealloc2_with_location(ptr, s1, s2, __FILE__, __LINE__)
271 
272 extern const char *ruby_malloc_info_file;
273 extern int ruby_malloc_info_line;
274 
275 static inline void *
276 ruby_xmalloc_with_location(size_t s, const char *file, int line)
277 {
278  void *ptr;
279  ruby_malloc_info_file = file;
280  ruby_malloc_info_line = line;
281  ptr = ruby_xmalloc_body(s);
282  ruby_malloc_info_file = NULL;
283  return ptr;
284 }
285 
286 static inline void *
287 ruby_xmalloc2_with_location(size_t s1, size_t s2, const char *file, int line)
288 {
289  void *ptr;
290  ruby_malloc_info_file = file;
291  ruby_malloc_info_line = line;
292  ptr = ruby_xmalloc2_body(s1, s2);
293  ruby_malloc_info_file = NULL;
294  return ptr;
295 }
296 
297 static inline void *
298 ruby_xcalloc_with_location(size_t s1, size_t s2, const char *file, int line)
299 {
300  void *ptr;
301  ruby_malloc_info_file = file;
302  ruby_malloc_info_line = line;
303  ptr = ruby_xcalloc_body(s1, s2);
304  ruby_malloc_info_file = NULL;
305  return ptr;
306 }
307 
308 static inline void *
309 ruby_xrealloc_with_location(void *ptr, size_t s, const char *file, int line)
310 {
311  void *rptr;
312  ruby_malloc_info_file = file;
313  ruby_malloc_info_line = line;
314  rptr = ruby_xrealloc_body(ptr, s);
315  ruby_malloc_info_file = NULL;
316  return rptr;
317 }
318 
319 static inline void *
320 ruby_xrealloc2_with_location(void *ptr, size_t s1, size_t s2, const char *file, int line)
321 {
322  void *rptr;
323  ruby_malloc_info_file = file;
324  ruby_malloc_info_line = line;
325  rptr = ruby_xrealloc2_body(ptr, s1, s2);
326  ruby_malloc_info_file = NULL;
327  return rptr;
328 }
329 #endif
330 
331 #define STRINGIZE(expr) STRINGIZE0(expr)
332 #ifndef STRINGIZE0
333 #define STRINGIZE0(expr) #expr
334 #endif
335 
336 #ifdef HAVE_LONG_LONG
337 # define HAVE_TRUE_LONG_LONG 1
338 #endif
339 
340 #if SIZEOF_LONG_LONG > 0
341 # define LONG_LONG long long
342 #elif SIZEOF___INT64 > 0
343 # define HAVE_LONG_LONG 1
344 # define LONG_LONG __int64
345 # undef SIZEOF_LONG_LONG
346 # define SIZEOF_LONG_LONG SIZEOF___INT64
347 #endif
348 
349 #ifdef __CYGWIN__
350 #undef _WIN32
351 #endif
352 
353 #if defined(_WIN32)
354 /*
355  DOSISH mean MS-Windows style filesystem.
356  But you should use more precise macros like DOSISH_DRIVE_LETTER, PATH_SEP,
357  ENV_IGNORECASE or CASEFOLD_FILESYSTEM.
358  */
359 #define DOSISH 1
360 # define DOSISH_DRIVE_LETTER
361 #endif
362 
363 #ifdef AC_APPLE_UNIVERSAL_BUILD
364 #undef WORDS_BIGENDIAN
365 #ifdef __BIG_ENDIAN__
366 #define WORDS_BIGENDIAN
367 #endif
368 #endif
369 
370 #ifdef _WIN32
371 #include "ruby/win32.h"
372 #endif
373 
374 #ifdef RUBY_EXPORT
375 #undef RUBY_EXTERN
376 
377 #ifndef FALSE
378 # define FALSE 0
379 #elif FALSE
380 # error FALSE must be false
381 #endif
382 #ifndef TRUE
383 # define TRUE 1
384 #elif !TRUE
385 # error TRUE must be true
386 #endif
387 
388 #endif
389 
390 #ifndef RUBY_FUNC_EXPORTED
391 #define RUBY_FUNC_EXPORTED
392 #endif
393 
394 /* These macros are used for functions which are exported only for MJIT
395  and NOT ensured to be exported in future versions. */
396 #define MJIT_FUNC_EXPORTED RUBY_FUNC_EXPORTED
397 #define MJIT_SYMBOL_EXPORT_BEGIN RUBY_SYMBOL_EXPORT_BEGIN
398 #define MJIT_SYMBOL_EXPORT_END RUBY_SYMBOL_EXPORT_END
399 
400 #if defined(MJIT_HEADER) && defined(_MSC_VER)
401 # undef MJIT_FUNC_EXPORTED
402 # define MJIT_FUNC_EXPORTED static
403 #endif
404 
405 #ifndef RUBY_EXTERN
406 #define RUBY_EXTERN extern
407 #endif
408 
409 #ifndef EXTERN
410 # if defined __GNUC__
411 # define EXTERN _Pragma("message \"EXTERN is deprecated, use RUBY_EXTERN instead\""); \
412  RUBY_EXTERN
413 # elif defined _MSC_VER
414 # define EXTERN __pragma(message(__FILE__"("STRINGIZE(__LINE__)"): warning: "\
415  "EXTERN is deprecated, use RUBY_EXTERN instead")); \
416  RUBY_EXTERN
417 # else
418 # define EXTERN <-<-"EXTERN is deprecated, use RUBY_EXTERN instead"->->
419 # endif
420 #endif
421 
422 #ifndef RUBY_MBCHAR_MAXSIZE
423 #define RUBY_MBCHAR_MAXSIZE INT_MAX
424  /* MB_CUR_MAX will not work well in C locale */
425 #endif
426 
427 #if defined(__sparc)
429 # define FLUSH_REGISTER_WINDOWS rb_sparc_flush_register_windows()
430 #else
431 # define FLUSH_REGISTER_WINDOWS ((void)0)
432 #endif
433 
434 #if defined(DOSISH)
435 #define PATH_SEP ";"
436 #else
437 #define PATH_SEP ":"
438 #endif
439 #define PATH_SEP_CHAR PATH_SEP[0]
440 
441 #define PATH_ENV "PATH"
442 
443 #if defined(DOSISH)
444 #define ENV_IGNORECASE
445 #endif
446 
447 #ifndef CASEFOLD_FILESYSTEM
448 # if defined DOSISH
449 # define CASEFOLD_FILESYSTEM 1
450 # else
451 # define CASEFOLD_FILESYSTEM 0
452 # endif
453 #endif
454 
455 #ifndef DLEXT_MAXLEN
456 #define DLEXT_MAXLEN 4
457 #endif
458 
459 #ifndef RUBY_PLATFORM
460 #define RUBY_PLATFORM "unknown-unknown"
461 #endif
462 
463 #ifndef FUNC_MINIMIZED
464 #define FUNC_MINIMIZED(x) x
465 #endif
466 #ifndef FUNC_UNOPTIMIZED
467 #define FUNC_UNOPTIMIZED(x) x
468 #endif
469 #ifndef RUBY_ALIAS_FUNCTION_TYPE
470 #define RUBY_ALIAS_FUNCTION_TYPE(type, prot, name, args) \
471  FUNC_MINIMIZED(type prot) {return (type)name args;}
472 #endif
473 #ifndef RUBY_ALIAS_FUNCTION_VOID
474 #define RUBY_ALIAS_FUNCTION_VOID(prot, name, args) \
475  FUNC_MINIMIZED(void prot) {name args;}
476 #endif
477 #ifndef RUBY_ALIAS_FUNCTION
478 #define RUBY_ALIAS_FUNCTION(prot, name, args) \
479  RUBY_ALIAS_FUNCTION_TYPE(VALUE, prot, name, args)
480 #endif
481 #ifndef RUBY_FUNC_NONNULL
482 #define RUBY_FUNC_NONNULL(n, x) x
483 #endif
484 
485 #ifndef UNALIGNED_WORD_ACCESS
486 # if defined(__i386) || defined(__i386__) || defined(_M_IX86) || \
487  defined(__x86_64) || defined(__x86_64__) || defined(_M_AMD64) || \
488  defined(__powerpc64__) || \
489  defined(__mc68020__)
490 # define UNALIGNED_WORD_ACCESS 1
491 # else
492 # define UNALIGNED_WORD_ACCESS 0
493 # endif
494 #endif
495 #ifndef PACKED_STRUCT
496 # define PACKED_STRUCT(x) x
497 #endif
498 #ifndef PACKED_STRUCT_UNALIGNED
499 # if UNALIGNED_WORD_ACCESS
500 # define PACKED_STRUCT_UNALIGNED(x) PACKED_STRUCT(x)
501 # else
502 # define PACKED_STRUCT_UNALIGNED(x) x
503 # endif
504 #endif
505 
506 #ifndef RUBY_ALIGNAS
507 #define RUBY_ALIGNAS(x) /* x */
508 #endif
509 
510 #ifdef RUBY_ALIGNOF
511 /* OK, take that definition */
512 #elif defined(__cplusplus) && (__cplusplus >= 201103L)
513 #define RUBY_ALIGNOF alignof
514 #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
515 #define RUBY_ALIGNOF _Alignof
516 #else
517 #define RUBY_ALIGNOF(type) ((size_t)offsetof(struct { char f1; type f2; }, f2))
518 #endif
519 
520 #define NORETURN_STYLE_NEW 1
521 #ifdef NORETURN
522 /* OK, take that definition */
523 #elif defined(__cplusplus) && (__cplusplus >= 201103L)
524 #define NORETURN(x) [[ noreturn ]] x
525 #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
526 #define NORETURN(x) _Noreturn x
527 #else
528 #define NORETURN(x) x
529 #endif
530 
532 
533 #if defined(__cplusplus)
534 #if 0
535 { /* satisfy cc-mode */
536 #endif
537 } /* extern "C" { */
538 #endif
539 
540 #endif /* RUBY_DEFINES_H */
RUBY_SYMBOL_EXPORT_END
#define RUBY_SYMBOL_EXPORT_END
Definition: missing.h:49
win32.h
ruby_xfree
void void ruby_xfree(void *)
Definition: gc.c:10169
RUBY_ATTR_ALLOC_SIZE
#define RUBY_ATTR_ALLOC_SIZE(params)
Definition: defines.h:226
ruby_xrealloc_body
void * ruby_xrealloc_body(void *ptr, size_t new_size)
Definition: gc.c:10136
ruby_xmalloc
void * ruby_xmalloc(size_t) RUBY_ATTR_MALLOC RUBY_ATTR_RETURNS_NONNULL RUBY_ATTR_ALLOC_SIZE((1))
Definition: gc.c:11969
ptr
struct RIMemo * ptr
Definition: debug.c:74
ruby_xmalloc_body
void * ruby_xmalloc_body(size_t size)
Definition: gc.c:10084
NULL
#define NULL
Definition: _sdbm.c:101
ruby_xrealloc2
void * ruby_xrealloc2(void *, size_t, size_t) RUBY_ATTR_RETURNS_NONNULL RUBY_ATTR_ALLOC_SIZE((2
ruby_xmalloc2
void * ruby_xmalloc2(size_t, size_t) RUBY_ATTR_MALLOC RUBY_ATTR_RETURNS_NONNULL RUBY_ATTR_ALLOC_SIZE((1
rb_sparc_flush_register_windows
void rb_sparc_flush_register_windows(void)
Definition: sparc.c:13
s2
const char * s2
Definition: rb_mjit_min_header-2.7.1.h:5415
ruby_xcalloc_body
void * ruby_xcalloc_body(size_t n, size_t size)
Definition: gc.c:10117
RUBY_ATTR_RETURNS_NONNULL
#define RUBY_ATTR_RETURNS_NONNULL
Definition: defines.h:244
ruby_xmalloc2_body
void * ruby_xmalloc2_body(size_t n, size_t size)
Definition: gc.c:10101
missing.h
RUBY_SYMBOL_EXPORT_BEGIN
#define RUBY_SYMBOL_EXPORT_BEGIN
Definition: missing.h:48
ruby_xrealloc
void void void * ruby_xrealloc(void *, size_t) RUBY_ATTR_RETURNS_NONNULL RUBY_ATTR_ALLOC_SIZE((2))
Definition: gc.c:11999
RUBY_ATTR_MALLOC
#define RUBY_ATTR_MALLOC
Definition: defines.h:235
ruby_xrealloc2_body
void * ruby_xrealloc2_body(void *ptr, size_t n, size_t size)
Definition: gc.c:10152
ruby_xcalloc
void void * ruby_xcalloc(size_t, size_t) RUBY_ATTR_MALLOC RUBY_ATTR_RETURNS_NONNULL RUBY_ATTR_ALLOC_SIZE((1