10static int vm_redefinition_check_flag(
VALUE klass);
11static void rb_vm_check_redefinition_opt_method(
const rb_method_entry_t *me,
VALUE klass,
VALUE *perf_warnings);
12static void vm_warn_redefinition_opt_method(
const rb_method_entry_t *me);
13static inline rb_method_entry_t *lookup_method_table(
VALUE klass,
ID id);
15#define object_id idObject_id
16#define added idMethod_added
17#define singleton_added idSingleton_method_added
18#define removed idMethod_removed
19#define singleton_removed idSingleton_method_removed
20#define undefined idMethod_undefined
21#define singleton_undefined idSingleton_method_undefined
23#define ruby_running (GET_VM()->running)
26static enum rb_id_table_iterator_result
27mark_cc_entry_i(
VALUE ccs_ptr,
void *data)
31 VM_ASSERT(vm_ccs_p(ccs));
33 if (METHOD_ENTRY_INVALIDATED(ccs->cme)) {
37 rb_gc_mark_movable((
VALUE)ccs->cme);
38 for (
int i = 0; i < ccs->len; i++) {
39 rb_gc_mark_movable((
VALUE)ccs->entries[i].cc);
41 return ID_TABLE_CONTINUE;
44 rb_gc_mark_movable((
VALUE)ccs->cme);
46 for (
int i = 0; i < ccs->len; i++) {
48 VM_ASSERT(cc->klass ==
Qundef || vm_cc_check_cme(cc, ccs->cme));
50 rb_gc_mark_movable((
VALUE)cc);
52 return ID_TABLE_CONTINUE;
57vm_cc_table_mark(
void *data)
61 rb_id_table_foreach_values(tbl, mark_cc_entry_i, NULL);
65static enum rb_id_table_iterator_result
66cc_table_free_i(
VALUE ccs_ptr,
void *data)
69 VM_ASSERT(vm_ccs_p(ccs));
71 ruby_xfree_sized(ccs, vm_ccs_alloc_size(ccs->capa));
73 return ID_TABLE_CONTINUE;
77vm_cc_table_free(
void *data)
81 rb_id_table_foreach_values(tbl, cc_table_free_i, NULL);
82 rb_managed_id_table_type.function.dfree(data);
85static enum rb_id_table_iterator_result
86cc_table_memsize_i(
VALUE ccs_ptr,
void *data_ptr)
88 size_t *total_size = data_ptr;
90 *total_size +=
sizeof(*ccs);
91 *total_size +=
sizeof(ccs->entries[0]) * ccs->capa;
92 return ID_TABLE_CONTINUE;
96vm_cc_table_memsize(
const void *data)
98 size_t memsize = rb_managed_id_table_type.function.dsize(data);
100 rb_id_table_foreach_values(tbl, cc_table_memsize_i, &memsize);
104static enum rb_id_table_iterator_result
105compact_cc_entry_i(
VALUE ccs_ptr,
void *data)
109 rb_gc_update_moved_ptr(&ccs->cme);
110 VM_ASSERT(vm_ccs_p(ccs));
112 for (
int i=0; i<ccs->len; i++) {
113 rb_gc_update_moved_ptr(&ccs->entries[i].cc);
116 return ID_TABLE_CONTINUE;
120vm_cc_table_compact(
void *data)
123 rb_id_table_foreach_values(tbl, compact_cc_entry_i, NULL);
127 .wrap_struct_name =
"VM/cc_table",
129 .dmark = vm_cc_table_mark,
130 .dfree = vm_cc_table_free,
131 .dsize = vm_cc_table_memsize,
132 .dcompact = vm_cc_table_compact,
134 .parent = &rb_managed_id_table_type,
135 .flags = RUBY_TYPED_THREAD_SAFE_FREE | RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_EMBEDDABLE,
139rb_vm_cc_table_create(
size_t capa)
141 return rb_managed_id_table_create(&cc_table_type,
capa);
146static enum rb_id_table_iterator_result
147vm_cc_table_dup_i(
ID key,
VALUE old_ccs_ptr,
void *data)
152 if (METHOD_ENTRY_INVALIDATED(old_ccs->cme)) {
159 vm_ccs_invalidate(old_ccs);
160 return ID_TABLE_CONTINUE;
163 size_t memsize = vm_ccs_alloc_size(old_ccs->capa);
165 rb_managed_id_table_insert(new_table, key, (
VALUE)new_ccs);
169 VM_ASSERT(!METHOD_ENTRY_INVALIDATED(old_ccs->cme));
171 memcpy(new_ccs, old_ccs, memsize);
174 new_ccs->debug_sig = ~(
VALUE)new_ccs;
178 for (
int index = 0; index < new_ccs->len; index++) {
181 return ID_TABLE_CONTINUE;
185rb_vm_cc_table_dup(
VALUE old_table)
188 VALUE new_table = rb_vm_cc_table_create(rb_managed_id_table_size(old_table));
189 rb_managed_id_table_foreach(old_table, vm_cc_table_dup_i, (
void *)new_table);
196 for (
int i=0; i<ccs->len; i++) {
198 if (cc->klass ==
Qundef)
continue;
199 VM_ASSERT(!vm_cc_super_p(cc) && !vm_cc_refinement_p(cc));
200 vm_cc_invalidate(cc);
207 RB_DEBUG_COUNTER_INC(ccs_free);
208 vm_ccs_invalidate(ccs);
209 ruby_xfree_sized(ccs, vm_ccs_alloc_size(ccs->capa));
213rb_vm_cc_table_delete(
VALUE table,
ID mid)
216 if (rb_managed_id_table_lookup(table, mid, &ccs_obj)) {
218 rb_managed_id_table_delete(table, mid);
219 rb_vm_ccs_invalidate_and_free(ccs);
223static enum rb_id_table_iterator_result
224vm_ccs_dump_i(
ID mid,
VALUE val,
void *data)
227 fprintf(stderr,
" | %s (len:%d) ", rb_id2name(mid), ccs->len);
230 for (
int i=0; i<ccs->len; i++) {
231 rp_m(
" | \t", ccs->entries[i].cc);
234 return ID_TABLE_CONTINUE;
238vm_ccs_dump(
VALUE klass,
ID target_mid)
240 VALUE cc_tbl = RCLASS_WRITABLE_CC_TBL(klass);
244 if (rb_managed_id_table_lookup(cc_tbl, target_mid, &ccs)) {
245 fprintf(stderr,
" [CCTB] %p\n", (
void *)cc_tbl);
246 vm_ccs_dump_i(target_mid, ccs, NULL);
250 fprintf(stderr,
" [CCTB] %p\n", (
void *)cc_tbl);
251 rb_managed_id_table_foreach(cc_tbl, vm_ccs_dump_i, (
void *)target_mid);
256static enum rb_id_table_iterator_result
257vm_cme_dump_i(
ID mid,
VALUE val,
void *data)
259 ID target_mid = (
ID)data;
260 if (target_mid == 0 || mid == target_mid) {
263 return ID_TABLE_CONTINUE;
267vm_mtbl_dump(
VALUE klass,
ID target_mid)
269 fprintf(stderr,
"# vm_mtbl\n");
274 if (RCLASS_M_TBL(klass)) {
275 if (target_mid != 0) {
276 if (rb_id_table_lookup(RCLASS_M_TBL(klass), target_mid, &me)) {
277 rp_m(
" [MTBL] ", me);
281 fprintf(stderr,
" ## RCLASS_M_TBL (%p)\n", (
void *)RCLASS_M_TBL(klass));
282 rb_id_table_foreach(RCLASS_M_TBL(klass), vm_cme_dump_i, NULL);
286 fprintf(stderr,
" MTBL: NULL\n");
288 if (RCLASS_WRITABLE_CALLABLE_M_TBL(klass)) {
289 if (target_mid != 0) {
290 if (rb_id_table_lookup(RCLASS_WRITABLE_CALLABLE_M_TBL(klass), target_mid, &me)) {
291 rp_m(
" [CM**] ", me);
295 fprintf(stderr,
" ## RCLASS_CALLABLE_M_TBL\n");
296 rb_id_table_foreach(RCLASS_WRITABLE_CALLABLE_M_TBL(klass), vm_cme_dump_i, NULL);
299 if (RCLASS_WRITABLE_CC_TBL(klass)) {
300 vm_ccs_dump(klass, target_mid);
308rb_vm_mtbl_dump(
const char *msg,
VALUE klass,
ID target_mid)
310 fprintf(stderr,
"[%s] ", msg);
311 vm_mtbl_dump(klass, target_mid);
315vm_cme_invalidate(rb_callable_method_entry_t *cme)
317 VM_ASSERT(IMEMO_TYPE_P(cme, imemo_ment),
"cme: %d", imemo_type((
VALUE)cme));
318 VM_ASSERT(callable_method_entry_p(cme));
319 METHOD_ENTRY_INVALIDATED_SET(cme);
320 RB_DEBUG_COUNTER_INC(cc_cme_invalidate);
322 rb_yjit_cme_invalidate(cme);
323 rb_zjit_cme_invalidate(cme);
327rb_clear_constant_cache_for_id_i(st_data_t ic, st_data_t arg)
329 ((IC) ic)->entry = NULL;
337 rb_vm_t *vm = GET_VM();
339 if (rb_id_table_lookup(&vm->constant_cache,
id, &lookup_result)) {
341 set_table_foreach(ics, rb_clear_constant_cache_for_id_i, (st_data_t) NULL);
342 ruby_vm_constant_cache_invalidations += ics->num_entries;
345 rb_yjit_constant_state_changed(
id);
346 rb_zjit_constant_state_changed(
id);
350invalidate_negative_cache(
ID mid)
353 rb_vm_t *vm = GET_VM();
355 if (rb_id_table_lookup(&vm->negative_cme_table, mid, &cme)) {
356 rb_id_table_delete(&vm->negative_cme_table, mid);
357 vm_cme_invalidate((rb_callable_method_entry_t *)cme);
358 RB_DEBUG_COUNTER_INC(cc_invalidate_negative);
362const rb_method_entry_t * rb_method_entry_clone(
const rb_method_entry_t *src_me);
363static const rb_callable_method_entry_t *complemented_callable_method_entry(
VALUE klass,
ID id);
364static const rb_callable_method_entry_t *lookup_overloaded_cme(
const rb_callable_method_entry_t *cme);
367invalidate_method_cache_in_cc_table(
VALUE tbl,
ID mid)
370 if (tbl && rb_managed_id_table_lookup(tbl, mid, &ccs_data)) {
372 rb_yjit_cme_invalidate((rb_callable_method_entry_t *)ccs->cme);
373 rb_zjit_cme_invalidate((rb_callable_method_entry_t *)ccs->cme);
374 if (
NIL_P(ccs->cme->owner)) invalidate_negative_cache(mid);
375 rb_vm_ccs_invalidate_and_free(ccs);
376 rb_managed_id_table_delete(tbl, mid);
377 RB_DEBUG_COUNTER_INC(cc_invalidate_leaf_ccs);
382invalidate_callable_method_entry_in_callable_m_table(
struct rb_id_table *tbl,
ID mid)
385 if (tbl && rb_id_table_lookup(tbl, mid, &cme)) {
386 rb_yjit_cme_invalidate((rb_callable_method_entry_t *)cme);
387 rb_zjit_cme_invalidate((rb_callable_method_entry_t *)cme);
388 rb_id_table_delete(tbl, mid);
389 RB_DEBUG_COUNTER_INC(cc_invalidate_leaf_callable);
396 const rb_method_entry_t *cme;
397 const rb_method_entry_t *newer;
401invalidate_callable_method_entry_in_every_m_table_i(rb_classext_t *ext,
bool is_prime,
VALUE box_value,
void *data)
407 if (rb_id_table_lookup(tbl, arg->mid, &me) && arg->cme == (
const rb_method_entry_t *)me) {
408 rb_method_table_insert(arg->klass, tbl, arg->mid, arg->newer);
414 VALUE klass_housing_cme;
419collect_per_box_origins_i(rb_classext_t *ext,
bool is_prime,
VALUE box_value,
void *data)
422 VALUE origin = RCLASSEXT_ORIGIN(ext);
424 if (origin == arg->owner || origin == arg->klass_housing_cme) {
437invalidate_callable_method_entry_in_every_m_table(
VALUE klass,
ID mid,
const rb_callable_method_entry_t *cme)
440 const rb_method_entry_t *newer = rb_method_entry_clone((
const rb_method_entry_t *)cme);
444 .cme = (
const rb_method_entry_t *) cme,
447 rb_class_classext_foreach(klass, invalidate_callable_method_entry_in_every_m_table_i, (
void *)&arg);
451invalidate_complemented_method_entry_in_callable_m_table(
struct rb_id_table *tbl,
ID mid)
454 if (tbl && rb_id_table_lookup(tbl, mid, &cme)) {
455 rb_yjit_cme_invalidate((rb_callable_method_entry_t *)cme);
456 rb_zjit_cme_invalidate((rb_callable_method_entry_t *)cme);
457 rb_id_table_delete(tbl, mid);
458 RB_DEBUG_COUNTER_INC(cc_invalidate_tree_callable);
463clear_method_cache_by_id_in_class(
VALUE klass,
ID mid)
466 if (rb_objspace_garbage_object_p(klass))
return;
471 if (LIKELY(!RCLASS_SUBCLASSES(klass)) &&
481 VALUE cc_tbl = RCLASS_WRITABLE_CC_TBL(klass);
482 invalidate_method_cache_in_cc_table(cc_tbl, mid);
483 if (RCLASS_CC_TBL_NOT_PRIME_P(klass, cc_tbl)) {
484 invalidate_method_cache_in_cc_table(RCLASS_PRIME_CC_TBL(klass), mid);
488 struct rb_id_table *cm_tbl = RCLASS_WRITABLE_CALLABLE_M_TBL(klass);
489 invalidate_callable_method_entry_in_callable_m_table(cm_tbl, mid);
490 if (RCLASS_CALLABLE_M_TBL_NOT_PRIME_P(klass, cm_tbl)) {
491 invalidate_callable_method_entry_in_callable_m_table(RCLASS_PRIME_CALLABLE_M_TBL(klass), mid);
494 RB_DEBUG_COUNTER_INC(cc_invalidate_leaf);
497 const rb_callable_method_entry_t *cme = complemented_callable_method_entry(klass, mid);
501 if (METHOD_ENTRY_CACHED(cme)) {
502 if (METHOD_ENTRY_COMPLEMENTED(cme)) {
507 VALUE owner = cme->owner;
508 VM_ASSERT_TYPE(owner,
T_CLASS);
509 VALUE klass_housing_cme;
510 if (cme->def->type == VM_METHOD_TYPE_REFINED && !cme->def->body.refined.orig_me) {
511 klass_housing_cme = owner;
514 klass_housing_cme = RCLASS_ORIGIN(owner);
518 invalidate_callable_method_entry_in_every_m_table(klass_housing_cme, mid, cme);
521 if (klass_housing_cme != owner) {
522 invalidate_callable_method_entry_in_every_m_table(owner, mid, cme);
533 .klass_housing_cme = klass_housing_cme,
536 rb_class_classext_foreach(owner, collect_per_box_origins_i, &origins_arg);
538 invalidate_callable_method_entry_in_every_m_table(
RARRAY_AREF(origins, i), mid, cme);
544 vm_cme_invalidate((rb_callable_method_entry_t *)cme);
545 RB_DEBUG_COUNTER_INC(cc_invalidate_tree_cme);
550 if (cme->def->type == VM_METHOD_TYPE_REFINED && cme->def->body.refined.orig_me) {
551 vm_cme_invalidate((rb_callable_method_entry_t *)cme->def->body.refined.orig_me);
554 if (cme->def->iseq_overload) {
555 rb_callable_method_entry_t *monly_cme = (rb_callable_method_entry_t *)lookup_overloaded_cme(cme);
557 vm_cme_invalidate(monly_cme);
563 if (METHOD_ENTRY_COMPLEMENTED(cme)) {
564 VALUE defined_class = cme->defined_class;
565 struct rb_id_table *cm_tbl = RCLASS_WRITABLE_CALLABLE_M_TBL(defined_class);
566 invalidate_complemented_method_entry_in_callable_m_table(cm_tbl, mid);
567 if (RCLASS_CALLABLE_M_TBL_NOT_PRIME_P(defined_class, cm_tbl)) {
568 struct rb_id_table *prime_cm_table = RCLASS_PRIME_CALLABLE_M_TBL(defined_class);
569 invalidate_complemented_method_entry_in_callable_m_table(prime_cm_table, mid);
573 RB_DEBUG_COUNTER_INC(cc_invalidate_tree);
576 invalidate_negative_cache(mid);
580 rb_gccct_clear_table();
585clear_iclass_method_cache_by_id(
VALUE iclass,
VALUE d)
589 clear_method_cache_by_id_in_class(iclass, mid);
593clear_iclass_method_cache_by_id_for_refinements(
VALUE klass,
VALUE d)
597 clear_method_cache_by_id_in_class(klass, mid);
602rb_clear_method_cache(
VALUE klass_or_module,
ID mid)
605 VALUE module = klass_or_module;
607 if (
FL_TEST(module, RMODULE_IS_REFINEMENT)) {
608 VALUE refined_class = rb_refinement_module_get_refined_class(module);
609 rb_clear_method_cache(refined_class, mid);
610 rb_class_foreach_subclass(refined_class, clear_iclass_method_cache_by_id_for_refinements, mid);
611 rb_clear_all_refinement_method_cache();
613 rb_class_foreach_subclass(module, clear_iclass_method_cache_by_id, mid);
616 clear_method_cache_by_id_in_class(klass_or_module, mid);
620static enum rb_id_table_iterator_result
621invalidate_method_entry_in_iclass_callable_m_tbl(
VALUE cme,
void *data)
623 vm_cme_invalidate((rb_callable_method_entry_t *)cme);
624 return ID_TABLE_DELETE;
627static enum rb_id_table_iterator_result
628invalidate_ccs_in_iclass_cc_tbl(
VALUE value,
void *data)
631 vm_cme_invalidate((rb_callable_method_entry_t *)ccs->cme);
632 ruby_xfree_sized(ccs, vm_ccs_alloc_size(ccs->capa));
633 return ID_TABLE_DELETE;
640 rb_id_table_foreach_values(cm_tbl, invalidate_method_entry_in_iclass_callable_m_tbl, NULL);
643 rb_managed_id_table_foreach_values(cc_tbl, invalidate_ccs_in_iclass_cc_tbl, NULL);
656 for (
int i = 0; i < ci->kwarg->keyword_len; i++) {
668 if (ci1->mid != ci2->mid)
return 1;
669 if (ci1->flag != ci2->flag)
return 1;
670 if (ci1->argc != ci2->argc)
return 1;
671 if (ci1->kwarg != NULL) {
672 VM_ASSERT(ci2->kwarg != NULL);
674 if (ci1->kwarg->keyword_len != ci2->kwarg->keyword_len)
677 for (
int i = 0; i < ci1->kwarg->keyword_len; i++) {
678 if (ci1->kwarg->keywords[i] != ci2->kwarg->keywords[i]) {
684 VM_ASSERT(ci2->kwarg == NULL);
689static const struct st_hash_type vm_ci_hashtype = {
695ci_lookup_i(st_data_t *key, st_data_t *value, st_data_t data,
int existing)
698 st_data_t *ret = (st_data_t *)data;
701 if (rb_objspace_garbage_object_p((
VALUE)ci)) {
702 *ret = (st_data_t)NULL;
711 *key = *value = *ret = (st_data_t)ci;
717rb_vm_ci_lookup(
ID mid,
unsigned int flag,
unsigned int argc,
const struct rb_callinfo_kwarg *kwarg)
719 rb_vm_t *vm = GET_VM();
732 st_table *ci_table = &vm->ci_table;
735 st_update(ci_table, (st_data_t)new_ci, ci_lookup_i, (st_data_t)&ci);
736 }
while (ci == NULL);
749 rb_vm_t *vm = GET_VM();
751 st_data_t key = (st_data_t)ci;
752 st_delete(&vm->ci_table, &key, NULL);
762cc_refinement_set_free(
void *ptr)
769cc_refinement_set_memsize(
const void *ptr)
772 return e->capa *
sizeof(
VALUE);
776cc_refinement_set_compact(
void *ptr)
779 for (
size_t i = 0; i < e->len; i++) {
780 rb_gc_update_moved(&e->entries[i]);
785cc_refinement_set_handle_weak_references(
void *ptr,
void *
objspace)
791 if (!rb_gc_during_global_gc_p() && !rb_gc_single_objspace_p())
return;
794 for (
size_t read = 0; read < e->len; read++) {
795 if (rb_gc_handle_weak_references_alive_p(
objspace, e->entries[read])) {
796 e->entries[write++] = e->entries[read];
803 "VM/cc_refinement_set",
806 cc_refinement_set_free,
807 cc_refinement_set_memsize,
808 cc_refinement_set_compact,
809 cc_refinement_set_handle_weak_references,
811 0, 0, RUBY_TYPED_THREAD_SAFE_FREE | RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_EMBEDDABLE
815rb_cc_refinement_set_create(
void)
824 rb_gc_declare_weak_references(obj);
826 rb_gc_obj_became_shareable(obj);
832rb_vm_insert_cc_refinement(
const struct rb_callcache *cc)
834 rb_vm_t *vm = GET_VM();
837 VALUE set = vm->cc_refinement_set;
839 if (e->len == e->capa) {
840 size_t new_capa = e->capa == 0 ? 16 : e->capa * 2;
841 SIZED_REALLOC_N(e->entries,
VALUE, new_capa, e->capa);
844 e->entries[e->len++] = (
VALUE)cc;
856rb_clear_all_refinement_method_cache(
void)
858 rb_vm_t *vm = GET_VM();
863 for (
size_t i = 0; i < e->len; i++) {
864 VALUE v = e->entries[i];
868 VM_ASSERT(!rb_objspace_garbage_object_p(v));
871 VM_ASSERT(vm_cc_refinement_p(cc));
873 if (vm_cc_valid(cc)) {
874 vm_cc_invalidate(cc);
881 rb_yjit_invalidate_all_method_lookup_assumptions();
885rb_method_table_insert(
VALUE klass,
struct rb_id_table *table,
ID method_id,
const rb_method_entry_t *me)
888 rb_method_table_insert0(klass, table, method_id, me,
RB_TYPE_P(klass,
T_ICLASS) && !RICLASS_OWNS_M_TBL_P(klass));
893rb_method_table_insert0(
VALUE klass,
struct rb_id_table *table,
ID method_id,
const rb_method_entry_t *me,
bool iclass_shared_mtbl)
895 VALUE table_owner = klass;
896 if (iclass_shared_mtbl) {
897 table_owner =
RBASIC(table_owner)->klass;
900 rb_id_table_insert(table, method_id, (
VALUE)me);
909NORETURN(
static VALUE rb_f_notimplement_internal(
int argc,
const VALUE *argv,
VALUE obj));
912rb_f_notimplement_internal(
int argc,
const VALUE *argv,
VALUE obj)
922 rb_f_notimplement_internal(argc, argv, obj);
926rb_define_notimplement_method_id(
VALUE mod,
ID id, rb_method_visibility_t visi)
928 rb_add_method(mod,
id, VM_METHOD_TYPE_NOTIMPLEMENTED, (
void *)1, visi);
932rb_add_method_cfunc(
VALUE klass,
ID mid,
VALUE (*func)(
ANYARGS),
int argc, rb_method_visibility_t visi)
934 if (argc < -2 || 15 < argc) rb_raise(rb_eArgError,
"arity out of range: %d for -2..15", argc);
936 rb_method_cfunc_t opt;
939 rb_add_method(klass, mid, VM_METHOD_TYPE_CFUNC, &opt, visi);
942 rb_define_notimplement_method_id(klass, mid, visi);
947rb_add_method_optimized(
VALUE klass,
ID mid,
enum method_optimized_type opt_type,
unsigned int index, rb_method_visibility_t visi)
949 rb_method_optimized_t opt = {
953 rb_add_method(klass, mid, VM_METHOD_TYPE_OPTIMIZED, &opt, visi);
957method_definition_release(rb_method_definition_t *def)
964 if (reference_count_was == 1) {
965 if (METHOD_DEBUG) fprintf(stderr,
"-%p-%s:1->0 (remove)\n", (
void *)def,
966 rb_id2name(def->original_id));
970 if (METHOD_DEBUG) fprintf(stderr,
"-%p-%s:%d->%d (dec)\n", (
void *)def, rb_id2name(def->original_id),
971 reference_count_was, reference_count_was - 1);
977rb_method_definition_release(rb_method_definition_t *def)
979 method_definition_release(def);
982static void delete_overloaded_cme(
const rb_callable_method_entry_t *cme);
985rb_free_method_entry_vm_weak_references(
const rb_method_entry_t *me)
987 if (me->def && me->def->iseq_overload) {
988 delete_overloaded_cme((
const rb_callable_method_entry_t *)me);
993rb_free_method_entry(
const rb_method_entry_t *me)
996 if (METHOD_ENTRY_CACHED(me)) {
997 rb_zjit_cme_free((
const rb_callable_method_entry_t *)me);
1006 method_definition_release(me->def);
1009static inline rb_method_entry_t *search_method(
VALUE klass,
ID id,
VALUE *defined_class_ptr);
1010extern int rb_method_definition_eq(
const rb_method_definition_t *d1,
const rb_method_definition_t *d2);
1015 if (!GET_THREAD()->ext_config.ractor_safe) {
1017 case -2:
return &call_cfunc_m2;
1018 case -1:
return &call_cfunc_m1;
1019 case 0:
return &call_cfunc_0;
1020 case 1:
return &call_cfunc_1;
1021 case 2:
return &call_cfunc_2;
1022 case 3:
return &call_cfunc_3;
1023 case 4:
return &call_cfunc_4;
1024 case 5:
return &call_cfunc_5;
1025 case 6:
return &call_cfunc_6;
1026 case 7:
return &call_cfunc_7;
1027 case 8:
return &call_cfunc_8;
1028 case 9:
return &call_cfunc_9;
1029 case 10:
return &call_cfunc_10;
1030 case 11:
return &call_cfunc_11;
1031 case 12:
return &call_cfunc_12;
1032 case 13:
return &call_cfunc_13;
1033 case 14:
return &call_cfunc_14;
1034 case 15:
return &call_cfunc_15;
1036 rb_bug(
"unsupported length: %d", argc);
1041 case -2:
return &ractor_safe_call_cfunc_m2;
1042 case -1:
return &ractor_safe_call_cfunc_m1;
1043 case 0:
return &ractor_safe_call_cfunc_0;
1044 case 1:
return &ractor_safe_call_cfunc_1;
1045 case 2:
return &ractor_safe_call_cfunc_2;
1046 case 3:
return &ractor_safe_call_cfunc_3;
1047 case 4:
return &ractor_safe_call_cfunc_4;
1048 case 5:
return &ractor_safe_call_cfunc_5;
1049 case 6:
return &ractor_safe_call_cfunc_6;
1050 case 7:
return &ractor_safe_call_cfunc_7;
1051 case 8:
return &ractor_safe_call_cfunc_8;
1052 case 9:
return &ractor_safe_call_cfunc_9;
1053 case 10:
return &ractor_safe_call_cfunc_10;
1054 case 11:
return &ractor_safe_call_cfunc_11;
1055 case 12:
return &ractor_safe_call_cfunc_12;
1056 case 13:
return &ractor_safe_call_cfunc_13;
1057 case 14:
return &ractor_safe_call_cfunc_14;
1058 case 15:
return &ractor_safe_call_cfunc_15;
1060 rb_bug(
"unsupported length: %d", argc);
1066setup_method_cfunc_struct(rb_method_cfunc_t *cfunc,
VALUE (*func)(
ANYARGS),
int argc)
1070 cfunc->invoker = call_cfunc_invoker_func(argc);
1074static rb_method_definition_t *
1075method_definition_addref(rb_method_definition_t *def,
bool complemented)
1078 if (!complemented && reference_count_was > 0) {
1080 def->aliased =
true;
1082 if (METHOD_DEBUG) fprintf(stderr,
"+%p-%s:%d->%d\n", (
void *)def, rb_id2name(def->original_id), reference_count_was, reference_count_was+1);
1088rb_method_definition_addref(rb_method_definition_t *def)
1090 method_definition_addref(def,
false);
1094rb_method_definition_set(
const rb_method_entry_t *me, rb_method_definition_t *def,
void *opts)
1096 rb_method_definition_t *old_def = me->def;
1099 rbimpl_atomic_ptr_store((
volatile void **)&me->def,
1100 method_definition_addref(def, METHOD_ENTRY_COMPLEMENTED(me)),
1101 RBIMPL_ATOMIC_RELEASE);
1102 method_definition_release(old_def);
1104 if (!ruby_running) add_opt_method_entry(me);
1107 switch (def->type) {
1108 case VM_METHOD_TYPE_ISEQ:
1110 rb_method_iseq_t *iseq_body = (rb_method_iseq_t *)opts;
1111 const rb_iseq_t *iseq = iseq_body->
iseqptr;
1112 rb_cref_t *method_cref, *cref = iseq_body->
cref;
1118 if (rb_iseq_attr_p(iseq, BUILTIN_ATTR_C_TRACE)) {
1119 METHOD_ENTRY_BASIC_SET((rb_method_entry_t *)me, TRUE);
1122 if (ISEQ_MANDATORY_ONLY_ISEQ(iseq)) def->iseq_overload = 1;
1124 if (0) vm_cref_dump(
"rb_method_definition_create", cref);
1130 method_cref = vm_cref_new_toplevel(GET_EC());
1136 case VM_METHOD_TYPE_CFUNC:
1138 rb_method_cfunc_t *cfunc = (rb_method_cfunc_t *)opts;
1139 setup_method_cfunc_struct(UNALIGNED_MEMBER_PTR(def, body.cfunc), cfunc->func, cfunc->argc);
1142 case VM_METHOD_TYPE_ATTRSET:
1143 case VM_METHOD_TYPE_IVAR:
1145 const rb_execution_context_t *ec = GET_EC();
1146 rb_control_frame_t *cfp;
1149 def->body.attr.id = (
ID)(
VALUE)opts;
1151 cfp = rb_vm_get_ruby_level_next_cfp(ec, ec->cfp);
1153 if (cfp && (line = rb_vm_get_sourceline(cfp))) {
1160 VM_ASSERT(def->body.attr.location == 0);
1164 case VM_METHOD_TYPE_BMETHOD:
1166 def->body.bmethod.defined_ractor_id = rb_ec_ractor_id(GET_EC());
1168 case VM_METHOD_TYPE_NOTIMPLEMENTED:
1169 setup_method_cfunc_struct(UNALIGNED_MEMBER_PTR(def, body.cfunc), (
VALUE(*)(
ANYARGS))rb_f_notimplement_internal, -1);
1171 case VM_METHOD_TYPE_OPTIMIZED:
1172 def->body.optimized = *(rb_method_optimized_t *)opts;
1174 case VM_METHOD_TYPE_REFINED:
1176 const rb_method_entry_t *orig_me = (
const rb_method_entry_t *)opts;
1178 RB_OBJ_WRITE(me, &def->original_module, orig_me->def->original_module);
1181 case VM_METHOD_TYPE_ALIAS:
1183 const rb_method_entry_t *orig_me = (
const rb_method_entry_t *)opts;
1184 RB_OBJ_WRITE(me, &def->body.alias.original_me, orig_me);
1185 RB_OBJ_WRITE(me, &def->original_module, orig_me->def->original_module);
1188 case VM_METHOD_TYPE_ZSUPER:
1189 case VM_METHOD_TYPE_UNDEF:
1190 case VM_METHOD_TYPE_MISSING:
1197method_definition_reset(
const rb_method_entry_t *me)
1199 rb_method_definition_t *def = me->def;
1203 switch (def->type) {
1204 case VM_METHOD_TYPE_ISEQ:
1208 case VM_METHOD_TYPE_ATTRSET:
1209 case VM_METHOD_TYPE_IVAR:
1212 case VM_METHOD_TYPE_BMETHOD:
1215 case VM_METHOD_TYPE_REFINED:
1218 case VM_METHOD_TYPE_ALIAS:
1221 case VM_METHOD_TYPE_CFUNC:
1222 case VM_METHOD_TYPE_ZSUPER:
1223 case VM_METHOD_TYPE_MISSING:
1224 case VM_METHOD_TYPE_OPTIMIZED:
1225 case VM_METHOD_TYPE_UNDEF:
1226 case VM_METHOD_TYPE_NOTIMPLEMENTED:
1233rb_method_definition_t *
1234rb_method_definition_create(rb_method_type_t
type,
ID mid)
1236 rb_method_definition_t *def;
1237 def =
ZALLOC(rb_method_definition_t);
1239 def->original_id = mid;
1241 def->box = rb_current_box();
1245static rb_method_entry_t *
1246rb_method_entry_alloc(
ID called_id,
VALUE owner,
VALUE defined_class, rb_method_definition_t *def,
bool complement)
1248 if (def) method_definition_addref(def, complement);
1249 if (
RTEST(defined_class)) {
1253 rb_method_entry_t *me = SHAREABLE_IMEMO_NEW(rb_method_entry_t, imemo_ment, defined_class);
1256 rb_gc_register_pinning_obj((
VALUE)me);
1258 *((rb_method_definition_t **)&me->def) = def;
1259 me->called_id = called_id;
1266filter_defined_class(
VALUE klass)
1278 rb_bug(
"filter_defined_class: %s", rb_obj_info(klass));
1282rb_method_entry_create(
ID called_id,
VALUE klass, rb_method_visibility_t visi, rb_method_definition_t *def)
1284 rb_method_entry_t *me = rb_method_entry_alloc(called_id, klass, filter_defined_class(klass), def,
false);
1285 METHOD_ENTRY_FLAGS_SET(me, visi, ruby_running ? FALSE : TRUE);
1286 if (def != NULL) method_definition_reset(me);
1291const rb_method_entry_t *
1292rb_method_entry_clone(
const rb_method_entry_t *src_me)
1294 rb_method_definition_t *src_def = rb_method_entry_def_acquire(src_me);
1295 rb_method_entry_t *me = rb_method_entry_alloc(src_me->called_id, src_me->owner, src_me->defined_class, src_def, METHOD_ENTRY_COMPLEMENTED(src_me));
1297 METHOD_ENTRY_FLAGS_COPY(me, src_me);
1301 src_def->type == VM_METHOD_TYPE_REFINED &&
1302 src_def->body.refined.orig_me) {
1303 const rb_method_entry_t *orig_me = src_def->body.refined.orig_me;
1304 VM_ASSERT(orig_me->def->type != VM_METHOD_TYPE_REFINED);
1306 rb_method_entry_t *orig_clone = rb_method_entry_alloc(orig_me->called_id,
1307 orig_me->owner, orig_me->defined_class, orig_me->def, METHOD_ENTRY_COMPLEMENTED(orig_me));
1308 METHOD_ENTRY_FLAGS_COPY(orig_clone, orig_me);
1312 rb_method_definition_t *clone_def =
1313 rb_method_definition_create(VM_METHOD_TYPE_REFINED, src_me->called_id);
1314 rb_method_definition_set(me, clone_def, orig_clone);
1319const rb_callable_method_entry_t *
1320rb_method_entry_complement_defined_class(
const rb_method_entry_t *src_me,
ID called_id,
VALUE defined_class)
1322 rb_method_definition_t *def = src_me->def;
1323 rb_method_entry_t *me;
1324 const rb_method_entry_t *refined_orig_me = NULL;
1326 if (def->type == VM_METHOD_TYPE_REFINED &&
1327 def->body.refined.orig_me) {
1328 const rb_method_entry_t *orig_me =
1329 rb_method_entry_clone(def->body.refined.orig_me);
1331 refined_orig_me = orig_me;
1335 me = rb_method_entry_alloc(called_id, src_me->owner, defined_class, def,
true);
1336 METHOD_ENTRY_FLAGS_COPY(me, src_me);
1337 METHOD_ENTRY_COMPLEMENTED_SET(me);
1339 def = rb_method_definition_create(VM_METHOD_TYPE_REFINED, called_id);
1340 rb_method_definition_set(me, def, (
void *)refined_orig_me);
1343 VM_ASSERT_TYPE(me->owner,
T_MODULE);
1345 return (rb_callable_method_entry_t *)me;
1349rb_method_entry_copy(rb_method_entry_t *dst,
const rb_method_entry_t *src)
1351 method_definition_release(dst->def);
1352 *(rb_method_definition_t **)&dst->def = method_definition_addref(src->def, METHOD_ENTRY_COMPLEMENTED(src));
1353 method_definition_reset(dst);
1354 dst->called_id = src->called_id;
1357 METHOD_ENTRY_FLAGS_COPY(dst, src);
1361make_method_entry_refined(
VALUE owner, rb_method_entry_t *me,
VALUE *perf_warnings)
1363 if (me->def->type == VM_METHOD_TYPE_REFINED) {
1367 rb_method_definition_t *def;
1369 rb_vm_check_redefinition_opt_method(me, me->owner, perf_warnings);
1372 rb_method_entry_alloc(me->called_id,
1377 METHOD_ENTRY_FLAGS_COPY(orig_me, me);
1379 def = rb_method_definition_create(VM_METHOD_TYPE_REFINED, me->called_id);
1380 rb_method_definition_set(me, def, orig_me);
1381 METHOD_ENTRY_VISI_SET(me, METHOD_VISI_PUBLIC);
1385static inline rb_method_entry_t *
1386lookup_method_table(
VALUE klass,
ID id)
1391 if (rb_id_table_lookup(m_tbl,
id, &body)) {
1392 return (rb_method_entry_t *) body;
1415static rb_method_entry_t *rb_method_entry_make(
VALUE klass,
ID mid,
VALUE defined_class, rb_method_visibility_t visi,
1416 rb_method_type_t
type, rb_method_definition_t *def,
ID original_id,
void *opts,
1424 rb_method_entry_t *me = lookup_method_table(refined_class, mid);
1427 make_method_entry_refined(refined_class, me, warnings ? &warnings->performance : NULL);
1428 rb_clear_method_cache(refined_class, mid);
1430 else if (warnings) {
1432 rb_method_entry_make(refined_class, mid, refined_class, METHOD_VISI_PUBLIC,
1433 VM_METHOD_TYPE_REFINED, NULL, mid, NULL, warnings);
1437 rb_add_method(refined_class, mid, VM_METHOD_TYPE_REFINED, 0, METHOD_VISI_PUBLIC);
1442rb_add_refined_method_entry(
VALUE refined_class,
ID mid)
1444 add_refined_method_entry(refined_class, mid, NULL);
1449 VALUE *perf_warnings;
1453check_override_opt_method_i(
VALUE klass,
VALUE arg)
1458 VALUE includer = RCLASS_INCLUDER(klass);
1459 if (!UNDEF_P(includer) && includer) {
1460 check_override_opt_method_i(includer, arg);
1468 const rb_method_entry_t *me, *newme;
1470 if (vm_redefinition_check_flag(klass)) {
1471 me = lookup_method_table(RCLASS_ORIGIN(klass), mid);
1473 newme = rb_method_entry(klass, mid);
1474 if (newme != me) rb_vm_check_redefinition_opt_method(me, me->owner, data->perf_warnings);
1477 rb_class_foreach_subclass(klass, check_override_opt_method_i, arg);
1481check_override_opt_method(
VALUE klass,
ID mid,
VALUE *perf_warnings)
1483 if (rb_vm_check_optimizable_mid(mid)) {
1485 .mid = mid, .perf_warnings = perf_warnings,
1487 check_override_opt_method_i(klass, (
VALUE)&arg);
1492rb_zsuper_to_super(
int argc,
VALUE *argv,
VALUE self)
1497static inline rb_method_entry_t* search_method0(
VALUE klass,
ID id,
VALUE *defined_class_ptr,
bool skip_refined);
1499method_entry_modify_check(
VALUE klass, rb_method_type_t
type)
1501 ASSERT_vm_unlocking();
1502 if (
type != VM_METHOD_TYPE_REFINED) {
1514 vm_warn_redefinition_opt_method((
const rb_method_entry_t *)
RARRAY_AREF(
warnings->performance, i));
1525static rb_method_entry_t *
1526rb_method_entry_make(
VALUE klass,
ID mid,
VALUE defined_class, rb_method_visibility_t visi,
1527 rb_method_type_t
type, rb_method_definition_t *def,
ID original_id,
void *opts,
1530 rb_method_entry_t *me;
1533 int make_refined = 0;
1535 bool turn_zsuper_to_super =
false;
1537 ASSERT_vm_locking();
1544 if (!RCLASS_SINGLETON_P(klass) &&
1545 type != VM_METHOD_TYPE_NOTIMPLEMENTED &&
1546 type != VM_METHOD_TYPE_ZSUPER) {
1549 case idInitialize_copy:
1550 case idInitialize_clone:
1551 case idInitialize_dup:
1552 case idRespond_to_missing:
1553 visi = METHOD_VISI_PRIVATE;
1558 VALUE refined_class = rb_refinement_module_get_refined_class(klass);
1559 if (
type == VM_METHOD_TYPE_ZSUPER) {
1560 turn_zsuper_to_super =
true;
1562 add_refined_method_entry(refined_class, mid, warnings);
1564 if (
type == VM_METHOD_TYPE_REFINED) {
1565 rb_method_entry_t *old_me = lookup_method_table(RCLASS_ORIGIN(klass), mid);
1566 if (old_me) rb_vm_check_redefinition_opt_method(old_me, klass, &
warnings->performance);
1569 klass = RCLASS_ORIGIN(klass);
1570 if (klass != orig_klass) {
1571 rb_clear_method_cache(orig_klass, mid);
1574 mtbl = RCLASS_WRITABLE_M_TBL(klass);
1577 if (rb_id_table_lookup(mtbl, mid, &data)) {
1578 rb_method_entry_t *old_me = (rb_method_entry_t *)data;
1579 rb_method_definition_t *old_def = old_me->def;
1581 if (rb_method_definition_eq(old_def, def)) {
1584 bool visi_changed = METHOD_ENTRY_VISI(old_me) != visi;
1587 rb_vm_check_redefinition_opt_method(old_me, klass, &
warnings->performance);
1589 old_def->no_redef_warning = TRUE;
1590 METHOD_ENTRY_FLAGS_SET(old_me, visi, FALSE);
1592 rb_clear_method_cache(klass, mid);
1596 rb_vm_check_redefinition_opt_method(old_me, klass, &
warnings->performance);
1598 if (old_def->type == VM_METHOD_TYPE_REFINED) make_refined = 1;
1601 type != VM_METHOD_TYPE_UNDEF &&
1602 (old_def->aliased ==
false) &&
1603 (!old_def->no_redef_warning) &&
1605 old_def->type != VM_METHOD_TYPE_UNDEF &&
1606 old_def->type != VM_METHOD_TYPE_ZSUPER &&
1607 old_def->type != VM_METHOD_TYPE_ALIAS) {
1608 const rb_iseq_t *iseq = 0;
1610 switch (old_def->type) {
1611 case VM_METHOD_TYPE_ISEQ:
1612 iseq = def_iseq_ptr(old_def);
1614 case VM_METHOD_TYPE_BMETHOD:
1615 iseq = rb_proc_get_iseq(old_def->body.bmethod.proc, 0);
1622 "method redefined; discarding old %"PRIsVALUE
"\n%"PRIsVALUE
":%d: warning: previous definition of %"PRIsVALUE
" was here",
1625 ISEQ_BODY(iseq)->location.first_lineno,
1626 rb_id2str(old_def->original_id)
1630 warnings->redefined = rb_sprintf(
"method redefined; discarding old %"PRIsVALUE, rb_id2str(mid));
1636 me = rb_method_entry_create(mid, defined_class, visi, NULL);
1638 def = rb_method_definition_create(
type, original_id);
1639 if (turn_zsuper_to_super) {
1640 def->type = VM_METHOD_TYPE_CFUNC;
1641 def->body.cfunc.func = (rb_cfunc_t)rb_zsuper_to_super;
1642 def->body.cfunc.invoker = ractor_safe_call_cfunc_m1;
1643 def->body.cfunc.argc = -1;
1647 rb_method_definition_set(me, def, opts);
1649 rb_clear_method_cache(klass, mid);
1655 case idRespond_to_missing:
1656 case idMethodMissing:
1658 warnings->problem = rb_sprintf(
"redefining Object#%s may cause infinite loop", rb_id2name(mid));
1662 if (mid == object_id || mid == id__id__ || mid == id__send__) {
1663 if (
type != VM_METHOD_TYPE_CFUNC && search_method(klass, mid, 0)) {
1664 warnings->problem = rb_sprintf(
"redefining '%s' may cause serious problems", rb_id2name(mid));
1669 make_method_entry_refined(klass, me, &
warnings->performance);
1672 rb_method_table_insert(klass, mtbl, mid, me);
1674 VM_ASSERT(me->def != NULL);
1678 check_override_opt_method(klass, mid, &
warnings->performance);
1685overloaded_cme_table(
void)
1687 return &GET_VM()->overloaded_cme_table;
1690#if VM_CHECK_MODE > 0
1692vm_dump_overloaded_cme_table(st_data_t key, st_data_t val, st_data_t dmy)
1694 fprintf(stderr,
"key: "); rp(key);
1695 fprintf(stderr,
"val: "); rp(val);
1700rb_vm_dump_overloaded_cme_table(
void)
1702 fprintf(stderr,
"== rb_vm_dump_overloaded_cme_table\n");
1703 st_foreach(overloaded_cme_table(), vm_dump_overloaded_cme_table, 0);
1708lookup_overloaded_cme_i(st_data_t *key, st_data_t *value, st_data_t data,
int existing)
1711 const rb_callable_method_entry_t *cme = (
const rb_callable_method_entry_t *)*key;
1712 const rb_callable_method_entry_t *monly_cme = (
const rb_callable_method_entry_t *)*value;
1713 const rb_callable_method_entry_t **ptr = (
const rb_callable_method_entry_t **)data;
1715 if (rb_objspace_garbage_object_p((
VALUE)cme) ||
1716 rb_objspace_garbage_object_p((
VALUE)monly_cme)) {
1728static const rb_callable_method_entry_t *
1729lookup_overloaded_cme(
const rb_callable_method_entry_t *cme)
1731 ASSERT_vm_locking();
1733 const rb_callable_method_entry_t *monly_cme = NULL;
1734 st_update(overloaded_cme_table(), (st_data_t)cme, lookup_overloaded_cme_i, (st_data_t)&monly_cme);
1738#if VM_CHECK_MODE > 0
1739const rb_callable_method_entry_t *
1740rb_vm_lookup_overloaded_cme(
const rb_callable_method_entry_t *cme)
1742 return lookup_overloaded_cme(cme);
1747delete_overloaded_cme(
const rb_callable_method_entry_t *cme)
1749 st_data_t cme_data = (st_data_t)cme;
1750 ASSERT_vm_locking();
1751 st_delete(overloaded_cme_table(), &cme_data, NULL);
1754static const rb_callable_method_entry_t *
1755get_overloaded_cme(
const rb_callable_method_entry_t *cme)
1757 const rb_callable_method_entry_t *monly_cme = lookup_overloaded_cme(cme);
1759 if (monly_cme && !METHOD_ENTRY_INVALIDATED(monly_cme)) {
1764 rb_method_definition_t *def = rb_method_definition_create(VM_METHOD_TYPE_ISEQ, cme->def->original_id);
1765 rb_method_entry_t *me = rb_method_entry_alloc(cme->called_id,
1773 RB_OBJ_WRITE(me, &def->original_module, cme->def->original_module);
1775 ASSERT_vm_locking();
1776 st_insert(overloaded_cme_table(), (st_data_t)cme, (st_data_t)me);
1778 METHOD_ENTRY_VISI_SET(me, METHOD_ENTRY_VISI(cme));
1779 return (rb_callable_method_entry_t *)me;
1783const rb_callable_method_entry_t *
1784rb_check_overloaded_cme(
const rb_callable_method_entry_t *cme,
const struct rb_callinfo *
const ci)
1786 if (UNLIKELY(cme->def->iseq_overload) &&
1787 (vm_ci_flag(ci) & (VM_CALL_ARGS_SIMPLE)) &&
1788 (!(vm_ci_flag(ci) & VM_CALL_FORWARDING)) &&
1789 (
int)vm_ci_argc(ci) == ISEQ_BODY(method_entry_iseqptr(cme))->param.lead_num) {
1790 VM_ASSERT(cme->def->type == VM_METHOD_TYPE_ISEQ,
"type: %d", cme->def->type);
1792 cme = get_overloaded_cme(cme);
1794 VM_ASSERT(cme != NULL);
1801static inline void stack_check(rb_execution_context_t *ec);
1803#define CALL_METHOD_HOOK(klass, hook, mid) do { \
1804 const VALUE arg = ID2SYM(mid); \
1805 VALUE recv_class = (klass); \
1806 ID hook_id = (hook); \
1807 if (RCLASS_SINGLETON_P((klass))) { \
1808 recv_class = RCLASS_ATTACHED_OBJECT((klass)); \
1809 hook_id = singleton_##hook; \
1811 rb_funcallv_uncached(recv_class, hook_id, 1, &arg); \
1815method_added(
VALUE klass,
ID mid,
const rb_method_entry_t *me)
1821 if (me) rb_vm_coverage_record_me(me);
1822 CALL_METHOD_HOOK(klass, added, mid);
1827rb_add_method(
VALUE klass,
ID mid, rb_method_type_t
type,
void *opts, rb_method_visibility_t visi)
1829 const rb_method_entry_t *me;
1832 method_entry_modify_check(klass,
type);
1835 me = rb_method_entry_make(klass, mid, klass, visi,
type, NULL, mid, opts, &warnings);
1838 method_entry_warnings_emit(&warnings);
1840 if (
type != VM_METHOD_TYPE_UNDEF &&
type != VM_METHOD_TYPE_REFINED) {
1841 method_added(klass, mid, me);
1846rb_add_method_iseq(
VALUE klass,
ID mid,
const rb_iseq_t *iseq, rb_cref_t *cref, rb_method_visibility_t visi)
1849 const rb_iseq_t *iseqptr;
1854 iseq_body.
cref = cref;
1856 rb_add_method(klass, mid, VM_METHOD_TYPE_ISEQ, &iseq_body, visi);
1859static rb_method_entry_t *
1860method_entry_set(
VALUE klass,
ID mid,
const rb_method_entry_t *me,
1861 rb_method_visibility_t visi,
VALUE defined_class)
1863 rb_method_entry_t *newme;
1866 method_entry_modify_check(klass, me->def->type);
1869 newme = rb_method_entry_make(klass, mid, defined_class, visi,
1870 me->def->type, me->def, 0, NULL, &warnings);
1873 method_entry_warnings_emit(&warnings);
1875 method_added(klass, mid, newme);
1880rb_method_entry_set(
VALUE klass,
ID mid,
const rb_method_entry_t *me, rb_method_visibility_t visi)
1882 return method_entry_set(klass, mid, me, visi, klass);
1885#define UNDEF_ALLOC_FUNC ((rb_alloc_func_t)-1)
1888propagate_alloc_func(
VALUE subclass,
VALUE arg)
1891 !RCLASS_SINGLETON_P(subclass) &&
1892 !
FL_TEST_RAW(subclass, RCLASS_ALLOCATOR_DEFINED)) {
1894 rb_class_foreach_subclass(subclass, propagate_alloc_func, arg);
1902 if (RCLASS_SINGLETON_P(klass)) {
1903 rb_raise(
rb_eTypeError,
"can't define an allocator for a singleton class");
1905 RCLASS_SET_ALLOCATOR(klass, func);
1907 rb_class_foreach_subclass(klass, propagate_alloc_func, (
VALUE)func);
1914 RCLASS_SET_ALLOCATOR(klass, UNDEF_ALLOC_FUNC);
1916 rb_class_foreach_subclass(klass, propagate_alloc_func, (
VALUE)UNDEF_ALLOC_FUNC);
1922 RBIMPL_ASSERT_TYPE(klass,
T_CLASS);
1925 if (allocator == UNDEF_ALLOC_FUNC)
return 0;
1930const rb_method_entry_t *
1931rb_method_entry_at(
VALUE klass,
ID id)
1933 return lookup_method_table(klass,
id);
1936static inline rb_method_entry_t*
1937search_method0(
VALUE klass,
ID id,
VALUE *defined_class_ptr,
bool skip_refined)
1939 rb_method_entry_t *me = NULL;
1941 RB_DEBUG_COUNTER_INC(mc_search);
1944 RB_DEBUG_COUNTER_INC(mc_search_super);
1945 if ((me = lookup_method_table(klass,
id)) != 0) {
1946 if (!skip_refined || me->def->type != VM_METHOD_TYPE_REFINED ||
1947 me->def->body.refined.orig_me) {
1953 if (defined_class_ptr) *defined_class_ptr = klass;
1955 if (me == NULL) RB_DEBUG_COUNTER_INC(mc_search_notfound);
1957 VM_ASSERT(me == NULL || !METHOD_ENTRY_INVALIDATED(me),
1958 "invalid me, mid:%s, klass:%"PRIsVALUE
"(%s)",
1961 rb_obj_info(klass));
1965static inline rb_method_entry_t*
1966search_method(
VALUE klass,
ID id,
VALUE *defined_class_ptr)
1968 return search_method0(klass,
id, defined_class_ptr,
false);
1971static rb_method_entry_t *
1972search_method_protect(
VALUE klass,
ID id,
VALUE *defined_class_ptr)
1974 rb_method_entry_t *me = search_method(klass,
id, defined_class_ptr);
1976 if (!UNDEFINED_METHOD_ENTRY_P(me)) {
1984const rb_method_entry_t *
1985rb_method_entry(
VALUE klass,
ID id)
1987 return search_method_protect(klass,
id, NULL);
1990static inline const rb_callable_method_entry_t *
1991prepare_callable_method_entry(
VALUE defined_class,
ID id,
const rb_method_entry_t *
const me,
int create)
1994 const rb_callable_method_entry_t *cme;
1999 if (me->defined_class == 0) {
2000 RB_DEBUG_COUNTER_INC(mc_cme_complement);
2003 mtbl = RCLASS_WRITABLE_CALLABLE_M_TBL(defined_class);
2004 if (mtbl && rb_id_table_lookup(mtbl,
id, &cme_data)) {
2005 cme = (rb_callable_method_entry_t *)cme_data;
2009 RB_DEBUG_COUNTER_INC(mc_cme_complement_hit);
2010 VM_ASSERT(callable_method_entry_p(cme));
2011 VM_ASSERT(!METHOD_ENTRY_INVALIDATED(cme));
2015 mtbl = rb_id_table_create(0);
2016 RCLASS_WRITE_CALLABLE_M_TBL(defined_class, mtbl);
2018 cme = rb_method_entry_complement_defined_class(me, me->called_id, defined_class);
2019 rb_id_table_insert(mtbl,
id, (
VALUE)cme);
2021 VM_ASSERT(callable_method_entry_p(cme));
2028 cme = (
const rb_callable_method_entry_t *)me;
2029 VM_ASSERT(callable_method_entry_p(cme));
2030 VM_ASSERT(!METHOD_ENTRY_INVALIDATED(cme));
2043rb_funcallv_uncached(
VALUE recv,
ID mid,
int argc,
const VALUE *argv)
2045 VALUE defined_class;
2046 const rb_method_entry_t *me = search_method(
CLASS_OF(recv), mid, &defined_class);
2048 if (UNLIKELY(UNDEFINED_METHOD_ENTRY_P(me))) {
2052 const rb_callable_method_entry_t *cme;
2054 if (UNLIKELY(me->defined_class == 0)) {
2056 cme = rb_method_entry_complement_defined_class(me, me->called_id, defined_class);
2059 cme = (
const rb_callable_method_entry_t *)me;
2062 rb_execution_context_t *ec = GET_EC();
2064 return rb_vm_call_kw(ec, recv, mid, argc, argv, cme,
RB_NO_KEYWORDS);
2067static const rb_callable_method_entry_t *
2068complemented_callable_method_entry(
VALUE klass,
ID id)
2070 VALUE defined_class;
2071 rb_method_entry_t *me = search_method(klass,
id, &defined_class);
2072 return prepare_callable_method_entry(defined_class,
id, me, FALSE);
2075static const rb_callable_method_entry_t *
2076cached_callable_method_entry(
VALUE klass,
ID mid)
2078 ASSERT_vm_locking();
2080 VALUE cc_tbl = RCLASS_WRITABLE_CC_TBL(klass);
2083 if (cc_tbl && rb_managed_id_table_lookup(cc_tbl, mid, &ccs_data)) {
2085 VM_ASSERT(vm_ccs_p(ccs));
2087 if (LIKELY(!METHOD_ENTRY_INVALIDATED(ccs->cme))) {
2088 VM_ASSERT(ccs->cme->called_id == mid);
2089 RB_DEBUG_COUNTER_INC(ccs_found);
2095 rb_managed_id_table_delete(cc_tbl, mid);
2096 rb_vm_ccs_invalidate_and_free(ccs);
2100 RB_DEBUG_COUNTER_INC(ccs_not_found);
2105cache_callable_method_entry(
VALUE klass,
ID mid,
const rb_callable_method_entry_t *cme)
2107 ASSERT_vm_locking();
2108 VM_ASSERT(cme != NULL);
2110 VALUE cc_tbl = RCLASS_WRITABLE_CC_TBL(klass);
2114 cc_tbl = rb_vm_cc_table_create(2);
2115 RCLASS_WRITE_CC_TBL(klass, cc_tbl);
2118 if (rb_managed_id_table_lookup(cc_tbl, mid, &ccs_data)) {
2119#if VM_CHECK_MODE > 0
2121 VM_ASSERT(ccs->cme == cme);
2125 if (rb_multi_ractor_p()) {
2126 VALUE new_cc_tbl = rb_vm_cc_table_dup(cc_tbl);
2127 vm_ccs_create(klass, new_cc_tbl, mid, cme);
2128 RB_OBJ_ATOMIC_WRITE(klass, &RCLASSEXT_CC_TBL(RCLASS_EXT_WRITABLE(klass)), new_cc_tbl);
2131 vm_ccs_create(klass, cc_tbl, mid, cme);
2136static const rb_callable_method_entry_t *
2139 rb_vm_t *vm = GET_VM();
2140 const rb_callable_method_entry_t *cme;
2143 if (rb_id_table_lookup(&vm->negative_cme_table, mid, &cme_data)) {
2144 cme = (rb_callable_method_entry_t *)cme_data;
2147 cme = (rb_callable_method_entry_t *)rb_method_entry_alloc(mid,
Qnil,
Qnil, NULL,
false);
2148 rb_id_table_insert(&vm->negative_cme_table, mid, (
VALUE)cme);
2151 VM_ASSERT(cme != NULL);
2155static const rb_callable_method_entry_t *
2156callable_method_entry_or_negative(
VALUE klass,
ID mid,
VALUE *defined_class_ptr)
2158 const rb_callable_method_entry_t *cme;
2168 rb_bug(
"attempted to search method '%s' on a garbage collected object",
2175 VALUE cc_tbl = RUBY_ATOMIC_VALUE_LOAD(RCLASS_WRITABLE_CC_TBL(klass));
2178 if (rb_managed_id_table_lookup(cc_tbl, mid, &ccs_data)) {
2180 VM_ASSERT(vm_ccs_p(ccs));
2182 if (LIKELY(!METHOD_ENTRY_INVALIDATED(ccs->cme))) {
2183 VM_ASSERT(ccs->cme->called_id == mid);
2184 if (defined_class_ptr != NULL) *defined_class_ptr = ccs->cme->defined_class;
2185 RB_DEBUG_COUNTER_INC(ccs_found);
2193 cme = cached_callable_method_entry(klass, mid);
2196 if (defined_class_ptr != NULL) *defined_class_ptr = cme->defined_class;
2199 VALUE defined_class;
2200 rb_method_entry_t *me = search_method(klass, mid, &defined_class);
2201 if (defined_class_ptr) *defined_class_ptr = defined_class;
2204 cme = prepare_callable_method_entry(defined_class, mid, me, TRUE);
2207 cme = negative_cme(mid);
2210 cache_callable_method_entry(klass, mid, cme);
2219const rb_callable_method_entry_t *
2220rb_callable_method_entry_or_negative(
VALUE klass,
ID mid)
2222 return callable_method_entry_or_negative(klass, mid, NULL);
2225static const rb_callable_method_entry_t *
2226callable_method_entry(
VALUE klass,
ID mid,
VALUE *defined_class_ptr)
2228 const rb_callable_method_entry_t *cme;
2229 cme = callable_method_entry_or_negative(klass, mid, defined_class_ptr);
2230 return !UNDEFINED_METHOD_ENTRY_P(cme) ? cme : NULL;
2233const rb_callable_method_entry_t *
2234rb_callable_method_entry(
VALUE klass,
ID mid)
2236 return callable_method_entry(klass, mid, NULL);
2239static const rb_method_entry_t *resolve_refined_method(
VALUE refinements,
const rb_method_entry_t *me,
VALUE *defined_class_ptr);
2241static const rb_method_entry_t *
2242method_entry_resolve_refinement(
VALUE klass,
ID id,
int with_refinement,
VALUE *defined_class_ptr)
2244 const rb_method_entry_t *me = search_method_protect(klass,
id, defined_class_ptr);
2247 if (me->def->type == VM_METHOD_TYPE_REFINED) {
2248 if (with_refinement) {
2249 const rb_cref_t *cref = rb_vm_cref();
2250 VALUE refinements = cref ? CREF_REFINEMENTS(cref) :
Qnil;
2251 me = resolve_refined_method(refinements, me, defined_class_ptr);
2254 me = resolve_refined_method(
Qnil, me, defined_class_ptr);
2257 if (UNDEFINED_METHOD_ENTRY_P(me)) me = NULL;
2264const rb_method_entry_t *
2265rb_method_entry_with_refinements(
VALUE klass,
ID id,
VALUE *defined_class_ptr)
2267 return method_entry_resolve_refinement(klass,
id, TRUE, defined_class_ptr);
2270static const rb_callable_method_entry_t *
2271callable_method_entry_refinements0(
VALUE klass,
ID id,
VALUE *defined_class_ptr,
bool with_refinements,
2272 const rb_callable_method_entry_t *cme)
2274 if (cme == NULL || LIKELY(cme->def->type != VM_METHOD_TYPE_REFINED)) {
2278 VALUE defined_class, *dcp = defined_class_ptr ? defined_class_ptr : &defined_class;
2279 const rb_method_entry_t *me = method_entry_resolve_refinement(klass,
id, with_refinements, dcp);
2280 return prepare_callable_method_entry(*dcp,
id, me, TRUE);
2284static const rb_callable_method_entry_t *
2285callable_method_entry_refinements(
VALUE klass,
ID id,
VALUE *defined_class_ptr,
bool with_refinements)
2287 const rb_callable_method_entry_t *cme = callable_method_entry(klass,
id, defined_class_ptr);
2288 return callable_method_entry_refinements0(klass,
id, defined_class_ptr, with_refinements, cme);
2291const rb_callable_method_entry_t *
2292rb_callable_method_entry_with_refinements(
VALUE klass,
ID id,
VALUE *defined_class_ptr)
2294 return callable_method_entry_refinements(klass,
id, defined_class_ptr,
true);
2297static const rb_callable_method_entry_t *
2298callable_method_entry_without_refinements(
VALUE klass,
ID id,
VALUE *defined_class_ptr)
2300 return callable_method_entry_refinements(klass,
id, defined_class_ptr,
false);
2303const rb_method_entry_t *
2304rb_method_entry_without_refinements(
VALUE klass,
ID id,
VALUE *defined_class_ptr)
2306 return method_entry_resolve_refinement(klass,
id, FALSE, defined_class_ptr);
2309const rb_callable_method_entry_t *
2310rb_callable_method_entry_without_refinements(
VALUE klass,
ID id,
VALUE *defined_class_ptr)
2312 VALUE defined_class, *dcp = defined_class_ptr ? defined_class_ptr : &defined_class;
2313 const rb_method_entry_t *me = method_entry_resolve_refinement(klass,
id, FALSE, dcp);
2314 return prepare_callable_method_entry(*dcp,
id, me, TRUE);
2317static const rb_method_entry_t *
2318resolve_refined_method(
VALUE refinements,
const rb_method_entry_t *me,
VALUE *defined_class_ptr)
2320 while (me && me->def->type == VM_METHOD_TYPE_REFINED) {
2322 const rb_method_entry_t *tmp_me;
2325 refinement = find_refinement(refinements, me->owner);
2326 if (!
NIL_P(refinement)) {
2328 refinement = module_refinement_iclass(refinement, *defined_class_ptr);
2330 tmp_me = search_method_protect(refinement, me->called_id, defined_class_ptr);
2332 if (tmp_me && tmp_me->def->type != VM_METHOD_TYPE_REFINED) {
2337 tmp_me = me->def->body.refined.orig_me;
2339 if (!tmp_me->defined_class) {
2340 VM_ASSERT_TYPE(tmp_me->owner,
T_MODULE);
2342 else if (defined_class_ptr) {
2343 *defined_class_ptr = tmp_me->defined_class;
2353 me = search_method_protect(super, me->called_id, defined_class_ptr);
2358const rb_method_entry_t *
2359rb_resolve_refined_method(
VALUE refinements,
const rb_method_entry_t *me)
2361 return resolve_refined_method(refinements, me, NULL);
2364const rb_callable_method_entry_t *
2365rb_resolve_refined_method_callable(
VALUE refinements,
const rb_callable_method_entry_t *me)
2367 VALUE defined_class = me->defined_class;
2368 const rb_method_entry_t *resolved_me = resolve_refined_method(refinements, (
const rb_method_entry_t *)me, &defined_class);
2370 if (resolved_me && resolved_me->defined_class == 0) {
2371 return rb_method_entry_complement_defined_class(resolved_me, me->called_id, defined_class);
2374 return (
const rb_callable_method_entry_t *)resolved_me;
2379remove_method(
VALUE klass,
ID mid)
2382 rb_method_entry_t *me = 0;
2386 klass = RCLASS_ORIGIN(klass);
2387 if (mid == object_id || mid == id__id__ || mid == id__send__ || mid == idInitialize) {
2388 rb_warn(
"removing '%s' may cause serious problems", rb_id2name(mid));
2391 if (!rb_id_table_lookup(RCLASS_M_TBL(klass), mid, &data) ||
2392 !(me = (rb_method_entry_t *)data) ||
2393 (!me->def || me->def->type == VM_METHOD_TYPE_UNDEF) ||
2394 UNDEFINED_REFINED_METHOD_P(me->def)) {
2395 rb_name_err_raise(
"method '%1$s' not defined in %2$s",
2399 if (klass != self) {
2400 rb_clear_method_cache(self, mid);
2402 rb_clear_method_cache(klass, mid);
2403 rb_id_table_delete(RCLASS_WRITABLE_M_TBL(klass), mid);
2405 rb_vm_check_redefinition_opt_method(me, klass, NULL);
2407 if (me->def->type == VM_METHOD_TYPE_REFINED) {
2408 rb_add_refined_method_entry(klass, mid);
2411 CALL_METHOD_HOOK(self, removed, mid);
2417 remove_method(klass, mid);
2423 remove_method(klass, rb_intern(name));
2437rb_mod_remove_method(
int argc,
VALUE *argv,
VALUE mod)
2441 for (i = 0; i < argc; i++) {
2445 rb_name_err_raise(
"method '%1$s' not defined in %2$s",
2448 remove_method(mod,
id);
2454rb_export_method(
VALUE klass,
ID name, rb_method_visibility_t visi)
2456 rb_method_entry_t *me;
2457 VALUE defined_class;
2458 VALUE origin_class = RCLASS_ORIGIN(klass);
2460 me = search_method0(origin_class, name, &defined_class,
true);
2463 me = search_method(
rb_cObject, name, &defined_class);
2466 if (UNDEFINED_METHOD_ENTRY_P(me) ||
2467 UNDEFINED_REFINED_METHOD_P(me->def)) {
2468 rb_print_undef(klass, name, METHOD_VISI_UNDEF);
2471 if (METHOD_ENTRY_VISI(me) != visi) {
2472 rb_vm_check_redefinition_opt_method(me, klass, NULL);
2474 if (klass == defined_class || origin_class == defined_class) {
2483 if (me->def->type == VM_METHOD_TYPE_REFINED) {
2486 if (me->def->body.refined.orig_me) {
2487 METHOD_ENTRY_VISI_SET((rb_method_entry_t *)me->def->body.refined.orig_me, visi);
2491 METHOD_ENTRY_VISI_SET(me, visi);
2493 rb_clear_method_cache(klass, name);
2497 rb_add_method(klass, name, VM_METHOD_TYPE_ZSUPER, 0, visi);
2502#define BOUND_PRIVATE 0x01
2503#define BOUND_RESPONDS 0x02
2506method_boundp(
VALUE klass,
ID id,
int ex)
2508 const rb_callable_method_entry_t *cme;
2512 if (ex & BOUND_RESPONDS) {
2513 cme = rb_callable_method_entry_with_refinements(klass,
id, NULL);
2516 cme = callable_method_entry_without_refinements(klass,
id, NULL);
2520 if (ex & ~BOUND_RESPONDS) {
2521 switch (METHOD_ENTRY_VISI(cme)) {
2522 case METHOD_VISI_PRIVATE:
2524 case METHOD_VISI_PROTECTED:
2525 if (ex & BOUND_RESPONDS)
return 0;
2531 if (cme->def->type == VM_METHOD_TYPE_NOTIMPLEMENTED) {
2532 if (ex & BOUND_RESPONDS)
return 2;
2544 return method_boundp(klass,
id, ex);
2548vm_cref_set_visibility(rb_method_visibility_t method_visi,
int module_func)
2550 rb_scope_visibility_t *scope_visi = (rb_scope_visibility_t *)&rb_vm_cref()->scope_visi;
2551 scope_visi->method_visi = method_visi;
2552 scope_visi->module_func = module_func;
2556rb_scope_visibility_set(rb_method_visibility_t visi)
2558 vm_cref_set_visibility(visi, FALSE);
2562scope_visibility_check(
void)
2565 rb_control_frame_t *cfp = GET_EC()->cfp+1;
2566 if (cfp && CFP_ISEQ(cfp) && ISEQ_BODY(CFP_ISEQ(cfp))->
type == ISEQ_TYPE_METHOD) {
2567 rb_warn(
"calling %s without arguments inside a method may not have the intended effect",
2573rb_scope_module_func_set(
void)
2575 scope_visibility_check();
2576 vm_cref_set_visibility(METHOD_VISI_PRIVATE, TRUE);
2579const rb_cref_t *rb_vm_cref_in_context(
VALUE self,
VALUE cbase);
2584 rb_method_visibility_t visi;
2585 const rb_execution_context_t *ec = GET_EC();
2586 const rb_cref_t *cref = rb_vm_cref_in_context(klass, klass);
2589 visi = METHOD_VISI_PUBLIC;
2592 switch (vm_scope_visibility_get(ec)) {
2593 case METHOD_VISI_PRIVATE:
2594 if (vm_scope_module_func_check(ec)) {
2595 rb_warning(
"attribute accessor as module_function");
2597 visi = METHOD_VISI_PRIVATE;
2599 case METHOD_VISI_PROTECTED:
2600 visi = METHOD_VISI_PROTECTED;
2603 visi = METHOD_VISI_PUBLIC;
2608 attriv = rb_intern_str(rb_sprintf(
"@%"PRIsVALUE, rb_id2str(
id)));
2610 rb_add_method(klass,
id, VM_METHOD_TYPE_IVAR, (
void *)attriv, visi);
2613 rb_add_method(klass, rb_id_attrset(
id), VM_METHOD_TYPE_ATTRSET, (
void *)attriv, visi);
2620 const rb_method_entry_t *me;
2626 if (
id == object_id ||
id == id__id__ ||
id == id__send__ ||
id == idInitialize) {
2627 rb_warn(
"undefining '%s' may cause serious problems", rb_id2name(
id));
2630 me = search_method(klass,
id, 0);
2631 if (me && me->def->type == VM_METHOD_TYPE_REFINED) {
2632 me = rb_resolve_refined_method(
Qnil, me);
2635 if (UNDEFINED_METHOD_ENTRY_P(me) ||
2636 UNDEFINED_REFINED_METHOD_P(me->def)) {
2637 rb_method_name_error(klass, rb_id2str(
id));
2640 rb_add_method(klass,
id, VM_METHOD_TYPE_UNDEF, 0, METHOD_VISI_PUBLIC);
2642 CALL_METHOD_HOOK(klass, undefined,
id);
2691rb_mod_undef_method(
int argc,
VALUE *argv,
VALUE mod)
2694 for (i = 0; i < argc; i++) {
2698 rb_method_name_error(mod, v);
2705static rb_method_visibility_t
2706check_definition_visibility(
VALUE mod,
VALUE mid,
bool inc_super)
2709 if (!
id)
return METHOD_VISI_UNDEF;
2711 VALUE lookup_mod = inc_super ? mod : RCLASS_ORIGIN(mod);
2713 const rb_method_entry_t *me = rb_method_entry_without_refinements(lookup_mod,
id, NULL);
2715 if (me->def->type == VM_METHOD_TYPE_NOTIMPLEMENTED)
return METHOD_VISI_UNDEF;
2716 if (!inc_super && me->owner != mod)
return METHOD_VISI_UNDEF;
2717 return METHOD_ENTRY_VISI(me);
2719 return METHOD_VISI_UNDEF;
2763rb_mod_method_defined(
int argc,
VALUE *argv,
VALUE mod)
2765 VALUE mid, include_super, include_private;
2767 rb_scan_args(argc, argv,
"12", &mid, &include_super, &include_private);
2769 include_private =
Qfalse;
2771 include_super =
Qtrue;
2775 rb_method_visibility_t visi = check_definition_visibility(mod, mid,
RTEST(include_super));
2777 case METHOD_VISI_UNDEF:
2779 case METHOD_VISI_PUBLIC:
2780 case METHOD_VISI_PROTECTED:
2782 case METHOD_VISI_PRIVATE:
2783 return RBOOL(
RTEST(include_private));
2790check_definition(
VALUE mod,
int argc,
VALUE *argv, rb_method_visibility_t visi)
2792 VALUE mid, include_super;
2795 include_super =
Qtrue;
2797 return RBOOL(check_definition_visibility(mod, mid,
RTEST(include_super)) == visi);
2831rb_mod_public_method_defined(
int argc,
VALUE *argv,
VALUE mod)
2833 return check_definition(mod, argc, argv, METHOD_VISI_PUBLIC);
2867rb_mod_private_method_defined(
int argc,
VALUE *argv,
VALUE mod)
2869 return check_definition(mod, argc, argv, METHOD_VISI_PRIVATE);
2903rb_mod_protected_method_defined(
int argc,
VALUE *argv,
VALUE mod)
2905 return check_definition(mod, argc, argv, METHOD_VISI_PROTECTED);
2909rb_method_entry_eq(
const rb_method_entry_t *m1,
const rb_method_entry_t *m2)
2911 return rb_method_definition_eq(rb_method_entry_def_acquire(m1), rb_method_entry_def_acquire(m2));
2914static const rb_method_definition_t *
2915original_method_definition(
const rb_method_definition_t *def)
2919 switch (def->type) {
2920 case VM_METHOD_TYPE_REFINED:
2921 if (def->body.refined.orig_me) {
2922 def = def->body.refined.orig_me->def;
2926 case VM_METHOD_TYPE_ALIAS:
2927 def = rb_method_entry_def_acquire(rb_method_alias_original_me(def));
2937rb_method_definition_eq(
const rb_method_definition_t *d1,
const rb_method_definition_t *d2)
2939 d1 = original_method_definition(d1);
2940 d2 = original_method_definition(d2);
2942 if (d1 == d2)
return 1;
2943 if (!d1 || !d2)
return 0;
2944 if (d1->type != d2->type)
return 0;
2947 case VM_METHOD_TYPE_ISEQ:
2948 return d1->body.iseq.iseqptr == d2->body.iseq.
iseqptr;
2949 case VM_METHOD_TYPE_CFUNC:
2951 d1->body.cfunc.func == d2->body.cfunc.func &&
2952 d1->body.cfunc.argc == d2->body.cfunc.argc;
2953 case VM_METHOD_TYPE_ATTRSET:
2954 case VM_METHOD_TYPE_IVAR:
2955 return d1->body.attr.id == d2->body.attr.id;
2956 case VM_METHOD_TYPE_BMETHOD:
2957 return RTEST(rb_proc_eq(d1->body.bmethod.proc, d2->body.bmethod.proc));
2958 case VM_METHOD_TYPE_MISSING:
2959 return d1->original_id == d2->original_id;
2960 case VM_METHOD_TYPE_ZSUPER:
2961 case VM_METHOD_TYPE_NOTIMPLEMENTED:
2962 case VM_METHOD_TYPE_UNDEF:
2964 case VM_METHOD_TYPE_OPTIMIZED:
2965 return (d1->body.optimized.type == d2->body.optimized.type) &&
2966 (d1->body.optimized.index == d2->body.optimized.index);
2967 case VM_METHOD_TYPE_REFINED:
2968 case VM_METHOD_TYPE_ALIAS:
2971 rb_bug(
"rb_method_definition_eq: unsupported type: %d", d1->type);
2975rb_hash_method_definition(st_index_t hash,
const rb_method_definition_t *def)
2978 def = original_method_definition(def);
2980 if (!def)
return hash;
2982 switch (def->type) {
2983 case VM_METHOD_TYPE_ISEQ:
2985 case VM_METHOD_TYPE_CFUNC:
2986 hash =
rb_hash_uint(hash, (st_index_t)def->body.cfunc.func);
2988 case VM_METHOD_TYPE_ATTRSET:
2989 case VM_METHOD_TYPE_IVAR:
2991 case VM_METHOD_TYPE_BMETHOD:
2992 return rb_hash_proc(hash, def->body.bmethod.proc);
2993 case VM_METHOD_TYPE_MISSING:
2995 case VM_METHOD_TYPE_ZSUPER:
2996 case VM_METHOD_TYPE_NOTIMPLEMENTED:
2997 case VM_METHOD_TYPE_UNDEF:
2999 case VM_METHOD_TYPE_OPTIMIZED:
3002 case VM_METHOD_TYPE_REFINED:
3003 case VM_METHOD_TYPE_ALIAS:
3006 rb_bug(
"rb_hash_method_definition: unsupported method type (%d)", def->type);
3010rb_hash_method_entry(st_index_t hash,
const rb_method_entry_t *me)
3012 return rb_hash_method_definition(hash, rb_method_entry_def_acquire(me));
3016rb_add_alias(
VALUE klass,
ID alias_name,
ID original_name, rb_method_visibility_t visi_alias)
3018 const VALUE target_klass = klass;
3019 VALUE defined_class;
3020 const rb_method_entry_t *orig_me;
3021 rb_method_visibility_t visi = METHOD_VISI_UNDEF;
3030 orig_me = search_method(klass, original_name, &defined_class);
3032 if (orig_me && orig_me->def->type == VM_METHOD_TYPE_REFINED) {
3033 orig_me = rb_resolve_refined_method(
Qnil, orig_me);
3036 if (UNDEFINED_METHOD_ENTRY_P(orig_me) ||
3037 UNDEFINED_REFINED_METHOD_P(orig_me->def)) {
3039 (orig_me = search_method(
rb_cObject, original_name, &defined_class),
3040 UNDEFINED_METHOD_ENTRY_P(orig_me))) {
3041 rb_print_undef(target_klass, original_name, METHOD_VISI_UNDEF);
3043 rb_warn_scheduled_deprecation(4.2, 4.3,
3044 "the fallback to Object for alias of '%"PRIsVALUE
"' in module '%"PRIsVALUE
"'",
3045 NULL, QUOTE_ID(original_name),
rb_class_path(target_klass));
3048 switch (orig_me->def->type) {
3049 case VM_METHOD_TYPE_ZSUPER:
3051 original_name = orig_me->def->original_id;
3052 visi = METHOD_ENTRY_VISI(orig_me);
3054 case VM_METHOD_TYPE_ALIAS:
3055 visi = METHOD_ENTRY_VISI(orig_me);
3056 orig_me = rb_method_alias_original_me(rb_method_entry_def_acquire(orig_me));
3057 VM_ASSERT(orig_me->def->type != VM_METHOD_TYPE_ALIAS);
3062 if (visi == METHOD_VISI_UNDEF) visi = METHOD_ENTRY_VISI(orig_me);
3063 if (visi_alias != METHOD_VISI_UNDEF) visi = visi_alias;
3066 VALUE owner_class = orig_me->defined_class ? orig_me->defined_class : defined_class;
3067 VALUE origin = RCLASS_ORIGIN(target_klass);
3068 bool in_prepended_module =
false;
3070 if (origin != target_klass) {
3072 if (p == owner_class) {
3073 in_prepended_module =
true;
3078 if (in_prepended_module) {
3079 rb_warn_scheduled_deprecation(4.2, 4.3,
3080 "aliasing %"PRIsVALUE
"#%"PRIsVALUE
" defined in a prepended module %"PRIsVALUE,
3087 if (orig_me->defined_class == 0) {
3089 const rb_method_entry_t *alias_me;
3092 alias_me = rb_method_entry_make(target_klass, alias_name, target_klass, visi,
3093 VM_METHOD_TYPE_ALIAS, NULL, orig_me->called_id,
3094 (
void *)rb_method_entry_clone(orig_me), &warnings);
3097 method_entry_warnings_emit(&warnings);
3098 method_added(target_klass, alias_name, alias_me);
3101 rb_method_entry_t *alias_me;
3103 alias_me = method_entry_set(target_klass, alias_name, orig_me, visi, orig_me->owner);
3104 RB_OBJ_WRITE(alias_me, &alias_me->owner, target_klass);
3110 RB_OBJ_WRITE(alias_me, &alias_me->defined_class, orig_me->defined_class);
3118 rb_add_alias(klass, alias_name, original_name, METHOD_VISI_UNDEF);
3149 rb_print_undef_str(mod, oldname);
3157check_and_export_method(
VALUE self,
VALUE name, rb_method_visibility_t visi)
3161 rb_print_undef_str(self, name);
3163 rb_export_method(self,
id, visi);
3167set_method_visibility(
VALUE self,
int argc,
const VALUE *argv, rb_method_visibility_t visi)
3173 rb_check_frozen(self);
3174 rb_class_owner_check(self);
3176 rb_warning(
"%"PRIsVALUE
" with no argument is just ignored",
3188 check_and_export_method(self,
RARRAY_AREF(v, j), visi);
3192 for (i = 0; i < argc; i++) {
3193 check_and_export_method(self, argv[i], visi);
3199set_visibility(
int argc,
const VALUE *argv,
VALUE module, rb_method_visibility_t visi)
3202 scope_visibility_check();
3203 rb_scope_visibility_set(visi);
3207 set_method_visibility(module, argc, argv, visi);
3232rb_mod_public(
int argc,
VALUE *argv,
VALUE module)
3234 return set_visibility(argc, argv, module, METHOD_VISI_PUBLIC);
3296rb_mod_protected(
int argc,
VALUE *argv,
VALUE module)
3298 return set_visibility(argc, argv, module, METHOD_VISI_PROTECTED);
3330rb_mod_private(
int argc,
VALUE *argv,
VALUE module)
3332 return set_visibility(argc, argv, module, METHOD_VISI_PRIVATE);
3363rb_mod_ruby2_keywords(
int argc,
VALUE *argv,
VALUE module)
3366 VALUE origin_class = RCLASS_ORIGIN(module);
3369 rb_check_frozen(module);
3370 rb_class_owner_check(module);
3372 for (i = 0; i < argc; i++) {
3375 rb_method_entry_t *me;
3376 VALUE defined_class;
3379 rb_print_undef_str(module, v);
3382 me = search_method(origin_class, name, &defined_class);
3384 me = search_method(
rb_cObject, name, &defined_class);
3387 if (UNDEFINED_METHOD_ENTRY_P(me) ||
3388 UNDEFINED_REFINED_METHOD_P(me->def)) {
3389 rb_print_undef(module, name, METHOD_VISI_UNDEF);
3392 if (module == defined_class || origin_class == defined_class) {
3393 switch (me->def->type) {
3394 case VM_METHOD_TYPE_ISEQ:
3395 if (ISEQ_BODY(me->def->body.iseq.
iseqptr)->param.flags.has_rest &&
3396 !ISEQ_BODY(me->def->body.iseq.
iseqptr)->param.flags.has_post &&
3397 !ISEQ_BODY(me->def->body.iseq.
iseqptr)->param.flags.has_kw &&
3398 !ISEQ_BODY(me->def->body.iseq.
iseqptr)->param.flags.has_kwrest) {
3399 ISEQ_BODY(me->def->body.iseq.
iseqptr)->param.flags.ruby2_keywords = 1;
3400 rb_clear_method_cache(module, name);
3403 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));
3406 case VM_METHOD_TYPE_BMETHOD: {
3407 VALUE procval = me->def->body.bmethod.proc;
3408 if (vm_block_handler_type(procval) == block_handler_type_proc) {
3409 procval = vm_proc_to_block_handler(VM_BH_TO_PROC(procval));
3412 if (vm_block_handler_type(procval) == block_handler_type_iseq) {
3414 const rb_iseq_t *iseq = rb_iseq_check(captured->code.iseq);
3415 if (ISEQ_BODY(iseq)->param.flags.has_rest &&
3416 !ISEQ_BODY(iseq)->param.flags.has_post &&
3417 !ISEQ_BODY(iseq)->param.flags.has_kw &&
3418 !ISEQ_BODY(iseq)->param.flags.has_kwrest) {
3419 ISEQ_BODY(iseq)->param.flags.ruby2_keywords = 1;
3420 rb_clear_method_cache(module, name);
3423 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));
3430 rb_warn(
"Skipping set of ruby2_keywords flag for %"PRIsVALUE
" (method not defined in Ruby)", QUOTE_ID(name));
3435 rb_warn(
"Skipping set of ruby2_keywords flag for %"PRIsVALUE
" (can only set in method defining module)", QUOTE_ID(name));
3454rb_mod_public_method(
int argc,
VALUE *argv,
VALUE obj)
3482rb_mod_private_method(
int argc,
VALUE *argv,
VALUE obj)
3506 return rb_mod_public(argc, argv, rb_top_main_class(
"public"));
3526 return rb_mod_private(argc, argv, rb_top_main_class(
"private"));
3543top_ruby2_keywords(
int argc,
VALUE *argv,
VALUE module)
3545 return rb_mod_ruby2_keywords(argc, argv, rb_top_main_class(
"ruby2_keywords"));
3601rb_mod_modfunc(
int argc,
VALUE *argv,
VALUE module)
3605 const rb_method_entry_t *me;
3608 rb_raise(
rb_eTypeError,
"module_function must be called for modules");
3612 rb_scope_module_func_set();
3616 set_method_visibility(module, argc, argv, METHOD_VISI_PRIVATE);
3618 for (i = 0; i < argc; i++) {
3623 me = search_method(m,
id, 0);
3627 if (UNDEFINED_METHOD_ENTRY_P(me)) {
3628 rb_print_undef(module,
id, METHOD_VISI_UNDEF);
3630 if (me->def->type != VM_METHOD_TYPE_ZSUPER) {
3646#pragma push_macro("rb_method_basic_definition_p")
3647#undef rb_method_basic_definition_p
3652 const rb_callable_method_entry_t *cme;
3653 if (!klass)
return TRUE;
3654 cme = rb_callable_method_entry(klass,
id);
3655 return (cme && METHOD_ENTRY_BASIC(cme)) ? TRUE : FALSE;
3658#pragma pop_macro("rb_method_basic_definition_p")
3662call_method_entry(rb_execution_context_t *ec,
VALUE defined_class,
VALUE obj,
ID id,
3663 const rb_callable_method_entry_t *cme,
int argc,
const VALUE *argv,
int kw_splat)
3665 VALUE passed_block_handler = vm_passed_block_handler(ec);
3666 VALUE result = rb_vm_call_kw(ec, obj,
id, argc, argv, cme, kw_splat);
3667 vm_passed_block_handler_set(ec, passed_block_handler);
3672basic_obj_respond_to_missing(rb_execution_context_t *ec,
VALUE klass,
VALUE obj,
3675 VALUE defined_class, args[2];
3676 const ID rtmid = idRespond_to_missing;
3677 const rb_callable_method_entry_t *
const cme = callable_method_entry(klass, rtmid, &defined_class);
3679 if (!cme || METHOD_ENTRY_BASIC(cme))
return Qundef;
3682 return call_method_entry(ec, defined_class, obj, rtmid, cme, 2, args,
RB_NO_KEYWORDS);
3686basic_obj_respond_to(rb_execution_context_t *ec,
VALUE obj,
ID id,
int pub)
3691 switch (method_boundp(klass,
id, pub|BOUND_RESPONDS)) {
3695 ret = basic_obj_respond_to_missing(ec, klass, obj,
ID2SYM(
id),
3697 return RTEST(ret) && !UNDEF_P(ret);
3704vm_respond_to(rb_execution_context_t *ec,
VALUE klass,
VALUE obj,
ID id,
int priv)
3706 VALUE defined_class;
3707 const ID resid = idRespond_to;
3708 const rb_callable_method_entry_t *
const cme = callable_method_entry(klass, resid, &defined_class);
3710 if (!cme)
return -1;
3711 if (METHOD_ENTRY_BASIC(cme)) {
3722 argc = rb_method_entry_arity((
const rb_method_entry_t *)cme);
3724 rb_raise(rb_eArgError,
3725 "respond_to? must accept 1 or 2 arguments (requires %d)",
3732 VALUE location = rb_method_entry_location((
const rb_method_entry_t *)cme);
3734 "%"PRIsVALUE
"%c""respond_to?(:%"PRIsVALUE
") uses"
3735 " the deprecated method signature, which takes one parameter",
3736 (RCLASS_SINGLETON_P(klass) ? obj : klass),
3737 (RCLASS_SINGLETON_P(klass) ?
'.' :
'#'),
3739 if (!
NIL_P(location)) {
3744 RSTRING_PTR(path),
NUM2INT(line),
3745 "respond_to? is defined here");
3750 result = call_method_entry(ec, defined_class, obj, resid, cme, argc, args,
RB_NO_KEYWORDS);
3751 return RTEST(result);
3758 rb_execution_context_t *ec = GET_EC();
3759 return rb_ec_obj_respond_to(ec, obj,
id, priv);
3763rb_ec_obj_respond_to(rb_execution_context_t *ec,
VALUE obj,
ID id,
int priv)
3766 int ret = vm_respond_to(ec, klass, obj,
id, priv);
3767 if (ret == -1) ret = basic_obj_respond_to(ec, obj,
id, !priv);
3799obj_respond_to(
int argc,
VALUE *argv,
VALUE obj)
3803 rb_execution_context_t *ec = GET_EC();
3807 VALUE ret = basic_obj_respond_to_missing(ec,
CLASS_OF(obj), obj,
3809 if (UNDEF_P(ret)) ret =
Qfalse;
3812 return RBOOL(basic_obj_respond_to(ec, obj,
id, !
RTEST(priv)));
3837method_uncached(
VALUE klass,
const char *name)
3839 rb_method_entry_t *me = lookup_method_table(klass, rb_intern(name));
3841 VM_ASSERT(me != NULL);
3842 me->def->uncached = 1;
3848Init_uncached_methods(
void)
3850 static const char *
const names[] = {
3851 "public",
"protected",
"private",
"module_function",
"ruby2_keywords",
3852 "alias_method",
"undef_method",
"remove_method",
3853 "attr_reader",
"attr_writer",
"attr_accessor",
3854 "include",
"prepend",
3857 for (
int i = 0; i < numberof(names); i++) {
3863Init_eval_method(
void)
3885 "public", top_public, -1);
3887 "private", top_private, -1);
3889 "ruby2_keywords", top_ruby2_keywords, -1);
3892#define REPLICATE_METHOD(klass, id) do { \
3893 const rb_method_entry_t *me = rb_method_entry((klass), (id)); \
3894 rb_method_entry_set((klass), (id), me, METHOD_ENTRY_VISI(me)); \
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 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 FL_SHAREABLE
Old name of RUBY_FL_SHAREABLE.
#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 INT2NUM
Old name of RB_INT2NUM.
#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 rb_notimplement()
#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.
#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.
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.
ID rb_frame_callee(void)
Identical to rb_frame_this_func(), except it returns the named used to call the method.
ID rb_frame_this_func(void)
Queries the name of the Ruby level method that is calling this function.
#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.
int st_foreach(st_table *q, int_type *w, st_data_t e)
Iteration over the given table.
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.
struct rb_data_type_struct rb_data_type_t
This is the struct that holds necessary info for a struct.
#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.
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.