lua-users home
lua-l archive

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


On Mon, Apr 19, 2010 at 12:35:16PM +0200, Mike Pall wrote:
> Daniel Wallin wrote:
> > > For luabind this means: you may want to remove all problematic
> > > uses of RAII. Compile in debug mode and check the disassembly for
> > > all references to fs:[0] that are not caused by explicit try/catch
> > > constructs.
> > 
> > That's certainly possible to do, lua_error() is only called in a handful
> > of places.
> 
> It's not just lua_error(). A lot of lua_* API functions can
> implicitly throw an error (see the manual).

Yes, I know, but I don't care about most of them.

> > This *does* work in plain Lua though, where lua_error() is
> > explicitly specified to perform a longjmp().
> 
> Since we're talking about Windows/x86, Microsoft's official
> statement wrt. mixing C++ and longjmp is here:
> 
>   "Do not use setjmp and longjmp in C++ programs."
>   http://msdn.microsoft.com/en-us/library/yz2ez4as(vs.71).aspx
> 
> MSVCRT's longjmp seems to do some clean up, but that's an
> implementation detail. All bets are off if you compiled Lua with
> MinGW.

That's just advice, albeit good advice. It isn't an implementation
detail that it doesn't randomly blow up though, it's required behaviour.

> [And regarding LuaJIT: I can't do anything about it. I can't use
> longjmp directly and the SEH patent prevents me from adding
> interoperability with SEH exception handling.]

That's too bad. Is this noted in the manual somewhere?

> > The use of longjmp() as in my example is well defined:
> > 
> >   18.7.4:
> > 
> >   If any automatic objects would be destroyed by a thrown exception
> >   transferring control to another (destination) point in the program, then
> >   a call to longjmp(jbuf, val) at the throw point that transfers control
> >   to the same (destination) point has undefined behavior.
> 
> Umm? It certainly explicitly says what's undefined. But nowhere
> does it claim what _is_ defined.

It states which conditions cause undefined behaviour, my example doesn't
and is thus well defined.

>  E.g. MSVC effectively hoists the implicit try/catch around RAII to
>  the top of the function. Both in theory and practice, longjmp() and
>  C++ exceptions do NOT mix well.

I know that, but the object in question isn't constructed at the
longjmp() point and would not be destroyed by a thrown exception.

-- 
Daniel Wallin
BoostPro Computing
http://www.boostpro.com