summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog9
-rw-r--r--test/ruby/test_refinement.rb49
-rw-r--r--version.h2
-rw-r--r--vm_method.c8
4 files changed, 63 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 0804274673..94663f21bc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Sat Oct 5 01:59:50 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.
+
Sat Oct 5 00:16:33 2013 NARUSE, Yui <naruse@ruby-lang.org>
* process.c (rb_daemon): daemon(3) is implemented with fork(2).
diff --git a/test/ruby/test_refinement.rb b/test/ruby/test_refinement.rb
index acca7c04ce..b9d9c3e30d 100644
--- a/test/ruby/test_refinement.rb
+++ b/test/ruby/test_refinement.rb
@@ -827,7 +827,8 @@ class TestRefinement < Test::Unit::TestCase
end
def test_case_dispatch_is_aware_of_refinements
- assert_in_out_err([], <<-RUBY, ["refinement used"], ["-:2: warning: Refinements are experimental, and the behavior may change in future versions of Ruby!"])
+ assert_in_out_err([], <<-RUBY, ["refinement used"], [])
+ $VERBOSE = nil #to suppress warning "Refinements are experimental, ..."
module RefineSymbol
refine Symbol do
def ===(other)
@@ -858,6 +859,52 @@ 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)
+ $VERBOSE = nil #to suppress warning "Refinements are experimental, ..."
+ 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)
+ $VERBOSE = nil #to suppress warning "Refinements are experimental, ..."
+ 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/version.h b/version.h
index 54e45b7cc1..2c547d77a6 100644
--- a/version.h
+++ b/version.h
@@ -1,6 +1,6 @@
#define RUBY_VERSION "2.0.0"
#define RUBY_RELEASE_DATE "2013-10-05"
-#define RUBY_PATCHLEVEL 324
+#define RUBY_PATCHLEVEL 325
#define RUBY_RELEASE_YEAR 2013
#define RUBY_RELEASE_MONTH 10
diff --git a/vm_method.c b/vm_method.c
index e00c282ca9..41ddb2d1ac 100644
--- a/vm_method.c
+++ b/vm_method.c
@@ -852,7 +852,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;
@@ -1092,9 +1094,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;