summaryrefslogtreecommitdiff
path: root/bootstraptest/test_literal.rb
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-04-12 01:33:34 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-04-12 01:33:34 +0000
commitee7f8d4805fb4a661b8e8328be49f32cbc3e606d (patch)
tree82f7f28bb49cb5c3c571a649a9b32b61eb7ce988 /bootstraptest/test_literal.rb
parent655738577ffd90df3796c73afd8be84cd89091f6 (diff)
* compile.c (compile_array, compile_array_):
Divide big array (or hash) literals into several blocks and concatetene them. There was a problem that a big array (hash) literal causes SystemStackError exception (stack overflow) because VM push all contents of the literal onto VM stack to make an array (or hash). To solve this issue, we make several arrays (hashes) and concatenate them to make a big array (hash) object. ?? * compile.c (iseq_compile_each, setup_args): use modified compile_array. * vm.c (m_core_hash_from_ary, m_core_hash_merge_ary, m_core_hash_merge_ptr): added for above change. * id.c (Init_id), parse.y: add core method ids. * bootstraptest/test_literal.rb: add simple tests. * bootstraptest/test_eval.rb: remove rescue clause to catch SystemStackError exception. * test/ruby/test_literal.rb: add tests to check no stack overflow. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35306 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'bootstraptest/test_literal.rb')
-rw-r--r--bootstraptest/test_literal.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/bootstraptest/test_literal.rb b/bootstraptest/test_literal.rb
index ab028e2..19200c1 100644
--- a/bootstraptest/test_literal.rb
+++ b/bootstraptest/test_literal.rb
@@ -200,3 +200,25 @@ assert_equal 'ok', %q{
assert_equal 'ok', %q{
"#{}o""#{}k""#{}"
}, '[ruby-core:25284]'
+
+assert_equal 'ok', %q{ # long array literal
+ x = nil
+ eval "a = [#{(1..10_000).map{'x'}.join(", ")}]"
+ :ok
+}
+
+assert_equal 'ok', %q{ # long array literal (optimized)
+ eval "a = [#{(1..10_000).to_a.join(", ")}]"
+ :ok
+}
+
+assert_equal 'ok', %q{ # long hash literal
+ x = nil
+ eval "a = {#{(1..10_000).map{|n| "#{n} => x"}.join(', ')}}"
+ :ok
+}
+
+assert_equal 'ok', %q{ # long hash literal (optimized)
+ eval "a = {#{(1..10_000).map{|n| "#{n} => #{n}"}.join(', ')}}"
+ :ok
+}