2009-07-15 20:37:25 -04:00
|
|
|
/**********************************************************************
|
|
|
|
|
|
|
|
method.h -
|
|
|
|
|
|
|
|
$Author$
|
|
|
|
created at: Wed Jul 15 20:02:33 2009
|
|
|
|
|
|
|
|
Copyright (C) 2009 Koichi Sasada
|
|
|
|
|
|
|
|
**********************************************************************/
|
|
|
|
#ifndef METHOD_H
|
|
|
|
#define METHOD_H
|
|
|
|
|
* class.c, compile.c, eval.c, gc.h, insns.def, internal.h, method.h,
variable.c, vm.c, vm_core.c, vm_insnhelper.c, vm_insnhelper.h,
vm_method.c: Implement class hierarchy method cache invalidation.
[ruby-core:55053] [Feature #8426] [GH-387]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42822 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-04 01:25:06 -04:00
|
|
|
#include "internal.h"
|
* fix namespace issue on singleton class expressions. [Bug #10943]
* vm_core.h, method.h: remove rb_iseq_t::cref_stack. CREF is stored
to rb_method_definition_t::body.iseq_body.cref.
* vm_insnhelper.c: modify SVAR usage.
When calling ISEQ type method, push CREF information onto method
frame, SVAR located place. Before this fix, SVAR is simply nil.
After this patch, CREF (or NULL == Qfalse for not iseq methods)
is stored at the method invocation.
When SVAR is requierd, then put NODE_IF onto SVAR location,
and NDOE_IF::nd_reserved points CREF itself.
* vm.c (vm_cref_new, vm_cref_dump, vm_cref_new_toplevel): added.
* vm_insnhelper.c (vm_push_frame): accept CREF.
* method.h, vm_method.c (rb_add_method_iseq): added. This function
accepts iseq and CREF.
* class.c (clone_method): use rb_add_method_iseq().
* gc.c (mark_method_entry): mark method_entry::body.iseq_body.cref.
* iseq.c: remove CREF related codes.
* insns.def (getinlinecache/setinlinecache): CREF should be cache key
because a different CREF has a different namespace.
* node.c (rb_gc_mark_node): mark NODE_IF::nd_reserved for SVAR.
* proc.c: catch up changes.
* struct.c: ditto.
* insns.def: ditto.
* vm_args.c (raise_argument_error): ditto.
* vm_eval.c: ditto.
* test/ruby/test_class.rb: add a test.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49874 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-03-06 07:24:58 -05:00
|
|
|
#include "node.h"
|
* class.c, compile.c, eval.c, gc.h, insns.def, internal.h, method.h,
variable.c, vm.c, vm_core.c, vm_insnhelper.c, vm_insnhelper.h,
vm_method.c: Implement class hierarchy method cache invalidation.
[ruby-core:55053] [Feature #8426] [GH-387]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42822 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-09-04 01:25:06 -04:00
|
|
|
|
2012-12-12 22:50:19 -05:00
|
|
|
#ifndef END_OF_ENUMERATION
|
2013-10-22 08:59:27 -04:00
|
|
|
# if defined(__GNUC__) &&! defined(__STRICT_ANSI__)
|
2012-12-12 22:50:19 -05:00
|
|
|
# define END_OF_ENUMERATION(key)
|
|
|
|
# else
|
|
|
|
# define END_OF_ENUMERATION(key) END_OF_##key##_PLACEHOLDER = 0
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2009-07-15 20:37:25 -04:00
|
|
|
typedef enum {
|
|
|
|
NOEX_PUBLIC = 0x00,
|
|
|
|
NOEX_NOSUPER = 0x01,
|
|
|
|
NOEX_PRIVATE = 0x02,
|
|
|
|
NOEX_PROTECTED = 0x04,
|
|
|
|
NOEX_MASK = 0x06,
|
|
|
|
NOEX_BASIC = 0x08,
|
|
|
|
NOEX_UNDEF = NOEX_NOSUPER,
|
|
|
|
NOEX_MODFUNC = 0x12,
|
|
|
|
NOEX_SUPER = 0x20,
|
2009-10-04 13:05:59 -04:00
|
|
|
NOEX_VCALL = 0x40,
|
2012-12-12 02:07:25 -05:00
|
|
|
NOEX_RESPONDS = 0x80,
|
|
|
|
|
|
|
|
NOEX_BIT_WIDTH = 8,
|
|
|
|
NOEX_SAFE_SHIFT_OFFSET = ((NOEX_BIT_WIDTH+3)/4)*4 /* round up to nibble */
|
2009-07-15 20:37:25 -04:00
|
|
|
} rb_method_flag_t;
|
|
|
|
|
2012-12-12 02:07:25 -05:00
|
|
|
#define NOEX_SAFE(n) ((int)((n) >> NOEX_SAFE_SHIFT_OFFSET) & 0x0F)
|
|
|
|
#define NOEX_WITH(n, s) (((s) << NOEX_SAFE_SHIFT_OFFSET) | (n) | (ruby_running ? 0 : NOEX_BASIC))
|
2011-01-19 16:03:36 -05:00
|
|
|
#define NOEX_WITH_SAFE(n) NOEX_WITH((n), rb_safe_level())
|
2009-07-15 20:37:25 -04:00
|
|
|
|
|
|
|
/* method data type */
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
VM_METHOD_TYPE_ISEQ,
|
|
|
|
VM_METHOD_TYPE_CFUNC,
|
|
|
|
VM_METHOD_TYPE_ATTRSET,
|
|
|
|
VM_METHOD_TYPE_IVAR,
|
|
|
|
VM_METHOD_TYPE_BMETHOD,
|
|
|
|
VM_METHOD_TYPE_ZSUPER,
|
|
|
|
VM_METHOD_TYPE_UNDEF,
|
|
|
|
VM_METHOD_TYPE_NOTIMPLEMENTED,
|
2009-09-27 23:09:16 -04:00
|
|
|
VM_METHOD_TYPE_OPTIMIZED, /* Kernel#send, Proc#call, etc */
|
2012-10-15 17:24:08 -04:00
|
|
|
VM_METHOD_TYPE_MISSING, /* wrapper for method_missing(id) */
|
2012-12-12 22:50:19 -05:00
|
|
|
VM_METHOD_TYPE_REFINED,
|
|
|
|
|
|
|
|
END_OF_ENUMERATION(VM_METHOD_TYPE)
|
2009-07-15 20:37:25 -04:00
|
|
|
} rb_method_type_t;
|
|
|
|
|
2012-10-19 06:38:30 -04:00
|
|
|
struct rb_call_info_struct;
|
|
|
|
|
2009-07-15 20:37:25 -04:00
|
|
|
typedef struct rb_method_cfunc_struct {
|
|
|
|
VALUE (*func)(ANYARGS);
|
2012-11-13 04:48:08 -05:00
|
|
|
VALUE (*invoker)(VALUE (*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv);
|
2009-07-15 20:37:25 -04:00
|
|
|
int argc;
|
|
|
|
} rb_method_cfunc_t;
|
|
|
|
|
2010-03-22 07:44:01 -04:00
|
|
|
typedef struct rb_method_attr_struct {
|
|
|
|
ID id;
|
2013-06-14 05:23:54 -04:00
|
|
|
const VALUE location;
|
2010-03-22 07:44:01 -04:00
|
|
|
} rb_method_attr_t;
|
|
|
|
|
2009-07-15 20:37:25 -04:00
|
|
|
typedef struct rb_iseq_struct rb_iseq_t;
|
|
|
|
|
2009-08-27 22:45:41 -04:00
|
|
|
typedef struct rb_method_definition_struct {
|
2009-07-15 20:37:25 -04:00
|
|
|
rb_method_type_t type; /* method type */
|
2014-01-22 23:59:30 -05:00
|
|
|
int alias_count;
|
2009-07-15 20:37:25 -04:00
|
|
|
ID original_id;
|
* fix namespace issue on singleton class expressions. [Bug #10943]
* vm_core.h, method.h: remove rb_iseq_t::cref_stack. CREF is stored
to rb_method_definition_t::body.iseq_body.cref.
* vm_insnhelper.c: modify SVAR usage.
When calling ISEQ type method, push CREF information onto method
frame, SVAR located place. Before this fix, SVAR is simply nil.
After this patch, CREF (or NULL == Qfalse for not iseq methods)
is stored at the method invocation.
When SVAR is requierd, then put NODE_IF onto SVAR location,
and NDOE_IF::nd_reserved points CREF itself.
* vm.c (vm_cref_new, vm_cref_dump, vm_cref_new_toplevel): added.
* vm_insnhelper.c (vm_push_frame): accept CREF.
* method.h, vm_method.c (rb_add_method_iseq): added. This function
accepts iseq and CREF.
* class.c (clone_method): use rb_add_method_iseq().
* gc.c (mark_method_entry): mark method_entry::body.iseq_body.cref.
* iseq.c: remove CREF related codes.
* insns.def (getinlinecache/setinlinecache): CREF should be cache key
because a different CREF has a different namespace.
* node.c (rb_gc_mark_node): mark NODE_IF::nd_reserved for SVAR.
* proc.c: catch up changes.
* struct.c: ditto.
* insns.def: ditto.
* vm_args.c (raise_argument_error): ditto.
* vm_eval.c: ditto.
* test/ruby/test_class.rb: add a test.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49874 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-03-06 07:24:58 -05:00
|
|
|
|
2009-07-15 20:37:25 -04:00
|
|
|
union {
|
* fix namespace issue on singleton class expressions. [Bug #10943]
* vm_core.h, method.h: remove rb_iseq_t::cref_stack. CREF is stored
to rb_method_definition_t::body.iseq_body.cref.
* vm_insnhelper.c: modify SVAR usage.
When calling ISEQ type method, push CREF information onto method
frame, SVAR located place. Before this fix, SVAR is simply nil.
After this patch, CREF (or NULL == Qfalse for not iseq methods)
is stored at the method invocation.
When SVAR is requierd, then put NODE_IF onto SVAR location,
and NDOE_IF::nd_reserved points CREF itself.
* vm.c (vm_cref_new, vm_cref_dump, vm_cref_new_toplevel): added.
* vm_insnhelper.c (vm_push_frame): accept CREF.
* method.h, vm_method.c (rb_add_method_iseq): added. This function
accepts iseq and CREF.
* class.c (clone_method): use rb_add_method_iseq().
* gc.c (mark_method_entry): mark method_entry::body.iseq_body.cref.
* iseq.c: remove CREF related codes.
* insns.def (getinlinecache/setinlinecache): CREF should be cache key
because a different CREF has a different namespace.
* node.c (rb_gc_mark_node): mark NODE_IF::nd_reserved for SVAR.
* proc.c: catch up changes.
* struct.c: ditto.
* insns.def: ditto.
* vm_args.c (raise_argument_error): ditto.
* vm_eval.c: ditto.
* test/ruby/test_class.rb: add a test.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49874 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-03-06 07:24:58 -05:00
|
|
|
struct {
|
|
|
|
rb_iseq_t *const iseq; /* should be mark */
|
|
|
|
NODE *cref;
|
|
|
|
} iseq_body;
|
2009-07-15 20:37:25 -04:00
|
|
|
rb_method_cfunc_t cfunc;
|
2010-03-22 07:44:01 -04:00
|
|
|
rb_method_attr_t attr;
|
2013-06-14 05:23:54 -04:00
|
|
|
const VALUE proc; /* should be mark */
|
2009-07-15 20:37:25 -04:00
|
|
|
enum method_optimized_type {
|
|
|
|
OPTIMIZED_METHOD_TYPE_SEND,
|
2012-12-12 02:07:25 -05:00
|
|
|
OPTIMIZED_METHOD_TYPE_CALL,
|
|
|
|
|
|
|
|
OPTIMIZED_METHOD_TYPE__MAX
|
2009-07-15 20:37:25 -04:00
|
|
|
} optimize_type;
|
* revised r37993 to avoid SEGV/ILL in tests. In r37993, a method
entry with VM_METHOD_TYPE_REFINED holds only the original method
definition, so ci->me is set to a method entry allocated in the
stack, and it causes SEGV/ILL. In this commit, a method entry
with VM_METHOD_TYPE_REFINED holds the whole original method entry.
Furthermore, rb_thread_mark() is changed to mark cfp->klass to
avoid GC for iclasses created by copy_refinement_iclass().
* vm_method.c (rb_method_entry_make): add a method entry with
VM_METHOD_TYPE_REFINED to the class refined by the refinement if
the target module is a refinement. When a method entry with
VM_METHOD_TYPE_UNDEF is invoked by vm_call_method(), a method with
the same name is searched in refinements. If such a method is
found, the method is invoked. Otherwise, the original method in
the refined class (rb_method_definition_t::body.orig_me) is
invoked. This change is made to simplify the normal method lookup
and to improve the performance of normal method calls.
* vm_method.c (EXPR1, search_method, rb_method_entry),
vm_eval.c (rb_call0, rb_search_method_entry): do not use
refinements for method lookup.
* vm_insnhelper.c (vm_call_method): search methods in refinements if
ci->me is VM_METHOD_TYPE_REFINED. If the method is called by
super (i.e., ci->call == vm_call_super_method), skip the same
method entry as the current method to avoid infinite call of the
same method.
* class.c (include_modules_at): add a refined method entry for each
method defined in a module included in a refinement.
* class.c (rb_prepend_module): set an empty table to
RCLASS_M_TBL(klass) to add refined method entries, because
refinements should have priority over prepended modules.
* proc.c (mnew): use rb_method_entry_with_refinements() to get
a refined method.
* vm.c (rb_thread_mark): mark cfp->klass for iclasses created by
copy_refinement_iclass().
* vm.c (Init_VM), cont.c (fiber_init): initialize th->cfp->klass.
* test/ruby/test_refinement.rb (test_inline_method_cache): do not skip
the test because it should pass successfully.
* test/ruby/test_refinement.rb (test_redefine_refined_method): new
test for the case a refined method is redefined.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38236 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-06 08:08:41 -05:00
|
|
|
struct rb_method_entry_struct *orig_me;
|
2009-07-15 20:37:25 -04:00
|
|
|
} body;
|
2009-08-27 22:45:41 -04:00
|
|
|
} rb_method_definition_t;
|
|
|
|
|
|
|
|
typedef struct rb_method_entry_struct {
|
|
|
|
rb_method_flag_t flag;
|
2010-05-05 13:51:21 -04:00
|
|
|
char mark;
|
2009-08-27 22:45:41 -04:00
|
|
|
rb_method_definition_t *def;
|
|
|
|
ID called_id;
|
|
|
|
VALUE klass; /* should be mark */
|
2009-07-15 20:37:25 -04:00
|
|
|
} rb_method_entry_t;
|
|
|
|
|
2010-05-05 13:51:21 -04:00
|
|
|
struct unlinked_method_entry_list_entry {
|
|
|
|
struct unlinked_method_entry_list_entry *next;
|
|
|
|
rb_method_entry_t *me;
|
|
|
|
};
|
|
|
|
|
2009-08-27 22:45:41 -04:00
|
|
|
#define UNDEFINED_METHOD_ENTRY_P(me) (!(me) || !(me)->def || (me)->def->type == VM_METHOD_TYPE_UNDEF)
|
2015-01-12 03:18:10 -05:00
|
|
|
#define UNDEFINED_REFINED_METHOD_P(def) \
|
|
|
|
((def)->type == VM_METHOD_TYPE_REFINED && \
|
|
|
|
UNDEFINED_METHOD_ENTRY_P((def)->body.orig_me))
|
2009-08-27 22:45:41 -04:00
|
|
|
|
2009-07-15 20:37:25 -04:00
|
|
|
void rb_add_method_cfunc(VALUE klass, ID mid, VALUE (*func)(ANYARGS), int argc, rb_method_flag_t noex);
|
* fix namespace issue on singleton class expressions. [Bug #10943]
* vm_core.h, method.h: remove rb_iseq_t::cref_stack. CREF is stored
to rb_method_definition_t::body.iseq_body.cref.
* vm_insnhelper.c: modify SVAR usage.
When calling ISEQ type method, push CREF information onto method
frame, SVAR located place. Before this fix, SVAR is simply nil.
After this patch, CREF (or NULL == Qfalse for not iseq methods)
is stored at the method invocation.
When SVAR is requierd, then put NODE_IF onto SVAR location,
and NDOE_IF::nd_reserved points CREF itself.
* vm.c (vm_cref_new, vm_cref_dump, vm_cref_new_toplevel): added.
* vm_insnhelper.c (vm_push_frame): accept CREF.
* method.h, vm_method.c (rb_add_method_iseq): added. This function
accepts iseq and CREF.
* class.c (clone_method): use rb_add_method_iseq().
* gc.c (mark_method_entry): mark method_entry::body.iseq_body.cref.
* iseq.c: remove CREF related codes.
* insns.def (getinlinecache/setinlinecache): CREF should be cache key
because a different CREF has a different namespace.
* node.c (rb_gc_mark_node): mark NODE_IF::nd_reserved for SVAR.
* proc.c: catch up changes.
* struct.c: ditto.
* insns.def: ditto.
* vm_args.c (raise_argument_error): ditto.
* vm_eval.c: ditto.
* test/ruby/test_class.rb: add a test.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49874 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-03-06 07:24:58 -05:00
|
|
|
void rb_add_method_iseq(VALUE klass, ID mid, rb_iseq_t *iseq, NODE *cref, rb_method_flag_t noex);
|
2009-07-15 20:37:25 -04:00
|
|
|
rb_method_entry_t *rb_add_method(VALUE klass, ID mid, rb_method_type_t type, void *option, rb_method_flag_t noex);
|
2012-08-02 07:08:44 -04:00
|
|
|
rb_method_entry_t *rb_method_entry(VALUE klass, ID id, VALUE *define_class_ptr);
|
2013-05-13 01:51:14 -04:00
|
|
|
rb_method_entry_t *rb_method_entry_at(VALUE obj, ID id);
|
* revised r37993 to avoid SEGV/ILL in tests. In r37993, a method
entry with VM_METHOD_TYPE_REFINED holds only the original method
definition, so ci->me is set to a method entry allocated in the
stack, and it causes SEGV/ILL. In this commit, a method entry
with VM_METHOD_TYPE_REFINED holds the whole original method entry.
Furthermore, rb_thread_mark() is changed to mark cfp->klass to
avoid GC for iclasses created by copy_refinement_iclass().
* vm_method.c (rb_method_entry_make): add a method entry with
VM_METHOD_TYPE_REFINED to the class refined by the refinement if
the target module is a refinement. When a method entry with
VM_METHOD_TYPE_UNDEF is invoked by vm_call_method(), a method with
the same name is searched in refinements. If such a method is
found, the method is invoked. Otherwise, the original method in
the refined class (rb_method_definition_t::body.orig_me) is
invoked. This change is made to simplify the normal method lookup
and to improve the performance of normal method calls.
* vm_method.c (EXPR1, search_method, rb_method_entry),
vm_eval.c (rb_call0, rb_search_method_entry): do not use
refinements for method lookup.
* vm_insnhelper.c (vm_call_method): search methods in refinements if
ci->me is VM_METHOD_TYPE_REFINED. If the method is called by
super (i.e., ci->call == vm_call_super_method), skip the same
method entry as the current method to avoid infinite call of the
same method.
* class.c (include_modules_at): add a refined method entry for each
method defined in a module included in a refinement.
* class.c (rb_prepend_module): set an empty table to
RCLASS_M_TBL(klass) to add refined method entries, because
refinements should have priority over prepended modules.
* proc.c (mnew): use rb_method_entry_with_refinements() to get
a refined method.
* vm.c (rb_thread_mark): mark cfp->klass for iclasses created by
copy_refinement_iclass().
* vm.c (Init_VM), cont.c (fiber_init): initialize th->cfp->klass.
* test/ruby/test_refinement.rb (test_inline_method_cache): do not skip
the test because it should pass successfully.
* test/ruby/test_refinement.rb (test_redefine_refined_method): new
test for the case a refined method is redefined.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38236 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-06 08:08:41 -05:00
|
|
|
void rb_add_refined_method_entry(VALUE refined_class, ID mid);
|
|
|
|
rb_method_entry_t *rb_resolve_refined_method(VALUE refinements,
|
2013-09-09 23:39:28 -04:00
|
|
|
const rb_method_entry_t *me,
|
* revised r37993 to avoid SEGV/ILL in tests. In r37993, a method
entry with VM_METHOD_TYPE_REFINED holds only the original method
definition, so ci->me is set to a method entry allocated in the
stack, and it causes SEGV/ILL. In this commit, a method entry
with VM_METHOD_TYPE_REFINED holds the whole original method entry.
Furthermore, rb_thread_mark() is changed to mark cfp->klass to
avoid GC for iclasses created by copy_refinement_iclass().
* vm_method.c (rb_method_entry_make): add a method entry with
VM_METHOD_TYPE_REFINED to the class refined by the refinement if
the target module is a refinement. When a method entry with
VM_METHOD_TYPE_UNDEF is invoked by vm_call_method(), a method with
the same name is searched in refinements. If such a method is
found, the method is invoked. Otherwise, the original method in
the refined class (rb_method_definition_t::body.orig_me) is
invoked. This change is made to simplify the normal method lookup
and to improve the performance of normal method calls.
* vm_method.c (EXPR1, search_method, rb_method_entry),
vm_eval.c (rb_call0, rb_search_method_entry): do not use
refinements for method lookup.
* vm_insnhelper.c (vm_call_method): search methods in refinements if
ci->me is VM_METHOD_TYPE_REFINED. If the method is called by
super (i.e., ci->call == vm_call_super_method), skip the same
method entry as the current method to avoid infinite call of the
same method.
* class.c (include_modules_at): add a refined method entry for each
method defined in a module included in a refinement.
* class.c (rb_prepend_module): set an empty table to
RCLASS_M_TBL(klass) to add refined method entries, because
refinements should have priority over prepended modules.
* proc.c (mnew): use rb_method_entry_with_refinements() to get
a refined method.
* vm.c (rb_thread_mark): mark cfp->klass for iclasses created by
copy_refinement_iclass().
* vm.c (Init_VM), cont.c (fiber_init): initialize th->cfp->klass.
* test/ruby/test_refinement.rb (test_inline_method_cache): do not skip
the test because it should pass successfully.
* test/ruby/test_refinement.rb (test_redefine_refined_method): new
test for the case a refined method is redefined.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38236 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-06 08:08:41 -05:00
|
|
|
VALUE *defined_class_ptr);
|
|
|
|
rb_method_entry_t *rb_method_entry_with_refinements(VALUE klass, ID id,
|
|
|
|
VALUE *defined_class_ptr);
|
2012-12-09 03:48:34 -05:00
|
|
|
rb_method_entry_t *rb_method_entry_without_refinements(VALUE klass, ID id,
|
|
|
|
VALUE *defined_class_ptr);
|
* revised r37993 to avoid SEGV/ILL in tests. In r37993, a method
entry with VM_METHOD_TYPE_REFINED holds only the original method
definition, so ci->me is set to a method entry allocated in the
stack, and it causes SEGV/ILL. In this commit, a method entry
with VM_METHOD_TYPE_REFINED holds the whole original method entry.
Furthermore, rb_thread_mark() is changed to mark cfp->klass to
avoid GC for iclasses created by copy_refinement_iclass().
* vm_method.c (rb_method_entry_make): add a method entry with
VM_METHOD_TYPE_REFINED to the class refined by the refinement if
the target module is a refinement. When a method entry with
VM_METHOD_TYPE_UNDEF is invoked by vm_call_method(), a method with
the same name is searched in refinements. If such a method is
found, the method is invoked. Otherwise, the original method in
the refined class (rb_method_definition_t::body.orig_me) is
invoked. This change is made to simplify the normal method lookup
and to improve the performance of normal method calls.
* vm_method.c (EXPR1, search_method, rb_method_entry),
vm_eval.c (rb_call0, rb_search_method_entry): do not use
refinements for method lookup.
* vm_insnhelper.c (vm_call_method): search methods in refinements if
ci->me is VM_METHOD_TYPE_REFINED. If the method is called by
super (i.e., ci->call == vm_call_super_method), skip the same
method entry as the current method to avoid infinite call of the
same method.
* class.c (include_modules_at): add a refined method entry for each
method defined in a module included in a refinement.
* class.c (rb_prepend_module): set an empty table to
RCLASS_M_TBL(klass) to add refined method entries, because
refinements should have priority over prepended modules.
* proc.c (mnew): use rb_method_entry_with_refinements() to get
a refined method.
* vm.c (rb_thread_mark): mark cfp->klass for iclasses created by
copy_refinement_iclass().
* vm.c (Init_VM), cont.c (fiber_init): initialize th->cfp->klass.
* test/ruby/test_refinement.rb (test_inline_method_cache): do not skip
the test because it should pass successfully.
* test/ruby/test_refinement.rb (test_redefine_refined_method): new
test for the case a refined method is redefined.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38236 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-06 08:08:41 -05:00
|
|
|
|
2013-09-24 01:02:13 -04:00
|
|
|
rb_method_entry_t *rb_method_entry_get_without_cache(VALUE klass, ID id, VALUE *define_class_ptr);
|
2010-05-04 16:25:09 -04:00
|
|
|
rb_method_entry_t *rb_method_entry_set(VALUE klass, ID mid, const rb_method_entry_t *, rb_method_flag_t noex);
|
|
|
|
|
2009-07-15 20:37:25 -04:00
|
|
|
int rb_method_entry_arity(const rb_method_entry_t *me);
|
* method.h, internal.h iseq.h: declare internal functions.
* compile.c, eval.c, iseq.c, object.c, parse.y, proc.c, process.c,
thread.c, vm.c, vm_eval.c, vm_insnhelper.c, vm_method.c: don't
declare internal functions.
Note that rb_method_entry_eq() is defined in vm_method.c but
there was a declaration in proc.c with different const-ness.
Now it is declared in method.h with same const-ness to the
definition.
* object.c (rb_mod_module_exec): don't declare functions declared in
include/ruby/intern.h.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32163 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-17 23:49:33 -04:00
|
|
|
int rb_method_entry_eq(const rb_method_entry_t *m1, const rb_method_entry_t *m2);
|
2012-02-20 19:13:44 -05:00
|
|
|
st_index_t rb_hash_method_entry(st_index_t hash, const rb_method_entry_t *me);
|
2010-05-04 16:25:09 -04:00
|
|
|
|
2013-02-05 23:35:23 -05:00
|
|
|
VALUE rb_method_entry_location(rb_method_entry_t *me);
|
|
|
|
VALUE rb_mod_method_location(VALUE mod, ID id);
|
|
|
|
VALUE rb_obj_method_location(VALUE obj, ID id);
|
|
|
|
|
2010-05-04 18:27:18 -04:00
|
|
|
void rb_mark_method_entry(const rb_method_entry_t *me);
|
2009-08-27 22:45:41 -04:00
|
|
|
void rb_free_method_entry(rb_method_entry_t *me);
|
2010-05-05 13:51:21 -04:00
|
|
|
void rb_sweep_method_entry(void *vm);
|
2009-07-15 20:37:25 -04:00
|
|
|
|
|
|
|
#endif /* METHOD_H */
|