summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-08-11 13:22:31 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-08-11 13:22:31 +0000
commit6ff49bf81f9101d7074c660b4aaa0f963fff55fa (patch)
tree11e7cd187bf71fe73fbade7307451e3554909154
parentc4e2581392ef828160b760488d52c36464b451e3 (diff)
merge revision(s) r46775: [Backport #10016]
* vm_insnhelper.c (vm_callee_setup_keyword_arg): adjust VM stack pointer to get rid of overwriting splat arguments by arguments for `to_hash` conversion. [ruby-core:63593] [Bug #10016] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@47138 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--test/ruby/test_keyword.rb10
-rw-r--r--version.h6
-rw-r--r--vm_insnhelper.c15
4 files changed, 31 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 7941d287a9..fd246c7803 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Mon Aug 11 22:14:28 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * vm_insnhelper.c (vm_callee_setup_keyword_arg): adjust VM stack
+ pointer to get rid of overwriting splat arguments by arguments
+ for `to_hash` conversion. [ruby-core:63593] [Bug #10016]
+
Fri Aug 8 23:36:01 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/stringio/stringio.c (strio_write): use rb_str_append to
diff --git a/test/ruby/test_keyword.rb b/test/ruby/test_keyword.rb
index eb548b95e2..0930cf0f5d 100644
--- a/test/ruby/test_keyword.rb
+++ b/test/ruby/test_keyword.rb
@@ -463,6 +463,16 @@ class TestKeywordArguments < Test::Unit::TestCase
assert_equal({a: 1, b: 2}, m1(**o, **o2) {|x| break x}, bug9898)
end
+ def test_implicit_hash_conversion
+ bug10016 = '[ruby-core:63593] [Bug #10016]'
+
+ o = Object.new
+ def o.to_hash() { k: 9 } end
+ assert_equal([1, 42, [], o, :key, {}, nil], f9(1, o))
+ assert_equal([1, 9], m1(1, o) {|a, k: 0| break [a, k]}, bug10016)
+ assert_equal([1, 9], m1(1, o, &->(a, k: 0) {break [a, k]}), bug10016)
+ end
+
def test_gced_object_in_stack
bug8964 = '[ruby-dev:47729] [Bug #8964]'
assert_normal_exit %q{
diff --git a/version.h b/version.h
index d89750b948..54f0dd3c50 100644
--- a/version.h
+++ b/version.h
@@ -1,10 +1,10 @@
#define RUBY_VERSION "2.1.2"
-#define RUBY_RELEASE_DATE "2014-08-08"
-#define RUBY_PATCHLEVEL 196
+#define RUBY_RELEASE_DATE "2014-08-11"
+#define RUBY_PATCHLEVEL 197
#define RUBY_RELEASE_YEAR 2014
#define RUBY_RELEASE_MONTH 8
-#define RUBY_RELEASE_DAY 8
+#define RUBY_RELEASE_DAY 11
#include "ruby/version.h"
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index c9c91b0fc7..03493c13c8 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -1067,10 +1067,15 @@ vm_caller_setup_args(const rb_thread_t *th, rb_control_frame_t *cfp, rb_call_inf
}
static inline int
-vm_callee_setup_keyword_arg(const rb_iseq_t *iseq, int argc, int m, VALUE *orig_argv, VALUE *kwd)
+vm_callee_setup_keyword_arg(rb_thread_t *th, const rb_iseq_t *iseq, int argc, int m, VALUE *orig_argv, VALUE *kwd)
{
VALUE keyword_hash = 0, orig_hash;
int optional = iseq->arg_keywords - iseq->arg_keyword_required;
+ VALUE *const sp = th->cfp->sp;
+ const int mark_stack_len = th->mark_stack_len;
+
+ th->cfp->sp += argc;
+ th->mark_stack_len -= argc;
if (argc > m &&
!NIL_P(orig_hash = rb_check_hash_type(orig_argv[argc-1])) &&
@@ -1085,10 +1090,14 @@ vm_callee_setup_keyword_arg(const rb_iseq_t *iseq, int argc, int m, VALUE *orig_
rb_get_kwargs(keyword_hash, iseq->arg_keyword_table, iseq->arg_keyword_required,
(iseq->arg_keyword_check ? optional : -1-optional),
NULL);
+
if (!keyword_hash) {
keyword_hash = rb_hash_new();
}
+ th->cfp->sp = sp;
+ th->mark_stack_len = mark_stack_len;
+
*kwd = keyword_hash;
return argc;
@@ -1111,7 +1120,7 @@ vm_callee_setup_arg_complex(rb_thread_t *th, rb_call_info_t *ci, const rb_iseq_t
/* keyword argument */
if (iseq->arg_keyword != -1) {
- argc = vm_callee_setup_keyword_arg(iseq, argc, min, orig_argv, &keyword_hash);
+ argc = vm_callee_setup_keyword_arg(th, iseq, argc, min, orig_argv, &keyword_hash);
}
/* mandatory */
@@ -2212,7 +2221,7 @@ vm_yield_setup_block_args(rb_thread_t *th, const rb_iseq_t * iseq,
/* keyword argument */
if (iseq->arg_keyword != -1) {
- argc = vm_callee_setup_keyword_arg(iseq, argc, min, argv, &keyword_hash);
+ argc = vm_callee_setup_keyword_arg(th, iseq, argc, min, argv, &keyword_hash);
}
for (i=argc; i<m; i++) {