Ruby 4.1.0dev (2026-09-07 revision b57404b461ba8bf34e802d86b0db78388216e182)
object.h
1#ifndef INTERNAL_OBJECT_H /*-*-C-*-vi:se ft=c:*/
2#define INTERNAL_OBJECT_H
11#include "ruby/ruby.h" /* for VALUE */
12
13/* object.c */
14
15VALUE rb_class_allocate_instance(VALUE klass);
16VALUE rb_class_allocate_instance_capa(VALUE klass, uint8_t /* attr_index_t */ max_iv_count);
17VALUE rb_class_search_ancestor(VALUE klass, VALUE super);
18NORETURN(void rb_undefined_alloc(VALUE klass));
19double rb_num_to_dbl(VALUE val);
20VALUE rb_obj_dig(int argc, VALUE *argv, VALUE self, VALUE notfound);
21VALUE rb_obj_clone_setup(VALUE obj, VALUE clone, VALUE kwfreeze);
22VALUE rb_obj_dup_setup(VALUE obj, VALUE dup);
23VALUE rb_immutable_obj_clone(int, VALUE *, VALUE);
24VALUE rb_check_convert_type_with_id_slow(VALUE,int,const char*,ID);
25int rb_bool_expected(VALUE, const char *, int raise);
26
27static inline VALUE
28rb_check_convert_type_with_id(VALUE val, int type, const char *tname, ID method)
29{
30 if (RB_TYPE_P(val, type) && type != T_DATA) return val;
31 return rb_check_convert_type_with_id_slow(val, type, tname, method);
32}
33static inline void RBASIC_CLEAR_CLASS(VALUE obj);
34static inline void RBASIC_SET_CLASS_RAW(VALUE obj, VALUE klass);
35static inline void RBASIC_SET_CLASS(VALUE obj, VALUE klass);
36
37RUBY_SYMBOL_EXPORT_BEGIN
38/* object.c (export) */
39int rb_opts_exception_p(VALUE opts, int default_value);
40RUBY_SYMBOL_EXPORT_END
41
42CONSTFUNC(VALUE rb_obj_equal(VALUE obj1, VALUE obj2));
43CONSTFUNC(VALUE rb_obj_not(VALUE obj));
44VALUE rb_obj_not_equal(VALUE obj1, VALUE obj2);
45void rb_obj_copy_ivar(VALUE dest, VALUE obj);
46VALUE rb_false(VALUE obj);
47VALUE rb_convert_type_with_id(VALUE v, int t, const char* nam, ID mid);
48VALUE rb_obj_size(VALUE self, VALUE args, VALUE obj);
49VALUE rb_get_freeze_opt(int argc, VALUE *argv);
50
51static inline void
52RBASIC_SET_CLASS_RAW(VALUE obj, VALUE klass)
53{
54 const VALUE *ptr = &RBASIC(obj)->klass;
55 *(VALUE *)ptr = klass;
56}
57
58static inline void
59RBASIC_CLEAR_CLASS(VALUE obj)
60{
61 RBASIC_SET_CLASS_RAW(obj, 0);
62}
63
64static inline void
65RBASIC_SET_CLASS(VALUE obj, VALUE klass)
66{
67 VALUE oldv = RBASIC_CLASS(obj);
68 RBASIC_SET_CLASS_RAW(obj, klass);
69 RB_OBJ_WRITTEN(obj, oldv, klass);
70}
71
72static inline void
73ROBJECT_SET_EXTENDED(VALUE obj, VALUE fields_obj)
74{
76 RUBY_ASSERT(RB_TYPE_P(fields_obj, T_IMEMO));
77 RB_OBJ_WRITE(obj, &ROBJECT(obj)->as.extended, fields_obj);
78}
79
80static inline size_t
81rb_obj_embedded_size(uint32_t fields_count)
82{
83 size_t size = offsetof(struct RObject, as.ary) + (sizeof(VALUE) * fields_count);
84 // Ensure enough room for the heap pointer if this expands
85 if (size < sizeof(struct RObject)) size = sizeof(struct RObject);
86 return size;
87}
88#endif /* INTERNAL_OBJECT_H */
#define RUBY_ASSERT(...)
Asserts that the given expression is truthy if and only if RUBY_DEBUG is truthy.
Definition assert.h:219
#define T_IMEMO
Old name of RUBY_T_IMEMO.
Definition value_type.h:67
#define T_DATA
Old name of RUBY_T_DATA.
Definition value_type.h:60
#define T_OBJECT
Old name of RUBY_T_OBJECT.
Definition value_type.h:75
#define RB_OBJ_WRITTEN(old, oldv, young)
Identical to RB_OBJ_WRITE(), except it doesn't write any values, but only a WB declaration.
Definition gc.h:468
#define RB_OBJ_WRITE(old, slot, young)
Declaration of a "back" pointer.
Definition gc.h:456
VALUE type(ANYARGS)
ANYARGS-ed function type.
static VALUE RBASIC_CLASS(VALUE obj)
Queries the class of an object.
Definition rbasic.h:166
#define RBASIC(obj)
Convenient casting macro.
Definition rbasic.h:40
#define ROBJECT(obj)
Convenient casting macro.
Definition robject.h:43
Ruby's ordinal objects.
Definition robject.h:56
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
Definition value.h:52
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40
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