Hi,

At Wed, 9 Jan 2002 01:31:03 +0900,
matz / ruby-lang.org (Yukihiro Matsumoto) wrote:
> ||Another solution is to call rb_clear_cache_by_id() when a
> ||method is replaced. 
> |
> |Could you commit this patch?
> 
> Oops, rb_clear_cache_by_id() should be called regardless of
> overriding, for cases such as:
> 
>   classes C < B < A.
>   class A defines foo.
>   {id:foo, klass:C, origin:A} is cached.
> 
>   then redefine B#foo, which does not replace older method, but cache
>   should be invalidated.

Exactly.


Index: eval.c =================================================================== RCS file: /cvs/ruby/src/ruby/eval.c,v retrieving revision 1.239 diff -u -2 -p -r1.239 eval.c --- eval.c 2002/01/08 07:02:26 1.239 +++ eval.c 2002/01/08 17:22:19 @@ -229,7 +229,7 @@ rb_add_method(klass, mid, node, noex) } if (OBJ_FROZEN(klass)) rb_error_frozen("class/module"); + rb_clear_cache_by_id(mid); body = NEW_METHOD(node, noex); - if (st_insert(RCLASS(klass)->m_tbl, mid, body)) - rb_clear_cache_by_id(mid); + st_insert(RCLASS(klass)->m_tbl, mid, body); } @@ -359,5 +359,4 @@ rb_disable_super(klass, name) } else { - rb_clear_cache_by_id(mid); rb_add_method(klass, mid, 0, NOEX_UNDEF); } @@ -409,5 +408,4 @@ rb_export_method(klass, name, noex) } else { - rb_clear_cache_by_id(name); rb_add_method(klass, name, NEW_ZSUPER(), noex); } @@ -479,5 +477,4 @@ rb_attr(klass, id, read, write, ex) attriv = rb_intern(buf); if (read) { - rb_clear_cache_by_id(id); rb_add_method(klass, id, NEW_IVAR(attriv), noex); rb_funcall(klass, added, 1, ID2SYM(id)); @@ -486,5 +483,4 @@ rb_attr(klass, id, read, write, ex) sprintf(buf, "%s=", name); id = rb_intern(buf); - rb_clear_cache_by_id(id); rb_add_method(klass, id, NEW_ATTRSET(attriv), noex); rb_funcall(klass, added, 1, ID2SYM(id)); @@ -1585,5 +1581,4 @@ rb_undef(klass, id) rb_id2name(id),s0,rb_class2name(c)); } - rb_clear_cache_by_id(id); rb_add_method(klass, id, 0, NOEX_PUBLIC); if (FL_TEST(klass, FL_SINGLETON)) { @@ -3106,5 +3101,4 @@ rb_eval(self, n) defn = copy_node_scope(node->nd_defn, ruby_cref); - rb_clear_cache_by_id(node->nd_mid); rb_add_method(ruby_class, node->nd_mid, defn, noex); if (scope_vmode == SCOPE_MODFUNC) { @@ -3152,5 +3146,4 @@ rb_eval(self, n) defn = copy_node_scope(node->nd_defn, ruby_cref); defn->nd_rval = (VALUE)ruby_cref; - rb_clear_cache_by_id(node->nd_mid); rb_add_method(klass, node->nd_mid, defn, NOEX_PUBLIC|(body?body->nd_noex&NOEX_UNDEF:0)); @@ -5715,5 +5708,4 @@ rb_mod_modfunc(argc, argv, module) m = RCLASS(m)->super; } - rb_clear_cache_by_id(id); rb_add_method(rb_singleton_class(module), id, body->nd_body, NOEX_PUBLIC); rb_funcall(module, singleton_added, 1, ID2SYM(id)); @@ -6982,5 +6974,4 @@ rb_mod_define_method(argc, argv, mod) noex = NOEX_PUBLIC; } - rb_clear_cache_by_id(id); rb_add_method(mod, id, node, noex); if (scope_vmode == SCOPE_MODFUNC) {
-- Nobu Nakada