diff --git a/ldblib.c b/ldblib.c index eb429acc..c2c9dafc 100644 --- a/ldblib.c +++ b/ldblib.c @@ -1,5 +1,5 @@ /* -** $Id: ldblib.c,v 1.65 2002/08/05 17:36:24 roberto Exp roberto $ +** $Id: ldblib.c,v 1.66 2002/08/06 18:01:50 roberto Exp roberto $ ** Interface from Lua to its debug API ** See Copyright Notice in lua.h */ @@ -126,8 +126,8 @@ static void hookf (lua_State *L, lua_Debug *ar) { } -static int makemask (const char *smask, int count) { - int mask = 0; +static unsigned long makemask (const char *smask, int count) { + unsigned long mask = 0; if (strchr(smask, 'c')) mask |= LUA_MASKCALL; if (strchr(smask, 'r')) mask |= LUA_MASKRET; if (strchr(smask, 'l')) mask |= LUA_MASKLINE; @@ -135,7 +135,7 @@ static int makemask (const char *smask, int count) { } -static char *unmakemask (int mask, char *smask) { +static char *unmakemask (unsigned long mask, char *smask) { int i = 0; if (mask & LUA_MASKCALL) smask[i++] = 'c'; if (mask & LUA_MASKRET) smask[i++] = 'r'; @@ -152,8 +152,9 @@ static int sethook (lua_State *L) { } else { const char *smask = luaL_check_string(L, 2); - int count = luaL_opt_int(L, 3, 0); + lua_Number count = luaL_opt_number(L, 3, 0); luaL_check_type(L, 1, LUA_TFUNCTION); + luaL_arg_check(L, count <= LUA_MAXCOUNT, 2, "count too large (>= 2^24)"); lua_sethook(L, hookf, makemask(smask, count)); } lua_pushlightuserdata(L, (void *)&KEY_HOOK); @@ -165,7 +166,7 @@ static int sethook (lua_State *L) { static int gethook (lua_State *L) { char buff[5]; - int mask = lua_gethookmask(L); + unsigned long mask = lua_gethookmask(L); lua_pushlightuserdata(L, (void *)&KEY_HOOK); lua_rawget(L, LUA_REGISTRYINDEX); /* get hook */ lua_pushstring(L, unmakemask(mask, buff)); diff --git a/ldebug.c b/ldebug.c index 40141157..d4d0eb00 100644 --- a/ldebug.c +++ b/ldebug.c @@ -1,5 +1,5 @@ /* -** $Id: ldebug.c,v 1.130 2002/08/07 19:22:39 roberto Exp roberto $ +** $Id: ldebug.c,v 1.131 2002/08/08 20:08:41 roberto Exp roberto $ ** Debug Interface ** See Copyright Notice in lua.h */ @@ -33,11 +33,8 @@ static const char *getfuncname (CallInfo *ci, const char **name); static int currentpc (CallInfo *ci) { if (!isLua(ci)) return -1; /* function is not a Lua function? */ - if (!(ci->state & CI_SAVEDPC)) { /* savedpc outdated? */ - lua_assert(ci->state & CI_HASFRAME); - ci->u.l.savedpc = *ci->u.l.pc; - ci->state |= CI_SAVEDPC; - } + if (ci->state & CI_HASFRAME) /* function has a frame? */ + ci->u.l.savedpc = *ci->u.l.pc; /* use `pc' from there */ /* function's pc is saved */ return pcRel(ci->u.l.savedpc, ci_func(ci)->l.p); } @@ -52,7 +49,7 @@ static int currentline (CallInfo *ci) { } -LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask) { +LUA_API int lua_sethook (lua_State *L, lua_Hook func, unsigned long mask) { int allow; CallInfo *ci; lua_lock(L); @@ -75,7 +72,7 @@ LUA_API lua_Hook lua_gethook (lua_State *L) { } -LUA_API int lua_gethookmask (lua_State *L) { +LUA_API unsigned long lua_gethookmask (lua_State *L) { return L->hookmask; } diff --git a/ldebug.h b/ldebug.h index fe9eb48a..19be8fee 100644 --- a/ldebug.h +++ b/ldebug.h @@ -1,5 +1,5 @@ /* -** $Id: ldebug.h,v 1.28 2002/08/06 18:01:50 roberto Exp roberto $ +** $Id: ldebug.h,v 1.29 2002/08/08 20:08:41 roberto Exp roberto $ ** Auxiliary functions from Debug Interface module ** See Copyright Notice in lua.h */ @@ -15,8 +15,7 @@ #define getline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : 0) -#define resethookcount(L) \ - (L->hookcount = lua_getmaskcount(L->hookmask), L->hookcount *= L->hookcount) +#define resethookcount(L) (L->hookcount = lua_getmaskcount(L->hookmask)) #define setallowhook(L,cond) ((L->hookmask) = ((L->hookmask) & ~1) | (cond)) #define allowhook(L) ((L->hookmask) & 1) diff --git a/lstate.h b/lstate.h index c5001f7b..372f2b37 100644 --- a/lstate.h +++ b/lstate.h @@ -1,5 +1,5 @@ /* -** $Id: lstate.h,v 1.92 2002/08/06 18:01:50 roberto Exp roberto $ +** $Id: lstate.h,v 1.93 2002/08/07 19:22:39 roberto Exp roberto $ ** Global State ** See Copyright Notice in lua.h */ @@ -151,7 +151,7 @@ struct lua_State { CallInfo *end_ci; /* points after end of ci array*/ CallInfo *base_ci; /* array of CallInfo's */ int size_ci; /* size of array `base_ci' */ - int hookmask; + unsigned long hookmask; ls_count hookcount; lua_Hook hook; UpVal *openupval; /* list of open upvalues in this stack */ diff --git a/lua.c b/lua.c index d662e485..643e8e79 100644 --- a/lua.c +++ b/lua.c @@ -1,5 +1,5 @@ /* -** $Id: lua.c,v 1.100 2002/08/07 20:54:17 roberto Exp roberto $ +** $Id: lua.c,v 1.101 2002/08/08 20:08:41 roberto Exp roberto $ ** Lua stand-alone interpreter ** See Copyright Notice in lua.h */ @@ -45,7 +45,7 @@ static const char *progname; static lua_Hook old_hook = NULL; -static int old_mask = 0; +static unsigned long old_mask = 0; static void lstop (lua_State *l, lua_Debug *ar) { diff --git a/lua.h b/lua.h index 2eef5439..aa7fd893 100644 --- a/lua.h +++ b/lua.h @@ -1,5 +1,5 @@ /* -** $Id: lua.h,v 1.152 2002/08/06 18:01:50 roberto Exp roberto $ +** $Id: lua.h,v 1.153 2002/08/06 18:54:18 roberto Exp roberto $ ** Lua - An Extensible Extension Language ** Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil ** http://www.lua.org mailto:info@lua.org @@ -316,8 +316,10 @@ typedef enum lua_Hookevent { #define LUA_MASKCALL (2 << LUA_HOOKCALL) #define LUA_MASKRET (2 << LUA_HOOKRET) #define LUA_MASKLINE (2 << LUA_HOOKLINE) -#define LUA_MASKCOUNT(count) ((count) << (LUA_HOOKCOUNT+1)) -#define lua_getmaskcount(mask) ((mask) >> (LUA_HOOKCOUNT+1)) +#define LUA_MASKCOUNT(count) ((unsigned long)(count) << 8) +#define lua_getmaskcount(mask) ((mask) >> 8) + +#define LUA_MAXCOUNT ((1<<24) - 1) typedef struct lua_Debug lua_Debug; /* activation record */ @@ -329,9 +331,9 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar); LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n); LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n); -LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask); +LUA_API int lua_sethook (lua_State *L, lua_Hook func, unsigned long mask); LUA_API lua_Hook lua_gethook (lua_State *L); -LUA_API int lua_gethookmask (lua_State *L); +LUA_API unsigned long lua_gethookmask (lua_State *L); #define LUA_IDSIZE 60 diff --git a/lvm.c b/lvm.c index c61d4a3c..fe30a27f 100644 --- a/lvm.c +++ b/lvm.c @@ -1,5 +1,5 @@ /* -** $Id: lvm.c,v 1.250 2002/08/07 14:24:24 roberto Exp roberto $ +** $Id: lvm.c,v 1.251 2002/08/07 19:22:39 roberto Exp roberto $ ** Lua virtual machine ** See Copyright Notice in lua.h */ @@ -70,8 +70,8 @@ int luaV_tostring (lua_State *L, TObject *obj) { static void traceexec (lua_State *L) { - int mask = L->hookmask; - if (mask > LUA_MASKLINE) { /* instruction hook set? */ + unsigned long mask = L->hookmask; + if (mask > LUA_MASKLINE) { /* instruction-hook set? */ if (L->hookcount == 0) { luaD_callhook(L, LUA_HOOKCOUNT, -1); resethookcount(L); @@ -92,7 +92,6 @@ static void traceexec (lua_State *L) { ci = L->ci; /* previous call may reallocate `ci' */ } ci->u.l.savedpc = *ci->u.l.pc; - ci->state |= CI_SAVEDPC; /* `savedpc' is updated */ } }