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

  • From: Dan Eloff <dan.eloff@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Mon, 27 Aug 2012 18:57:07 -0500

That makes perfect sense, of course you can't call lua_* functions
from ffi called functions. Thanks Mike for taking the time to clear
things up for me.

Cheers,
Dan

On Mon, Aug 27, 2012 at 6:41 PM, Mike Pall <mike-1208@xxxxxxxxxx> wrote:
> 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: