Ruby  3.1.4p223 (2023-03-30 revision HEAD)
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"
36 #include "ruby/internal/stdbool.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
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_PROMOTED0 RBIMPL_CAST((VALUE)RUBY_FL_PROMOTED0)
61 #define FL_PROMOTED1 RBIMPL_CAST((VALUE)RUBY_FL_PROMOTED1)
62 #define FL_FINALIZE RBIMPL_CAST((VALUE)RUBY_FL_FINALIZE)
63 #define FL_TAINT RBIMPL_CAST((VALUE)RUBY_FL_TAINT)
64 #define FL_SHAREABLE RBIMPL_CAST((VALUE)RUBY_FL_SHAREABLE)
65 #define FL_UNTRUSTED RBIMPL_CAST((VALUE)RUBY_FL_UNTRUSTED)
66 #define FL_SEEN_OBJ_ID RBIMPL_CAST((VALUE)RUBY_FL_SEEN_OBJ_ID)
67 #define FL_EXIVAR RBIMPL_CAST((VALUE)RUBY_FL_EXIVAR)
68 #define FL_FREEZE RBIMPL_CAST((VALUE)RUBY_FL_FREEZE)
70 #define FL_USHIFT RBIMPL_CAST((VALUE)RUBY_FL_USHIFT)
72 #define FL_USER0 RBIMPL_CAST((VALUE)RUBY_FL_USER0)
73 #define FL_USER1 RBIMPL_CAST((VALUE)RUBY_FL_USER1)
74 #define FL_USER2 RBIMPL_CAST((VALUE)RUBY_FL_USER2)
75 #define FL_USER3 RBIMPL_CAST((VALUE)RUBY_FL_USER3)
76 #define FL_USER4 RBIMPL_CAST((VALUE)RUBY_FL_USER4)
77 #define FL_USER5 RBIMPL_CAST((VALUE)RUBY_FL_USER5)
78 #define FL_USER6 RBIMPL_CAST((VALUE)RUBY_FL_USER6)
79 #define FL_USER7 RBIMPL_CAST((VALUE)RUBY_FL_USER7)
80 #define FL_USER8 RBIMPL_CAST((VALUE)RUBY_FL_USER8)
81 #define FL_USER9 RBIMPL_CAST((VALUE)RUBY_FL_USER9)
82 #define FL_USER10 RBIMPL_CAST((VALUE)RUBY_FL_USER10)
83 #define FL_USER11 RBIMPL_CAST((VALUE)RUBY_FL_USER11)
84 #define FL_USER12 RBIMPL_CAST((VALUE)RUBY_FL_USER12)
85 #define FL_USER13 RBIMPL_CAST((VALUE)RUBY_FL_USER13)
86 #define FL_USER14 RBIMPL_CAST((VALUE)RUBY_FL_USER14)
87 #define FL_USER15 RBIMPL_CAST((VALUE)RUBY_FL_USER15)
88 #define FL_USER16 RBIMPL_CAST((VALUE)RUBY_FL_USER16)
89 #define FL_USER17 RBIMPL_CAST((VALUE)RUBY_FL_USER17)
90 #define FL_USER18 RBIMPL_CAST((VALUE)RUBY_FL_USER18)
91 #define FL_USER19 RBIMPL_CAST((VALUE)(unsigned int)RUBY_FL_USER19)
93 #define ELTS_SHARED RUBY_ELTS_SHARED
94 #define RB_OBJ_FREEZE rb_obj_freeze_inline
97 #define RUBY_ELTS_SHARED RUBY_ELTS_SHARED
98 #define RB_FL_ABLE RB_FL_ABLE
99 #define RB_FL_ALL RB_FL_ALL
100 #define RB_FL_ALL_RAW RB_FL_ALL_RAW
101 #define RB_FL_ANY RB_FL_ANY
102 #define RB_FL_ANY_RAW RB_FL_ANY_RAW
103 #define RB_FL_REVERSE RB_FL_REVERSE
104 #define RB_FL_REVERSE_RAW RB_FL_REVERSE_RAW
105 #define RB_FL_SET RB_FL_SET
106 #define RB_FL_SET_RAW RB_FL_SET_RAW
107 #define RB_FL_TEST RB_FL_TEST
108 #define RB_FL_TEST_RAW RB_FL_TEST_RAW
109 #define RB_FL_UNSET RB_FL_UNSET
110 #define RB_FL_UNSET_RAW RB_FL_UNSET_RAW
111 #define RB_OBJ_FREEZE_RAW RB_OBJ_FREEZE_RAW
112 #define RB_OBJ_FROZEN RB_OBJ_FROZEN
113 #define RB_OBJ_FROZEN_RAW RB_OBJ_FROZEN_RAW
114 #define RB_OBJ_INFECT RB_OBJ_INFECT
115 #define RB_OBJ_INFECT_RAW RB_OBJ_INFECT_RAW
116 #define RB_OBJ_TAINT RB_OBJ_TAINT
117 #define RB_OBJ_TAINTABLE RB_OBJ_TAINTABLE
118 #define RB_OBJ_TAINTED RB_OBJ_TAINTED
119 #define RB_OBJ_TAINTED_RAW RB_OBJ_TAINTED_RAW
120 #define RB_OBJ_TAINT_RAW RB_OBJ_TAINT_RAW
121 #define RB_OBJ_UNTRUST RB_OBJ_TAINT
122 #define RB_OBJ_UNTRUSTED RB_OBJ_TAINTED
130 #define FL_ABLE RB_FL_ABLE
131 #define FL_ALL RB_FL_ALL
132 #define FL_ALL_RAW RB_FL_ALL_RAW
133 #define FL_ANY RB_FL_ANY
134 #define FL_ANY_RAW RB_FL_ANY_RAW
135 #define FL_REVERSE RB_FL_REVERSE
136 #define FL_REVERSE_RAW RB_FL_REVERSE_RAW
137 #define FL_SET RB_FL_SET
138 #define FL_SET_RAW RB_FL_SET_RAW
139 #define FL_TEST RB_FL_TEST
140 #define FL_TEST_RAW RB_FL_TEST_RAW
141 #define FL_UNSET RB_FL_UNSET
142 #define FL_UNSET_RAW RB_FL_UNSET_RAW
143 #define OBJ_FREEZE RB_OBJ_FREEZE
144 #define OBJ_FREEZE_RAW RB_OBJ_FREEZE_RAW
145 #define OBJ_FROZEN RB_OBJ_FROZEN
146 #define OBJ_FROZEN_RAW RB_OBJ_FROZEN_RAW
147 #define OBJ_INFECT RB_OBJ_INFECT
148 #define OBJ_INFECT_RAW RB_OBJ_INFECT_RAW
149 #define OBJ_TAINT RB_OBJ_TAINT
150 #define OBJ_TAINTABLE RB_OBJ_TAINTABLE
151 #define OBJ_TAINTED RB_OBJ_TAINTED
152 #define OBJ_TAINTED_RAW RB_OBJ_TAINTED_RAW
153 #define OBJ_TAINT_RAW RB_OBJ_TAINT_RAW
154 #define OBJ_UNTRUST RB_OBJ_UNTRUST
155 #define OBJ_UNTRUSTED RB_OBJ_UNTRUSTED
167  RUBY_FL_USHIFT = 12
168 };
169 
170 /* > The expression that defines the value of an enumeration constant shall be
171  * > an integer constant expression that has a value representable as an `int`.
172  *
173  * -- ISO/IEC 9899:2018 section 6.7.2.2
174  *
175  * So ENUM_OVER_INT situation is an extension to the standard. Note however
176  * that we do not support 16 bit `int` environment. */
191 enum
193 ruby_fl_type {
194 
208 
224 
241 
258 
272 
279 
280 #if defined(RBIMPL_HAVE_ENUM_ATTRIBUTE)
281  RBIMPL_ATTR_DEPRECATED(("taintedness turned out to be a wrong idea."))
282 #elif defined(_MSC_VER)
283 # pragma deprecated(RUBY_FL_TAINT)
284 #endif
285 
286  = (1<<8),
287 
299 
306 
307 #if defined(RBIMPL_HAVE_ENUM_ATTRIBUTE)
308  RBIMPL_ATTR_DEPRECATED(("trustedness turned out to be a wrong idea."))
309 #elif defined(_MSC_VER)
310 # pragma deprecated(RUBY_FL_UNTRUSTED)
311 #endif
312 
313  = (1<<8),
314 
333 
345  RUBY_FL_EXIVAR = (1<<10),
346 
356  RUBY_FL_FREEZE = (1<<11),
357 
359 #define RBIMPL_FL_USER_N(n) RUBY_FL_USER##n = (1<<(RUBY_FL_USHIFT+n))
379 #ifdef ENUM_OVER_INT
381 #else
382 # define RUBY_FL_USER19 (RBIMPL_VALUE_ONE<<(RUBY_FL_USHIFT+19))
383 #endif
384 #undef RBIMPL_FL_USER_N
385 #undef RBIMPL_WIDER_ENUM
386 
406 
431 };
432 
433 enum {
440 
441 #if defined(RBIMPL_HAVE_ENUM_ATTRIBUTE)
442  RBIMPL_ATTR_DEPRECATED(("It seems there is no actual usage of this enum."))
443 #elif defined(_MSC_VER)
444 # pragma deprecated(RUBY_FL_DUPPED)
445 #endif
446 
447  = (int)RUBY_T_MASK | (int)RUBY_FL_EXIVAR
448 };
449 
450 #undef RBIMPL_HAVE_ENUM_ATTRIBUTE
451 
457 void rb_obj_infect(VALUE victim, VALUE carrier);
458 
466 void rb_freeze_singleton_class(VALUE klass);
468 
481 static bool
483 {
484  if (RB_SPECIAL_CONST_P(obj)) {
485  return false;
486  }
487  else if (RB_TYPE_P(obj, RUBY_T_NODE)) {
488  return false;
489  }
490  else {
491  return true;
492  }
493 }
494 
506 static inline VALUE
508 {
510  return RBASIC(obj)->flags & flags;
511 }
512 
532 static inline VALUE
533 RB_FL_TEST(VALUE obj, VALUE flags)
534 {
535  if (RB_FL_ABLE(obj)) {
536  return RB_FL_TEST_RAW(obj, flags);
537  }
538  else {
539  return RBIMPL_VALUE_NULL;
540  }
541 }
542 
555 static inline bool
557 {
558  return RB_FL_TEST_RAW(obj, flags);
559 }
560 
571 static inline bool
572 RB_FL_ANY(VALUE obj, VALUE flags)
573 {
574  return RB_FL_TEST(obj, flags);
575 }
576 
589 static inline bool
591 {
592  return RB_FL_TEST_RAW(obj, flags) == flags;
593 }
594 
605 static inline bool
606 RB_FL_ALL(VALUE obj, VALUE flags)
607 {
608  return RB_FL_TEST(obj, flags) == flags;
609 }
610 
628 static inline void
629 rbimpl_fl_set_raw_raw(struct RBasic *obj, VALUE flags)
630 {
631  obj->flags |= flags;
632 }
633 
643 static inline void
645 {
647  rbimpl_fl_set_raw_raw(RBASIC(obj), flags);
648 }
649 
663 static inline void
664 RB_FL_SET(VALUE obj, VALUE flags)
665 {
666  if (RB_FL_ABLE(obj)) {
667  RB_FL_SET_RAW(obj, flags);
668  }
669 }
670 
688 static inline void
689 rbimpl_fl_unset_raw_raw(struct RBasic *obj, VALUE flags)
690 {
691  obj->flags &= ~flags;
692 }
693 
703 static inline void
705 {
707  rbimpl_fl_unset_raw_raw(RBASIC(obj), flags);
708 }
709 
718 static inline void
720 {
721  if (RB_FL_ABLE(obj)) {
722  RB_FL_UNSET_RAW(obj, flags);
723  }
724 }
725 
743 static inline void
744 rbimpl_fl_reverse_raw_raw(struct RBasic *obj, VALUE flags)
745 {
746  obj->flags ^= flags;
747 }
748 
758 static inline void
760 {
762  rbimpl_fl_reverse_raw_raw(RBASIC(obj), flags);
763 }
764 
774 static inline void
776 {
777  if (RB_FL_ABLE(obj)) {
778  RB_FL_REVERSE_RAW(obj, flags);
779  }
780 }
781 
784 RBIMPL_ATTR_DEPRECATED(("taintedness turned out to be a wrong idea."))
793 static inline bool
795 {
796  return false;
797 }
798 
801 RBIMPL_ATTR_DEPRECATED(("taintedness turned out to be a wrong idea."))
810 static inline VALUE
812 {
813  return false;
814 }
815 
818 RBIMPL_ATTR_DEPRECATED(("taintedness turned out to be a wrong idea."))
827 static inline bool
829 {
830  return false;
831 }
832 
834 RBIMPL_ATTR_DEPRECATED(("taintedness turned out to be a wrong idea."))
842 static inline void
844 {
845  return;
846 }
847 
849 RBIMPL_ATTR_DEPRECATED(("taintedness turned out to be a wrong idea."))
857 static inline void
859 {
860  return;
861 }
862 
864 RBIMPL_ATTR_DEPRECATED(("taintedness turned out to be a wrong idea."))
873 static inline void
875 {
876  return;
877 }
878 
880 RBIMPL_ATTR_DEPRECATED(("taintedness turned out to be a wrong idea."))
889 static inline void
891 {
892  return;
893 }
894 
911 static inline VALUE
913 {
914  return RB_FL_TEST_RAW(obj, RUBY_FL_FREEZE);
915 }
916 
926 static inline bool
928 {
929  if (! RB_FL_ABLE(obj)) {
930  return true;
931  }
932  else {
933  return RB_OBJ_FROZEN_RAW(obj);
934  }
935 }
936 
944 static inline void
946 {
948 }
949 
956 static inline void
958 {
959  if (RB_FL_ABLE(x)) {
961  if (RBASIC_CLASS(x) && !(RBASIC(x)->flags & RUBY_FL_SINGLETON)) {
963  }
964  }
965 }
966 
967 #endif /* RBIMPL_FL_TYPE_H */
Defines RBIMPL_ATTR_ARTIFICIAL.
#define RBIMPL_ATTR_ARTIFICIAL()
Wraps (or simulates) __attribute__((artificial))
Definition: artificial.h:41
#define RBIMPL_ASSERT_OR_ASSUME(expr)
This is either RUBY_ASSERT or RBIMPL_ASSUME, depending on RUBY_DEBUG.
Definition: assert.h:229
Defines RBIMPL_COMPILER_SINCE.
#define RB_GNUC_EXTENSION
This is expanded to nothing for non-GCC compilers.
Definition: defines.h:89
Defines RBIMPL_ATTR_DEPRECATED.
#define RBIMPL_ATTR_DEPRECATED(msg)
Wraps (or simulates) [[deprecated]]
Definition: deprecated.h:36
Tweaking visibility of C variables/functions.
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
Definition: dllexport.h:106
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
Definition: dllexport.h:97
Defines RBIMPL_HAS_EXTENSION.
ruby_fl_ushift
This is an enum because GDB wants it (rather than a macro).
Definition: fl_type.h:162
@ RUBY_FL_USHIFT
Number of bits in ruby_fl_type that are not open to users.
Definition: fl_type.h:167
static VALUE RB_OBJ_FROZEN_RAW(VALUE obj)
This is an implenentation detail of RB_OBJ_FROZEN().
Definition: fl_type.h:912
static bool RB_OBJ_TAINTABLE(VALUE obj)
Definition: fl_type.h:794
static VALUE RB_FL_TEST(VALUE obj, VALUE flags)
Tests if the given flag(s) are set or not.
Definition: fl_type.h:533
static VALUE RB_FL_TEST_RAW(VALUE obj, VALUE flags)
This is an implenentation detail of RB_FL_TEST().
Definition: fl_type.h:507
static bool RB_FL_ABLE(VALUE obj)
Checks if the object is flaggable.
Definition: fl_type.h:482
static bool RB_FL_ANY_RAW(VALUE obj, VALUE flags)
This is an implenentation detail of RB_FL_ANY().
Definition: fl_type.h:556
static void rb_obj_freeze_inline(VALUE x)
Prevents further modifications to the given object.
Definition: fl_type.h:957
static bool RB_FL_ANY(VALUE obj, VALUE flags)
Identical to RB_FL_TEST(), except it returns bool.
Definition: fl_type.h:572
static void RB_FL_SET_RAW(VALUE obj, VALUE flags)
This is an implenentation detail of RB_FL_SET().
Definition: fl_type.h:644
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:606
static bool RB_OBJ_FROZEN(VALUE obj)
Checks if an object is frozen.
Definition: fl_type.h:927
static bool RB_OBJ_TAINTED(VALUE obj)
Definition: fl_type.h:828
static VALUE RB_OBJ_TAINTED_RAW(VALUE obj)
Definition: fl_type.h:811
static void RB_OBJ_INFECT(VALUE dst, VALUE src)
Definition: fl_type.h:890
static void RB_FL_UNSET_RAW(VALUE obj, VALUE flags)
This is an implenentation detail of RB_FL_UNSET().
Definition: fl_type.h:704
@ RUBY_FL_DUPPED
Definition: fl_type.h:439
static void RB_FL_SET(VALUE obj, VALUE flags)
Sets the given flag(s).
Definition: fl_type.h:664
static void RB_OBJ_INFECT_RAW(VALUE dst, VALUE src)
Definition: fl_type.h:874
static void RB_FL_REVERSE(VALUE obj, VALUE flags)
Reverses the flags.
Definition: fl_type.h:775
static void RB_FL_UNSET(VALUE obj, VALUE flags)
Clears the given flag(s).
Definition: fl_type.h:719
static void RB_OBJ_FREEZE_RAW(VALUE obj)
This is an implenentation detail of RB_OBJ_FREEZE().
Definition: fl_type.h:945
static void RB_FL_REVERSE_RAW(VALUE obj, VALUE flags)
This is an implenentation detail of RB_FL_REVERSE().
Definition: fl_type.h:759
static bool RB_FL_ALL_RAW(VALUE obj, VALUE flags)
This is an implenentation detail of RB_FL_ALL().
Definition: fl_type.h:590
ruby_fl_type
The flags.
Definition: fl_type.h:193
@ RUBY_FL_PROMOTED1
This flag has something to do with our garbage collector.
Definition: fl_type.h:240
@ RUBY_ELTS_SHARED
This flag has something to do with data structures.
Definition: fl_type.h:405
@ RUBY_FL_SINGLETON
This flag has something to do with an object's class.
Definition: fl_type.h:430
@ RUBY_FL_TAINT
Definition: fl_type.h:278
@ RUBY_FL_WB_PROTECTED
Definition: fl_type.h:207
@ RUBY_FL_PROMOTED0
This flag has something to do with our garbage collector.
Definition: fl_type.h:223
@ RUBY_FL_EXIVAR
This flag has something to do with instance variables.
Definition: fl_type.h:345
@ RUBY_FL_UNTRUSTED
Definition: fl_type.h:305
@ RUBY_FL_PROMOTED
This flag has something to do with our garbage collector.
Definition: fl_type.h:257
@ RUBY_FL_USER0
User-defined flag.
Definition: fl_type.h:360
@ RUBY_FL_FREEZE
This flag has something to do with data immutability.
Definition: fl_type.h:356
@ RUBY_FL_SEEN_OBJ_ID
This flag has something to do with object IDs.
Definition: fl_type.h:332
@ RUBY_FL_USER2
User-defined flag.
Definition: fl_type.h:362
@ RUBY_FL_SHAREABLE
This flag has something to do with Ractor.
Definition: fl_type.h:298
@ RUBY_FL_FINALIZE
This flag has something to do with finalisers.
Definition: fl_type.h:271
static void RB_OBJ_TAINT_RAW(VALUE obj)
Definition: fl_type.h:843
#define RBIMPL_FL_USER_N(n)
(@shyouhei doesn't know how to excude this macro from doxygen).
Definition: fl_type.h:359
static void RB_OBJ_TAINT(VALUE obj)
Definition: fl_type.h:858
Defines RBIMPL_ATTR_FLAG_ENUM.
#define RBIMPL_ATTR_FLAG_ENUM()
Wraps (or simulates) __attribute__((flag_enum)
Definition: flag_enum.h:28
Defines RBIMPL_ATTR_FORCEINLINE.
#define RBIMPL_ATTR_FORCEINLINE()
Wraps (or simulates) __forceinline.
Definition: forceinline.h:35
void rb_freeze_singleton_class(VALUE klass)
This is an implementation detail of RB_OBJ_FREEZE().
Definition: class.c:2034
void rb_obj_infect(VALUE victim, VALUE carrier)
Definition: object.c:1131
Defines RBIMPL_ATTR_NOALIAS.
#define RBIMPL_ATTR_NOALIAS()
Wraps (or simulates) __declspec((noalias))
Definition: noalias.h:62
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.
static VALUE RBASIC_CLASS(VALUE obj)
Queries the class of an object.
Definition: rbasic.h:152
#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's object's, base components.
Definition: rbasic.h:64
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:375
@ RUBY_T_NODE
Definition: value_type.h:139
@ RUBY_T_MASK
Bitmask of ruby_value_type.
Definition: value_type.h:144