10static int vm_redefinition_check_flag(
VALUE klass);
14#define object_id idObject_id
15#define added idMethod_added
16#define singleton_added idSingleton_method_added
17#define removed idMethod_removed
18#define singleton_removed idSingleton_method_removed
19#define undefined idMethod_undefined
20#define singleton_undefined idSingleton_method_undefined
22#define ruby_running (GET_VM()->running)
25static enum rb_id_table_iterator_result
26mark_cc_entry_i(
VALUE ccs_ptr,
void *data)
30 VM_ASSERT(vm_ccs_p(ccs));
32 if (METHOD_ENTRY_INVALIDATED(ccs->cme)) {
36 for (
int i = 0; i < ccs->len; i++) {
38 if (cc->klass ==
Qundef)
continue;
39 VM_ASSERT(cc->klass ==
Qundef || vm_cc_check_cme(cc, ccs->cme));
40 VM_ASSERT(!vm_cc_super_p(cc) && !vm_cc_refinement_p(cc));
43 ruby_xfree_sized(ccs, vm_ccs_alloc_size(ccs->capa));
44 return ID_TABLE_DELETE;
47 rb_gc_mark_movable((
VALUE)ccs->cme);
49 for (
int i = 0; i < ccs->len; i++) {
51 VM_ASSERT(cc->klass ==
Qundef || vm_cc_check_cme(cc, ccs->cme));
53 rb_gc_mark_movable((
VALUE)cc);
55 return ID_TABLE_CONTINUE;
60vm_cc_table_mark(
void *data)
64 rb_id_table_foreach_values(tbl, mark_cc_entry_i, NULL);
68static enum rb_id_table_iterator_result
69cc_table_free_i(
VALUE ccs_ptr,
void *data)
72 VM_ASSERT(vm_ccs_p(ccs));
74 ruby_xfree_sized(ccs, vm_ccs_alloc_size(ccs->capa));
76 return ID_TABLE_CONTINUE;
80vm_cc_table_free(
void *data)
84 rb_id_table_foreach_values(tbl, cc_table_free_i, NULL);
88static enum rb_id_table_iterator_result
89cc_table_memsize_i(
VALUE ccs_ptr,
void *data_ptr)
91 size_t *total_size = data_ptr;
93 *total_size +=
sizeof(*ccs);
94 *total_size +=
sizeof(ccs->entries[0]) * ccs->capa;
95 return ID_TABLE_CONTINUE;
99vm_cc_table_memsize(
const void *data)
101 size_t memsize = rb_managed_id_table_type.
function.
dsize(data);
103 rb_id_table_foreach_values(tbl, cc_table_memsize_i, &memsize);
107static enum rb_id_table_iterator_result
108compact_cc_entry_i(
VALUE ccs_ptr,
void *data)
113 VM_ASSERT(vm_ccs_p(ccs));
115 for (
int i=0; i<ccs->len; i++) {
116 ccs->entries[i].cc = (
const struct rb_callcache *)rb_gc_location((
VALUE)ccs->entries[i].cc);
119 return ID_TABLE_CONTINUE;
123vm_cc_table_compact(
void *data)
126 rb_id_table_foreach_values(tbl, compact_cc_entry_i, NULL);
132 .dmark = vm_cc_table_mark,
133 .dfree = vm_cc_table_free,
134 .dsize = vm_cc_table_memsize,
135 .dcompact = vm_cc_table_compact,
137 .parent = &rb_managed_id_table_type,
142rb_vm_cc_table_create(
size_t capa)
144 return rb_managed_id_table_create(&cc_table_type,
capa);
147static enum rb_id_table_iterator_result
148vm_cc_table_dup_i(
ID key,
VALUE old_ccs_ptr,
void *data)
153 if (METHOD_ENTRY_INVALIDATED(old_ccs->cme)) {
156 return ID_TABLE_CONTINUE;
159 size_t memsize = vm_ccs_alloc_size(old_ccs->capa);
161 rb_managed_id_table_insert(new_table, key, (
VALUE)new_ccs);
165 VM_ASSERT(!METHOD_ENTRY_INVALIDATED(old_ccs->cme));
167 memcpy(new_ccs, old_ccs, memsize);
170 new_ccs->debug_sig = ~(
VALUE)new_ccs;
174 for (
int index = 0; index < new_ccs->len; index++) {
177 return ID_TABLE_CONTINUE;
181rb_vm_cc_table_dup(
VALUE old_table)
184 VALUE new_table = rb_vm_cc_table_create(rb_managed_id_table_size(old_table));
185 rb_managed_id_table_foreach(old_table, vm_cc_table_dup_i, (
void *)new_table);
192 for (
int i=0; i<ccs->len; i++) {
194 VM_ASSERT(!vm_cc_super_p(cc) && !vm_cc_refinement_p(cc));
195 vm_cc_invalidate(cc);
202 RB_DEBUG_COUNTER_INC(ccs_free);
203 vm_ccs_invalidate(ccs);
204 ruby_xfree_sized(ccs, vm_ccs_alloc_size(ccs->capa));
208rb_vm_cc_table_delete(
VALUE table,
ID mid)
211 if (rb_managed_id_table_lookup(table, mid, &ccs_obj)) {
213 rb_managed_id_table_delete(table, mid);
214 rb_vm_ccs_invalidate_and_free(ccs);
218static enum rb_id_table_iterator_result
219vm_ccs_dump_i(
ID mid,
VALUE val,
void *data)
222 fprintf(stderr,
" | %s (len:%d) ", rb_id2name(mid), ccs->len);
225 for (
int i=0; i<ccs->len; i++) {
226 rp_m(
" | \t", ccs->entries[i].cc);
229 return ID_TABLE_CONTINUE;
233vm_ccs_dump(
VALUE klass,
ID target_mid)
235 VALUE cc_tbl = RCLASS_WRITABLE_CC_TBL(klass);
239 if (rb_managed_id_table_lookup(cc_tbl, target_mid, &ccs)) {
240 fprintf(stderr,
" [CCTB] %p\n", (
void *)cc_tbl);
241 vm_ccs_dump_i(target_mid, ccs, NULL);
245 fprintf(stderr,
" [CCTB] %p\n", (
void *)cc_tbl);
246 rb_managed_id_table_foreach(cc_tbl, vm_ccs_dump_i, (
void *)target_mid);
251static enum rb_id_table_iterator_result
252vm_cme_dump_i(
ID mid,
VALUE val,
void *data)
254 ID target_mid = (
ID)data;
255 if (target_mid == 0 || mid == target_mid) {
258 return ID_TABLE_CONTINUE;
262vm_mtbl_dump(
VALUE klass,
ID target_mid)
264 fprintf(stderr,
"# vm_mtbl\n");
269 if (RCLASS_M_TBL(klass)) {
270 if (target_mid != 0) {
271 if (rb_id_table_lookup(RCLASS_M_TBL(klass), target_mid, &me)) {
272 rp_m(
" [MTBL] ", me);
276 fprintf(stderr,
" ## RCLASS_M_TBL (%p)\n", (
void *)RCLASS_M_TBL(klass));
277 rb_id_table_foreach(RCLASS_M_TBL(klass), vm_cme_dump_i, NULL);
281 fprintf(stderr,
" MTBL: NULL\n");
283 if (RCLASS_WRITABLE_CALLABLE_M_TBL(klass)) {
284 if (target_mid != 0) {
285 if (rb_id_table_lookup(RCLASS_WRITABLE_CALLABLE_M_TBL(klass), target_mid, &me)) {
286 rp_m(
" [CM**] ", me);
290 fprintf(stderr,
" ## RCLASS_CALLABLE_M_TBL\n");
291 rb_id_table_foreach(RCLASS_WRITABLE_CALLABLE_M_TBL(klass), vm_cme_dump_i, NULL);
294 if (RCLASS_WRITABLE_CC_TBL(klass)) {
295 vm_ccs_dump(klass, target_mid);
303rb_vm_mtbl_dump(
const char *msg,
VALUE klass,
ID target_mid)
305 fprintf(stderr,
"[%s] ", msg);
306 vm_mtbl_dump(klass, target_mid);
312 VM_ASSERT(IMEMO_TYPE_P(cme, imemo_ment),
"cme: %d", imemo_type((
VALUE)cme));
313 VM_ASSERT(callable_method_entry_p(cme));
314 METHOD_ENTRY_INVALIDATED_SET(cme);
315 RB_DEBUG_COUNTER_INC(cc_cme_invalidate);
317 rb_yjit_cme_invalidate(cme);
318 rb_zjit_cme_invalidate(cme);
322rb_clear_constant_cache_for_id_i(st_data_t ic, st_data_t arg)
324 ((
IC) ic)->entry = NULL;
334 if (rb_id_table_lookup(&vm->constant_cache,
id, &lookup_result)) {
336 set_table_foreach(ics, rb_clear_constant_cache_for_id_i, (st_data_t) NULL);
337 ruby_vm_constant_cache_invalidations += ics->num_entries;
340 rb_yjit_constant_state_changed(
id);
341 rb_zjit_constant_state_changed(
id);
345invalidate_negative_cache(
ID mid)
350 if (rb_id_table_lookup(&vm->negative_cme_table, mid, &cme)) {
351 rb_id_table_delete(&vm->negative_cme_table, mid);
353 RB_DEBUG_COUNTER_INC(cc_invalidate_negative);
362invalidate_method_cache_in_cc_table(
VALUE tbl,
ID mid)
365 if (tbl && rb_managed_id_table_lookup(tbl, mid, &ccs_data)) {
369 if (
NIL_P(ccs->cme->owner)) invalidate_negative_cache(mid);
370 rb_vm_ccs_invalidate_and_free(ccs);
371 rb_managed_id_table_delete(tbl, mid);
372 RB_DEBUG_COUNTER_INC(cc_invalidate_leaf_ccs);
377invalidate_callable_method_entry_in_callable_m_table(
struct rb_id_table *tbl,
ID mid)
380 if (tbl && rb_id_table_lookup(tbl, mid, &cme)) {
383 rb_id_table_delete(tbl, mid);
384 RB_DEBUG_COUNTER_INC(cc_invalidate_leaf_callable);
396invalidate_callable_method_entry_in_every_m_table_i(
rb_classext_t *ext,
bool is_prime,
VALUE box_value,
void *data)
402 if (rb_id_table_lookup(tbl, arg->mid, &me) && arg->cme == (
const rb_method_entry_t *)me) {
403 rb_method_table_insert(arg->klass, tbl, arg->mid, arg->newer);
418 rb_class_classext_foreach(klass, invalidate_callable_method_entry_in_every_m_table_i, (
void *)&arg);
422invalidate_complemented_method_entry_in_callable_m_table(
struct rb_id_table *tbl,
ID mid)
425 if (tbl && rb_id_table_lookup(tbl, mid, &cme)) {
428 rb_id_table_delete(tbl, mid);
429 RB_DEBUG_COUNTER_INC(cc_invalidate_tree_callable);
434clear_method_cache_by_id_in_class(
VALUE klass,
ID mid)
437 if (rb_objspace_garbage_object_p(klass))
return;
442 if (LIKELY(RCLASS_SUBCLASSES_FIRST(klass) == NULL) &&
452 VALUE cc_tbl = RCLASS_WRITABLE_CC_TBL(klass);
453 invalidate_method_cache_in_cc_table(cc_tbl, mid);
454 if (RCLASS_CC_TBL_NOT_PRIME_P(klass, cc_tbl)) {
455 invalidate_method_cache_in_cc_table(RCLASS_PRIME_CC_TBL(klass), mid);
459 struct rb_id_table *cm_tbl = RCLASS_WRITABLE_CALLABLE_M_TBL(klass);
460 invalidate_callable_method_entry_in_callable_m_table(cm_tbl, mid);
461 if (RCLASS_CALLABLE_M_TBL_NOT_PRIME_P(klass, cm_tbl)) {
462 invalidate_callable_method_entry_in_callable_m_table(RCLASS_PRIME_CALLABLE_M_TBL(klass), mid);
465 RB_DEBUG_COUNTER_INC(cc_invalidate_leaf);
472 if (METHOD_ENTRY_CACHED(cme)) {
473 if (METHOD_ENTRY_COMPLEMENTED(cme)) {
478 VALUE owner = cme->owner;
479 VM_ASSERT_TYPE(owner,
T_CLASS);
480 VALUE klass_housing_cme;
481 if (cme->def->type == VM_METHOD_TYPE_REFINED && !cme->def->body.refined.orig_me) {
482 klass_housing_cme = owner;
485 klass_housing_cme = RCLASS_ORIGIN(owner);
489 invalidate_callable_method_entry_in_every_m_table(klass_housing_cme, mid, cme);
493 RB_DEBUG_COUNTER_INC(cc_invalidate_tree_cme);
498 if (cme->def->type == VM_METHOD_TYPE_REFINED && cme->def->body.refined.orig_me) {
502 if (cme->def->iseq_overload) {
505 vm_cme_invalidate(monly_cme);
511 if (METHOD_ENTRY_COMPLEMENTED(cme)) {
512 VALUE defined_class = cme->defined_class;
513 struct rb_id_table *cm_tbl = RCLASS_WRITABLE_CALLABLE_M_TBL(defined_class);
514 invalidate_complemented_method_entry_in_callable_m_table(cm_tbl, mid);
515 if (RCLASS_CALLABLE_M_TBL_NOT_PRIME_P(defined_class, cm_tbl)) {
516 struct rb_id_table *prime_cm_table = RCLASS_PRIME_CALLABLE_M_TBL(defined_class);
517 invalidate_complemented_method_entry_in_callable_m_table(prime_cm_table, mid);
521 RB_DEBUG_COUNTER_INC(cc_invalidate_tree);
524 invalidate_negative_cache(mid);
528 rb_gccct_clear_table();
533clear_iclass_method_cache_by_id(
VALUE iclass,
VALUE d)
537 clear_method_cache_by_id_in_class(iclass, mid);
541clear_iclass_method_cache_by_id_for_refinements(
VALUE klass,
VALUE d)
545 clear_method_cache_by_id_in_class(klass, mid);
550rb_clear_method_cache(
VALUE klass_or_module,
ID mid)
553 VALUE module = klass_or_module;
555 if (
FL_TEST(module, RMODULE_IS_REFINEMENT)) {
556 VALUE refined_class = rb_refinement_module_get_refined_class(module);
557 rb_clear_method_cache(refined_class, mid);
558 rb_class_foreach_subclass(refined_class, clear_iclass_method_cache_by_id_for_refinements, mid);
559 rb_clear_all_refinement_method_cache();
561 rb_class_foreach_subclass(module, clear_iclass_method_cache_by_id, mid);
564 clear_method_cache_by_id_in_class(klass_or_module, mid);
568static enum rb_id_table_iterator_result
569invalidate_method_entry_in_iclass_callable_m_tbl(
VALUE cme,
void *data)
572 return ID_TABLE_DELETE;
575static enum rb_id_table_iterator_result
576invalidate_ccs_in_iclass_cc_tbl(
VALUE value,
void *data)
580 ruby_xfree_sized(ccs, vm_ccs_alloc_size(ccs->capa));
581 return ID_TABLE_DELETE;
588 rb_id_table_foreach_values(cm_tbl, invalidate_method_entry_in_iclass_callable_m_tbl, NULL);
591 rb_managed_id_table_foreach_values(cc_tbl, invalidate_ccs_in_iclass_cc_tbl, NULL);
604 for (
int i = 0; i < ci->kwarg->keyword_len; i++) {
616 if (ci1->mid != ci2->mid)
return 1;
617 if (ci1->flag != ci2->flag)
return 1;
618 if (ci1->argc != ci2->argc)
return 1;
619 if (ci1->kwarg != NULL) {
620 VM_ASSERT(ci2->kwarg != NULL);
622 if (ci1->kwarg->keyword_len != ci2->kwarg->keyword_len)
625 for (
int i = 0; i < ci1->kwarg->keyword_len; i++) {
626 if (ci1->kwarg->keywords[i] != ci2->kwarg->keywords[i]) {
632 VM_ASSERT(ci2->kwarg == NULL);
643ci_lookup_i(st_data_t *key, st_data_t *value, st_data_t data,
int existing)
646 st_data_t *ret = (st_data_t *)data;
649 if (rb_objspace_garbage_object_p((
VALUE)ci)) {
650 *ret = (st_data_t)NULL;
659 *key = *value = *ret = (st_data_t)ci;
665rb_vm_ci_lookup(
ID mid,
unsigned int flag,
unsigned int argc,
const struct rb_callinfo_kwarg *kwarg)
683 st_update(ci_table, (st_data_t)new_ci, ci_lookup_i, (st_data_t)&ci);
684 }
while (ci == NULL);
699 st_data_t key = (st_data_t)ci;
700 st_delete(&vm->ci_table, &key, NULL);
710cc_refinement_set_free(
void *ptr)
717cc_refinement_set_memsize(
const void *ptr)
720 return e->capa *
sizeof(
VALUE);
724cc_refinement_set_compact(
void *ptr)
727 for (
size_t i = 0; i < e->len; i++) {
728 e->entries[i] = rb_gc_location(e->entries[i]);
733cc_refinement_set_handle_weak_references(
void *ptr)
737 for (
size_t read = 0; read < e->len; read++) {
738 if (rb_gc_handle_weak_references_alive_p(e->entries[read])) {
739 e->entries[write++] = e->entries[read];
746 "VM/cc_refinement_set",
749 cc_refinement_set_free,
750 cc_refinement_set_memsize,
751 cc_refinement_set_compact,
752 cc_refinement_set_handle_weak_references,
758rb_cc_refinement_set_create(
void)
767 rb_gc_declare_weak_references(obj);
773rb_vm_insert_cc_refinement(
const struct rb_callcache *cc)
779 if (e->len == e->capa) {
780 size_t new_capa = e->capa == 0 ? 16 : e->capa * 2;
781 SIZED_REALLOC_N(e->entries,
VALUE, new_capa, e->capa);
784 e->entries[e->len++] = (
VALUE)cc;
794rb_clear_all_refinement_method_cache(
void)
801 for (
size_t i = 0; i < e->len; i++) {
802 VALUE v = e->entries[i];
806 VM_ASSERT(rb_gc_pointer_to_heap_p(v));
807 VM_ASSERT(!rb_objspace_garbage_object_p(v));
810 VM_ASSERT(vm_cc_refinement_p(cc));
812 if (vm_cc_valid(cc)) {
813 vm_cc_invalidate(cc);
820 rb_yjit_invalidate_all_method_lookup_assumptions();
827 rb_method_table_insert0(klass, table, method_id, me,
RB_TYPE_P(klass,
T_ICLASS) && !RICLASS_OWNS_M_TBL_P(klass));
834 VALUE table_owner = klass;
835 if (iclass_shared_mtbl) {
836 table_owner =
RBASIC(table_owner)->klass;
839 rb_id_table_insert(table, method_id, (
VALUE)me);
848NORETURN(
static VALUE rb_f_notimplement_internal(
int argc,
const VALUE *argv,
VALUE obj));
851rb_f_notimplement_internal(
int argc,
const VALUE *argv,
VALUE obj)
861 rb_f_notimplement_internal(argc, argv, obj);
865rb_define_notimplement_method_id(
VALUE mod,
ID id, rb_method_visibility_t visi)
867 rb_add_method(mod,
id, VM_METHOD_TYPE_NOTIMPLEMENTED, (
void *)1, visi);
871rb_add_method_cfunc(
VALUE klass,
ID mid,
VALUE (*func)(
ANYARGS),
int argc, rb_method_visibility_t visi)
873 if (argc < -2 || 15 < argc) rb_raise(rb_eArgError,
"arity out of range: %d for -2..15", argc);
878 rb_add_method(klass, mid, VM_METHOD_TYPE_CFUNC, &opt, visi);
881 rb_define_notimplement_method_id(klass, mid, visi);
886rb_add_method_optimized(
VALUE klass,
ID mid,
enum method_optimized_type opt_type,
unsigned int index, rb_method_visibility_t visi)
892 rb_add_method(klass, mid, VM_METHOD_TYPE_OPTIMIZED, &opt, visi);
903 if (reference_count_was == 1) {
904 if (METHOD_DEBUG) fprintf(stderr,
"-%p-%s:1->0 (remove)\n", (
void *)def,
905 rb_id2name(def->original_id));
909 if (METHOD_DEBUG) fprintf(stderr,
"-%p-%s:%d->%d (dec)\n", (
void *)def, rb_id2name(def->original_id),
910 reference_count_was, reference_count_was - 1);
918 method_definition_release(def);
926 if (me->def && me->def->iseq_overload) {
935 if (METHOD_ENTRY_CACHED(me)) {
945 method_definition_release(me->def);
954 if (!GET_THREAD()->ext_config.ractor_safe) {
956 case -2:
return &call_cfunc_m2;
957 case -1:
return &call_cfunc_m1;
958 case 0:
return &call_cfunc_0;
959 case 1:
return &call_cfunc_1;
960 case 2:
return &call_cfunc_2;
961 case 3:
return &call_cfunc_3;
962 case 4:
return &call_cfunc_4;
963 case 5:
return &call_cfunc_5;
964 case 6:
return &call_cfunc_6;
965 case 7:
return &call_cfunc_7;
966 case 8:
return &call_cfunc_8;
967 case 9:
return &call_cfunc_9;
968 case 10:
return &call_cfunc_10;
969 case 11:
return &call_cfunc_11;
970 case 12:
return &call_cfunc_12;
971 case 13:
return &call_cfunc_13;
972 case 14:
return &call_cfunc_14;
973 case 15:
return &call_cfunc_15;
975 rb_bug(
"unsupported length: %d", argc);
980 case -2:
return &ractor_safe_call_cfunc_m2;
981 case -1:
return &ractor_safe_call_cfunc_m1;
982 case 0:
return &ractor_safe_call_cfunc_0;
983 case 1:
return &ractor_safe_call_cfunc_1;
984 case 2:
return &ractor_safe_call_cfunc_2;
985 case 3:
return &ractor_safe_call_cfunc_3;
986 case 4:
return &ractor_safe_call_cfunc_4;
987 case 5:
return &ractor_safe_call_cfunc_5;
988 case 6:
return &ractor_safe_call_cfunc_6;
989 case 7:
return &ractor_safe_call_cfunc_7;
990 case 8:
return &ractor_safe_call_cfunc_8;
991 case 9:
return &ractor_safe_call_cfunc_9;
992 case 10:
return &ractor_safe_call_cfunc_10;
993 case 11:
return &ractor_safe_call_cfunc_11;
994 case 12:
return &ractor_safe_call_cfunc_12;
995 case 13:
return &ractor_safe_call_cfunc_13;
996 case 14:
return &ractor_safe_call_cfunc_14;
997 case 15:
return &ractor_safe_call_cfunc_15;
999 rb_bug(
"unsupported length: %d", argc);
1009 cfunc->invoker = call_cfunc_invoker_func(argc);
1017 if (!complemented && reference_count_was > 0) {
1019 def->aliased =
true;
1021 if (METHOD_DEBUG) fprintf(stderr,
"+%p-%s:%d->%d\n", (
void *)def, rb_id2name(def->original_id), reference_count_was, reference_count_was+1);
1029 method_definition_addref(def,
false);
1035 method_definition_release(me->def);
1038 if (!ruby_running) add_opt_method_entry(me);
1041 switch (def->type) {
1042 case VM_METHOD_TYPE_ISEQ:
1052 if (rb_iseq_attr_p(iseq, BUILTIN_ATTR_C_TRACE)) {
1056 if (ISEQ_BODY(iseq)->mandatory_only_iseq) def->iseq_overload = 1;
1058 if (0) vm_cref_dump(
"rb_method_definition_create", cref);
1064 method_cref = vm_cref_new_toplevel(GET_EC());
1070 case VM_METHOD_TYPE_CFUNC:
1073 setup_method_cfunc_struct(UNALIGNED_MEMBER_PTR(def, body.cfunc), cfunc->func, cfunc->argc);
1076 case VM_METHOD_TYPE_ATTRSET:
1077 case VM_METHOD_TYPE_IVAR:
1083 def->body.attr.id = (
ID)(
VALUE)opts;
1085 cfp = rb_vm_get_ruby_level_next_cfp(ec, ec->cfp);
1087 if (cfp && (line = rb_vm_get_sourceline(cfp))) {
1090 RB_OBJ_SET_SHAREABLE(location);
1094 VM_ASSERT(def->body.attr.location == 0);
1098 case VM_METHOD_TYPE_BMETHOD:
1100 def->body.bmethod.defined_ractor_id = rb_ec_ractor_id(GET_EC());
1102 case VM_METHOD_TYPE_NOTIMPLEMENTED:
1103 setup_method_cfunc_struct(UNALIGNED_MEMBER_PTR(def, body.cfunc), (
VALUE(*)(
ANYARGS))rb_f_notimplement_internal, -1);
1105 case VM_METHOD_TYPE_OPTIMIZED:
1108 case VM_METHOD_TYPE_REFINED:
1113 case VM_METHOD_TYPE_ALIAS:
1116 case VM_METHOD_TYPE_ZSUPER:
1117 case VM_METHOD_TYPE_UNDEF:
1118 case VM_METHOD_TYPE_MISSING:
1129 switch (def->type) {
1130 case VM_METHOD_TYPE_ISEQ:
1134 case VM_METHOD_TYPE_ATTRSET:
1135 case VM_METHOD_TYPE_IVAR:
1138 case VM_METHOD_TYPE_BMETHOD:
1141 case VM_METHOD_TYPE_REFINED:
1144 case VM_METHOD_TYPE_ALIAS:
1147 case VM_METHOD_TYPE_CFUNC:
1148 case VM_METHOD_TYPE_ZSUPER:
1149 case VM_METHOD_TYPE_MISSING:
1150 case VM_METHOD_TYPE_OPTIMIZED:
1151 case VM_METHOD_TYPE_UNDEF:
1152 case VM_METHOD_TYPE_NOTIMPLEMENTED:
1160rb_method_definition_create(rb_method_type_t
type,
ID mid)
1165 def->original_id = mid;
1167 def->box = rb_current_box();
1174 if (def) method_definition_addref(def, complement);
1175 if (
RTEST(defined_class)) {
1182 rb_gc_register_pinning_obj((
VALUE)me);
1185 me->called_id = called_id;
1192filter_defined_class(
VALUE klass)
1204 rb_bug(
"filter_defined_class: %s", rb_obj_info(klass));
1210 rb_method_entry_t *me = rb_method_entry_alloc(called_id, klass, filter_defined_class(klass), def,
false);
1211 METHOD_ENTRY_FLAGS_SET(me, visi, ruby_running ? FALSE : TRUE);
1212 if (def != NULL) method_definition_reset(me);
1220 rb_method_entry_t *me = rb_method_entry_alloc(src_me->called_id, src_me->owner, src_me->defined_class, src_me->def, METHOD_ENTRY_COMPLEMENTED(src_me));
1222 METHOD_ENTRY_FLAGS_COPY(me, src_me);
1226 src_me->def->type == VM_METHOD_TYPE_REFINED &&
1227 src_me->def->body.refined.orig_me) {
1229 VM_ASSERT(orig_me->def->type != VM_METHOD_TYPE_REFINED);
1232 orig_me->owner, orig_me->defined_class, orig_me->def, METHOD_ENTRY_COMPLEMENTED(orig_me));
1233 METHOD_ENTRY_FLAGS_COPY(orig_clone, orig_me);
1238 rb_method_definition_create(VM_METHOD_TYPE_REFINED, src_me->called_id);
1239 rb_method_definition_set(me, clone_def, orig_clone);
1251 if (!src_me->defined_class &&
1252 def->type == VM_METHOD_TYPE_REFINED &&
1253 def->body.refined.orig_me) {
1255 rb_method_entry_clone(def->body.refined.orig_me);
1257 refined_orig_me = orig_me;
1261 me = rb_method_entry_alloc(called_id, src_me->owner, defined_class, def,
true);
1262 METHOD_ENTRY_FLAGS_COPY(me, src_me);
1263 METHOD_ENTRY_COMPLEMENTED_SET(me);
1265 def = rb_method_definition_create(VM_METHOD_TYPE_REFINED, called_id);
1266 rb_method_definition_set(me, def, (
void *)refined_orig_me);
1269 VM_ASSERT_TYPE(me->owner,
T_MODULE);
1277 method_definition_release(dst->def);
1278 *(
rb_method_definition_t **)&dst->def = method_definition_addref(src->def, METHOD_ENTRY_COMPLEMENTED(src));
1279 method_definition_reset(dst);
1280 dst->called_id = src->called_id;
1283 METHOD_ENTRY_FLAGS_COPY(dst, src);
1289 if (me->def->type == VM_METHOD_TYPE_REFINED) {
1295 rb_vm_check_redefinition_opt_method(me, me->owner);
1298 rb_method_entry_alloc(me->called_id,
1303 METHOD_ENTRY_FLAGS_COPY(orig_me, me);
1305 def = rb_method_definition_create(VM_METHOD_TYPE_REFINED, me->called_id);
1306 rb_method_definition_set(me, def, orig_me);
1307 METHOD_ENTRY_VISI_SET(me, METHOD_VISI_PUBLIC);
1312lookup_method_table(
VALUE klass,
ID id)
1317 if (rb_id_table_lookup(m_tbl,
id, &body)) {
1326rb_add_refined_method_entry(
VALUE refined_class,
ID mid)
1331 make_method_entry_refined(refined_class, me);
1332 rb_clear_method_cache(refined_class, mid);
1335 rb_add_method(refined_class, mid, VM_METHOD_TYPE_REFINED, 0, METHOD_VISI_PUBLIC);
1340check_override_opt_method_i(
VALUE klass,
VALUE arg)
1345 VALUE includer = RCLASS_INCLUDER(klass);
1346 if (!UNDEF_P(includer) && includer) {
1347 check_override_opt_method_i(includer, arg);
1355 if (vm_redefinition_check_flag(klass)) {
1356 me = lookup_method_table(RCLASS_ORIGIN(klass), mid);
1358 newme = rb_method_entry(klass, mid);
1359 if (newme != me) rb_vm_check_redefinition_opt_method(me, me->owner);
1362 rb_class_foreach_subclass(klass, check_override_opt_method_i, (
VALUE)mid);
1366check_override_opt_method(
VALUE klass,
VALUE mid)
1368 if (rb_vm_check_optimizable_mid(mid)) {
1369 check_override_opt_method_i(klass, mid);
1381rb_method_entry_make(
VALUE klass,
ID mid,
VALUE defined_class, rb_method_visibility_t visi,
1387 int make_refined = 0;
1395 if (!RCLASS_SINGLETON_P(klass) &&
1396 type != VM_METHOD_TYPE_NOTIMPLEMENTED &&
1397 type != VM_METHOD_TYPE_ZSUPER) {
1400 case idInitialize_copy:
1401 case idInitialize_clone:
1402 case idInitialize_dup:
1403 case idRespond_to_missing:
1404 visi = METHOD_VISI_PRIVATE;
1408 if (
type != VM_METHOD_TYPE_REFINED) {
1413 VALUE refined_class = rb_refinement_module_get_refined_class(klass);
1414 bool search_superclass =
type == VM_METHOD_TYPE_ZSUPER && !lookup_method_table(refined_class, mid);
1415 rb_add_refined_method_entry(refined_class, mid);
1416 if (search_superclass) {
1418 me->def->body.refined.orig_me = search_method0(refined_class, mid, NULL,
true);
1421 if (
type == VM_METHOD_TYPE_REFINED) {
1423 if (old_me) rb_vm_check_redefinition_opt_method(old_me, klass);
1426 klass = RCLASS_ORIGIN(klass);
1427 if (klass != orig_klass) {
1428 rb_clear_method_cache(orig_klass, mid);
1431 mtbl = RCLASS_WRITABLE_M_TBL(klass);
1434 if (rb_id_table_lookup(mtbl, mid, &data)) {
1438 if (rb_method_definition_eq(old_def, def))
return old_me;
1439 rb_vm_check_redefinition_opt_method(old_me, klass);
1441 if (old_def->type == VM_METHOD_TYPE_REFINED) make_refined = 1;
1444 type != VM_METHOD_TYPE_UNDEF &&
1445 (old_def->aliased ==
false) &&
1446 (!old_def->no_redef_warning) &&
1448 old_def->type != VM_METHOD_TYPE_UNDEF &&
1449 old_def->type != VM_METHOD_TYPE_ZSUPER &&
1450 old_def->type != VM_METHOD_TYPE_ALIAS) {
1453 switch (old_def->type) {
1454 case VM_METHOD_TYPE_ISEQ:
1455 iseq = def_iseq_ptr(old_def);
1457 case VM_METHOD_TYPE_BMETHOD:
1458 iseq = rb_proc_get_iseq(old_def->body.bmethod.proc, 0);
1465 "method redefined; discarding old %"PRIsVALUE
"\n%s:%d: warning: previous definition of %"PRIsVALUE
" was here",
1467 RSTRING_PTR(rb_iseq_path(iseq)),
1468 ISEQ_BODY(iseq)->location.first_lineno,
1469 rb_id2str(old_def->original_id)
1473 rb_warning(
"method redefined; discarding old %"PRIsVALUE, rb_id2str(mid));
1479 me = rb_method_entry_create(mid, defined_class, visi, NULL);
1481 def = rb_method_definition_create(
type, original_id);
1483 rb_method_definition_set(me, def, opts);
1485 rb_clear_method_cache(klass, mid);
1491 case idRespond_to_missing:
1492 case idMethodMissing:
1494 rb_warn(
"redefining Object#%s may cause infinite loop", rb_id2name(mid));
1498 if (mid == object_id || mid == id__id__ || mid == id__send__) {
1499 if (
type != VM_METHOD_TYPE_CFUNC && search_method(klass, mid, 0)) {
1500 rb_warn(
"redefining '%s' may cause serious problems", rb_id2name(mid));
1505 make_method_entry_refined(klass, me);
1508 rb_method_table_insert(klass, mtbl, mid, me);
1510 VM_ASSERT(me->def != NULL);
1514 check_override_opt_method(klass, (
VALUE)mid);
1521overloaded_cme_table(
void)
1523 return &GET_VM()->overloaded_cme_table;
1526#if VM_CHECK_MODE > 0
1528vm_dump_overloaded_cme_table(st_data_t key, st_data_t val, st_data_t dmy)
1530 fprintf(stderr,
"key: "); rp(key);
1531 fprintf(stderr,
"val: "); rp(val);
1536rb_vm_dump_overloaded_cme_table(
void)
1538 fprintf(stderr,
"== rb_vm_dump_overloaded_cme_table\n");
1539 st_foreach(overloaded_cme_table(), vm_dump_overloaded_cme_table, 0);
1544lookup_overloaded_cme_i(st_data_t *key, st_data_t *value, st_data_t data,
int existing)
1551 if (rb_objspace_garbage_object_p((
VALUE)cme) ||
1552 rb_objspace_garbage_object_p((
VALUE)monly_cme)) {
1567 ASSERT_vm_locking();
1570 st_update(overloaded_cme_table(), (st_data_t)cme, lookup_overloaded_cme_i, (st_data_t)&monly_cme);
1574#if VM_CHECK_MODE > 0
1578 return lookup_overloaded_cme(cme);
1585 st_data_t cme_data = (st_data_t)cme;
1586 ASSERT_vm_locking();
1587 st_delete(overloaded_cme_table(), &cme_data, NULL);
1595 if (monly_cme && !METHOD_ENTRY_INVALIDATED(monly_cme)) {
1610 ASSERT_vm_locking();
1611 st_insert(overloaded_cme_table(), (st_data_t)cme, (st_data_t)me);
1613 METHOD_ENTRY_VISI_SET(me, METHOD_ENTRY_VISI(cme));
1621 if (UNLIKELY(cme->def->iseq_overload) &&
1622 (vm_ci_flag(ci) & (VM_CALL_ARGS_SIMPLE)) &&
1623 (!(vm_ci_flag(ci) & VM_CALL_FORWARDING)) &&
1624 (
int)vm_ci_argc(ci) == ISEQ_BODY(method_entry_iseqptr(cme))->param.lead_num) {
1625 VM_ASSERT(cme->def->type == VM_METHOD_TYPE_ISEQ,
"type: %d", cme->def->type);
1627 cme = get_overloaded_cme(cme);
1629 VM_ASSERT(cme != NULL);
1636#define CALL_METHOD_HOOK(klass, hook, mid) do { \
1637 const VALUE arg = ID2SYM(mid); \
1638 VALUE recv_class = (klass); \
1639 ID hook_id = (hook); \
1640 if (RCLASS_SINGLETON_P((klass))) { \
1641 recv_class = RCLASS_ATTACHED_OBJECT((klass)); \
1642 hook_id = singleton_##hook; \
1644 rb_funcallv(recv_class, hook_id, 1, &arg); \
1648method_added(
VALUE klass,
ID mid)
1651 CALL_METHOD_HOOK(klass, added, mid);
1656rb_add_method(
VALUE klass,
ID mid, rb_method_type_t
type,
void *opts, rb_method_visibility_t visi)
1659 rb_method_entry_make(klass, mid, klass, visi,
type, NULL, mid, opts);
1662 if (
type != VM_METHOD_TYPE_UNDEF &&
type != VM_METHOD_TYPE_REFINED) {
1663 method_added(klass, mid);
1676 iseq_body.
cref = cref;
1678 rb_add_method(klass, mid, VM_METHOD_TYPE_ISEQ, &iseq_body, visi);
1683 rb_method_visibility_t visi,
VALUE defined_class)
1687 newme = rb_method_entry_make(klass, mid, defined_class, visi,
1688 me->def->type, me->def, 0, NULL);
1690 me->def->no_redef_warning = TRUE;
1691 METHOD_ENTRY_FLAGS_SET(newme, visi, FALSE);
1695 method_added(klass, mid);
1702 return method_entry_set(klass, mid, me, visi, klass);
1705#define UNDEF_ALLOC_FUNC ((rb_alloc_func_t)-1)
1708propagate_alloc_func(
VALUE subclass,
VALUE arg)
1711 !RCLASS_SINGLETON_P(subclass) &&
1712 !
FL_TEST_RAW(subclass, RCLASS_ALLOCATOR_DEFINED)) {
1714 rb_class_foreach_subclass(subclass, propagate_alloc_func, arg);
1722 if (RCLASS_SINGLETON_P(klass)) {
1723 rb_raise(
rb_eTypeError,
"can't define an allocator for a singleton class");
1725 RCLASS_SET_ALLOCATOR(klass, func);
1727 rb_class_foreach_subclass(klass, propagate_alloc_func, (
VALUE)func);
1734 RCLASS_SET_ALLOCATOR(klass, UNDEF_ALLOC_FUNC);
1736 rb_class_foreach_subclass(klass, propagate_alloc_func, (
VALUE)UNDEF_ALLOC_FUNC);
1742 RBIMPL_ASSERT_TYPE(klass,
T_CLASS);
1745 if (allocator == UNDEF_ALLOC_FUNC)
return 0;
1751rb_method_entry_at(
VALUE klass,
ID id)
1753 return lookup_method_table(klass,
id);
1757search_method0(
VALUE klass,
ID id,
VALUE *defined_class_ptr,
bool skip_refined)
1761 RB_DEBUG_COUNTER_INC(mc_search);
1764 RB_DEBUG_COUNTER_INC(mc_search_super);
1765 if ((me = lookup_method_table(klass,
id)) != 0) {
1766 if (!skip_refined || me->def->type != VM_METHOD_TYPE_REFINED ||
1767 me->def->body.refined.orig_me) {
1773 if (defined_class_ptr) *defined_class_ptr = klass;
1775 if (me == NULL) RB_DEBUG_COUNTER_INC(mc_search_notfound);
1777 VM_ASSERT(me == NULL || !METHOD_ENTRY_INVALIDATED(me),
1778 "invalid me, mid:%s, klass:%s(%s)",
1781 rb_obj_info(klass));
1786search_method(
VALUE klass,
ID id,
VALUE *defined_class_ptr)
1788 return search_method0(klass,
id, defined_class_ptr,
false);
1792search_method_protect(
VALUE klass,
ID id,
VALUE *defined_class_ptr)
1796 if (!UNDEFINED_METHOD_ENTRY_P(me)) {
1805rb_method_entry(
VALUE klass,
ID id)
1807 return search_method_protect(klass,
id, NULL);
1819 if (me->defined_class == 0) {
1820 RB_DEBUG_COUNTER_INC(mc_cme_complement);
1823 mtbl = RCLASS_WRITABLE_CALLABLE_M_TBL(defined_class);
1824 if (mtbl && rb_id_table_lookup(mtbl,
id, &cme_data)) {
1829 RB_DEBUG_COUNTER_INC(mc_cme_complement_hit);
1830 VM_ASSERT(callable_method_entry_p(cme));
1831 VM_ASSERT(!METHOD_ENTRY_INVALIDATED(cme));
1835 mtbl = rb_id_table_create(0);
1836 RCLASS_WRITE_CALLABLE_M_TBL(defined_class, mtbl);
1838 cme = rb_method_entry_complement_defined_class(me, me->called_id, defined_class);
1839 rb_id_table_insert(mtbl,
id, (
VALUE)cme);
1841 VM_ASSERT(callable_method_entry_p(cme));
1849 VM_ASSERT(callable_method_entry_p(cme));
1850 VM_ASSERT(!METHOD_ENTRY_INVALIDATED(cme));
1860complemented_callable_method_entry(
VALUE klass,
ID id)
1862 VALUE defined_class;
1864 return prepare_callable_method_entry(defined_class,
id, me, FALSE);
1868cached_callable_method_entry(
VALUE klass,
ID mid)
1870 ASSERT_vm_locking();
1872 VALUE cc_tbl = RCLASS_WRITABLE_CC_TBL(klass);
1875 if (cc_tbl && rb_managed_id_table_lookup(cc_tbl, mid, &ccs_data)) {
1877 VM_ASSERT(vm_ccs_p(ccs));
1879 if (LIKELY(!METHOD_ENTRY_INVALIDATED(ccs->cme))) {
1880 VM_ASSERT(ccs->cme->called_id == mid);
1881 RB_DEBUG_COUNTER_INC(ccs_found);
1887 rb_managed_id_table_delete(cc_tbl, mid);
1888 rb_vm_ccs_invalidate_and_free(ccs);
1892 RB_DEBUG_COUNTER_INC(ccs_not_found);
1899 ASSERT_vm_locking();
1900 VM_ASSERT(cme != NULL);
1902 VALUE cc_tbl = RCLASS_WRITABLE_CC_TBL(klass);
1906 cc_tbl = rb_vm_cc_table_create(2);
1907 RCLASS_WRITE_CC_TBL(klass, cc_tbl);
1910 if (rb_managed_id_table_lookup(cc_tbl, mid, &ccs_data)) {
1911#if VM_CHECK_MODE > 0
1913 VM_ASSERT(ccs->cme == cme);
1917 if (rb_multi_ractor_p()) {
1918 VALUE new_cc_tbl = rb_vm_cc_table_dup(cc_tbl);
1919 vm_ccs_create(klass, new_cc_tbl, mid, cme);
1920 RB_OBJ_ATOMIC_WRITE(klass, &RCLASSEXT_CC_TBL(RCLASS_EXT_WRITABLE(klass)), new_cc_tbl);
1923 vm_ccs_create(klass, cc_tbl, mid, cme);
1935 if (rb_id_table_lookup(&vm->negative_cme_table, mid, &cme_data)) {
1940 rb_id_table_insert(&vm->negative_cme_table, mid, (
VALUE)cme);
1943 VM_ASSERT(cme != NULL);
1948callable_method_entry_or_negative(
VALUE klass,
ID mid,
VALUE *defined_class_ptr)
1955 VALUE cc_tbl = RUBY_ATOMIC_VALUE_LOAD(RCLASS_WRITABLE_CC_TBL(klass));
1958 if (rb_managed_id_table_lookup(cc_tbl, mid, &ccs_data)) {
1960 VM_ASSERT(vm_ccs_p(ccs));
1962 if (LIKELY(!METHOD_ENTRY_INVALIDATED(ccs->cme))) {
1963 VM_ASSERT(ccs->cme->called_id == mid);
1964 if (defined_class_ptr != NULL) *defined_class_ptr = ccs->cme->defined_class;
1965 RB_DEBUG_COUNTER_INC(ccs_found);
1973 cme = cached_callable_method_entry(klass, mid);
1976 if (defined_class_ptr != NULL) *defined_class_ptr = cme->defined_class;
1979 VALUE defined_class;
1981 if (defined_class_ptr) *defined_class_ptr = defined_class;
1984 cme = prepare_callable_method_entry(defined_class, mid, me, TRUE);
1987 cme = negative_cme(mid);
1990 cache_callable_method_entry(klass, mid, cme);
2000rb_callable_method_entry_or_negative(
VALUE klass,
ID mid)
2002 return callable_method_entry_or_negative(klass, mid, NULL);
2006callable_method_entry(
VALUE klass,
ID mid,
VALUE *defined_class_ptr)
2009 cme = callable_method_entry_or_negative(klass, mid, defined_class_ptr);
2010 return !UNDEFINED_METHOD_ENTRY_P(cme) ? cme : NULL;
2014rb_callable_method_entry(
VALUE klass,
ID mid)
2016 return callable_method_entry(klass, mid, NULL);
2022method_entry_resolve_refinement(
VALUE klass,
ID id,
int with_refinement,
VALUE *defined_class_ptr)
2024 const rb_method_entry_t *me = search_method_protect(klass,
id, defined_class_ptr);
2027 if (me->def->type == VM_METHOD_TYPE_REFINED) {
2028 if (with_refinement) {
2030 VALUE refinements = cref ? CREF_REFINEMENTS(cref) :
Qnil;
2031 me = resolve_refined_method(refinements, me, defined_class_ptr);
2034 me = resolve_refined_method(
Qnil, me, defined_class_ptr);
2037 if (UNDEFINED_METHOD_ENTRY_P(me)) me = NULL;
2045rb_method_entry_with_refinements(
VALUE klass,
ID id,
VALUE *defined_class_ptr)
2047 return method_entry_resolve_refinement(klass,
id, TRUE, defined_class_ptr);
2051callable_method_entry_refinements0(
VALUE klass,
ID id,
VALUE *defined_class_ptr,
bool with_refinements,
2054 if (cme == NULL || LIKELY(cme->def->type != VM_METHOD_TYPE_REFINED)) {
2058 VALUE defined_class, *dcp = defined_class_ptr ? defined_class_ptr : &defined_class;
2059 const rb_method_entry_t *me = method_entry_resolve_refinement(klass,
id, with_refinements, dcp);
2060 return prepare_callable_method_entry(*dcp,
id, me, TRUE);
2065callable_method_entry_refinements(
VALUE klass,
ID id,
VALUE *defined_class_ptr,
bool with_refinements)
2068 return callable_method_entry_refinements0(klass,
id, defined_class_ptr, with_refinements, cme);
2072rb_callable_method_entry_with_refinements(
VALUE klass,
ID id,
VALUE *defined_class_ptr)
2074 return callable_method_entry_refinements(klass,
id, defined_class_ptr,
true);
2078callable_method_entry_without_refinements(
VALUE klass,
ID id,
VALUE *defined_class_ptr)
2080 return callable_method_entry_refinements(klass,
id, defined_class_ptr,
false);
2084rb_method_entry_without_refinements(
VALUE klass,
ID id,
VALUE *defined_class_ptr)
2086 return method_entry_resolve_refinement(klass,
id, FALSE, defined_class_ptr);
2090rb_callable_method_entry_without_refinements(
VALUE klass,
ID id,
VALUE *defined_class_ptr)
2092 VALUE defined_class, *dcp = defined_class_ptr ? defined_class_ptr : &defined_class;
2093 const rb_method_entry_t *me = method_entry_resolve_refinement(klass,
id, FALSE, dcp);
2094 return prepare_callable_method_entry(*dcp,
id, me, TRUE);
2100 while (me && me->def->type == VM_METHOD_TYPE_REFINED) {
2105 refinement = find_refinement(refinements, me->owner);
2106 if (!
NIL_P(refinement)) {
2107 tmp_me = search_method_protect(refinement, me->called_id, defined_class_ptr);
2109 if (tmp_me && tmp_me->def->type != VM_METHOD_TYPE_REFINED) {
2114 tmp_me = me->def->body.refined.orig_me;
2116 if (!tmp_me->defined_class) {
2117 VM_ASSERT_TYPE(tmp_me->owner,
T_MODULE);
2119 else if (defined_class_ptr) {
2120 *defined_class_ptr = tmp_me->defined_class;
2130 me = search_method_protect(super, me->called_id, defined_class_ptr);
2138 return resolve_refined_method(refinements, me, NULL);
2144 VALUE defined_class = me->defined_class;
2147 if (resolved_me && resolved_me->defined_class == 0) {
2148 return rb_method_entry_complement_defined_class(resolved_me, me->called_id, defined_class);
2156remove_method(
VALUE klass,
ID mid)
2163 klass = RCLASS_ORIGIN(klass);
2164 if (mid == object_id || mid == id__id__ || mid == id__send__ || mid == idInitialize) {
2165 rb_warn(
"removing '%s' may cause serious problems", rb_id2name(mid));
2168 if (!rb_id_table_lookup(RCLASS_M_TBL(klass), mid, &data) ||
2170 (!me->def || me->def->type == VM_METHOD_TYPE_UNDEF) ||
2171 UNDEFINED_REFINED_METHOD_P(me->def)) {
2172 rb_name_err_raise(
"method '%1$s' not defined in %2$s",
2176 if (klass != self) {
2177 rb_clear_method_cache(self, mid);
2179 rb_clear_method_cache(klass, mid);
2180 rb_id_table_delete(RCLASS_WRITABLE_M_TBL(klass), mid);
2182 rb_vm_check_redefinition_opt_method(me, klass);
2184 if (me->def->type == VM_METHOD_TYPE_REFINED) {
2185 rb_add_refined_method_entry(klass, mid);
2188 CALL_METHOD_HOOK(self, removed, mid);
2194 remove_method(klass, mid);
2200 remove_method(klass, rb_intern(name));
2214rb_mod_remove_method(
int argc,
VALUE *argv,
VALUE mod)
2218 for (i = 0; i < argc; i++) {
2222 rb_name_err_raise(
"method '%1$s' not defined in %2$s",
2225 remove_method(mod,
id);
2231rb_export_method(
VALUE klass,
ID name, rb_method_visibility_t visi)
2234 VALUE defined_class;
2235 VALUE origin_class = RCLASS_ORIGIN(klass);
2237 me = search_method0(origin_class, name, &defined_class,
true);
2240 me = search_method(
rb_cObject, name, &defined_class);
2243 if (UNDEFINED_METHOD_ENTRY_P(me) ||
2244 UNDEFINED_REFINED_METHOD_P(me->def)) {
2245 rb_print_undef(klass, name, METHOD_VISI_UNDEF);
2248 if (METHOD_ENTRY_VISI(me) != visi) {
2249 rb_vm_check_redefinition_opt_method(me, klass);
2251 if (klass == defined_class || origin_class == defined_class) {
2252 if (me->def->type == VM_METHOD_TYPE_REFINED) {
2255 if (me->def->body.refined.orig_me) {
2256 METHOD_ENTRY_VISI_SET((
rb_method_entry_t *)me->def->body.refined.orig_me, visi);
2260 METHOD_ENTRY_VISI_SET(me, visi);
2262 rb_clear_method_cache(klass, name);
2265 rb_add_method(klass, name, VM_METHOD_TYPE_ZSUPER, 0, visi);
2270#define BOUND_PRIVATE 0x01
2271#define BOUND_RESPONDS 0x02
2274method_boundp(
VALUE klass,
ID id,
int ex)
2280 if (ex & BOUND_RESPONDS) {
2281 cme = rb_callable_method_entry_with_refinements(klass,
id, NULL);
2284 cme = callable_method_entry_without_refinements(klass,
id, NULL);
2288 if (ex & ~BOUND_RESPONDS) {
2289 switch (METHOD_ENTRY_VISI(cme)) {
2290 case METHOD_VISI_PRIVATE:
2292 case METHOD_VISI_PROTECTED:
2293 if (ex & BOUND_RESPONDS)
return 0;
2299 if (cme->def->type == VM_METHOD_TYPE_NOTIMPLEMENTED) {
2300 if (ex & BOUND_RESPONDS)
return 2;
2312 return method_boundp(klass,
id, ex);
2316vm_cref_set_visibility(rb_method_visibility_t method_visi,
int module_func)
2319 scope_visi->method_visi = method_visi;
2320 scope_visi->module_func = module_func;
2324rb_scope_visibility_set(rb_method_visibility_t visi)
2326 vm_cref_set_visibility(visi, FALSE);
2330scope_visibility_check(
void)
2334 if (cfp && CFP_ISEQ(cfp) && ISEQ_BODY(CFP_ISEQ(cfp))->
type == ISEQ_TYPE_METHOD) {
2335 rb_warn(
"calling %s without arguments inside a method may not have the intended effect",
2336 rb_id2name(rb_frame_this_func()));
2341rb_scope_module_func_set(
void)
2343 scope_visibility_check();
2344 vm_cref_set_visibility(METHOD_VISI_PRIVATE, TRUE);
2352 rb_method_visibility_t visi;
2354 const rb_cref_t *cref = rb_vm_cref_in_context(klass, klass);
2357 visi = METHOD_VISI_PUBLIC;
2360 switch (vm_scope_visibility_get(ec)) {
2361 case METHOD_VISI_PRIVATE:
2362 if (vm_scope_module_func_check(ec)) {
2363 rb_warning(
"attribute accessor as module_function");
2365 visi = METHOD_VISI_PRIVATE;
2367 case METHOD_VISI_PROTECTED:
2368 visi = METHOD_VISI_PROTECTED;
2371 visi = METHOD_VISI_PUBLIC;
2376 attriv = rb_intern_str(rb_sprintf(
"@%"PRIsVALUE, rb_id2str(
id)));
2378 rb_add_method(klass,
id, VM_METHOD_TYPE_IVAR, (
void *)attriv, visi);
2381 rb_add_method(klass, rb_id_attrset(
id), VM_METHOD_TYPE_ATTRSET, (
void *)attriv, visi);
2394 if (
id == object_id ||
id == id__id__ ||
id == id__send__ ||
id == idInitialize) {
2395 rb_warn(
"undefining '%s' may cause serious problems", rb_id2name(
id));
2398 me = search_method(klass,
id, 0);
2399 if (me && me->def->type == VM_METHOD_TYPE_REFINED) {
2400 me = rb_resolve_refined_method(
Qnil, me);
2403 if (UNDEFINED_METHOD_ENTRY_P(me) ||
2404 UNDEFINED_REFINED_METHOD_P(me->def)) {
2405 rb_method_name_error(klass, rb_id2str(
id));
2408 rb_add_method(klass,
id, VM_METHOD_TYPE_UNDEF, 0, METHOD_VISI_PUBLIC);
2410 CALL_METHOD_HOOK(klass, undefined,
id);
2459rb_mod_undef_method(
int argc,
VALUE *argv,
VALUE mod)
2462 for (i = 0; i < argc; i++) {
2466 rb_method_name_error(mod, v);
2473static rb_method_visibility_t
2474check_definition_visibility(
VALUE mod,
int argc,
VALUE *argv)
2477 VALUE mid, include_super, lookup_mod = mod;
2483 if (!
id)
return METHOD_VISI_UNDEF;
2489 inc_super =
RTEST(include_super);
2491 lookup_mod = RCLASS_ORIGIN(mod);
2495 me = rb_method_entry_without_refinements(lookup_mod,
id, NULL);
2497 if (me->def->type == VM_METHOD_TYPE_NOTIMPLEMENTED)
return METHOD_VISI_UNDEF;
2498 if (!inc_super && me->owner != mod)
return METHOD_VISI_UNDEF;
2499 return METHOD_ENTRY_VISI(me);
2501 return METHOD_VISI_UNDEF;
2541rb_mod_method_defined(
int argc,
VALUE *argv,
VALUE mod)
2543 rb_method_visibility_t visi = check_definition_visibility(mod, argc, argv);
2544 return RBOOL(visi == METHOD_VISI_PUBLIC || visi == METHOD_VISI_PROTECTED);
2548check_definition(
VALUE mod,
int argc,
VALUE *argv, rb_method_visibility_t visi)
2550 return RBOOL(check_definition_visibility(mod, argc, argv) == visi);
2584rb_mod_public_method_defined(
int argc,
VALUE *argv,
VALUE mod)
2586 return check_definition(mod, argc, argv, METHOD_VISI_PUBLIC);
2620rb_mod_private_method_defined(
int argc,
VALUE *argv,
VALUE mod)
2622 return check_definition(mod, argc, argv, METHOD_VISI_PRIVATE);
2656rb_mod_protected_method_defined(
int argc,
VALUE *argv,
VALUE mod)
2658 return check_definition(mod, argc, argv, METHOD_VISI_PROTECTED);
2664 return rb_method_definition_eq(m1->def, m2->def);
2672 switch (def->type) {
2673 case VM_METHOD_TYPE_REFINED:
2674 if (def->body.refined.orig_me) {
2675 def = def->body.refined.orig_me->def;
2679 case VM_METHOD_TYPE_ALIAS:
2680 def = def->body.alias.original_me->def;
2692 d1 = original_method_definition(d1);
2693 d2 = original_method_definition(d2);
2695 if (d1 == d2)
return 1;
2696 if (!d1 || !d2)
return 0;
2697 if (d1->type != d2->type)
return 0;
2700 case VM_METHOD_TYPE_ISEQ:
2701 return d1->body.iseq.iseqptr == d2->body.iseq.
iseqptr;
2702 case VM_METHOD_TYPE_CFUNC:
2704 d1->body.cfunc.func == d2->body.cfunc.func &&
2705 d1->body.cfunc.argc == d2->body.cfunc.argc;
2706 case VM_METHOD_TYPE_ATTRSET:
2707 case VM_METHOD_TYPE_IVAR:
2708 return d1->body.attr.id == d2->body.attr.id;
2709 case VM_METHOD_TYPE_BMETHOD:
2710 return RTEST(
rb_equal(d1->body.bmethod.proc, d2->body.bmethod.proc));
2711 case VM_METHOD_TYPE_MISSING:
2712 return d1->original_id == d2->original_id;
2713 case VM_METHOD_TYPE_ZSUPER:
2714 case VM_METHOD_TYPE_NOTIMPLEMENTED:
2715 case VM_METHOD_TYPE_UNDEF:
2717 case VM_METHOD_TYPE_OPTIMIZED:
2718 return (d1->body.optimized.type == d2->body.optimized.type) &&
2719 (d1->body.optimized.index == d2->body.optimized.index);
2720 case VM_METHOD_TYPE_REFINED:
2721 case VM_METHOD_TYPE_ALIAS:
2724 rb_bug(
"rb_method_definition_eq: unsupported type: %d", d1->type);
2731 def = original_method_definition(def);
2733 if (!def)
return hash;
2735 switch (def->type) {
2736 case VM_METHOD_TYPE_ISEQ:
2738 case VM_METHOD_TYPE_CFUNC:
2739 hash =
rb_hash_uint(hash, (st_index_t)def->body.cfunc.func);
2741 case VM_METHOD_TYPE_ATTRSET:
2742 case VM_METHOD_TYPE_IVAR:
2744 case VM_METHOD_TYPE_BMETHOD:
2745 return rb_hash_proc(hash, def->body.bmethod.proc);
2746 case VM_METHOD_TYPE_MISSING:
2748 case VM_METHOD_TYPE_ZSUPER:
2749 case VM_METHOD_TYPE_NOTIMPLEMENTED:
2750 case VM_METHOD_TYPE_UNDEF:
2752 case VM_METHOD_TYPE_OPTIMIZED:
2755 case VM_METHOD_TYPE_REFINED:
2756 case VM_METHOD_TYPE_ALIAS:
2759 rb_bug(
"rb_hash_method_definition: unsupported method type (%d)", def->type);
2765 return rb_hash_method_definition(hash, me->def);
2771 const VALUE target_klass = klass;
2772 VALUE defined_class;
2774 rb_method_visibility_t visi = METHOD_VISI_UNDEF;
2783 orig_me = search_method(klass, original_name, &defined_class);
2785 if (orig_me && orig_me->def->type == VM_METHOD_TYPE_REFINED) {
2786 orig_me = rb_resolve_refined_method(
Qnil, orig_me);
2789 if (UNDEFINED_METHOD_ENTRY_P(orig_me) ||
2790 UNDEFINED_REFINED_METHOD_P(orig_me->def)) {
2792 (orig_me = search_method(
rb_cObject, original_name, &defined_class),
2793 UNDEFINED_METHOD_ENTRY_P(orig_me))) {
2794 rb_print_undef(target_klass, original_name, METHOD_VISI_UNDEF);
2798 switch (orig_me->def->type) {
2799 case VM_METHOD_TYPE_ZSUPER:
2801 original_name = orig_me->def->original_id;
2802 visi = METHOD_ENTRY_VISI(orig_me);
2804 case VM_METHOD_TYPE_ALIAS:
2805 visi = METHOD_ENTRY_VISI(orig_me);
2806 orig_me = orig_me->def->body.alias.original_me;
2807 VM_ASSERT(orig_me->def->type != VM_METHOD_TYPE_ALIAS);
2812 if (visi == METHOD_VISI_UNDEF) visi = METHOD_ENTRY_VISI(orig_me);
2814 if (orig_me->defined_class == 0) {
2815 rb_method_entry_make(target_klass, alias_name, target_klass, visi,
2816 VM_METHOD_TYPE_ALIAS, NULL, orig_me->called_id,
2817 (
void *)rb_method_entry_clone(orig_me));
2818 method_added(target_klass, alias_name);
2823 alias_me = method_entry_set(target_klass, alias_name, orig_me, visi, orig_me->owner);
2824 RB_OBJ_WRITE(alias_me, &alias_me->owner, target_klass);
2830 RB_OBJ_WRITE(alias_me, &alias_me->defined_class, orig_me->defined_class);
2862 rb_print_undef_str(mod, oldname);
2870check_and_export_method(
VALUE self,
VALUE name, rb_method_visibility_t visi)
2874 rb_print_undef_str(self, name);
2876 rb_export_method(self,
id, visi);
2880set_method_visibility(
VALUE self,
int argc,
const VALUE *argv, rb_method_visibility_t visi)
2884 rb_check_frozen(self);
2886 rb_warning(
"%"PRIsVALUE
" with no argument is just ignored",
2887 QUOTE_ID(rb_frame_callee()));
2898 check_and_export_method(self,
RARRAY_AREF(v, j), visi);
2902 for (i = 0; i < argc; i++) {
2903 check_and_export_method(self, argv[i], visi);
2909set_visibility(
int argc,
const VALUE *argv,
VALUE module, rb_method_visibility_t visi)
2912 scope_visibility_check();
2913 rb_scope_visibility_set(visi);
2917 set_method_visibility(module, argc, argv, visi);
2942rb_mod_public(
int argc,
VALUE *argv,
VALUE module)
2944 return set_visibility(argc, argv, module, METHOD_VISI_PUBLIC);
3006rb_mod_protected(
int argc,
VALUE *argv,
VALUE module)
3008 return set_visibility(argc, argv, module, METHOD_VISI_PROTECTED);
3040rb_mod_private(
int argc,
VALUE *argv,
VALUE module)
3042 return set_visibility(argc, argv, module, METHOD_VISI_PRIVATE);
3082rb_mod_ruby2_keywords(
int argc,
VALUE *argv,
VALUE module)
3085 VALUE origin_class = RCLASS_ORIGIN(module);
3088 rb_check_frozen(module);
3090 for (i = 0; i < argc; i++) {
3094 VALUE defined_class;
3097 rb_print_undef_str(module, v);
3100 me = search_method(origin_class, name, &defined_class);
3102 me = search_method(
rb_cObject, name, &defined_class);
3105 if (UNDEFINED_METHOD_ENTRY_P(me) ||
3106 UNDEFINED_REFINED_METHOD_P(me->def)) {
3107 rb_print_undef(module, name, METHOD_VISI_UNDEF);
3110 if (module == defined_class || origin_class == defined_class) {
3111 switch (me->def->type) {
3112 case VM_METHOD_TYPE_ISEQ:
3113 if (ISEQ_BODY(me->def->body.iseq.
iseqptr)->param.flags.has_rest &&
3114 !ISEQ_BODY(me->def->body.iseq.
iseqptr)->param.flags.has_post &&
3115 !ISEQ_BODY(me->def->body.iseq.
iseqptr)->param.flags.has_kw &&
3116 !ISEQ_BODY(me->def->body.iseq.
iseqptr)->param.flags.has_kwrest) {
3117 ISEQ_BODY(me->def->body.iseq.
iseqptr)->param.flags.ruby2_keywords = 1;
3118 rb_clear_method_cache(module, name);
3121 rb_warn(
"Skipping set of ruby2_keywords flag for %"PRIsVALUE
" (method accepts keywords or post arguments or method does not accept argument splat)", QUOTE_ID(name));
3124 case VM_METHOD_TYPE_BMETHOD: {
3125 VALUE procval = me->def->body.bmethod.proc;
3126 if (vm_block_handler_type(procval) == block_handler_type_proc) {
3127 procval = vm_proc_to_block_handler(VM_BH_TO_PROC(procval));
3130 if (vm_block_handler_type(procval) == block_handler_type_iseq) {
3132 const rb_iseq_t *iseq = rb_iseq_check(captured->code.iseq);
3133 if (ISEQ_BODY(iseq)->param.flags.has_rest &&
3134 !ISEQ_BODY(iseq)->param.flags.has_post &&
3135 !ISEQ_BODY(iseq)->param.flags.has_kw &&
3136 !ISEQ_BODY(iseq)->param.flags.has_kwrest) {
3137 ISEQ_BODY(iseq)->param.flags.ruby2_keywords = 1;
3138 rb_clear_method_cache(module, name);
3141 rb_warn(
"Skipping set of ruby2_keywords flag for %"PRIsVALUE
" (method accepts keywords or post arguments or method does not accept argument splat)", QUOTE_ID(name));
3148 rb_warn(
"Skipping set of ruby2_keywords flag for %"PRIsVALUE
" (method not defined in Ruby)", QUOTE_ID(name));
3153 rb_warn(
"Skipping set of ruby2_keywords flag for %"PRIsVALUE
" (can only set in method defining module)", QUOTE_ID(name));
3172rb_mod_public_method(
int argc,
VALUE *argv,
VALUE obj)
3200rb_mod_private_method(
int argc,
VALUE *argv,
VALUE obj)
3224 return rb_mod_public(argc, argv, rb_top_main_class(
"public"));
3244 return rb_mod_private(argc, argv, rb_top_main_class(
"private"));
3255top_ruby2_keywords(
int argc,
VALUE *argv,
VALUE module)
3257 return rb_mod_ruby2_keywords(argc, argv, rb_top_main_class(
"ruby2_keywords"));
3303rb_mod_modfunc(
int argc,
VALUE *argv,
VALUE module)
3310 rb_raise(
rb_eTypeError,
"module_function must be called for modules");
3314 rb_scope_module_func_set();
3318 set_method_visibility(module, argc, argv, METHOD_VISI_PRIVATE);
3320 for (i = 0; i < argc; i++) {
3325 me = search_method(m,
id, 0);
3329 if (UNDEFINED_METHOD_ENTRY_P(me)) {
3330 rb_print_undef(module,
id, METHOD_VISI_UNDEF);
3332 if (me->def->type != VM_METHOD_TYPE_ZSUPER) {
3348#pragma push_macro("rb_method_basic_definition_p")
3349#undef rb_method_basic_definition_p
3355 if (!klass)
return TRUE;
3356 cme = rb_callable_method_entry(klass,
id);
3357 return (cme && METHOD_ENTRY_BASIC(cme)) ? TRUE : FALSE;
3360#pragma pop_macro("rb_method_basic_definition_p")
3367 VALUE passed_block_handler = vm_passed_block_handler(ec);
3368 VALUE result = rb_vm_call_kw(ec, obj,
id, argc, argv, cme, kw_splat);
3369 vm_passed_block_handler_set(ec, passed_block_handler);
3377 VALUE defined_class, args[2];
3378 const ID rtmid = idRespond_to_missing;
3381 if (!cme || METHOD_ENTRY_BASIC(cme))
return Qundef;
3384 return call_method_entry(ec, defined_class, obj, rtmid, cme, 2, args,
RB_NO_KEYWORDS);
3393 switch (method_boundp(klass,
id, pub|BOUND_RESPONDS)) {
3397 ret = basic_obj_respond_to_missing(ec, klass, obj,
ID2SYM(
id),
3399 return RTEST(ret) && !UNDEF_P(ret);
3408 VALUE defined_class;
3409 const ID resid = idRespond_to;
3412 if (!cme)
return -1;
3413 if (METHOD_ENTRY_BASIC(cme)) {
3426 rb_raise(rb_eArgError,
3427 "respond_to? must accept 1 or 2 arguments (requires %d)",
3436 "%"PRIsVALUE
"%c""respond_to?(:%"PRIsVALUE
") uses"
3437 " the deprecated method signature, which takes one parameter",
3438 (RCLASS_SINGLETON_P(klass) ? obj : klass),
3439 (RCLASS_SINGLETON_P(klass) ?
'.' :
'#'),
3441 if (!
NIL_P(location)) {
3446 RSTRING_PTR(path),
NUM2INT(line),
3447 "respond_to? is defined here");
3452 result = call_method_entry(ec, defined_class, obj, resid, cme, argc, args,
RB_NO_KEYWORDS);
3453 return RTEST(result);
3461 return rb_ec_obj_respond_to(ec, obj,
id, priv);
3468 int ret = vm_respond_to(ec, klass, obj,
id, priv);
3469 if (ret == -1) ret = basic_obj_respond_to(ec, obj,
id, !priv);
3501obj_respond_to(
int argc,
VALUE *argv,
VALUE obj)
3509 VALUE ret = basic_obj_respond_to_missing(ec,
CLASS_OF(obj), obj,
3511 if (UNDEF_P(ret)) ret =
Qfalse;
3514 return RBOOL(basic_obj_respond_to(ec, obj,
id, !
RTEST(priv)));
3539Init_eval_method(
void)
3561 "public", top_public, -1);
3563 "private", top_private, -1);
3565 "ruby2_keywords", top_ruby2_keywords, -1);
3568#define REPLICATE_METHOD(klass, id) do { \
3569 const rb_method_entry_t *me = rb_method_entry((klass), (id)); \
3570 rb_method_entry_set((klass), (id), me, METHOD_ENTRY_VISI(me)); \
#define RUBY_ASSERT_ALWAYS(expr,...)
A variant of RUBY_ASSERT that does not interface with RUBY_DEBUG.
#define RUBY_ASSERT(...)
Asserts that the given expression is truthy if and only if RUBY_DEBUG is truthy.
std::atomic< unsigned > rb_atomic_t
Type that is eligible for atomic operations.
#define RUBY_ATOMIC_FETCH_ADD(var, val)
Atomically replaces the value pointed by var with the result of addition of val to the old value of v...
#define RUBY_ATOMIC_FETCH_SUB(var, val)
Atomically replaces the value pointed by var with the result of subtraction of val to the old value o...
#define rb_define_method(klass, mid, func, arity)
Defines klass#mid.
#define rb_define_private_method(klass, mid, func, arity)
Defines klass#mid and makes it private.
VALUE rb_singleton_class(VALUE obj)
Finds or creates the singleton class of the passed object.
void rb_class_modify_check(VALUE klass)
Asserts that klass is not a frozen class.
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 xfree
Old name of ruby_xfree.
#define Qundef
Old name of RUBY_Qundef.
#define INT2FIX
Old name of RB_INT2FIX.
#define ID2SYM
Old name of RB_ID2SYM.
#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 T_MODULE
Old name of RUBY_T_MODULE.
#define T_ICLASS
Old name of RUBY_T_ICLASS.
#define FL_TEST_RAW
Old name of RB_FL_TEST_RAW.
#define rb_ary_new3
Old name of rb_ary_new_from_args.
#define Qtrue
Old name of RUBY_Qtrue.
#define NUM2INT
Old name of RB_NUM2INT.
#define Qnil
Old name of RUBY_Qnil.
#define Qfalse
Old name of RUBY_Qfalse.
#define NIL_P
Old name of RB_NIL_P.
#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_SET_RAW
Old name of RB_FL_SET_RAW.
void rb_notimplement(void)
void rb_category_warn(rb_warning_category_t category, const char *fmt,...)
Identical to rb_category_warning(), except it reports unless $VERBOSE is nil.
#define ruby_verbose
This variable controls whether the interpreter is in debug mode.
VALUE rb_eTypeError
TypeError exception.
void rb_category_compile_warn(rb_warning_category_t category, const char *file, int line, const char *fmt,...)
Identical to rb_compile_warn(), except it also accepts category.
void rb_warn(const char *fmt,...)
Identical to rb_warning(), except it reports unless $VERBOSE is nil.
VALUE rb_eException
Mother of all exceptions.
void rb_warning(const char *fmt,...)
Issues a warning.
@ RB_WARN_CATEGORY_DEPRECATED
Warning is for deprecated features.
VALUE rb_mKernel
Kernel module.
VALUE rb_cObject
Object class.
VALUE rb_cModule
Module class.
VALUE rb_equal(VALUE lhs, VALUE rhs)
This function is an optimised version of calling #==.
#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_ary_new_from_values(long n, const VALUE *elts)
Identical to rb_ary_new_from_args(), except how objects are passed.
VALUE rb_check_array_type(VALUE obj)
Try converting an object to its array representation using its to_ary method, if any.
VALUE rb_ary_freeze(VALUE obj)
Freeze an array, preventing further modifications.
void rb_undef(VALUE mod, ID mid)
Inserts a method entry that hides previous method definition of the given name.
#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.
#define rb_hash_uint(h, i)
Just another name of st_hash_uint.
st_index_t rb_hash_start(st_index_t i)
Starts a series of hashing.
VALUE rb_mod_name(VALUE mod)
Queries the name of a module.
int rb_respond_to(VALUE obj, ID mid)
Queries if the object responds to the method.
VALUE(* rb_alloc_func_t)(VALUE klass)
This is the type of functions that ruby calls when trying to allocate an object.
void rb_undef_alloc_func(VALUE klass)
Deletes the allocator function of a class.
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_remove_method(VALUE klass, const char *name)
Removes a method.
rb_alloc_func_t rb_get_alloc_func(VALUE klass)
Queries the allocator function of a class.
void rb_clear_constant_cache_for_id(ID id)
Clears the inline constant caches associated with a particular ID.
void rb_remove_method_id(VALUE klass, ID mid)
Identical to rb_remove_method(), except it accepts the method name as ID.
void rb_define_alloc_func(VALUE klass, rb_alloc_func_t func)
Sets the allocator function of a class.
VALUE rb_f_notimplement(int argc, const VALUE *argv, VALUE obj, VALUE marker)
Raises rb_eNotImpError.
int rb_method_boundp(VALUE klass, ID id, int ex)
Queries if the klass has this method.
int rb_obj_respond_to(VALUE obj, ID mid, int private_p)
Identical to rb_respond_to(), except it additionally takes the visibility parameter.
ID rb_check_id(volatile VALUE *namep)
Detects if the given name is already interned or not.
VALUE rb_to_symbol(VALUE name)
Identical to rb_intern_str(), except it generates a dynamic symbol if necessary.
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...
int capa
Designed capacity of the buffer.
VALUE type(ANYARGS)
ANYARGS-ed function type.
#define RARRAY_LEN
Just another name of rb_array_len.
#define RARRAY_AREF(a, i)
#define RBASIC(obj)
Convenient casting macro.
#define RCLASS_SUPER
Just another name of rb_class_get_superclass.
#define RUBY_TYPED_FREE_IMMEDIATELY
Macros to see if each corresponding flag is defined.
#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...
#define RB_NO_KEYWORDS
Do not pass keywords.
#define RTEST
This is an old name of RB_TEST.
#define _(args)
This was a transition path from K&R to ANSI.
#define ANYARGS
Functions declared using this macro take arbitrary arguments, including void.
This is the struct that holds necessary info for a struct.
size_t(* dsize)(const void *)
This function is to query the size of the underlying memory regions.
RUBY_DATA_FUNC dfree
This function is called when the object is no longer used.
struct rb_data_type_struct::@57 function
Function pointers.
const char * wrap_struct_name
Name of structs of this kind.
VALUE flags
Type-specific behavioural characteristics.
rb_cref_t * cref
class reference, should be marked
const rb_iseq_t * iseqptr
iseq pointer, should be separated from iseqval
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.