Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Stack level too deep (SystemStackError)

Reply
Thread Tools

Stack level too deep (SystemStackError)

 
 
Jesper Olsen
Guest
Posts: n/a
 
      01-14-2004
I have a program where I'm getting a Stack level too deep (SystemStackError)
exception

I did not expect this, and I would prefer to fix it by increasing the
stack, rather than changing the program...

Is this possible?
I think this exception is quite common, but was not able to google a
solution.

Jesper

--
http://JesperOlsen.Net


 
Reply With Quote
 
 
 
 
Gennady
Guest
Posts: n/a
 
      01-14-2004
Jesper Olsen wrote:
> I have a program where I'm getting a Stack level too deep (SystemStackError)
> exception
>
> I did not expect this, and I would prefer to fix it by increasing the
> stack, rather than changing the program...
>
> Is this possible?
> I think this exception is quite common, but was not able to google a
> solution.
>
> Jesper
>
> --
> http://JesperOlsen.Net
>

What's your OS? BTW, it is a known issue with Mac OS X where in most
cases you must increase the default stack size.

Gennady.


 
Reply With Quote
 
 
 
 
Jesper Olsen
Guest
Posts: n/a
 
      01-15-2004
Gennady <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> Jesper Olsen wrote:
> > I have a program where I'm getting a Stack level too deep (SystemStackError)
> > exception
> >
> > I did not expect this, and I would prefer to fix it by increasing the
> > stack, rather than changing the program...
> >
> > Is this possible?
> > I think this exception is quite common, but was not able to google a
> > solution.
> >
> > Jesper
> >
> > --
> > http://JesperOlsen.Net
> >

> What's your OS? BTW, it is a known issue with Mac OS X where in most
> cases you must increase the default stack size.


How?

>
> Gennady.


It happens both with

- Ruby 1.6.8 on BSD Unix
- Ruby 1.8.0 on Win2000


Jesper
 
Reply With Quote
 
Gennady
Guest
Posts: n/a
 
      01-15-2004

On Jan 14, 2004, at 23:31, Jesper Olsen wrote:

> Gennady <(E-Mail Removed)> wrote in message
> news:<(E-Mail Removed)>...
>> Jesper Olsen wrote:
>>> I have a program where I'm getting a Stack level too deep
>>> (SystemStackError)
>>> exception
>>>
>>> I did not expect this, and I would prefer to fix it by increasing the
>>> stack, rather than changing the program...
>>>
>>> Is this possible?
>>> I think this exception is quite common, but was not able to google a
>>> solution.
>>>
>>> Jesper
>>>
>>> --
>>> http://JesperOlsen.Net
>>>

>> What's your OS? BTW, it is a known issue with Mac OS X where in most
>> cases you must increase the default stack size.

>
> How?


In bash, "ulimit -s" shows the current stack size in kbytes (defaults
to 8192 in Mac OS X, really low). To change it issue "ulimit -s
<kbytes>".

The command may be different for other shells. You may put this command
in /etc/profile to be set every time a user logs in.

>
>>
>> Gennady.

>
> It happens both with
>
> - Ruby 1.6.8 on BSD Unix
> - Ruby 1.8.0 on Win2000


The above command will work for BSD Unix too. I do not know how to do
it for Win2000.

Are you sure that there's no actual problem with your program? It may
really be run-away in recursion, so increasing the stack size will only
make the problem happen somewhat later.

>
>
> Jesper
>
>


Sincerely,
Gennady Bystritsky




 
Reply With Quote
 
Robert Klemme
Guest
Posts: n/a
 
      01-15-2004

"Gennady" <(E-Mail Removed)> schrieb im Newsbeitrag
news:(E-Mail Removed)...
>
> On Jan 14, 2004, at 23:31, Jesper Olsen wrote:
>
> > Gennady <(E-Mail Removed)> wrote in message
> > news:<(E-Mail Removed)>...
> >> Jesper Olsen wrote:
> >>> I have a program where I'm getting a Stack level too deep
> >>> (SystemStackError)
> >>> exception
> >>>
> >>> I did not expect this, and I would prefer to fix it by increasing

the
> >>> stack, rather than changing the program...
> >>>
> >>> Is this possible?
> >>> I think this exception is quite common, but was not able to google a
> >>> solution.
> >>>
> >>> Jesper
> >>>
> >>> --
> >>> http://JesperOlsen.Net
> >>>
> >> What's your OS? BTW, it is a known issue with Mac OS X where in most
> >> cases you must increase the default stack size.

> >
> > How?

