On 4/10/07, MenTaLguY <mental / rydia.net> wrote:
> On Wed, 11 Apr 2007 02:28:33 +0900, "Luis Parravicini" <lparravi / gmail.com> wrote:
> > grepping the ruby source shows regex.c is the only file with that
> > string. And thats how far I got. Any ideas?
>
> The error is coming from the parser.  Here's a simpler test case using integers:
>
>  eval <<EOS
>    case x
>    #{ (0..2498).map { |n| "when #{n}: nil\n" }.join('') }
>    end
>  EOS
>
> We know that it's happening at parse-time rather than run-time, because the out-of-memory error occurs before Ruby has a chance to complain that 'x' is undefined.
>
> In short, the Ruby parser apparently cannot cope with case statements which have more than 2498 branches (at least with the build of Ruby I've got here, changing 2498 to 2497 is enough to avoid the memory issue).
>

Probably hitting a lex/yacc semantic stack limit.

I wonder if you could do the same kind of thing with a
begin/rescue/ensure/end clause?

Hmmm ....

eval <<EOS
begin
  raise
#{ (0..1999).map { "rescue;\n" }.join('') }
end
EOS

(eval):2003: compile error (SyntaxError)
(eval):2003: memory exhausted


Sure enough!  But it only took 1999 rescue clauses. 1998 does not
cause it to happen.

Blessings,
TwP