summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-26 08:11:48 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-26 08:11:48 +0000
commitb20ecf49d4d81474bf9352c0f14963cefea660c7 (patch)
tree7c4180bee03d7b0ac4e390d910dd6b59c8291413
parentc4b61464a69c3b3fb6f9701a3c5b8e0aededb336 (diff)
merge revision(s) 41343,41360,41386: [Backport #8531]
test/ruby/test_symbol.rb: tests for [Bug #8531] * include/ruby/ruby.h, vm_eval.c (rb_funcall_with_block): new function to invoke a method with a block passed as an argument. * string.c (sym_call): use the above function to avoid a block sharing. [ruby-dev:47438] [Bug #8531] * vm_insnhelper.c (vm_yield_with_cfunc): don't set block in the frame. * test/ruby/test_symbol.rb (TestSymbol#test_block_given_to_proc): run related tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@41653 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog15
-rw-r--r--include/ruby/ruby.h1
-rw-r--r--string.c4
-rw-r--r--test/ruby/test_symbol.rb29
-rw-r--r--version.h2
-rw-r--r--vm_eval.c17
6 files changed, 64 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index ce135d499d..6ac7c155c7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+Wed Jun 26 17:08:13 2013 Kazuki Tsujimoto <kazuki@callcc.net>
+
+ * include/ruby/ruby.h, vm_eval.c (rb_funcall_with_block):
+ new function to invoke a method with a block passed
+ as an argument.
+
+ * string.c (sym_call): use the above function to avoid
+ a block sharing. [ruby-dev:47438] [Bug #8531]
+
+ * vm_insnhelper.c (vm_yield_with_cfunc): don't set block
+ in the frame.
+
+ * test/ruby/test_symbol.rb (TestSymbol#test_block_given_to_proc):
+ run related tests.
+
Wed Jun 26 17:01:22 2013 NAKAMURA Usaku <usa@ruby-lang.org>
* benchmark/bm_hash_shift.rb: add benchmark for Hash#shift
diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h
index 2f97b33bc4..453a6039a9 100644
--- a/include/ruby/ruby.h
+++ b/include/ruby/ruby.h
@@ -1153,6 +1153,7 @@ VALUE rb_funcall(VALUE, ID, int, ...);
VALUE rb_funcall2(VALUE, ID, int, const VALUE*);
VALUE rb_funcall3(VALUE, ID, int, const VALUE*);
VALUE rb_funcall_passing_block(VALUE, ID, int, const VALUE*);
+VALUE rb_funcall_with_block(VALUE, ID, int, const VALUE*, VALUE);
int rb_scan_args(int, const VALUE*, const char*, ...);
VALUE rb_call_super(int, const VALUE*);
diff --git a/string.c b/string.c
index f2c60715a2..7f4c44eba6 100644
--- a/string.c
+++ b/string.c
@@ -7512,7 +7512,7 @@ sym_to_sym(VALUE sym)
}
static VALUE
-sym_call(VALUE args, VALUE sym, int argc, VALUE *argv)
+sym_call(VALUE args, VALUE sym, int argc, VALUE *argv, VALUE passed_proc)
{
VALUE obj;
@@ -7520,7 +7520,7 @@ sym_call(VALUE args, VALUE sym, int argc, VALUE *argv)
rb_raise(rb_eArgError, "no receiver given");
}
obj = argv[0];
- return rb_funcall_passing_block(obj, (ID)sym, argc - 1, argv + 1);
+ return rb_funcall_with_block(obj, (ID)sym, argc - 1, argv + 1, passed_proc);
}
/*
diff --git a/test/ruby/test_symbol.rb b/test/ruby/test_symbol.rb
index c98f954092..23c50e6778 100644
--- a/test/ruby/test_symbol.rb
+++ b/test/ruby/test_symbol.rb
@@ -33,7 +33,7 @@ class TestSymbol < Test::Unit::TestCase
assert_inspect_evaled(':foo')
assert_inspect_evaled(':foo!')
assert_inspect_evaled(':bar?')
- assert_inspect_evaled(':<<')
+ assert_inspect_evaled(":<<")
assert_inspect_evaled(':>>')
assert_inspect_evaled(':<=')
assert_inspect_evaled(':>=')
@@ -102,6 +102,33 @@ class TestSymbol < Test::Unit::TestCase
assert_raise(ArgumentError) { :foo.to_proc.call }
end
+ def m_block_given?
+ block_given?
+ end
+
+ def m2_block_given?(m = nil)
+ if m
+ [block_given?, m.call(self)]
+ else
+ block_given?
+ end
+ end
+
+ def test_block_given_to_proc
+ bug8531 = '[Bug #8531]'
+ m = :m_block_given?.to_proc
+ assert(!m.call(self), "#{bug8531} without block")
+ assert(m.call(self) {}, "#{bug8531} with block")
+ assert(!m.call(self), "#{bug8531} without block second")
+ end
+
+ def test_block_persist_between_calls
+ bug8531 = '[Bug #8531]'
+ m2 = :m2_block_given?.to_proc
+ assert_equal([true, false], m2.call(self, m2) {}, "#{bug8531} nested with block")
+ assert_equal([false, false], m2.call(self, m2), "#{bug8531} nested without block")
+ end
+
def test_succ
assert_equal(:fop, :foo.succ)
end
diff --git a/version.h b/version.h
index 709573220f..6288f6d747 100644
--- a/version.h
+++ b/version.h
@@ -1,5 +1,5 @@
#define RUBY_VERSION "1.9.3"
-#define RUBY_PATCHLEVEL 444
+#define RUBY_PATCHLEVEL 445
#define RUBY_RELEASE_DATE "2013-06-26"
#define RUBY_RELEASE_YEAR 2013
diff --git a/vm_eval.c b/vm_eval.c
index 0c740285be..2291001a2e 100644
--- a/vm_eval.c
+++ b/vm_eval.c
@@ -694,6 +694,23 @@ rb_funcall_passing_block(VALUE recv, ID mid, int argc, const VALUE *argv)
return rb_call(recv, mid, argc, argv, CALL_PUBLIC);
}
+VALUE
+rb_funcall_with_block(VALUE recv, ID mid, int argc, const VALUE *argv, VALUE pass_procval)
+{
+ if (!NIL_P(pass_procval)) {
+ rb_thread_t *th = GET_THREAD();
+ rb_block_t *block = 0;
+
+ rb_proc_t *pass_proc;
+ GetProcPtr(pass_procval, pass_proc);
+ block = &pass_proc->block;
+
+ th->passed_block = block;
+ }
+
+ return rb_call(recv, mid, argc, argv, CALL_PUBLIC);
+}
+
static VALUE
send_internal(int argc, const VALUE *argv, VALUE recv, call_type scope)
{