diff options
author | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-09-30 01:49:21 +0000 |
---|---|---|
committer | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-09-30 01:49:21 +0000 |
commit | 59f5fa102af7777ba1c620b764fa05f62dad9b54 (patch) | |
tree | 705fcdae3058eec37e84035030f7deadf0c34136 | |
parent | 7eca2a43b98d7a752a9dc1c19a0955f343b3383d (diff) | |
download | ruby-59f5fa102af7777ba1c620b764fa05f62dad9b54.tar.gz |
* vm_method.c (rb_undef): raise a NameError if the original method
of a refined method is not defined.
* vm_insnhelper.c (rb_method_entry_eq): added NULL check to avoid SEGV.
* test/ruby/test_refinement.rb: related test.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43090 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | test/ruby/test_refinement.rb | 44 | ||||
-rw-r--r-- | vm_method.c | 8 |
3 files changed, 58 insertions, 3 deletions
@@ -1,3 +1,12 @@ +Mon Sep 30 10:40:20 2013 Shugo Maeda <shugo@ruby-lang.org> + + * vm_method.c (rb_undef): raise a NameError if the original method + of a refined method is not defined. + + * vm_insnhelper.c (rb_method_entry_eq): added NULL check to avoid SEGV. + + * test/ruby/test_refinement.rb: related test. + Sun Sep 29 23:45:42 2013 Nobuyoshi Nakada <nobu@ruby-lang.org> * parse.y (rb_id_attrset, intern_str): allow junk attrset ID for diff --git a/test/ruby/test_refinement.rb b/test/ruby/test_refinement.rb index 60681b2f1a..92f293cad5 100644 --- a/test/ruby/test_refinement.rb +++ b/test/ruby/test_refinement.rb @@ -1016,6 +1016,50 @@ class TestRefinement < Test::Unit::TestCase assert_not_send([FooSub, :method_defined?, :z]) end + def test_undef_refined_method + bug8966 = '[ruby-core:57466] [Bug #8966]' + + assert_in_out_err([], <<-INPUT, ["NameError"], [], bug8966) + module Foo + refine Object do + def foo + puts "foo" + end + end + end + + using Foo + + class Object + begin + undef foo + rescue Exception => e + p e.class + end + end + INPUT + + assert_in_out_err([], <<-INPUT, ["NameError"], [], bug8966) + module Foo + refine Object do + def foo + puts "foo" + end + end + end + + # without `using Foo' + + class Object + begin + undef foo + rescue Exception => e + p e.class + end + end + INPUT + end + private def eval_using(mod, s) diff --git a/vm_method.c b/vm_method.c index e4ba0e9865..8bd2b2ce56 100644 --- a/vm_method.c +++ b/vm_method.c @@ -868,7 +868,9 @@ rb_undef(VALUE klass, ID id) me = search_method(klass, id, 0); - if (UNDEFINED_METHOD_ENTRY_P(me)) { + if (UNDEFINED_METHOD_ENTRY_P(me) || + (me->def->type == VM_METHOD_TYPE_REFINED && + UNDEFINED_METHOD_ENTRY_P(me->def->body.orig_me))) { const char *s0 = " class"; VALUE c = klass; @@ -1118,9 +1120,9 @@ rb_method_entry_eq(const rb_method_entry_t *m1, const rb_method_entry_t *m2) static int rb_method_definition_eq(const rb_method_definition_t *d1, const rb_method_definition_t *d2) { - if (d1 && d1->type == VM_METHOD_TYPE_REFINED) + if (d1 && d1->type == VM_METHOD_TYPE_REFINED && d1->body.orig_me) d1 = d1->body.orig_me->def; - if (d2 && d2->type == VM_METHOD_TYPE_REFINED) + if (d2 && d2->type == VM_METHOD_TYPE_REFINED && d2->body.orig_me) d2 = d2->body.orig_me->def; if (d1 == d2) return 1; if (!d1 || !d2) return 0; |