[#35027] [Ruby 1.9-Bug#4352][Open] [patch] Fix eval(s, b) backtrace; make eval(s, b) consistent with eval(s) — "James M. Lawrence" <redmine@...>

Bug #4352: [patch] Fix eval(s, b) backtrace; make eval(s, b) consistent with eval(s)

16 messages 2011/02/01

[#35114] [Ruby 1.9-Bug#4373][Open] http.rb:677: [BUG] Segmentation fault — Christian Fazzini <redmine@...>

Bug #4373: http.rb:677: [BUG] Segmentation fault

59 messages 2011/02/06

[#35171] [Ruby 1.9-Bug#4386][Open] encoding: directive does not affect regex expressions — mathew murphy <redmine@...>

Bug #4386: encoding: directive does not affect regex expressions

9 messages 2011/02/09

[#35237] [Ruby 1.9-Bug#4400][Open] nested at_exit hooks run in strange order — Suraj Kurapati <redmine@...>

Bug #4400: nested at_exit hooks run in strange order

12 messages 2011/02/15

[ruby-core:35361] Re: eval'ing large strings runs out of stack space?

From: Michael Edgar <adgar@...>
Date: 2011-02-24 04:47:03 UTC
List: ruby-core #35361
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
> 


In This Thread