Ruby  3.1.4p223 (2023-03-30 revision HEAD)
compilers.h
1 #ifndef INTERNAL_COMPILERS_H /*-*-C-*-vi:se ft=c:*/
2 #define INTERNAL_COMPILERS_H
19 #include "ruby/backward/2/gcc_version_since.h"
20 
21 #define MSC_VERSION_SINCE(_) RBIMPL_COMPILER_SINCE(MSVC, (_) / 100, (_) % 100, 0)
22 #define MSC_VERSION_BEFORE(_) RBIMPL_COMPILER_BEFORE(MSVC, (_) / 100, (_) % 100, 0)
23 
24 #ifndef __has_attribute
25 # define __has_attribute(...) RBIMPL_HAS_ATTRIBUTE(__VA_ARGS__)
26 #endif
27 
28 #ifndef __has_c_attribute
29 # /* As of writing everything that lacks __has_c_attribute also completely
30 # * lacks C2x attributes as well. Might change in future? */
31 # define __has_c_attribute(...) 0
32 #endif
33 
34 #ifndef __has_declspec_attribute
35 # define __has_declspec_attribute(...) RBIMPL_HAS_DECLSPEC_ATTRIBUTE(__VA_ARGS__)
36 #endif
37 
38 #ifndef __has_builtin
39 # define __has_builtin(...) RBIMPL_HAS_BUILTIN(__VA_ARGS__)
40 #endif
41 
42 #ifndef __has_feature
43 # define __has_feature(...) RBIMPL_HAS_FEATURE(__VA_ARGS__)
44 #endif
45 
46 #ifndef __has_extension
47 # define __has_extension(...) RBIMPL_HAS_EXTENSION(__VA_ARGS__)
48 #endif
49 
50 #ifndef __has_warning
51 # define __has_warning(...) RBIMPL_HAS_WARNING(__VA_ARGS__)
52 #endif
53 
54 #ifndef __GNUC__
55 # define __extension__ /* void */
56 #endif
57 
58 #ifndef MAYBE_UNUSED
59 # define MAYBE_UNUSED(x) x
60 #endif
61 
62 #ifndef WARN_UNUSED_RESULT
63 # define WARN_UNUSED_RESULT(x) x
64 #endif
65 
66 #define RB_OBJ_BUILTIN_TYPE(obj) rb_obj_builtin_type(obj)
67 #define OBJ_BUILTIN_TYPE(obj) RB_OBJ_BUILTIN_TYPE(obj)
68 #ifdef __GNUC__
69 #define rb_obj_builtin_type(obj) \
70 __extension__({ \
71  VALUE arg_obj = (obj); \
72  RB_SPECIAL_CONST_P(arg_obj) ? -1 : \
73  (int)RB_BUILTIN_TYPE(arg_obj); \
74  })
75 #else
76 # include "ruby/ruby.h"
77 static inline int
78 rb_obj_builtin_type(VALUE obj)
79 {
80  return RB_SPECIAL_CONST_P(obj) ? -1 :
81  (int)RB_BUILTIN_TYPE(obj);
82 }
83 #endif
84 
85 /* A macro for defining a flexible array, like: VALUE ary[FLEX_ARY_LEN]; */
86 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
87 # define FLEX_ARY_LEN /* VALUE ary[]; */
88 #elif defined(__GNUC__) && !defined(__STRICT_ANSI__)
89 # define FLEX_ARY_LEN 0 /* VALUE ary[0]; */
90 #else
91 # define FLEX_ARY_LEN 1 /* VALUE ary[1]; */
92 #endif
93 
94 /*
95  * For declaring bitfields out of non-unsigned int types:
96  * struct date {
97  * BITFIELD(enum months, month, 4);
98  * ...
99  * };
100  */
101 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
102 # define BITFIELD(type, name, size) type name : size
103 #else
104 # define BITFIELD(type, name, size) unsigned int name : size
105 #endif
106 
107 #endif /* INTERNAL_COMPILERS_H */
Defines RBIMPL_HAS_ATTRIBUTE.
Defines RBIMPL_HAS_C_ATTRIBUTE.
Defines RBIMPL_COMPILER_SINCE.
Defines RBIMPL_HAS_DECLSPEC_ATTRIBUTE.
Defines RBIMPL_HAS_EXTENSION.
Defines RBIMPL_HAS_FEATURE.
Defines RBIMPL_HAS_WARNING.
Defines RBIMPL_HAS_BUILTIN.
static bool RB_SPECIAL_CONST_P(VALUE obj)
Checks if the given object is of enum ruby_special_consts.
uintptr_t VALUE
Type that represents a Ruby object.
Definition: value.h:40
static enum ruby_value_type RB_BUILTIN_TYPE(VALUE obj)
Queries the type of the object.
Definition: value_type.h:181