lua-users home
lua-l archive

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

> Agreed - my point was that this discipline is not being followed, i.e.
> there will not be a corresponding lua_unlock() call due to the longjmp
> leading to a lock that will not be released.

When a C function is called from Lua, there is (and there must be) a
"reverse lock":

   in function luaD_precall, file ldo.c:
      n = (*f)(L);  /* do the actual call */

If there is a long jump, this 'lua_lock' is skipped, keeping the lock
balanced. For instance:

   C code -> enter lua_pcall:   lock
   Lua code -> call C function: unlock
   C code: enter lua_settabel:   lock
     lua_settable throws an error, jumping back to lua_pcall
   lua_pcall returns: unlock

But it is easier to think differently. The main point is: you enter Lua,
it locks. You leave lua, it unlocks. A long jump is not leaving Lua, so
it does not have to unlock.

-- Roberto