11static int vm_redefinition_check_flag(
VALUE klass);
12static void rb_vm_check_redefinition_opt_method(
const rb_method_entry_t *me,
VALUE klass);
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
27vm_ccs_dump_i(
ID mid,
VALUE val,
void *data)
30 fprintf(stderr,
" | %s (len:%d) ", rb_id2name(mid), ccs->len);
33 for (
int i=0; i<ccs->len; i++) {
34 rp_m(
" | \t", ccs->entries[i].cc);
37 return ID_TABLE_CONTINUE;
41vm_ccs_dump(
VALUE klass,
ID target_mid)
47 if (rb_id_table_lookup(cc_tbl, target_mid, &ccs)) {
48 fprintf(stderr,
" [CCTB] %p\n", (
void *)cc_tbl);
49 vm_ccs_dump_i(target_mid, ccs, NULL);
53 fprintf(stderr,
" [CCTB] %p\n", (
void *)cc_tbl);
54 rb_id_table_foreach(cc_tbl, vm_ccs_dump_i, (
void *)target_mid);
59static enum rb_id_table_iterator_result
60vm_cme_dump_i(
ID mid,
VALUE val,
void *data)
62 ID target_mid = (
ID)data;
63 if (target_mid == 0 || mid == target_mid) {
66 return ID_TABLE_CONTINUE;
70vm_mtbl_dump(
VALUE klass,
ID target_mid)
72 fprintf(stderr,
"# vm_mtbl\n");
77 if (RCLASS_M_TBL(klass)) {
78 if (target_mid != 0) {
79 if (rb_id_table_lookup(RCLASS_M_TBL(klass), target_mid, &me)) {
84 fprintf(stderr,
" ## RCLASS_M_TBL (%p)\n", (
void *)RCLASS_M_TBL(klass));
85 rb_id_table_foreach(RCLASS_M_TBL(klass), vm_cme_dump_i, NULL);
89 fprintf(stderr,
" MTBL: NULL\n");
91 if (RCLASS_CALLABLE_M_TBL(klass)) {
92 if (target_mid != 0) {
93 if (rb_id_table_lookup(RCLASS_CALLABLE_M_TBL(klass), target_mid, &me)) {
98 fprintf(stderr,
" ## RCLASS_CALLABLE_M_TBL\n");
99 rb_id_table_foreach(RCLASS_CALLABLE_M_TBL(klass), vm_cme_dump_i, NULL);
102 if (RCLASS_CC_TBL(klass)) {
103 vm_ccs_dump(klass, target_mid);
111rb_vm_mtbl_dump(
const char *msg,
VALUE klass,
ID target_mid)
113 fprintf(stderr,
"[%s] ", msg);
114 vm_mtbl_dump(klass, target_mid);
118vm_cme_invalidate(rb_callable_method_entry_t *cme)
120 VM_ASSERT(IMEMO_TYPE_P(cme, imemo_ment),
"cme: %d", imemo_type((
VALUE)cme));
121 VM_ASSERT(callable_method_entry_p(cme));
122 METHOD_ENTRY_INVALIDATED_SET(cme);
123 RB_DEBUG_COUNTER_INC(cc_cme_invalidate);
125 rb_yjit_cme_invalidate(cme);
126 rb_rjit_cme_invalidate(cme);
130rb_clear_constant_cache_for_id_i(st_data_t ic, st_data_t idx, st_data_t arg)
132 ((IC) ic)->entry = NULL;
137void rb_clear_constant_cache(
void) {}
143 rb_vm_t *vm = GET_VM();
145 if (rb_id_table_lookup(vm->constant_cache,
id, &lookup_result)) {
146 st_table *ics = (st_table *)lookup_result;
147 st_foreach(ics, rb_clear_constant_cache_for_id_i, (st_data_t) NULL);
148 ruby_vm_constant_cache_invalidations += ics->num_entries;
151 rb_yjit_constant_state_changed(
id);
152 rb_rjit_constant_state_changed(
id);
156invalidate_negative_cache(
ID mid)
159 rb_vm_t *vm = GET_VM();
161 if (rb_id_table_lookup(vm->negative_cme_table, mid, &cme)) {
162 rb_id_table_delete(vm->negative_cme_table, mid);
163 vm_cme_invalidate((rb_callable_method_entry_t *)cme);
164 RB_DEBUG_COUNTER_INC(cc_invalidate_negative);
168const rb_method_entry_t * rb_method_entry_clone(
const rb_method_entry_t *src_me);
169static const rb_callable_method_entry_t *complemented_callable_method_entry(
VALUE klass,
ID id);
170static const rb_callable_method_entry_t *lookup_overloaded_cme(
const rb_callable_method_entry_t *cme);
174clear_method_cache_by_id_in_class(
VALUE klass,
ID mid)
177 if (rb_objspace_garbage_object_p(klass))
return;
180 if (LIKELY(RCLASS_SUBCLASSES(klass) == NULL)) {
188 if (cc_tbl && rb_id_table_lookup(cc_tbl, mid, &ccs_data)) {
190 rb_yjit_cme_invalidate((rb_callable_method_entry_t *)ccs->cme);
191 rb_rjit_cme_invalidate((rb_callable_method_entry_t *)ccs->cme);
192 if (
NIL_P(ccs->cme->owner)) invalidate_negative_cache(mid);
194 rb_id_table_delete(cc_tbl, mid);
195 RB_DEBUG_COUNTER_INC(cc_invalidate_leaf_ccs);
200 if ((cm_tbl = RCLASS_CALLABLE_M_TBL(klass)) != NULL) {
202 if (rb_yjit_enabled_p && rb_id_table_lookup(cm_tbl, mid, &cme)) {
203 rb_yjit_cme_invalidate((rb_callable_method_entry_t *)cme);
205 if (rb_rjit_enabled && rb_id_table_lookup(cm_tbl, mid, &cme)) {
206 rb_rjit_cme_invalidate((rb_callable_method_entry_t *)cme);
208 rb_id_table_delete(cm_tbl, mid);
209 RB_DEBUG_COUNTER_INC(cc_invalidate_leaf_callable);
211 RB_DEBUG_COUNTER_INC(cc_invalidate_leaf);
214 const rb_callable_method_entry_t *cme = complemented_callable_method_entry(klass, mid);
218 if (METHOD_ENTRY_CACHED(cme)) {
219 if (METHOD_ENTRY_COMPLEMENTED(cme)) {
224 VALUE owner = cme->owner;
225 VM_ASSERT_TYPE(owner,
T_CLASS);
226 VALUE klass_housing_cme;
227 if (cme->def->type == VM_METHOD_TYPE_REFINED && !cme->def->body.refined.orig_me) {
228 klass_housing_cme = owner;
231 klass_housing_cme = RCLASS_ORIGIN(owner);
234 VM_ASSERT(lookup_method_table(klass_housing_cme, mid) == (
const rb_method_entry_t *)cme);
235 const rb_method_entry_t *new_cme = rb_method_entry_clone((
const rb_method_entry_t *)cme);
236 rb_method_table_insert(klass_housing_cme, RCLASS_M_TBL(klass_housing_cme), mid, new_cme);
239 vm_cme_invalidate((rb_callable_method_entry_t *)cme);
240 RB_DEBUG_COUNTER_INC(cc_invalidate_tree_cme);
245 if (cme->def->type == VM_METHOD_TYPE_REFINED && cme->def->body.refined.orig_me) {
246 vm_cme_invalidate((rb_callable_method_entry_t *)cme->def->body.refined.orig_me);
249 if (cme->def->iseq_overload) {
250 rb_callable_method_entry_t *monly_cme = (rb_callable_method_entry_t *)lookup_overloaded_cme(cme);
252 vm_cme_invalidate(monly_cme);
258 if (METHOD_ENTRY_COMPLEMENTED(cme)) {
259 VALUE defined_class = cme->defined_class;
260 struct rb_id_table *cm_tbl = RCLASS_CALLABLE_M_TBL(defined_class);
261 VM_ASSERT(cm_tbl != NULL);
262 int r = rb_id_table_delete(cm_tbl, mid);
263 VM_ASSERT(r == TRUE); (void)r;
264 RB_DEBUG_COUNTER_INC(cc_invalidate_tree_callable);
267 RB_DEBUG_COUNTER_INC(cc_invalidate_tree);
270 invalidate_negative_cache(mid);
277clear_iclass_method_cache_by_id(
VALUE iclass,
VALUE d)
281 clear_method_cache_by_id_in_class(iclass, mid);
285clear_iclass_method_cache_by_id_for_refinements(
VALUE klass,
VALUE d)
289 clear_method_cache_by_id_in_class(klass, mid);
294rb_clear_method_cache(
VALUE klass_or_module,
ID mid)
297 VALUE module = klass_or_module;
299 if (
FL_TEST(module, RMODULE_IS_REFINEMENT)) {
300 VALUE refined_class = rb_refinement_module_get_refined_class(module);
301 rb_clear_method_cache(refined_class, mid);
302 rb_class_foreach_subclass(refined_class, clear_iclass_method_cache_by_id_for_refinements, mid);
303 rb_clear_all_refinement_method_cache();
305 rb_class_foreach_subclass(module, clear_iclass_method_cache_by_id, mid);
308 clear_method_cache_by_id_in_class(klass_or_module, mid);
313invalidate_all_refinement_cc(
void *vstart,
void *vend,
size_t stride,
void *data)
316 for (; v != (
VALUE)vend; v += stride) {
317 void *ptr = rb_asan_poisoned_object_p(v);
318 rb_asan_unpoison_object(v,
false);
321 if (imemo_type_p(v, imemo_callcache)) {
323 if (vm_cc_refinement_p(cc) && cc->klass) {
324 vm_cc_invalidate(cc);
330 rb_asan_poison_object(v);
345 for (
int i = 0; i < ci->kwarg->keyword_len; i++) {
357 if (ci1->mid != ci2->mid)
return 1;
358 if (ci1->flag != ci2->flag)
return 1;
359 if (ci1->argc != ci2->argc)
return 1;
360 if (ci1->kwarg != NULL) {
361 VM_ASSERT(ci2->kwarg != NULL);
363 if (ci1->kwarg->keyword_len != ci2->kwarg->keyword_len)
366 for (
int i = 0; i < ci1->kwarg->keyword_len; i++) {
367 if (ci1->kwarg->keywords[i] != ci2->kwarg->keywords[i]) {
372 VM_ASSERT(ci2->kwarg == NULL);
377static const struct st_hash_type vm_ci_hashtype = {
383ci_lookup_i(st_data_t *key, st_data_t *value, st_data_t data,
int existing)
386 st_data_t *ret = (st_data_t *)data;
389 if (rb_objspace_garbage_object_p((
VALUE)ci)) {
390 *ret = (st_data_t)NULL;
398 *key = *value = *ret = (st_data_t)ci;
404rb_vm_ci_lookup(
ID mid,
unsigned int flag,
unsigned int argc,
const struct rb_callinfo_kwarg *kwarg)
406 rb_vm_t *vm = GET_VM();
420 st_table *ci_table = vm->ci_table;
424 st_update(ci_table, (st_data_t)new_ci, ci_lookup_i, (st_data_t)&ci);
425 }
while (ci == NULL);
439 rb_vm_t *vm = GET_VM();
441 st_data_t key = (st_data_t)ci;
442 st_delete(vm->ci_table, &key, NULL);
446rb_clear_all_refinement_method_cache(
void)
448 rb_objspace_each_objects(invalidate_all_refinement_cc, NULL);
449 rb_yjit_invalidate_all_method_lookup_assumptions();
453rb_method_table_insert(
VALUE klass,
struct rb_id_table *table,
ID method_id,
const rb_method_entry_t *me)
455 VALUE table_owner = klass;
457 table_owner =
RBASIC(table_owner)->klass;
460 VM_ASSERT(table == RCLASS_M_TBL(table_owner));
461 rb_id_table_insert(table, method_id, (
VALUE)me);
470NORETURN(
static VALUE rb_f_notimplement_internal(
int argc,
const VALUE *argv,
VALUE obj));
473rb_f_notimplement_internal(
int argc,
const VALUE *argv,
VALUE obj)
483 rb_f_notimplement_internal(argc, argv, obj);
487rb_define_notimplement_method_id(
VALUE mod,
ID id, rb_method_visibility_t visi)
489 rb_add_method(mod,
id, VM_METHOD_TYPE_NOTIMPLEMENTED, (
void *)1, visi);
493rb_add_method_cfunc(
VALUE klass,
ID mid,
VALUE (*func)(
ANYARGS),
int argc, rb_method_visibility_t visi)
495 if (argc < -2 || 15 < argc) rb_raise(rb_eArgError,
"arity out of range: %d for -2..15", argc);
497 rb_method_cfunc_t opt;
500 rb_add_method(klass, mid, VM_METHOD_TYPE_CFUNC, &opt, visi);
503 rb_define_notimplement_method_id(klass, mid, visi);
508rb_add_method_optimized(
VALUE klass,
ID mid,
enum method_optimized_type opt_type,
unsigned int index, rb_method_visibility_t visi)
510 rb_method_optimized_t opt = {
514 rb_add_method(klass, mid, VM_METHOD_TYPE_OPTIMIZED, &opt, visi);
518rb_method_definition_release(rb_method_definition_t *def)
521 const int reference_count = def->reference_count;
522 def->reference_count--;
524 VM_ASSERT(reference_count >= 0);
526 if (def->reference_count == 0) {
527 if (METHOD_DEBUG) fprintf(stderr,
"-%p-%s:%d (remove)\n", (
void *)def,
528 rb_id2name(def->original_id), def->reference_count);
529 if (def->type == VM_METHOD_TYPE_BMETHOD && def->body.bmethod.hooks) {
530 xfree(def->body.bmethod.hooks);
535 if (METHOD_DEBUG) fprintf(stderr,
"-%p-%s:%d->%d (dec)\n", (
void *)def, rb_id2name(def->original_id),
536 reference_count, def->reference_count);
541static void delete_overloaded_cme(
const rb_callable_method_entry_t *cme);
544rb_free_method_entry_vm_weak_references(
const rb_method_entry_t *me)
546 if (me->def && me->def->iseq_overload) {
547 delete_overloaded_cme((
const rb_callable_method_entry_t *)me);
552rb_free_method_entry(
const rb_method_entry_t *me)
554 rb_method_definition_release(me->def);
557static inline rb_method_entry_t *search_method(
VALUE klass,
ID id,
VALUE *defined_class_ptr);
558extern int rb_method_definition_eq(
const rb_method_definition_t *d1,
const rb_method_definition_t *d2);
563 if (!GET_THREAD()->ext_config.ractor_safe) {
565 case -2:
return &call_cfunc_m2;
566 case -1:
return &call_cfunc_m1;
567 case 0:
return &call_cfunc_0;
568 case 1:
return &call_cfunc_1;
569 case 2:
return &call_cfunc_2;
570 case 3:
return &call_cfunc_3;
571 case 4:
return &call_cfunc_4;
572 case 5:
return &call_cfunc_5;
573 case 6:
return &call_cfunc_6;
574 case 7:
return &call_cfunc_7;
575 case 8:
return &call_cfunc_8;
576 case 9:
return &call_cfunc_9;
577 case 10:
return &call_cfunc_10;
578 case 11:
return &call_cfunc_11;
579 case 12:
return &call_cfunc_12;
580 case 13:
return &call_cfunc_13;
581 case 14:
return &call_cfunc_14;
582 case 15:
return &call_cfunc_15;
584 rb_bug(
"unsupported length: %d", argc);
589 case -2:
return &ractor_safe_call_cfunc_m2;
590 case -1:
return &ractor_safe_call_cfunc_m1;
591 case 0:
return &ractor_safe_call_cfunc_0;
592 case 1:
return &ractor_safe_call_cfunc_1;
593 case 2:
return &ractor_safe_call_cfunc_2;
594 case 3:
return &ractor_safe_call_cfunc_3;
595 case 4:
return &ractor_safe_call_cfunc_4;
596 case 5:
return &ractor_safe_call_cfunc_5;
597 case 6:
return &ractor_safe_call_cfunc_6;
598 case 7:
return &ractor_safe_call_cfunc_7;
599 case 8:
return &ractor_safe_call_cfunc_8;
600 case 9:
return &ractor_safe_call_cfunc_9;
601 case 10:
return &ractor_safe_call_cfunc_10;
602 case 11:
return &ractor_safe_call_cfunc_11;
603 case 12:
return &ractor_safe_call_cfunc_12;
604 case 13:
return &ractor_safe_call_cfunc_13;
605 case 14:
return &ractor_safe_call_cfunc_14;
606 case 15:
return &ractor_safe_call_cfunc_15;
608 rb_bug(
"unsupported length: %d", argc);
614setup_method_cfunc_struct(rb_method_cfunc_t *cfunc,
VALUE (*func)(
ANYARGS),
int argc)
618 cfunc->invoker = call_cfunc_invoker_func(argc);
621static rb_method_definition_t *
622method_definition_addref(rb_method_definition_t *def,
bool complemented)
624 if (!complemented && def->reference_count > 0) def->aliased =
true;
625 def->reference_count++;
626 if (METHOD_DEBUG) fprintf(stderr,
"+%p-%s:%d\n", (
void *)def, rb_id2name(def->original_id), def->reference_count);
631rb_method_definition_set(
const rb_method_entry_t *me, rb_method_definition_t *def,
void *opts)
633 rb_method_definition_release(me->def);
634 *(rb_method_definition_t **)&me->def = method_definition_addref(def, METHOD_ENTRY_COMPLEMENTED(me));
636 if (!ruby_running) add_opt_method_entry(me);
640 case VM_METHOD_TYPE_ISEQ:
642 rb_method_iseq_t *iseq_body = (rb_method_iseq_t *)opts;
643 const rb_iseq_t *iseq = iseq_body->
iseqptr;
644 rb_cref_t *method_cref, *cref = iseq_body->
cref;
650 if (rb_iseq_attr_p(iseq, BUILTIN_ATTR_C_TRACE)) {
651 METHOD_ENTRY_BASIC_SET((rb_method_entry_t *)me, TRUE);
654 if (ISEQ_BODY(iseq)->mandatory_only_iseq) def->iseq_overload = 1;
656 if (0) vm_cref_dump(
"rb_method_definition_create", cref);
662 method_cref = vm_cref_new_toplevel(GET_EC());
668 case VM_METHOD_TYPE_CFUNC:
670 rb_method_cfunc_t *cfunc = (rb_method_cfunc_t *)opts;
671 setup_method_cfunc_struct(UNALIGNED_MEMBER_PTR(def, body.cfunc), cfunc->func, cfunc->argc);
674 case VM_METHOD_TYPE_ATTRSET:
675 case VM_METHOD_TYPE_IVAR:
677 const rb_execution_context_t *ec = GET_EC();
678 rb_control_frame_t *cfp;
681 def->body.attr.id = (
ID)(
VALUE)opts;
683 cfp = rb_vm_get_ruby_level_next_cfp(ec, ec->cfp);
685 if (cfp && (line = rb_vm_get_sourceline(cfp))) {
687 RB_OBJ_WRITE(me, &def->body.attr.location, rb_ary_freeze(location));
690 VM_ASSERT(def->body.attr.location == 0);
694 case VM_METHOD_TYPE_BMETHOD:
696 RB_OBJ_WRITE(me, &def->body.bmethod.defined_ractor, rb_ractor_self(GET_RACTOR()));
698 case VM_METHOD_TYPE_NOTIMPLEMENTED:
699 setup_method_cfunc_struct(UNALIGNED_MEMBER_PTR(def, body.cfunc), (
VALUE(*)(
ANYARGS))rb_f_notimplement_internal, -1);
701 case VM_METHOD_TYPE_OPTIMIZED:
702 def->body.optimized = *(rb_method_optimized_t *)opts;
704 case VM_METHOD_TYPE_REFINED:
706 RB_OBJ_WRITE(me, &def->body.refined.orig_me, (rb_method_entry_t *)opts);
709 case VM_METHOD_TYPE_ALIAS:
710 RB_OBJ_WRITE(me, &def->body.alias.original_me, (rb_method_entry_t *)opts);
712 case VM_METHOD_TYPE_ZSUPER:
713 case VM_METHOD_TYPE_UNDEF:
714 case VM_METHOD_TYPE_MISSING:
721method_definition_reset(
const rb_method_entry_t *me)
723 rb_method_definition_t *def = me->def;
726 case VM_METHOD_TYPE_ISEQ:
730 case VM_METHOD_TYPE_ATTRSET:
731 case VM_METHOD_TYPE_IVAR:
734 case VM_METHOD_TYPE_BMETHOD:
738 if (def->body.bmethod.hooks) rb_gc_writebarrier_remember((
VALUE)me);
740 case VM_METHOD_TYPE_REFINED:
743 case VM_METHOD_TYPE_ALIAS:
746 case VM_METHOD_TYPE_CFUNC:
747 case VM_METHOD_TYPE_ZSUPER:
748 case VM_METHOD_TYPE_MISSING:
749 case VM_METHOD_TYPE_OPTIMIZED:
750 case VM_METHOD_TYPE_UNDEF:
751 case VM_METHOD_TYPE_NOTIMPLEMENTED:
756rb_method_definition_t *
757rb_method_definition_create(rb_method_type_t
type,
ID mid)
759 rb_method_definition_t *def;
760 def =
ZALLOC(rb_method_definition_t);
762 def->original_id = mid;
763 static uintptr_t method_serial = 1;
764 def->method_serial = method_serial++;
768static rb_method_entry_t *
769rb_method_entry_alloc(
ID called_id,
VALUE owner,
VALUE defined_class, rb_method_definition_t *def,
bool complement)
771 if (def) method_definition_addref(def, complement);
772 if (
RTEST(defined_class)) {
776 rb_method_entry_t *me = IMEMO_NEW(rb_method_entry_t, imemo_ment, defined_class);
777 *((rb_method_definition_t **)&me->def) = def;
778 me->called_id = called_id;
785filter_defined_class(
VALUE klass)
797 rb_bug(
"filter_defined_class: %s", rb_obj_info(klass));
801rb_method_entry_create(
ID called_id,
VALUE klass, rb_method_visibility_t visi, rb_method_definition_t *def)
803 rb_method_entry_t *me = rb_method_entry_alloc(called_id, klass, filter_defined_class(klass), def,
false);
804 METHOD_ENTRY_FLAGS_SET(me, visi, ruby_running ? FALSE : TRUE);
805 if (def != NULL) method_definition_reset(me);
810const rb_method_entry_t *
811rb_method_entry_clone(
const rb_method_entry_t *src_me)
813 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));
815 METHOD_ENTRY_FLAGS_COPY(me, src_me);
819 src_me->def->type == VM_METHOD_TYPE_REFINED &&
820 src_me->def->body.refined.orig_me) {
821 const rb_method_entry_t *orig_me = src_me->def->body.refined.orig_me;
822 VM_ASSERT(orig_me->def->type != VM_METHOD_TYPE_REFINED);
824 rb_method_entry_t *orig_clone = rb_method_entry_alloc(orig_me->called_id,
825 orig_me->owner, orig_me->defined_class, orig_me->def, METHOD_ENTRY_COMPLEMENTED(orig_me));
826 METHOD_ENTRY_FLAGS_COPY(orig_clone, orig_me);
830 rb_method_definition_t *clone_def =
831 rb_method_definition_create(VM_METHOD_TYPE_REFINED, src_me->called_id);
832 rb_method_definition_set(me, clone_def, orig_clone);
837const rb_callable_method_entry_t *
838rb_method_entry_complement_defined_class(
const rb_method_entry_t *src_me,
ID called_id,
VALUE defined_class)
840 rb_method_definition_t *def = src_me->def;
841 rb_method_entry_t *me;
842 const rb_method_entry_t *refined_orig_me = NULL;
844 if (!src_me->defined_class &&
845 def->type == VM_METHOD_TYPE_REFINED &&
846 def->body.refined.orig_me) {
847 const rb_method_entry_t *orig_me =
848 rb_method_entry_clone(def->body.refined.orig_me);
850 refined_orig_me = orig_me;
854 me = rb_method_entry_alloc(called_id, src_me->owner, defined_class, def,
true);
855 METHOD_ENTRY_FLAGS_COPY(me, src_me);
856 METHOD_ENTRY_COMPLEMENTED_SET(me);
858 def = rb_method_definition_create(VM_METHOD_TYPE_REFINED, called_id);
859 rb_method_definition_set(me, def, (
void *)refined_orig_me);
862 VM_ASSERT_TYPE(me->owner,
T_MODULE);
864 return (rb_callable_method_entry_t *)me;
868rb_method_entry_copy(rb_method_entry_t *dst,
const rb_method_entry_t *src)
870 rb_method_definition_release(dst->def);
871 *(rb_method_definition_t **)&dst->def = method_definition_addref(src->def, METHOD_ENTRY_COMPLEMENTED(src));
872 method_definition_reset(dst);
873 dst->called_id = src->called_id;
876 METHOD_ENTRY_FLAGS_COPY(dst, src);
880make_method_entry_refined(
VALUE owner, rb_method_entry_t *me)
882 if (me->def->type == VM_METHOD_TYPE_REFINED) {
886 rb_method_definition_t *def;
888 rb_vm_check_redefinition_opt_method(me, me->owner);
891 rb_method_entry_alloc(me->called_id,
896 METHOD_ENTRY_FLAGS_COPY(orig_me, me);
898 def = rb_method_definition_create(VM_METHOD_TYPE_REFINED, me->called_id);
899 rb_method_definition_set(me, def, orig_me);
900 METHOD_ENTRY_VISI_SET(me, METHOD_VISI_PUBLIC);
904static inline rb_method_entry_t *
905lookup_method_table(
VALUE klass,
ID id)
910 if (rb_id_table_lookup(m_tbl,
id, &body)) {
911 return (rb_method_entry_t *) body;
919rb_add_refined_method_entry(
VALUE refined_class,
ID mid)
921 rb_method_entry_t *me = lookup_method_table(refined_class, mid);
924 make_method_entry_refined(refined_class, me);
925 rb_clear_method_cache(refined_class, mid);
928 rb_add_method(refined_class, mid, VM_METHOD_TYPE_REFINED, 0, METHOD_VISI_PUBLIC);
933check_override_opt_method_i(
VALUE klass,
VALUE arg)
936 const rb_method_entry_t *me, *newme;
938 if (vm_redefinition_check_flag(klass)) {
939 me = lookup_method_table(RCLASS_ORIGIN(klass), mid);
941 newme = rb_method_entry(klass, mid);
942 if (newme != me) rb_vm_check_redefinition_opt_method(me, me->owner);
945 rb_class_foreach_subclass(klass, check_override_opt_method_i, (
VALUE)mid);
949check_override_opt_method(
VALUE klass,
VALUE mid)
951 if (rb_vm_check_optimizable_mid(mid)) {
952 check_override_opt_method_i(klass, mid);
956static inline rb_method_entry_t* search_method0(
VALUE klass,
ID id,
VALUE *defined_class_ptr,
bool skip_refined);
963static rb_method_entry_t *
964rb_method_entry_make(
VALUE klass,
ID mid,
VALUE defined_class, rb_method_visibility_t visi,
965 rb_method_type_t
type, rb_method_definition_t *def,
ID original_id,
void *opts)
967 rb_method_entry_t *me;
970 int make_refined = 0;
978 if (!RCLASS_SINGLETON_P(klass) &&
979 type != VM_METHOD_TYPE_NOTIMPLEMENTED &&
980 type != VM_METHOD_TYPE_ZSUPER) {
983 case idInitialize_copy:
984 case idInitialize_clone:
985 case idInitialize_dup:
986 case idRespond_to_missing:
987 visi = METHOD_VISI_PRIVATE;
991 if (
type != VM_METHOD_TYPE_REFINED) {
996 VALUE refined_class = rb_refinement_module_get_refined_class(klass);
997 bool search_superclass =
type == VM_METHOD_TYPE_ZSUPER && !lookup_method_table(refined_class, mid);
998 rb_add_refined_method_entry(refined_class, mid);
999 if (search_superclass) {
1000 rb_method_entry_t *me = lookup_method_table(refined_class, mid);
1001 me->def->body.refined.orig_me = search_method0(refined_class, mid, NULL,
true);
1004 if (
type == VM_METHOD_TYPE_REFINED) {
1005 rb_method_entry_t *old_me = lookup_method_table(RCLASS_ORIGIN(klass), mid);
1006 if (old_me) rb_vm_check_redefinition_opt_method(old_me, klass);
1009 klass = RCLASS_ORIGIN(klass);
1010 if (klass != orig_klass) {
1011 rb_clear_method_cache(orig_klass, mid);
1014 mtbl = RCLASS_M_TBL(klass);
1017 if (rb_id_table_lookup(mtbl, mid, &data)) {
1018 rb_method_entry_t *old_me = (rb_method_entry_t *)data;
1019 rb_method_definition_t *old_def = old_me->def;
1021 if (rb_method_definition_eq(old_def, def))
return old_me;
1022 rb_vm_check_redefinition_opt_method(old_me, klass);
1024 if (old_def->type == VM_METHOD_TYPE_REFINED) make_refined = 1;
1027 type != VM_METHOD_TYPE_UNDEF &&
1028 (old_def->aliased ==
false) &&
1029 (!old_def->no_redef_warning) &&
1031 old_def->type != VM_METHOD_TYPE_UNDEF &&
1032 old_def->type != VM_METHOD_TYPE_ZSUPER &&
1033 old_def->type != VM_METHOD_TYPE_ALIAS) {
1034 const rb_iseq_t *iseq = 0;
1036 switch (old_def->type) {
1037 case VM_METHOD_TYPE_ISEQ:
1038 iseq = def_iseq_ptr(old_def);
1040 case VM_METHOD_TYPE_BMETHOD:
1041 iseq = rb_proc_get_iseq(old_def->body.bmethod.proc, 0);
1048 "method redefined; discarding old %"PRIsVALUE
"\n%s:%d: warning: previous definition of %"PRIsVALUE
" was here",
1050 RSTRING_PTR(rb_iseq_path(iseq)),
1051 ISEQ_BODY(iseq)->location.first_lineno,
1052 rb_id2str(old_def->original_id)
1056 rb_warning(
"method redefined; discarding old %"PRIsVALUE, rb_id2str(mid));
1062 me = rb_method_entry_create(mid, defined_class, visi, NULL);
1064 def = rb_method_definition_create(
type, original_id);
1066 rb_method_definition_set(me, def, opts);
1068 rb_clear_method_cache(klass, mid);
1071 if (klass == rb_cObject) {
1074 case idRespond_to_missing:
1075 case idMethodMissing:
1077 rb_warn(
"redefining Object#%s may cause infinite loop", rb_id2name(mid));
1081 if (mid == object_id || mid == id__id__ || mid == id__send__) {
1082 if (
type != VM_METHOD_TYPE_CFUNC && search_method(klass, mid, 0)) {
1083 rb_warn(
"redefining '%s' may cause serious problems", rb_id2name(mid));
1088 make_method_entry_refined(klass, me);
1091 rb_method_table_insert(klass, mtbl, mid, me);
1093 VM_ASSERT(me->def != NULL);
1097 check_override_opt_method(klass, (
VALUE)mid);
1104overloaded_cme_table(
void)
1106 VM_ASSERT(GET_VM()->overloaded_cme_table != NULL);
1107 return GET_VM()->overloaded_cme_table;
1110#if VM_CHECK_MODE > 0
1112vm_dump_overloaded_cme_table(st_data_t key, st_data_t val, st_data_t dmy)
1114 fprintf(stderr,
"key: "); rp(key);
1115 fprintf(stderr,
"val: "); rp(val);
1120rb_vm_dump_overloaded_cme_table(
void)
1122 fprintf(stderr,
"== rb_vm_dump_overloaded_cme_table\n");
1123 st_foreach(overloaded_cme_table(), vm_dump_overloaded_cme_table, 0);
1128lookup_overloaded_cme_i(st_data_t *key, st_data_t *value, st_data_t data,
int existing)
1131 const rb_callable_method_entry_t *cme = (
const rb_callable_method_entry_t *)*key;
1132 const rb_callable_method_entry_t *monly_cme = (
const rb_callable_method_entry_t *)*value;
1133 const rb_callable_method_entry_t **ptr = (
const rb_callable_method_entry_t **)data;
1135 if (rb_objspace_garbage_object_p((
VALUE)cme) ||
1136 rb_objspace_garbage_object_p((
VALUE)monly_cme)) {
1148static const rb_callable_method_entry_t *
1149lookup_overloaded_cme(
const rb_callable_method_entry_t *cme)
1151 ASSERT_vm_locking();
1153 const rb_callable_method_entry_t *monly_cme = NULL;
1154 st_update(overloaded_cme_table(), (st_data_t)cme, lookup_overloaded_cme_i, (st_data_t)&monly_cme);
1158#if VM_CHECK_MODE > 0
1159const rb_callable_method_entry_t *
1160rb_vm_lookup_overloaded_cme(
const rb_callable_method_entry_t *cme)
1162 return lookup_overloaded_cme(cme);
1167delete_overloaded_cme(
const rb_callable_method_entry_t *cme)
1169 st_data_t cme_data = (st_data_t)cme;
1170 ASSERT_vm_locking();
1171 st_delete(overloaded_cme_table(), &cme_data, NULL);
1174static const rb_callable_method_entry_t *
1175get_overloaded_cme(
const rb_callable_method_entry_t *cme)
1177 const rb_callable_method_entry_t *monly_cme = lookup_overloaded_cme(cme);
1179 if (monly_cme && !METHOD_ENTRY_INVALIDATED(monly_cme)) {
1184 rb_method_definition_t *def = rb_method_definition_create(VM_METHOD_TYPE_ISEQ, cme->def->original_id);
1185 rb_method_entry_t *me = rb_method_entry_alloc(cme->called_id,
1194 ASSERT_vm_locking();
1195 st_insert(overloaded_cme_table(), (st_data_t)cme, (st_data_t)me);
1197 METHOD_ENTRY_VISI_SET(me, METHOD_ENTRY_VISI(cme));
1198 return (rb_callable_method_entry_t *)me;
1202const rb_callable_method_entry_t *
1203rb_check_overloaded_cme(
const rb_callable_method_entry_t *cme,
const struct rb_callinfo *
const ci)
1205 if (UNLIKELY(cme->def->iseq_overload) &&
1206 (vm_ci_flag(ci) & (VM_CALL_ARGS_SIMPLE)) &&
1207 (!(vm_ci_flag(ci) & VM_CALL_FORWARDING)) &&
1208 (
int)vm_ci_argc(ci) == ISEQ_BODY(method_entry_iseqptr(cme))->param.lead_num) {
1209 VM_ASSERT(cme->def->type == VM_METHOD_TYPE_ISEQ,
"type: %d", cme->def->type);
1211 cme = get_overloaded_cme(cme);
1213 VM_ASSERT(cme != NULL);
1220#define CALL_METHOD_HOOK(klass, hook, mid) do { \
1221 const VALUE arg = ID2SYM(mid); \
1222 VALUE recv_class = (klass); \
1223 ID hook_id = (hook); \
1224 if (RCLASS_SINGLETON_P((klass))) { \
1225 recv_class = RCLASS_ATTACHED_OBJECT((klass)); \
1226 hook_id = singleton_##hook; \
1228 rb_funcallv(recv_class, hook_id, 1, &arg); \
1232method_added(
VALUE klass,
ID mid)
1235 CALL_METHOD_HOOK(klass, added, mid);
1240rb_add_method(
VALUE klass,
ID mid, rb_method_type_t
type,
void *opts, rb_method_visibility_t visi)
1242 rb_method_entry_make(klass, mid, klass, visi,
type, NULL, mid, opts);
1244 if (
type != VM_METHOD_TYPE_UNDEF &&
type != VM_METHOD_TYPE_REFINED) {
1245 method_added(klass, mid);
1250rb_add_method_iseq(
VALUE klass,
ID mid,
const rb_iseq_t *iseq, rb_cref_t *cref, rb_method_visibility_t visi)
1253 const rb_iseq_t *iseqptr;
1258 iseq_body.
cref = cref;
1260 rb_add_method(klass, mid, VM_METHOD_TYPE_ISEQ, &iseq_body, visi);
1263static rb_method_entry_t *
1264method_entry_set(
VALUE klass,
ID mid,
const rb_method_entry_t *me,
1265 rb_method_visibility_t visi,
VALUE defined_class)
1267 rb_method_entry_t *newme = rb_method_entry_make(klass, mid, defined_class, visi,
1268 me->def->type, me->def, 0, NULL);
1270 me->def->no_redef_warning = TRUE;
1271 METHOD_ENTRY_FLAGS_SET(newme, visi, FALSE);
1274 method_added(klass, mid);
1279rb_method_entry_set(
VALUE klass,
ID mid,
const rb_method_entry_t *me, rb_method_visibility_t visi)
1281 return method_entry_set(klass, mid, me, visi, klass);
1284#define UNDEF_ALLOC_FUNC ((rb_alloc_func_t)-1)
1290 if (RCLASS_SINGLETON_P(klass)) {
1291 rb_raise(
rb_eTypeError,
"can't define an allocator for a singleton class");
1293 RCLASS_SET_ALLOCATOR(klass, func);
1309 if (allocator == UNDEF_ALLOC_FUNC)
break;
1310 if (allocator)
return allocator;
1315const rb_method_entry_t *
1316rb_method_entry_at(
VALUE klass,
ID id)
1318 return lookup_method_table(klass,
id);
1321static inline rb_method_entry_t*
1322search_method0(
VALUE klass,
ID id,
VALUE *defined_class_ptr,
bool skip_refined)
1324 rb_method_entry_t *me = NULL;
1326 RB_DEBUG_COUNTER_INC(mc_search);
1329 RB_DEBUG_COUNTER_INC(mc_search_super);
1330 if ((me = lookup_method_table(klass,
id)) != 0) {
1331 if (!skip_refined || me->def->type != VM_METHOD_TYPE_REFINED ||
1332 me->def->body.refined.orig_me) {
1338 if (defined_class_ptr) *defined_class_ptr = klass;
1340 if (me == NULL) RB_DEBUG_COUNTER_INC(mc_search_notfound);
1342 VM_ASSERT(me == NULL || !METHOD_ENTRY_INVALIDATED(me));
1346static inline rb_method_entry_t*
1347search_method(
VALUE klass,
ID id,
VALUE *defined_class_ptr)
1349 return search_method0(klass,
id, defined_class_ptr,
false);
1352static rb_method_entry_t *
1353search_method_protect(
VALUE klass,
ID id,
VALUE *defined_class_ptr)
1355 rb_method_entry_t *me = search_method(klass,
id, defined_class_ptr);
1357 if (!UNDEFINED_METHOD_ENTRY_P(me)) {
1365const rb_method_entry_t *
1366rb_method_entry(
VALUE klass,
ID id)
1368 return search_method_protect(klass,
id, NULL);
1371static inline const rb_callable_method_entry_t *
1372prepare_callable_method_entry(
VALUE defined_class,
ID id,
const rb_method_entry_t *
const me,
int create)
1375 const rb_callable_method_entry_t *cme;
1379 if (me->defined_class == 0) {
1380 RB_DEBUG_COUNTER_INC(mc_cme_complement);
1382 VM_ASSERT(me->defined_class == 0,
"me->defined_class: %s", rb_obj_info(me->defined_class));
1384 mtbl = RCLASS_CALLABLE_M_TBL(defined_class);
1386 if (mtbl && rb_id_table_lookup(mtbl,
id, &cme_data)) {
1387 cme = (rb_callable_method_entry_t *)cme_data;
1388 RB_DEBUG_COUNTER_INC(mc_cme_complement_hit);
1389 VM_ASSERT(callable_method_entry_p(cme));
1390 VM_ASSERT(!METHOD_ENTRY_INVALIDATED(cme));
1394 mtbl = RCLASS_EXT(defined_class)->callable_m_tbl = rb_id_table_create(0);
1396 cme = rb_method_entry_complement_defined_class(me, me->called_id, defined_class);
1397 rb_id_table_insert(mtbl,
id, (
VALUE)cme);
1399 VM_ASSERT(callable_method_entry_p(cme));
1406 cme = (
const rb_callable_method_entry_t *)me;
1407 VM_ASSERT(callable_method_entry_p(cme));
1408 VM_ASSERT(!METHOD_ENTRY_INVALIDATED(cme));
1417static const rb_callable_method_entry_t *
1418complemented_callable_method_entry(
VALUE klass,
ID id)
1420 VALUE defined_class;
1421 rb_method_entry_t *me = search_method(klass,
id, &defined_class);
1422 return prepare_callable_method_entry(defined_class,
id, me, FALSE);
1425static const rb_callable_method_entry_t *
1426cached_callable_method_entry(
VALUE klass,
ID mid)
1428 ASSERT_vm_locking();
1430 struct rb_id_table *cc_tbl = RCLASS_CC_TBL(klass);
1433 if (cc_tbl && rb_id_table_lookup(cc_tbl, mid, &ccs_data)) {
1435 VM_ASSERT(vm_ccs_p(ccs));
1437 if (LIKELY(!METHOD_ENTRY_INVALIDATED(ccs->cme))) {
1438 VM_ASSERT(ccs->cme->called_id == mid);
1439 RB_DEBUG_COUNTER_INC(ccs_found);
1443 rb_vm_ccs_free(ccs);
1444 rb_id_table_delete(cc_tbl, mid);
1448 RB_DEBUG_COUNTER_INC(ccs_not_found);
1453cache_callable_method_entry(
VALUE klass,
ID mid,
const rb_callable_method_entry_t *cme)
1455 ASSERT_vm_locking();
1456 VM_ASSERT(cme != NULL);
1458 struct rb_id_table *cc_tbl = RCLASS_CC_TBL(klass);
1462 cc_tbl = RCLASS_CC_TBL(klass) = rb_id_table_create(2);
1465 if (rb_id_table_lookup(cc_tbl, mid, &ccs_data)) {
1466#if VM_CHECK_MODE > 0
1468 VM_ASSERT(ccs->cme == cme);
1472 vm_ccs_create(klass, cc_tbl, mid, cme);
1476static const rb_callable_method_entry_t *
1479 rb_vm_t *vm = GET_VM();
1480 const rb_callable_method_entry_t *cme;
1483 if (rb_id_table_lookup(vm->negative_cme_table, mid, &cme_data)) {
1484 cme = (rb_callable_method_entry_t *)cme_data;
1487 cme = (rb_callable_method_entry_t *)rb_method_entry_alloc(mid,
Qnil,
Qnil, NULL,
false);
1488 rb_id_table_insert(vm->negative_cme_table, mid, (
VALUE)cme);
1491 VM_ASSERT(cme != NULL);
1495static const rb_callable_method_entry_t *
1496callable_method_entry_or_negative(
VALUE klass,
ID mid,
VALUE *defined_class_ptr)
1498 const rb_callable_method_entry_t *cme;
1503 cme = cached_callable_method_entry(klass, mid);
1506 if (defined_class_ptr != NULL) *defined_class_ptr = cme->defined_class;
1509 VALUE defined_class;
1510 rb_method_entry_t *me = search_method(klass, mid, &defined_class);
1511 if (defined_class_ptr) *defined_class_ptr = defined_class;
1514 cme = prepare_callable_method_entry(defined_class, mid, me, TRUE);
1517 cme = negative_cme(mid);
1520 cache_callable_method_entry(klass, mid, cme);
1530const rb_callable_method_entry_t *
1531rb_callable_method_entry_or_negative(
VALUE klass,
ID mid)
1533 return callable_method_entry_or_negative(klass, mid, NULL);
1536static const rb_callable_method_entry_t *
1537callable_method_entry(
VALUE klass,
ID mid,
VALUE *defined_class_ptr)
1539 const rb_callable_method_entry_t *cme;
1540 cme = callable_method_entry_or_negative(klass, mid, defined_class_ptr);
1541 return !UNDEFINED_METHOD_ENTRY_P(cme) ? cme : NULL;
1544const rb_callable_method_entry_t *
1545rb_callable_method_entry(
VALUE klass,
ID mid)
1547 return callable_method_entry(klass, mid, NULL);
1550static const rb_method_entry_t *resolve_refined_method(
VALUE refinements,
const rb_method_entry_t *me,
VALUE *defined_class_ptr);
1552static const rb_method_entry_t *
1553method_entry_resolve_refinement(
VALUE klass,
ID id,
int with_refinement,
VALUE *defined_class_ptr)
1555 const rb_method_entry_t *me = search_method_protect(klass,
id, defined_class_ptr);
1558 if (me->def->type == VM_METHOD_TYPE_REFINED) {
1559 if (with_refinement) {
1560 const rb_cref_t *cref = rb_vm_cref();
1561 VALUE refinements = cref ? CREF_REFINEMENTS(cref) :
Qnil;
1562 me = resolve_refined_method(refinements, me, defined_class_ptr);
1565 me = resolve_refined_method(
Qnil, me, defined_class_ptr);
1568 if (UNDEFINED_METHOD_ENTRY_P(me)) me = NULL;
1575const rb_method_entry_t *
1576rb_method_entry_with_refinements(
VALUE klass,
ID id,
VALUE *defined_class_ptr)
1578 return method_entry_resolve_refinement(klass,
id, TRUE, defined_class_ptr);
1581static const rb_callable_method_entry_t *
1582callable_method_entry_refinements0(
VALUE klass,
ID id,
VALUE *defined_class_ptr,
bool with_refinements,
1583 const rb_callable_method_entry_t *cme)
1585 if (cme == NULL || LIKELY(cme->def->type != VM_METHOD_TYPE_REFINED)) {
1589 VALUE defined_class, *dcp = defined_class_ptr ? defined_class_ptr : &defined_class;
1590 const rb_method_entry_t *me = method_entry_resolve_refinement(klass,
id, with_refinements, dcp);
1591 return prepare_callable_method_entry(*dcp,
id, me, TRUE);
1595static const rb_callable_method_entry_t *
1596callable_method_entry_refinements(
VALUE klass,
ID id,
VALUE *defined_class_ptr,
bool with_refinements)
1598 const rb_callable_method_entry_t *cme = callable_method_entry(klass,
id, defined_class_ptr);
1599 return callable_method_entry_refinements0(klass,
id, defined_class_ptr, with_refinements, cme);
1602const rb_callable_method_entry_t *
1603rb_callable_method_entry_with_refinements(
VALUE klass,
ID id,
VALUE *defined_class_ptr)
1605 return callable_method_entry_refinements(klass,
id, defined_class_ptr,
true);
1608static const rb_callable_method_entry_t *
1609callable_method_entry_without_refinements(
VALUE klass,
ID id,
VALUE *defined_class_ptr)
1611 return callable_method_entry_refinements(klass,
id, defined_class_ptr,
false);
1614const rb_method_entry_t *
1615rb_method_entry_without_refinements(
VALUE klass,
ID id,
VALUE *defined_class_ptr)
1617 return method_entry_resolve_refinement(klass,
id, FALSE, defined_class_ptr);
1620const rb_callable_method_entry_t *
1621rb_callable_method_entry_without_refinements(
VALUE klass,
ID id,
VALUE *defined_class_ptr)
1623 VALUE defined_class, *dcp = defined_class_ptr ? defined_class_ptr : &defined_class;
1624 const rb_method_entry_t *me = method_entry_resolve_refinement(klass,
id, FALSE, dcp);
1625 return prepare_callable_method_entry(*dcp,
id, me, TRUE);
1628static const rb_method_entry_t *
1629resolve_refined_method(
VALUE refinements,
const rb_method_entry_t *me,
VALUE *defined_class_ptr)
1631 while (me && me->def->type == VM_METHOD_TYPE_REFINED) {
1633 const rb_method_entry_t *tmp_me;
1636 refinement = find_refinement(refinements, me->owner);
1637 if (!
NIL_P(refinement)) {
1638 tmp_me = search_method_protect(refinement, me->called_id, defined_class_ptr);
1640 if (tmp_me && tmp_me->def->type != VM_METHOD_TYPE_REFINED) {
1645 tmp_me = me->def->body.refined.orig_me;
1647 if (!tmp_me->defined_class) {
1648 VM_ASSERT_TYPE(tmp_me->owner,
T_MODULE);
1650 else if (defined_class_ptr) {
1651 *defined_class_ptr = tmp_me->defined_class;
1661 me = search_method_protect(super, me->called_id, defined_class_ptr);
1666const rb_method_entry_t *
1667rb_resolve_refined_method(
VALUE refinements,
const rb_method_entry_t *me)
1669 return resolve_refined_method(refinements, me, NULL);
1672const rb_callable_method_entry_t *
1673rb_resolve_refined_method_callable(
VALUE refinements,
const rb_callable_method_entry_t *me)
1675 VALUE defined_class = me->defined_class;
1676 const rb_method_entry_t *resolved_me = resolve_refined_method(refinements, (
const rb_method_entry_t *)me, &defined_class);
1678 if (resolved_me && resolved_me->defined_class == 0) {
1679 return rb_method_entry_complement_defined_class(resolved_me, me->called_id, defined_class);
1682 return (
const rb_callable_method_entry_t *)resolved_me;
1687remove_method(
VALUE klass,
ID mid)
1690 rb_method_entry_t *me = 0;
1694 klass = RCLASS_ORIGIN(klass);
1695 if (mid == object_id || mid == id__id__ || mid == id__send__ || mid == idInitialize) {
1696 rb_warn(
"removing '%s' may cause serious problems", rb_id2name(mid));
1699 if (!rb_id_table_lookup(RCLASS_M_TBL(klass), mid, &data) ||
1700 !(me = (rb_method_entry_t *)data) ||
1701 (!me->def || me->def->type == VM_METHOD_TYPE_UNDEF) ||
1702 UNDEFINED_REFINED_METHOD_P(me->def)) {
1703 rb_name_err_raise(
"method '%1$s' not defined in %2$s",
1707 if (klass != self) {
1708 rb_clear_method_cache(self, mid);
1710 rb_clear_method_cache(klass, mid);
1711 rb_id_table_delete(RCLASS_M_TBL(klass), mid);
1713 rb_vm_check_redefinition_opt_method(me, klass);
1715 if (me->def->type == VM_METHOD_TYPE_REFINED) {
1716 rb_add_refined_method_entry(klass, mid);
1719 CALL_METHOD_HOOK(self, removed, mid);
1725 remove_method(klass, mid);
1731 remove_method(klass, rb_intern(name));
1745rb_mod_remove_method(
int argc,
VALUE *argv,
VALUE mod)
1749 for (i = 0; i < argc; i++) {
1753 rb_name_err_raise(
"method '%1$s' not defined in %2$s",
1756 remove_method(mod,
id);
1762rb_export_method(
VALUE klass,
ID name, rb_method_visibility_t visi)
1764 rb_method_entry_t *me;
1765 VALUE defined_class;
1766 VALUE origin_class = RCLASS_ORIGIN(klass);
1768 me = search_method0(origin_class, name, &defined_class,
true);
1771 me = search_method(rb_cObject, name, &defined_class);
1774 if (UNDEFINED_METHOD_ENTRY_P(me) ||
1775 UNDEFINED_REFINED_METHOD_P(me->def)) {
1776 rb_print_undef(klass, name, METHOD_VISI_UNDEF);
1779 if (METHOD_ENTRY_VISI(me) != visi) {
1780 rb_vm_check_redefinition_opt_method(me, klass);
1782 if (klass == defined_class || origin_class == defined_class) {
1783 if (me->def->type == VM_METHOD_TYPE_REFINED) {
1786 if (me->def->body.refined.orig_me) {
1787 METHOD_ENTRY_VISI_SET((rb_method_entry_t *)me->def->body.refined.orig_me, visi);
1791 METHOD_ENTRY_VISI_SET(me, visi);
1793 rb_clear_method_cache(klass, name);
1796 rb_add_method(klass, name, VM_METHOD_TYPE_ZSUPER, 0, visi);
1801#define BOUND_PRIVATE 0x01
1802#define BOUND_RESPONDS 0x02
1805method_boundp(
VALUE klass,
ID id,
int ex)
1807 const rb_callable_method_entry_t *cme;
1811 if (ex & BOUND_RESPONDS) {
1812 cme = rb_callable_method_entry_with_refinements(klass,
id, NULL);
1815 cme = callable_method_entry_without_refinements(klass,
id, NULL);
1819 if (ex & ~BOUND_RESPONDS) {
1820 switch (METHOD_ENTRY_VISI(cme)) {
1821 case METHOD_VISI_PRIVATE:
1823 case METHOD_VISI_PROTECTED:
1824 if (ex & BOUND_RESPONDS)
return 0;
1830 if (cme->def->type == VM_METHOD_TYPE_NOTIMPLEMENTED) {
1831 if (ex & BOUND_RESPONDS)
return 2;
1843 return method_boundp(klass,
id, ex);
1847vm_cref_set_visibility(rb_method_visibility_t method_visi,
int module_func)
1849 rb_scope_visibility_t *scope_visi = (rb_scope_visibility_t *)&rb_vm_cref()->scope_visi;
1850 scope_visi->method_visi = method_visi;
1851 scope_visi->module_func = module_func;
1855rb_scope_visibility_set(rb_method_visibility_t visi)
1857 vm_cref_set_visibility(visi, FALSE);
1861scope_visibility_check(
void)
1864 rb_control_frame_t *cfp = GET_EC()->cfp+1;
1865 if (cfp && cfp->iseq && ISEQ_BODY(cfp->iseq)->type == ISEQ_TYPE_METHOD) {
1866 rb_warn(
"calling %s without arguments inside a method may not have the intended effect",
1872rb_scope_module_func_set(
void)
1874 scope_visibility_check();
1875 vm_cref_set_visibility(METHOD_VISI_PRIVATE, TRUE);
1878const rb_cref_t *rb_vm_cref_in_context(
VALUE self,
VALUE cbase);
1883 rb_method_visibility_t visi;
1884 const rb_execution_context_t *ec = GET_EC();
1885 const rb_cref_t *cref = rb_vm_cref_in_context(klass, klass);
1888 visi = METHOD_VISI_PUBLIC;
1891 switch (vm_scope_visibility_get(ec)) {
1892 case METHOD_VISI_PRIVATE:
1893 if (vm_scope_module_func_check(ec)) {
1894 rb_warning(
"attribute accessor as module_function");
1896 visi = METHOD_VISI_PRIVATE;
1898 case METHOD_VISI_PROTECTED:
1899 visi = METHOD_VISI_PROTECTED;
1902 visi = METHOD_VISI_PUBLIC;
1907 attriv = rb_intern_str(rb_sprintf(
"@%"PRIsVALUE, rb_id2str(
id)));
1909 rb_add_method(klass,
id, VM_METHOD_TYPE_IVAR, (
void *)attriv, visi);
1912 rb_add_method(klass, rb_id_attrset(
id), VM_METHOD_TYPE_ATTRSET, (
void *)attriv, visi);
1919 const rb_method_entry_t *me;
1925 if (
id == object_id ||
id == id__id__ ||
id == id__send__ ||
id == idInitialize) {
1926 rb_warn(
"undefining '%s' may cause serious problems", rb_id2name(
id));
1929 me = search_method(klass,
id, 0);
1930 if (me && me->def->type == VM_METHOD_TYPE_REFINED) {
1931 me = rb_resolve_refined_method(
Qnil, me);
1934 if (UNDEFINED_METHOD_ENTRY_P(me) ||
1935 UNDEFINED_REFINED_METHOD_P(me->def)) {
1936 rb_method_name_error(klass, rb_id2str(
id));
1939 rb_add_method(klass,
id, VM_METHOD_TYPE_UNDEF, 0, METHOD_VISI_PUBLIC);
1941 CALL_METHOD_HOOK(klass, undefined,
id);
1990rb_mod_undef_method(
int argc,
VALUE *argv,
VALUE mod)
1993 for (i = 0; i < argc; i++) {
1997 rb_method_name_error(mod, v);
2004static rb_method_visibility_t
2005check_definition_visibility(
VALUE mod,
int argc,
VALUE *argv)
2007 const rb_method_entry_t *me;
2008 VALUE mid, include_super, lookup_mod = mod;
2014 if (!
id)
return METHOD_VISI_UNDEF;
2020 inc_super =
RTEST(include_super);
2022 lookup_mod = RCLASS_ORIGIN(mod);
2026 me = rb_method_entry_without_refinements(lookup_mod,
id, NULL);
2028 if (me->def->type == VM_METHOD_TYPE_NOTIMPLEMENTED)
return METHOD_VISI_UNDEF;
2029 if (!inc_super && me->owner != mod)
return METHOD_VISI_UNDEF;
2030 return METHOD_ENTRY_VISI(me);
2032 return METHOD_VISI_UNDEF;
2072rb_mod_method_defined(
int argc,
VALUE *argv,
VALUE mod)
2074 rb_method_visibility_t visi = check_definition_visibility(mod, argc, argv);
2075 return RBOOL(visi == METHOD_VISI_PUBLIC || visi == METHOD_VISI_PROTECTED);
2079check_definition(
VALUE mod,
int argc,
VALUE *argv, rb_method_visibility_t visi)
2081 return RBOOL(check_definition_visibility(mod, argc, argv) == visi);
2115rb_mod_public_method_defined(
int argc,
VALUE *argv,
VALUE mod)
2117 return check_definition(mod, argc, argv, METHOD_VISI_PUBLIC);
2151rb_mod_private_method_defined(
int argc,
VALUE *argv,
VALUE mod)
2153 return check_definition(mod, argc, argv, METHOD_VISI_PRIVATE);
2187rb_mod_protected_method_defined(
int argc,
VALUE *argv,
VALUE mod)
2189 return check_definition(mod, argc, argv, METHOD_VISI_PROTECTED);
2193rb_method_entry_eq(
const rb_method_entry_t *m1,
const rb_method_entry_t *m2)
2195 return rb_method_definition_eq(m1->def, m2->def);
2198static const rb_method_definition_t *
2199original_method_definition(
const rb_method_definition_t *def)
2203 switch (def->type) {
2204 case VM_METHOD_TYPE_REFINED:
2205 if (def->body.refined.orig_me) {
2206 def = def->body.refined.orig_me->def;
2210 case VM_METHOD_TYPE_ALIAS:
2211 def = def->body.alias.original_me->def;
2221rb_method_definition_eq(
const rb_method_definition_t *d1,
const rb_method_definition_t *d2)
2223 d1 = original_method_definition(d1);
2224 d2 = original_method_definition(d2);
2226 if (d1 == d2)
return 1;
2227 if (!d1 || !d2)
return 0;
2228 if (d1->type != d2->type)
return 0;
2231 case VM_METHOD_TYPE_ISEQ:
2232 return d1->body.iseq.iseqptr == d2->body.iseq.
iseqptr;
2233 case VM_METHOD_TYPE_CFUNC:
2235 d1->body.cfunc.func == d2->body.cfunc.func &&
2236 d1->body.cfunc.argc == d2->body.cfunc.argc;
2237 case VM_METHOD_TYPE_ATTRSET:
2238 case VM_METHOD_TYPE_IVAR:
2239 return d1->body.attr.id == d2->body.attr.id;
2240 case VM_METHOD_TYPE_BMETHOD:
2241 return RTEST(
rb_equal(d1->body.bmethod.proc, d2->body.bmethod.proc));
2242 case VM_METHOD_TYPE_MISSING:
2243 return d1->original_id == d2->original_id;
2244 case VM_METHOD_TYPE_ZSUPER:
2245 case VM_METHOD_TYPE_NOTIMPLEMENTED:
2246 case VM_METHOD_TYPE_UNDEF:
2248 case VM_METHOD_TYPE_OPTIMIZED:
2249 return (d1->body.optimized.type == d2->body.optimized.type) &&
2250 (d1->body.optimized.index == d2->body.optimized.index);
2251 case VM_METHOD_TYPE_REFINED:
2252 case VM_METHOD_TYPE_ALIAS:
2255 rb_bug(
"rb_method_definition_eq: unsupported type: %d", d1->type);
2259rb_hash_method_definition(st_index_t hash,
const rb_method_definition_t *def)
2262 def = original_method_definition(def);
2264 if (!def)
return hash;
2266 switch (def->type) {
2267 case VM_METHOD_TYPE_ISEQ:
2269 case VM_METHOD_TYPE_CFUNC:
2270 hash =
rb_hash_uint(hash, (st_index_t)def->body.cfunc.func);
2272 case VM_METHOD_TYPE_ATTRSET:
2273 case VM_METHOD_TYPE_IVAR:
2275 case VM_METHOD_TYPE_BMETHOD:
2276 return rb_hash_proc(hash, def->body.bmethod.proc);
2277 case VM_METHOD_TYPE_MISSING:
2279 case VM_METHOD_TYPE_ZSUPER:
2280 case VM_METHOD_TYPE_NOTIMPLEMENTED:
2281 case VM_METHOD_TYPE_UNDEF:
2283 case VM_METHOD_TYPE_OPTIMIZED:
2286 case VM_METHOD_TYPE_REFINED:
2287 case VM_METHOD_TYPE_ALIAS:
2290 rb_bug(
"rb_hash_method_definition: unsupported method type (%d)", def->type);
2294rb_hash_method_entry(st_index_t hash,
const rb_method_entry_t *me)
2296 return rb_hash_method_definition(hash, me->def);
2302 const VALUE target_klass = klass;
2303 VALUE defined_class;
2304 const rb_method_entry_t *orig_me;
2305 rb_method_visibility_t visi = METHOD_VISI_UNDEF;
2314 orig_me = search_method(klass, original_name, &defined_class);
2316 if (orig_me && orig_me->def->type == VM_METHOD_TYPE_REFINED) {
2317 orig_me = rb_resolve_refined_method(
Qnil, orig_me);
2320 if (UNDEFINED_METHOD_ENTRY_P(orig_me) ||
2321 UNDEFINED_REFINED_METHOD_P(orig_me->def)) {
2323 (orig_me = search_method(rb_cObject, original_name, &defined_class),
2324 UNDEFINED_METHOD_ENTRY_P(orig_me))) {
2325 rb_print_undef(klass, original_name, METHOD_VISI_UNDEF);
2329 switch (orig_me->def->type) {
2330 case VM_METHOD_TYPE_ZSUPER:
2332 original_name = orig_me->def->original_id;
2333 visi = METHOD_ENTRY_VISI(orig_me);
2335 case VM_METHOD_TYPE_ALIAS:
2336 visi = METHOD_ENTRY_VISI(orig_me);
2337 orig_me = orig_me->def->body.alias.original_me;
2338 VM_ASSERT(orig_me->def->type != VM_METHOD_TYPE_ALIAS);
2343 if (visi == METHOD_VISI_UNDEF) visi = METHOD_ENTRY_VISI(orig_me);
2345 if (orig_me->defined_class == 0) {
2346 rb_method_entry_make(target_klass, alias_name, target_klass, visi,
2347 VM_METHOD_TYPE_ALIAS, NULL, orig_me->called_id,
2348 (
void *)rb_method_entry_clone(orig_me));
2349 method_added(target_klass, alias_name);
2352 rb_method_entry_t *alias_me;
2354 alias_me = method_entry_set(target_klass, alias_name, orig_me, visi, orig_me->owner);
2355 RB_OBJ_WRITE(alias_me, &alias_me->owner, target_klass);
2361 RB_OBJ_WRITE(alias_me, &alias_me->defined_class, orig_me->defined_class);
2393 rb_print_undef_str(mod, oldname);
2401check_and_export_method(
VALUE self,
VALUE name, rb_method_visibility_t visi)
2405 rb_print_undef_str(self, name);
2407 rb_export_method(self,
id, visi);
2411set_method_visibility(
VALUE self,
int argc,
const VALUE *argv, rb_method_visibility_t visi)
2415 rb_check_frozen(self);
2417 rb_warning(
"%"PRIsVALUE
" with no argument is just ignored",
2425 if (argc == 1 && (v = rb_check_array_type(argv[0])) !=
Qnil) {
2429 check_and_export_method(self,
RARRAY_AREF(v, j), visi);
2433 for (i = 0; i < argc; i++) {
2434 check_and_export_method(self, argv[i], visi);
2440set_visibility(
int argc,
const VALUE *argv,
VALUE module, rb_method_visibility_t visi)
2443 scope_visibility_check();
2444 rb_scope_visibility_set(visi);
2448 set_method_visibility(module, argc, argv, visi);
2452 return rb_ary_new_from_values(argc, argv);
2473rb_mod_public(
int argc,
VALUE *argv,
VALUE module)
2475 return set_visibility(argc, argv, module, METHOD_VISI_PUBLIC);
2505rb_mod_protected(
int argc,
VALUE *argv,
VALUE module)
2507 return set_visibility(argc, argv, module, METHOD_VISI_PROTECTED);
2539rb_mod_private(
int argc,
VALUE *argv,
VALUE module)
2541 return set_visibility(argc, argv, module, METHOD_VISI_PRIVATE);
2581rb_mod_ruby2_keywords(
int argc,
VALUE *argv,
VALUE module)
2584 VALUE origin_class = RCLASS_ORIGIN(module);
2587 rb_check_frozen(module);
2589 for (i = 0; i < argc; i++) {
2592 rb_method_entry_t *me;
2593 VALUE defined_class;
2596 rb_print_undef_str(module, v);
2599 me = search_method(origin_class, name, &defined_class);
2601 me = search_method(rb_cObject, name, &defined_class);
2604 if (UNDEFINED_METHOD_ENTRY_P(me) ||
2605 UNDEFINED_REFINED_METHOD_P(me->def)) {
2606 rb_print_undef(module, name, METHOD_VISI_UNDEF);
2609 if (module == defined_class || origin_class == defined_class) {
2610 switch (me->def->type) {
2611 case VM_METHOD_TYPE_ISEQ:
2612 if (ISEQ_BODY(me->def->body.iseq.
iseqptr)->param.flags.has_rest &&
2613 !ISEQ_BODY(me->def->body.iseq.
iseqptr)->param.flags.has_post &&
2614 !ISEQ_BODY(me->def->body.iseq.
iseqptr)->param.flags.has_kw &&
2615 !ISEQ_BODY(me->def->body.iseq.
iseqptr)->param.flags.has_kwrest) {
2616 ISEQ_BODY(me->def->body.iseq.
iseqptr)->param.flags.ruby2_keywords = 1;
2617 rb_clear_method_cache(module, name);
2620 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));
2623 case VM_METHOD_TYPE_BMETHOD: {
2624 VALUE procval = me->def->body.bmethod.proc;
2625 if (vm_block_handler_type(procval) == block_handler_type_proc) {
2626 procval = vm_proc_to_block_handler(VM_BH_TO_PROC(procval));
2629 if (vm_block_handler_type(procval) == block_handler_type_iseq) {
2631 const rb_iseq_t *iseq = rb_iseq_check(captured->code.iseq);
2632 if (ISEQ_BODY(iseq)->param.flags.has_rest &&
2633 !ISEQ_BODY(iseq)->param.flags.has_post &&
2634 !ISEQ_BODY(iseq)->param.flags.has_kw &&
2635 !ISEQ_BODY(iseq)->param.flags.has_kwrest) {
2636 ISEQ_BODY(iseq)->param.flags.ruby2_keywords = 1;
2637 rb_clear_method_cache(module, name);
2640 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));
2647 rb_warn(
"Skipping set of ruby2_keywords flag for %"PRIsVALUE
" (method not defined in Ruby)", QUOTE_ID(name));
2652 rb_warn(
"Skipping set of ruby2_keywords flag for %"PRIsVALUE
" (can only set in method defining module)", QUOTE_ID(name));
2671rb_mod_public_method(
int argc,
VALUE *argv,
VALUE obj)
2699rb_mod_private_method(
int argc,
VALUE *argv,
VALUE obj)
2723 return rb_mod_public(argc, argv, rb_top_main_class(
"public"));
2743 return rb_mod_private(argc, argv, rb_top_main_class(
"private"));
2754top_ruby2_keywords(
int argc,
VALUE *argv,
VALUE module)
2756 return rb_mod_ruby2_keywords(argc, argv, rb_top_main_class(
"ruby2_keywords"));
2802rb_mod_modfunc(
int argc,
VALUE *argv,
VALUE module)
2806 const rb_method_entry_t *me;
2809 rb_raise(
rb_eTypeError,
"module_function must be called for modules");
2813 rb_scope_module_func_set();
2817 set_method_visibility(module, argc, argv, METHOD_VISI_PRIVATE);
2819 for (i = 0; i < argc; i++) {
2824 me = search_method(m,
id, 0);
2826 me = search_method(rb_cObject,
id, 0);
2828 if (UNDEFINED_METHOD_ENTRY_P(me)) {
2829 rb_print_undef(module,
id, METHOD_VISI_UNDEF);
2831 if (me->def->type != VM_METHOD_TYPE_ZSUPER) {
2843 return rb_ary_new_from_values(argc, argv);
2847#pragma push_macro("rb_method_basic_definition_p")
2848#undef rb_method_basic_definition_p
2853 const rb_callable_method_entry_t *cme;
2854 if (!klass)
return TRUE;
2855 cme = rb_callable_method_entry(klass,
id);
2856 return (cme && METHOD_ENTRY_BASIC(cme)) ? TRUE : FALSE;
2859#pragma pop_macro("rb_method_basic_definition_p")
2863call_method_entry(rb_execution_context_t *ec,
VALUE defined_class,
VALUE obj,
ID id,
2864 const rb_callable_method_entry_t *cme,
int argc,
const VALUE *argv,
int kw_splat)
2866 VALUE passed_block_handler = vm_passed_block_handler(ec);
2867 VALUE result = rb_vm_call_kw(ec, obj,
id, argc, argv, cme, kw_splat);
2868 vm_passed_block_handler_set(ec, passed_block_handler);
2873basic_obj_respond_to_missing(rb_execution_context_t *ec,
VALUE klass,
VALUE obj,
2876 VALUE defined_class, args[2];
2877 const ID rtmid = idRespond_to_missing;
2878 const rb_callable_method_entry_t *
const cme = callable_method_entry(klass, rtmid, &defined_class);
2880 if (!cme || METHOD_ENTRY_BASIC(cme))
return Qundef;
2883 return call_method_entry(ec, defined_class, obj, rtmid, cme, 2, args,
RB_NO_KEYWORDS);
2887basic_obj_respond_to(rb_execution_context_t *ec,
VALUE obj,
ID id,
int pub)
2892 switch (method_boundp(klass,
id, pub|BOUND_RESPONDS)) {
2896 ret = basic_obj_respond_to_missing(ec, klass, obj,
ID2SYM(
id),
2898 return RTEST(ret) && !UNDEF_P(ret);
2905vm_respond_to(rb_execution_context_t *ec,
VALUE klass,
VALUE obj,
ID id,
int priv)
2907 VALUE defined_class;
2908 const ID resid = idRespond_to;
2909 const rb_callable_method_entry_t *
const cme = callable_method_entry(klass, resid, &defined_class);
2911 if (!cme)
return -1;
2912 if (METHOD_ENTRY_BASIC(cme)) {
2923 argc = rb_method_entry_arity((
const rb_method_entry_t *)cme);
2925 rb_raise(rb_eArgError,
2926 "respond_to? must accept 1 or 2 arguments (requires %d)",
2933 VALUE location = rb_method_entry_location((
const rb_method_entry_t *)cme);
2935 "%"PRIsVALUE
"%c""respond_to?(:%"PRIsVALUE
") uses"
2936 " the deprecated method signature, which takes one parameter",
2937 (RCLASS_SINGLETON_P(klass) ? obj : klass),
2938 (RCLASS_SINGLETON_P(klass) ?
'.' :
'#'),
2940 if (!
NIL_P(location)) {
2945 RSTRING_PTR(path),
NUM2INT(line),
2946 "respond_to? is defined here");
2951 result = call_method_entry(ec, defined_class, obj, resid, cme, argc, args,
RB_NO_KEYWORDS);
2952 return RTEST(result);
2959 rb_execution_context_t *ec = GET_EC();
2960 return rb_ec_obj_respond_to(ec, obj,
id, priv);
2964rb_ec_obj_respond_to(rb_execution_context_t *ec,
VALUE obj,
ID id,
int priv)
2967 int ret = vm_respond_to(ec, klass, obj,
id, priv);
2968 if (ret == -1) ret = basic_obj_respond_to(ec, obj,
id, !priv);
3000obj_respond_to(
int argc,
VALUE *argv,
VALUE obj)
3004 rb_execution_context_t *ec = GET_EC();
3008 VALUE ret = basic_obj_respond_to_missing(ec,
CLASS_OF(obj), obj,
3010 if (UNDEF_P(ret)) ret =
Qfalse;
3013 return RBOOL(basic_obj_respond_to(ec, obj,
id, !
RTEST(priv)));
3038Init_eval_method(
void)
3060 "public", top_public, -1);
3062 "private", top_private, -1);
3064 "ruby2_keywords", top_ruby2_keywords, -1);
3067#define REPLICATE_METHOD(klass, id) do { \
3068 const rb_method_entry_t *me = rb_method_entry((klass), (id)); \
3069 rb_method_entry_set((klass), (id), me, METHOD_ENTRY_VISI(me)); \
#define rb_define_method(klass, mid, func, arity)
Defines klass#mid.
#define rb_define_private_method(klass, mid, func, arity)
Defines klass#mid and makes it private.
VALUE rb_singleton_class(VALUE obj)
Finds or creates the singleton class of the passed object.
void rb_class_modify_check(VALUE klass)
Asserts that klass is not a frozen class.
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Retrieves argument from argc and argv to given VALUE references according to the format string.
#define xfree
Old name of ruby_xfree.
#define Qundef
Old name of RUBY_Qundef.
#define INT2FIX
Old name of RB_INT2FIX.
#define ID2SYM
Old name of RB_ID2SYM.
#define UNREACHABLE_RETURN
Old name of RBIMPL_UNREACHABLE_RETURN.
#define ZALLOC
Old name of RB_ZALLOC.
#define CLASS_OF
Old name of rb_class_of.
#define T_MODULE
Old name of RUBY_T_MODULE.
#define T_ICLASS
Old name of RUBY_T_ICLASS.
#define 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.
void rb_notimplement(void)
void rb_category_warn(rb_warning_category_t category, const char *fmt,...)
Identical to rb_category_warning(), except it reports unless $VERBOSE is nil.
#define ruby_verbose
This variable controls whether the interpreter is in debug mode.
VALUE rb_eTypeError
TypeError exception.
void rb_category_compile_warn(rb_warning_category_t category, const char *file, int line, const char *fmt,...)
Identical to rb_compile_warn(), except it also accepts category.
void rb_warn(const char *fmt,...)
Identical to rb_warning(), except it reports unless $VERBOSE is nil.
VALUE rb_eException
Mother of all exceptions.
void rb_warning(const char *fmt,...)
Issues a warning.
@ RB_WARN_CATEGORY_DEPRECATED
Warning is for deprecated features.
VALUE rb_mKernel
Kernel module.
VALUE rb_cModule
Module class.
VALUE rb_equal(VALUE lhs, VALUE rhs)
This function is an optimised version of calling #==.
#define RB_OBJ_WRITTEN(old, oldv, young)
Identical to RB_OBJ_WRITE(), except it doesn't write any values, but only a WB declaration.
#define RB_OBJ_WRITE(old, slot, young)
Declaration of a "back" pointer.
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.
st_index_t rb_hash_start(st_index_t i)
Starts a series of hashing.
int rb_respond_to(VALUE obj, ID mid)
Queries if the object responds to the method.
VALUE(* rb_alloc_func_t)(VALUE klass)
This is the type of functions that ruby calls when trying to allocate an object.
void rb_undef_alloc_func(VALUE klass)
Deletes the allocator function of a class.
void rb_alias(VALUE klass, ID dst, ID src)
Resembles alias.
void rb_attr(VALUE klass, ID name, int need_reader, int need_writer, int honour_visibility)
This function resembles now-deprecated Module#attr.
void rb_remove_method(VALUE klass, const char *name)
Removes a method.
rb_alloc_func_t rb_get_alloc_func(VALUE klass)
Queries the allocator function of a class.
void rb_clear_constant_cache_for_id(ID id)
Clears the inline constant caches associated with a particular ID.
void rb_remove_method_id(VALUE klass, ID mid)
Identical to rb_remove_method(), except it accepts the method name as ID.
void rb_define_alloc_func(VALUE klass, rb_alloc_func_t func)
Sets the allocator function of a class.
VALUE rb_f_notimplement(int argc, const VALUE *argv, VALUE obj, VALUE marker)
Raises rb_eNotImpError.
int rb_method_boundp(VALUE klass, ID id, int ex)
Queries if the klass has this method.
int rb_obj_respond_to(VALUE obj, ID mid, int private_p)
Identical to rb_respond_to(), except it additionally takes the visibility parameter.
ID rb_check_id(volatile VALUE *namep)
Detects if the given name is already interned or not.
VALUE rb_to_symbol(VALUE name)
Identical to rb_intern_str(), except it generates a dynamic symbol if necessary.
VALUE type(ANYARGS)
ANYARGS-ed function type.
int st_foreach(st_table *q, int_type *w, st_data_t e)
Iteration over the given table.
#define RARRAY_LEN
Just another name of rb_array_len.
#define RARRAY_AREF(a, i)
#define RBASIC(obj)
Convenient casting macro.
#define RCLASS_SUPER
Just another name of rb_class_get_superclass.
#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
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
uintptr_t VALUE
Type that represents a Ruby object.
static void Check_Type(VALUE v, enum ruby_value_type t)
Identical to RB_TYPE_P(), except it raises exceptions on predication failure.
static bool RB_TYPE_P(VALUE obj, enum ruby_value_type t)
Queries if the given object is of given type.