Subject: Re: bug#24005: Segfault after playing around a bit

From: Andy Wingo <[email-masked]>
Date: Sat, 23 Jul 2016 12:45:05 +0200

Hi :)

On Sat 16 Jul 2016 13:46, Giedrius Statkevičius <[email-masked]> writes:

> scheme@(guile-user)> (define (sqrt-iter guess x) (new-if (good-enough? guess x)
> guess (sqrt-iter (improve guess x) x)))
> scheme@(guile-user)> (sqrt 2)
> <unnamed port>:4:42: In procedure good-enough?:
> <unnamed port>:4:42: Throw to key `vm-error' with args `(vm-run "VM: Stack

What's happening here is that you have a function that uses too much
stack.  In Guile 2.0 there is a fixed amount of stack.  If you exceed
that amount, Guile enters a nested REPL at the error:

> Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
> scheme@(guile-user) [1]> (define (sqrt-iter guess x) (new-if (good-enough? guess
> x) guess x))

So you can get a backtrace to see what's on your stack.  This repl is in
the context of the stack overflow -- so all the frames are still on the
stack.  There's just a little bit of stack reserved so that you can poke
around and see what's going on.  You then cause the stack overflow
again, when it already overflowed, and at some point Guile detects this
and because it can't handle it, it aborts (not segfaults):

> zsh: abort (core dumped)  guile

Ah well.  In Guile 2.0 we can't fix this very nicely.  There's no
corruption here, just a limit that we can't handle.  Fortunately we
fixed it in 2.2:

  https://wingolog.org/archives/2014/03/17/stack-overflow

My machine is down for maintenance atm, should be back shortly, in the
meantime there's

  https://web.archive.org/web/*/https://wingolog.org/archives/2014/03/17/stack-overflow

Anyway.  Thanks for the report, it's a limitation in 2.0 that's fixed in
2.2.

Cheers,

Andy