Re: -fno-exceptions, ffi, lua_error, and C++ exceptions

  • From: Mike Pall <mike-1208@xxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Tue, 28 Aug 2012 01:41:15 +0200

Dan Eloff wrote:
> Or do I need to do that? If lua_error is really raising a c++
> exception then I don't want to catch that. I would guess it's safe for
> the ffi invoked functions to raise c++ exceptions on x64 posix.

Well, no ... it's generally NOT safe to raise an exception from a
C++ function called via the FFI. This *will* crash on x64, if the
code path that includes the FFI call gets JIT-compiled. There's a
frame on the stack that has no corresponding unwind info, because
there's no POSIX/Linux/GLIBC or whatever API to add unwind info
for runtime-generated machine code. :-/

But ... just to clarify: you cannot run any lua_*() function from
a C++ function called via the FFI, anyway. Nor would you need to:
pass and return C types instead. So you cannot possibly get into
the situation that a lua_error() is thrown across your C++ code
which was invoked by the FFI.

--Mike

Other related posts: