[comp.lang.forth] setjmp/longjmp

wmb@MITCH.ENG.SUN.COM (07/04/90)

You can implement setjmp/longjmp semantics in terms of CATCH/THROW.
You just have ensure that every CATCH compares the return value against
the set of error codes that it is expecting.  This is no more trouble
(in fact it is less troble) than what you have to do to implement
CATCH/THROW in terms of setjmp/longjmp (with is to maintain a separate
stack of jmp_bufs, and to add code to pop that stack when the dynamic
scope of a particular setjmp has expired).

Without that extra code, and the attendant programming discipline to
use it properly, setjmp suffers from the "dangling pointer problem".
If a routine which has called setjmp exits without cleaning up after
itself (i.e. popping this additional jmp_buf stack), a longjmp can
"jump to outer space".

Mitch

peter@ficc.ferranti.com (Peter da Silva) (07/05/90)

In article <9007040422.AA28752@ucbvax.Berkeley.EDU> wmb%MITCH.ENG.SUN.COM@SCFVM.GSFC.NASA.GOV writes:
> than what you have to do to implement
> CATCH/THROW in terms of setjmp/longjmp (with is to maintain a separate
> stack of jmp_bufs, and to add code to pop that stack when the dynamic
> scope of a particular setjmp has expired).

Nonsense. You can push the jmp_buf on the return stack.

> If a routine which has called setjmp exits without cleaning up after
> itself (i.e. popping this additional jmp_buf stack), a longjmp can
> "jump to outer space".

Which solves this problem quite nicely.
-- 
Peter da Silva.   `-_-'
+1 713 274 5180.
<peter@ficc.ferranti.com>