1#ifndef INTERNAL_CLASS_H
2#define INTERNAL_CLASS_H
13#include "internal/serial.h"
14#include "internal/static_assert.h"
15#include "internal/variable.h"
20#include "ruby_assert.h"
38 rb_serial_t global_cvar_state;
49 size_t superclass_depth;
60 const VALUE refined_class;
66 VALUE attached_object;
70 attr_index_t max_iv_count;
71 unsigned char variation_count;
72 bool permanent_classpath : 1;
78STATIC_ASSERT(shape_max_variations, SHAPE_MAX_VARIATIONS < (1 << (
sizeof(((
rb_classext_t *)0)->variation_count) * CHAR_BIT)));
87STATIC_ASSERT(sizeof_rb_classext_t,
sizeof(
struct RClass) +
sizeof(
rb_classext_t) <= 4 * RVALUE_SIZE);
94#define RCLASS_EXT(c) (&((struct RClass_and_rb_classext_t*)(c))->classext)
95#define RCLASS_CONST_TBL(c) (RCLASS_EXT(c)->const_tbl)
96#define RCLASS_M_TBL(c) (RCLASS(c)->m_tbl)
97#define RCLASS_IVPTR(c) (RCLASS_EXT(c)->iv_ptr)
98#define RCLASS_CALLABLE_M_TBL(c) (RCLASS_EXT(c)->callable_m_tbl)
99#define RCLASS_CC_TBL(c) (RCLASS_EXT(c)->cc_tbl)
100#define RCLASS_CVC_TBL(c) (RCLASS_EXT(c)->cvc_tbl)
101#define RCLASS_ORIGIN(c) (RCLASS_EXT(c)->origin_)
102#define RCLASS_REFINED_CLASS(c) (RCLASS_EXT(c)->refined_class)
103#define RCLASS_INCLUDER(c) (RCLASS_EXT(c)->includer)
104#define RCLASS_SUBCLASS_ENTRY(c) (RCLASS_EXT(c)->subclass_entry)
105#define RCLASS_MODULE_SUBCLASS_ENTRY(c) (RCLASS_EXT(c)->module_subclass_entry)
106#define RCLASS_SUBCLASSES(c) (RCLASS_EXT(c)->subclasses)
107#define RCLASS_SUPERCLASS_DEPTH(c) (RCLASS_EXT(c)->superclass_depth)
108#define RCLASS_SUPERCLASSES(c) (RCLASS_EXT(c)->superclasses)
109#define RCLASS_ATTACHED_OBJECT(c) (RCLASS_EXT(c)->as.singleton_class.attached_object)
111#define RICLASS_IS_ORIGIN FL_USER0
112#define RCLASS_SUPERCLASSES_INCLUDE_SELF FL_USER2
113#define RICLASS_ORIGIN_SHARED_MTBL FL_USER3
116RCLASS_IV_HASH(
VALUE obj)
120 return (
st_table *)RCLASS_IVPTR(obj);
128 RCLASS_IVPTR(obj) = (
VALUE *)tbl;
131static inline uint32_t
132RCLASS_IV_COUNT(
VALUE obj)
135 if (rb_shape_obj_too_complex(obj)) {
142 count = (uint32_t)rb_st_table_size(RCLASS_IV_HASH(obj));
149 return rb_shape_get_shape_by_id(RCLASS_SHAPE_ID(obj))->next_iv_index;
157 RCLASS_M_TBL(klass) = table;
161void rb_class_subclass_add(
VALUE super,
VALUE klass);
162void rb_class_remove_from_super_subclasses(
VALUE);
163void rb_class_update_superclasses(
VALUE);
164size_t rb_class_superclasses_memsize(
VALUE);
165void rb_class_remove_subclass_head(
VALUE);
166int rb_singleton_class_internal_p(
VALUE sklass);
170void rb_module_set_initialized(
VALUE module);
171void rb_module_check_initializable(
VALUE module);
175void rb_class_detach_subclasses(
VALUE);
176void rb_class_detach_module_subclasses(
VALUE);
177void rb_class_remove_from_module_subclasses(
VALUE);
182VALUE rb_class_undefined_instance_methods(
VALUE mod);
186void rb_undef_methods_from(
VALUE klass,
VALUE super);
188static inline void RCLASS_SET_ORIGIN(
VALUE klass,
VALUE origin);
189static inline void RICLASS_SET_ORIGIN_SHARED_MTBL(
VALUE iclass);
192static inline void RCLASS_SET_INCLUDER(
VALUE iclass,
VALUE klass);
195VALUE rb_keyword_error_new(
const char *,
VALUE);
198RCLASS_ALLOCATOR(
VALUE klass)
203 return RCLASS_EXT(klass)->as.class.allocator;
210 RCLASS_EXT(klass)->as.class.allocator = allocator;
217 if (klass != origin)
FL_SET(origin, RICLASS_IS_ORIGIN);
221RICLASS_SET_ORIGIN_SHARED_MTBL(
VALUE iclass)
223 FL_SET(iclass, RICLASS_ORIGIN_SHARED_MTBL);
227RICLASS_OWNS_M_TBL_P(
VALUE iclass)
229 return FL_TEST_RAW(iclass, RICLASS_IS_ORIGIN | RICLASS_ORIGIN_SHARED_MTBL) == RICLASS_IS_ORIGIN;
241 return RCLASS(klass)->super;
248 rb_class_remove_from_super_subclasses(klass);
249 rb_class_subclass_add(super, klass);
252 rb_class_update_superclasses(klass);
257RCLASS_SET_CLASSPATH(
VALUE klass,
VALUE classpath,
bool permanent)
262 RB_OBJ_WRITE(klass, &(RCLASS_EXT(klass)->classpath), classpath);
263 RCLASS_EXT(klass)->permanent_classpath = permanent;
267RCLASS_SET_ATTACHED_OBJECT(
VALUE klass,
VALUE attached_object)
272 RB_OBJ_WRITE(klass, &RCLASS_EXT(klass)->as.singleton_class.attached_object, attached_object);
273 return attached_object;
#define RUBY_ASSERT(expr)
Asserts that the given expression is truthy if and only if RUBY_DEBUG is truthy.
VALUE rb_class_boot(VALUE)
A utility function that wraps class_alloc.
VALUE rb_class_inherited(VALUE, VALUE)
Calls Class::inherited.
VALUE rb_singleton_class_get(VALUE obj)
Returns the singleton class of obj, or nil if obj is not a singleton object.
#define FL_SINGLETON
Old name of RUBY_FL_SINGLETON.
#define T_STRING
Old name of RUBY_T_STRING.
#define T_MODULE
Old name of RUBY_T_MODULE.
#define FL_TEST_RAW
Old name of RB_FL_TEST_RAW.
#define FL_SET
Old name of RB_FL_SET.
#define T_CLASS
Old name of RUBY_T_CLASS.
#define BUILTIN_TYPE
Old name of RB_BUILTIN_TYPE.
#define FL_TEST
Old name of RB_FL_TEST.
#define RB_OBJ_WRITE(old, slot, young)
Declaration of a "back" pointer.
static bool RB_OBJ_PROMOTED(VALUE obj)
Tests if the object is "promoted" – that is, whether the object experienced one or more GC marks.
VALUE(* rb_alloc_func_t)(VALUE klass)
This is the type of functions that ruby calls when trying to allocate an object.
#define RCLASS_SUPER
Just another name of rb_class_get_superclass.
#define RCLASS(obj)
Convenient casting macro.
Ruby's object's, base components.
struct rb_subclass_entry * module_subclass_entry
In the case that this is an ICLASS, module_subclasses points to the link in the module's subclasses l...
Internal header for Class.
uintptr_t VALUE
Type that represents a Ruby object.