Ruby 4.1.0dev (2026-12-06 revision 2c909473e0801d734f63591bb567e8d554c8a771)
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#ifndef __has_attribute
22# define __has_attribute(...) RBIMPL_HAS_ATTRIBUTE(__VA_ARGS__)
23#endif
24
25#ifndef __has_c_attribute
26# /* As of writing everything that lacks __has_c_attribute also completely
27# * lacks C2x attributes as well. Might change in future? */
28# define __has_c_attribute(...) 0
29#endif
30
31#ifndef __has_declspec_attribute
32# define __has_declspec_attribute(...) RBIMPL_HAS_DECLSPEC_ATTRIBUTE(__VA_ARGS__)
33#endif
34
35#ifndef __has_builtin
36# define __has_builtin(...) RBIMPL_HAS_BUILTIN(__VA_ARGS__)
37#endif
38
39#ifndef __has_feature
40# define __has_feature(...) RBIMPL_HAS_FEATURE(__VA_ARGS__)
41#endif
42
43#ifndef __has_extension
44# define __has_extension(...) RBIMPL_HAS_EXTENSION(__VA_ARGS__)
45#endif
46
47#ifndef __has_warning
48# define __has_warning(...) RBIMPL_HAS_WARNING(__VA_ARGS__)
49#endif
50
51#ifndef __GNUC__
52# define __extension__ /* void */
53#endif
54
55#ifndef MAYBE_UNUSED
56# define MAYBE_UNUSED(x) x
57#endif
58
59#ifndef WARN_UNUSED_RESULT
60# define WARN_UNUSED_RESULT(x) x
61#endif
62
63#define RB_OBJ_BUILTIN_TYPE(obj) rb_obj_builtin_type(obj)
64#define OBJ_BUILTIN_TYPE(obj) RB_OBJ_BUILTIN_TYPE(obj)
65#ifdef __GNUC__
66#define rb_obj_builtin_type(obj) \
67__extension__({ \
68 VALUE arg_obj = (obj); \
69 RB_SPECIAL_CONST_P(arg_obj) ? -1 : \
70 (int)RB_BUILTIN_TYPE(arg_obj); \
71 })
72#else
73# include "ruby/ruby.h"
74static inline int
75rb_obj_builtin_type(VALUE obj)
76{
77 return RB_SPECIAL_CONST_P(obj) ? -1 :
78 (int)RB_BUILTIN_TYPE(obj);
79}
80#endif
81
82/* A macro for defining a flexible array, like: VALUE ary[FLEX_ARY_LEN]; */
83#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || defined(_MSC_VER)
84# define FLEX_ARY_LEN /* VALUE ary[]; */
85#elif defined(__GNUC__) && !defined(__STRICT_ANSI__)
86# define FLEX_ARY_LEN 0 /* VALUE ary[0]; */
87#else
88# define FLEX_ARY_LEN 1 /* VALUE ary[1]; */
89#endif
90
91/*
92 * For declaring bitfields out of non-unsigned int types:
93 * struct date {
94 * BITFIELD(enum months, month, 4);
95 * ...
96 * };
97 */
98#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && !defined(_MSC_VER)
99# define BITFIELD(type, name, size) type name : size
100#else
101# define BITFIELD(type, name, size) unsigned int name : size
102#endif
103
104/*
105 * RUBY_DEBUG_EXPORT(name, target) gives `target`, a function or variable
106 * defined in the same file, the additional exported name `name`, so that
107 * tools outside the process, such as profilers, can still find it after
108 * libruby is stripped. Ruby itself keeps using `target`, so its generated
109 * code does not change. These names are best-effort debugging aids, not an
110 * API, and may change or disappear at any time.
111 */
112#if defined(__linux__) && defined(HAVE_ATTRIBUTE_FUNCTION_ALIAS)
113# define RUBY_DEBUG_EXPORT_DECL(decl, target) \
114 extern decl __attribute__((__alias__(STRINGIZE(target)), __visibility__("protected")));
115#else
116# define RUBY_DEBUG_EXPORT_DECL(decl, target) /* not supported */
117#endif
118#define RUBY_DEBUG_EXPORT(name, target) \
119 RUBY_DEBUG_EXPORT_DECL(__typeof__(target) name, target)
120#define RUBY_DEBUG_EXPORT_TLS(name, target) \
121 RUBY_DEBUG_EXPORT_DECL(RB_THREAD_LOCAL_SPECIFIER __typeof__(target) name, target)
122
123#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_FEATURE.
Defines RBIMPL_HAS_WARNING.
Defines RBIMPL_HAS_BUILTIN.
Defines RBIMPL_HAS_EXTENSION.
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:182