lua-users home
lua-l archive

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


In the course of adding breakpoint support to ldb, I ran into this problem. Sorry I didn't notice it before 5.1.2 went out.

In luaD_poscall (ldo.c:541), callrethooks is called if return hooks
are enabled in the hookmask. callrethooks then issues a call for
each deleted tailcall frame without checking to see whether the
hookmask is still enabled. Consequently, if the return hook
handler disables return hooks, it will unexpectedly get them
anyway. (The hook handler I wrote aggressively turns itself
off when possible in order to try to keep handling time to a
minimum.)

I believe that callrethooks should look like this:

static StkId callrethooks (lua_State *L, StkId firstResult) {
ptrdiff_t fr = savestack(L, firstResult); /* next call may change stack */
  luaD_callhook(L, LUA_HOOKRET, -1);
  if (f_isLua(L->ci)) {  /* Lua function? */
    while ((L->hookmask & LUA_MASKRET)  /* condition added */
           && L->ci->tailcalls--)
      /* call hook for eventual tail calls */
      luaD_callhook(L, LUA_HOOKTAILRET, -1);
  }
  return restorestack(L, fr);
}

Also, call and return hooks would be a lot more useful if they
carried an indication of the number of actual arguments and
return values (resp.). I'll see if I can find an elegant way of
doing this.