Ruby 3.4.2p28 (2025-02-15 revision d2930f8e7a5db8a7337fa43370940381b420cc3e)
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_SEEN_OBJ_ID RBIMPL_CAST((VALUE)RUBY_FL_SEEN_OBJ_ID)
66#define FL_EXIVAR RBIMPL_CAST((VALUE)RUBY_FL_EXIVAR)
67#define FL_FREEZE RBIMPL_CAST((VALUE)RUBY_FL_FREEZE)
68
69#define FL_USHIFT RBIMPL_CAST((VALUE)RUBY_FL_USHIFT)
70
71#define FL_USER0 RBIMPL_CAST((VALUE)RUBY_FL_USER0)
72#define FL_USER1 RBIMPL_CAST((VALUE)RUBY_FL_USER1)
73#define FL_USER2 RBIMPL_CAST((VALUE)RUBY_FL_USER2)
74#define FL_USER3 RBIMPL_CAST((VALUE)RUBY_FL_USER3)
75#define FL_USER4 RBIMPL_CAST((VALUE)RUBY_FL_USER4)
76#define FL_USER5 RBIMPL_CAST((VALUE)RUBY_FL_USER5)
77#define FL_USER6 RBIMPL_CAST((VALUE)RUBY_FL_USER6)
78#define FL_USER7 RBIMPL_CAST((VALUE)RUBY_FL_USER7)
79#define FL_USER8 RBIMPL_CAST((VALUE)RUBY_FL_USER8)
80#define FL_USER9 RBIMPL_CAST((VALUE)RUBY_FL_USER9)
81#define FL_USER10 RBIMPL_CAST((VALUE)RUBY_FL_USER10)
82#define FL_USER11 RBIMPL_CAST((VALUE)RUBY_FL_USER11)
83#define FL_USER12 RBIMPL_CAST((VALUE)RUBY_FL_USER12)
84#define FL_USER13 RBIMPL_CAST((VALUE)RUBY_FL_USER13)
85#define FL_USER14 RBIMPL_CAST((VALUE)RUBY_FL_USER14)
86#define FL_USER15 RBIMPL_CAST((VALUE)RUBY_FL_USER15)
87#define FL_USER16 RBIMPL_CAST((VALUE)RUBY_FL_USER16)
88#define FL_USER17 RBIMPL_CAST((VALUE)RUBY_FL_USER17)
89#define FL_USER18 RBIMPL_CAST((VALUE)RUBY_FL_USER18)
90#define FL_USER19 RBIMPL_CAST((VALUE)(unsigned int)RUBY_FL_USER19)
91
92#define ELTS_SHARED RUBY_ELTS_SHARED
93#define RB_OBJ_FREEZE rb_obj_freeze_inline
94
96#define RUBY_ELTS_SHARED RUBY_ELTS_SHARED
97#define RB_FL_ABLE RB_FL_ABLE
98#define RB_FL_ALL RB_FL_ALL
99#define RB_FL_ALL_RAW RB_FL_ALL_RAW
100#define RB_FL_ANY RB_FL_ANY
101#define RB_FL_ANY_RAW RB_FL_ANY_RAW
102#define RB_FL_REVERSE RB_FL_REVERSE
103#define RB_FL_REVERSE_RAW RB_FL_REVERSE_RAW
104#define RB_FL_SET RB_FL_SET
105#define RB_FL_SET_RAW RB_FL_SET_RAW
106#define RB_FL_TEST RB_FL_TEST
107#define RB_FL_TEST_RAW RB_FL_TEST_RAW
108#define RB_FL_UNSET RB_FL_UNSET
109#define RB_FL_UNSET_RAW RB_FL_UNSET_RAW
110#define RB_OBJ_FREEZE_RAW RB_OBJ_FREEZE_RAW
111#define RB_OBJ_FROZEN RB_OBJ_FROZEN
112#define RB_OBJ_FROZEN_RAW RB_OBJ_FROZEN_RAW
113#define RB_OBJ_UNTRUST RB_OBJ_TAINT
114#define RB_OBJ_UNTRUSTED RB_OBJ_TAINTED
116
122#define FL_ABLE RB_FL_ABLE
123#define FL_ALL RB_FL_ALL
124#define FL_ALL_RAW RB_FL_ALL_RAW
125#define FL_ANY RB_FL_ANY
126#define FL_ANY_RAW RB_FL_ANY_RAW
127#define FL_REVERSE RB_FL_REVERSE
128#define FL_REVERSE_RAW RB_FL_REVERSE_RAW
129#define FL_SET RB_FL_SET
130#define FL_SET_RAW RB_FL_SET_RAW
131#define FL_TEST RB_FL_TEST
132#define FL_TEST_RAW RB_FL_TEST_RAW
133#define FL_UNSET RB_FL_UNSET
134#define FL_UNSET_RAW RB_FL_UNSET_RAW
135#define OBJ_FREEZE RB_OBJ_FREEZE
136#define OBJ_FREEZE_RAW RB_OBJ_FREEZE_RAW
137#define OBJ_FROZEN RB_OBJ_FROZEN
138#define OBJ_FROZEN_RAW RB_OBJ_FROZEN_RAW
139#define OBJ_INFECT RB_OBJ_INFECT
140#define OBJ_INFECT_RAW RB_OBJ_INFECT_RAW
141#define OBJ_TAINT RB_OBJ_TAINT
142#define OBJ_TAINTABLE RB_OBJ_TAINTABLE
143#define OBJ_TAINTED RB_OBJ_TAINTED
144#define OBJ_TAINTED_RAW RB_OBJ_TAINTED_RAW
145#define OBJ_TAINT_RAW RB_OBJ_TAINT_RAW
146#define OBJ_UNTRUST RB_OBJ_UNTRUST
147#define OBJ_UNTRUSTED RB_OBJ_UNTRUSTED
149
161
162/* > The expression that defines the value of an enumeration constant shall be
163 * > an integer constant expression that has a value representable as an `int`.
164 *
165 * -- ISO/IEC 9899:2018 section 6.7.2.2
166 *
167 * So ENUM_OVER_INT situation is an extension to the standard. Note however
168 * that we do not support 16 bit `int` environment. */
183enum
186
200
219
226
240
247
248#if defined(RBIMPL_HAVE_ENUM_ATTRIBUTE)
249 RBIMPL_ATTR_DEPRECATED(("taintedness turned out to be a wrong idea."))
250#elif defined(_MSC_VER)
251# pragma deprecated(RUBY_FL_TAINT)
252#endif
253
254 = 0,
255
267
274
275#if defined(RBIMPL_HAVE_ENUM_ATTRIBUTE)
276 RBIMPL_ATTR_DEPRECATED(("trustedness turned out to be a wrong idea."))
277#elif defined(_MSC_VER)
278# pragma deprecated(RUBY_FL_UNTRUSTED)
279#endif
280
281 = 0,
282
301
313 RUBY_FL_EXIVAR = (1<<10),
314
324 RUBY_FL_FREEZE = (1<<11),
325
327#define RBIMPL_FL_USER_N(n) RUBY_FL_USER##n = (1<<(RUBY_FL_USHIFT+n))
347#ifdef ENUM_OVER_INT
349#else
350# define RUBY_FL_USER19 (RBIMPL_VALUE_ONE<<(RUBY_FL_USHIFT+19))
351#endif
352#undef RBIMPL_FL_USER_N
353#undef RBIMPL_WIDER_ENUM
354
374
399};
400
401enum {
408
409#if defined(RBIMPL_HAVE_ENUM_ATTRIBUTE)
410 RBIMPL_ATTR_DEPRECATED(("It seems there is no actual usage of this enum."))
411#elif defined(_MSC_VER)
412# pragma deprecated(RUBY_FL_DUPPED)
413#endif
414
415 = (int)RUBY_T_MASK | (int)RUBY_FL_EXIVAR
416};
417
418#undef RBIMPL_HAVE_ENUM_ATTRIBUTE
419
430
443static bool
445{
446 if (RB_SPECIAL_CONST_P(obj)) {
447 return false;
448 }
449 else if (RB_TYPE_P(obj, RUBY_T_NODE)) {
450 return false;
451 }
452 else {
453 return true;
454 }
455}
456
468static inline VALUE
470{
472 return RBASIC(obj)->flags & flags;
473}
474
494static inline VALUE
496{
497 if (RB_FL_ABLE(obj)) {
498 return RB_FL_TEST_RAW(obj, flags);
499 }
500 else {
501 return RBIMPL_VALUE_NULL;
502 }
503}
504
517static inline bool
519{
520 return RB_FL_TEST_RAW(obj, flags);
521}
522
533static inline bool
535{
536 return RB_FL_TEST(obj, flags);
537}
538
551static inline bool
553{
554 return RB_FL_TEST_RAW(obj, flags) == flags;
555}
556
567static inline bool
569{
570 return RB_FL_TEST(obj, flags) == flags;
571}
572
590static inline void
591rbimpl_fl_set_raw_raw(struct RBasic *obj, VALUE flags)
592{
593 obj->flags |= flags;
594}
595
605static inline void
607{
609 rbimpl_fl_set_raw_raw(RBASIC(obj), flags);
610}
611
625static inline void
627{
628 if (RB_FL_ABLE(obj)) {
629 RB_FL_SET_RAW(obj, flags);
630 }
631}
632
650static inline void
651rbimpl_fl_unset_raw_raw(struct RBasic *obj, VALUE flags)
652{
653 obj->flags &= ~flags;
654}
655
665static inline void
667{
669 rbimpl_fl_unset_raw_raw(RBASIC(obj), flags);
670}
671
680static inline void
682{
683 if (RB_FL_ABLE(obj)) {
684 RB_FL_UNSET_RAW(obj, flags);
685 }
686}
687
705static inline void
706rbimpl_fl_reverse_raw_raw(struct RBasic *obj, VALUE flags)
707{
708 obj->flags ^= flags;
709}
710
720static inline void
722{
724 rbimpl_fl_reverse_raw_raw(RBASIC(obj), flags);
725}
726
736static inline void
738{
739 if (RB_FL_ABLE(obj)) {
740 RB_FL_REVERSE_RAW(obj, flags);
741 }
742}
743
746RBIMPL_ATTR_DEPRECATED(("taintedness turned out to be a wrong idea."))
755static inline bool
757{
758 (void)obj;
759 return false;
760}
761
764RBIMPL_ATTR_DEPRECATED(("taintedness turned out to be a wrong idea."))
773static inline VALUE
775{
776 (void)obj;
777 return false;
778}
779
782RBIMPL_ATTR_DEPRECATED(("taintedness turned out to be a wrong idea."))
791static inline bool
793{
794 (void)obj;
795 return false;
796}
797
799RBIMPL_ATTR_DEPRECATED(("taintedness turned out to be a wrong idea."))
807static inline void
809{
810 (void)obj;
811 return;
812}
813
815RBIMPL_ATTR_DEPRECATED(("taintedness turned out to be a wrong idea."))
823static inline void
825{
826 (void)obj;
827 return;
828}
829
831RBIMPL_ATTR_DEPRECATED(("taintedness turned out to be a wrong idea."))
840static inline void
842{
843 (void)dst;
844 (void)src;
845 return;
846}
847
849RBIMPL_ATTR_DEPRECATED(("taintedness turned out to be a wrong idea."))
858static inline void
860{
861 (void)dst;
862 (void)src;
863 return;
864}
865
882static inline VALUE
884{
885 return RB_FL_TEST_RAW(obj, RUBY_FL_FREEZE);
886}
887
897static inline bool
899{
900 if (! RB_FL_ABLE(obj)) {
901 return true;
902 }
903 else {
904 return RB_OBJ_FROZEN_RAW(obj);
905 }
906}
907
908RUBY_SYMBOL_EXPORT_BEGIN
918RUBY_SYMBOL_EXPORT_END
919
927static inline void
932
933#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:407
ruby_fl_ushift
This is an enum because GDB wants it (rather than a macro).
Definition fl_type.h:154
@ RUBY_FL_USHIFT
Number of bits in ruby_fl_type that are not open to users.
Definition fl_type.h:159
static VALUE RB_OBJ_FROZEN_RAW(VALUE obj)
This is an implementation detail of RB_OBJ_FROZEN().
Definition fl_type.h:883
static bool RB_OBJ_TAINTABLE(VALUE obj)
Definition fl_type.h:756
static VALUE RB_FL_TEST(VALUE obj, VALUE flags)
Tests if the given flag(s) are set or not.
Definition fl_type.h:495
static VALUE RB_FL_TEST_RAW(VALUE obj, VALUE flags)
This is an implementation detail of RB_FL_TEST().
Definition fl_type.h:469
static bool RB_FL_ABLE(VALUE obj)
Checks if the object is flaggable.
Definition fl_type.h:444
static bool RB_FL_ANY_RAW(VALUE obj, VALUE flags)
This is an implementation detail of RB_FL_ANY().
Definition fl_type.h:518
static bool RB_FL_ANY(VALUE obj, VALUE flags)
Identical to RB_FL_TEST(), except it returns bool.
Definition fl_type.h:534
static void RB_FL_SET_RAW(VALUE obj, VALUE flags)
This is an implementation detail of RB_FL_SET().
Definition fl_type.h:606
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:568
void rb_obj_freeze_inline(VALUE obj)
Prevents further modifications to the given object.
Definition variable.c:1824
static bool RB_OBJ_FROZEN(VALUE obj)
Checks if an object is frozen.
Definition fl_type.h:898
static bool RB_OBJ_TAINTED(VALUE obj)
Definition fl_type.h:792
static VALUE RB_OBJ_TAINTED_RAW(VALUE obj)
Definition fl_type.h:774
static void RB_OBJ_INFECT(VALUE dst, VALUE src)
Definition fl_type.h:859
static void RB_FL_UNSET_RAW(VALUE obj, VALUE flags)
This is an implementation detail of RB_FL_UNSET().
Definition fl_type.h:666
static void RB_FL_SET(VALUE obj, VALUE flags)
Sets the given flag(s).
Definition fl_type.h:626
static void RB_OBJ_INFECT_RAW(VALUE dst, VALUE src)
Definition fl_type.h:841
static void RB_FL_REVERSE(VALUE obj, VALUE flags)
Reverses the flags.
Definition fl_type.h:737
static void RB_FL_UNSET(VALUE obj, VALUE flags)
Clears the given flag(s).
Definition fl_type.h:681
static void RB_OBJ_FREEZE_RAW(VALUE obj)
This is an implementation detail of RB_OBJ_FREEZE().
Definition fl_type.h:928
static void RB_FL_REVERSE_RAW(VALUE obj, VALUE flags)
This is an implementation detail of RB_FL_REVERSE().
Definition fl_type.h:721
static bool RB_FL_ALL_RAW(VALUE obj, VALUE flags)
This is an implementation detail of RB_FL_ALL().
Definition fl_type.h:552
ruby_fl_type
The flags.
Definition fl_type.h:185
@ RUBY_ELTS_SHARED
This flag has something to do with data structures.
Definition fl_type.h:373
@ RUBY_FL_SINGLETON
This flag has something to do with an object's class.
Definition fl_type.h:398
@ RUBY_FL_TAINT
Definition fl_type.h:246
@ RUBY_FL_WB_PROTECTED
Definition fl_type.h:199
@ RUBY_FL_EXIVAR
This flag has something to do with instance variables.
Definition fl_type.h:313
@ RUBY_FL_UNTRUSTED
Definition fl_type.h:273
@ RUBY_FL_PROMOTED
Ruby objects are "generational".
Definition fl_type.h:218
@ RUBY_FL_UNUSED6
This flag is no longer in use.
Definition fl_type.h:225
@ RUBY_FL_USER0
User-defined flag.
Definition fl_type.h:328
@ RUBY_FL_FREEZE
This flag has something to do with data immutability.
Definition fl_type.h:324
@ RUBY_FL_SEEN_OBJ_ID
This flag has something to do with object IDs.
Definition fl_type.h:300
@ RUBY_FL_USER1
User-defined flag.
Definition fl_type.h:329
@ RUBY_FL_SHAREABLE
This flag has something to do with Ractor.
Definition fl_type.h:266
@ RUBY_FL_FINALIZE
This flag has something to do with finalisers.
Definition fl_type.h:239
static void RB_OBJ_TAINT_RAW(VALUE obj)
Definition fl_type.h:808
#define RBIMPL_FL_USER_N(n)
(@shyouhei doesn't know how to excude this macro from doxygen).
Definition fl_type.h:327
static void RB_OBJ_TAINT(VALUE obj)
Definition fl_type.h:824
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:2263
#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:88
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:63
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