Ruby 4.1.0dev (2026-09-26 revision 227006291d35b2255b3f7a888d75102c129b0472)
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#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