From: Michael Edgar Date: 2011-02-24T13:47:03+09:00 Subject: [ruby-core:35361] Re: eval'ing large strings runs out of stack space? This occurs because array literals with string literals in them get compiled to YARV bytecode as follows: p RubyVM::InstructionSequence.compile(%Q{ #{(['0'] * 15).inspect} }).to_a (snip) [:putstring, "0"], [:putstring, "0"], [:putstring, "0"], [:putstring, "0"], [:putstring, "0"], [:putstring, "0"], [:putstring, "0"], [:putstring, "0"], [:putstring, "0"], [:putstring, "0"], [:putstring, "0"], [:putstring, "0"], [:putstring, "0"], [:putstring, "0"], [:putstring, "0"], [:newarray, 15], [:leave] It pushes each string argument and then calls newarray to collapse all the strings on the stack into one array. If you use something else, say integers, you might see something like this: p RubyVM::InstructionSequence.compile(%Q{ #{(0..15).to_a.inspect} }).to_a (snip) [:duparray, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]], [:leave] Needless to say, when you switch "15" to "150000", the stack gets too big. I'm pretty sure the SystemStackError gets raised at vm_eval.c : 1027-1028 which does a standard CHECK_STACK_OVERFLOW on the compiled bytecode, but don't hold me to that. Michael Edgar adgar@carboni.ca http://carboni.ca/ On Feb 23, 2011, at 3:28 PM, Roger Pack wrote: > Hello all. > This code: > > eval (['000000000']*500000).inspect > > with 1.9.2 (but not jruby) > > causes this: > > das_inspect:0: stack level too deep (SystemStackError) > > Is this expected? > Thanks! > -r >