ruby-changes:22934
From: nobu <ko1@a...>
Date: Mon, 12 Mar 2012 12:44:56 +0900 (JST)
Subject: [ruby-changes:22934] nobu:r34983 (trunk): * vm_method.c (Init_eval_method): copy basic methods to Exception.
nobu 2012-03-12 12:44:40 +0900 (Mon, 12 Mar 2012) New Revision: 34983 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=34983 Log: * vm_method.c (Init_eval_method): copy basic methods to Exception. [ruby-core:40287][Bug #5473] Modified files: trunk/ChangeLog trunk/test/ruby/test_object.rb trunk/vm_method.c Index: ChangeLog =================================================================== --- ChangeLog (revision 34982) +++ ChangeLog (revision 34983) @@ -1,3 +1,8 @@ +Mon Mar 12 12:44:33 2012 Nobuyoshi Nakada <nobu@r...> + + * vm_method.c (Init_eval_method): copy basic methods to Exception. + [ruby-core:40287][Bug #5473] + Mon Mar 12 10:13:36 2012 Nobuyoshi Nakada <nobu@r...> * eval_jump.c (rb_exec_end_proc): remember the latest exit status. Index: vm_method.c =================================================================== --- vm_method.c (revision 34982) +++ vm_method.c (revision 34983) @@ -6,6 +6,8 @@ #define CACHE_MASK 0x7ff #define EXPR1(c,m) ((((c)>>3)^(m))&CACHE_MASK) +#define NOEX_NOREDEF NOEX_RESPONDS + static void rb_vm_check_redefinition_opt_method(const rb_method_entry_t *me, VALUE klass); static ID object_id, respond_to_missing; @@ -195,6 +197,11 @@ rb_method_definition_t *old_def = old_me->def; if (rb_method_definition_eq(old_def, def)) return old_me; +#if 0 + if (old_me->flag & NOEX_NOREDEF) { + rb_raise(rb_eTypeError, "cannot redefine %s#%s", rb_class2name(klass), rb_id2name(mid)); + } +#endif rb_vm_check_redefinition_opt_method(old_me, klass); if (RTEST(ruby_verbose) && @@ -1385,5 +1392,14 @@ singleton_undefined = rb_intern("singleton_method_undefined"); attached = rb_intern("__attached__"); respond_to_missing = rb_intern("respond_to_missing?"); + + { +#define REPLICATE_METHOD(klass, id) \ + rb_method_entry_set((klass), (id), rb_method_entry((klass), (id)), \ + (rb_method_flag_t)(NOEX_PRIVATE | NOEX_BASIC | NOEX_NOREDEF)) + REPLICATE_METHOD(rb_eException, idMethodMissing); + REPLICATE_METHOD(rb_eException, idRespond_to); + REPLICATE_METHOD(rb_eException, respond_to_missing); + } } Index: test/ruby/test_object.rb =================================================================== --- test/ruby/test_object.rb (revision 34982) +++ test/ruby/test_object.rb (revision 34983) @@ -728,4 +728,22 @@ :foo.singleton_class end end + + def test_redef_method_missing + bug5473 = '[ruby-core:40287]' + ['ArgumentError.new("bug5473")', 'ArgumentError, "bug5473"', '"bug5473"'].each do |code| + out, err, status = EnvUtil.invoke_ruby([], <<-SRC, true, true) + class ::Object + def method_missing(m, *a, &b) + raise #{code} + end + end + + p((1.foo rescue $!)) + SRC + assert_send([status, :success?], bug5473) + assert_equal("", err, bug5473) + assert_equal((eval("raise #{code}") rescue $!.inspect), out.chomp, bug5473) + end + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/