Ruby: include/ruby/internal/core/rbasic.h Source File

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

rbasic.h
Go to the documentation of this file.
1#ifndef RBIMPL_RBASIC_H /*-*-C++-*-vi:se ft=cpp:*/
2#define RBIMPL_RBASIC_H
23#include "ruby/internal/attr/artificial.h"
24#include "ruby/internal/attr/constexpr.h"
25#include "ruby/internal/attr/forceinline.h"
26#include "ruby/internal/attr/noalias.h"
27#include "ruby/internal/attr/pure.h"
28#include "ruby/internal/cast.h"
29#include "ruby/internal/dllexport.h"
30#include "ruby/internal/special_consts.h"
31#include "ruby/internal/value.h"
32#include "ruby/assert.h"
33
34#define RBASIC(obj) RBIMPL_CAST((struct RBasic *)(obj))
35#define RBASIC_CLASS RBASIC_CLASS
36#define RVALUE_EMBED_LEN_MAX RVALUE_EMBED_LEN_MAX
37
39#define RBIMPL_EMBED_LEN_MAX_OF(T) \
40 RBIMPL_CAST((int)(sizeof(VALUE[RVALUE_EMBED_LEN_MAX]) / (sizeof(T))))
43 enum ruby_rvalue_flags { RVALUE_EMBED_LEN_MAX = 3 };
44
45 struct
46 RUBY_ALIGNAS(SIZEOF_VALUE)
47 RBasic {
48 VALUE flags;
49 const VALUE klass;
50
51#ifdef __cplusplus
52 public:
53 RBIMPL_ATTR_CONSTEXPR(CXX11)
54 RBIMPL_ATTR_ARTIFICIAL()
55 RBIMPL_ATTR_FORCEINLINE()
56 RBIMPL_ATTR_NOALIAS()
63 RBasic() :
64 flags(RBIMPL_VALUE_NULL),
65 klass(RBIMPL_VALUE_NULL)
66 {
67 }
68#endif
69};
70
71 RBIMPL_SYMBOL_EXPORT_BEGIN()
72 VALUE rb_obj_hide(VALUE obj);
73 VALUE rb_obj_reveal(VALUE obj, VALUE klass); /* do not use this API to change klass information */
74 RBIMPL_SYMBOL_EXPORT_END()
75
76 RBIMPL_ATTR_PURE_UNLESS_DEBUG()
77 RBIMPL_ATTR_ARTIFICIAL()
78static inline VALUE
79 RBASIC_CLASS(VALUE obj)
80{
81 RBIMPL_ASSERT_OR_ASSUME(! RB_SPECIAL_CONST_P(obj));
82 return RBASIC(obj)->klass;
83}
84
85#endif /* RBIMPL_RBASIC_H */
artificial.h
Defines RBIMPL_ATTR_ARTIFICIAL.
RBIMPL_ATTR_ARTIFICIAL
#define RBIMPL_ATTR_ARTIFICIAL()
Wraps (or simulates) __attribute__((artificial))
Definition: artificial.h:43
assert.h
RBIMPL_ASSERT_OR_ASSUME
#define RBIMPL_ASSERT_OR_ASSUME(expr)
This is either RUBY_ASSERT or RBIMPL_ASSUME, depending on RUBY_DEBUG.
Definition: assert.h:229
RUBY_ALIGNAS
#define RUBY_ALIGNAS
Definition: stdalign.h:27
cast.h
Defines RBIMPL_CAST.
constexpr.h
RBIMPL_ATTR_CONSTEXPR.
RBIMPL_ATTR_CONSTEXPR
#define RBIMPL_ATTR_CONSTEXPR(_)
Wraps (or simulates) C++11 constexpr.
Definition: constexpr.h:75
dllexport.h
Tewaking visibility of C variables/functions.
RBIMPL_SYMBOL_EXPORT_END
#define RBIMPL_SYMBOL_EXPORT_END()
Counterpart of RBIMPL_SYMBOL_EXPORT_BEGIN.
Definition: dllexport.h:86
RBIMPL_SYMBOL_EXPORT_BEGIN
#define RBIMPL_SYMBOL_EXPORT_BEGIN()
Shortcut macro equivalent to RUBY_SYMBOL_EXPORT_BEGIN extern "C" {.
Definition: dllexport.h:77
forceinline.h
Defines RBIMPL_ATTR_FORCEINLINE.
RBIMPL_ATTR_FORCEINLINE
#define RBIMPL_ATTR_FORCEINLINE()
Wraps (or simulates) __forceinline.
Definition: forceinline.h:37
rb_obj_reveal
VALUE rb_obj_reveal(VALUE obj, VALUE klass)
Make a hidden object visible again.
Definition: object.c:109
rb_obj_hide
VALUE rb_obj_hide(VALUE obj)
Make the object invisible from Ruby code.
Definition: object.c:92
noalias.h
Defines RBIMPL_ATTR_NOALIAS.
RBIMPL_ATTR_NOALIAS
#define RBIMPL_ATTR_NOALIAS()
Wraps (or simulates) __declspec((noalias))
Definition: noalias.h:55
pure.h
Defines RBIMPL_ATTR_PURE.
RBIMPL_ATTR_PURE_UNLESS_DEBUG
#define RBIMPL_ATTR_PURE_UNLESS_DEBUG()
Enables RBIMPL_ATTR_PURE iff.
Definition: pure.h:38
RBASIC
#define RBASIC(obj)
Definition: rbasic.h:34
ruby_rvalue_flags
ruby_rvalue_flags
Definition: rbasic.h:43
RBASIC_CLASS
#define RBASIC_CLASS
Definition: rbasic.h:35
RVALUE_EMBED_LEN_MAX
#define RVALUE_EMBED_LEN_MAX
Definition: rbasic.h:36
special_consts.h
Defines enum ruby_special_consts.
RBasic
Definition: rbasic.h:47
RBasic::klass
const VALUE klass
Definition: rbasic.h:49
RBasic::flags
VALUE flags
Definition: rbasic.h:48
value.h
Defines VALUE and ID.
RBIMPL_VALUE_NULL
#define RBIMPL_VALUE_NULL
Definition: value.h:43
VALUE
unsigned long VALUE
Definition: value.h:38
SIZEOF_VALUE
#define SIZEOF_VALUE
Definition: value.h:41