5 #define CACHE_SIZE 0x800
6 #define CACHE_MASK 0x7ff
7 #define EXPR1(c,m) ((((c)>>3)^(m))&CACHE_MASK)
11 #define NOEX_NOREDEF NOEX_RESPONDS
29 #define ruby_running (GET_VM()->running)
103 ume->
next =
GET_VM()->unlinked_method_entry_list;
104 GET_VM()->unlinked_method_entry_list = ume;
233 int make_refined = 0;
245 (mid == idInitialize || mid == idInitialize_copy ||
246 mid == idInitialize_clone || mid == idInitialize_dup ||
256 VALUE refined_class =
295 switch (old_def->
type) {
308 "previous definition of %s was here",
328 if (klass ==
rb_cObject && mid == idInitialize) {
329 rb_warn(
"redefining Object#initialize may cause infinite loop");
332 if (mid ==
object_id || mid == id__send__) {
347 #define CALL_METHOD_HOOK(klass, hook, mid) do { \
348 const VALUE arg = ID2SYM(mid); \
349 VALUE recv_class = (klass); \
350 ID hook_id = (hook); \
351 if (FL_TEST((klass), FL_SINGLETON)) { \
352 recv_class = rb_ivar_get((klass), attached); \
353 hook_id = singleton_##hook; \
355 rb_funcall2(recv_class, hook_id, 1, &arg); \
389 rb_bug(
"call_cfunc_func: unsupported length: %d", argc);
455 rb_bug(
"rb_add_method: unsupported method type (%d)\n", type);
472 #define UNDEF_ALLOC_FUNC ((rb_alloc_func_t)-1)
495 if (allocator)
return allocator;
509 if (defined_class_ptr)
510 *defined_class_ptr = klass;
522 VALUE *defined_class_ptr)
545 if (defined_class_ptr)
553 #if OPT_GLOBAL_METHOD_CACHE
558 ent->
mid ==
id && ent->
klass == klass) {
559 if (defined_class_ptr)
571 VALUE *defined_class_ptr)
587 VALUE *defined_class_ptr)
594 if (
NIL_P(refinement)) {
615 VALUE *defined_class_ptr)
622 VALUE refinements = cref ? cref->nd_refinements :
Qnil;
626 if (defined_class_ptr)
633 VALUE *defined_class_ptr)
641 if (defined_class_ptr)
666 if (mid ==
object_id || mid == id__send__ || mid == idInitialize) {
711 for (i = 0; i <
argc; i++) {
723 #undef rb_disable_super
724 #undef rb_enable_super
757 if (me->
flag != noex) {
760 if (klass == defined_class ||
785 if (!me->
def)
return 0;
787 if (ex & NOEX_RESPONDS)
return 2;
810 "attribute accessor as module_function" :
811 "private attribute?");
854 if (
id ==
object_id ||
id == id__send__ ||
id == idInitialize) {
863 const char *s0 =
" class";
933 for (i = 0; i <
argc; i++) {
981 #define VISI_CHECK(x,f) (((x)&NOEX_MASK) == (f))
1106 if (d1 == d2)
return 1;
1107 if (!d1 || !d2)
return 0;
1132 rb_bug(
"rb_method_entry_eq: unsupported method type (%d)\n", d1->
type);
1142 switch (def->
type) {
1170 rb_bug(
"rb_hash_method_definition: unsupported method type (%d)\n", def->
type);
1210 flag = orig_me->
flag;
1256 "Insecure: can't change method visibility");
1270 for (i = 0; i <
argc; i++) {
1473 for (i = 0; i <
argc; i++) {
1545 " old fashion which takes only one parameter",
1549 if (!
NIL_P(location)) {
1554 "respond_to? is defined here");
1628 #define rb_intern(str) rb_intern_const(str)
1663 #define REPLICATE_METHOD(klass, id, noex) \
1664 rb_method_entry_set((klass), (id), \
1665 rb_method_entry((klass), (id), 0), \
1666 (rb_method_flag_t)(noex | NOEX_BASIC | NOEX_NOREDEF))
static struct cache_entry cache[CACHE_SIZE]
struct unlinked_method_entry_list_entry * next
int rb_method_boundp(VALUE klass, ID id, int ex)
static int rb_method_definition_eq(const rb_method_definition_t *d1, const rb_method_definition_t *d2)
#define UNDEFINED_METHOD_ENTRY_P(me)
static VALUE rb_mod_public_method(int argc, VALUE *argv, VALUE obj)
static VALUE call_cfunc_0(VALUE(*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv)
void rb_bug(const char *fmt,...)
rb_method_entry_t * rb_method_entry(VALUE klass, ID id, VALUE *defined_class_ptr)
void rb_enc_copy(VALUE obj1, VALUE obj2)
static VALUE rb_mod_method_defined(VALUE mod, VALUE mid)
VALUE rb_ary_freeze(VALUE ary)
static VALUE rb_mod_alias_method(VALUE mod, VALUE newname, VALUE oldname)
int rb_vm_get_sourceline(const rb_control_frame_t *cfp)
#define NOEX_WITH_SAFE(n)
void rb_remove_method(VALUE klass, const char *name)
st_index_t rb_hash_method_entry(st_index_t hash, const rb_method_entry_t *me)
static VALUE rb_mod_remove_method(int argc, VALUE *argv, VALUE mod)
static VALUE find_refinement(VALUE refinements, VALUE klass)
int rb_obj_method_arity(VALUE, ID)
static ID singleton_removed
int st_insert(st_table *, st_data_t, st_data_t)
void rb_add_refined_method_entry(VALUE refined_class, ID mid)
void rb_disable_super(VALUE klass, const char *name)
VALUE rb_mod_method_location(VALUE mod, ID id)
static VALUE call_cfunc_10(VALUE(*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv)
struct rb_method_entry_struct * orig_me
rb_alloc_func_t rb_get_alloc_func(VALUE klass)
VALUE rb_refinement_module_get_refined_class(VALUE module)
void rb_define_private_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
static void setup_method_cfunc_struct(rb_method_cfunc_t *cfunc, VALUE(*func)(), int argc)
static rb_method_entry_t * search_method(VALUE klass, ID id, VALUE *defined_class_ptr)
SSL_METHOD *(* func)(void)
static ID singleton_undefined
void rb_alias(VALUE klass, ID name, ID def)
void rb_print_undef_str(VALUE klass, VALUE name)
union rb_method_definition_struct::@90 body
void rb_raise(VALUE exc, const char *fmt,...)
VALUE rb_ivar_get(VALUE, ID)
void rb_compile_warn(const char *file, int line, const char *fmt,...)
#define GET_VM_STATE_VERSION()
VALUE rb_ary_new3(long n,...)
void rb_method_name_error(VALUE klass, VALUE str)
ID rb_check_id(volatile VALUE *namep)
Returns ID for the given name if it is interned already, or 0.
int rb_method_basic_definition_p(VALUE klass, ID id)
static rb_method_entry_t * lookup_method_table(VALUE klass, ID id)
static void rb_vm_check_redefinition_opt_method(const rb_method_entry_t *me, VALUE klass)
static VALUE call_cfunc_11(VALUE(*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv)
void rb_mark_method_entry(const rb_method_entry_t *me)
rb_method_entry_t * rb_add_method(VALUE klass, ID mid, rb_method_type_t type, void *opts, rb_method_flag_t noex)
void rb_name_error_str(VALUE str, const char *fmt,...)
void rb_name_error(ID id, const char *fmt,...)
static void remove_method(VALUE klass, ID mid)
static st_index_t rb_hash_method_definition(st_index_t hash, const rb_method_definition_t *def)
static void rb_export_method(VALUE klass, ID name, rb_method_flag_t noex)
VALUE rb_singleton_class(VALUE obj)
Returns the singleton class of obj.
void rb_attr(VALUE klass, ID id, int read, int write, int ex)
int rb_is_const_id(ID id)
int rb_obj_respond_to(VALUE obj, ID id, int priv)
#define RB_TYPE_P(obj, type)
void rb_vm_change_state(void)
int st_lookup(st_table *, st_data_t, st_data_t *)
static rb_method_entry_t * rb_method_entry_make(VALUE klass, ID mid, rb_method_type_t type, rb_method_definition_t *def, rb_method_flag_t noex)
static VALUE call_cfunc_15(VALUE(*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv)
#define rb_intern_str(string)
VALUE rb_class_name(VALUE)
int rb_iseq_first_lineno(const rb_iseq_t *iseq)
rb_control_frame_t * rb_vm_get_ruby_level_next_cfp(rb_thread_t *th, const rb_control_frame_t *cfp)
RUBY_EXTERN VALUE rb_cObject
int rb_respond_to(VALUE obj, ID id)
#define RMODULE_IS_REFINEMENT
void rb_clear_cache(void)
static VALUE top_public(int argc, VALUE *argv)
static VALUE obj_respond_to(int argc, VALUE *argv, VALUE obj)
RUBY_EXTERN VALUE rb_mKernel
void rb_remove_method_id(VALUE klass, ID mid)
static VALUE check_definition(VALUE mod, VALUE mid, rb_method_flag_t noex)
void rb_undef_alloc_func(VALUE klass)
int st_delete(st_table *, st_data_t *, st_data_t *)
static VALUE top_private(int argc, VALUE *argv)
static VALUE call_cfunc_2(VALUE(*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv)
struct unlinked_method_entry_list_entry * unlinked_method_entry_list
static void rb_clear_cache_by_id(ID id)
void rb_clear_cache_by_class(VALUE klass)
void rb_gc_mark_unlinked_live_method_entries(void *pvm)
RUBY_EXTERN VALUE rb_cModule
static int basic_obj_respond_to(VALUE obj, ID id, int pub)
static VALUE call_cfunc_1(VALUE(*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv)
static VALUE call_cfunc_9(VALUE(*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv)
static VALUE call_cfunc_3(VALUE(*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv)
static VALUE rb_mod_private_method_defined(VALUE mod, VALUE mid)
void rb_add_method_cfunc(VALUE klass, ID mid, VALUE(*func)(ANYARGS), int argc, rb_method_flag_t noex)
static void secure_visibility(VALUE self)
VALUE(* invoker)(VALUE(*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv)
static VALUE(*)(VALUE(*func)(ANYARGS), VALUE recv, int argc, const VALUE *) call_cfunc_invoker_func(int argc)
VALUE rb_funcall2(VALUE, ID, int, const VALUE *)
Calls a method.
static VALUE call_cfunc_13(VALUE(*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv)
VALUE rb_sprintf(const char *format,...)
static VALUE rb_mod_public(int argc, VALUE *argv, VALUE module)
rb_method_entry_t * rb_method_entry_with_refinements(VALUE klass, ID id, VALUE *defined_class_ptr)
static void release_method_definition(rb_method_definition_t *def)
int rb_is_local_id(ID id)
static VALUE rb_mod_protected_method_defined(VALUE mod, VALUE mid)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
rb_iseq_t * rb_proc_get_iseq(VALUE proc, int *is_proc)
static void vm_clear_global_method_cache(void)
static VALUE rb_mod_modfunc(int argc, VALUE *argv, VALUE module)
const char * rb_class2name(VALUE)
static VALUE obj_respond_to_missing(VALUE obj, VALUE mid, VALUE priv)
rb_method_entry_t * rb_method_entry_set(VALUE klass, ID mid, const rb_method_entry_t *me, rb_method_flag_t noex)
rb_iseq_location_t location
static VALUE call_cfunc_m2(VALUE(*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv)
static VALUE call_cfunc_12(VALUE(*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv)
static VALUE call_cfunc_5(VALUE(*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv)
static VALUE rb_mod_undef_method(int argc, VALUE *argv, VALUE mod)
#define CALL_METHOD_HOOK(klass, hook, mid)
static void method_added(VALUE klass, ID mid)
static void set_method_visibility(VALUE self, int argc, VALUE *argv, rb_method_flag_t ex)
static VALUE call_cfunc_7(VALUE(*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv)
VALUE rb_f_notimplement(int argc, VALUE *argv, VALUE obj)
static VALUE rb_mod_private_method(int argc, VALUE *argv, VALUE obj)
void rb_enable_super(VALUE klass, const char *name)
void rb_sweep_method_entry(void *pvm)
static void rb_clear_cache_for_undef(VALUE klass, ID id)
VALUE rb_equal(VALUE, VALUE)
static VALUE call_cfunc_m1(VALUE(*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv)
rb_method_definition_t * def
static VALUE call_cfunc_14(VALUE(*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv)
int rb_method_entry_eq(const rb_method_entry_t *m1, const rb_method_entry_t *m2)
void rb_compile_warning(const char *file, int line, const char *fmt,...)
void rb_free_method_entry(rb_method_entry_t *me)
st_index_t rb_hash_uint(st_index_t, st_index_t)
void rb_define_alloc_func(VALUE klass, VALUE(*func)(VALUE))
struct iseq_line_info_entry * line_info_table
static void make_method_entry_refined(rb_method_entry_t *me)
static VALUE rb_mod_protected(int argc, VALUE *argv, VALUE module)
static VALUE call_cfunc_6(VALUE(*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv)
void rb_notimplement(void)
static unsigned int hash(const char *str, unsigned int len)
static VALUE call_cfunc_4(VALUE(*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv)
void Init_eval_method(void)
static VALUE rb_mod_public_method_defined(VALUE mod, VALUE mid)
static VALUE rb_mod_private(int argc, VALUE *argv, VALUE module)
void rb_frozen_class_p(VALUE klass)
void rb_undef(VALUE klass, ID id)
const char * rb_id2name(ID id)
#define REPLICATE_METHOD(klass, id, noex)
rb_method_entry_t * rb_method_entry_get_without_cache(VALUE klass, ID id, VALUE *defined_class_ptr)
rb_method_entry_t * rb_resolve_refined_method(VALUE refinements, const rb_method_entry_t *me, VALUE *defined_class_ptr)
void rb_warning(const char *fmt,...)
#define rb_check_frozen(obj)
void rb_print_undef(VALUE klass, ID id, int scope)
st_index_t rb_hash_proc(st_index_t hash, VALUE proc)
void rb_unlink_method_entry(rb_method_entry_t *me)
VALUE(* rb_alloc_func_t)(VALUE)
rb_method_entry_t * rb_method_entry_without_refinements(VALUE klass, ID id, VALUE *defined_class_ptr)
enum rb_method_definition_struct::@90::method_optimized_type optimize_type
static void rb_define_notimplement_method_id(VALUE mod, ID id, rb_method_flag_t noex)
static rb_thread_t * GET_THREAD(void)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
void rb_warn(const char *fmt,...)
static ID singleton_added
static VALUE call_cfunc_8(VALUE(*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv)
static rb_method_entry_t * get_original_method_entry(VALUE refinements, const rb_method_entry_t *me, VALUE *defined_class_ptr)