1 #ifndef RBIMPL_VALUE_TYPE_H
2 #define RBIMPL_VALUE_TYPE_H
29 #include "ruby/internal/cast.h"
53 # error Bail out due to conflicting definition of T_DATA.
56 #define T_ARRAY RUBY_T_ARRAY
57 #define T_BIGNUM RUBY_T_BIGNUM
58 #define T_CLASS RUBY_T_CLASS
59 #define T_COMPLEX RUBY_T_COMPLEX
60 #define T_DATA RUBY_T_DATA
61 #define T_FALSE RUBY_T_FALSE
62 #define T_FILE RUBY_T_FILE
63 #define T_FIXNUM RUBY_T_FIXNUM
64 #define T_FLOAT RUBY_T_FLOAT
65 #define T_HASH RUBY_T_HASH
66 #define T_ICLASS RUBY_T_ICLASS
67 #define T_IMEMO RUBY_T_IMEMO
68 #define T_MASK RUBY_T_MASK
69 #define T_MATCH RUBY_T_MATCH
70 #define T_MODULE RUBY_T_MODULE
71 #define T_MOVED RUBY_T_MOVED
72 #define T_NIL RUBY_T_NIL
73 #define T_NODE RUBY_T_NODE
74 #define T_NONE RUBY_T_NONE
75 #define T_OBJECT RUBY_T_OBJECT
76 #define T_RATIONAL RUBY_T_RATIONAL
77 #define T_REGEXP RUBY_T_REGEXP
78 #define T_STRING RUBY_T_STRING
79 #define T_STRUCT RUBY_T_STRUCT
80 #define T_SYMBOL RUBY_T_SYMBOL
81 #define T_TRUE RUBY_T_TRUE
82 #define T_UNDEF RUBY_T_UNDEF
83 #define T_ZOMBIE RUBY_T_ZOMBIE
85 #define BUILTIN_TYPE RB_BUILTIN_TYPE
86 #define DYNAMIC_SYM_P RB_DYNAMIC_SYM_P
87 #define RB_INTEGER_TYPE_P rb_integer_type_p
88 #define SYMBOL_P RB_SYMBOL_P
89 #define rb_type_p RB_TYPE_P
92 #define RB_BUILTIN_TYPE RB_BUILTIN_TYPE
93 #define RB_DYNAMIC_SYM_P RB_DYNAMIC_SYM_P
94 #define RB_FLOAT_TYPE_P RB_FLOAT_TYPE_P
95 #define RB_SYMBOL_P RB_SYMBOL_P
96 #define RB_TYPE_P RB_TYPE_P
97 #define Check_Type Check_Type
100 # define RBIMPL_ASSERT_TYPE(v, t) RBIMPL_ASSERT_OR_ASSUME(RB_TYPE_P((v), (t)))
102 # define RBIMPL_ASSERT_TYPE Check_Type
107 #define TYPE(_) RBIMPL_CAST((int)rb_type(_))
185 #if 0 && defined __GNUC__ && !defined __clang__
188 __asm
volatile(
"": : :
"memory");
378 return rbimpl_RB_TYPE_P_fastpath(obj, t);
388 #if defined(__clang__)
390 # define RB_TYPE_P(obj, t) \
391 (RBIMPL_CONSTANT_P(t) ? \
392 rbimpl_RB_TYPE_P_fastpath((obj), (t)) : \
393 (RB_TYPE_P)((obj), (t)))
400 #if RBIMPL_COMPILER_BEFORE(Clang, 4, 0, 0)
401 # undef rb_integer_type_p
402 # define rb_integer_type_p(obj) \
404 const VALUE integer_type_obj = (obj); \
405 (RB_FIXNUM_P(integer_type_obj) || \
406 (!RB_SPECIAL_CONST_P(integer_type_obj) && \
407 RB_BUILTIN_TYPE(integer_type_obj) == RUBY_T_BIGNUM)); \
418 static inline
bool rbimpl_rtypeddata_p(
VALUE obj);
435 goto unexpected_type;
437 else if (t ==
RUBY_T_DATA && rbimpl_rtypeddata_p(v)) {
439 goto unexpected_type;
Defines RBIMPL_ATTR_ARTIFICIAL.
#define RBIMPL_ATTR_ARTIFICIAL()
Wraps (or simulates) __attribute__((artificial))
#define RBIMPL_ASSERT_OR_ASSUME(expr)
This is either RUBY_ASSERT or RBIMPL_ASSUME, depending on RUBY_DEBUG.
#define RB_UNLIKELY(x)
Asserts that the given Boolean expression likely doesn't hold.
Defines RBIMPL_ATTR_COLD.
#define RBIMPL_ATTR_COLD()
Wraps (or simulates) __attribute__((cold))
Defines RBIMPL_CONSTANT_P.
#define RBIMPL_CONSTANT_P(expr)
Wraps (or simulates) __builtin_constant_p
Tweaking visibility of C variables/functions.
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
RBIMPL_ATTR_ENUM_EXTENSIBILITY.
#define RBIMPL_ATTR_ENUM_EXTENSIBILITY(_)
Wraps (or simulates) __attribute__((enum_extensibility))
Defines RBIMPL_ATTR_FORCEINLINE.
#define RBIMPL_ATTR_FORCEINLINE()
Wraps (or simulates) __forceinline.
void rb_unexpected_type(VALUE x, int t)
Fails with the given object's type incompatibility to the type.
void rb_check_type(VALUE x, int t)
This was the old implementation of Check_Type(), but they diverged.
Defines RBIMPL_HAS_BUILTIN.
RBIMPL_ATTR_PURE() int rb_io_read_pending(rb_io_t *fptr)
Queries if the passed IO has any pending reads.
Defines RBIMPL_ASSUME / RBIMPL_UNREACHABLE.
#define RBIMPL_ASSUME
Wraps (or simulates) __assume.
Defines RBIMPL_ATTR_PURE.
#define RBIMPL_ATTR_PURE_UNLESS_DEBUG()
Enables RBIMPL_ATTR_PURE if and only if.
#define RBASIC(obj)
Convenient casting macro.
Defines enum ruby_special_consts.
static bool RB_STATIC_SYM_P(VALUE obj)
Checks if the given object is a static symbol.
static bool RB_FIXNUM_P(VALUE obj)
Checks if the given object is a so-called Fixnum.
static bool RB_SPECIAL_CONST_P(VALUE obj)
Checks if the given object is of enum ruby_special_consts.
@ RUBY_Qundef
Represents so-called undef.
static bool RB_FLONUM_P(VALUE obj)
Checks if the given object is a so-called Flonum.
uintptr_t VALUE
Type that represents a Ruby object.
static enum ruby_value_type rb_type(VALUE obj)
Identical to RB_BUILTIN_TYPE(), except it can also accept special constants.
static enum ruby_value_type RB_BUILTIN_TYPE(VALUE obj)
Queries the type of the object.
static bool RB_FLOAT_TYPE_P(VALUE obj)
Queries if the object is an instance of rb_cFloat.
static bool RB_SYMBOL_P(VALUE obj)
Queries if the object is an instance of rb_cSymbol.
static void Check_Type(VALUE v, enum ruby_value_type t)
Identical to RB_TYPE_P(), except it raises exceptions on predication failure.
static bool rb_integer_type_p(VALUE obj)
Queries if the object is an instance of rb_cInteger.
static bool RB_DYNAMIC_SYM_P(VALUE obj)
Queries if the object is a dynamic symbol.
static bool RB_TYPE_P(VALUE obj, enum ruby_value_type t)
Queries if the given object is of given type.
ruby_value_type
C-level type of an object.
@ RUBY_T_ICLASS
Hidden classes known as IClasses.
@ RUBY_T_FIXNUM
Integers formerly known as Fixnums.
@ RUBY_T_MASK
Bitmask of ruby_value_type.
@ RUBY_T_NONE
Non-object (swept etc.)