Ruby 4.1.0dev (2026-09-14 revision c4e06b4e30d0dbdd1a9cd76f5d97fe1220b3a23c)
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
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_SHAREABLE RBIMPL_CAST((VALUE)RUBY_FL_SHAREABLE)
63#define FL_UNTRUSTED RBIMPL_CAST((VALUE)RUBY_FL_UNTRUSTED)
64#define FL_EXIVAR RBIMPL_CAST((VALUE)RUBY_FL_EXIVAR)
65#define FL_FREEZE RBIMPL_CAST((VALUE)RUBY_FL_FREEZE)
67#define FL_USHIFT RBIMPL_CAST((VALUE)RUBY_FL_USHIFT)
69#define FL_USER0 RBIMPL_CAST((VALUE)RUBY_FL_USER0)
70#define FL_USER1 RBIMPL_CAST((VALUE)RUBY_FL_USER1)
71#define FL_USER2 RBIMPL_CAST((VALUE)RUBY_FL_USER2)
72#define FL_USER3 RBIMPL_CAST((VALUE)RUBY_FL_USER3)
73#define FL_USER4 RBIMPL_CAST((VALUE)RUBY_FL_USER4)
74#define FL_USER5 RBIMPL_CAST((VALUE)RUBY_FL_USER5)
75#define FL_USER6 RBIMPL_CAST((VALUE)RUBY_FL_USER6)
76#define FL_USER7 RBIMPL_CAST((VALUE)RUBY_FL_USER7)
77#define FL_USER8 RBIMPL_CAST((VALUE)RUBY_FL_USER8)
78#define FL_USER9 RBIMPL_CAST((VALUE)RUBY_FL_USER9)
79#define FL_USER10 RBIMPL_CAST((VALUE)RUBY_FL_USER10)
80#define FL_USER11 RBIMPL_CAST((VALUE)RUBY_FL_USER11)
81#define FL_USER12 RBIMPL_CAST((VALUE)RUBY_FL_USER12)
82#define FL_USER13 RBIMPL_CAST((VALUE)RUBY_FL_USER13)
83#define FL_USER14 RBIMPL_CAST((VALUE)RUBY_FL_USER14)
84#define FL_USER15 RBIMPL_CAST((VALUE)RUBY_FL_USER15)
85#define FL_USER16 RBIMPL_CAST((VALUE)RUBY_FL_USER16)
86#define FL_USER17 RBIMPL_CAST((VALUE)RUBY_FL_USER17)
87#define FL_USER18 RBIMPL_CAST((VALUE)RUBY_FL_USER18)
88#define FL_USER19 RBIMPL_CAST((VALUE)(unsigned int)RUBY_FL_USER19)
90#define ELTS_SHARED RUBY_ELTS_SHARED
91#define RB_OBJ_FREEZE rb_obj_freeze_inline
94#define RUBY_ELTS_SHARED RUBY_ELTS_SHARED
95#define RB_FL_ABLE RB_FL_ABLE
96#define RB_FL_ALL RB_FL_ALL
97#define RB_FL_ALL_RAW RB_FL_ALL_RAW
98#define RB_FL_ANY RB_FL_ANY
99#define RB_FL_ANY_RAW RB_FL_ANY_RAW
100#define RB_FL_REVERSE RB_FL_REVERSE
101#define RB_FL_REVERSE_RAW RB_FL_REVERSE_RAW
102#define RB_FL_SET RB_FL_SET
103#define RB_FL_SET_RAW RB_FL_SET_RAW
104#define RB_FL_TEST RB_FL_TEST
105#define RB_FL_TEST_RAW RB_FL_TEST_RAW
106#define RB_FL_UNSET RB_FL_UNSET
107#define RB_FL_UNSET_RAW RB_FL_UNSET_RAW
108#define RB_OBJ_FREEZE_RAW RB_OBJ_FREEZE_RAW
109#define RB_OBJ_FROZEN RB_OBJ_FROZEN
110#define RB_OBJ_FROZEN_RAW RB_OBJ_FROZEN_RAW
118#define FL_ABLE RB_FL_ABLE
119#define FL_ALL RB_FL_ALL
120#define FL_ALL_RAW RB_FL_ALL_RAW
121#define FL_ANY RB_FL_ANY
122#define FL_ANY_RAW RB_FL_ANY_RAW
123#define FL_REVERSE RB_FL_REVERSE
124#define FL_REVERSE_RAW RB_FL_REVERSE_RAW
125#define FL_SET RB_FL_SET
126#define FL_SET_RAW RB_FL_SET_RAW
127#define FL_TEST RB_FL_TEST
128#define FL_TEST_RAW RB_FL_TEST_RAW
129#define FL_UNSET RB_FL_UNSET
130#define FL_UNSET_RAW RB_FL_UNSET_RAW
131#define OBJ_FREEZE RB_OBJ_FREEZE
132#define OBJ_FREEZE_RAW RB_OBJ_FREEZE_RAW
133#define OBJ_FROZEN RB_OBJ_FROZEN
134#define OBJ_FROZEN_RAW RB_OBJ_FROZEN_RAW
148
149/* > The expression that defines the value of an enumeration constant shall be
150 * > an integer constant expression that has a value representable as an `int`.
151 *
152 * -- ISO/IEC 9899:2018 section 6.7.2.2
153 *
154 * So ENUM_OVER_INT situation is an extension to the standard. Note however
155 * that we do not support 16 bit `int` environment. */
170enum
173
187
206
213
227
234
235#if defined(RBIMPL_HAVE_ENUM_ATTRIBUTE)
236 RBIMPL_ATTR_DEPRECATED(("FL_EXIVAR is an outdated implementation detail, it should not be used."))
237#elif defined(_MSC_VER)
238# pragma deprecated(RUBY_FL_EXIVAR)
239#endif
240
241 = 0,
242
254
261
268
278 RUBY_FL_FREEZE = (1<<11),
279
281#define RBIMPL_FL_USER_N(n) RUBY_FL_USER##n = (1<<(RUBY_FL_USHIFT+n))
301#ifdef ENUM_OVER_INT
303#else
304# define RUBY_FL_USER19 (RBIMPL_VALUE_ONE<<(RUBY_FL_USHIFT+19))
305#endif
306#undef RBIMPL_FL_USER_N
307#undef RBIMPL_WIDER_ENUM
308
328
353};
354
355#undef RBIMPL_HAVE_ENUM_ATTRIBUTE
356
367
380static bool
382{
383 if (RB_SPECIAL_CONST_P(obj)) {
384 return false;
385 }
386 else {
388 return true;
389 }
390}
391
403static inline VALUE
405{
407 return RBASIC(obj)->flags & flags;
408}
409
429static inline VALUE
431{
432 if (RB_FL_ABLE(obj)) {
433 return RB_FL_TEST_RAW(obj, flags);
434 }
435 else {
436 return RBIMPL_VALUE_NULL;
437 }
438}
439
452static inline bool
454{
455 return RB_FL_TEST_RAW(obj, flags);
456}
457
468static inline bool
470{
471 return RB_FL_TEST(obj, flags);
472}
473
486static inline bool
488{
489 return RB_FL_TEST_RAW(obj, flags) == flags;
490}
491
502static inline bool
504{
505 return RB_FL_TEST(obj, flags) == flags;
506}
507
525static inline void
526rbimpl_fl_set_raw_raw(struct RBasic *obj, VALUE flags)
527{
528 obj->flags |= flags;
529}
530
540static inline void
542{
544 rbimpl_fl_set_raw_raw(RBASIC(obj), flags);
545}
546
560static inline void
562{
563 if (RB_FL_ABLE(obj)) {
564 RB_FL_SET_RAW(obj, flags);
565 }
566}
567
585static inline void
586rbimpl_fl_unset_raw_raw(struct RBasic *obj, VALUE flags)
587{
588 obj->flags &= ~flags;
589}
590
600static inline void
602{
604 rbimpl_fl_unset_raw_raw(RBASIC(obj), flags);
605}
606
615static inline void
617{
618 if (RB_FL_ABLE(obj)) {
619 RB_FL_UNSET_RAW(obj, flags);
620 }
621}
622
640static inline void
641rbimpl_fl_reverse_raw_raw(struct RBasic *obj, VALUE flags)
642{
643 obj->flags ^= flags;
644}
645
655static inline void
657{
659 rbimpl_fl_reverse_raw_raw(RBASIC(obj), flags);
660}
661
671static inline void
673{
674 if (RB_FL_ABLE(obj)) {
675 RB_FL_REVERSE_RAW(obj, flags);
676 }
677}
678
695static inline VALUE
697{
698 return RB_FL_TEST_RAW(obj, RUBY_FL_FREEZE);
699}
700
710static inline bool
712{
713 if (! RB_FL_ABLE(obj)) {
714 return true;
715 }
716 else {
717 return RB_OBJ_FROZEN_RAW(obj);
718 }
719}
720
721RUBY_SYMBOL_EXPORT_BEGIN
731RUBY_SYMBOL_EXPORT_END
732
740static inline void
745
746#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.
#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: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_ushift
This is an enum because GDB wants it (rather than a macro).
Definition fl_type.h:141
@ RUBY_FL_USHIFT
Number of bits in ruby_fl_type that are not open to users.
Definition fl_type.h:146
static VALUE RB_OBJ_FROZEN_RAW(VALUE obj)
This is an implementation detail of RB_OBJ_FROZEN().
Definition fl_type.h:696
static VALUE RB_FL_TEST(VALUE obj, VALUE flags)
Tests if the given flag(s) are set or not.
Definition fl_type.h:430
static VALUE RB_FL_TEST_RAW(VALUE obj, VALUE flags)
This is an implementation detail of RB_FL_TEST().
Definition fl_type.h:404
static bool RB_FL_ABLE(VALUE obj)
Checks if the object is flaggable.
Definition fl_type.h:381
static bool RB_FL_ANY_RAW(VALUE obj, VALUE flags)
This is an implementation detail of RB_FL_ANY().
Definition fl_type.h:453
static bool RB_FL_ANY(VALUE obj, VALUE flags)
Identical to RB_FL_TEST(), except it returns bool.
Definition fl_type.h:469
static void RB_FL_SET_RAW(VALUE obj, VALUE flags)
This is an implementation detail of RB_FL_SET().
Definition fl_type.h:541
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:503
void rb_obj_freeze_inline(VALUE obj)
Prevents further modifications to the given object.
Definition variable.c:2013
static bool RB_OBJ_FROZEN(VALUE obj)
Checks if an object is frozen.
Definition fl_type.h:711
static void RB_FL_UNSET_RAW(VALUE obj, VALUE flags)
This is an implementation detail of RB_FL_UNSET().
Definition fl_type.h:601
static void RB_FL_SET(VALUE obj, VALUE flags)
Sets the given flag(s).
Definition fl_type.h:561
static void RB_FL_REVERSE(VALUE obj, VALUE flags)
Reverses the flags.
Definition fl_type.h:672
static void RB_FL_UNSET(VALUE obj, VALUE flags)
Clears the given flag(s).
Definition fl_type.h:616
static void RB_OBJ_FREEZE_RAW(VALUE obj)
This is an implementation detail of RB_OBJ_FREEZE().
Definition fl_type.h:741
static void RB_FL_REVERSE_RAW(VALUE obj, VALUE flags)
This is an implementation detail of RB_FL_REVERSE().
Definition fl_type.h:656
static bool RB_FL_ALL_RAW(VALUE obj, VALUE flags)
This is an implementation detail of RB_FL_ALL().
Definition fl_type.h:487
ruby_fl_type
The flags.
Definition fl_type.h:172
@ RUBY_ELTS_SHARED
This flag has something to do with data structures.
Definition fl_type.h:327
@ RUBY_FL_UNUSED10
This flag is no longer in use.
Definition fl_type.h:267
@ RUBY_FL_SINGLETON
This flag has something to do with an object's class.
Definition fl_type.h:352
@ RUBY_FL_WB_PROTECTED
Definition fl_type.h:186
@ RUBY_FL_EXIVAR
Definition fl_type.h:233
@ RUBY_FL_PROMOTED
Ruby objects are "generational".
Definition fl_type.h:205
@ RUBY_FL_UNUSED6
This flag is no longer in use.
Definition fl_type.h:212
@ RUBY_FL_USER0
User-defined flag.
Definition fl_type.h:282
@ RUBY_FL_FREEZE
This flag has something to do with data immutability.
Definition fl_type.h:278
@ RUBY_FL_USER1
User-defined flag.
Definition fl_type.h:283
@ RUBY_FL_SHAREABLE
This flag has something to do with Ractor.
Definition fl_type.h:253
@ RUBY_FL_FINALIZE
This flag has something to do with finalisers.
Definition fl_type.h:226
@ RUBY_FL_WEAK_REFERENCE
This object weakly refers to other objects.
Definition fl_type.h:260
#define RBIMPL_FL_USER_N(n)
(@shyouhei doesn't know how to excude this macro from doxygen).
Definition fl_type.h:281
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 klass)
This is an implementation detail of RB_OBJ_FREEZE().
Definition class.c:3002
Defines RBIMPL_HAS_EXTENSION.
Defines RBIMPL_ATTR_NOALIAS.
#define RBIMPL_ATTR_NOALIAS()
Wraps (or simulates) __declspec((noalias))
Definition noalias.h:66
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