>
> In bash, "ulimit -s" shows the current stack size in kbytes (defaults
> to 8192 in Mac OS X, really low). To change it issue "ulimit -s
> <kbytes>".
>
> The command may be different for other shells. You may put this command
> in /etc/profile to be set every time a user logs in.
>
> >
> >>
> >> Gennady.

> >
> > It happens both with
> >
> > - Ruby 1.6.8 on BSD Unix
> > - Ruby 1.8.0 on Win2000

>
> The above command will work for BSD Unix too. I do not know how to do
> it for Win2000.
>
> Are you sure that there's no actual problem with your program? It may
> really be run-away in recursion, so increasing the stack size will only
> make the problem happen somewhat later.


Hm. On cygwin this happens:

10:15:30 [ContentReporter_BRANCH]: cat /c/temp/ruby/ulimit.sh
#!/bin/bash -f

ruby -e 'def t(i);p i;t(i+1);end;t(0)'
ulimit -s


<lines deleted>
13281
13282
13283
-e:1:in `p': stack level too deep (SystemStackError)
from -e:1:in `t'
from -e:1:in `t'
from -e:1:in `t'
from -e:1:in `t'
from -e:1:in `t'
from -e:1:in `t'
from -e:1:in `t'
from -e:1:in `t'
... 13274 levels...
from -e:1:in `t'
from -e:1:in `t'
from -e:1:in `t'
from -e:1
2047

This means that a stack size of approx 2MB suffices only for 13000+ stack
levels. IOW about 157 bytes per stack frame.

Unfortunately this can't be changed on cygwin:

10:16:06 [ContentReporter_BRANCH]: ulimit -s 4096
bash: ulimit: stack size: cannot modify limit: Invalid argument
10:18:19 [ContentReporter_BRANCH]: ulimit -S -s 4096
bash: ulimit: stack size: cannot modify limit: Invalid argument
10:18:23 [ContentReporter_BRANCH]: ulimit -H -s 4096
bash: ulimit: stack size: cannot modify limit: Invalid argument

I've always felt that Ruby is not too comfortable with recursion...

Cheers

robert

 
Reply With Quote
 
Jesper Olsen
Guest
Posts: n/a
 
      01-15-2004
Gennady <(E-Mail Removed)> wrote in message :
> >>>
> >> What's your OS? BTW, it is a known issue with Mac OS X where in most
> >> cases you must increase the default stack size.

> >
> > How?

>
> In bash, "ulimit -s" shows the current stack size in kbytes (defaults
> to 8192 in Mac OS X, really low). To change it issue "ulimit -s
> <kbytes>".
>


>
> Sincerely,
> Gennady Bystritsky


Thanks Gennady - that helped. (Mine was 4096)

Cheers
Jesper
 
Reply With Quote
 
gabriele renzi
Guest
Posts: n/a
 
      01-15-2004
il Thu, 15 Jan 2004 17:18:17 +0900, Gennady <(E-Mail Removed)> ha
scritto::

>
>On Jan 14, 2004, at 23:31, Jesper Olsen wrote:
>
>
>In bash, "ulimit -s" shows the current stack size in kbytes (defaults
>to 8192 in Mac OS X, really low). To change it issue "ulimit -s
><kbytes>".


on a sidenote, someone I know has the same max stack size as me
(8192), and with slightly different versions of 1.8.1, on debian he's
got a SystemStackError calculating ackermann(3,7), while I can even
calculate ackermann(3,.
I'm not a unix guru, may be possible that there are other things to
look for?


the ackermann implementation is:
def ackermann(m, n)
if m == 0
n + 1
elsif n == 0
ack(m - 1, 1)
else
ack(m - 1, ack(m, n - 1))
end
end
 
Reply With Quote
 
Van Jacques
Guest
Posts: n/a
 
      01-16-2004
gabriele renzi <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>. ..
> il Thu, 15 Jan 2004 17:18:17 +0900, Gennady <(E-Mail Removed)> ha
> scritto::

I had the same problem with stacksize too low on a MAC OS X,
running the 3n+1 problem. It would go till the number in the 30s
where there are many iterations, then give me the stacksize
error. Increasing the stacksize solved the problem.

Van
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"stack level too deep"... because Threads keep their "starting" stack Sam Roberts Ruby 1 02-11-2005 04:25 AM
stack level too deep or crash in Marshal.load Ronny Voelker Ruby 0 09-24-2004 12:06 PM
[Q] YAML Error: stack level too deep E.-R. Bruecklmeier Ruby 4 07-06-2004 08:19 PM
yaml, level too deep, stack error Jean-Hugues ROBERT Ruby 1 04-27-2004 02:58 PM
stack level too deep on ia64 Eric Schwartz Ruby 3 11-11-2003 06:00 PM



Advertisments