Discussion:
C++ destructors and lua_error()
Nick Hutchinson
2014-09-22 15:41:27 UTC
Permalink
Hi,

I'm working on a x64 Linux project and we're stuck using a relatively old
version of GCC -- 4.1.

I'd wonder if someone could clarify to what extent LuaJIT integrates with C++
destructors using this version of GCC. I note the C++ Exception
Interoperability section at <http://luajit.org/extensions.html> states that
only GCC 4.3+ supports throwing Lua errors across C++ frames and having the
stack unwound correctly and destructors called.

However I've tried calling from Lua into C (via the classic API). The C
function constructs a few C++ objects with destructors, and exits via a call to
lua_error(). To my surprise, the destructors were indeed called.

Is this a happy accident, or does LuaJIT have better support for GCC < 4.3 than
that page suggests?

Cheers,
Nick
Mike Pall
2014-09-24 09:55:54 UTC
Permalink
Post by Nick Hutchinson
Is this a happy accident, or does LuaJIT have better support for GCC < 4.3 than
that page suggests?
It's untested for any earlier GCC release. But exception unwinding
on x64 likely works for 4.1, too (as you found out).

The usual caveats about C++ exceptions apply: this won't work with
the FFI, so you'll need to bind the C++ functions via the classic
Lua/C API, which is slow. If you have many calls into C/C++ and
need performance, consider not using exceptions for a new project.

--Mike

Loading...