Ruby 4.0.5p0 (2026-05-20 revision 64336ffd0ee9e1f4c05891695a3d7b49cb709721)
fl_type.h
Go to the documentation of this file.
1#ifndef RBIMPL_FL_TYPE_H /*-*-C++-*-vi:se ft=cpp:*/
2#define RBIMPL_FL_TYPE_H
23#include "ruby/internal/config.h" /* for ENUM_OVER_INT */
30#include "ruby/internal/cast.h"
37#include "ruby/internal/value.h"
39#include "ruby/assert.h"
40#include "ruby/defines.h"
41
43#if RBIMPL_HAS_EXTENSION(enumerator_attributes)
44# define RBIMPL_HAVE_ENUM_ATTRIBUTE 1
45#elif RBIMPL_COMPILER_SINCE(GCC, 6, 0, 0)
46# define RBIMPL_HAVE_ENUM_ATTRIBUTE 1
47#endif
48
49#ifdef ENUM_OVER_INT
50# define RBIMPL_WIDER_ENUM 1
51#elif SIZEOF_INT * CHAR_BIT > 12+19+1
52# define RBIMPL_WIDER_ENUM 1
53#else
54# define RBIMPL_WIDER_ENUM 0
55#endif
57
58#define FL_SINGLETON RBIMPL_CAST((VALUE)RUBY_FL_SINGLETON)
59#define FL_WB_PROTECTED RBIMPL_CAST((VALUE)RUBY_FL_WB_PROTECTED)
60#define FL_PROMOTED RBIMPL_CAST((VALUE)RUBY_FL_PROMOTED)
61#define FL_FINALIZE RBIMPL_CAST((VALUE)RUBY_FL_FINALIZE)
62#define FL_TAINT RBIMPL_CAST((VALUE)RUBY_FL_TAINT)
63#define FL_SHAREABLE RBIMPL_CAST((VALUE)RUBY_FL_SHAREABLE)
64#define FL_UNTRUSTED RBIMPL_CAST((VALUE)RUBY_FL_UNTRUSTED)
65#define FL_EXIVAR RBIMPL_CAST((VALUE)RUBY_FL_EXIVAR)
66#define FL_FREEZE RBIMPL_CAST((VALUE)RUBY_FL_FREEZE)
67
68#define FL_USHIFT RBIMPL_CAST((VALUE)RUBY_FL_USHIFT)
69
70#define FL_USER0 RBIMPL_CAST((VALUE)RUBY_FL_USER0)
71#define FL_USER1 RBIMPL_CAST((VALUE)RUBY_FL_USER1)
72#define FL_USER2 RBIMPL_CAST((VALUE)RUBY_FL_USER2)
73#define FL_USER3 RBIMPL_CAST((VALUE)RUBY_FL_USER3)
74#define FL_USER4 RBIMPL_CAST((VALUE)RUBY_FL_USER4)
75#define FL_USER5 RBIMPL_CAST((VALUE)RUBY_FL_USER5)
76#define FL_USER6 RBIMPL_CAST((VALUE)RUBY_FL_USER6)
77#define FL_USER7 RBIMPL_CAST((VALUE)RUBY_FL_USER7)
78#define FL_USER8 RBIMPL_CAST((VALUE)RUBY_FL_USER8)
79#define FL_USER9 RBIMPL_CAST((VALUE)RUBY_FL_USER9)
80#define FL_USER10 RBIMPL_CAST((VALUE)RUBY_FL_USER10)
81#define FL_USER11 RBIMPL_CAST((VALUE)RUBY_FL_USER11)
82#define FL_USER12 RBIMPL_CAST((VALUE)RUBY_FL_USER12)
83#define FL_USER13 RBIMPL_CAST((VALUE)RUBY_FL_USER13)
84#define FL_USER14 RBIMPL_CAST((VALUE)RUBY_FL_USER14)
85#define FL_USER15 RBIMPL_CAST((VALUE)RUBY_FL_USER15)
86#define FL_USER16 RBIMPL_CAST((VALUE)RUBY_FL_USER16)
87#define FL_USER17 RBIMPL_CAST((VALUE)RUBY_FL_USER17)
88#define FL_USER18 RBIMPL_CAST((VALUE)RUBY_FL_USER18)
89#define FL_USER19 RBIMPL_CAST((VALUE)(unsigned int)RUBY_FL_USER19)
90
91#define ELTS_SHARED RUBY_ELTS_SHARED
92#define RB_OBJ_FREEZE rb_obj_freeze_inline
93
95#define RUBY_ELTS_SHARED RUBY_ELTS_SHARED
96#define RB_FL_ABLE RB_FL_ABLE
97#define RB_FL_ALL RB_FL_ALL
98#define RB_FL_ALL_RAW RB_FL_ALL_RAW
99#define RB_FL_ANY RB_FL_ANY
100#define RB_FL_ANY_RAW RB_FL_ANY_RAW
101#define RB_FL_REVERSE RB_FL_REVERSE
102#define RB_FL_REVERSE_RAW RB_FL_REVERSE_RAW
103#define RB_FL_SET RB_FL_SET
104#define RB_FL_SET_RAW RB_FL_SET_RAW
105#define RB_FL_TEST RB_FL_TEST
106#define RB_FL_TEST_RAW RB_FL_TEST_RAW
107#define RB_FL_UNSET RB_FL_UNSET
108#define RB_FL_UNSET_RAW RB_FL_UNSET_RAW
109#define RB_OBJ_FREEZE_RAW RB_OBJ_FREEZE_RAW
110#define RB_OBJ_FROZEN RB_OBJ_FROZEN
111#define RB_OBJ_FROZEN_RAW RB_OBJ_FROZEN_RAW
112#define RB_OBJ_UNTRUST RB_OBJ_TAINT
113#define RB_OBJ_UNTRUSTED RB_OBJ_TAINTED
115
121#define FL_ABLE RB_FL_ABLE
122#define FL_ALL RB_FL_ALL
123#define FL_ALL_RAW RB_FL_ALL_RAW
124#define FL_ANY RB_FL_ANY
125#define FL_ANY_RAW RB_FL_ANY_RAW
126#define FL_REVERSE RB_FL_REVERSE
127#define FL_REVERSE_RAW RB_FL_REVERSE_RAW
128#define FL_SET RB_FL_SET
129#define FL_SET_RAW RB_FL_SET_RAW
130#define FL_TEST RB_FL_TEST
131#define FL_TEST_RAW RB_FL_TEST_RAW
132#define FL_UNSET RB_FL_UNSET
133#define FL_UNSET_RAW RB_FL_UNSET_RAW
134#define OBJ_FREEZE RB_OBJ_FREEZE
135#define OBJ_FREEZE_RAW RB_OBJ_FREEZE_RAW
136#define OBJ_FROZEN RB_OBJ_FROZEN
137#define OBJ_FROZEN_RAW RB_OBJ_FROZEN_RAW
138#define OBJ_INFECT RB_OBJ_INFECT
139#define OBJ_INFECT_RAW RB_OBJ_INFECT_RAW
140#define OBJ_TAINT RB_OBJ_TAINT
141#define OBJ_TAINTABLE RB_OBJ_TAINTABLE
142#define OBJ_TAINTED RB_OBJ_TAINTED
143#define OBJ_TAINTED_RAW RB_OBJ_TAINTED_RAW
144#define OBJ_TAINT_RAW RB_OBJ_TAINT_RAW
145#define OBJ_UNTRUST RB_OBJ_UNTRUST
146#define OBJ_UNTRUSTED RB_OBJ_UNTRUSTED
148
160
161/* > The expression that defines the value of an enumeration constant shall be
162 * > an integer constant expression that has a value representable as an `int`.
163 *
164 * -- ISO/IEC 9899:2018 section 6.7.2.2
165 *
166 * So ENUM_OVER_INT situation is an extension to the standard. Note however
167 * that we do not support 16 bit `int` environment. */
182enum
185
199
218
225
239
246
247#if defined(RBIMPL_HAVE_ENUM_ATTRIBUTE)
248 RBIMPL_ATTR_DEPRECATED(("taintedness turned out to be a wrong idea."))
249#elif defined(_MSC_VER)
250# pragma deprecated(RUBY_FL_TAINT)
251#endif
252
253 = 0,
254
261
262#if defined(RBIMPL_HAVE_ENUM_ATTRIBUTE)
263 RBIMPL_ATTR_DEPRECATED(("FL_EXIVAR is an outdated implementation detail, it should not be used."))
264#elif defined(_MSC_VER)
265# pragma deprecated(RUBY_FL_EXIVAR)
266#endif
267
268 = 0,
269
281
288
289#if defined(RBIMPL_HAVE_ENUM_ATTRIBUTE)
290 RBIMPL_ATTR_DEPRECATED(("trustedness turned out to be a wrong idea."))
291#elif defined(_MSC_VER)
292# pragma deprecated(RUBY_FL_UNTRUSTED)
293#endif
294
295 = 0,
296
303
310
320 RUBY_FL_FREEZE = (1<<11),
321
323#define RBIMPL_FL_USER_N(n) RUBY_FL_USER##n = (1<<(RUBY_FL_USHIFT+n))
343#ifdef ENUM_OVER_INT
345#else
346# define RUBY_FL_USER19 (RBIMPL_VALUE_ONE<<(RUBY_FL_USHIFT+19))
347#endif
348#undef RBIMPL_FL_USER_N
349#undef RBIMPL_WIDER_ENUM
350
370
395};
396
397enum {
404
405#if defined(RBIMPL_HAVE_ENUM_ATTRIBUTE)
406 RBIMPL_ATTR_DEPRECATED(("It seems there is no actual usage of this enum."))
407#elif defined(_MSC_VER)
408# pragma deprecated(RUBY_FL_DUPPED)
409#endif
410
411 = (int)RUBY_T_MASK
412};
413
414#undef RBIMPL_HAVE_ENUM_ATTRIBUTE
415
426
439static bool
441{
442 if (RB_SPECIAL_CONST_P(obj)) {
443 return false;
444 }
445 else {
447 return true;
448 }
449}
450
462static inline VALUE
464{
466 return RBASIC(obj)->flags & flags;
467}
468
488static inline VALUE
490{
491 if (RB_FL_ABLE(obj)) {
492 return RB_FL_TEST_RAW(obj, flags);
493 }
494 else {
495 return RBIMPL_VALUE_NULL;
496 }
497}
498
511static inline bool
513{
514 return RB_FL_TEST_RAW(obj, flags);
515}
516
527static inline bool
529{
530 return RB_FL_TEST(obj, flags);
531}
532
545static inline bool
547{
548 return RB_FL_TEST_RAW(obj, flags) == flags;
549}
550
561static inline bool
563{
564 return RB_FL_TEST(obj, flags) == flags;
565}
566
584static inline void
585rbimpl_fl_set_raw_raw(struct RBasic *obj, VALUE flags)
586{
587 obj->flags |= flags;
588}
589
599static inline void
601{
603 rbimpl_fl_set_raw_raw(RBASIC(obj), flags);
604}
605
619static inline void
621{
622 if (RB_FL_ABLE(obj)) {
623 RB_FL_SET_RAW(obj, flags);
624 }
625}
626
644static inline void
645rbimpl_fl_unset_raw_raw(struct RBasic *obj, VALUE flags)
646{
647 obj->flags &= ~flags;
648}
649
659static inline void
661{
663 rbimpl_fl_unset_raw_raw(RBASIC(obj), flags);
664}
665
674static inline void
676{
677 if (RB_FL_ABLE(obj)) {
678 RB_FL_UNSET_RAW(obj, flags);
679 }
680}
681
699static inline void
700rbimpl_fl_reverse_raw_raw(struct RBasic *obj, VALUE flags)
701{
702 obj->flags ^= flags;
703}
704
714static inline void
716{
718 rbimpl_fl_reverse_raw_raw(RBASIC(obj), flags);
719}
720
730static inline void
732{
733 if (RB_FL_ABLE(obj)) {
734 RB_FL_REVERSE_RAW(obj, flags);
735 }
736}
737
740RBIMPL_ATTR_DEPRECATED(("taintedness turned out to be a wrong idea."))
749static inline bool
751{
752 (void)obj;
753 return false;
754}
755
758RBIMPL_ATTR_DEPRECATED(("taintedness turned out to be a wrong idea."))
767static inline VALUE
769{
770 (void)obj;
771 return false;
772}
773
776RBIMPL_ATTR_DEPRECATED(("taintedness turned out to be a wrong idea."))
785static inline bool
787{
788 (void)obj;
789 return false;
790}
791
793RBIMPL_ATTR_DEPRECATED(("taintedness turned out to be a wrong idea."))
801static inline void
803{
804 (void)obj;
805 return;
806}
807
809RBIMPL_ATTR_DEPRECATED(("taintedness turned out to be a wrong idea."))
817static inline void
819{
820 (void)obj;
821 return;
822}
823
825RBIMPL_ATTR_DEPRECATED(("taintedness turned out to be a wrong idea."))
834static inline void
836{
837 (void)dst;
838 (void)src;
839 return;
840}
841
843RBIMPL_ATTR_DEPRECATED(("taintedness turned out to be a wrong idea."))
852static inline void
854{
855 (void)dst;
856 (void)src;
857 return;
858}
859
876static inline VALUE
878{
879 return RB_FL_TEST_RAW(obj, RUBY_FL_FREEZE);
880}
881
891static inline bool
893{
894 if (! RB_FL_ABLE(obj)) {
895 return true;
896 }
897 else {
898 return RB_OBJ_FROZEN_RAW(obj);
899 }
900}
901
902RUBY_SYMBOL_EXPORT_BEGIN
912RUBY_SYMBOL_EXPORT_END
913
921static inline void
926
927#endif /* RBIMPL_FL_TYPE_H */
Defines RBIMPL_ATTR_ARTIFICIAL.
#define RBIMPL_ATTR_ARTIFICIAL()
Wraps (or simulates) __attribute__((artificial)).
Definition artificial.h:43
#define RBIMPL_ASSERT_OR_ASSUME(...)
This is either RUBY_ASSERT or RBIMPL_ASSUME, depending on RUBY_DEBUG.
Definition assert.h:311
Defines RBIMPL_COMPILER_SINCE.
Defines RBIMPL_ATTR_DEPRECATED.
#define RBIMPL_ATTR_DEPRECATED(msg)
Wraps (or simulates) [[deprecated]].
Definition deprecated.h:64
Tweaking visibility of C variables/functions.
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
Definition dllexport.h:74
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
Definition dllexport.h:65
@ RUBY_FL_DUPPED
Definition fl_type.h:403
ruby_fl_ushift
This is an enum because GDB wants it (rather than a macro).
Definition fl_type.h:153
@ RUBY_FL_USHIFT
Number of bits in ruby_fl_type that are not open to users.
Definition fl_type.h:158
static VALUE RB_OBJ_FROZEN_RAW(VALUE obj)
This is an implementation detail of RB_OBJ_FROZEN().
Definition fl_type.h:877
static bool RB_OBJ_TAINTABLE(VALUE obj)
Definition fl_type.h:750
static VALUE RB_FL_TEST(VALUE obj, VALUE flags)
Tests if the given flag(s) are set or not.
Definition fl_type.h:489
static VALUE RB_FL_TEST_RAW(VALUE obj, VALUE flags)
This is an implementation detail of RB_FL_TEST().
Definition fl_type.h:463
static bool RB_FL_ABLE(VALUE obj)
Checks if the object is flaggable.
Definition fl_type.h:440
static bool RB_FL_ANY_RAW(VALUE obj, VALUE flags)
This is an implementation detail of RB_FL_ANY().
Definition fl_type.h:512
static bool RB_FL_ANY(VALUE obj, VALUE flags)
Identical to RB_FL_TEST(), except it returns bool.
Definition fl_type.h:528
static void RB_FL_SET_RAW(VALUE obj, VALUE flags)
This is an implementation detail of RB_FL_SET().
Definition fl_type.h:600
static bool RB_FL_ALL(VALUE obj, VALUE flags)
Identical to RB_FL_ANY(), except it mandates all passed flags be set.
Definition fl_type.h:562
void rb_obj_freeze_inline(VALUE obj)
Prevents further modifications to the given object.
Definition variable.c:1991
static bool RB_OBJ_FROZEN(VALUE obj)
Checks if an object is frozen.
Definition fl_type.h:892
static bool RB_OBJ_TAINTED(VALUE obj)
Definition fl_type.h:786
static VALUE RB_OBJ_TAINTED_RAW(VALUE obj)
Definition fl_type.h:768
static void RB_OBJ_INFECT(VALUE dst, VALUE src)
Definition fl_type.h:853
static void RB_FL_UNSET_RAW(VALUE obj, VALUE flags)
This is an implementation detail of RB_FL_UNSET().
Definition fl_type.h:660
static void RB_FL_SET(VALUE obj, VALUE flags)
Sets the given flag(s).
Definition fl_type.h:620
static void RB_OBJ_INFECT_RAW(VALUE dst, VALUE src)
Definition fl_type.h:835
static void RB_FL_REVERSE(VALUE obj, VALUE flags)
Reverses the flags.
Definition fl_type.h:731
static void RB_FL_UNSET(VALUE obj, VALUE flags)
Clears the given flag(s).
Definition fl_type.h:675
static void RB_OBJ_FREEZE_RAW(VALUE obj)
This is an implementation detail of RB_OBJ_FREEZE().
Definition fl_type.h:922
static void RB_FL_REVERSE_RAW(VALUE obj, VALUE flags)
This is an implementation detail of RB_FL_REVERSE().
Definition fl_type.h:715
static bool RB_FL_ALL_RAW(VALUE obj, VALUE flags)
This is an implementation detail of RB_FL_ALL().
Definition fl_type.h:546
ruby_fl_type
The flags.
Definition fl_type.h:184
@ RUBY_ELTS_SHARED
This flag has something to do with data structures.
Definition fl_type.h:369
@ RUBY_FL_UNUSED10
This flag is no longer in use.
Definition fl_type.h:309
@ RUBY_FL_SINGLETON
This flag has something to do with an object's class.
Definition fl_type.h:394
@ RUBY_FL_TAINT
Definition fl_type.h:245
@ RUBY_FL_UNUSED9
This flag is no longer in use.
Definition fl_type.h:302
@ RUBY_FL_WB_PROTECTED
Definition fl_type.h:198
@ RUBY_FL_EXIVAR
Definition fl_type.h:260
@ RUBY_FL_UNTRUSTED
Definition fl_type.h:287
@ RUBY_FL_PROMOTED
Ruby objects are "generational".
Definition fl_type.h:217
@ RUBY_FL_USER0
User-defined flag.
Definition fl_type.h:324
@ RUBY_FL_FREEZE
This flag has something to do with data immutability.
Definition fl_type.h:320
@ RUBY_FL_USERPRIV0
This flag meaning is type dependent, currently only used by T_DATA.
Definition fl_type.h:224
@ RUBY_FL_USER1
User-defined flag.
Definition fl_type.h:325
@ RUBY_FL_SHAREABLE
This flag has something to do with Ractor.
Definition fl_type.h:280
@ RUBY_FL_FINALIZE
This flag has something to do with finalisers.
Definition fl_type.h:238
static void RB_OBJ_TAINT_RAW(VALUE obj)
Definition fl_type.h:802
#define RBIMPL_FL_USER_N(n)
(@shyouhei doesn't know how to excude this macro from doxygen).
Definition fl_type.h:323
static void RB_OBJ_TAINT(VALUE obj)
Definition fl_type.h:818
Defines RBIMPL_ATTR_FLAG_ENUM.
#define RBIMPL_ATTR_FLAG_ENUM()
Wraps (or simulates) __attribute__((flag_enum).
Definition flag_enum.h:30
Defines RBIMPL_ATTR_FORCEINLINE.
#define RBIMPL_ATTR_FORCEINLINE()
Wraps (or simulates) __forceinline.
Definition forceinline.h:37
void rb_freeze_singleton_class(VALUE x)
This is an implementation detail of RB_OBJ_FREEZE().
Definition class.c:2765
#define RB_GNUC_EXTENSION
This is expanded to nothing for non-GCC compilers.
Definition defines.h:89
Defines RBIMPL_HAS_EXTENSION.
Defines RBIMPL_ATTR_NOALIAS.
#define RBIMPL_ATTR_NOALIAS()
Wraps (or simulates) __declspec((noalias)).
Definition noalias.h:66
#define inline
Old Visual Studio versions do not support the inline keyword, so we need to define it to be __inline.
Definition defines.h:91
Defines RBIMPL_ATTR_PURE.
#define RBIMPL_ATTR_PURE_UNLESS_DEBUG()
Enables RBIMPL_ATTR_PURE if and only if.
Definition pure.h:38
Defines struct RBasic.
#define RBASIC(obj)
Convenient casting macro.
Definition rbasic.h:40
Defines enum ruby_special_consts.
static bool RB_SPECIAL_CONST_P(VALUE obj)
Checks if the given object is of enum ruby_special_consts.
C99 shim for <stdbool.h>.
Ruby object's base components.
Definition rbasic.h:69
Defines VALUE and ID.
#define RBIMPL_VALUE_NULL
A compile-time constant of type VALUE whose value is 0.
Definition value.h:76
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40
Defines enum ruby_value_type.
static bool RB_TYPE_P(VALUE obj, enum ruby_value_type t)
Queries if the given object is of given type.
Definition value_type.h:376
@ RUBY_T_NODE
Definition value_type.h:140
@ RUBY_T_MASK
Bitmask of ruby_value_type.
Definition value_type.h:145