Looks like it is undefined, after all. In any event, there's lots of
code out there that depends on this to jump between contexts. I suppose
this makes it undefined by the standard, but defined on particular
implementations.
It seems quite difficult to implement this in JS.
On 11/06/14 11:14, Chad Austin wrote:
Wikipedia seems to agree:
Similarly,C99 <http://en.wikipedia.org/wiki/C99>does not require
that|longjmp|preserve the current stack frame. This means that jumping
into a function which was exited via a call to|longjmp|is undefined.^[6]
<http://en.wikipedia.org/wiki/Setjmp.h#cite_note-ISO.2FIEC_9899:1999-6>
However, most implementations of|longjmp|leave the stack frame intact,
allowing|setjmp|and|longjmp|to be used to jump back-and-forth between
two or more functions—a feature exploited formultitasking
<http://en.wikipedia.org/wiki/Setjmp.h#Cooperative_multitasking>.
http://en.wikipedia.org/wiki/Setjmp.h
On Wed, Jun 11, 2014 at 1:03 AM, Chad Austin
<[email protected]
<mailto:[email protected]>> wrote:
I think Alon is correct here: longjmp is only legal up the stack.
At least, my reading of the spec agrees with Alon's argument:
The longjmp function restores the environment saved by the most
recent invocation of
the setjmp macro in the same invocation of the program with the
corresponding
jmp_buf argument. If there has been no such invocation, or if the
function containing
the invocation of the setjmp macro has terminated execution217) in
the interim, or if the
invocation of the setjmp macro was within the scope of an identifier
with variably
modified type and execution has left that scope in the interim, the
behavior is undefined.
217) For example, by executing a return statement or because another
longjmp call has caused a
transfer to a setjmp invocation in a function earlier in the set of
nested calls.
On Tue, Jun 10, 2014 at 8:23 PM, Nikos Chantziaras
<[email protected]
<mailto:[email protected]>> wrote:
It's not undefined behavior. You can save stack contexts at any
point and jump to them. Coroutines and threads can be
implemented with this.
Unwinding the stack due to an exception, which only goes up the
stack, is only one use case of longjmp.
On 11/06/14 02:06, Alon Zakai wrote:
You can use longjmp only to unwind the stack. I believe that
to jump the
in the other direction is undefined behavior, and we don't
support it -
a very different model would be needed for that.
- Alon
On Tue, Jun 10, 2014 at 8:07 AM, Stanislav Tsukrov
<[email protected]
<mailto:[email protected]>
<mailto:[email protected]
<mailto:[email protected]>__>>
wrote:
Is there a way to jump with longjmp to a setjmp-point
outside of the
current stack?
As far I can see longjmp is implemented with
exceptions, so the
jump-point must be upwards on the current stack.
Any way to jump "down"?
--
You received this message because you are subscribed to the Google Groups
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.