[Top][All Lists]

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

Re: [Enigma-devel] crashes on linux gcc exception handling

From: Daniel Heck
Subject: Re: [Enigma-devel] crashes on linux gcc exception handling
Date: Sun, 24 Sep 2006 14:43:08 +0200
User-agent: Thunderbird (X11/20060728)


> If such a runtime exception is thrown with C longjump-based Lua frames
> on the execution stack the C++ exception will not unwind to the catch
> statement but crash the app within gcc internal code (f.e. the appended
> diff causes all levels with triggers to throw exceptions on load).
> This behaviour may be within some gcc specs or it may be a bug. But it
> is at least very annoying.

It is annoying, but really not gcc's fault.  What we're doing here is
probably deep inside the realm of "implementation defined behavior"
since we are happily mixing functions with different linkage specification.

Now that I think of it, I think that gcc should at least emit
compile-time warnings.  For example, most of the functions defined in
lua.cc are (implicitly) declared 'extern "C++"' but we can pass pointers
to these functions to lua_pushcfunction, which definitely expects
'extern "C"' functions.

> In general there are two Enigma internal solutions:
> 1. write an own unwind that catches all C++ exceptions before returning
> via Lua and rethrow the exceptions after returnung to C++.

Nobody wants to do this, really.  Even generating a stack trace using
the unwind information is painful.

> 2. switch Lua to C++ for Linux and other OS, too
> As approach 1. means a lot of work and would force a rewrite of all
> tolua based code I would prefer the second solution.
> Is anyone aware of other solutions? Does anyone object solution 2?

I think this would be a reasonable solution for the moment, although I'm
not sure that this is safe from Lua's perspective.  For example, I'm not
sure that this couldn't lead to memory leaks in the Lua interpreter, or
leave the Lua interpreter in some inconstistent state.

It doesn't solve another problem: Lua scripts still don't have a chance
to handle errors raised in the Enigma engine.  A better (long-term)
solution might therefore be to map C++ exceptions to "lua_error" or
luaL_error calls.   I don't think that this is an urgent issue at the
moment, and I'm not sure that tolua would support this, but it's
certainly something to think about.

- Daniel

reply via email to

[Prev in Thread] Current Thread [Next in Thread]