At 11.58 -0600 0-08-30, Alastair Reid wrote:
>> >Prelude> take 1 (reverse [0..])
>> >zsh: 17627 segmentation fault hugs
>
>Hans Aberg:
>> But I do not think this is a bug; if I put it into Mac Hugs, I get after a
>> while:
>> INTERNAL ERROR: Application parameter stack overflow.
>
>I disagree.
>If I run it on GHC, I get a proper stack overflow message.
>If I run it on Mac-Hugs, I get a proper stack overflow message.
>I'll bet that if I ran it on nhc or hbc, I'd get a proper stack
>overflow message.
>
>So I'd classify this as a bug.
The reason that one gets a proper stack overflow message on the Mac-Hugs
version, is that I implemented this feature (and I took it from MacGofer, I
think); it does not come with the Hugs kernel. Without it, Hugs would bomb,
but it would still be a "feature", and not a "bug". :-)
But on a UNIX system, one can simply skip it, and let the system pick it
down when it overflows.
So it need to not be a bug just because Hugs terminates, even though the
best thing would be if the program terminates within Hugs.
-- But I have forgotten what exactly a "segmentation fault" means; doesn't
it just mean "memory problems"?
> It just happens to be one that is hard
>to fix on Unix without extensive changes to Hugs innards. (Unless
>someone out there happens to have experience in trapping (and, most
>importantly, recovering from) stack overflows in one or more Unixen?)
The MacOS solution is to spray the code with stack checks at points where
recursive calls may happen, and if it gets low, the program Hugs is running
is picked down. Though one must spray the code with such checks, the
changes to the sources are not extensive. One must know of a system
dependent way to check for stack overflows, though.
On UNIX it would be better if it sent Hugs a signal when stack memory start
running out; does anybody out there know of such a UNIX command? (I figure
that GHC implements its own stack, and can therefore check it from time to
time.)
I am lookin into a book about the Mach kernel ("Programming Under Mach" by
Boykin, Kirsen, Langerman & LoVerso), and it says (p 100) UNIX systems have
a system call sbrk() which adjusts the demarkation line between the stack
and heap. If there is a way to check when the stack is getting low, it
would be relatively simple to use this to implement the Mac-Hugs stack
adjustments and stack check into the Hugs kernel, so it works with UNIX
systems as well.
But most UNIX's nowadays run a Mach kernel or an equivalent (or at least
BSD UNIX, SUN and Linux). Under Mach, one can control it via virtual memory
techniques -- if you want the details, look in that book.
Hans Aberg