17 #include "ruby/internal/config.h"
21 #include "debug_counter.h"
24 #include "internal/class.h"
25 #include "internal/eval.h"
26 #include "internal/hash.h"
27 #include "internal/object.h"
28 #include "internal/string.h"
29 #include "internal/variable.h"
78 #define METACLASS_OF(k) RBASIC(k)->klass
79 #define SET_METACLASS_OF(k, cls) RBASIC_SET_CLASS(k, cls)
84 push_subclass_entry_to_list(
VALUE super,
VALUE klass)
91 head = RCLASS_SUBCLASSES(super);
94 RCLASS_SUBCLASSES(super) = head;
96 entry->next = head->next;
100 head->next->prev = entry;
108 rb_class_subclass_add(
VALUE super,
VALUE klass)
110 if (super && !UNDEF_P(super)) {
112 RCLASS_SUBCLASS_ENTRY(klass) = entry;
117 rb_module_add_to_subclasses_list(
VALUE module,
VALUE iclass)
120 RCLASS_MODULE_SUBCLASS_ENTRY(iclass) = entry;
124 rb_class_remove_subclass_head(
VALUE klass)
130 head->next->prev = NULL;
132 RCLASS_SUBCLASSES(klass) = NULL;
138 rb_class_remove_from_super_subclasses(
VALUE klass)
155 RCLASS_SUBCLASS_ENTRY(klass) = NULL;
159 rb_class_remove_from_module_subclasses(
VALUE klass)
176 RCLASS_MODULE_SUBCLASS_ENTRY(klass) = NULL;
194 VALUE curklass = cur->klass;
203 class_detach_subclasses(
VALUE klass,
VALUE arg)
205 rb_class_remove_from_super_subclasses(klass);
209 rb_class_detach_subclasses(
VALUE klass)
211 rb_class_foreach_subclass(klass, class_detach_subclasses,
Qnil);
215 class_detach_module_subclasses(
VALUE klass,
VALUE arg)
217 rb_class_remove_from_module_subclasses(klass);
221 rb_class_detach_module_subclasses(
VALUE klass)
223 rb_class_foreach_subclass(klass, class_detach_module_subclasses,
Qnil);
245 NEWOBJ_OF(obj,
struct RClass, klass, flags, alloc_size, 0);
260 RCLASS_SET_ALLOCATOR((
VALUE)obj, 0);
266 RCLASS_M_TBL_INIT(
VALUE c)
268 RCLASS_M_TBL(c) = rb_id_table_create(0);
285 RCLASS_SET_SUPER(klass, super);
286 RCLASS_M_TBL_INIT(klass);
292 class_superclasses_including_self(
VALUE klass)
294 if (
FL_TEST_RAW(klass, RCLASS_SUPERCLASSES_INCLUDE_SELF))
295 return RCLASS_SUPERCLASSES(klass);
297 size_t depth = RCLASS_SUPERCLASS_DEPTH(klass);
300 memcpy(superclasses, RCLASS_SUPERCLASSES(klass),
sizeof(
VALUE) * depth);
301 superclasses[depth] = klass;
303 RCLASS_SUPERCLASSES(klass) = superclasses;
304 FL_SET_RAW(klass, RCLASS_SUPERCLASSES_INCLUDE_SELF);
309 rb_class_update_superclasses(
VALUE klass)
314 if (UNDEF_P(super))
return;
317 if (RCLASS_SUPERCLASSES(klass))
332 rb_class_update_superclasses(super);
335 if (!RCLASS_SUPERCLASS_DEPTH(super))
339 RCLASS_SUPERCLASSES(klass) = class_superclasses_including_self(super);
340 RCLASS_SUPERCLASS_DEPTH(klass) = RCLASS_SUPERCLASS_DEPTH(super) + 1;
347 rb_raise(
rb_eTypeError,
"superclass must be an instance of Class (given an instance of %"PRIsVALUE
")",
350 if (RCLASS_SINGLETON_P(super)) {
366 RCLASS_EXT(klass)->max_iv_count = RCLASS_EXT(super)->max_iv_count;
373 rb_class_s_alloc(
VALUE klass)
381 if (me->def->type == VM_METHOD_TYPE_ISEQ) {
383 rb_vm_rewrite_cref(me->def->body.iseq.
cref, old_klass, new_klass, &new_cref);
384 rb_add_method_iseq(new_klass, mid, me->def->body.iseq.
iseqptr, new_cref, METHOD_ENTRY_VISI(me));
387 rb_method_entry_set(new_klass, mid, me, METHOD_ENTRY_VISI(me));
396 static enum rb_id_table_iterator_result
397 clone_method_i(
ID key,
VALUE value,
void *data)
400 clone_method(arg->old_klass, arg->new_klass, key, (
const rb_method_entry_t *)value);
401 return ID_TABLE_CONTINUE;
417 rb_id_table_insert(arg->tbl, key, (
VALUE)nce);
418 return ID_TABLE_CONTINUE;
421 static enum rb_id_table_iterator_result
422 clone_const_i(
ID key,
VALUE value,
void *data)
428 class_init_copy_check(
VALUE clone,
VALUE orig)
436 if (RCLASS_SINGLETON_P(orig)) {
446 static enum rb_id_table_iterator_result
447 cvc_table_copy(
ID id,
VALUE val,
void *data)
456 ent->class_value = ctx->clone;
457 ent->cref = orig_entry->cref;
458 ent->global_cvar_state = orig_entry->global_cvar_state;
459 rb_id_table_insert(ctx->new_table,
id, (
VALUE)ent);
463 return ID_TABLE_CONTINUE;
469 if (RCLASS_CONST_TBL(clone)) {
470 rb_free_const_table(RCLASS_CONST_TBL(clone));
471 RCLASS_CONST_TBL(clone) = 0;
473 if (RCLASS_CVC_TBL(orig)) {
474 struct rb_id_table *rb_cvc_tbl = RCLASS_CVC_TBL(orig);
475 struct rb_id_table *rb_cvc_tbl_dup = rb_id_table_create(rb_id_table_size(rb_cvc_tbl));
479 ctx.new_table = rb_cvc_tbl_dup;
480 rb_id_table_foreach(rb_cvc_tbl, cvc_table_copy, &ctx);
481 RCLASS_CVC_TBL(clone) = rb_cvc_tbl_dup;
483 rb_id_table_free(RCLASS_M_TBL(clone));
484 RCLASS_M_TBL(clone) = 0;
488 rb_iv_tbl_copy(clone, orig);
490 rb_attr_delete(clone,
id);
492 rb_attr_delete(clone,
id);
494 if (RCLASS_CONST_TBL(orig)) {
497 arg.tbl = RCLASS_CONST_TBL(clone) = rb_id_table_create(0);
499 rb_id_table_foreach(RCLASS_CONST_TBL(orig), clone_const_i, &arg);
503 static bool ensure_origin(
VALUE klass);
508 enum {RMODULE_ALLOCATED_BUT_NOT_INITIALIZED =
RUBY_FL_USER1};
511 RMODULE_UNINITIALIZED(
VALUE module)
513 return FL_TEST_RAW(module, RMODULE_ALLOCATED_BUT_NOT_INITIALIZED);
517 rb_module_set_initialized(
VALUE mod)
519 FL_UNSET_RAW(mod, RMODULE_ALLOCATED_BUT_NOT_INITIALIZED);
524 rb_module_check_initializable(
VALUE mod)
526 if (!RMODULE_UNINITIALIZED(mod)) {
538 class_init_copy_check(clone, orig);
541 rb_module_check_initializable(clone);
551 RCLASS_EXT(clone)->cloned =
true;
552 RCLASS_EXT(orig)->cloned =
true;
554 if (!RCLASS_SINGLETON_P(
CLASS_OF(clone))) {
558 RCLASS_SET_ALLOCATOR(clone, RCLASS_ALLOCATOR(orig));
559 copy_tables(clone, orig);
560 if (RCLASS_M_TBL(orig)) {
562 arg.old_klass = orig;
563 arg.new_klass = clone;
564 RCLASS_M_TBL_INIT(clone);
565 rb_id_table_foreach(RCLASS_M_TBL(orig), clone_method_i, &arg);
568 if (RCLASS_ORIGIN(orig) == orig) {
573 VALUE orig_origin = RCLASS_ORIGIN(orig);
574 VALUE prev_clone_p = clone;
582 ensure_origin(clone);
583 clone_origin = RCLASS_ORIGIN(clone);
585 while (p && p != orig_origin) {
587 rb_bug(
"non iclass between module/class and origin");
593 RCLASS_SET_M_TBL(clone_p, RCLASS_M_TBL(p));
594 RCLASS_SET_SUPER(prev_clone_p, clone_p);
595 prev_clone_p = clone_p;
596 RCLASS_CONST_TBL(clone_p) = RCLASS_CONST_TBL(p);
597 RCLASS_SET_ALLOCATOR(clone_p, RCLASS_ALLOCATOR(p));
599 RCLASS_SET_INCLUDER(clone_p, clone);
602 if (p != RCLASS_ORIGIN(p)) {
604 origin[1] = RCLASS_ORIGIN(p);
607 else if ((origin_len =
RARRAY_LEN(origin_stack)) > 1 &&
609 RCLASS_SET_ORIGIN(
RARRAY_AREF(origin_stack, (origin_len -= 2)), clone_p);
610 RICLASS_SET_ORIGIN_SHARED_MTBL(clone_p);
612 add_subclass = FALSE;
615 rb_module_add_to_subclasses_list(METACLASS_OF(p), clone_p);
620 if (p == orig_origin) {
622 RCLASS_SET_SUPER(clone_p, clone_origin);
623 RCLASS_SET_SUPER(clone_origin,
RCLASS_SUPER(orig_origin));
625 copy_tables(clone_origin, orig_origin);
626 if (RCLASS_M_TBL(orig_origin)) {
628 arg.old_klass = orig;
629 arg.new_klass = clone;
630 RCLASS_M_TBL_INIT(clone_origin);
631 rb_id_table_foreach(RCLASS_M_TBL(orig_origin), clone_method_i, &arg);
635 rb_bug(
"no origin for class that has origin");
638 rb_class_update_superclasses(clone);
647 return rb_singleton_class_clone_and_attach(obj,
Qundef);
652 rb_singleton_class_clone_and_attach(
VALUE obj,
VALUE attach)
654 const VALUE klass = METACLASS_OF(obj);
660 if (!(RCLASS_SINGLETON_P(klass) && RCLASS_ATTACHED_OBJECT(klass) == obj)) {
666 bool klass_of_clone_is_new;
670 klass_of_clone_is_new =
true;
671 RBASIC_SET_CLASS(clone, clone);
677 klass_of_clone_is_new = (METACLASS_OF(klass) != klass_metaclass_clone);
678 RBASIC_SET_CLASS(clone, klass_metaclass_clone);
682 rb_iv_tbl_copy(clone, klass);
683 if (RCLASS_CONST_TBL(klass)) {
685 arg.tbl = RCLASS_CONST_TBL(clone) = rb_id_table_create(0);
687 rb_id_table_foreach(RCLASS_CONST_TBL(klass), clone_const_i, &arg);
689 if (!UNDEF_P(attach)) {
692 RCLASS_M_TBL_INIT(clone);
695 arg.old_klass = klass;
696 arg.new_klass = clone;
697 rb_id_table_foreach(RCLASS_M_TBL(klass), clone_method_i, &arg);
699 if (klass_of_clone_is_new) {
711 if (RCLASS_SINGLETON_P(klass)) {
712 RCLASS_SET_ATTACHED_OBJECT(klass, obj);
721 #define META_CLASS_OF_CLASS_CLASS_P(k) (METACLASS_OF(k) == (k))
724 rb_singleton_class_has_metaclass_p(
VALUE sklass)
726 return RCLASS_ATTACHED_OBJECT(METACLASS_OF(sklass)) == sklass;
730 rb_singleton_class_internal_p(
VALUE sklass)
733 !rb_singleton_class_has_metaclass_p(sklass));
741 #define HAVE_METACLASS_P(k) \
742 (FL_TEST(METACLASS_OF(k), FL_SINGLETON) && \
743 rb_singleton_class_has_metaclass_p(k))
752 #define ENSURE_EIGENCLASS(klass) \
753 (HAVE_METACLASS_P(klass) ? METACLASS_OF(klass) : make_metaclass(klass))
775 SET_METACLASS_OF(klass, metaclass);
776 SET_METACLASS_OF(metaclass, metaclass);
779 VALUE tmp = METACLASS_OF(klass);
780 SET_METACLASS_OF(klass, metaclass);
789 rb_class_update_superclasses(METACLASS_OF(metaclass));
803 VALUE orig_class = METACLASS_OF(obj);
807 RBASIC_SET_CLASS(obj, klass);
809 rb_yjit_invalidate_no_singleton_class(orig_class);
811 SET_METACLASS_OF(klass, METACLASS_OF(
rb_class_real(orig_class)));
817 boot_defclass(
const char *name,
VALUE super)
823 rb_vm_register_global_object(obj);
874 refinement_import_methods(
int argc,
VALUE *argv,
VALUE refinement)
903 rb_vm_register_global_object(rb_cObject);
908 rb_cModule = boot_defclass(
"Module", rb_cObject);
954 if (!super) super = rb_cObject;
956 rb_make_metaclass(klass, METACLASS_OF(super));
974 if (!super) super = rb_cObject;
976 return rb_funcall(super, inherited, 1, klass);
997 rb_vm_register_global_object(klass);
1004 rb_vm_register_global_object(klass);
1018 rb_define_class_id_under_no_pin(
VALUE outer,
ID id,
VALUE super)
1031 "%"PRIsVALUE
"::%"PRIsVALUE
""
1032 " (%"PRIsVALUE
" is given but was %"PRIsVALUE
")",
1053 VALUE klass = rb_define_class_id_under_no_pin(outer,
id, super);
1054 rb_vm_register_global_object(klass);
1059 rb_module_s_alloc(
VALUE klass)
1062 RCLASS_M_TBL_INIT(mod);
1063 FL_SET(mod, RMODULE_ALLOCATED_BUT_NOT_INITIALIZED);
1068 module_new(
VALUE klass)
1071 RCLASS_M_TBL_INIT(mdl);
1108 rb_vm_register_global_object(module);
1112 rb_vm_register_global_object(module);
1137 rb_vm_register_global_object(module);
1143 rb_vm_register_global_object(module);
1149 rb_include_class_new(
VALUE module,
VALUE super)
1153 RCLASS_SET_M_TBL(klass, RCLASS_M_TBL(module));
1155 RCLASS_SET_ORIGIN(klass, klass);
1157 module = METACLASS_OF(module);
1160 if (!RCLASS_CONST_TBL(module)) {
1161 RCLASS_CONST_TBL(module) = rb_id_table_create(0);
1164 RCLASS_CVC_TBL(klass) = RCLASS_CVC_TBL(module);
1165 RCLASS_CONST_TBL(klass) = RCLASS_CONST_TBL(module);
1167 RCLASS_SET_SUPER(klass, super);
1168 RBASIC_SET_CLASS(klass, module);
1170 return (
VALUE)klass;
1173 static int include_modules_at(
const VALUE klass,
VALUE c,
VALUE module,
int search_super);
1180 rb_module_set_initialized(module);
1181 if (!
NIL_P(rb_refinement_module_get_refined_class(module))) {
1191 ensure_includable(klass, module);
1193 changed = include_modules_at(klass, RCLASS_ORIGIN(klass), module, TRUE);
1202 iclass = iclass->next;
1207 VALUE check_class = iclass->klass;
1210 if (!rb_objspace_garbage_object_p(check_class)) {
1211 while (check_class) {
1212 RUBY_ASSERT(!rb_objspace_garbage_object_p(check_class));
1215 (METACLASS_OF(check_class) == module)) {
1222 include_modules_at(iclass->klass, RCLASS_ORIGIN(iclass->klass), module, TRUE);
1226 iclass = iclass->next;
1231 static enum rb_id_table_iterator_result
1232 add_refined_method_entry_i(
ID key,
VALUE value,
void *data)
1234 rb_add_refined_method_entry((
VALUE)data, key);
1235 return ID_TABLE_CONTINUE;
1238 static enum rb_id_table_iterator_result
1239 clear_module_cache_i(
ID id,
VALUE val,
void *data)
1242 rb_clear_method_cache(klass,
id);
1243 return ID_TABLE_CONTINUE;
1247 module_in_super_chain(
const VALUE klass,
VALUE module)
1249 struct rb_id_table *
const klass_m_tbl = RCLASS_M_TBL(RCLASS_ORIGIN(klass));
1252 if (klass_m_tbl == RCLASS_M_TBL(module))
1262 static enum rb_id_table_iterator_result
1263 clear_constant_cache_i(
ID id,
VALUE value,
void *data)
1266 return ID_TABLE_CONTINUE;
1270 do_include_modules_at(
const VALUE klass,
VALUE c,
VALUE module,
int search_super,
bool check_cyclic)
1272 VALUE p, iclass, origin_stack = 0;
1273 int method_changed = 0;
1275 VALUE klass_origin = RCLASS_ORIGIN(klass);
1276 VALUE original_klass = klass;
1278 if (check_cyclic && module_in_super_chain(klass, module))
1283 int superclass_seen = FALSE;
1289 if (klass_origin != c || search_super) {
1295 if (klass_origin == p && !search_super)
1300 if (RCLASS_M_TBL(p) == RCLASS_M_TBL(module)) {
1301 if (!superclass_seen && c_seen) {
1308 superclass_seen = TRUE;
1316 RB_DEBUG_COUNTER_INC(cvar_include_invalidate);
1317 ruby_vm_global_cvar_state++;
1318 tbl = RCLASS_M_TBL(module);
1319 if (tbl && rb_id_table_size(tbl)) {
1322 rb_id_table_foreach(tbl, clear_module_cache_i, (
void *)super_class);
1327 rb_id_table_foreach(tbl, clear_module_cache_i, (
void *)original_klass);
1334 iclass = rb_include_class_new(module, super_class);
1335 c = RCLASS_SET_SUPER(c, iclass);
1336 RCLASS_SET_INCLUDER(iclass, klass);
1337 if (module != RCLASS_ORIGIN(module)) {
1339 VALUE origin[2] = {iclass, RCLASS_ORIGIN(module)};
1342 else if (origin_stack && (origin_len =
RARRAY_LEN(origin_stack)) > 1 &&
1343 RARRAY_AREF(origin_stack, origin_len - 1) == module) {
1344 RCLASS_SET_ORIGIN(
RARRAY_AREF(origin_stack, (origin_len -= 2)), iclass);
1345 RICLASS_SET_ORIGIN_SHARED_MTBL(iclass);
1351 rb_module_add_to_subclasses_list(m, iclass);
1354 VALUE refined_class =
1355 rb_refinement_module_get_refined_class(klass);
1357 rb_id_table_foreach(RCLASS_M_TBL(module), add_refined_method_entry_i, (
void *)refined_class);
1361 tbl = RCLASS_CONST_TBL(module);
1362 if (tbl && rb_id_table_size(tbl))
1363 rb_id_table_foreach(tbl, clear_constant_cache_i, NULL);
1368 return method_changed;
1372 include_modules_at(
const VALUE klass,
VALUE c,
VALUE module,
int search_super)
1374 return do_include_modules_at(klass, c, module, search_super,
true);
1377 static enum rb_id_table_iterator_result
1378 move_refined_method(
ID key,
VALUE value,
void *data)
1382 if (me->def->type == VM_METHOD_TYPE_REFINED) {
1386 if (me->def->body.refined.orig_me) {
1388 RB_OBJ_WRITE(me, &me->def->body.refined.orig_me, NULL);
1389 new_me = rb_method_entry_clone(me);
1390 rb_method_table_insert(klass, tbl, key, new_me);
1391 rb_method_entry_copy(me, orig_me);
1392 return ID_TABLE_CONTINUE;
1395 rb_method_table_insert(klass, tbl, key, me);
1396 return ID_TABLE_DELETE;
1400 return ID_TABLE_CONTINUE;
1404 static enum rb_id_table_iterator_result
1405 cache_clear_refined_method(
ID key,
VALUE value,
void *data)
1409 if (me->def->type == VM_METHOD_TYPE_REFINED && me->def->body.refined.orig_me) {
1411 rb_clear_method_cache(klass, me->called_id);
1416 return ID_TABLE_CONTINUE;
1420 ensure_origin(
VALUE klass)
1422 VALUE origin = RCLASS_ORIGIN(klass);
1423 if (origin == klass) {
1425 RCLASS_SET_M_TBL(origin, RCLASS_M_TBL(klass));
1427 RCLASS_SET_SUPER(klass, origin);
1428 RCLASS_SET_ORIGIN(klass, origin);
1429 RCLASS_M_TBL_INIT(klass);
1430 rb_id_table_foreach(RCLASS_M_TBL(origin), cache_clear_refined_method, (
void *)klass);
1431 rb_id_table_foreach(RCLASS_M_TBL(origin), move_refined_method, (
void *)klass);
1441 bool klass_had_no_origin;
1443 ensure_includable(klass, module);
1444 if (module_in_super_chain(klass, module))
1447 klass_had_no_origin = ensure_origin(klass);
1448 changed = do_include_modules_at(klass, klass, module, FALSE,
false);
1451 rb_vm_check_redefinition_by_prepend(klass);
1458 iclass = iclass->next;
1461 VALUE klass_origin = RCLASS_ORIGIN(klass);
1462 struct rb_id_table *klass_m_tbl = RCLASS_M_TBL(klass);
1463 struct rb_id_table *klass_origin_m_tbl = RCLASS_M_TBL(klass_origin);
1467 if (!rb_objspace_garbage_object_p(iclass->klass)) {
1468 const VALUE subclass = iclass->klass;
1469 if (klass_had_no_origin && klass_origin_m_tbl == RCLASS_M_TBL(subclass)) {
1471 rb_id_table_foreach(RCLASS_M_TBL(subclass), clear_module_cache_i, (
void *)subclass);
1472 RCLASS_M_TBL(subclass) = klass_m_tbl;
1474 RCLASS_SET_SUPER(subclass, origin);
1475 RCLASS_SET_INCLUDER(origin, RCLASS_INCLUDER(subclass));
1476 RCLASS_SET_ORIGIN(subclass, origin);
1477 RICLASS_SET_ORIGIN_SHARED_MTBL(origin);
1479 include_modules_at(subclass, subclass, module, FALSE);
1482 iclass = iclass->next;
1514 VALUE origin = RCLASS_ORIGIN(mod);
1518 VALUE m = METACLASS_OF(p);
1553 if (METACLASS_OF(p) == mod2)
return Qtrue;
1583 refined_class = rb_refinement_module_get_refined_class(mod);
1587 if (p == refined_class)
break;
1588 if (p != RCLASS_ORIGIN(p))
continue;
1604 bool immediate_only;
1608 class_descendants_recursive(
VALUE klass,
VALUE v)
1613 if (data->buffer && data->count < data->maxcount && !rb_objspace_garbage_object_p(klass)) {
1618 if (!data->immediate_only) {
1619 rb_class_foreach_subclass(klass, class_descendants_recursive, v);
1623 rb_class_foreach_subclass(klass, class_descendants_recursive, v);
1628 class_descendants(
VALUE klass,
bool immediate_only)
1633 rb_class_foreach_subclass(klass, class_descendants_recursive, (
VALUE) &data);
1637 data.maxcount = data.count;
1643 rb_class_foreach_subclass(klass, class_descendants_recursive, (
VALUE) &data);
1646 rb_bug(
"GC must not occur during the subclass iteration of Class#descendants");
1694 return class_descendants(klass,
true);
1717 if (!RCLASS_SINGLETON_P(klass)) {
1721 return RCLASS_ATTACHED_OBJECT(klass);
1725 ins_methods_push(st_data_t name, st_data_t ary)
1731 ins_methods_i(st_data_t name, st_data_t
type, st_data_t ary)
1733 switch ((rb_method_visibility_t)
type) {
1734 case METHOD_VISI_UNDEF:
1735 case METHOD_VISI_PRIVATE:
1738 ins_methods_push(name, ary);
1745 ins_methods_type_i(st_data_t name, st_data_t
type, st_data_t ary, rb_method_visibility_t visi)
1747 if ((rb_method_visibility_t)
type == visi) {
1748 ins_methods_push(name, ary);
1754 ins_methods_prot_i(st_data_t name, st_data_t
type, st_data_t ary)
1756 return ins_methods_type_i(name,
type, ary, METHOD_VISI_PROTECTED);
1760 ins_methods_priv_i(st_data_t name, st_data_t
type, st_data_t ary)
1762 return ins_methods_type_i(name,
type, ary, METHOD_VISI_PRIVATE);
1766 ins_methods_pub_i(st_data_t name, st_data_t
type, st_data_t ary)
1768 return ins_methods_type_i(name,
type, ary, METHOD_VISI_PUBLIC);
1772 ins_methods_undef_i(st_data_t name, st_data_t
type, st_data_t ary)
1774 return ins_methods_type_i(name,
type, ary, METHOD_VISI_UNDEF);
1782 static enum rb_id_table_iterator_result
1783 method_entry_i(
ID key,
VALUE value,
void *data)
1787 rb_method_visibility_t
type;
1789 if (me->def->type == VM_METHOD_TYPE_REFINED) {
1790 VALUE owner = me->owner;
1791 me = rb_resolve_refined_method(
Qnil, me);
1792 if (!me)
return ID_TABLE_CONTINUE;
1793 if (!arg->recur && me->owner != owner)
return ID_TABLE_CONTINUE;
1795 if (!st_is_member(arg->list, key)) {
1796 if (UNDEFINED_METHOD_ENTRY_P(me)) {
1797 type = METHOD_VISI_UNDEF;
1800 type = METHOD_ENTRY_VISI(me);
1803 st_add_direct(arg->list, key, (st_data_t)
type);
1805 return ID_TABLE_CONTINUE;
1813 rb_id_table_foreach(m_tbl, method_entry_i, me_arg);
1817 particular_class_p(
VALUE mod)
1819 if (!mod)
return false;
1820 if (RCLASS_SINGLETON_P(mod))
return true;
1826 class_instance_method_list(
int argc,
const VALUE *argv,
VALUE mod,
int obj,
int (*func) (st_data_t, st_data_t, st_data_t))
1829 int recur = TRUE, prepended = 0;
1834 me_arg.list = st_init_numtable();
1835 me_arg.recur = recur;
1838 for (; particular_class_p(mod); mod =
RCLASS_SUPER(mod)) {
1839 add_instance_method_list(mod, &me_arg);
1843 if (!recur && RCLASS_ORIGIN(mod) != mod) {
1844 mod = RCLASS_ORIGIN(mod);
1849 add_instance_method_list(mod, &me_arg);
1855 st_free_table(me_arg.list);
1899 return class_instance_method_list(argc, argv, mod, 0, ins_methods_i);
1914 return class_instance_method_list(argc, argv, mod, 0, ins_methods_prot_i);
1937 return class_instance_method_list(argc, argv, mod, 0, ins_methods_priv_i);
1952 return class_instance_method_list(argc, argv, mod, 0, ins_methods_pub_i);
1964 rb_class_undefined_instance_methods(
VALUE mod)
1967 return class_instance_method_list(1, &include_super, mod, 0, ins_methods_undef_i);
2001 rb_obj_methods(
int argc,
const VALUE *argv,
VALUE obj)
2004 if (argc > 0 && !
RTEST(argv[0])) {
2007 return class_instance_method_list(argc, argv,
CLASS_OF(obj), 1, ins_methods_i);
2020 rb_obj_protected_methods(
int argc,
const VALUE *argv,
VALUE obj)
2022 return class_instance_method_list(argc, argv,
CLASS_OF(obj), 1, ins_methods_prot_i);
2035 rb_obj_private_methods(
int argc,
const VALUE *argv,
VALUE obj)
2037 return class_instance_method_list(argc, argv,
CLASS_OF(obj), 1, ins_methods_priv_i);
2050 rb_obj_public_methods(
int argc,
const VALUE *argv,
VALUE obj)
2052 return class_instance_method_list(argc, argv,
CLASS_OF(obj), 1, ins_methods_pub_i);
2091 VALUE ary, klass, origin;
2097 if (RCLASS_SINGLETON_P(obj)) {
2101 origin = RCLASS_ORIGIN(klass);
2102 me_arg.list = st_init_numtable();
2103 me_arg.recur = recur;
2104 if (klass && RCLASS_SINGLETON_P(klass)) {
2105 if ((mtbl = RCLASS_M_TBL(origin)) != 0) rb_id_table_foreach(mtbl, method_entry_i, &me_arg);
2110 if (klass != origin && (mtbl = RCLASS_M_TBL(klass)) != 0) rb_id_table_foreach(mtbl, method_entry_i, &me_arg);
2116 st_free_table(me_arg.list);
2129 #ifdef rb_define_method_id
2130 #undef rb_define_method_id
2135 rb_add_method_cfunc(klass, mid, func, argc, METHOD_VISI_PUBLIC);
2138 #ifdef rb_define_method
2139 #undef rb_define_method
2144 rb_add_method_cfunc(klass,
rb_intern(name), func, argc, METHOD_VISI_PUBLIC);
2147 #ifdef rb_define_protected_method
2148 #undef rb_define_protected_method
2153 rb_add_method_cfunc(klass,
rb_intern(name), func, argc, METHOD_VISI_PROTECTED);
2156 #ifdef rb_define_private_method
2157 #undef rb_define_private_method
2162 rb_add_method_cfunc(klass,
rb_intern(name), func, argc, METHOD_VISI_PRIVATE);
2168 rb_add_method(klass,
rb_intern(name), VM_METHOD_TYPE_UNDEF, 0, METHOD_VISI_UNDEF);
2171 static enum rb_id_table_iterator_result
2172 undef_method_i(
ID name,
VALUE value,
void *data)
2175 rb_add_method(klass, name, VM_METHOD_TYPE_UNDEF, 0, METHOD_VISI_UNDEF);
2176 return ID_TABLE_CONTINUE;
2180 rb_undef_methods_from(
VALUE klass,
VALUE super)
2184 rb_id_table_foreach(mtbl, undef_method_i, (
void *)klass);
2197 special_singleton_class_of(
VALUE obj)
2203 default:
return Qnil;
2208 rb_special_singleton_class(
VALUE obj)
2210 return special_singleton_class_of(obj);
2223 singleton_class_of(
VALUE obj)
2227 switch (
TYPE(obj)) {
2237 klass = special_singleton_class_of(obj);
2239 rb_bug(
"unknown immediate %p", (
void *)obj);
2243 if (CHILLED_STRING_P(obj)) {
2244 CHILLED_STRING_MUTATED(obj);
2251 klass = METACLASS_OF(obj);
2252 if (!(RCLASS_SINGLETON_P(klass) &&
2253 RCLASS_ATTACHED_OBJECT(klass) == obj)) {
2254 klass = rb_make_metaclass(obj, klass);
2266 if (!RCLASS_SINGLETON_P(x)) {
2288 return rb_special_singleton_class(obj);
2290 klass = METACLASS_OF(obj);
2291 if (!RCLASS_SINGLETON_P(klass))
return Qnil;
2292 if (RCLASS_ATTACHED_OBJECT(klass) != obj)
return Qnil;
2299 VALUE klass = singleton_class_of(obj);
2316 #ifdef rb_define_singleton_method
2317 #undef rb_define_singleton_method
2325 #ifdef rb_define_module_function
2326 #undef rb_define_module_function
2335 #ifdef rb_define_global_function
2336 #undef rb_define_global_function
2357 rb_keyword_error_new(
const char *error,
VALUE keys)
2367 if (++i >=
len)
break;
2375 NORETURN(
static void rb_keyword_error(
const char *error,
VALUE keys));
2377 rb_keyword_error(
const char *error,
VALUE keys)
2382 NORETURN(
static void unknown_keyword_error(
VALUE hash,
const ID *table,
int keywords));
2384 unknown_keyword_error(
VALUE hash,
const ID *table,
int keywords)
2387 for (i = 0; i < keywords; i++) {
2388 st_data_t key =
ID2SYM(table[i]);
2389 rb_hash_stlike_delete(hash, &key, NULL);
2391 rb_keyword_error(
"unknown", rb_hash_keys(hash));
2396 separate_symbol(st_data_t key, st_data_t value, st_data_t arg)
2408 VALUE parthash[2] = {0, 0};
2409 VALUE hash = *orighash;
2416 *orighash = parthash[1];
2431 #define extract_kwarg(keyword, val) \
2432 (key = (st_data_t)(keyword), values ? \
2433 (rb_hash_stlike_delete(keyword_hash, &key, &(val)) || ((val) = Qundef, 0)) : \
2434 rb_hash_stlike_lookup(keyword_hash, key, NULL))
2436 if (
NIL_P(keyword_hash)) keyword_hash = 0;
2440 optional = -1-optional;
2443 for (; i < required; i++) {
2446 if (extract_kwarg(keyword, values[i])) {
2453 if (!
NIL_P(missing)) {
2454 rb_keyword_error(
"missing", missing);
2458 if (optional && keyword_hash) {
2459 for (i = 0; i < optional; i++) {
2460 if (extract_kwarg(
ID2SYM(table[required+i]), values[required+i])) {
2465 if (!rest && keyword_hash) {
2466 if (
RHASH_SIZE(keyword_hash) > (
unsigned int)(values ? 0 : j)) {
2467 unknown_keyword_error(keyword_hash, table, required+optional);
2470 if (values && !keyword_hash) {
2471 for (i = 0; i < required + optional; i++) {
2476 #undef extract_kwarg
2490 rb_scan_args_parse(
int kw_flag,
const char *fmt,
struct rb_scan_args_t *arg)
2492 const char *p = fmt;
2494 memset(arg, 0,
sizeof(*arg));
2495 arg->kw_flag = kw_flag;
2498 arg->n_lead = *p -
'0';
2501 arg->n_opt = *p -
'0';
2510 arg->n_trail = *p -
'0';
2522 rb_fatal(
"bad scan arg format: %s", fmt);
2527 rb_scan_args_assign(
const struct rb_scan_args_t *arg,
int argc,
const VALUE *
const argv, va_list vargs)
2531 #define rb_scan_args_next_param() va_arg(vargs, VALUE *)
2532 const int kw_flag = arg->kw_flag;
2533 const int n_lead = arg->n_lead;
2534 const int n_opt = arg->n_opt;
2535 const int n_trail = arg->n_trail;
2536 const int n_mand = n_lead + n_trail;
2537 const bool f_var = arg->f_var;
2538 const bool f_hash = arg->f_hash;
2539 const bool f_block = arg->f_block;
2542 if (f_hash && argc > 0) {
2543 VALUE last = argv[argc - 1];
2544 if (rb_scan_args_keyword_p(kw_flag, last)) {
2550 if (argc < n_mand) {
2555 for (i = 0; i < n_lead; i++) {
2556 var = rb_scan_args_next_param();
2557 if (var) *var = argv[argi];
2561 for (i = 0; i < n_opt; i++) {
2562 var = rb_scan_args_next_param();
2563 if (argi < argc - n_trail) {
2564 if (var) *var = argv[argi];
2568 if (var) *var =
Qnil;
2573 int n_var = argc - argi - n_trail;
2575 var = rb_scan_args_next_param();
2585 for (i = 0; i < n_trail; i++) {
2586 var = rb_scan_args_next_param();
2587 if (var) *var = argv[argi];
2592 var = rb_scan_args_next_param();
2593 if (var) *var = hash;
2597 var = rb_scan_args_next_param();
2612 #undef rb_scan_args_next_param
2616 rb_scan_args_result(
const struct rb_scan_args_t *
const arg,
int argc)
2618 const int n_lead = arg->n_lead;
2619 const int n_opt = arg->n_opt;
2620 const int n_trail = arg->n_trail;
2621 const int n_mand = n_lead + n_trail;
2622 const bool f_var = arg->f_var;
2640 va_start(vargs,fmt);
2641 argc = rb_scan_args_assign(&arg, argc, argv, vargs);
2643 return rb_scan_args_result(&arg, argc);
2646 #undef rb_scan_args_kw
2652 rb_scan_args_parse(kw_flag, fmt, &arg);
2653 va_start(vargs,fmt);
2654 argc = rb_scan_args_assign(&arg, argc, argv, vargs);
2656 return rb_scan_args_result(&arg, argc);
#define RUBY_ASSERT(...)
Asserts that the given expression is truthy if and only if RUBY_DEBUG is truthy.
#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 void RB_FL_SET_RAW(VALUE obj, VALUE flags)
This is an implementation detail of RB_FL_SET().
@ RUBY_FL_USER1
User-defined flag.
VALUE rb_class_protected_instance_methods(int argc, const VALUE *argv, VALUE mod)
Identical to rb_class_instance_methods(), except it returns names of methods that are protected only.
void rb_include_module(VALUE klass, VALUE module)
Includes a module to a class.
VALUE rb_refinement_new(void)
Creates a new, anonymous refinement.
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
VALUE rb_class_new(VALUE super)
Creates a new, anonymous class.
static VALUE make_singleton_class(VALUE obj)
Creates a singleton class for obj.
VALUE rb_singleton_class_clone(VALUE obj)
Clones a singleton class.
void rb_prepend_module(VALUE klass, VALUE module)
Identical to rb_include_module(), except it "prepends" the passed module to the klass,...
VALUE rb_class_subclasses(VALUE klass)
Queries the class's direct descendants.
VALUE rb_singleton_class(VALUE obj)
Finds or creates the singleton class of the passed object.
void Init_class_hierarchy(void)
Internal header aggregating init functions.
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
VALUE rb_class_attached_object(VALUE klass)
Returns the attached object for a singleton class.
VALUE rb_obj_singleton_methods(int argc, const VALUE *argv, VALUE obj)
Identical to rb_class_instance_methods(), except it returns names of singleton methods instead of ins...
VALUE rb_module_new(void)
Creates a new, anonymous module.
#define META_CLASS_OF_CLASS_CLASS_P(k)
whether k is a meta^(n)-class of Class class
VALUE rb_class_instance_methods(int argc, const VALUE *argv, VALUE mod)
Generates an array of symbols, which are the list of method names defined in the passed class.
void rb_check_inheritable(VALUE super)
Asserts that the given class can derive a child class.
VALUE rb_class_public_instance_methods(int argc, const VALUE *argv, VALUE mod)
Identical to rb_class_instance_methods(), except it returns names of methods that are public only.
VALUE rb_class_boot(VALUE super)
A utility function that wraps class_alloc.
VALUE rb_define_module(const char *name)
Defines a top-level module.
void rb_class_modify_check(VALUE klass)
Asserts that klass is not a frozen class.
VALUE rb_define_module_id_under(VALUE outer, ID id)
Identical to rb_define_module_under(), except it takes the name in ID instead of C's string.
void rb_singleton_class_attached(VALUE klass, VALUE obj)
Attaches a singleton class to its corresponding object.
void rb_freeze_singleton_class(VALUE x)
This is an implementation detail of RB_OBJ_FREEZE().
VALUE rb_mod_included_modules(VALUE mod)
Queries the list of included modules.
VALUE rb_define_class_id_under(VALUE outer, ID id, VALUE super)
Identical to rb_define_class_under(), except it takes the name in ID instead of C's string.
VALUE rb_mod_ancestors(VALUE mod)
Queries the module's ancestors.
static VALUE make_metaclass(VALUE klass)
Creates a metaclass of klass
static VALUE class_alloc(VALUE flags, VALUE klass)
Allocates a struct RClass for a new class.
VALUE rb_class_inherited(VALUE super, VALUE klass)
Calls Class::inherited.
VALUE rb_mod_include_p(VALUE mod, VALUE mod2)
Queries if the passed module is included by the module.
VALUE rb_class_private_instance_methods(int argc, const VALUE *argv, VALUE mod)
Identical to rb_class_instance_methods(), except it returns names of methods that are private only.
#define ENSURE_EIGENCLASS(klass)
ensures klass belongs to its own eigenclass.
VALUE rb_mod_init_copy(VALUE clone, VALUE orig)
The comment that comes with this function says :nodoc:.
VALUE rb_define_module_under(VALUE outer, const char *name)
Defines a module under the namespace of outer.
VALUE rb_singleton_class_get(VALUE obj)
Returns the singleton class of obj, or nil if obj is not a singleton object.
VALUE rb_define_module_id(ID id)
This is a very badly designed API that creates an anonymous module.
VALUE rb_define_class_id(ID id, VALUE super)
This is a very badly designed API that creates an anonymous class.
void rb_define_alias(VALUE klass, const char *name1, const char *name2)
Defines an alias of a method.
void rb_define_module_function(VALUE module, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a module function for a module.
void rb_define_protected_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Identical to rb_define_method(), except it defines a protected method.
VALUE rb_extract_keywords(VALUE *orighash)
Splits a hash into two.
void rb_define_attr(VALUE klass, const char *name, int read, int write)
Defines public accessor method(s) for an attribute.
void rb_define_private_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Identical to rb_define_method(), except it defines a private method.
void rb_undef_method(VALUE klass, const char *name)
Defines an undef of a method.
int rb_scan_args_kw(int kw_flag, int argc, const VALUE *argv, const char *fmt,...)
Identical to rb_scan_args(), except it also accepts kw_splat.
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.
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a method.
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Identical to rb_define_method(), except it defines a singleton method.
int rb_block_given_p(void)
Determines if the current method is given a block.
void rb_define_method_id(VALUE klass, ID mid, VALUE(*func)(ANYARGS), int argc)
Identical to rb_define_method(), except it takes the name of the method in ID instead of C's string.
int rb_get_kwargs(VALUE keyword_hash, const ID *table, int required, int optional, VALUE *values)
Keyword argument deconstructor.
void rb_define_global_function(const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a global function.
#define TYPE(_)
Old name of rb_type.
#define FL_SINGLETON
Old name of RUBY_FL_SINGLETON.
#define FL_UNSET_RAW
Old name of RB_FL_UNSET_RAW.
#define OBJ_INIT_COPY(obj, orig)
Old name of RB_OBJ_INIT_COPY.
#define ALLOC
Old name of RB_ALLOC.
#define T_STRING
Old name of RUBY_T_STRING.
#define xfree
Old name of ruby_xfree.
#define T_MASK
Old name of RUBY_T_MASK.
#define Qundef
Old name of RUBY_Qundef.
#define T_NIL
Old name of RUBY_T_NIL.
#define T_FLOAT
Old name of RUBY_T_FLOAT.
#define ID2SYM
Old name of RB_ID2SYM.
#define T_BIGNUM
Old name of RUBY_T_BIGNUM.
#define SPECIAL_CONST_P
Old name of RB_SPECIAL_CONST_P.
#define OBJ_FREEZE
Old name of RB_OBJ_FREEZE.
#define T_FIXNUM
Old name of RUBY_T_FIXNUM.
#define UNREACHABLE_RETURN
Old name of RBIMPL_UNREACHABLE_RETURN.
#define ZALLOC
Old name of RB_ZALLOC.
#define CLASS_OF
Old name of rb_class_of.
#define xmalloc
Old name of ruby_xmalloc.
#define T_MODULE
Old name of RUBY_T_MODULE.
#define ISDIGIT
Old name of rb_isdigit.
#define T_TRUE
Old name of RUBY_T_TRUE.
#define T_ICLASS
Old name of RUBY_T_ICLASS.
#define FL_TEST_RAW
Old name of RB_FL_TEST_RAW.
#define FL_SET
Old name of RB_FL_SET.
#define T_FALSE
Old name of RUBY_T_FALSE.
#define Qtrue
Old name of RUBY_Qtrue.
#define Qnil
Old name of RUBY_Qnil.
#define Qfalse
Old name of RUBY_Qfalse.
#define NIL_P
Old name of RB_NIL_P.
#define FL_WB_PROTECTED
Old name of RUBY_FL_WB_PROTECTED.
#define T_SYMBOL
Old name of RUBY_T_SYMBOL.
#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 FL_FREEZE
Old name of RUBY_FL_FREEZE.
#define CONST_ID
Old name of RUBY_CONST_ID.
#define rb_ary_new2
Old name of rb_ary_new_capa.
#define FL_SET_RAW
Old name of RB_FL_SET_RAW.
#define SYMBOL_P
Old name of RB_SYMBOL_P.
void rb_raise(VALUE exc, const char *fmt,...)
Exception entry point.
void rb_exc_raise(VALUE mesg)
Raises an exception in the current thread.
void rb_bug(const char *fmt,...)
Interpreter panic switch.
VALUE rb_eTypeError
TypeError exception.
void rb_fatal(const char *fmt,...)
Raises the unsung "fatal" exception.
VALUE rb_exc_new_str(VALUE etype, VALUE str)
Identical to rb_exc_new_cstr(), except it takes a Ruby's string instead of C's.
VALUE rb_eArgError
ArgumentError exception.
VALUE rb_cClass
Class class.
VALUE rb_mKernel
Kernel module.
VALUE rb_cRefinement
Refinement class.
VALUE rb_cNilClass
NilClass class.
VALUE rb_cHash
Hash class.
VALUE rb_cFalseClass
FalseClass class.
VALUE rb_obj_class(VALUE obj)
Queries the class of an object.
VALUE rb_inspect(VALUE obj)
Generates a human-readable textual representation of the given object.
VALUE rb_cBasicObject
BasicObject class.
VALUE rb_cModule
Module class.
VALUE rb_class_real(VALUE klass)
Finds a "real" class.
VALUE rb_cTrueClass
TrueClass 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.
VALUE rb_funcall(VALUE recv, ID mid, int n,...)
Calls a method.
#define RGENGC_WB_PROTECTED_CLASS
This is a compile-time flag to enable/disable write barrier for struct RClass.
size_t rb_gc_count(void)
Identical to rb_gc_stat(), with "count" parameter.
VALUE rb_ary_new_from_values(long n, const VALUE *elts)
Identical to rb_ary_new_from_args(), except how objects are passed.
VALUE rb_ary_cat(VALUE ary, const VALUE *train, long len)
Destructively appends multiple elements at the end of the array.
VALUE rb_ary_new(void)
Allocates a new, empty array.
VALUE rb_ary_new_capa(long capa)
Identical to rb_ary_new(), except it additionally specifies how many rooms of objects it should alloc...
VALUE rb_ary_resize(VALUE ary, long len)
Expands or shrinks the passed array to the passed length.
VALUE rb_ary_hidden_new(long 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.
#define UNLIMITED_ARGUMENTS
This macro is used in conjunction with rb_check_arity().
static int rb_check_arity(int argc, int min, int max)
Ensures that the passed integer is in the passed range.
void rb_hash_foreach(VALUE hash, int(*func)(VALUE key, VALUE val, VALUE arg), VALUE arg)
Iterates over a hash.
VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE val)
Inserts or replaces ("upsert"s) the objects into the given hash table.
VALUE rb_hash_dup(VALUE hash)
Duplicates a hash.
VALUE rb_hash_new(void)
Creates a new, empty hash object.
VALUE rb_block_proc(void)
Constructs a Proc object from implicitly passed components.
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_cat_cstr(VALUE dst, const char *src)
Identical to rb_str_cat(), except it assumes the passed pointer is a pointer to a C string.
VALUE rb_const_get(VALUE space, ID name)
Identical to rb_const_defined(), except it returns the actual defined value.
void rb_const_set(VALUE space, ID name, VALUE val)
Names a constant.
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.
int rb_const_defined_at(VALUE space, ID name)
Identical to rb_const_defined(), except it doesn't look for parent classes.
VALUE rb_class_path(VALUE mod)
Identical to rb_mod_name(), except it returns #<Class: ...> style inspection for anonymous modules.
int rb_const_defined(VALUE space, ID name)
Queries if the constant is defined at the namespace.
void rb_alias(VALUE klass, ID dst, ID src)
Resembles alias.
void rb_attr(VALUE klass, ID name, int need_reader, int need_writer, int honour_visibility)
This function resembles now-deprecated Module#attr.
void rb_clear_constant_cache_for_id(ID id)
Clears the inline constant caches associated with a particular ID.
static ID rb_intern_const(const char *str)
This is a "tiny optimisation" over rb_intern().
ID rb_intern(const char *name)
Finds or creates a symbol of the given name.
VALUE rb_id2str(ID id)
Identical to rb_id2name(), except it returns a Ruby's String instead of C's.
int len
Length of the buffer.
VALUE rb_sprintf(const char *fmt,...)
Ruby's extended sprintf(3).
#define MEMCPY(p1, p2, type, n)
Handy macro to call memcpy.
VALUE type(ANYARGS)
ANYARGS-ed function type.
int st_foreach(st_table *q, int_type *w, st_data_t e)
Iteration over the given table.
#define RARRAY_LEN
Just another name of rb_array_len.
#define RARRAY_AREF(a, i)
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 RHASH_SIZE(h)
Queries the size of the hash.
#define RHASH_EMPTY_P(h)
Checks if the hash is empty.
#define RB_SCAN_ARGS_PASS_CALLED_KEYWORDS
Same behaviour as rb_scan_args().
#define RTEST
This is an old name of RB_TEST.
#define ANYARGS
Functions declared using this macro take arbitrary arguments, including void.
rb_cref_t * cref
class reference, should be marked
const rb_iseq_t * iseqptr
iseq pointer, should be separated from iseqval
Internal header for Class.
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
uintptr_t VALUE
Type that represents a Ruby 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.