14#include "ruby/internal/config.h"
17#include "ccan/list/list.h"
19#include "debug_counter.h"
23#include "internal/box.h"
24#include "internal/class.h"
25#include "internal/compilers.h"
26#include "internal/error.h"
27#include "internal/eval.h"
28#include "eval_intern.h"
29#include "internal/hash.h"
30#include "internal/object.h"
31#include "internal/gc.h"
32#include "internal/ractor.h"
33#include "internal/re.h"
34#include "internal/string.h"
35#include "internal/struct.h"
36#include "internal/symbol.h"
37#include "internal/thread.h"
38#include "internal/variable.h"
39#include "internal/vm.h"
47#include "ractor_core.h"
51#define GET_GLOBAL_CVAR_STATE() (ruby_vm_global_cvar_state)
53typedef void rb_gvar_compact_t(
void *var);
60static VALUE autoload_features;
65static VALUE autoload_mutex;
67static void check_before_mod_set(
VALUE,
ID,
VALUE,
const char *);
68static void setup_const_entry(rb_const_entry_t *,
VALUE,
VALUE, rb_const_flag_t);
69static VALUE rb_const_search(
VALUE klass,
ID id,
int exclude,
int recurse,
int visibility,
VALUE *found_in);
70static st_table *generic_fields_tbl_;
78typedef int rb_ivar_foreach_callback_func(
ID key,
VALUE val, st_data_t arg);
79static void rb_field_foreach(
VALUE obj, rb_ivar_foreach_callback_func *func, st_data_t arg,
bool ivar_only);
82rb_generic_fields_lock_atfork(
void)
91 rb_global_tbl = rb_id_table_create(0);
92 generic_fields_tbl_ = st_init_numtable();
96 rb_vm_register_global_object(autoload_mutex);
98 autoload_features = rb_ident_hash_new();
100 rb_vm_register_global_object(autoload_features);
104rb_namespace_p(
VALUE obj)
125classname(
VALUE klass,
bool *permanent)
129 VALUE classpath = RCLASS_CLASSPATH(klass);
130 if (classpath == 0)
return Qnil;
132 *permanent = RCLASS_PERMANENT_CLASSPATH_P(klass);
138rb_mod_name0(
VALUE klass,
bool *permanent)
140 return classname(klass, permanent);
155 return classname(mod, &permanent);
160is_constant_path(
VALUE name)
162 const char *path = RSTRING_PTR(name);
164 rb_encoding *enc = rb_enc_get(name);
166 const char *p = path;
168 if (p >= pend || !*p) {
173 if (p + 2 <= pend && p[0] ==
':' && p[1] ==
':') {
177 const char *pbeg = p;
178 while (p < pend && *p !=
':') p++;
180 if (pbeg == p)
return false;
182 if (rb_enc_symname_type(pbeg, p - pbeg, enc, 0) != ID_CONST) {
199set_sub_temporary_name_recursive(
VALUE mod,
VALUE data,
int recursive)
201 if (recursive)
return Qfalse;
206 name = build_const_path(rb_ary_last(0, 0, args->names), args->last);
208 set_sub_temporary_name_foreach(mod, args, name);
213set_sub_temporary_name_topmost(
VALUE mod,
VALUE data,
int recursive)
215 if (recursive)
return Qfalse;
218 VALUE name = args->names;
222 set_sub_temporary_name_foreach(mod, args, name);
226static enum rb_id_table_iterator_result
227set_sub_temporary_name_i(
ID id,
VALUE val,
void *data)
229 val = ((rb_const_entry_t *)val)->value;
230 if (rb_namespace_p(val) && !RCLASS_PERMANENT_CLASSPATH_P(val)) {
236 return ID_TABLE_CONTINUE;
242 RCLASS_WRITE_CLASSPATH(mod, name, FALSE);
246 rb_id_table_foreach(tbl, set_sub_temporary_name_i, args);
251 rb_id_table_foreach(tbl, set_sub_temporary_name_i, args);
252 rb_ary_set_len(args->names, names_len);
313rb_mod_set_temporary_name(
VALUE mod,
VALUE name)
315 rb_class_owner_check(mod);
318 if (RCLASS_PERMANENT_CLASSPATH_P(mod)) {
325 set_sub_temporary_name(mod, 0);
332 if (RSTRING_LEN(name) == 0) {
333 rb_raise(rb_eArgError,
"empty class/module name");
336 if (is_constant_path(name)) {
337 rb_raise(rb_eArgError,
"the temporary name must not be a constant path to avoid confusion");
345 set_sub_temporary_name(mod, name);
358 path = rb_sprintf(
"#<Class:%p>", (
void*)obj);
361 path = rb_sprintf(
"#<Module:%p>", (
void*)obj);
364 path = rb_sprintf(
"#<%"PRIsVALUE
":%p>", klass, (
void*)obj);
374rb_tmp_class_path(
VALUE klass,
bool *permanent, fallback_func fallback)
376 VALUE path = classname(klass, permanent);
388 path = rb_tmp_class_path(
RBASIC(klass)->klass, &perm, fallback);
393 return fallback(klass, path);
400 VALUE path = rb_tmp_class_path(klass, &permanent, make_temporary_path);
418rb_search_class_path(
VALUE klass)
421 return rb_tmp_class_path(klass, &permanent, no_fallback);
430 return rb_fstring(path);
434build_const_path(
VALUE head,
ID tail)
436 return build_const_pathname(head, rb_id2str(tail));
442 bool permanent =
true;
449 str = rb_tmp_class_path(under, &permanent, make_temporary_path);
450 str = build_const_pathname(str, name);
454 RCLASS_SET_CLASSPATH(klass, str, permanent);
468 rb_encoding *enc = rb_enc_get(pathname);
469 const char *pbeg, *pend, *p, *path = RSTRING_PTR(pathname);
473 if (!rb_enc_asciicompat(enc)) {
474 rb_raise(rb_eArgError,
"invalid class path encoding (non ASCII)");
477 pend = path + RSTRING_LEN(pathname);
478 if (path == pend || path[0] ==
'#') {
479 rb_raise(rb_eArgError,
"can't retrieve anonymous class %"PRIsVALUE,
483 while (p < pend && *p !=
':') p++;
485 if (p < pend && p[0] ==
':') {
486 if ((
size_t)(pend - p) < 2 || p[1] !=
':')
goto undefined_class;
491 goto undefined_class;
493 c = rb_const_search(c,
id, TRUE, FALSE, FALSE, NULL);
494 if (UNDEF_P(c))
goto undefined_class;
495 if (!rb_namespace_p(c)) {
496 rb_raise(
rb_eTypeError,
"%"PRIsVALUE
" does not refer to class/module",
505 rb_raise(rb_eArgError,
"undefined class/module % "PRIsVALUE,
526 VALUE path = rb_tmp_class_path(
rb_class_real(klass), &permanent, make_temporary_path);
527 if (
NIL_P(path))
return NULL;
528 return RSTRING_PTR(path);
551 rb_gvar_compact_t *compactor;
578static enum rb_id_table_iterator_result
579free_global_entry_i(
VALUE val,
void *arg)
582 entry->var->counter--;
583 if (entry->var->counter == 0) {
584 free_global_variable(entry->var);
587 return ID_TABLE_DELETE;
591rb_free_rb_global_tbl(
void)
593 rb_id_table_foreach_values(rb_global_tbl, free_global_entry_i, 0);
594 rb_id_table_free(rb_global_tbl);
598rb_free_generic_fields_tbl_(
void)
600 st_free_table(generic_fields_tbl_);
604rb_gvar_undef_compactor(
void *var)
608NORETURN(
static void global_entry_isolation_error(
ID id));
611global_entry_isolation_error(
ID id)
613 rb_raise(rb_eRactorIsolationError,
"can not access global variable %s from non-main Ractor", rb_id2name(
id));
619global_entry_lookup(
ID id,
bool create_entry,
bool *isolation_error)
625 if (rb_id_table_lookup(rb_global_tbl,
id, &data)) {
633 *isolation_error = UNLIKELY(!rb_ractor_main_p()) && (!entry || !entry->ractor_local);
635 if (!entry && create_entry && !*isolation_error) {
640 entry->ractor_local =
false;
647 var->compactor = rb_gvar_undef_compactor;
649 var->block_trace = 0;
651 var->box_ready =
false;
652 var->box_dynamic =
false;
653 rb_id_table_insert(rb_global_tbl,
id, (
VALUE)entry);
661rb_find_global_entry(
ID id)
663 bool isolation_error;
664 struct rb_global_entry *entry = global_entry_lookup(
id,
false, &isolation_error);
666 if (isolation_error) global_entry_isolation_error(
id);
672rb_gvar_ractor_local(
const char *name)
675 entry->ractor_local =
true;
679rb_gvar_box_ready(
const char *name)
682 entry->var->box_ready =
true;
686rb_gvar_box_dynamic(
const char *name)
689 entry->var->box_dynamic =
true;
695 bool isolation_error;
696 struct rb_global_entry *entry = global_entry_lookup(
id,
true, &isolation_error);
698 if (isolation_error) global_entry_isolation_error(
id);
706 rb_warning(
"global variable '%"PRIsVALUE
"' not initialized", QUOTE_ID(
id));
712rb_gvar_val_compactor(
void *_var)
717 rb_gc_update_moved_ptr(&var->data);
728 var->compactor = rb_gvar_val_compactor;
730 var->data = (
void*)val;
748 var->data = (
void*)val;
755 if (data) rb_gc_mark_movable(data);
761 if (!var)
return Qnil;
774 if (var) rb_gc_mark_maybe(*var);
780 rb_name_error(
id,
"%"PRIsVALUE
" is a read-only variable", QUOTE_ID(
id));
783static enum rb_id_table_iterator_result
784mark_global_entry(
VALUE v,
void *ignored)
790 (*var->marker)(var->data);
793 if (trace->data) rb_gc_mark_maybe(trace->data);
796 return ID_TABLE_CONTINUE;
799#define gc_mark_table(task) \
800 if (rb_global_tbl) { rb_id_table_foreach_values(rb_global_tbl, task##_global_entry, 0); }
803rb_gc_mark_global_tbl(
void)
808static enum rb_id_table_iterator_result
809update_global_entry(
VALUE v,
void *ignored)
814 (*var->compactor)(var);
815 return ID_TABLE_CONTINUE;
819rb_gc_update_global_tbl(
void)
821 gc_mark_table(update);
825global_id(
const char *name)
829 if (name[0] ==
'$')
id = rb_intern(name);
831 size_t len = strlen(name);
835 memcpy(buf+1, name,
len);
836 id = rb_intern2(buf,
len+1);
843find_global_id(
const char *name)
846 size_t len = strlen(name);
848 if (name[0] ==
'$') {
855 memcpy(buf+1, name,
len);
871 ID id = global_id(name);
874 gvar->data = (
void*)var;
926 trace->next = entry->var->trace;
927 trace->func = rb_trace_eval;
930 entry->var->trace = trace;
944 while (trace->next) {
947 trace->next = next->next;
970 if ((entry = rb_find_global_entry(
id)) == NULL) {
971 rb_name_error(
id,
"undefined global variable %"PRIsVALUE
"", QUOTE_ID(
id));
974 trace = entry->var->trace;
985 if (!entry->var->block_trace) remove_trace(entry->var);
990 if (trace->data == cmd) {
992 if (!entry->var->block_trace) remove_trace(entry->var);
1013 (*trace->func)(trace->data, data->val);
1014 trace = trace->next;
1024 var->block_trace = 0;
1034 if (var->trace && !var->block_trace) {
1035 var->block_trace = 1;
1036 trace.trace = var->trace;
1047 (*var->setter)(val, entry->id, var->data);
1048 gvar_trace(var, val);
1053gvar_use_box_tbl(
const rb_box_t *box,
const struct rb_global_entry *entry)
1055 return BOX_USER_P(box) &&
1056 !entry->var->box_dynamic &&
1065 const rb_box_t *box = rb_current_box();
1066 bool use_box_tbl =
false;
1067 bool isolation_error =
false;
1070 entry = global_entry_lookup(
id,
true, &isolation_error);
1072 if (!isolation_error && gvar_use_box_tbl(box, entry)) {
1074 rb_hash_aset(box->gvar_tbl,
rb_id2sym(entry->var->id), val);
1079 if (isolation_error) global_entry_isolation_error(
id);
1082 gvar_trace(entry->var, val);
1085 retval = rb_gvar_set_entry(entry, val);
1093 return rb_gvar_set(global_id(name), val);
1099 VALUE retval, gvars, key;
1100 const rb_box_t *box = rb_current_box();
1101 bool use_box_tbl =
false;
1102 bool isolation_error =
false;
1108 entry = global_entry_lookup(
id,
true, &isolation_error);
1110 if (!isolation_error) {
1113 if (gvar_use_box_tbl(box, entry)) {
1115 gvars = box->gvar_tbl;
1117 if (
RTEST(rb_hash_has_key(gvars, key))) {
1118 retval = rb_hash_aref(gvars, key);
1126 retval = (*var->getter)(entry->id, var->data);
1128 retval =
rb_funcall(retval, rb_intern(
"clone"), 0);
1132 if (cache) rb_hash_aset(gvars, key, retval);
1138 if (isolation_error) global_entry_isolation_error(
id);
1141 retval = (*var->getter)(entry->id, var->data);
1149 ID id = find_global_id(name);
1152 rb_warning(
"global variable '%s' not initialized", name);
1156 return rb_gvar_get(
id);
1160rb_gvar_defined(
ID id)
1162 const rb_box_t *box = rb_current_box();
1169 (gvar_use_box_tbl(box, entry) &&
1170 RTEST(rb_hash_has_key(box->gvar_tbl,
rb_id2sym(entry->var->id))));
1172 return RBOOL(defined);
1176rb_gvar_getter_function_of(
ID id)
1179 return entry->var->getter;
1183rb_gvar_setter_function_of(
ID id)
1186 return entry->var->setter;
1189static enum rb_id_table_iterator_result
1190gvar_i(
ID key,
VALUE val,
void *a)
1194 return ID_TABLE_CONTINUE;
1203 if (!rb_ractor_main_p()) {
1204 rb_raise(rb_eRactorIsolationError,
"can not access global variables from non-main Ractors");
1208 rb_id_table_foreach(rb_global_tbl, gvar_i, (
void *)ary);
1209 if (!
NIL_P(backref)) {
1211 int i, nmatch = rb_match_count(backref);
1213 for (i = 1; i <= nmatch; ++i) {
1217 buf[1] = (char)(i +
'0');
1218 sym =
ID2SYM(rb_intern2(buf, 2));
1236 bool tracer_error =
false;
1238 if (!rb_ractor_main_p()) {
1239 rb_raise(rb_eRactorIsolationError,
"can not access global variables from non-main Ractors");
1243 bool isolation_error;
1244 entry2 = global_entry_lookup(name2,
true, &isolation_error);
1245 VM_ASSERT(!isolation_error);
1247 if (!rb_id_table_lookup(gtbl, name1, &data1)) {
1250 rb_id_table_insert(gtbl, name1, (
VALUE)entry1);
1252 else if ((entry1 = (
struct rb_global_entry *)data1)->var != entry2->var) {
1254 if (var->block_trace) {
1255 tracer_error =
true;
1259 if (var->counter == 0) {
1260 free_global_variable(var);
1264 if (!tracer_error && entry1->var != entry2->var) {
1265 entry2->var->counter++;
1266 entry1->var = entry2->var;
1274class_ivar_set_ractor_check(
VALUE klass,
ID id)
1277 UNLIKELY(!rb_class_owned_p(klass))) {
1279 rb_eRactorIsolationError,
1280 "can not set instance variables of classes/modules "
1281 "created by another Ractor (%"PRIsVALUE
" from %"PRIsVALUE
")",
1291cvar_set_ractor_check(
VALUE klass,
ID id)
1293 if (UNLIKELY(!rb_class_owned_p(klass))) {
1294 rb_raise(rb_eRactorIsolationError,
1295 "can not set class variable %"PRIsVALUE
" of %"PRIsVALUE
", which was created by another Ractor",
1296 rb_id2str(
id), klass);
1303 if (UNLIKELY(!rb_class_owned_p(klass)) && !rb_class_field_shareable_p(klass, val)) {
1304 rb_raise(rb_eRactorIsolationError,
1305 "can not read non-shareable class variable %"PRIsVALUE
" of %"PRIsVALUE
", which was created by another Ractor",
1306 rb_id2str(
id), klass);
1311ivar_ractor_assert(
VALUE obj,
ID id)
1319 rb_shape_frozen_p(RBASIC_SHAPE_ID(obj)),
1320 "shareable object must not have writable instance variables");
1324rb_generic_fields_tbl_get(
void)
1326 return generic_fields_tbl_;
1335 if (rb_multi_ractor_p()) {
1343 if (rb_multi_ractor_p()) {
1349rb_mark_generic_ivar(
VALUE obj)
1354 if (rb_gc_during_global_gc_p() && rb_gc_multi_objspace_p()) {
1362 st_lookup(generic_fields_tbl_, (st_data_t)obj, (st_data_t *)&data);
1365 rb_gc_mark_movable(data);
1373rb_obj_fields_generic_uncached(
VALUE obj)
1375 VALUE fields_obj = 0;
1379 found = st_lookup(generic_fields_tbl_, (st_data_t)obj, (st_data_t *)&fields_obj);
1383 rb_bug(
"Object is missing entry in generic_fields_tbl");
1389obj_use_generic_fields_tbl_p(
VALUE obj)
1404obj_fields_get(
VALUE obj)
1412 return ROBJECT_FIELDS_OBJ(obj);
1416 return RCLASS_WRITABLE_FIELDS_OBJ(obj);
1419 return rbimpl_atomic_value_load(&
RTYPEDDATA(obj)->fields_obj, RBIMPL_ATOMIC_ACQUIRE);
1422 return RSTRUCT_FIELDS_OBJ(obj);
1426 VALUE fields_obj = 0;
1428 if (rb_obj_shape_has_fields(obj)) {
1429 rb_execution_context_t *ec = GET_EC();
1430 if (ec->gen_fields_cache.obj == obj && !UNDEF_P(ec->gen_fields_cache.fields_obj) && rb_imemo_fields_owner(ec->gen_fields_cache.fields_obj) == obj) {
1431 fields_obj = ec->gen_fields_cache.fields_obj;
1432 RUBY_ASSERT(fields_obj == rb_obj_fields_generic_uncached(obj));
1435 fields_obj = rb_obj_fields_generic_uncached(obj);
1436 ec->gen_fields_cache.fields_obj = fields_obj;
1437 ec->gen_fields_cache.obj = obj;
1447rb_obj_fields(
VALUE obj,
ID field_name)
1449 ivar_ractor_assert(obj, field_name);
1450 return obj_fields_get(obj);
1454obj_fields(
VALUE obj, shape_id_t shape_id)
1457 ivar_ractor_assert(obj, RSHAPE_EDGE_NAME(shape_id));
1459 return obj_fields_get(obj);
1465 if (rb_obj_gen_fields_p(obj)) {
1466 st_data_t key = (st_data_t)obj, value;
1472 RSTRUCT_SET_FIELDS_OBJ(obj, 0);
1479 rb_execution_context_t *ec = GET_EC();
1480 if (ec->gen_fields_cache.obj == obj) {
1481 ec->gen_fields_cache.obj =
Qundef;
1482 ec->gen_fields_cache.fields_obj =
Qundef;
1487 if (rb_gc_during_global_gc_p() || ruby_vm_during_cleanup) {
1495 deleted = st_delete(generic_fields_tbl_, &key, &value);
1498 rb_bug(
"Object is missing entry in generic_fields_tbl");
1502 RBASIC_SET_SHAPE_ID(obj, ROOT_SHAPE_ID);
1507rb_obj_set_fields(
VALUE obj,
VALUE fields_obj,
ID field_name,
VALUE original_fields_obj)
1509 ivar_ractor_assert(obj, field_name);
1514 rb_imemo_fields_clear(original_fields_obj);
1518 RUBY_ASSERT(IMEMO_TYPE_P(fields_obj, imemo_fields));
1522 if (fields_obj != original_fields_obj) {
1526 ROBJECT_SET_EXTENDED(obj, fields_obj);
1529 RB_OBJ_ATOMIC_WRITE(obj, &
RTYPEDDATA(obj)->fields_obj, fields_obj);
1532 RSTRUCT_SET_FIELDS_OBJ(obj, fields_obj);
1541 bool gc_disabled =
RTEST(rb_gc_local_disable_no_rest());
1542 rb_execution_context_t *insert_ec = GET_EC();
1543 enum ruby_tag_type state;
1545 EC_PUSH_TAG(insert_ec);
1546 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
1547 st_insert(generic_fields_tbl_, (st_data_t)obj, (st_data_t)fields_obj);
1551 if (!gc_disabled) rb_gc_local_enable();
1552 if (state != TAG_NONE) EC_JUMP_TAG(insert_ec, state);
1555 rb_execution_context_t *ec = GET_EC();
1556 if (ec->gen_fields_cache.fields_obj != fields_obj) {
1557 ec->gen_fields_cache.obj = obj;
1558 ec->gen_fields_cache.fields_obj = fields_obj;
1563 if (original_fields_obj && original_fields_obj != obj) {
1565 rb_imemo_fields_clear(original_fields_obj);
1570 RBASIC_SET_SHAPE_ID_WITH_LAYOUT(obj, RBASIC_SHAPE_ID(fields_obj), SHAPE_ID_LAYOUT_EXTENDED);
1573 RBASIC_SET_SHAPE_ID(obj, RBASIC_SHAPE_ID(fields_obj));
1578rb_obj_replace_fields(
VALUE obj,
VALUE fields_obj)
1580 if (obj_use_generic_fields_tbl_p(obj)) {
1584 VALUE original_fields_obj = rb_obj_fields_no_ractor_check(obj);
1585 rb_obj_set_fields(obj, fields_obj, 0, original_fields_obj);
1589 VALUE original_fields_obj = rb_obj_fields_no_ractor_check(obj);
1590 rb_obj_set_fields(obj, fields_obj, 0, original_fields_obj);
1595rb_imemo_fields_field_get(
VALUE fields_obj, shape_id_t target_shape_id)
1597 RUBY_ASSERT(RSHAPE_TYPE_P(target_shape_id, SHAPE_IVAR) || RSHAPE_TYPE_P(target_shape_id, SHAPE_OBJ_ID));
1599 if (UNLIKELY(rb_shape_complex_p(target_shape_id))) {
1600 st_table *fields_hash = rb_imemo_fields_complex_tbl(fields_obj);
1602 st_lookup(fields_hash, RSHAPE_EDGE_NAME(target_shape_id), &value);
1607 attr_index_t index = RSHAPE_INDEX(target_shape_id);
1608 return rb_imemo_fields_ptr(fields_obj)[index];
1612rb_obj_field_get(
VALUE obj, shape_id_t target_shape_id)
1616 return rb_imemo_fields_field_get(obj_fields(obj, target_shape_id), target_shape_id);
1626 VALUE fields_obj = rb_obj_fields(obj, is_class ? 0 :
id);
1632 shape_id_t shape_id = RBASIC_SHAPE_ID(fields_obj);
1635 if (UNLIKELY(rb_shape_complex_p(shape_id))) {
1636 st_table *iv_table = rb_imemo_fields_complex_tbl(fields_obj);
1637 if (!rb_st_lookup(iv_table, (st_data_t)
id, (st_data_t *)&val)) {
1642 attr_index_t index = 0;
1643 if (!rb_shape_get_iv_index(shape_id,
id, &index)) {
1646 val = rb_imemo_fields_ptr(fields_obj)[index];
1650 if (UNLIKELY(!rb_class_owned_p(obj)) && !rb_class_field_shareable_p(obj, val)) {
1652 rb_eRactorIsolationError,
1653 "can not get unshareable values from instance variables of classes/modules "
1654 "created by another Ractor (%"PRIsVALUE
" from %"PRIsVALUE
")",
1667 VALUE iv = rb_ivar_lookup(obj,
id,
Qnil);
1668 RB_DEBUG_COUNTER_INC(ivar_get_base);
1673rb_ivar_get_at(
VALUE obj, attr_index_t index,
ID id)
1684 VALUE fields_obj = RCLASS_WRITABLE_FIELDS_OBJ(obj);
1685 VALUE val = rb_imemo_fields_ptr(fields_obj)[index];
1687 if (UNLIKELY(!rb_class_owned_p(obj)) && !rb_class_field_shareable_p(obj, val)) {
1689 rb_eRactorIsolationError,
1690 "can not get unshareable values from instance variables of classes/modules "
1691 "created by another Ractor (%"PRIsVALUE
" from %"PRIsVALUE
")",
1701 VALUE fields_obj = rb_obj_fields(obj,
id);
1702 return rb_imemo_fields_ptr(fields_obj)[index];
1708rb_ivar_get_at_no_ractor_check(
VALUE obj, attr_index_t index)
1712 VALUE fields_obj = rb_obj_fields_no_ractor_check(obj);
1713 return rb_imemo_fields_ptr(fields_obj)[index];
1719 return rb_ivar_lookup(obj,
id,
Qnil);
1722static VALUE imemo_fields_evacutate_to_complex(
VALUE owner,
VALUE source_fields_obj, shape_id_t shape_id,
int extra_capa);
1725rb_obj_convert_too_complex(
VALUE obj,
VALUE fields_obj, shape_id_t shape_id)
1730 shape_id = rb_shape_transition_complex(shape_id);
1731 VALUE new_fields_obj = imemo_fields_evacutate_to_complex(obj, fields_obj, shape_id, 1);
1732 ROBJECT_SET_EXTENDED(obj, new_fields_obj);
1733 RBASIC_SET_SHAPE_ID_WITH_LAYOUT(obj, shape_id, SHAPE_ID_LAYOUT_EXTENDED);
1740 rb_check_frozen(obj);
1743 bool concurrent =
false;
1747 class_ivar_set_ractor_check(obj,
id);
1749 if (rb_multi_ractor_p()) {
1754 VALUE fields_obj = rb_obj_fields(obj,
id);
1759 const VALUE original_fields_obj = fields_obj;
1761 fields_obj = rb_imemo_fields_clone(fields_obj);
1764 shape_id_t old_shape_id = RBASIC_SHAPE_ID(fields_obj);
1765 shape_id_t removed_shape_id;
1766 shape_id_t next_shape_id = rb_obj_shape_transition_remove_ivar(fields_obj,
id, &removed_shape_id);
1768 if (UNLIKELY(rb_shape_complex_p(next_shape_id))) {
1769 if (UNLIKELY(!rb_shape_complex_p(old_shape_id))) {
1770 fields_obj = imemo_fields_evacutate_to_complex(obj, fields_obj, next_shape_id, -1);
1773 if (!st_delete(rb_imemo_fields_complex_tbl(fields_obj), &key, (st_data_t *)&val)) {
1778 if (next_shape_id == old_shape_id) {
1782 RUBY_ASSERT(removed_shape_id != INVALID_SHAPE_ID);
1783 RUBY_ASSERT(RSHAPE_LEN(next_shape_id) == RSHAPE_LEN(old_shape_id) - 1);
1785 VALUE *fields = rb_imemo_fields_ptr(fields_obj);
1786 attr_index_t removed_index = RSHAPE_INDEX(removed_shape_id);
1787 val = fields[removed_index];
1789 attr_index_t new_fields_count = RSHAPE_LEN(next_shape_id);
1790 if (new_fields_count) {
1791 size_t trailing_fields = new_fields_count - removed_index;
1793 MEMMOVE(&fields[removed_index], &fields[removed_index + 1],
VALUE, trailing_fields);
1794 RBASIC_SET_SHAPE_ID(fields_obj, next_shape_id);
1796 if (
type ==
T_OBJECT && obj != fields_obj && new_fields_count == rb_shape_embedded_capacity(RBASIC_SHAPE_ID(obj))) {
1801 VALUE *embedded_fields = ROBJECT_EMBEDDED_FIELDS(obj);
1802 MEMCPY(embedded_fields, fields,
VALUE, new_fields_count);
1803 for (attr_index_t i = 0; i < new_fields_count; i++) {
1815 if (fields_obj != original_fields_obj) {
1818 if (fields_obj && fields_obj != obj) {
1819 ROBJECT_SET_EXTENDED(obj, fields_obj);
1824 RCLASS_WRITABLE_SET_FIELDS_OBJ(obj, fields_obj);
1827 rb_obj_set_fields(obj, fields_obj,
id, original_fields_obj);
1833 if (!fields_obj || fields_obj == obj) {
1834 RBASIC_SET_SHAPE_ID_WITH_LAYOUT(obj, next_shape_id, SHAPE_ID_LAYOUT_ROBJECT);
1837 RBASIC_SET_SHAPE_ID_WITH_LAYOUT(obj, next_shape_id, SHAPE_ID_LAYOUT_EXTENDED);
1841 RBASIC_SET_SHAPE_ID_ATOMIC(obj, next_shape_id);
1844 RBASIC_SET_SHAPE_ID(obj, next_shape_id);
1851rb_attr_delete(
VALUE obj,
ID id)
1853 return rb_ivar_delete(obj,
id,
Qnil);
1857imemo_fields_complex_from_obj_i(
ID key,
VALUE val, st_data_t arg)
1860 st_table *table = rb_imemo_fields_complex_tbl(fields);
1862 RUBY_ASSERT(!st_lookup(table, (st_data_t)key, NULL));
1863 st_add_direct(table, (st_data_t)key, (st_data_t)val);
1870imemo_fields_shref_i(
ID key,
VALUE val, st_data_t arg)
1877 rb_gc_writebarrier(fields_obj, val);
1885rb_imemo_fields_record_shrefs(
VALUE fields_obj)
1887 rb_field_foreach(fields_obj, imemo_fields_shref_i, (st_data_t)fields_obj,
false);
1891imemo_fields_complex_from_obj(
VALUE owner,
VALUE source, shape_id_t shape_id,
bool ivar_only,
int extra_capa)
1893 attr_index_t
len = source ? RSHAPE_LEN(RBASIC_SHAPE_ID(source)) : 0;
1894 int capa = (
len + extra_capa);
1899 rb_field_foreach(source, imemo_fields_complex_from_obj_i, (st_data_t)fields_obj, ivar_only);
1905imemo_fields_evacutate_to_complex(
VALUE owner,
VALUE source, shape_id_t shape_id,
int extra_capa)
1907 return imemo_fields_complex_from_obj(owner, source, shape_id,
false, extra_capa);
1911rb_obj_complex_fields_build(
VALUE obj)
1913 return imemo_fields_complex_from_obj(obj, obj, ROOT_COMPLEX_SHAPE_ID,
true, 0);
1917imemo_fields_copy_append(
VALUE owner,
VALUE source_fields_obj, shape_id_t current_shape_id, shape_id_t target_shape_id,
VALUE val)
1919 attr_index_t fields_count = RSHAPE_LEN(current_shape_id);
1923 VALUE *fields = rb_imemo_fields_ptr(fields_obj);
1925 if (source_fields_obj) {
1926 MEMCPY(fields, rb_imemo_fields_ptr(source_fields_obj),
VALUE, fields_count);
1927 for (attr_index_t i = 0; i < fields_count; i++) {
1938imemo_fields_set(
VALUE owner,
VALUE fields_obj, shape_id_t target_shape_id,
ID field_name,
VALUE val,
bool concurrent)
1940 const VALUE original_fields_obj = fields_obj;
1941 shape_id_t current_shape_id = fields_obj ? RBASIC_SHAPE_ID(fields_obj) : ROOT_SHAPE_ID;
1943 if (UNLIKELY(rb_shape_complex_p(target_shape_id))) {
1944 if (rb_shape_complex_p(current_shape_id)) {
1949 fields_obj = rb_imemo_fields_clone(fields_obj);
1953 fields_obj = imemo_fields_evacutate_to_complex(owner, original_fields_obj, target_shape_id, 1);
1954 current_shape_id = target_shape_id;
1957 st_table *table = rb_imemo_fields_complex_tbl(fields_obj);
1960 st_insert(table, (st_data_t)field_name, (st_data_t)val);
1962 RBASIC_SET_SHAPE_ID(fields_obj, target_shape_id);
1965 attr_index_t index = RSHAPE_INDEX(target_shape_id);
1966 if (concurrent || index >= rb_shape_embedded_capacity(current_shape_id)) {
1967 return imemo_fields_copy_append(owner, original_fields_obj, current_shape_id, target_shape_id, val);
1970 VALUE *table = rb_imemo_fields_ptr(fields_obj);
1973 if (index >= RSHAPE_LEN(current_shape_id)) {
1974 RBASIC_SET_SHAPE_ID(fields_obj, target_shape_id);
1982generic_field_set(
VALUE obj, shape_id_t target_shape_id,
ID field_name,
VALUE val)
1985 field_name = RSHAPE_EDGE_NAME(target_shape_id);
1989 const VALUE original_fields_obj = rb_obj_fields(obj, field_name);
1992 VALUE fields_obj = imemo_fields_set(obj, original_fields_obj, target_shape_id, field_name, val, concurrent);
1994 rb_obj_set_fields(obj, fields_obj, field_name, original_fields_obj);
1995 return rb_shape_complex_p(target_shape_id) ? ATTR_INDEX_NOT_SET : RSHAPE_INDEX(target_shape_id);
1999generic_shape_ivar(
VALUE obj,
ID id,
bool *new_ivar_out)
2001 bool new_ivar =
false;
2002 shape_id_t current_shape_id = RBASIC_SHAPE_ID(obj);
2003 shape_id_t target_shape_id = current_shape_id;
2005 if (!rb_shape_complex_p(current_shape_id)) {
2006 if (!rb_shape_find_ivar(current_shape_id,
id, &target_shape_id)) {
2008 target_shape_id = rb_obj_shape_transition_add_ivar(obj,
id);
2012 *new_ivar_out = new_ivar;
2013 return target_shape_id;
2020 shape_id_t target_shape_id = generic_shape_ivar(obj,
id, &dontcare);
2021 return generic_field_set(obj, target_shape_id,
id, val);
2025obj_field_set(
VALUE obj, shape_id_t target_shape_id,
ID field_name,
VALUE val)
2028 VALUE fields_obj = ROBJECT_FIELDS_OBJ(obj);
2029 shape_id_t current_shape_id = RBASIC_SHAPE_ID(obj);
2031 if (UNLIKELY(rb_shape_complex_p(target_shape_id))) {
2032 if (UNLIKELY(!rb_shape_complex_p(current_shape_id))) {
2033 current_shape_id = rb_obj_convert_too_complex(obj, fields_obj, current_shape_id);
2034 fields_obj = ROBJECT_FIELDS_OBJ(obj);
2041 field_name = RSHAPE_EDGE_NAME(target_shape_id);
2045 st_insert(rb_imemo_fields_complex_tbl(fields_obj), (st_data_t)field_name, (st_data_t)val);
2048 RBASIC_SET_SHAPE_ID(obj, target_shape_id);
2049 if (obj != fields_obj) {
2050 RBASIC_SET_SHAPE_ID(fields_obj, target_shape_id);
2053 return ATTR_INDEX_NOT_SET;
2056 attr_index_t index = RSHAPE_INDEX(target_shape_id);
2058 if (index < RSHAPE_LEN(current_shape_id)) {
2060 RB_OBJ_WRITE(fields_obj, &rb_imemo_fields_ptr(fields_obj)[index], val);
2064 RUBY_ASSERT(index == RSHAPE_LEN(current_shape_id));
2066 if (UNLIKELY(index >= RSHAPE_CAPACITY(current_shape_id))) {
2067 fields_obj = imemo_fields_copy_append(obj, fields_obj, current_shape_id, target_shape_id, val);
2068 ROBJECT_SET_EXTENDED(obj, fields_obj);
2069 RBASIC_SET_FULL_SHAPE_ID(obj, rb_shape_transition_layout(target_shape_id, SHAPE_ID_LAYOUT_EXTENDED));
2072 RB_OBJ_WRITE(fields_obj, &rb_imemo_fields_ptr(fields_obj)[index], val);
2073 RBASIC_SET_SHAPE_ID(obj, target_shape_id);
2076 if (obj != fields_obj) {
2077 RBASIC_SET_SHAPE_ID(fields_obj, target_shape_id);
2088 shape_id_t target_shape_id = generic_shape_ivar(obj,
id, &dontcare);
2089 return obj_field_set(obj, target_shape_id,
id, val);
2093rb_check_ivar_modifiable(
VALUE obj)
2095 if (UNLIKELY(!
RB_FL_ABLE(obj) || rb_shape_frozen_p(RBASIC_SHAPE_ID(obj)))) {
2096 rb_check_frozen(obj);
2100 rb_raise(rb_eRactorIsolationError,
2101 "can't modify instance variables of a shareable %"PRIsVALUE,
2104 else if (UNLIKELY(CHILLED_STRING_P(obj))) {
2105 CHILLED_STRING_MUTATED(obj);
2118 rb_check_ivar_modifiable(obj);
2119 obj_ivar_set(obj,
id, val);
2133 shape_id_t shape_id = rb_obj_shape_transition_frozen(x);
2138 VALUE fields_obj = RCLASS_WRITABLE_FIELDS_OBJ(x);
2143 fields_obj = rb_imemo_fields_new(x, ROOT_SHAPE_ID,
true);
2145 RCLASS_WRITABLE_SET_FIELDS_OBJ(x, fields_obj);
2149 RBASIC_SET_SHAPE_ID(x, shape_id);
2152 RBASIC_SET_SHAPE_ID(x, shape_id);
2162static attr_index_t class_ivar_set(
VALUE obj,
ID id,
VALUE val,
bool *new_ivar);
2167 RB_DEBUG_COUNTER_INC(ivar_set_base);
2171 return obj_ivar_set(obj,
id, val);
2175 class_ivar_set_ractor_check(obj,
id);
2177 return class_ivar_set(obj,
id, val, &dontcare);
2180 return generic_ivar_set(obj,
id, val);
2187 rb_check_ivar_modifiable(obj);
2188 ivar_set(obj,
id, val);
2195 return ivar_set(obj,
id, val);
2204 ivar_set(obj,
id, val);
2208rb_obj_field_set(
VALUE obj, shape_id_t target_shape_id,
ID field_name,
VALUE val)
2212 return obj_field_set(obj, target_shape_id, field_name, val);
2216 rb_bug(
"Unreachable");
2219 return generic_field_set(obj, target_shape_id, field_name, val);
2224ivar_defined0(
VALUE obj,
ID id)
2226 if (rb_obj_shape_complex_p(obj)) {
2228 VALUE fields_obj = rb_obj_fields_no_ractor_check(obj);
2229 st_table *table = rb_imemo_fields_complex_tbl(fields_obj);
2232 if (!table || !rb_st_lookup(table,
id, &idx)) {
2240 return RBOOL(rb_shape_get_iv_index(RBASIC_SHAPE_ID(obj),
id, &index));
2254 VALUE fields_obj = RCLASS_WRITABLE_FIELDS_OBJ(obj);
2256 defined = ivar_defined0(fields_obj,
id);
2261 defined = ivar_defined0(obj,
id);
2269 struct gen_fields_tbl *fields_tbl;
2271 rb_ivar_foreach_callback_func *func;
2273 shape_id_t shape_id;
2278iterate_over_shapes_callback(shape_id_t shape_id,
void *data)
2282 if (itr_data->ivar_only && !RSHAPE_TYPE_P(shape_id, SHAPE_IVAR)) {
2289 RUBY_ASSERT(!rb_obj_shape_complex_p(itr_data->obj));
2290 fields = ROBJECT_FIELDS(itr_data->obj);
2293 RUBY_ASSERT(IMEMO_TYPE_P(itr_data->obj, imemo_fields));
2294 RUBY_ASSERT(!rb_obj_shape_complex_p(itr_data->obj));
2296 fields = rb_imemo_fields_ptr(itr_data->obj);
2299 rb_bug(
"Unreachable");
2302 RUBY_ASSERT(itr_data->shape_id == RBASIC_SHAPE_ID(itr_data->obj));
2304 VALUE val = fields[RSHAPE_INDEX(shape_id)];
2305 int ret = itr_data->func(RSHAPE_EDGE_NAME(shape_id), val, itr_data->arg);
2307 RUBY_ASSERT(itr_data->shape_id == RBASIC_SHAPE_ID(itr_data->obj));
2316iterate_over_shapes(shape_id_t shape_id, rb_ivar_foreach_callback_func *callback,
struct iv_itr_data *itr_data)
2318 rb_shape_foreach_field(shape_id, iterate_over_shapes_callback, itr_data);
2322each_hash_iv(st_data_t
id, st_data_t val, st_data_t data)
2325 rb_ivar_foreach_callback_func *callback = itr_data->func;
2326 if ((
ID)
id == rb_shape_tree.id_object_id) {
2329 return callback((
ID)
id, (
VALUE)val, itr_data->arg);
2333obj_fields_each(
VALUE obj, rb_ivar_foreach_callback_func *func, st_data_t arg,
bool ivar_only)
2339 .ivar_only = ivar_only,
2342 VALUE fields_obj = ROBJECT_FIELDS_OBJ(obj);
2343 shape_id_t shape_id = RBASIC_SHAPE_ID(obj);
2345 if (rb_shape_complex_p(shape_id)) {
2346 st_foreach_safe(rb_imemo_fields_complex_tbl(fields_obj), each_hash_iv, (st_data_t)&itr_data);
2349 itr_data.fields = rb_imemo_fields_ptr(fields_obj);
2350 itr_data.shape_id = shape_id;
2351 iterate_over_shapes(shape_id, func, &itr_data);
2356imemo_fields_each(
VALUE fields_obj, rb_ivar_foreach_callback_func *func, st_data_t arg,
bool ivar_only)
2358 IMEMO_TYPE_P(fields_obj, imemo_fields);
2364 .ivar_only = ivar_only,
2367 shape_id_t shape_id = RBASIC_SHAPE_ID(fields_obj);
2368 if (rb_shape_complex_p(shape_id)) {
2369 rb_st_foreach(rb_imemo_fields_complex_tbl(fields_obj), each_hash_iv, (st_data_t)&itr_data);
2372 itr_data.fields = rb_imemo_fields_ptr(fields_obj);
2373 itr_data.shape_id = shape_id;
2374 iterate_over_shapes(shape_id, func, &itr_data);
2381 VALUE new_fields_obj;
2383 rb_check_frozen(dest);
2385 if (!rb_obj_gen_fields_p(obj)) {
2389 shape_id_t src_shape_id = rb_obj_shape_id(obj);
2391 VALUE fields_obj = rb_obj_fields_no_ractor_check(obj);
2399 shape_id_t initial_shape_id = rb_obj_shape_id(dest);
2400 shape_id_t dest_shape_id = rb_shape_rebuild(initial_shape_id, src_shape_id);
2402 if (UNLIKELY(rb_shape_complex_p(dest_shape_id))) {
2403 rb_obj_replace_fields(dest, rb_obj_complex_fields_build(obj));
2407 if (!RSHAPE_LEN(dest_shape_id)) {
2408 RBASIC_SET_SHAPE_ID(dest, dest_shape_id);
2413 VALUE *src_buf = rb_imemo_fields_ptr(fields_obj);
2414 VALUE *dest_buf = rb_imemo_fields_ptr(new_fields_obj);
2415 rb_shape_copy_fields(new_fields_obj, dest_buf, dest_shape_id, src_buf, src_shape_id);
2417 rb_obj_replace_fields(dest, new_fields_obj);
2425rb_generic_fields_shared_table_foreach(
void (*cb)(
struct st_table *tbl,
void *arg),
void *arg)
2428 if (generic_fields_tbl_ != NULL) {
2429 cb(generic_fields_tbl_, arg);
2438rb_generic_fields_tables_foreach(
void (*cb)(
struct st_table *tbl,
void *arg),
void *arg)
2440 if (generic_fields_tbl_ != NULL) {
2441 cb(generic_fields_tbl_, arg);
2446rb_field_foreach(
VALUE obj, rb_ivar_foreach_callback_func *func, st_data_t arg,
bool ivar_only)
2451 if (IMEMO_TYPE_P(obj, imemo_fields)) {
2452 imemo_fields_each(obj, func, arg, ivar_only);
2456 obj_fields_each(obj, func, arg, ivar_only);
2463 VALUE fields_obj = RCLASS_WRITABLE_FIELDS_OBJ(obj);
2465 imemo_fields_each(fields_obj, func, arg, ivar_only);
2471 VALUE fields_obj = rb_obj_fields_no_ractor_check(obj);
2473 imemo_fields_each(fields_obj, func, arg, ivar_only);
2486collect_ivar_i(
ID id,
VALUE val, st_data_t arg)
2498 rb_field_foreach(obj, func, arg,
true);
2502rb_ivar_foreach_buffered(
VALUE obj, rb_ivar_foreach_callback_func *func, st_data_t arg)
2505 if (count == 0)
return;
2511 rb_field_foreach(obj, collect_ivar_i, (st_data_t)&pos,
true);
2514 for (st_index_t i = 0; i < count; i++) {
2515 if (func(buf[i].name, buf[i].val, arg) == ST_STOP)
break;
2526 st_index_t iv_count = 0;
2527 VALUE fields_obj = rb_obj_fields_no_ractor_check(obj);
2530 if (rb_obj_shape_complex_p(fields_obj)) {
2531 iv_count = rb_st_table_size(rb_imemo_fields_complex_tbl(fields_obj));
2534 iv_count = RBASIC_FIELDS_COUNT(obj);
2538 if (rb_obj_shape_has_id(obj)) {
2546ivar_i(
ID key,
VALUE v, st_data_t a)
2581#define rb_is_constant_id rb_is_const_id
2582#define rb_is_constant_name rb_is_const_name
2583#define id_for_var(obj, name, part, type) \
2584 id_for_var_message(obj, name, type, "'%1$s' is not allowed as "#part" "#type" variable name")
2585#define id_for_var_message(obj, name, type, message) \
2586 check_id_type(obj, &(name), rb_is_##type##_id, rb_is_##type##_name, message, strlen(message))
2589 int (*valid_id_p)(
ID),
int (*valid_name_p)(
VALUE),
2590 const char *message,
size_t message_len)
2593 VALUE name = *pname;
2595 if (
id ? !valid_id_p(
id) : !valid_name_p(name)) {
2596 rb_name_err_raise_str(rb_fstring_new(message, message_len),
2628 const ID id = id_for_var(obj, name, an, instance);
2632 rb_check_frozen(obj);
2637 if (!UNDEF_P(val))
return val;
2640 rb_name_err_raise(
"instance variable %1$s not defined",
2645NORETURN(
static void uninitialized_constant(
VALUE,
VALUE));
2647uninitialized_constant(
VALUE klass,
VALUE name)
2650 rb_name_err_raise(
"uninitialized constant %2$s::%1$s",
2653 rb_name_err_raise(
"uninitialized constant %1$s",
2661 rb_vm_inc_const_missing_count();
2709 rb_execution_context_t *ec = GET_EC();
2710 VALUE ref = ec->private_const_reference;
2711 rb_vm_pop_cfunc_frame();
2713 ec->private_const_reference = 0;
2714 rb_name_err_raise(
"private constant %2$s::%1$s referenced", ref, name);
2716 uninitialized_constant(klass, name);
2724 struct ccan_list_node cnode;
2727 VALUE autoload_data_value;
2737 VALUE autoload_call_file;
2746 rb_const_flag_t flag;
2762 rb_serial_t fork_gen;
2765 struct ccan_list_head constants;
2769autoload_data_mark_and_move(
void *ptr)
2773 rb_gc_mark_and_move(&p->feature);
2774 rb_gc_mark_and_move(&p->mutex);
2778autoload_data_free(
void *ptr)
2783 ccan_list_for_each_safe(&p->constants,
autoload_const, next, cnode) {
2791autoload_data_memsize(
const void *ptr)
2798 {autoload_data_mark_and_move, autoload_data_free, autoload_data_memsize, autoload_data_mark_and_move},
2803autoload_const_mark_and_move(
void *ptr)
2807 rb_gc_mark_and_move(&ac->module);
2808 rb_gc_mark_and_move(&ac->autoload_call_file);
2809 rb_gc_mark_and_move(&ac->autoload_data_value);
2810 rb_gc_mark_and_move(&ac->value);
2811 rb_gc_mark_and_move(&ac->file);
2812 rb_gc_mark_and_move(&ac->box_value);
2816autoload_const_memsize(
const void *ptr)
2822autoload_const_free(
void *ptr)
2832 {autoload_const_mark_and_move, autoload_const_free, autoload_const_memsize, autoload_const_mark_and_move,},
2837get_autoload_data(
VALUE autoload_const_value,
struct autoload_const **autoload_const_pointer)
2850 if (autoload_const_pointer) *autoload_const_pointer =
autoload_const;
2857autoload_entry(
VALUE mod,
ID id)
2859 rb_const_entry_t *ce = rb_const_lookup(mod,
id);
2860 if (!ce || !UNDEF_P(ce->value))
return 0;
2861 VM_ASSERT(rb_typeddata_is_kind_of(ce->u.autoload_const, &autoload_const_type));
2862 return ce->u.autoload_const;
2867static void const_added(
VALUE klass,
ID const_name);
2877autoload_feature_lookup_or_create(
VALUE feature,
struct autoload_data **autoload_data_pointer)
2879 RUBY_ASSERT_MUTEX_OWNED(autoload_mutex);
2880 RUBY_ASSERT_CRITICAL_SECTION_ENTER();
2882 VALUE autoload_data_value = rb_hash_aref(autoload_features, feature);
2885 if (
NIL_P(autoload_data_value)) {
2891 if (autoload_data_pointer) *autoload_data_pointer =
autoload_data;
2893 rb_hash_aset(autoload_features, feature, autoload_data_value);
2895 else if (autoload_data_pointer) {
2896 *autoload_data_pointer =
rb_check_typeddata(autoload_data_value, &autoload_data_type);
2899 RUBY_ASSERT_CRITICAL_SECTION_LEAVE();
2900 return autoload_data_value;
2904autoload_synchronized(
VALUE _arguments)
2908 rb_const_entry_t *constant_entry = rb_const_lookup(arguments->module, arguments->name);
2909 if (constant_entry && !UNDEF_P(constant_entry->value)) {
2914 const_set(arguments->module, arguments->name,
Qundef);
2915 constant_entry = rb_const_lookup(arguments->module, arguments->name);
2918 VALUE feature = rb_fstring(arguments->feature);
2921 VALUE autoload_data_value = autoload_feature_lookup_or_create(feature, &
autoload_data);
2934 RB_OBJ_WRITE(arguments->module, &constant_entry->u.autoload_const, autoload_const_value);
2943 const rb_box_t *box = rb_current_box();
2944 VALUE current_box_value = rb_get_box_object((rb_box_t *)box);
2947 rb_raise(
rb_eNameError,
"autoload must be constant name: %"PRIsVALUE
"", QUOTE_ID(name));
2950 rb_class_owner_check(module);
2953 if (!RSTRING_LEN(feature)) {
2954 rb_raise(rb_eArgError,
"empty feature name");
2961 .box_value = current_box_value,
2966 if (result ==
Qtrue) {
2967 const_added(module, name);
2972autoload_delete(
VALUE autoload_const_value)
2974 RUBY_ASSERT_CRITICAL_SECTION_ENTER();
2976 VM_ASSERT(rb_typeddata_is_kind_of(autoload_const_value, &autoload_const_type));
2994 RUBY_ASSERT_CRITICAL_SECTION_LEAVE();
3004check_autoload_required(
VALUE mod,
ID id,
const char **loadingpath)
3006 VALUE autoload_const_value = autoload_entry(mod,
id);
3008 const char *loading;
3010 if (!autoload_const_value || !(
autoload_data = get_autoload_data(autoload_const_value, 0))) {
3023 return autoload_const_value;
3026 loading = RSTRING_PTR(feature);
3029 return autoload_const_value;
3032 if (loadingpath && loading) {
3033 *loadingpath = loading;
3034 return autoload_const_value;
3043rb_autoloading_value(
VALUE mod,
ID id,
VALUE* value, rb_const_flag_t *flag)
3046 if (!ac)
return FALSE;
3062 return ele->mutex !=
Qnil && rb_mutex_owned_p(ele->mutex);
3069autoloading_const_entry(
VALUE mod,
ID id)
3071 VALUE load = autoload_entry(mod,
id);
3076 if (!load || !(ele = get_autoload_data(load, &ac))) {
3082 if (autoload_by_current(ele)) {
3083 if (!UNDEF_P(ac->value)) {
3092autoload_defined_p(
VALUE mod,
ID id)
3094 rb_const_entry_t *ce = rb_const_lookup(mod,
id);
3097 if (!ce || !UNDEF_P(ce->value)) {
3103 return !rb_autoloading_value(mod,
id, NULL, NULL);
3122 if (!warning->id)
return;
3124 VALUE name = QUOTE_ID(warning->id);
3127 if (!
NIL_P(warning->file) && warning->line) {
3128 previous = rb_sprintf(
"\n%"PRIsVALUE
":%d: warning: previous definition of %"PRIsVALUE
" was here",
3129 warning->file, warning->line, name);
3133 rb_warn(
"already initialized constant %"PRIsVALUE
"%"PRIsVALUE
"", name, previous);
3136 rb_warn(
"already initialized constant %"PRIsVALUE
"::%"PRIsVALUE
"%"PRIsVALUE
"",
3149 struct autoload_const *autoload_const;
3152 struct autoload_data *autoload_data;
3158 check_before_mod_set(ac->module, ac->name, ac->value,
"constant");
3162 const_tbl_update(ac,
true, &warning);
3164 const_warning_emit(&warning);
3170autoload_load_needed(
VALUE _arguments)
3174 const char *loading = 0, *src;
3176 if (!autoload_defined_p(arguments->module, arguments->name)) {
3180 VALUE autoload_const_value = check_autoload_required(arguments->module, arguments->name, &loading);
3181 if (!autoload_const_value) {
3186 if (src && loading && strcmp(src, loading) == 0) {
3207 return autoload_const_value;
3211autoload_apply_constants(
VALUE _arguments)
3213 RUBY_ASSERT_CRITICAL_SECTION_ENTER();
3225 ccan_list_for_each_safe(&arguments->autoload_data->constants,
autoload_const, next, cnode) {
3231 RUBY_ASSERT_CRITICAL_SECTION_LEAVE();
3238autoload_require_and_apply(
VALUE receiver,
VALUE _arguments)
3242 VALUE result =
rb_funcall(receiver, rb_intern(
"require"), 1, arguments->autoload_data->feature);
3243 if (
RTEST(result)) {
3250autoload_feature_require_in_box(
VALUE receiver,
VALUE _arguments)
3252 rb_vm_frame_flag_set_box_require(GET_EC());
3254 return autoload_require_and_apply(receiver, _arguments);
3258autoload_feature_require(
VALUE _arguments)
3274 rb_gccct_clear_table();
3276 VALUE feature = arguments->autoload_data->feature;
3277 rb_box_t *box = NULL;
3278 if (rb_box_available() && BOX_OBJ_P(autoload_box_value)) {
3279 box = rb_get_box_t(autoload_box_value);
3282 if (box && box->top_self) {
3288 return rb_vm_call_cfunc_in_box(box->top_self, autoload_feature_require_in_box,
3289 box->top_self, _arguments, feature, box);
3291 return autoload_require_and_apply(rb_vm_top_self(), _arguments);
3294static rb_const_entry_t *const_lookup(
struct rb_id_table *tbl,
ID id);
3297static const rb_box_t *
3300 if (rb_box_available() && BOX_OBJ_P(ac->box_value)) {
3301 const rb_box_t *box = rb_get_box_t(ac->box_value);
3302 if (box->top_self)
return box;
3304 return rb_current_box();
3308static rb_const_entry_t *
3309const_lookup_in_box(
VALUE mod,
ID id,
const rb_box_t *box)
3311 return const_lookup(RCLASSEXT_CONST_TBL(RCLASS_EXT_READABLE_IN_BOX(mod, box)),
id);
3315autoload_try_load(
VALUE _arguments)
3320 VALUE result = autoload_feature_require(_arguments);
3323 rb_const_entry_t *ce = rb_const_lookup(arguments->module, arguments->name);
3328 if (ce && UNDEF_P(ce->value)) {
3329 rb_const_entry_t *loaded = const_lookup_in_box(arguments->module, arguments->name,
3330 autoload_box(arguments->autoload_const));
3331 if (loaded && !UNDEF_P(loaded->value)) {
3333 ce->flag = loaded->flag;
3334 RB_OBJ_WRITE(arguments->module, &ce->value, loaded->value);
3335 RB_OBJ_WRITE(arguments->module, &ce->u.file, loaded->u.file);
3336 ce->line = loaded->line;
3343 if (!ce || UNDEF_P(ce->value)) {
3350 "Expected %"PRIsVALUE
" to define %"PRIsVALUE
" but it didn't",
3351 arguments->autoload_data->feature,
3357 "Expected %"PRIsVALUE
" to define %"PRIsVALUE
"::%"PRIsVALUE
" but it didn't",
3358 arguments->autoload_data->feature,
3366 ce->flag |= arguments->flag;
3375 rb_const_entry_t *ce = rb_const_lookup(module, name);
3378 if (!ce || !UNDEF_P(ce->value)) {
3383 if (UNLIKELY(!rb_ractor_main_p())) {
3384 return rb_ractor_autoload_load(module, name);
3394 if (autoload_const_value ==
Qfalse)
return autoload_const_value;
3396 arguments.flag = ce->flag & (CONST_DEPRECATED | CONST_VISIBILITY_MASK);
3413 return rb_autoload_at_p(mod,
id, TRUE);
3417rb_autoload_at_p(
VALUE mod,
ID id,
int recur)
3422 while (!autoload_defined_p(mod,
id)) {
3423 if (!recur)
return Qnil;
3425 if (!mod)
return Qnil;
3427 load = check_autoload_required(mod,
id, 0);
3428 if (!load)
return Qnil;
3429 return (ele = get_autoload_data(load, 0)) ? ele->feature :
Qnil;
3433rb_const_warn_if_deprecated(
const rb_const_entry_t *ce,
VALUE klass,
ID id)
3435 if (RB_CONST_DEPRECATED_P(ce) &&
3448rb_const_unshareable_error(
VALUE klass,
ID id)
3450 rb_raise(rb_eRactorIsolationError,
"can not access non-shareable objects in constant %"PRIsVALUE
"::%"PRIsVALUE
" of a class/module created by another Ractor.",
rb_class_path(klass), rb_id2str(
id));
3454rb_const_get_0(
VALUE klass,
ID id,
int exclude,
int recurse,
int visibility)
3457 VALUE c = rb_const_search(klass,
id, exclude, recurse, visibility, &found_in);
3461 return rb_const_missing(klass,
ID2SYM(
id));
3465rb_const_search_from(
VALUE klass,
ID id,
int exclude,
int recurse,
int visibility,
VALUE *found_in)
3467 VALUE value, current;
3468 bool first_iteration =
true;
3470 for (current = klass;
3472 current =
RCLASS_SUPER(current), first_iteration =
false) {
3475 rb_const_entry_t entry, *ce = &entry;
3477 if (!first_iteration && RCLASS_ORIGIN(current) != current) {
3490 while (rb_const_lookup_copy(tmp,
id, ce)) {
3491 if (visibility && RB_CONST_PRIVATE_P(ce)) {
3492 GET_EC()->private_const_reference = tmp;
3497 if (!UNDEF_P(value) && UNLIKELY(!rb_class_owned_p(tmp)) && !rb_class_field_shareable_p(tmp, value)) {
3498 rb_const_warn_if_deprecated(ce, tmp,
id);
3499 rb_const_unshareable_error(tmp,
id);
3501 rb_const_warn_if_deprecated(ce, tmp,
id);
3502 if (UNDEF_P(value)) {
3504 if (am == tmp)
break;
3506 ac = autoloading_const_entry(tmp,
id);
3508 if (found_in) { *found_in = tmp; }
3509 if (UNLIKELY(!rb_class_owned_p(tmp)) && !rb_class_field_shareable_p(tmp, ac->value)) {
3510 rb_const_unshareable_error(tmp,
id);
3520 if (found_in) { *found_in = tmp; }
3523 if (!recurse)
break;
3527 GET_EC()->private_const_reference = 0;
3532rb_const_search(
VALUE klass,
ID id,
int exclude,
int recurse,
int visibility,
VALUE *found_in)
3537 value = rb_const_search_from(klass,
id, exclude, recurse, visibility, found_in);
3538 if (!UNDEF_P(value))
return value;
3539 if (exclude)
return value;
3542 return rb_const_search_from(
rb_cObject,
id, FALSE, recurse, visibility, found_in);
3548 return rb_const_get_0(klass,
id, TRUE, TRUE, FALSE);
3554 return rb_const_get_0(klass,
id, FALSE, TRUE, FALSE);
3560 return rb_const_get_0(klass,
id, TRUE, FALSE, FALSE);
3564rb_public_const_get_from(
VALUE klass,
ID id)
3566 return rb_const_get_0(klass,
id, TRUE, TRUE, TRUE);
3570rb_public_const_get_at(
VALUE klass,
ID id)
3572 return rb_const_get_0(klass,
id, TRUE, FALSE, TRUE);
3575NORETURN(
static void undefined_constant(
VALUE mod,
VALUE name));
3579 rb_name_err_raise(
"constant %2$s::%1$s not defined",
3584rb_const_location_from(
VALUE klass,
ID id,
int exclude,
int recurse,
int visibility)
3586 while (
RTEST(klass)) {
3587 rb_const_entry_t entry, *ce = &entry;
3589 while (rb_const_lookup_copy(klass,
id, ce)) {
3590 if (visibility && RB_CONST_PRIVATE_P(ce)) {
3597 VALUE file = ce->u.file;
3598 VALUE autoload_const_value = autoload_entry(klass,
id);
3599 if (autoload_const_value) {
3612 if (!recurse)
break;
3621rb_const_location(
VALUE klass,
ID id,
int exclude,
int recurse,
int visibility)
3626 loc = rb_const_location_from(klass,
id, exclude, recurse, visibility);
3627 if (!
NIL_P(loc))
return loc;
3628 if (exclude)
return loc;
3631 return rb_const_location_from(
rb_cObject,
id, FALSE, recurse, visibility);
3635rb_const_source_location(
VALUE klass,
ID id)
3637 return rb_const_location(klass,
id, FALSE, TRUE, FALSE);
3641rb_const_source_location_at(
VALUE klass,
ID id)
3643 return rb_const_location(klass,
id, TRUE, FALSE, FALSE);
3659 const ID id = id_for_var(mod, name, a, constant);
3662 undefined_constant(mod, name);
3667static rb_const_entry_t * const_lookup(
struct rb_id_table *tbl,
ID id);
3673 rb_const_entry_t *ce;
3675 rb_check_frozen(mod);
3676 rb_class_owner_check(mod);
3678 ce = rb_const_lookup(mod,
id);
3682 rb_name_err_raise(
"cannot remove %2$s::%1$s", mod,
ID2SYM(
id));
3685 undefined_constant(mod,
ID2SYM(
id));
3688 VALUE writable_ce = 0;
3691 found = rb_id_table_lookup(RCLASS_WRITABLE_CONST_TBL(mod),
id, &writable_ce);
3692 if (found) rb_id_table_delete(RCLASS_WRITABLE_CONST_TBL(mod),
id);
3694 if (found && (rb_const_entry_t *)writable_ce != ce) {
3695 SIZED_FREE((rb_const_entry_t *)writable_ce);
3698 rb_const_warn_if_deprecated(ce, mod,
id);
3704 autoload_delete(ce->u.autoload_const);
3708 if (ce != const_lookup(RCLASS_PRIME_CONST_TBL(mod),
id)) {
3717cv_i_update(st_data_t *k, st_data_t *v, st_data_t a,
int existing)
3719 if (existing)
return ST_STOP;
3724static enum rb_id_table_iterator_result
3727 rb_const_entry_t *ce = (rb_const_entry_t *)v;
3731 st_update(tbl, (st_data_t)key, cv_i_update, (st_data_t)ce);
3733 return ID_TABLE_CONTINUE;
3736static enum rb_id_table_iterator_result
3737rb_local_constants_i(
ID const_name,
VALUE const_value,
void *ary)
3739 if (
rb_is_const_id(const_name) && !RB_CONST_PRIVATE_P((rb_const_entry_t *)const_value)) {
3742 return ID_TABLE_CONTINUE;
3746rb_local_constants(
VALUE mod)
3755 rb_id_table_foreach(tbl, rb_local_constants_i, (
void *)ary);
3764 st_table *tbl = data;
3766 tbl = st_init_numtable();
3768 if (RCLASS_CONST_TBL(mod)) {
3770 rb_id_table_foreach(RCLASS_CONST_TBL(mod), sv_i, tbl);
3790list_i(st_data_t key, st_data_t value,
VALUE ary)
3793 rb_const_entry_t *ce = (rb_const_entry_t *)value;
3801 st_table *tbl = data;
3833 bool inherit =
true;
3841 return rb_local_constants(mod);
3846rb_const_defined_0(
VALUE klass,
ID id,
int exclude,
int recurse,
int visibility)
3850 rb_const_entry_t entry, *ce = &entry;
3855 if (rb_const_lookup_copy(tmp,
id, ce)) {
3856 if (visibility && RB_CONST_PRIVATE_P(ce)) {
3859 if (UNDEF_P(ce->value) && !check_autoload_required(tmp,
id, 0) &&
3860 !rb_autoloading_value(tmp,
id, NULL, NULL))
3869 if (!recurse)
break;
3883 return rb_const_defined_0(klass,
id, TRUE, TRUE, FALSE);
3889 return rb_const_defined_0(klass,
id, FALSE, TRUE, FALSE);
3895 return rb_const_defined_0(klass,
id, TRUE, FALSE, FALSE);
3899rb_public_const_defined_from(
VALUE klass,
ID id)
3901 return rb_const_defined_0(klass,
id, TRUE, TRUE, TRUE);
3905check_before_mod_set(
VALUE klass,
ID id,
VALUE val,
const char *dest)
3907 rb_check_frozen(klass);
3910static void set_namespace_path(
VALUE named_namespace,
VALUE name);
3912static enum rb_id_table_iterator_result
3913set_namespace_path_i(
ID id,
VALUE v,
void *payload)
3915 rb_const_entry_t *ce = (rb_const_entry_t *)v;
3916 VALUE value = ce->value;
3919 return ID_TABLE_CONTINUE;
3922 bool has_permanent_classpath;
3923 classname(value, &has_permanent_classpath);
3924 if (has_permanent_classpath) {
3925 return ID_TABLE_CONTINUE;
3927 set_namespace_path(value, build_const_path(parental_path,
id));
3929 if (!RCLASS_PERMANENT_CLASSPATH_P(value)) {
3930 RCLASS_WRITE_CLASSPATH(value, 0,
false);
3933 return ID_TABLE_CONTINUE;
3942set_namespace_path(
VALUE named_namespace,
VALUE namespace_path)
3944 struct rb_id_table *const_table = RCLASS_CONST_TBL(named_namespace);
3948 RCLASS_WRITE_CLASSPATH(named_namespace, namespace_path,
true);
3951 rb_id_table_foreach(const_table, set_namespace_path_i, &namespace_path);
3957const_added(
VALUE klass,
ID const_name)
3959 if (GET_VM()->running) {
3961 rb_funcallv_uncached(klass, idConst_added, 1, &arg);
3968 rb_const_entry_t *ce;
3971 rb_raise(
rb_eTypeError,
"no class/module to define constant %"PRIsVALUE
"",
3975 if (UNLIKELY(!rb_class_owned_p(klass))) {
3976 rb_raise(rb_eRactorIsolationError,
"can not set constants of classes/modules created by another Ractor");
3979 check_before_mod_set(klass,
id, val,
"constant");
3983 struct rb_id_table *tbl = RCLASS_WRITABLE_CONST_TBL(klass);
3985 tbl = rb_id_table_create(0);
3986 RCLASS_WRITE_CONST_TBL(klass, tbl,
false);
3988 ce =
ZALLOC(rb_const_entry_t);
3989 rb_id_table_insert(tbl,
id, (
VALUE)ce);
3990 setup_const_entry(ce, klass, val, CONST_PUBLIC);
3994 .module = klass, .name = id,
3995 .value = val, .flag = CONST_PUBLIC,
3998 ac.file = rb_source_location(&ac.line);
3999 const_tbl_update(&ac,
false, &warning);
4002 const_warning_emit(&warning);
4009 bool val_path_permanent;
4010 VALUE val_path = classname(val, &val_path_permanent);
4011 if (
NIL_P(val_path) || !val_path_permanent) {
4013 set_namespace_path(val, rb_id2str(
id));
4016 bool parental_path_permanent;
4017 VALUE parental_path = classname(klass, &parental_path_permanent);
4018 if (
NIL_P(parental_path)) {
4020 parental_path = rb_tmp_class_path(klass, &throwaway, make_temporary_path);
4022 if (parental_path_permanent && !val_path_permanent) {
4023 set_namespace_path(val, build_const_path(parental_path,
id));
4025 else if (!parental_path_permanent &&
NIL_P(val_path)) {
4026 VALUE path = build_const_path(parental_path,
id);
4027 RCLASS_SET_CLASSPATH(val, path,
false);
4037 const_set(klass,
id, val);
4038 const_added(klass,
id);
4042autoload_const_value_for_named_constant(
VALUE module,
ID name,
struct autoload_const **autoload_const_pointer)
4044 VALUE autoload_const_value = autoload_entry(module, name);
4045 if (!autoload_const_value)
return Qfalse;
4052 return autoload_const_value;
4062 ASSERT_vm_locking();
4064 VALUE klass = ac->module;
4065 VALUE val = ac->value;
4067 struct rb_id_table *tbl = RCLASS_CONST_TBL(klass);
4068 rb_const_flag_t visibility = ac->flag;
4069 rb_const_entry_t *ce;
4071 if (rb_id_table_lookup(tbl,
id, &value)) {
4072 ce = (rb_const_entry_t *)value;
4073 if (UNDEF_P(ce->value)) {
4074 RUBY_ASSERT_CRITICAL_SECTION_ENTER();
4075 VALUE file = ac->file;
4076 int line = ac->line;
4077 VALUE autoload_const_value = autoload_const_value_for_named_constant(klass,
id, &ac);
4079 if (!autoload_force && autoload_const_value) {
4083 RB_OBJ_WRITE(autoload_const_value, &ac->file, rb_source_location(&ac->line));
4087 autoload_delete(ce->u.autoload_const);
4088 ce->flag = visibility;
4093 RUBY_ASSERT_CRITICAL_SECTION_LEAVE();
4097 visibility = ce->flag;
4100 warning->module = klass;
4101 warning->file = ce->u.file;
4102 warning->line = ce->line;
4105 setup_const_entry(ce, klass, val, visibility);
4108 tbl = RCLASS_WRITABLE_CONST_TBL(klass);
4111 ce =
ZALLOC(rb_const_entry_t);
4112 rb_id_table_insert(tbl,
id, (
VALUE)ce);
4113 setup_const_entry(ce, klass, val, visibility);
4118setup_const_entry(rb_const_entry_t *ce,
VALUE klass,
VALUE val,
4119 rb_const_flag_t visibility)
4121 ce->flag = visibility;
4123 RB_OBJ_WRITE(klass, &ce->u.file, rb_source_location(&ce->line));
4129 ID id = rb_intern(name);
4132 rb_warn(
"rb_define_const: invalid name '%s' for constant", name);
4135 rb_vm_register_global_object(val);
4147set_const_visibility(
VALUE mod,
int argc,
const VALUE *argv,
4148 rb_const_flag_t flag, rb_const_flag_t mask)
4151 rb_const_entry_t *ce;
4156 rb_warning(
"%"PRIsVALUE
" with no argument is just ignored",
4161 for (i = 0; i < argc; i++) {
4163 VALUE val = argv[i];
4166 undefined_constant(mod, val);
4168 if ((ce = rb_const_lookup(mod,
id))) {
4171 if (UNDEF_P(ce->value)) {
4172 if (autoload_const_value_for_named_constant(mod,
id, &ac)) {
4180 undefined_constant(mod,
ID2SYM(
id));
4188 rb_const_entry_t *ce;
4190 long len = strlen(name);
4194 undefined_constant(mod, rb_fstring_new(name,
len));
4196 if (!(ce = rb_const_lookup(mod,
id))) {
4197 undefined_constant(mod,
ID2SYM(
id));
4199 ce->flag |= CONST_DEPRECATED;
4210rb_mod_private_constant(
int argc,
const VALUE *argv,
VALUE obj)
4212 set_const_visibility(obj, argc, argv, CONST_PRIVATE, CONST_VISIBILITY_MASK);
4224rb_mod_public_constant(
int argc,
const VALUE *argv,
VALUE obj)
4226 set_const_visibility(obj, argc, argv, CONST_PUBLIC, CONST_VISIBILITY_MASK);
4250rb_mod_deprecate_constant(
int argc,
const VALUE *argv,
VALUE obj)
4252 set_const_visibility(obj, argc, argv, CONST_DEPRECATED, CONST_DEPRECATED);
4257original_module(
VALUE c)
4265cvar_lookup_at(
VALUE klass,
ID id, st_data_t *v)
4268 if (RICLASS_IS_ORIGIN_P(klass)) {
4273 klass =
RBASIC(klass)->klass;
4278 if (UNDEF_P(n))
return 0;
4285cvar_front_klass(
VALUE klass)
4287 if (RCLASS_SINGLETON_P(klass)) {
4288 VALUE obj = RCLASS_ATTACHED_OBJECT(klass);
4289 if (rb_namespace_p(obj)) {
4299 if (front && target != front && original_module(front) != original_module(target)) {
4301 "class variable % "PRIsVALUE
" of %"PRIsVALUE
" is overtaken by %"PRIsVALUE
"",
4311 if (front && target != front) {
4314 rb_ivar_delete(front,
id,
Qundef);
4319#define CVAR_FOREACH_ANCESTORS(klass, v, r) \
4320 for (klass = cvar_front_klass(klass); klass; klass = RCLASS_SUPER(klass)) { \
4321 if (cvar_lookup_at(klass, id, (v))) { \
4326#define CVAR_LOOKUP(v,r) do {\
4327 if (cvar_lookup_at(klass, id, (v))) {r;}\
4328 CVAR_FOREACH_ANCESTORS(klass, v, r);\
4348 VALUE tmp, front = 0, target = 0;
4351 CVAR_LOOKUP(0, {
if (!front) front = klass; target = klass;});
4353 cvar_overtaken_check(front, target,
id);
4354 cvar_overtaken(front, target,
id);
4361 target =
RBASIC(target)->klass;
4363 cvar_set_ractor_check(target,
id);
4364 check_before_mod_set(target,
id, val,
"class variable");
4366 bool new_cvar = rb_class_ivar_set(target,
id, val);
4368 VALUE cvc_tbl = RCLASS_WRITABLE_CVC_TBL(target);
4373 if (!cvc_tbl || !rb_marked_id_table_lookup(cvc_tbl,
id, &ent_data)) {
4377 ent->global_cvar_state = GET_GLOBAL_CVAR_STATE();
4379 VALUE new_cvc_tbl = cvc_tbl;
4381 new_cvc_tbl = rb_marked_id_table_new(2);
4383 else if (rb_multi_ractor_p()) {
4384 new_cvc_tbl = rb_marked_id_table_dup(cvc_tbl);
4387 rb_marked_id_table_insert(new_cvc_tbl,
id, (
VALUE)ent);
4388 if (new_cvc_tbl != cvc_tbl) {
4389 RCLASS_WRITE_CVC_TBL(target, new_cvc_tbl);
4391 RB_DEBUG_COUNTER_INC(cvar_inline_miss);
4394 ent = (
void *)ent_data;
4395 ent->global_cvar_state = GET_GLOBAL_CVAR_STATE();
4402 ruby_vm_global_cvar_state++;
4412 value = find_cvar(klass, front, &target,
id);
4414 rb_name_err_raise(
"uninitialized class variable %1$s in %2$s",
4417 cvar_overtaken_check(*front, target,
id);
4420 cvar_overtaken(*front, target,
id);
4434 if (!klass)
return Qfalse;
4435 CVAR_LOOKUP(0,
return Qtrue);
4440cv_intern(
VALUE klass,
const char *name)
4442 ID id = rb_intern(name);
4444 rb_name_err_raise(
"wrong class variable name %1$s",
4453 ID id = cv_intern(klass, name);
4460 ID id = cv_intern(klass, name);
4471cv_i(
ID key,
VALUE v, st_data_t a)
4473 st_table *tbl = (st_table *)a;
4476 st_update(tbl, (st_data_t)key, cv_i_update, 0);
4482mod_cvar_at(
VALUE mod,
void *data)
4484 st_table *tbl = data;
4486 tbl = st_init_numtable();
4488 mod = original_module(mod);
4495mod_cvar_of(
VALUE mod,
void *data)
4498 if (RCLASS_SINGLETON_P(mod)) {
4499 if (rb_namespace_p(RCLASS_ATTACHED_OBJECT(mod))) {
4500 data = mod_cvar_at(tmp, data);
4501 tmp = cvar_front_klass(tmp);
4505 data = mod_cvar_at(tmp, data);
4513cv_list_i(st_data_t key, st_data_t value,
VALUE ary)
4521cvar_list(
void *data)
4523 st_table *tbl = data;
4557 bool inherit =
true;
4562 tbl = mod_cvar_of(mod, 0);
4565 tbl = mod_cvar_at(mod, 0);
4567 return cvar_list(tbl);
4592 const ID id = id_for_var_message(mod, name,
class,
"wrong class variable name %1$s");
4598 rb_check_frozen(mod);
4599 cvar_set_ractor_check(mod,
id);
4600 val = rb_ivar_delete(mod,
id,
Qundef);
4601 if (!UNDEF_P(val)) {
4602 ruby_vm_global_cvar_state++;
4606 rb_name_err_raise(
"cannot remove %1$s for %2$s", mod,
ID2SYM(
id));
4609 rb_name_err_raise(
"class variable %1$s not defined for %2$s",
4628 ID id = rb_intern(name);
4634class_fields_ivar_set(
VALUE klass,
VALUE fields_obj,
ID id,
VALUE val,
bool concurrent,
VALUE *new_fields_obj,
bool *new_ivar_out)
4636 const VALUE original_fields_obj = fields_obj;
4637 fields_obj = original_fields_obj ? original_fields_obj : rb_imemo_fields_new(klass, ROOT_SHAPE_ID,
true);
4639 shape_id_t current_shape_id = RBASIC_SHAPE_ID(fields_obj);
4640 shape_id_t next_shape_id = current_shape_id;
4641 if (UNLIKELY(rb_shape_complex_p(current_shape_id))) {
4646 next_shape_id = generic_shape_ivar(fields_obj,
id, &new_ivar);
4648 if (UNLIKELY(rb_shape_complex_p(next_shape_id))) {
4649 fields_obj = imemo_fields_evacutate_to_complex(klass, fields_obj, next_shape_id, 1);
4653 attr_index_t index = RSHAPE_INDEX(next_shape_id);
4654 if (new_ivar && index >= RSHAPE_CAPACITY(current_shape_id)) {
4657 fields_obj = imemo_fields_copy_append(klass, fields_obj, current_shape_id, next_shape_id, val);
4660 VALUE *fields = rb_imemo_fields_ptr(fields_obj);
4662 if (concurrent && original_fields_obj == fields_obj) {
4668 RB_OBJ_ATOMIC_WRITE(fields_obj, &fields[index], val);
4675 RUBY_ASSERT(rb_shape_layout(next_shape_id) == SHAPE_ID_LAYOUT_ROBJECT);
4676 RBASIC_SET_SHAPE_ID(fields_obj, next_shape_id);
4680 *new_fields_obj = fields_obj;
4681 *new_ivar_out = new_ivar;
4686 if (concurrent && fields_obj == original_fields_obj) {
4690 fields_obj = rb_imemo_fields_clone(fields_obj);
4693 st_table *table = rb_imemo_fields_complex_tbl(fields_obj);
4694 new_ivar = !st_insert(table, (st_data_t)
id, (st_data_t)val);
4697 if (fields_obj != original_fields_obj) {
4698 RUBY_ASSERT(rb_shape_layout(next_shape_id) == SHAPE_ID_LAYOUT_ROBJECT);
4699 RBASIC_SET_SHAPE_ID(fields_obj, next_shape_id);
4703 *new_fields_obj = fields_obj;
4704 *new_ivar_out = new_ivar;
4705 return ATTR_INDEX_NOT_SET;
4709class_ivar_set(
VALUE obj,
ID id,
VALUE val,
bool *new_ivar)
4711 rb_class_ensure_writable(obj);
4713 const VALUE original_fields_obj = RCLASS_WRITABLE_FIELDS_OBJ(obj);
4714 VALUE new_fields_obj = 0;
4716 attr_index_t index = class_fields_ivar_set(obj, original_fields_obj,
id, val, rb_multi_ractor_p(), &new_fields_obj, new_ivar);
4718 if (new_fields_obj != original_fields_obj) {
4719 RCLASS_WRITABLE_SET_FIELDS_OBJ(obj, new_fields_obj);
4725 RBASIC_SET_SHAPE_ID_ATOMIC(obj, RBASIC_SHAPE_ID(new_fields_obj));
4733 rb_check_frozen(obj);
4736 class_ivar_set(obj,
id, val, &new_ivar);
4745 RUBY_ASSERT(RSHAPE_TYPE_P(RBASIC_SHAPE_ID(dst), SHAPE_ROOT));
4747 VALUE fields_obj = RCLASS_WRITABLE_FIELDS_OBJ(src);
4749 VALUE dst_fields_obj = rb_imemo_fields_clone(fields_obj);
4752 shape_id_t shape_id = RBASIC_SHAPE_ID(dst_fields_obj) & ~SHAPE_ID_FL_FROZEN;
4753 RBASIC_SET_SHAPE_ID(dst_fields_obj, shape_id);
4754 RCLASS_WRITABLE_SET_FIELDS_OBJ(dst, dst_fields_obj);
4755 RBASIC_SET_SHAPE_ID(dst, shape_id);
4759static rb_const_entry_t *
4766 r = rb_id_table_lookup(tbl,
id, &val);
4769 if (r)
return (rb_const_entry_t *)val;
4775rb_const_lookup(
VALUE klass,
ID id)
4777 return const_lookup(RCLASS_CONST_TBL(klass),
id);
4783rb_const_lookup_copy(
VALUE klass,
ID id, rb_const_entry_t *ce)
4787 struct rb_id_table *tbl = RCLASS_CONST_TBL(klass);
4789 if (tbl && rb_id_table_lookup(tbl,
id, &entry)) {
4790 *ce = *(rb_const_entry_t *)entry;
#define RUBY_EXTERN
Declaration of externally visible global variables.
static VALUE RB_OBJ_FROZEN_RAW(VALUE obj)
This is an implementation detail of RB_OBJ_FROZEN().
static bool RB_FL_ABLE(VALUE obj)
Checks if the object is flaggable.
static void RB_FL_SET_RAW(VALUE obj, VALUE flags)
This is an implementation detail of RB_FL_SET().
void rb_obj_freeze_inline(VALUE obj)
Prevents further modifications to the given object.
static void RB_FL_UNSET_RAW(VALUE obj, VALUE flags)
This is an implementation detail of RB_FL_UNSET().
@ RUBY_FL_FREEZE
This flag has something to do with data immutability.
void rb_class_modify_check(VALUE klass)
Asserts that klass is not a frozen class.
void rb_freeze_singleton_class(VALUE attached_object)
This is an implementation detail of RB_OBJ_FREEZE().
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Retrieves argument from argc and argv to given VALUE references according to the format string.
#define rb_str_new2
Old name of rb_str_new_cstr.
#define TYPE(_)
Old name of rb_type.
#define ALLOC
Old name of RB_ALLOC.
#define T_STRING
Old name of RUBY_T_STRING.
#define Qundef
Old name of RUBY_Qundef.
#define rb_str_cat2
Old name of rb_str_cat_cstr.
#define T_IMEMO
Old name of RUBY_T_IMEMO.
#define ID2SYM
Old name of RB_ID2SYM.
#define SPECIAL_CONST_P
Old name of RB_SPECIAL_CONST_P.
#define T_STRUCT
Old name of RUBY_T_STRUCT.
#define OBJ_FREEZE
Old name of RB_OBJ_FREEZE.
#define UNREACHABLE_RETURN
Old name of RBIMPL_UNREACHABLE_RETURN.
#define T_DATA
Old name of RUBY_T_DATA.
#define ZALLOC
Old name of RB_ZALLOC.
#define CLASS_OF
Old name of rb_class_of.
#define T_MODULE
Old name of RUBY_T_MODULE.
#define T_ICLASS
Old name of RUBY_T_ICLASS.
#define rb_ary_new3
Old name of rb_ary_new_from_args.
#define FL_USER2
Old name of RUBY_FL_USER2.
#define Qtrue
Old name of RUBY_Qtrue.
#define INT2NUM
Old name of RB_INT2NUM.
#define Qnil
Old name of RUBY_Qnil.
#define Qfalse
Old name of RUBY_Qfalse.
#define T_OBJECT
Old name of RUBY_T_OBJECT.
#define NIL_P
Old name of RB_NIL_P.
#define ALLOCV_N
Old name of RB_ALLOCV_N.
#define T_CLASS
Old name of RUBY_T_CLASS.
#define BUILTIN_TYPE
Old name of RB_BUILTIN_TYPE.
#define rb_ary_new2
Old name of rb_ary_new_capa.
#define ALLOCV_END
Old name of RB_ALLOCV_END.
void rb_category_warn(rb_warning_category_t category, const char *fmt,...)
Identical to rb_category_warning(), except it reports unless $VERBOSE is nil.
void rb_name_error(ID id, const char *fmt,...)
Raises an instance of rb_eNameError.
VALUE rb_eTypeError
TypeError exception.
void rb_name_error_str(VALUE str, const char *fmt,...)
Identical to rb_name_error(), except it takes a VALUE instead of ID.
VALUE rb_eNameError
NameError exception.
VALUE rb_eRuntimeError
RuntimeError exception.
void * rb_check_typeddata(VALUE obj, const rb_data_type_t *data_type)
Identical to rb_typeddata_is_kind_of(), except it raises exceptions instead of returning false.
void rb_warn(const char *fmt,...)
Identical to rb_warning(), except it reports unless $VERBOSE is nil.
void rb_warning(const char *fmt,...)
Issues a warning.
@ RB_WARN_CATEGORY_DEPRECATED
Warning is for deprecated features.
VALUE rb_cObject
Object class.
VALUE rb_obj_hide(VALUE obj)
Make the object invisible from Ruby code.
VALUE rb_obj_class(VALUE obj)
Queries the class of an object.
VALUE rb_cModule
Module class.
VALUE rb_class_real(VALUE klass)
Finds a "real" class.
#define RB_OBJ_WRITTEN(old, oldv, young)
Identical to RB_OBJ_WRITE(), except it doesn't write any values, but only a WB declaration.
#define RB_OBJ_WRITE(old, slot, young)
Declaration of a "back" pointer.
#define RUBY_ASSERT(...)
Asserts that the given expression is truthy if and only if RUBY_DEBUG is truthy.
rb_encoding * rb_usascii_encoding(void)
Queries the encoding that represents US-ASCII.
ID rb_check_id_cstr(const char *ptr, rb_len_t len, rb_encoding *enc)
Identical to rb_check_id(), except it takes a pointer to a memory region instead of Ruby's string.
VALUE rb_funcall(VALUE recv, ID mid, int n,...)
Calls a method.
VALUE rb_funcallv(VALUE recv, ID mid, int argc, const VALUE *argv)
Identical to rb_funcall(), except it takes the method arguments as a C array.
VALUE rb_ary_new_capa(rb_len_t capa)
Identical to rb_ary_new(), except it additionally specifies how many rooms of objects it should alloc...
VALUE rb_ary_new(void)
Allocates a new, empty array.
VALUE rb_ary_hidden_new(rb_len_t capa)
Allocates a hidden (no class) empty array.
VALUE rb_ary_push(VALUE ary, VALUE elem)
Special case of rb_ary_cat() that it adds only one element.
VALUE rb_assoc_new(VALUE car, VALUE cdr)
Identical to rb_ary_new_from_values(), except it expects exactly two parameters.
static int rb_check_arity(int argc, int min, int max)
Ensures that the passed integer is in the passed range.
ID rb_frame_callee(void)
Identical to rb_frame_this_func(), except it returns the named used to call the method.
#define st_foreach_safe
Just another name of rb_st_foreach_safe.
int rb_feature_provided(const char *feature, const char **loading)
Identical to rb_provided(), except it additionally returns the "canonical" name of the loaded feature...
VALUE rb_backref_get(void)
Queries the last match, or Regexp.last_match, or the $~.
int rb_is_instance_id(ID id)
Classifies the given ID, then sees if it is an instance variable.
int rb_is_const_id(ID id)
Classifies the given ID, then sees if it is a constant.
int rb_is_class_id(ID id)
Classifies the given ID, then sees if it is a class variable.
VALUE rb_block_proc(void)
Constructs a Proc object from implicitly passed components.
VALUE rb_reg_nth_defined(int n, VALUE md)
Identical to rb_reg_nth_match(), except it just returns Boolean.
VALUE rb_str_subseq(VALUE str, rb_len_t beg, rb_len_t len)
Identical to rb_str_substr(), except the numbers are interpreted as byte offsets instead of character...
VALUE rb_str_append(VALUE dst, VALUE src)
Identical to rb_str_buf_append(), except it converts the right hand side before concatenating.
VALUE rb_str_new_frozen(VALUE str)
Creates a frozen copy of the string, if necessary.
VALUE rb_str_dup(VALUE str)
Duplicates a string.
#define rb_str_new_cstr(str)
Identical to rb_str_new, except it assumes the passed pointer is a pointer to a C string.
VALUE rb_str_intern(VALUE str)
Identical to rb_to_symbol(), except it assumes the receiver being an instance of RString.
VALUE rb_mutex_new(void)
Creates a mutex.
VALUE rb_mutex_locked_p(VALUE mutex)
Queries if there are any threads that holds the lock.
VALUE rb_mutex_synchronize(VALUE mutex, VALUE(*func)(VALUE arg), VALUE arg)
Obtains the lock, runs the passed function, and releases the lock when it completes.
VALUE rb_exec_recursive_paired(VALUE(*f)(VALUE g, VALUE h, int r), VALUE g, VALUE p, VALUE h)
Identical to rb_exec_recursive(), except it checks for the recursion on the ordered pair of { g,...
VALUE rb_mod_remove_cvar(VALUE mod, VALUE name)
Resembles Module#remove_class_variable.
VALUE rb_obj_instance_variables(VALUE obj)
Resembles Object#instance_variables.
VALUE rb_f_untrace_var(int argc, const VALUE *argv)
Deletes the passed tracer from the passed global variable, or if omitted, deletes everything.
VALUE rb_const_get(VALUE space, ID name)
Identical to rb_const_defined(), except it returns the actual defined value.
VALUE rb_const_list(void *)
This is another mysterious API that comes with no documents at all.
VALUE rb_path2class(const char *path)
Resolves a Q::W::E::R-style path string to the actual class it points.
VALUE rb_autoload_p(VALUE space, ID name)
Queries if an autoload is defined at a point.
void rb_set_class_path(VALUE klass, VALUE space, const char *name)
Names a class.
VALUE rb_ivar_set(VALUE obj, ID name, VALUE val)
Identical to rb_iv_set(), except it accepts the name as an ID instead of a C string.
VALUE rb_mod_remove_const(VALUE space, VALUE name)
Resembles Module#remove_const.
VALUE rb_class_path_cached(VALUE mod)
Just another name of rb_mod_name.
VALUE rb_f_trace_var(int argc, const VALUE *argv)
Traces a global variable.
void rb_cvar_set(VALUE klass, ID name, VALUE val)
Assigns a value to a class variable.
VALUE rb_cvar_get(VALUE klass, ID name)
Obtains a value from a class variable.
VALUE rb_mod_constants(int argc, const VALUE *argv, VALUE recv)
Resembles Module#constants.
VALUE rb_cvar_find(VALUE klass, ID name, VALUE *front)
Identical to rb_cvar_get(), except it takes additional "front" pointer.
VALUE rb_path_to_class(VALUE path)
Identical to rb_path2class(), except it accepts the path as Ruby's string instead of C's.
VALUE rb_ivar_get(VALUE obj, ID name)
Identical to rb_iv_get(), except it accepts the name as an ID instead of a C string.
void rb_const_set(VALUE space, ID name, VALUE val)
Names a constant.
VALUE rb_autoload_load(VALUE space, ID name)
Kicks the autoload procedure as if it was "touched".
VALUE rb_mod_name(VALUE mod)
Queries the name of a module.
VALUE rb_class_name(VALUE obj)
Queries the name of the given object's class.
VALUE rb_const_get_at(VALUE space, ID name)
Identical to rb_const_defined_at(), except it returns the actual defined value.
void rb_set_class_path_string(VALUE klass, VALUE space, VALUE name)
Identical to rb_set_class_path(), except it accepts the name as Ruby's string instead of C's.
void rb_alias_variable(ID dst, ID src)
Aliases a global variable.
void rb_define_class_variable(VALUE, const char *, VALUE)
Just another name of rb_cv_set.
VALUE rb_obj_remove_instance_variable(VALUE obj, VALUE name)
Resembles Object#remove_instance_variable.
void * rb_mod_const_of(VALUE, void *)
This is a variant of rb_mod_const_at().
st_index_t rb_ivar_count(VALUE obj)
Number of instance variables defined on an object.
void * rb_mod_const_at(VALUE, void *)
This API is mysterious.
VALUE rb_const_remove(VALUE space, ID name)
Identical to rb_mod_remove_const(), except it takes the name as ID instead of VALUE.
VALUE rb_const_get_from(VALUE space, ID name)
Identical to rb_const_defined_at(), except it returns the actual defined value.
VALUE rb_ivar_defined(VALUE obj, ID name)
Queries if the instance variable is defined at the object.
VALUE rb_cv_get(VALUE klass, const char *name)
Identical to rb_cvar_get(), except it accepts C's string instead of ID.
int rb_const_defined_at(VALUE space, ID name)
Identical to rb_const_defined(), except it doesn't look for parent classes.
void rb_cv_set(VALUE klass, const char *name, VALUE val)
Identical to rb_cvar_set(), except it accepts C's string instead of ID.
VALUE rb_mod_class_variables(int argc, const VALUE *argv, VALUE recv)
Resembles Module#class_variables.
VALUE rb_f_global_variables(void)
Queries the list of global variables.
VALUE rb_cvar_defined(VALUE klass, ID name)
Queries if the given class has the given class variable.
VALUE rb_class_path(VALUE mod)
Identical to rb_mod_name(), except it returns #<Class: ...> style inspection for anonymous modules.
int rb_const_defined_from(VALUE space, ID name)
Identical to rb_const_defined(), except it returns false for private constants.
int rb_const_defined(VALUE space, ID name)
Queries if the constant is defined at the namespace.
void rb_free_generic_ivar(VALUE obj)
Frees the list of instance variables.
const char * rb_sourcefile(void)
Resembles __FILE__.
void rb_clear_constant_cache_for_id(ID id)
Clears the inline constant caches associated with a particular ID.
int rb_obj_respond_to(VALUE obj, ID mid, int private_p)
Identical to rb_respond_to(), except it additionally takes the visibility parameter.
VALUE rb_id2sym(ID id)
Allocates an instance of rb_cSymbol that has the given id.
ID rb_check_id(volatile VALUE *namep)
Detects if the given name is already interned or not.
ID rb_to_id(VALUE str)
Identical to rb_intern_str(), except it tries to convert the parameter object to an instance of rb_cS...
rb_gvar_setter_t rb_gvar_var_setter
rb_gvar_marker_t rb_gvar_var_marker
void rb_define_global_const(const char *name, VALUE val)
Identical to rb_define_const(), except it defines that of "global", i.e.
VALUE rb_gv_get(const char *name)
Obtains a global variable.
void rb_define_variable(const char *name, VALUE *var)
"Shares" a global variable between Ruby and C.
void rb_gvar_marker_t(VALUE *var)
Type that represents a global variable marker function.
void rb_deprecate_constant(VALUE mod, const char *name)
Asserts that the given constant is deprecated.
void rb_gvar_setter_t(VALUE val, ID id, VALUE *data)
Type that represents a global variable setter function.
rb_gvar_setter_t rb_gvar_val_setter
This is the setter function that backs global variables defined from a ruby script.
rb_gvar_marker_t rb_gvar_undef_marker
void rb_define_readonly_variable(const char *name, const VALUE *var)
Identical to rb_define_variable(), except it does not allow Ruby programs to assign values to such gl...
rb_gvar_setter_t rb_gvar_readonly_setter
This function just raises rb_eNameError.
rb_gvar_getter_t rb_gvar_undef_getter
VALUE rb_gv_set(const char *name, VALUE val)
Assigns to a global variable.
rb_gvar_marker_t rb_gvar_val_marker
This is the setter function that backs global variables defined from a ruby script.
VALUE rb_gvar_getter_t(ID id, VALUE *data)
Type that represents a global variable getter function.
VALUE rb_iv_get(VALUE obj, const char *name)
Obtains an instance variable.
rb_gvar_setter_t rb_gvar_undef_setter
rb_gvar_getter_t rb_gvar_val_getter
This is the getter function that backs global variables defined from a ruby script.
VALUE rb_iv_set(VALUE obj, const char *name, VALUE val)
Assigns to an instance variable.
rb_gvar_getter_t rb_gvar_var_getter
int capa
Designed capacity of the buffer.
int len
Length of the buffer.
#define RB_OBJ_SET_SHAREABLE(obj)
Wrapper of rb_obj_set_shareable().
static bool rb_ractor_shareable_p(VALUE obj)
Queries if multiple Ractors can share the passed object or not.
#define RB_OBJ_SHAREABLE_P(obj)
Queries if the passed object has previously classified as shareable or not.
#define MEMCPY(p1, p2, type, n)
Handy macro to call memcpy.
#define RB_GC_GUARD(v)
Prevents premature destruction of local objects.
#define MEMMOVE(p1, p2, type, n)
Handy macro to call memmove.
void rb_define_hooked_variable(const char *q, VALUE *w, type *e, void_type *r)
Define a function-backended global variable.
VALUE type(ANYARGS)
ANYARGS-ed function type.
void rb_define_virtual_variable(const char *q, type *w, void_type *e)
Define a function-backended global variable.
void rb_ivar_foreach(VALUE q, int_type *w, VALUE e)
Iteration over each instance variable of the object.
VALUE rb_ensure(type *q, VALUE w, type *e, VALUE r)
An equivalent of ensure clause.
void rb_copy_generic_ivar(VALUE clone, VALUE obj)
Copies the list of instance variables.
#define RARRAY_LEN
Just another name of rb_array_len.
static VALUE RBASIC_CLASS(VALUE obj)
Queries the class of an object.
#define RBASIC(obj)
Convenient casting macro.
#define RCLASS_SUPER
Just another name of rb_class_get_superclass.
#define StringValue(v)
Ensures that the parameter object is a String.
static char * RSTRING_END(VALUE str)
Queries the end of the contents pointer of the string.
#define RUBY_TYPED_FREE_IMMEDIATELY
Macros to see if each corresponding flag is defined.
struct rb_data_type_struct rb_data_type_t
This is the struct that holds necessary info for a struct.
#define RTYPEDDATA(obj)
Convenient casting macro.
#define TypedData_Make_Struct(klass, type, data_type, sval)
Identical to TypedData_Wrap_Struct, except it allocates a new data region internally instead of takin...
const char * rb_class2name(VALUE klass)
Queries the name of the passed class.
const char * rb_obj_classname(VALUE obj)
Queries the name of the class of the passed object.
#define RB_NO_KEYWORDS
Do not pass keywords.
static bool RB_SPECIAL_CONST_P(VALUE obj)
Checks if the given object is of enum ruby_special_consts.
#define RTEST
This is an old name of RB_TEST.
#define _(args)
This was a transition path from K&R to ANSI.
C99 shim for <stdbool.h>.
Internal header for Class.
void rb_native_mutex_lock(rb_nativethread_lock_t *lock)
Just another name of rb_nativethread_lock_lock.
void rb_native_mutex_initialize(rb_nativethread_lock_t *lock)
Just another name of rb_nativethread_lock_initialize.
void rb_native_mutex_unlock(rb_nativethread_lock_t *lock)
Just another name of rb_nativethread_lock_unlock.
long rb_len_t
A signed integer type for lengths and indices of objects such as String and Array.
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
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 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_TYPE_P(VALUE obj, enum ruby_value_type t)
Queries if the given object is of given type.