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 rb_gc_mark_movable((
VALUE)ccs->cme);
37 for (
int i = 0; i < ccs->len; i++) {
38 rb_gc_mark_movable((
VALUE)ccs->entries[i].cc);
40 return ID_TABLE_CONTINUE;
43 rb_gc_mark_movable((
VALUE)ccs->cme);
45 for (
int i = 0; i < ccs->len; i++) {
47 VM_ASSERT(cc->klass ==
Qundef || vm_cc_check_cme(cc, ccs->cme));
49 rb_gc_mark_movable((
VALUE)cc);
51 return ID_TABLE_CONTINUE;
56vm_cc_table_mark(
void *data)
60 rb_id_table_foreach_values(tbl, mark_cc_entry_i, NULL);
64static enum rb_id_table_iterator_result
65cc_table_free_i(
VALUE ccs_ptr,
void *data)
68 VM_ASSERT(vm_ccs_p(ccs));
70 ruby_xfree_sized(ccs, vm_ccs_alloc_size(ccs->capa));
72 return ID_TABLE_CONTINUE;
76vm_cc_table_free(
void *data)
80 rb_id_table_foreach_values(tbl, cc_table_free_i, NULL);
84static enum rb_id_table_iterator_result
85cc_table_memsize_i(
VALUE ccs_ptr,
void *data_ptr)
87 size_t *total_size = data_ptr;
89 *total_size +=
sizeof(*ccs);
90 *total_size +=
sizeof(ccs->entries[0]) * ccs->capa;
91 return ID_TABLE_CONTINUE;
95vm_cc_table_memsize(
const void *data)
97 size_t memsize = rb_managed_id_table_type.
function.
dsize(data);
99 rb_id_table_foreach_values(tbl, cc_table_memsize_i, &memsize);
103static enum rb_id_table_iterator_result
104compact_cc_entry_i(
VALUE ccs_ptr,
void *data)
108 rb_gc_update_moved_ptr(&ccs->cme);
109 VM_ASSERT(vm_ccs_p(ccs));
111 for (
int i=0; i<ccs->len; i++) {
112 rb_gc_update_moved_ptr(&ccs->entries[i].cc);
115 return ID_TABLE_CONTINUE;
119vm_cc_table_compact(
void *data)
122 rb_id_table_foreach_values(tbl, compact_cc_entry_i, NULL);
128 .dmark = vm_cc_table_mark,
129 .dfree = vm_cc_table_free,
130 .dsize = vm_cc_table_memsize,
131 .dcompact = vm_cc_table_compact,
133 .parent = &rb_managed_id_table_type,
134 .
flags = RUBY_TYPED_THREAD_SAFE_FREE | RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_EMBEDDABLE,
138rb_vm_cc_table_create(
size_t capa)
140 return rb_managed_id_table_create(&cc_table_type,
capa);
145static enum rb_id_table_iterator_result
146vm_cc_table_dup_i(
ID key,
VALUE old_ccs_ptr,
void *data)
151 if (METHOD_ENTRY_INVALIDATED(old_ccs->cme)) {
158 vm_ccs_invalidate(old_ccs);
159 return ID_TABLE_CONTINUE;
162 size_t memsize = vm_ccs_alloc_size(old_ccs->capa);
164 rb_managed_id_table_insert(new_table, key, (
VALUE)new_ccs);
168 VM_ASSERT(!METHOD_ENTRY_INVALIDATED(old_ccs->cme));
170 memcpy(new_ccs, old_ccs, memsize);
173 new_ccs->debug_sig = ~(
VALUE)new_ccs;
177 for (
int index = 0; index < new_ccs->len; index++) {
180 return ID_TABLE_CONTINUE;
184rb_vm_cc_table_dup(
VALUE old_table)
187 VALUE new_table = rb_vm_cc_table_create(rb_managed_id_table_size(old_table));
188 rb_managed_id_table_foreach(old_table, vm_cc_table_dup_i, (
void *)new_table);
195 for (
int i=0; i<ccs->len; i++) {
197 if (cc->klass ==
Qundef)
continue;
198 VM_ASSERT(!vm_cc_super_p(cc) && !vm_cc_refinement_p(cc));
199 vm_cc_invalidate(cc);
206 RB_DEBUG_COUNTER_INC(ccs_free);
207 vm_ccs_invalidate(ccs);
208 ruby_xfree_sized(ccs, vm_ccs_alloc_size(ccs->capa));
212rb_vm_cc_table_delete(
VALUE table,
ID mid)
215 if (rb_managed_id_table_lookup(table, mid, &ccs_obj)) {
217 rb_managed_id_table_delete(table, mid);
218 rb_vm_ccs_invalidate_and_free(ccs);
222static enum rb_id_table_iterator_result
223vm_ccs_dump_i(
ID mid,
VALUE val,
void *data)
226 fprintf(stderr,
" | %s (len:%d) ", rb_id2name(mid), ccs->len);
229 for (
int i=0; i<ccs->len; i++) {
230 rp_m(
" | \t", ccs->entries[i].cc);
233 return ID_TABLE_CONTINUE;
237vm_ccs_dump(
VALUE klass,
ID target_mid)
239 VALUE cc_tbl = RCLASS_WRITABLE_CC_TBL(klass);
243 if (rb_managed_id_table_lookup(cc_tbl, target_mid, &ccs)) {
244 fprintf(stderr,
" [CCTB] %p\n", (
void *)cc_tbl);
245 vm_ccs_dump_i(target_mid, ccs, NULL);
249 fprintf(stderr,
" [CCTB] %p\n", (
void *)cc_tbl);
250 rb_managed_id_table_foreach(cc_tbl, vm_ccs_dump_i, (
void *)target_mid);
255static enum rb_id_table_iterator_result
256vm_cme_dump_i(
ID mid,
VALUE val,
void *data)
258 ID target_mid = (
ID)data;
259 if (target_mid == 0 || mid == target_mid) {
262 return ID_TABLE_CONTINUE;
266vm_mtbl_dump(
VALUE klass,
ID target_mid)
268 fprintf(stderr,
"# vm_mtbl\n");
273 if (RCLASS_M_TBL(klass)) {
274 if (target_mid != 0) {
275 if (rb_id_table_lookup(RCLASS_M_TBL(klass), target_mid, &me)) {
276 rp_m(
" [MTBL] ", me);
280 fprintf(stderr,
" ## RCLASS_M_TBL (%p)\n", (
void *)RCLASS_M_TBL(klass));
281 rb_id_table_foreach(RCLASS_M_TBL(klass), vm_cme_dump_i, NULL);
285 fprintf(stderr,
" MTBL: NULL\n");
287 if (RCLASS_WRITABLE_CALLABLE_M_TBL(klass)) {
288 if (target_mid != 0) {
289 if (rb_id_table_lookup(RCLASS_WRITABLE_CALLABLE_M_TBL(klass), target_mid, &me)) {
290 rp_m(
" [CM**] ", me);
294 fprintf(stderr,
" ## RCLASS_CALLABLE_M_TBL\n");
295 rb_id_table_foreach(RCLASS_WRITABLE_CALLABLE_M_TBL(klass), vm_cme_dump_i, NULL);
298 if (RCLASS_WRITABLE_CC_TBL(klass)) {
299 vm_ccs_dump(klass, target_mid);
307rb_vm_mtbl_dump(
const char *msg,
VALUE klass,
ID target_mid)
309 fprintf(stderr,
"[%s] ", msg);
310 vm_mtbl_dump(klass, target_mid);
316 VM_ASSERT(IMEMO_TYPE_P(cme, imemo_ment),
"cme: %d", imemo_type((
VALUE)cme));
317 VM_ASSERT(callable_method_entry_p(cme));
318 METHOD_ENTRY_INVALIDATED_SET(cme);
319 RB_DEBUG_COUNTER_INC(cc_cme_invalidate);
321 rb_yjit_cme_invalidate(cme);
322 rb_zjit_cme_invalidate(cme);
326rb_clear_constant_cache_for_id_i(st_data_t ic, st_data_t arg)
328 ((
IC) ic)->entry = NULL;
338 if (rb_id_table_lookup(&vm->constant_cache,
id, &lookup_result)) {
340 set_table_foreach(ics, rb_clear_constant_cache_for_id_i, (st_data_t) NULL);
341 ruby_vm_constant_cache_invalidations += ics->num_entries;
344 rb_yjit_constant_state_changed(
id);
345 rb_zjit_constant_state_changed(
id);
349invalidate_negative_cache(
ID mid)
354 if (rb_id_table_lookup(&vm->negative_cme_table, mid, &cme)) {
355 rb_id_table_delete(&vm->negative_cme_table, mid);
357 RB_DEBUG_COUNTER_INC(cc_invalidate_negative);
366invalidate_method_cache_in_cc_table(
VALUE tbl,
ID mid)
369 if (tbl && rb_managed_id_table_lookup(tbl, mid, &ccs_data)) {
373 if (
NIL_P(ccs->cme->owner)) invalidate_negative_cache(mid);
374 rb_vm_ccs_invalidate_and_free(ccs);
375 rb_managed_id_table_delete(tbl, mid);
376 RB_DEBUG_COUNTER_INC(cc_invalidate_leaf_ccs);
381invalidate_callable_method_entry_in_callable_m_table(
struct rb_id_table *tbl,
ID mid)
384 if (tbl && rb_id_table_lookup(tbl, mid, &cme)) {
387 rb_id_table_delete(tbl, mid);
388 RB_DEBUG_COUNTER_INC(cc_invalidate_leaf_callable);
400invalidate_callable_method_entry_in_every_m_table_i(
rb_classext_t *ext,
bool is_prime,
VALUE box_value,
void *data)
406 if (rb_id_table_lookup(tbl, arg->mid, &me) && arg->cme == (
const rb_method_entry_t *)me) {
407 rb_method_table_insert(arg->klass, tbl, arg->mid, arg->newer);
413 VALUE klass_housing_cme;
418collect_per_box_origins_i(
rb_classext_t *ext,
bool is_prime,
VALUE box_value,
void *data)
421 VALUE origin = RCLASSEXT_ORIGIN(ext);
423 if (origin == arg->owner || origin == arg->klass_housing_cme) {
446 rb_class_classext_foreach(klass, invalidate_callable_method_entry_in_every_m_table_i, (
void *)&arg);
450invalidate_complemented_method_entry_in_callable_m_table(
struct rb_id_table *tbl,
ID mid)
453 if (tbl && rb_id_table_lookup(tbl, mid, &cme)) {
456 rb_id_table_delete(tbl, mid);
457 RB_DEBUG_COUNTER_INC(cc_invalidate_tree_callable);
462clear_method_cache_by_id_in_class(
VALUE klass,
ID mid)
465 if (rb_objspace_garbage_object_p(klass))
return;
470 if (LIKELY(!RCLASS_SUBCLASSES(klass)) &&
480 VALUE cc_tbl = RCLASS_WRITABLE_CC_TBL(klass);
481 invalidate_method_cache_in_cc_table(cc_tbl, mid);
482 if (RCLASS_CC_TBL_NOT_PRIME_P(klass, cc_tbl)) {
483 invalidate_method_cache_in_cc_table(RCLASS_PRIME_CC_TBL(klass), mid);
487 struct rb_id_table *cm_tbl = RCLASS_WRITABLE_CALLABLE_M_TBL(klass);
488 invalidate_callable_method_entry_in_callable_m_table(cm_tbl, mid);
489 if (RCLASS_CALLABLE_M_TBL_NOT_PRIME_P(klass, cm_tbl)) {
490 invalidate_callable_method_entry_in_callable_m_table(RCLASS_PRIME_CALLABLE_M_TBL(klass), mid);
493 RB_DEBUG_COUNTER_INC(cc_invalidate_leaf);
500 if (METHOD_ENTRY_CACHED(cme)) {
501 if (METHOD_ENTRY_COMPLEMENTED(cme)) {
506 VALUE owner = cme->owner;
507 VM_ASSERT_TYPE(owner,
T_CLASS);
508 VALUE klass_housing_cme;
509 if (cme->def->type == VM_METHOD_TYPE_REFINED && !cme->def->body.refined.orig_me) {
510 klass_housing_cme = owner;
513 klass_housing_cme = RCLASS_ORIGIN(owner);
517 invalidate_callable_method_entry_in_every_m_table(klass_housing_cme, mid, cme);
520 if (klass_housing_cme != owner) {
521 invalidate_callable_method_entry_in_every_m_table(owner, mid, cme);
532 .klass_housing_cme = klass_housing_cme,
535 rb_class_classext_foreach(owner, collect_per_box_origins_i, &origins_arg);
537 invalidate_callable_method_entry_in_every_m_table(
RARRAY_AREF(origins, i), mid, cme);
544 RB_DEBUG_COUNTER_INC(cc_invalidate_tree_cme);
549 if (cme->def->type == VM_METHOD_TYPE_REFINED && cme->def->body.refined.orig_me) {
553 if (cme->def->iseq_overload) {
556 vm_cme_invalidate(monly_cme);
562 if (METHOD_ENTRY_COMPLEMENTED(cme)) {
563 VALUE defined_class = cme->defined_class;
564 struct rb_id_table *cm_tbl = RCLASS_WRITABLE_CALLABLE_M_TBL(defined_class);
565 invalidate_complemented_method_entry_in_callable_m_table(cm_tbl, mid);
566 if (RCLASS_CALLABLE_M_TBL_NOT_PRIME_P(defined_class, cm_tbl)) {
567 struct rb_id_table *prime_cm_table = RCLASS_PRIME_CALLABLE_M_TBL(defined_class);
568 invalidate_complemented_method_entry_in_callable_m_table(prime_cm_table, mid);
572 RB_DEBUG_COUNTER_INC(cc_invalidate_tree);
575 invalidate_negative_cache(mid);
579 rb_gccct_clear_table();
584clear_iclass_method_cache_by_id(
VALUE iclass,
VALUE d)
588 clear_method_cache_by_id_in_class(iclass, mid);
592clear_iclass_method_cache_by_id_for_refinements(
VALUE klass,
VALUE d)
596 clear_method_cache_by_id_in_class(klass, mid);
601rb_clear_method_cache(
VALUE klass_or_module,
ID mid)
604 VALUE module = klass_or_module;
606 if (
FL_TEST(module, RMODULE_IS_REFINEMENT)) {
607 VALUE refined_class = rb_refinement_module_get_refined_class(module);
608 rb_clear_method_cache(refined_class, mid);
609 rb_class_foreach_subclass(refined_class, clear_iclass_method_cache_by_id_for_refinements, mid);
610 rb_clear_all_refinement_method_cache();
612 rb_class_foreach_subclass(module, clear_iclass_method_cache_by_id, mid);
615 clear_method_cache_by_id_in_class(klass_or_module, mid);
619static enum rb_id_table_iterator_result
620invalidate_method_entry_in_iclass_callable_m_tbl(
VALUE cme,
void *data)
623 return ID_TABLE_DELETE;
626static enum rb_id_table_iterator_result
627invalidate_ccs_in_iclass_cc_tbl(
VALUE value,
void *data)
631 ruby_xfree_sized(ccs, vm_ccs_alloc_size(ccs->capa));
632 return ID_TABLE_DELETE;
639 rb_id_table_foreach_values(cm_tbl, invalidate_method_entry_in_iclass_callable_m_tbl, NULL);
642 rb_managed_id_table_foreach_values(cc_tbl, invalidate_ccs_in_iclass_cc_tbl, NULL);
655 for (
int i = 0; i < ci->kwarg->keyword_len; i++) {
667 if (ci1->mid != ci2->mid)
return 1;
668 if (ci1->flag != ci2->flag)
return 1;
669 if (ci1->argc != ci2->argc)
return 1;
670 if (ci1->kwarg != NULL) {
671 VM_ASSERT(ci2->kwarg != NULL);
673 if (ci1->kwarg->keyword_len != ci2->kwarg->keyword_len)
676 for (
int i = 0; i < ci1->kwarg->keyword_len; i++) {
677 if (ci1->kwarg->keywords[i] != ci2->kwarg->keywords[i]) {
683 VM_ASSERT(ci2->kwarg == NULL);
694ci_lookup_i(st_data_t *key, st_data_t *value, st_data_t data,
int existing)
697 st_data_t *ret = (st_data_t *)data;
700 if (rb_objspace_garbage_object_p((
VALUE)ci)) {
701 *ret = (st_data_t)NULL;
710 *key = *value = *ret = (st_data_t)ci;
716rb_vm_ci_lookup(
ID mid,
unsigned int flag,
unsigned int argc,
const struct rb_callinfo_kwarg *kwarg)
734 st_update(ci_table, (st_data_t)new_ci, ci_lookup_i, (st_data_t)&ci);
735 }
while (ci == NULL);
750 st_data_t key = (st_data_t)ci;
751 st_delete(&vm->ci_table, &key, NULL);
761cc_refinement_set_free(
void *ptr)
768cc_refinement_set_memsize(
const void *ptr)
771 return e->capa *
sizeof(
VALUE);
775cc_refinement_set_compact(
void *ptr)
778 for (
size_t i = 0; i < e->len; i++) {
779 rb_gc_update_moved(&e->entries[i]);
784cc_refinement_set_handle_weak_references(
void *ptr)
788 for (
size_t read = 0; read < e->len; read++) {
789 if (rb_gc_handle_weak_references_alive_p(e->entries[read])) {
790 e->entries[write++] = e->entries[read];
797 "VM/cc_refinement_set",
800 cc_refinement_set_free,
801 cc_refinement_set_memsize,
802 cc_refinement_set_compact,
803 cc_refinement_set_handle_weak_references,
805 0, 0, RUBY_TYPED_THREAD_SAFE_FREE | RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_EMBEDDABLE
809rb_cc_refinement_set_create(
void)
818 rb_gc_declare_weak_references(obj);
824rb_vm_insert_cc_refinement(
const struct rb_callcache *cc)
829 VALUE set = vm->cc_refinement_set;
831 if (e->len == e->capa) {
832 size_t new_capa = e->capa == 0 ? 16 : e->capa * 2;
833 SIZED_REALLOC_N(e->entries,
VALUE, new_capa, e->capa);
836 e->entries[e->len++] = (
VALUE)cc;
848rb_clear_all_refinement_method_cache(
void)
855 for (
size_t i = 0; i < e->len; i++) {
856 VALUE v = e->entries[i];
860 VM_ASSERT(!rb_objspace_garbage_object_p(v));
863 VM_ASSERT(vm_cc_refinement_p(cc));
865 if (vm_cc_valid(cc)) {
866 vm_cc_invalidate(cc);
873 rb_yjit_invalidate_all_method_lookup_assumptions();
880 rb_method_table_insert0(klass, table, method_id, me,
RB_TYPE_P(klass,
T_ICLASS) && !RICLASS_OWNS_M_TBL_P(klass));
887 VALUE table_owner = klass;
888 if (iclass_shared_mtbl) {
889 table_owner =
RBASIC(table_owner)->klass;
892 rb_id_table_insert(table, method_id, (
VALUE)me);
901NORETURN(
static VALUE rb_f_notimplement_internal(
int argc,
const VALUE *argv,
VALUE obj));
904rb_f_notimplement_internal(
int argc,
const VALUE *argv,
VALUE obj)
914 rb_f_notimplement_internal(argc, argv, obj);
918rb_define_notimplement_method_id(
VALUE mod,
ID id, rb_method_visibility_t visi)
920 rb_add_method(mod,
id, VM_METHOD_TYPE_NOTIMPLEMENTED, (
void *)1, visi);
924rb_add_method_cfunc(
VALUE klass,
ID mid,
VALUE (*func)(
ANYARGS),
int argc, rb_method_visibility_t visi)
926 if (argc < -2 || 15 < argc) rb_raise(rb_eArgError,
"arity out of range: %d for -2..15", argc);
931 rb_add_method(klass, mid, VM_METHOD_TYPE_CFUNC, &opt, visi);
934 rb_define_notimplement_method_id(klass, mid, visi);
939rb_add_method_optimized(
VALUE klass,
ID mid,
enum method_optimized_type opt_type,
unsigned int index, rb_method_visibility_t visi)
945 rb_add_method(klass, mid, VM_METHOD_TYPE_OPTIMIZED, &opt, visi);
956 if (reference_count_was == 1) {
957 if (METHOD_DEBUG) fprintf(stderr,
"-%p-%s:1->0 (remove)\n", (
void *)def,
958 rb_id2name(def->original_id));
962 if (METHOD_DEBUG) fprintf(stderr,
"-%p-%s:%d->%d (dec)\n", (
void *)def, rb_id2name(def->original_id),
963 reference_count_was, reference_count_was - 1);
971 method_definition_release(def);
979 if (me->def && me->def->iseq_overload) {
988 if (METHOD_ENTRY_CACHED(me)) {
998 method_definition_release(me->def);
1007 if (!GET_THREAD()->ext_config.ractor_safe) {
1009 case -2:
return &call_cfunc_m2;
1010 case -1:
return &call_cfunc_m1;
1011 case 0:
return &call_cfunc_0;
1012 case 1:
return &call_cfunc_1;
1013 case 2:
return &call_cfunc_2;
1014 case 3:
return &call_cfunc_3;
1015 case 4:
return &call_cfunc_4;
1016 case 5:
return &call_cfunc_5;
1017 case 6:
return &call_cfunc_6;
1018 case 7:
return &call_cfunc_7;
1019 case 8:
return &call_cfunc_8;
1020 case 9:
return &call_cfunc_9;
1021 case 10:
return &call_cfunc_10;
1022 case 11:
return &call_cfunc_11;
1023 case 12:
return &call_cfunc_12;
1024 case 13:
return &call_cfunc_13;
1025 case 14:
return &call_cfunc_14;
1026 case 15:
return &call_cfunc_15;
1028 rb_bug(
"unsupported length: %d", argc);
1033 case -2:
return &ractor_safe_call_cfunc_m2;
1034 case -1:
return &ractor_safe_call_cfunc_m1;
1035 case 0:
return &ractor_safe_call_cfunc_0;
1036 case 1:
return &ractor_safe_call_cfunc_1;
1037 case 2:
return &ractor_safe_call_cfunc_2;
1038 case 3:
return &ractor_safe_call_cfunc_3;
1039 case 4:
return &ractor_safe_call_cfunc_4;
1040 case 5:
return &ractor_safe_call_cfunc_5;
1041 case 6:
return &ractor_safe_call_cfunc_6;
1042 case 7:
return &ractor_safe_call_cfunc_7;
1043 case 8:
return &ractor_safe_call_cfunc_8;
1044 case 9:
return &ractor_safe_call_cfunc_9;
1045 case 10:
return &ractor_safe_call_cfunc_10;
1046 case 11:
return &ractor_safe_call_cfunc_11;
1047 case 12:
return &ractor_safe_call_cfunc_12;
1048 case 13:
return &ractor_safe_call_cfunc_13;
1049 case 14:
return &ractor_safe_call_cfunc_14;
1050 case 15:
return &ractor_safe_call_cfunc_15;
1052 rb_bug(
"unsupported length: %d", argc);
1062 cfunc->invoker = call_cfunc_invoker_func(argc);
1070 if (!complemented && reference_count_was > 0) {
1072 def->aliased =
true;
1074 if (METHOD_DEBUG) fprintf(stderr,
"+%p-%s:%d->%d\n", (
void *)def, rb_id2name(def->original_id), reference_count_was, reference_count_was+1);
1082 method_definition_addref(def,
false);
1088 method_definition_release(me->def);
1091 if (!ruby_running) add_opt_method_entry(me);
1094 switch (def->type) {
1095 case VM_METHOD_TYPE_ISEQ:
1105 if (rb_iseq_attr_p(iseq, BUILTIN_ATTR_C_TRACE)) {
1109 if (ISEQ_BODY(iseq)->mandatory_only_iseq) def->iseq_overload = 1;
1111 if (0) vm_cref_dump(
"rb_method_definition_create", cref);
1117 method_cref = vm_cref_new_toplevel(GET_EC());
1123 case VM_METHOD_TYPE_CFUNC:
1126 setup_method_cfunc_struct(UNALIGNED_MEMBER_PTR(def, body.cfunc), cfunc->func, cfunc->argc);
1129 case VM_METHOD_TYPE_ATTRSET:
1130 case VM_METHOD_TYPE_IVAR:
1136 def->body.attr.id = (
ID)(
VALUE)opts;
1138 cfp = rb_vm_get_ruby_level_next_cfp(ec, ec->cfp);
1140 if (cfp && (line = rb_vm_get_sourceline(cfp))) {
1147 VM_ASSERT(def->body.attr.location == 0);
1151 case VM_METHOD_TYPE_BMETHOD:
1153 def->body.bmethod.defined_ractor_id = rb_ec_ractor_id(GET_EC());
1155 case VM_METHOD_TYPE_NOTIMPLEMENTED:
1156 setup_method_cfunc_struct(UNALIGNED_MEMBER_PTR(def, body.cfunc), (
VALUE(*)(
ANYARGS))rb_f_notimplement_internal, -1);
1158 case VM_METHOD_TYPE_OPTIMIZED:
1161 case VM_METHOD_TYPE_REFINED:
1165 RB_OBJ_WRITE(me, &def->original_module, orig_me->def->original_module);
1168 case VM_METHOD_TYPE_ALIAS:
1171 RB_OBJ_WRITE(me, &def->body.alias.original_me, orig_me);
1172 RB_OBJ_WRITE(me, &def->original_module, orig_me->def->original_module);
1175 case VM_METHOD_TYPE_ZSUPER:
1176 case VM_METHOD_TYPE_UNDEF:
1177 case VM_METHOD_TYPE_MISSING:
1190 switch (def->type) {
1191 case VM_METHOD_TYPE_ISEQ:
1195 case VM_METHOD_TYPE_ATTRSET:
1196 case VM_METHOD_TYPE_IVAR:
1199 case VM_METHOD_TYPE_BMETHOD:
1202 case VM_METHOD_TYPE_REFINED:
1205 case VM_METHOD_TYPE_ALIAS:
1208 case VM_METHOD_TYPE_CFUNC:
1209 case VM_METHOD_TYPE_ZSUPER:
1210 case VM_METHOD_TYPE_MISSING:
1211 case VM_METHOD_TYPE_OPTIMIZED:
1212 case VM_METHOD_TYPE_UNDEF:
1213 case VM_METHOD_TYPE_NOTIMPLEMENTED:
1221rb_method_definition_create(rb_method_type_t
type,
ID mid)
1226 def->original_id = mid;
1228 def->box = rb_current_box();
1235 if (def) method_definition_addref(def, complement);
1236 if (
RTEST(defined_class)) {
1243 rb_gc_register_pinning_obj((
VALUE)me);
1246 me->called_id = called_id;
1253filter_defined_class(
VALUE klass)
1265 rb_bug(
"filter_defined_class: %s", rb_obj_info(klass));
1271 rb_method_entry_t *me = rb_method_entry_alloc(called_id, klass, filter_defined_class(klass), def,
false);
1272 METHOD_ENTRY_FLAGS_SET(me, visi, ruby_running ? FALSE : TRUE);
1273 if (def != NULL) method_definition_reset(me);
1281 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));
1283 METHOD_ENTRY_FLAGS_COPY(me, src_me);
1287 src_me->def->type == VM_METHOD_TYPE_REFINED &&
1288 src_me->def->body.refined.orig_me) {
1290 VM_ASSERT(orig_me->def->type != VM_METHOD_TYPE_REFINED);
1293 orig_me->owner, orig_me->defined_class, orig_me->def, METHOD_ENTRY_COMPLEMENTED(orig_me));
1294 METHOD_ENTRY_FLAGS_COPY(orig_clone, orig_me);
1299 rb_method_definition_create(VM_METHOD_TYPE_REFINED, src_me->called_id);
1300 rb_method_definition_set(me, clone_def, orig_clone);
1312 if (!src_me->defined_class &&
1313 def->type == VM_METHOD_TYPE_REFINED &&
1314 def->body.refined.orig_me) {
1316 rb_method_entry_clone(def->body.refined.orig_me);
1318 refined_orig_me = orig_me;
1322 me = rb_method_entry_alloc(called_id, src_me->owner, defined_class, def,
true);
1323 METHOD_ENTRY_FLAGS_COPY(me, src_me);
1324 METHOD_ENTRY_COMPLEMENTED_SET(me);
1326 def = rb_method_definition_create(VM_METHOD_TYPE_REFINED, called_id);
1327 rb_method_definition_set(me, def, (
void *)refined_orig_me);
1330 VM_ASSERT_TYPE(me->owner,
T_MODULE);
1338 method_definition_release(dst->def);
1339 *(
rb_method_definition_t **)&dst->def = method_definition_addref(src->def, METHOD_ENTRY_COMPLEMENTED(src));
1340 method_definition_reset(dst);
1341 dst->called_id = src->called_id;
1344 METHOD_ENTRY_FLAGS_COPY(dst, src);
1350 if (me->def->type == VM_METHOD_TYPE_REFINED) {
1356 rb_vm_check_redefinition_opt_method(me, me->owner);
1359 rb_method_entry_alloc(me->called_id,
1364 METHOD_ENTRY_FLAGS_COPY(orig_me, me);
1366 def = rb_method_definition_create(VM_METHOD_TYPE_REFINED, me->called_id);
1367 rb_method_definition_set(me, def, orig_me);
1368 METHOD_ENTRY_VISI_SET(me, METHOD_VISI_PUBLIC);
1373lookup_method_table(
VALUE klass,
ID id)
1378 if (rb_id_table_lookup(m_tbl,
id, &body)) {
1399 make_method_entry_refined(refined_class, me);
1400 rb_clear_method_cache(refined_class, mid);
1402 else if (warnings) {
1404 rb_method_entry_make(refined_class, mid, refined_class, METHOD_VISI_PUBLIC,
1405 VM_METHOD_TYPE_REFINED, NULL, mid, NULL, warnings);
1409 rb_add_method(refined_class, mid, VM_METHOD_TYPE_REFINED, 0, METHOD_VISI_PUBLIC);
1414rb_add_refined_method_entry(
VALUE refined_class,
ID mid)
1416 add_refined_method_entry(refined_class, mid, NULL);
1420check_override_opt_method_i(
VALUE klass,
VALUE arg)
1425 VALUE includer = RCLASS_INCLUDER(klass);
1426 if (!UNDEF_P(includer) && includer) {
1427 check_override_opt_method_i(includer, arg);
1435 if (vm_redefinition_check_flag(klass)) {
1436 me = lookup_method_table(RCLASS_ORIGIN(klass), mid);
1438 newme = rb_method_entry(klass, mid);
1439 if (newme != me) rb_vm_check_redefinition_opt_method(me, me->owner);
1442 rb_class_foreach_subclass(klass, check_override_opt_method_i, (
VALUE)mid);
1446check_override_opt_method(
VALUE klass,
VALUE mid)
1448 if (rb_vm_check_optimizable_mid(mid)) {
1449 check_override_opt_method_i(klass, mid);
1454rb_zsuper_to_super(
int argc,
VALUE *argv,
VALUE self)
1461method_entry_modify_check(
VALUE klass, rb_method_type_t
type)
1463 ASSERT_vm_unlocking();
1464 if (
type != VM_METHOD_TYPE_REFINED) {
1481 if (warnings->redefined)
rb_warning(
"%"PRIsVALUE, warnings->redefined);
1482 if (warnings->problem)
rb_warn(
"%"PRIsVALUE, warnings->problem);
1492rb_method_entry_make(
VALUE klass,
ID mid,
VALUE defined_class, rb_method_visibility_t visi,
1499 int make_refined = 0;
1501 bool turn_zsuper_to_super =
false;
1508 if (!RCLASS_SINGLETON_P(klass) &&
1509 type != VM_METHOD_TYPE_NOTIMPLEMENTED &&
1510 type != VM_METHOD_TYPE_ZSUPER) {
1513 case idInitialize_copy:
1514 case idInitialize_clone:
1515 case idInitialize_dup:
1516 case idRespond_to_missing:
1517 visi = METHOD_VISI_PRIVATE;
1522 VALUE refined_class = rb_refinement_module_get_refined_class(klass);
1523 if (
type == VM_METHOD_TYPE_ZSUPER) {
1524 turn_zsuper_to_super =
true;
1526 add_refined_method_entry(refined_class, mid, warnings);
1528 if (
type == VM_METHOD_TYPE_REFINED) {
1530 if (old_me) rb_vm_check_redefinition_opt_method(old_me, klass);
1533 klass = RCLASS_ORIGIN(klass);
1534 if (klass != orig_klass) {
1535 rb_clear_method_cache(orig_klass, mid);
1538 mtbl = RCLASS_WRITABLE_M_TBL(klass);
1541 if (rb_id_table_lookup(mtbl, mid, &data)) {
1545 if (rb_method_definition_eq(old_def, def))
return old_me;
1546 rb_vm_check_redefinition_opt_method(old_me, klass);
1548 if (old_def->type == VM_METHOD_TYPE_REFINED) make_refined = 1;
1551 type != VM_METHOD_TYPE_UNDEF &&
1552 (old_def->aliased ==
false) &&
1553 (!old_def->no_redef_warning) &&
1555 old_def->type != VM_METHOD_TYPE_UNDEF &&
1556 old_def->type != VM_METHOD_TYPE_ZSUPER &&
1557 old_def->type != VM_METHOD_TYPE_ALIAS) {
1560 switch (old_def->type) {
1561 case VM_METHOD_TYPE_ISEQ:
1562 iseq = def_iseq_ptr(old_def);
1564 case VM_METHOD_TYPE_BMETHOD:
1565 iseq = rb_proc_get_iseq(old_def->body.bmethod.proc, 0);
1572 "method redefined; discarding old %"PRIsVALUE
"\n%"PRIsVALUE
":%d: warning: previous definition of %"PRIsVALUE
" was here",
1575 ISEQ_BODY(iseq)->location.first_lineno,
1576 rb_id2str(old_def->original_id)
1580 warnings->redefined = rb_sprintf(
"method redefined; discarding old %"PRIsVALUE, rb_id2str(mid));
1586 me = rb_method_entry_create(mid, defined_class, visi, NULL);
1588 def = rb_method_definition_create(
type, original_id);
1589 if (turn_zsuper_to_super) {
1590 def->type = VM_METHOD_TYPE_CFUNC;
1591 def->body.cfunc.func = (rb_cfunc_t)rb_zsuper_to_super;
1592 def->body.cfunc.invoker = ractor_safe_call_cfunc_m1;
1593 def->body.cfunc.argc = -1;
1597 rb_method_definition_set(me, def, opts);
1599 rb_clear_method_cache(klass, mid);
1605 case idRespond_to_missing:
1606 case idMethodMissing:
1608 warnings->problem = rb_sprintf(
"redefining Object#%s may cause infinite loop", rb_id2name(mid));
1612 if (mid == object_id || mid == id__id__ || mid == id__send__) {
1613 if (
type != VM_METHOD_TYPE_CFUNC && search_method(klass, mid, 0)) {
1614 warnings->problem = rb_sprintf(
"redefining '%s' may cause serious problems", rb_id2name(mid));
1619 make_method_entry_refined(klass, me);
1622 rb_method_table_insert(klass, mtbl, mid, me);
1624 VM_ASSERT(me->def != NULL);
1628 check_override_opt_method(klass, (
VALUE)mid);
1635overloaded_cme_table(
void)
1637 return &GET_VM()->overloaded_cme_table;
1640#if VM_CHECK_MODE > 0
1642vm_dump_overloaded_cme_table(st_data_t key, st_data_t val, st_data_t dmy)
1644 fprintf(stderr,
"key: "); rp(key);
1645 fprintf(stderr,
"val: "); rp(val);
1650rb_vm_dump_overloaded_cme_table(
void)
1652 fprintf(stderr,
"== rb_vm_dump_overloaded_cme_table\n");
1653 st_foreach(overloaded_cme_table(), vm_dump_overloaded_cme_table, 0);
1658lookup_overloaded_cme_i(st_data_t *key, st_data_t *value, st_data_t data,
int existing)
1665 if (rb_objspace_garbage_object_p((
VALUE)cme) ||
1666 rb_objspace_garbage_object_p((
VALUE)monly_cme)) {
1681 ASSERT_vm_locking();
1684 st_update(overloaded_cme_table(), (st_data_t)cme, lookup_overloaded_cme_i, (st_data_t)&monly_cme);
1688#if VM_CHECK_MODE > 0
1692 return lookup_overloaded_cme(cme);
1699 st_data_t cme_data = (st_data_t)cme;
1700 ASSERT_vm_locking();
1701 st_delete(overloaded_cme_table(), &cme_data, NULL);
1709 if (monly_cme && !METHOD_ENTRY_INVALIDATED(monly_cme)) {
1723 RB_OBJ_WRITE(me, &def->original_module, cme->def->original_module);
1725 ASSERT_vm_locking();
1726 st_insert(overloaded_cme_table(), (st_data_t)cme, (st_data_t)me);
1728 METHOD_ENTRY_VISI_SET(me, METHOD_ENTRY_VISI(cme));
1736 if (UNLIKELY(cme->def->iseq_overload) &&
1737 (vm_ci_flag(ci) & (VM_CALL_ARGS_SIMPLE)) &&
1738 (!(vm_ci_flag(ci) & VM_CALL_FORWARDING)) &&
1739 (
int)vm_ci_argc(ci) == ISEQ_BODY(method_entry_iseqptr(cme))->param.lead_num) {
1740 VM_ASSERT(cme->def->type == VM_METHOD_TYPE_ISEQ,
"type: %d", cme->def->type);
1742 cme = get_overloaded_cme(cme);
1744 VM_ASSERT(cme != NULL);
1753#define CALL_METHOD_HOOK(klass, hook, mid) do { \
1754 const VALUE arg = ID2SYM(mid); \
1755 VALUE recv_class = (klass); \
1756 ID hook_id = (hook); \
1757 if (RCLASS_SINGLETON_P((klass))) { \
1758 recv_class = RCLASS_ATTACHED_OBJECT((klass)); \
1759 hook_id = singleton_##hook; \
1761 rb_funcallv_uncached(recv_class, hook_id, 1, &arg); \
1771 if (me) rb_vm_coverage_record_me(me);
1772 CALL_METHOD_HOOK(klass, added, mid);
1777rb_add_method(
VALUE klass,
ID mid, rb_method_type_t
type,
void *opts, rb_method_visibility_t visi)
1782 method_entry_modify_check(klass,
type);
1785 me = rb_method_entry_make(klass, mid, klass, visi,
type, NULL, mid, opts, &warnings);
1788 method_entry_warnings_emit(&warnings);
1790 if (
type != VM_METHOD_TYPE_UNDEF &&
type != VM_METHOD_TYPE_REFINED) {
1791 method_added(klass, mid, me);
1804 iseq_body.
cref = cref;
1806 rb_add_method(klass, mid, VM_METHOD_TYPE_ISEQ, &iseq_body, visi);
1811 rb_method_visibility_t visi,
VALUE defined_class)
1816 method_entry_modify_check(klass, me->def->type);
1819 newme = rb_method_entry_make(klass, mid, defined_class, visi,
1820 me->def->type, me->def, 0, NULL, &warnings);
1822 me->def->no_redef_warning = TRUE;
1823 METHOD_ENTRY_FLAGS_SET(newme, visi, FALSE);
1827 method_entry_warnings_emit(&warnings);
1829 method_added(klass, mid, newme);
1836 return method_entry_set(klass, mid, me, visi, klass);
1839#define UNDEF_ALLOC_FUNC ((rb_alloc_func_t)-1)
1842propagate_alloc_func(
VALUE subclass,
VALUE arg)
1845 !RCLASS_SINGLETON_P(subclass) &&
1846 !
FL_TEST_RAW(subclass, RCLASS_ALLOCATOR_DEFINED)) {
1848 rb_class_foreach_subclass(subclass, propagate_alloc_func, arg);
1856 if (RCLASS_SINGLETON_P(klass)) {
1857 rb_raise(
rb_eTypeError,
"can't define an allocator for a singleton class");
1859 RCLASS_SET_ALLOCATOR(klass, func);
1861 rb_class_foreach_subclass(klass, propagate_alloc_func, (
VALUE)func);
1868 RCLASS_SET_ALLOCATOR(klass, UNDEF_ALLOC_FUNC);
1870 rb_class_foreach_subclass(klass, propagate_alloc_func, (
VALUE)UNDEF_ALLOC_FUNC);
1876 RBIMPL_ASSERT_TYPE(klass,
T_CLASS);
1879 if (allocator == UNDEF_ALLOC_FUNC)
return 0;
1885rb_method_entry_at(
VALUE klass,
ID id)
1887 return lookup_method_table(klass,
id);
1891search_method0(
VALUE klass,
ID id,
VALUE *defined_class_ptr,
bool skip_refined)
1895 RB_DEBUG_COUNTER_INC(mc_search);
1898 RB_DEBUG_COUNTER_INC(mc_search_super);
1899 if ((me = lookup_method_table(klass,
id)) != 0) {
1900 if (!skip_refined || me->def->type != VM_METHOD_TYPE_REFINED ||
1901 me->def->body.refined.orig_me) {
1907 if (defined_class_ptr) *defined_class_ptr = klass;
1909 if (me == NULL) RB_DEBUG_COUNTER_INC(mc_search_notfound);
1911 VM_ASSERT(me == NULL || !METHOD_ENTRY_INVALIDATED(me),
1912 "invalid me, mid:%s, klass:%"PRIsVALUE
"(%s)",
1915 rb_obj_info(klass));
1920search_method(
VALUE klass,
ID id,
VALUE *defined_class_ptr)
1922 return search_method0(klass,
id, defined_class_ptr,
false);
1926search_method_protect(
VALUE klass,
ID id,
VALUE *defined_class_ptr)
1930 if (!UNDEFINED_METHOD_ENTRY_P(me)) {
1939rb_method_entry(
VALUE klass,
ID id)
1941 return search_method_protect(klass,
id, NULL);
1953 if (me->defined_class == 0) {
1954 RB_DEBUG_COUNTER_INC(mc_cme_complement);
1957 mtbl = RCLASS_WRITABLE_CALLABLE_M_TBL(defined_class);
1958 if (mtbl && rb_id_table_lookup(mtbl,
id, &cme_data)) {
1963 RB_DEBUG_COUNTER_INC(mc_cme_complement_hit);
1964 VM_ASSERT(callable_method_entry_p(cme));
1965 VM_ASSERT(!METHOD_ENTRY_INVALIDATED(cme));
1969 mtbl = rb_id_table_create(0);
1970 RCLASS_WRITE_CALLABLE_M_TBL(defined_class, mtbl);
1972 cme = rb_method_entry_complement_defined_class(me, me->called_id, defined_class);
1973 rb_id_table_insert(mtbl,
id, (
VALUE)cme);
1975 VM_ASSERT(callable_method_entry_p(cme));
1983 VM_ASSERT(callable_method_entry_p(cme));
1984 VM_ASSERT(!METHOD_ENTRY_INVALIDATED(cme));
1997rb_funcallv_uncached(
VALUE recv,
ID mid,
int argc,
const VALUE *argv)
1999 VALUE defined_class;
2002 if (UNLIKELY(UNDEFINED_METHOD_ENTRY_P(me))) {
2008 if (UNLIKELY(me->defined_class == 0)) {
2010 cme = rb_method_entry_complement_defined_class(me, me->called_id, defined_class);
2018 return rb_vm_call_kw(ec, recv, mid, argc, argv, cme,
RB_NO_KEYWORDS);
2022complemented_callable_method_entry(
VALUE klass,
ID id)
2024 VALUE defined_class;
2026 return prepare_callable_method_entry(defined_class,
id, me, FALSE);
2030cached_callable_method_entry(
VALUE klass,
ID mid)
2032 ASSERT_vm_locking();
2034 VALUE cc_tbl = RCLASS_WRITABLE_CC_TBL(klass);
2037 if (cc_tbl && rb_managed_id_table_lookup(cc_tbl, mid, &ccs_data)) {
2039 VM_ASSERT(vm_ccs_p(ccs));
2041 if (LIKELY(!METHOD_ENTRY_INVALIDATED(ccs->cme))) {
2042 VM_ASSERT(ccs->cme->called_id == mid);
2043 RB_DEBUG_COUNTER_INC(ccs_found);
2049 rb_managed_id_table_delete(cc_tbl, mid);
2050 rb_vm_ccs_invalidate_and_free(ccs);
2054 RB_DEBUG_COUNTER_INC(ccs_not_found);
2061 ASSERT_vm_locking();
2062 VM_ASSERT(cme != NULL);
2064 VALUE cc_tbl = RCLASS_WRITABLE_CC_TBL(klass);
2068 cc_tbl = rb_vm_cc_table_create(2);
2069 RCLASS_WRITE_CC_TBL(klass, cc_tbl);
2072 if (rb_managed_id_table_lookup(cc_tbl, mid, &ccs_data)) {
2073#if VM_CHECK_MODE > 0
2075 VM_ASSERT(ccs->cme == cme);
2079 if (rb_multi_ractor_p()) {
2080 VALUE new_cc_tbl = rb_vm_cc_table_dup(cc_tbl);
2081 vm_ccs_create(klass, new_cc_tbl, mid, cme);
2082 RB_OBJ_ATOMIC_WRITE(klass, &RCLASSEXT_CC_TBL(RCLASS_EXT_WRITABLE(klass)), new_cc_tbl);
2085 vm_ccs_create(klass, cc_tbl, mid, cme);
2097 if (rb_id_table_lookup(&vm->negative_cme_table, mid, &cme_data)) {
2102 rb_id_table_insert(&vm->negative_cme_table, mid, (
VALUE)cme);
2105 VM_ASSERT(cme != NULL);
2110callable_method_entry_or_negative(
VALUE klass,
ID mid,
VALUE *defined_class_ptr)
2122 rb_bug(
"attempted to search method '%s' on a garbage collected object",
2129 VALUE cc_tbl = RUBY_ATOMIC_VALUE_LOAD(RCLASS_WRITABLE_CC_TBL(klass));
2132 if (rb_managed_id_table_lookup(cc_tbl, mid, &ccs_data)) {
2134 VM_ASSERT(vm_ccs_p(ccs));
2136 if (LIKELY(!METHOD_ENTRY_INVALIDATED(ccs->cme))) {
2137 VM_ASSERT(ccs->cme->called_id == mid);
2138 if (defined_class_ptr != NULL) *defined_class_ptr = ccs->cme->defined_class;
2139 RB_DEBUG_COUNTER_INC(ccs_found);
2147 cme = cached_callable_method_entry(klass, mid);
2150 if (defined_class_ptr != NULL) *defined_class_ptr = cme->defined_class;
2153 VALUE defined_class;
2155 if (defined_class_ptr) *defined_class_ptr = defined_class;
2158 cme = prepare_callable_method_entry(defined_class, mid, me, TRUE);
2161 cme = negative_cme(mid);
2164 cache_callable_method_entry(klass, mid, cme);
2174rb_callable_method_entry_or_negative(
VALUE klass,
ID mid)
2176 return callable_method_entry_or_negative(klass, mid, NULL);
2180callable_method_entry(
VALUE klass,
ID mid,
VALUE *defined_class_ptr)
2183 cme = callable_method_entry_or_negative(klass, mid, defined_class_ptr);
2184 return !UNDEFINED_METHOD_ENTRY_P(cme) ? cme : NULL;
2188rb_callable_method_entry(
VALUE klass,
ID mid)
2190 return callable_method_entry(klass, mid, NULL);
2196method_entry_resolve_refinement(
VALUE klass,
ID id,
int with_refinement,
VALUE *defined_class_ptr)
2198 const rb_method_entry_t *me = search_method_protect(klass,
id, defined_class_ptr);
2201 if (me->def->type == VM_METHOD_TYPE_REFINED) {
2202 if (with_refinement) {
2204 VALUE refinements = cref ? CREF_REFINEMENTS(cref) :
Qnil;
2205 me = resolve_refined_method(refinements, me, defined_class_ptr);
2208 me = resolve_refined_method(
Qnil, me, defined_class_ptr);
2211 if (UNDEFINED_METHOD_ENTRY_P(me)) me = NULL;
2219rb_method_entry_with_refinements(
VALUE klass,
ID id,
VALUE *defined_class_ptr)
2221 return method_entry_resolve_refinement(klass,
id, TRUE, defined_class_ptr);
2225callable_method_entry_refinements0(
VALUE klass,
ID id,
VALUE *defined_class_ptr,
bool with_refinements,
2228 if (cme == NULL || LIKELY(cme->def->type != VM_METHOD_TYPE_REFINED)) {
2232 VALUE defined_class, *dcp = defined_class_ptr ? defined_class_ptr : &defined_class;
2233 const rb_method_entry_t *me = method_entry_resolve_refinement(klass,
id, with_refinements, dcp);
2234 return prepare_callable_method_entry(*dcp,
id, me, TRUE);
2239callable_method_entry_refinements(
VALUE klass,
ID id,
VALUE *defined_class_ptr,
bool with_refinements)
2242 return callable_method_entry_refinements0(klass,
id, defined_class_ptr, with_refinements, cme);
2246rb_callable_method_entry_with_refinements(
VALUE klass,
ID id,
VALUE *defined_class_ptr)
2248 return callable_method_entry_refinements(klass,
id, defined_class_ptr,
true);
2252callable_method_entry_without_refinements(
VALUE klass,
ID id,
VALUE *defined_class_ptr)
2254 return callable_method_entry_refinements(klass,
id, defined_class_ptr,
false);
2258rb_method_entry_without_refinements(
VALUE klass,
ID id,
VALUE *defined_class_ptr)
2260 return method_entry_resolve_refinement(klass,
id, FALSE, defined_class_ptr);
2264rb_callable_method_entry_without_refinements(
VALUE klass,
ID id,
VALUE *defined_class_ptr)
2266 VALUE defined_class, *dcp = defined_class_ptr ? defined_class_ptr : &defined_class;
2267 const rb_method_entry_t *me = method_entry_resolve_refinement(klass,
id, FALSE, dcp);
2268 return prepare_callable_method_entry(*dcp,
id, me, TRUE);
2274 while (me && me->def->type == VM_METHOD_TYPE_REFINED) {
2279 refinement = find_refinement(refinements, me->owner);
2280 if (!
NIL_P(refinement)) {
2282 refinement = module_refinement_iclass(refinement, *defined_class_ptr);
2284 tmp_me = search_method_protect(refinement, me->called_id, defined_class_ptr);
2286 if (tmp_me && tmp_me->def->type != VM_METHOD_TYPE_REFINED) {
2291 tmp_me = me->def->body.refined.orig_me;
2293 if (!tmp_me->defined_class) {
2294 VM_ASSERT_TYPE(tmp_me->owner,
T_MODULE);
2296 else if (defined_class_ptr) {
2297 *defined_class_ptr = tmp_me->defined_class;
2307 me = search_method_protect(super, me->called_id, defined_class_ptr);
2315 return resolve_refined_method(refinements, me, NULL);
2321 VALUE defined_class = me->defined_class;
2324 if (resolved_me && resolved_me->defined_class == 0) {
2325 return rb_method_entry_complement_defined_class(resolved_me, me->called_id, defined_class);
2333remove_method(
VALUE klass,
ID mid)
2340 klass = RCLASS_ORIGIN(klass);
2341 if (mid == object_id || mid == id__id__ || mid == id__send__ || mid == idInitialize) {
2342 rb_warn(
"removing '%s' may cause serious problems", rb_id2name(mid));
2345 if (!rb_id_table_lookup(RCLASS_M_TBL(klass), mid, &data) ||
2347 (!me->def || me->def->type == VM_METHOD_TYPE_UNDEF) ||
2348 UNDEFINED_REFINED_METHOD_P(me->def)) {
2349 rb_name_err_raise(
"method '%1$s' not defined in %2$s",
2353 if (klass != self) {
2354 rb_clear_method_cache(self, mid);
2356 rb_clear_method_cache(klass, mid);
2357 rb_id_table_delete(RCLASS_WRITABLE_M_TBL(klass), mid);
2359 rb_vm_check_redefinition_opt_method(me, klass);
2361 if (me->def->type == VM_METHOD_TYPE_REFINED) {
2362 rb_add_refined_method_entry(klass, mid);
2365 CALL_METHOD_HOOK(self, removed, mid);
2371 remove_method(klass, mid);
2377 remove_method(klass, rb_intern(name));
2391rb_mod_remove_method(
int argc,
VALUE *argv,
VALUE mod)
2395 for (i = 0; i < argc; i++) {
2399 rb_name_err_raise(
"method '%1$s' not defined in %2$s",
2402 remove_method(mod,
id);
2408rb_export_method(
VALUE klass,
ID name, rb_method_visibility_t visi)
2411 VALUE defined_class;
2412 VALUE origin_class = RCLASS_ORIGIN(klass);
2414 me = search_method0(origin_class, name, &defined_class,
true);
2417 me = search_method(
rb_cObject, name, &defined_class);
2420 if (UNDEFINED_METHOD_ENTRY_P(me) ||
2421 UNDEFINED_REFINED_METHOD_P(me->def)) {
2422 rb_print_undef(klass, name, METHOD_VISI_UNDEF);
2425 if (METHOD_ENTRY_VISI(me) != visi) {
2426 rb_vm_check_redefinition_opt_method(me, klass);
2428 if (klass == defined_class || origin_class == defined_class) {
2429 if (me->def->type == VM_METHOD_TYPE_REFINED) {
2432 if (me->def->body.refined.orig_me) {
2433 METHOD_ENTRY_VISI_SET((
rb_method_entry_t *)me->def->body.refined.orig_me, visi);
2437 METHOD_ENTRY_VISI_SET(me, visi);
2439 rb_clear_method_cache(klass, name);
2442 rb_add_method(klass, name, VM_METHOD_TYPE_ZSUPER, 0, visi);
2447#define BOUND_PRIVATE 0x01
2448#define BOUND_RESPONDS 0x02
2451method_boundp(
VALUE klass,
ID id,
int ex)
2457 if (ex & BOUND_RESPONDS) {
2458 cme = rb_callable_method_entry_with_refinements(klass,
id, NULL);
2461 cme = callable_method_entry_without_refinements(klass,
id, NULL);
2465 if (ex & ~BOUND_RESPONDS) {
2466 switch (METHOD_ENTRY_VISI(cme)) {
2467 case METHOD_VISI_PRIVATE:
2469 case METHOD_VISI_PROTECTED:
2470 if (ex & BOUND_RESPONDS)
return 0;
2476 if (cme->def->type == VM_METHOD_TYPE_NOTIMPLEMENTED) {
2477 if (ex & BOUND_RESPONDS)
return 2;
2489 return method_boundp(klass,
id, ex);
2493vm_cref_set_visibility(rb_method_visibility_t method_visi,
int module_func)
2496 scope_visi->method_visi = method_visi;
2497 scope_visi->module_func = module_func;
2501rb_scope_visibility_set(rb_method_visibility_t visi)
2503 vm_cref_set_visibility(visi, FALSE);
2507scope_visibility_check(
void)
2511 if (cfp && CFP_ISEQ(cfp) && ISEQ_BODY(CFP_ISEQ(cfp))->
type == ISEQ_TYPE_METHOD) {
2512 rb_warn(
"calling %s without arguments inside a method may not have the intended effect",
2513 rb_id2name(rb_frame_this_func()));
2518rb_scope_module_func_set(
void)
2520 scope_visibility_check();
2521 vm_cref_set_visibility(METHOD_VISI_PRIVATE, TRUE);
2529 rb_method_visibility_t visi;
2531 const rb_cref_t *cref = rb_vm_cref_in_context(klass, klass);
2534 visi = METHOD_VISI_PUBLIC;
2537 switch (vm_scope_visibility_get(ec)) {
2538 case METHOD_VISI_PRIVATE:
2539 if (vm_scope_module_func_check(ec)) {
2540 rb_warning(
"attribute accessor as module_function");
2542 visi = METHOD_VISI_PRIVATE;
2544 case METHOD_VISI_PROTECTED:
2545 visi = METHOD_VISI_PROTECTED;
2548 visi = METHOD_VISI_PUBLIC;
2553 attriv = rb_intern_str(rb_sprintf(
"@%"PRIsVALUE, rb_id2str(
id)));
2555 rb_add_method(klass,
id, VM_METHOD_TYPE_IVAR, (
void *)attriv, visi);
2558 rb_add_method(klass, rb_id_attrset(
id), VM_METHOD_TYPE_ATTRSET, (
void *)attriv, visi);
2571 if (
id == object_id ||
id == id__id__ ||
id == id__send__ ||
id == idInitialize) {
2572 rb_warn(
"undefining '%s' may cause serious problems", rb_id2name(
id));
2575 me = search_method(klass,
id, 0);
2576 if (me && me->def->type == VM_METHOD_TYPE_REFINED) {
2577 me = rb_resolve_refined_method(
Qnil, me);
2580 if (UNDEFINED_METHOD_ENTRY_P(me) ||
2581 UNDEFINED_REFINED_METHOD_P(me->def)) {
2582 rb_method_name_error(klass, rb_id2str(
id));
2585 rb_add_method(klass,
id, VM_METHOD_TYPE_UNDEF, 0, METHOD_VISI_PUBLIC);
2587 CALL_METHOD_HOOK(klass, undefined,
id);
2636rb_mod_undef_method(
int argc,
VALUE *argv,
VALUE mod)
2639 for (i = 0; i < argc; i++) {
2643 rb_method_name_error(mod, v);
2650static rb_method_visibility_t
2651check_definition_visibility(
VALUE mod,
VALUE mid,
bool inc_super)
2654 if (!
id)
return METHOD_VISI_UNDEF;
2656 VALUE lookup_mod = inc_super ? mod : RCLASS_ORIGIN(mod);
2658 const rb_method_entry_t *me = rb_method_entry_without_refinements(lookup_mod,
id, NULL);
2660 if (me->def->type == VM_METHOD_TYPE_NOTIMPLEMENTED)
return METHOD_VISI_UNDEF;
2661 if (!inc_super && me->owner != mod)
return METHOD_VISI_UNDEF;
2662 return METHOD_ENTRY_VISI(me);
2664 return METHOD_VISI_UNDEF;
2708rb_mod_method_defined(
int argc,
VALUE *argv,
VALUE mod)
2710 VALUE mid, include_super, include_private;
2712 rb_scan_args(argc, argv,
"12", &mid, &include_super, &include_private);
2714 include_private =
Qfalse;
2716 include_super =
Qtrue;
2720 rb_method_visibility_t visi = check_definition_visibility(mod, mid,
RTEST(include_super));
2722 case METHOD_VISI_UNDEF:
2724 case METHOD_VISI_PUBLIC:
2725 case METHOD_VISI_PROTECTED:
2727 case METHOD_VISI_PRIVATE:
2728 return RBOOL(
RTEST(include_private));
2735check_definition(
VALUE mod,
int argc,
VALUE *argv, rb_method_visibility_t visi)
2737 VALUE mid, include_super;
2740 include_super =
Qtrue;
2742 return RBOOL(check_definition_visibility(mod, mid,
RTEST(include_super)) == visi);
2776rb_mod_public_method_defined(
int argc,
VALUE *argv,
VALUE mod)
2778 return check_definition(mod, argc, argv, METHOD_VISI_PUBLIC);
2812rb_mod_private_method_defined(
int argc,
VALUE *argv,
VALUE mod)
2814 return check_definition(mod, argc, argv, METHOD_VISI_PRIVATE);
2848rb_mod_protected_method_defined(
int argc,
VALUE *argv,
VALUE mod)
2850 return check_definition(mod, argc, argv, METHOD_VISI_PROTECTED);
2856 return rb_method_definition_eq(m1->def, m2->def);
2864 switch (def->type) {
2865 case VM_METHOD_TYPE_REFINED:
2866 if (def->body.refined.orig_me) {
2867 def = def->body.refined.orig_me->def;
2871 case VM_METHOD_TYPE_ALIAS:
2872 def = def->body.alias.original_me->def;
2884 d1 = original_method_definition(d1);
2885 d2 = original_method_definition(d2);
2887 if (d1 == d2)
return 1;
2888 if (!d1 || !d2)
return 0;
2889 if (d1->type != d2->type)
return 0;
2892 case VM_METHOD_TYPE_ISEQ:
2893 return d1->body.iseq.iseqptr == d2->body.iseq.
iseqptr;
2894 case VM_METHOD_TYPE_CFUNC:
2896 d1->body.cfunc.func == d2->body.cfunc.func &&
2897 d1->body.cfunc.argc == d2->body.cfunc.argc;
2898 case VM_METHOD_TYPE_ATTRSET:
2899 case VM_METHOD_TYPE_IVAR:
2900 return d1->body.attr.id == d2->body.attr.id;
2901 case VM_METHOD_TYPE_BMETHOD:
2902 return RTEST(rb_proc_eq(d1->body.bmethod.proc, d2->body.bmethod.proc));
2903 case VM_METHOD_TYPE_MISSING:
2904 return d1->original_id == d2->original_id;
2905 case VM_METHOD_TYPE_ZSUPER:
2906 case VM_METHOD_TYPE_NOTIMPLEMENTED:
2907 case VM_METHOD_TYPE_UNDEF:
2909 case VM_METHOD_TYPE_OPTIMIZED:
2910 return (d1->body.optimized.type == d2->body.optimized.type) &&
2911 (d1->body.optimized.index == d2->body.optimized.index);
2912 case VM_METHOD_TYPE_REFINED:
2913 case VM_METHOD_TYPE_ALIAS:
2916 rb_bug(
"rb_method_definition_eq: unsupported type: %d", d1->type);
2923 def = original_method_definition(def);
2925 if (!def)
return hash;
2927 switch (def->type) {
2928 case VM_METHOD_TYPE_ISEQ:
2930 case VM_METHOD_TYPE_CFUNC:
2931 hash =
rb_hash_uint(hash, (st_index_t)def->body.cfunc.func);
2933 case VM_METHOD_TYPE_ATTRSET:
2934 case VM_METHOD_TYPE_IVAR:
2936 case VM_METHOD_TYPE_BMETHOD:
2937 return rb_hash_proc(hash, def->body.bmethod.proc);
2938 case VM_METHOD_TYPE_MISSING:
2940 case VM_METHOD_TYPE_ZSUPER:
2941 case VM_METHOD_TYPE_NOTIMPLEMENTED:
2942 case VM_METHOD_TYPE_UNDEF:
2944 case VM_METHOD_TYPE_OPTIMIZED:
2947 case VM_METHOD_TYPE_REFINED:
2948 case VM_METHOD_TYPE_ALIAS:
2951 rb_bug(
"rb_hash_method_definition: unsupported method type (%d)", def->type);
2957 return rb_hash_method_definition(hash, me->def);
2961rb_add_alias(
VALUE klass,
ID alias_name,
ID original_name, rb_method_visibility_t visi_alias)
2963 const VALUE target_klass = klass;
2964 VALUE defined_class;
2966 rb_method_visibility_t visi = METHOD_VISI_UNDEF;
2975 orig_me = search_method(klass, original_name, &defined_class);
2977 if (orig_me && orig_me->def->type == VM_METHOD_TYPE_REFINED) {
2978 orig_me = rb_resolve_refined_method(
Qnil, orig_me);
2981 if (UNDEFINED_METHOD_ENTRY_P(orig_me) ||
2982 UNDEFINED_REFINED_METHOD_P(orig_me->def)) {
2984 (orig_me = search_method(
rb_cObject, original_name, &defined_class),
2985 UNDEFINED_METHOD_ENTRY_P(orig_me))) {
2986 rb_print_undef(target_klass, original_name, METHOD_VISI_UNDEF);
2988 rb_warn_scheduled_deprecation(4.2, 4.3,
2989 "the fallback to Object for alias of '%"PRIsVALUE
"' in module '%"PRIsVALUE
"'",
2990 NULL, QUOTE_ID(original_name),
rb_class_path(target_klass));
2993 switch (orig_me->def->type) {
2994 case VM_METHOD_TYPE_ZSUPER:
2996 original_name = orig_me->def->original_id;
2997 visi = METHOD_ENTRY_VISI(orig_me);
2999 case VM_METHOD_TYPE_ALIAS:
3000 visi = METHOD_ENTRY_VISI(orig_me);
3001 orig_me = orig_me->def->body.alias.original_me;
3002 VM_ASSERT(orig_me->def->type != VM_METHOD_TYPE_ALIAS);
3007 if (visi == METHOD_VISI_UNDEF) visi = METHOD_ENTRY_VISI(orig_me);
3008 if (visi_alias != METHOD_VISI_UNDEF) visi = visi_alias;
3011 VALUE owner_class = orig_me->defined_class ? orig_me->defined_class : defined_class;
3012 VALUE origin = RCLASS_ORIGIN(target_klass);
3013 bool in_prepended_module =
false;
3015 if (origin != target_klass) {
3017 if (p == owner_class) {
3018 in_prepended_module =
true;
3023 if (in_prepended_module) {
3024 rb_warn_scheduled_deprecation(4.2, 4.3,
3025 "aliasing %"PRIsVALUE
"#%"PRIsVALUE
" defined in a prepended module %"PRIsVALUE,
3032 if (orig_me->defined_class == 0) {
3036 rb_method_entry_make(target_klass, alias_name, target_klass, visi,
3037 VM_METHOD_TYPE_ALIAS, NULL, orig_me->called_id,
3038 (
void *)rb_method_entry_clone(orig_me), &warnings);
3040 method_entry_warnings_emit(&warnings);
3041 method_added(target_klass, alias_name, alias_me);
3046 alias_me = method_entry_set(target_klass, alias_name, orig_me, visi, orig_me->owner);
3047 RB_OBJ_WRITE(alias_me, &alias_me->owner, target_klass);
3053 RB_OBJ_WRITE(alias_me, &alias_me->defined_class, orig_me->defined_class);
3061 rb_add_alias(klass, alias_name, original_name, METHOD_VISI_UNDEF);
3092 rb_print_undef_str(mod, oldname);
3100check_and_export_method(
VALUE self,
VALUE name, rb_method_visibility_t visi)
3104 rb_print_undef_str(self, name);
3106 rb_export_method(self,
id, visi);
3110set_method_visibility(
VALUE self,
int argc,
const VALUE *argv, rb_method_visibility_t visi)
3116 rb_check_frozen(self);
3117 rb_class_owner_check(self);
3119 rb_warning(
"%"PRIsVALUE
" with no argument is just ignored",
3120 QUOTE_ID(rb_frame_callee()));
3131 check_and_export_method(self,
RARRAY_AREF(v, j), visi);
3135 for (i = 0; i < argc; i++) {
3136 check_and_export_method(self, argv[i], visi);
3142set_visibility(
int argc,
const VALUE *argv,
VALUE module, rb_method_visibility_t visi)
3145 scope_visibility_check();
3146 rb_scope_visibility_set(visi);
3150 set_method_visibility(module, argc, argv, visi);
3175rb_mod_public(
int argc,
VALUE *argv,
VALUE module)
3177 return set_visibility(argc, argv, module, METHOD_VISI_PUBLIC);
3239rb_mod_protected(
int argc,
VALUE *argv,
VALUE module)
3241 return set_visibility(argc, argv, module, METHOD_VISI_PROTECTED);
3273rb_mod_private(
int argc,
VALUE *argv,
VALUE module)
3275 return set_visibility(argc, argv, module, METHOD_VISI_PRIVATE);
3306rb_mod_ruby2_keywords(
int argc,
VALUE *argv,
VALUE module)
3309 VALUE origin_class = RCLASS_ORIGIN(module);
3312 rb_check_frozen(module);
3313 rb_class_owner_check(module);
3315 for (i = 0; i < argc; i++) {
3319 VALUE defined_class;
3322 rb_print_undef_str(module, v);
3325 me = search_method(origin_class, name, &defined_class);
3327 me = search_method(
rb_cObject, name, &defined_class);
3330 if (UNDEFINED_METHOD_ENTRY_P(me) ||
3331 UNDEFINED_REFINED_METHOD_P(me->def)) {
3332 rb_print_undef(module, name, METHOD_VISI_UNDEF);
3335 if (module == defined_class || origin_class == defined_class) {
3336 switch (me->def->type) {
3337 case VM_METHOD_TYPE_ISEQ:
3338 if (ISEQ_BODY(me->def->body.iseq.
iseqptr)->param.flags.has_rest &&
3339 !ISEQ_BODY(me->def->body.iseq.
iseqptr)->param.flags.has_post &&
3340 !ISEQ_BODY(me->def->body.iseq.
iseqptr)->param.flags.has_kw &&
3341 !ISEQ_BODY(me->def->body.iseq.
iseqptr)->param.flags.has_kwrest) {
3342 ISEQ_BODY(me->def->body.iseq.
iseqptr)->param.flags.ruby2_keywords = 1;
3343 rb_clear_method_cache(module, name);
3346 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));
3349 case VM_METHOD_TYPE_BMETHOD: {
3350 VALUE procval = me->def->body.bmethod.proc;
3351 if (vm_block_handler_type(procval) == block_handler_type_proc) {
3352 procval = vm_proc_to_block_handler(VM_BH_TO_PROC(procval));
3355 if (vm_block_handler_type(procval) == block_handler_type_iseq) {
3357 const rb_iseq_t *iseq = rb_iseq_check(captured->code.iseq);
3358 if (ISEQ_BODY(iseq)->param.flags.has_rest &&
3359 !ISEQ_BODY(iseq)->param.flags.has_post &&
3360 !ISEQ_BODY(iseq)->param.flags.has_kw &&
3361 !ISEQ_BODY(iseq)->param.flags.has_kwrest) {
3362 ISEQ_BODY(iseq)->param.flags.ruby2_keywords = 1;
3363 rb_clear_method_cache(module, name);
3366 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));
3373 rb_warn(
"Skipping set of ruby2_keywords flag for %"PRIsVALUE
" (method not defined in Ruby)", QUOTE_ID(name));
3378 rb_warn(
"Skipping set of ruby2_keywords flag for %"PRIsVALUE
" (can only set in method defining module)", QUOTE_ID(name));
3397rb_mod_public_method(
int argc,
VALUE *argv,
VALUE obj)
3425rb_mod_private_method(
int argc,
VALUE *argv,
VALUE obj)
3449 return rb_mod_public(argc, argv, rb_top_main_class(
"public"));
3469 return rb_mod_private(argc, argv, rb_top_main_class(
"private"));
3486top_ruby2_keywords(
int argc,
VALUE *argv,
VALUE module)
3488 return rb_mod_ruby2_keywords(argc, argv, rb_top_main_class(
"ruby2_keywords"));
3544rb_mod_modfunc(
int argc,
VALUE *argv,
VALUE module)
3551 rb_raise(
rb_eTypeError,
"module_function must be called for modules");
3555 rb_scope_module_func_set();
3559 set_method_visibility(module, argc, argv, METHOD_VISI_PRIVATE);
3561 for (i = 0; i < argc; i++) {
3566 me = search_method(m,
id, 0);
3570 if (UNDEFINED_METHOD_ENTRY_P(me)) {
3571 rb_print_undef(module,
id, METHOD_VISI_UNDEF);
3573 if (me->def->type != VM_METHOD_TYPE_ZSUPER) {
3589#pragma push_macro("rb_method_basic_definition_p")
3590#undef rb_method_basic_definition_p
3596 if (!klass)
return TRUE;
3597 cme = rb_callable_method_entry(klass,
id);
3598 return (cme && METHOD_ENTRY_BASIC(cme)) ? TRUE : FALSE;
3601#pragma pop_macro("rb_method_basic_definition_p")
3608 VALUE passed_block_handler = vm_passed_block_handler(ec);
3609 VALUE result = rb_vm_call_kw(ec, obj,
id, argc, argv, cme, kw_splat);
3610 vm_passed_block_handler_set(ec, passed_block_handler);
3618 VALUE defined_class, args[2];
3619 const ID rtmid = idRespond_to_missing;
3622 if (!cme || METHOD_ENTRY_BASIC(cme))
return Qundef;
3625 return call_method_entry(ec, defined_class, obj, rtmid, cme, 2, args,
RB_NO_KEYWORDS);
3634 switch (method_boundp(klass,
id, pub|BOUND_RESPONDS)) {
3638 ret = basic_obj_respond_to_missing(ec, klass, obj,
ID2SYM(
id),
3640 return RTEST(ret) && !UNDEF_P(ret);
3649 VALUE defined_class;
3650 const ID resid = idRespond_to;
3653 if (!cme)
return -1;
3654 if (METHOD_ENTRY_BASIC(cme)) {
3667 rb_raise(rb_eArgError,
3668 "respond_to? must accept 1 or 2 arguments (requires %d)",
3677 "%"PRIsVALUE
"%c""respond_to?(:%"PRIsVALUE
") uses"
3678 " the deprecated method signature, which takes one parameter",
3679 (RCLASS_SINGLETON_P(klass) ? obj : klass),
3680 (RCLASS_SINGLETON_P(klass) ?
'.' :
'#'),
3682 if (!
NIL_P(location)) {
3687 RSTRING_PTR(path),
NUM2INT(line),
3688 "respond_to? is defined here");
3693 result = call_method_entry(ec, defined_class, obj, resid, cme, argc, args,
RB_NO_KEYWORDS);
3694 return RTEST(result);
3702 return rb_ec_obj_respond_to(ec, obj,
id, priv);
3709 int ret = vm_respond_to(ec, klass, obj,
id, priv);
3710 if (ret == -1) ret = basic_obj_respond_to(ec, obj,
id, !priv);
3742obj_respond_to(
int argc,
VALUE *argv,
VALUE obj)
3750 VALUE ret = basic_obj_respond_to_missing(ec,
CLASS_OF(obj), obj,
3752 if (UNDEF_P(ret)) ret =
Qfalse;
3755 return RBOOL(basic_obj_respond_to(ec, obj,
id, !
RTEST(priv)));
3780Init_eval_method(
void)
3802 "public", top_public, -1);
3804 "private", top_private, -1);
3806 "ruby2_keywords", top_ruby2_keywords, -1);
3809#define REPLICATE_METHOD(klass, id) do { \
3810 const rb_method_entry_t *me = rb_method_entry((klass), (id)); \
3811 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 SPECIAL_CONST_P
Old name of RB_SPECIAL_CONST_P.
#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_NONE
Old name of RUBY_T_NONE.
#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_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.
#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_funcallv(VALUE recv, ID mid, int argc, const VALUE *argv)
Identical to rb_funcall(), except it takes the method arguments as a C array.
VALUE rb_call_super_kw(int argc, const VALUE *argv, int kw_splat)
Identical to rb_call_super(), except you can specify how to handle the last element of the given arra...
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_hidden_new(rb_len_t capa)
Allocates a hidden (no class) empty array.
VALUE rb_ary_push(VALUE ary, VALUE elem)
Special case of rb_ary_cat() that it adds only one element.
VALUE rb_ary_freeze(VALUE obj)
Freeze an array, preventing further modifications.
VALUE rb_ary_new_from_values(rb_len_t n, const VALUE *elts)
Identical to rb_ary_new_from_args(), except how objects are passed.
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.
#define rb_str_new_lit(str)
Identical to rb_str_new_static(), except it cannot take string variables.
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.
VALUE rb_class_path(VALUE mod)
Identical to rb_mod_name(), except it returns #<Class: ...> style inspection for anonymous modules.
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.
int rb_method_basic_definition_p(VALUE klass, ID mid)
Well... Let us hesitate from describing what a "basic definition" is.
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.
int len
Length of the buffer.
#define RB_OBJ_SET_SHAREABLE(obj)
Wrapper of rb_obj_set_shareable().
#define RB_GC_GUARD(v)
Prevents premature destruction of local objects.
VALUE type(ANYARGS)
ANYARGS-ed function type.
diagnostic_range warnings(const pm_parser_t *parser PRISM_LIFETIMEBOUND) noexcept
The warnings found while parsing.
#define RARRAY_LEN
Just another name of rb_array_len.
#define RARRAY_AREF(a, i)
References an object in an array.
#define RBASIC(obj)
Convenient casting macro.
#define RCLASS_SUPER
Just another name of rb_class_get_superclass.
#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_PASS_CALLED_KEYWORDS
Pass keywords if current method is called with keywords, useful for argument delegation.
#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.
const char * wrap_struct_name
Name of structs of this kind.
struct rb_data_type_struct::@63 function
Function pointers.
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
long rb_len_t
A signed integer type for lengths and indices of objects such as String and Array.
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
uintptr_t VALUE
Type that represents a Ruby object.
static enum ruby_value_type RB_BUILTIN_TYPE(VALUE obj)
Queries the type of the object.
static void Check_Type(VALUE v, enum ruby_value_type t)
Identical to RB_TYPE_P(), except it raises exceptions on predication failure.
static bool RB_TYPE_P(VALUE obj, enum ruby_value_type t)
Queries if the given object is of given type.