Blogged by Ujihisa. Standard methods of programming and thoughts including Clojure, Vim, LLVM, Haskell, Ruby and Mathematics written by a Japanese programmer. github/ujihisa

Thursday, May 14, 2009

Memory exhausted in a deep nested array literal

When I was reading '[' section of parser.y,

7190       case '[':
7191         paren_nest++;

I got interested in how it will happen when paren_nest becomes huge. I tried this script:

(9995..11000).each do |n|
  p n
  eval '['*n + ']'*n
end

The result was

/var/folders/Dz/Dz5WpFSZGUaFLA8jp8kT5E+++TM/-Tmp-/v258465/130:3: (eval):1: compile error (SyntaxError)
(eval):1: memory exhausted
...[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]...
                              ^
  from /var/folders/Dz/Dz5WpFSZGUaFLA8jp8kT5E+++TM/-Tmp-/v258465/130:1:in `eval'
  from /var/folders/Dz/Dz5WpFSZGUaFLA8jp8kT5E+++TM/-Tmp-/v258465/130:3
  from /var/folders/Dz/Dz5WpFSZGUaFLA8jp8kT5E+++TM/-Tmp-/v258465/130:1:in `each'
  from /var/folders/Dz/Dz5WpFSZGUaFLA8jp8kT5E+++TM/-Tmp-/v258465/130:1

hmm

No comments:

Post a Comment

Followers