From ee7f8d4805fb4a661b8e8328be49f32cbc3e606d Mon Sep 17 00:00:00 2001 From: ko1 Date: Thu, 12 Apr 2012 01:33:34 +0000 Subject: * 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 --- test/ruby/test_literal.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test/ruby/test_literal.rb') diff --git a/test/ruby/test_literal.rb b/test/ruby/test_literal.rb index e7a7c76891..12b3eddd50 100644 --- a/test/ruby/test_literal.rb +++ b/test/ruby/test_literal.rb @@ -1,4 +1,5 @@ require 'test/unit' +require_relative 'envutil' class TestRubyLiteral < Test::Unit::TestCase @@ -186,6 +187,13 @@ class TestRubyLiteral < Test::Unit::TestCase assert_equal "literal", h["string"] end + def test_big_array_and_hash_literal + assert_normal_exit %q{x = nil; raise if eval("[#{(1..1_000_000).map{'x'}.join(", ")}]").size != 1_000_000}, "", timeout: 300 + assert_normal_exit %q{x = nil; raise if eval("[#{(1..1_000_000).to_a.join(", ")}]").size != 1_000_000}, "", timeout: 300 + assert_normal_exit %q{x = nil; raise if eval("{#{(1..1_000_000).map{|n| "#{n} => x"}.join(', ')}}").size != 1_000_000}, "", timeout: 300 + assert_normal_exit %q{x = nil; raise if eval("{#{(1..1_000_000).map{|n| "#{n} => #{n}"}.join(', ')}}").size != 1_000_000}, "", timeout: 300 + end + def test_range assert_instance_of Range, (1..2) assert_equal(1..2, 1..2) -- cgit v1.2.3