lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 24 November 2015 at 21:10, Coda Highland <chighland@gmail.com> wrote:

> I don't think longjmp is a problem, in and of itself. Microsoft used
> setjmp/longjmp to implement C++ exception handling and was able to
> clean up after itself. They switched to a better implementation later,
> yes, but it's still possible. The important bit, I think, is that
> setjmp/longjmp isn't part of the exposed Lua API, but instead the Lua
> internals are able to set up whatever information they need before the
> longjmp call and between the return to setjmp and the invocation of
> the panic handler or the resumption of the pcall.
>

Agreed but I once did a home grown exception handling using longjmp
and I think the implementation is not at all pretty. Every time a
'try' clause is entered, an object needs to be put on the stack linked
to the previous such object - then there has to be a setjmp within the
try block. When the code exits the block or an exception is thrown,
the code needs to longjmp to this setmp, execute any destructors or
finally code, and then allow normal return. How will all that
machinary work in lua in the presence of C functions all over the
place?

> Yeah, we'd be out of luck if the host used setjmp/longjmp for its own
> purposes, but I don't think that's any different than now.
>

In Microsoft's current C++ implementation, longjmp is also tied to the
exception unwind mechanism.

Regards