lua-users home
lua-l archive

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


On Thu, Apr 15, 2010 at 09:20:23PM +0200, Mike Pall wrote:
> Daniel Wallin wrote:
> > On Thu, Apr 15, 2010 at 02:17:23PM +0200, Mike Pall wrote:
> > > It could be that luabind tries to throw exceptions across Lua
> > > frames or tries to throw Lua errors across C++ frames protected
> > > with try/catch (works on Windows/x64, crashes on Windows/x86).
> > 
> > It doesn't. In this case static_class_gettable() calls lua_error()
> > directly, with no non-trivial objects alive on the stack, so it should
> > be longjmp-safe. lua_pcall() returns properly, and then the crash
> > happens when luabind throws an exception.
> 
> [...]
> As far as I can see from the comments in the code, the first error
> (for the invalid member) works, only the second error (for the
> invalid static member) ought to cause a crash on Windows/x86 (do
> you see this, too?).

Yep.

> That's remarkable, because the only difference is from where the
> original error is thrown. Either from lj_meta_call() (for the call
> of a nil value) or in static_class_gettable() -- but both end up
> in the exact same code path. And your analysis indicates that it
> crashes later on the rethrow. Maybe this is order-sensitive? Maybe
> the free list of the memory allocator got corrupted?

Here's a much simplified test:

  #include <string>
  #include "lua.hpp"

  int throw_error(lua_State* L)
  {
      lua_pushstring(L, "foo");
      lua_error(L);

      std::string dummy;
      dummy += "foo";

      return 0;
  }

  int main()
  {
      lua_State* L = lua_open();
      luaL_openlibs(L);

      lua_pushcclosure(L, &throw_error, 0);
      lua_setglobal(L, "throw_error");
      luaL_dostring(L, "throw_error()");

      try
      {
          throw 0;
      }
      catch (...)
      {}

      lua_close(L);
  }

The key is the std::string object in throw_error(). Without that
everything works fine, with it present the throw crashes. Any ideas?

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