/elua/elua-svn-r844-patches/lua-remove-hooks.patch
Patch | 392 lines | 347 code | 45 blank | 0 comment | 0 complexity | 4f36583faf829afe9c9b98aeb3200da2 MD5 | raw file
- Make the inclusion of the Lua hooks mechanism, only useful when Lua is
- embedded in a larger C program, conditional on the definition of LUA_HOOKS.
- Saving in code: 512 bytes
- Note that the hook mechanism is needed by the new eLua interrupt mechanism.
- Index: elua-svn/src/lua/ldebug.c
- ===================================================================
- --- elua-svn.orig/src/lua/ldebug.c 2010-12-02 11:28:05.633727001 +0100
- +++ elua-svn/src/lua/ldebug.c 2010-12-02 11:30:17.733727000 +0100
- @@ -50,6 +50,7 @@
- }
-
-
- +#ifdef LUA_HOOKS
- /*
- ** this function can be called asynchronous (e.g. during a signal)
- */
- @@ -79,6 +80,7 @@
- LUA_API int lua_gethookcount (lua_State *L) {
- return L->basehookcount;
- }
- +#endif
-
-
- LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) {
- Index: elua-svn/src/lua/ldebug.h
- ===================================================================
- --- elua-svn.orig/src/lua/ldebug.h 2010-12-02 11:28:05.777727001 +0100
- +++ elua-svn/src/lua/ldebug.h 2010-12-02 11:30:17.733727000 +0100
- @@ -15,7 +15,9 @@
-
- #define getline(f,pc) (((f)->lineinfo) ? (f)->lineinfo[pc] : 0)
-
- +#ifdef LUA_HOOKS
- #define resethookcount(L) (L->hookcount = L->basehookcount)
- +#endif
-
-
- LUAI_FUNC void luaG_typeerror (lua_State *L, const TValue *o,
- Index: elua-svn/src/lua/lua.h
- ===================================================================
- --- elua-svn.orig/src/lua/lua.h 2010-12-02 11:28:05.713727001 +0100
- +++ elua-svn/src/lua/lua.h 2010-12-02 11:30:17.733727000 +0100
- @@ -335,8 +335,10 @@
- typedef struct lua_Debug lua_Debug; /* activation record */
-
-
- +#ifdef LUA_HOOKS
- /* Functions to be called by the debuger in specific events */
- typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);
- +#endif
-
-
- LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar);
- @@ -346,10 +348,14 @@
- LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n);
- LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n);
-
- +#ifdef LUA_HOOKS
- LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count);
- LUA_API lua_Hook lua_gethook (lua_State *L);
- LUA_API int lua_gethookmask (lua_State *L);
- LUA_API int lua_gethookcount (lua_State *L);
- +#else
- +// #define lua_sethook(a,b,c,d) do { } while(0)
- +#endif
-
-
- struct lua_Debug {
- Index: elua-svn/src/lua/luaconf.h
- ===================================================================
- --- elua-svn.orig/src/lua/luaconf.h 2010-12-02 11:28:27.269727000 +0100
- +++ elua-svn/src/lua/luaconf.h 2010-12-02 11:31:04.669727000 +0100
- @@ -397,6 +397,14 @@
-
-
- /*
- +@@ LUA_HOOKS enables the debug hook interface
- +** CHANGE it to undefined if you don't want that
- +*/
- +#undef LUA_HOOKS
- +
- +
- +
- +/*
- @@ luai_apicheck is the assert macro used by the Lua-C API.
- ** CHANGE luai_apicheck if you want Lua to perform some checks in the
- ** parameters it gets from API calls. This may slow down the interpreter
- Index: elua-svn/src/lua/ldblib.c
- ===================================================================
- --- elua-svn.orig/src/lua/ldblib.c 2010-12-02 11:28:05.805727001 +0100
- +++ elua-svn/src/lua/ldblib.c 2010-12-02 11:30:17.737727000 +0100
- @@ -204,6 +204,7 @@
- static const char KEY_HOOK = 'h';
-
-
- +#ifdef LUA_HOOKS
- static void hookf (lua_State *L, lua_Debug *ar) {
- static const char *const hooknames[] =
- {"call", "return", "line", "count", "tail return"};
- @@ -220,6 +221,7 @@
- lua_call(L, 2, 0);
- }
- }
- +#endif
-
-
- static int makemask (const char *smask, int count) {
- @@ -242,6 +244,7 @@
- }
-
-
- +#ifdef LUA_HOOKS
- static void gethooktable (lua_State *L) {
- lua_pushlightuserdata(L, (void *)&KEY_HOOK);
- lua_rawget(L, LUA_REGISTRYINDEX);
- @@ -297,6 +300,7 @@
- lua_pushinteger(L, lua_gethookcount(L1));
- return 3;
- }
- +#endif
-
-
- static int db_debug (lua_State *L) {
- @@ -376,14 +380,18 @@
- const LUA_REG_TYPE dblib[] = {
- {LSTRKEY("debug"), LFUNCVAL(db_debug)},
- {LSTRKEY("getfenv"), LFUNCVAL(db_getfenv)},
- +#ifdef LUA_HOOKS
- {LSTRKEY("gethook"), LFUNCVAL(db_gethook)},
- +#endif
- {LSTRKEY("getinfo"), LFUNCVAL(db_getinfo)},
- {LSTRKEY("getlocal"), LFUNCVAL(db_getlocal)},
- {LSTRKEY("getregistry"), LFUNCVAL(db_getregistry)},
- {LSTRKEY("getmetatable"), LFUNCVAL(db_getmetatable)},
- {LSTRKEY("getupvalue"), LFUNCVAL(db_getupvalue)},
- {LSTRKEY("setfenv"), LFUNCVAL(db_setfenv)},
- +#ifdef LUA_HOOKS
- {LSTRKEY("sethook"), LFUNCVAL(db_sethook)},
- +#endif
- {LSTRKEY("setlocal"), LFUNCVAL(db_setlocal)},
- {LSTRKEY("setmetatable"), LFUNCVAL(db_setmetatable)},
- {LSTRKEY("setupvalue"), LFUNCVAL(db_setupvalue)},
- Index: elua-svn/src/lua/ldo.c
- ===================================================================
- --- elua-svn.orig/src/lua/ldo.c 2010-12-02 11:28:15.321727001 +0100
- +++ elua-svn/src/lua/ldo.c 2010-12-02 11:31:04.625727000 +0100
- @@ -86,7 +86,9 @@
- luaF_close(L, L->base); /* close eventual pending closures */
- luaD_seterrorobj(L, status, L->base);
- L->nCcalls = L->baseCcalls;
- +#ifdef LUA_HOOKS
- L->allowhook = 1;
- +#endif
- restore_stack_limit(L);
- L->errfunc = 0;
- L->errorJmp = NULL;
- @@ -182,6 +184,7 @@
- }
-
-
- +#ifdef LUA_HOOKS
- void luaD_callhook (lua_State *L, int event, int line) {
- lua_Hook hook = L->hook;
- if (hook && L->allowhook) {
- @@ -207,6 +210,7 @@
- L->top = restorestack(L, top);
- }
- }
- +#endif
-
-
- static StkId adjust_varargs (lua_State *L, Proto *p, int actual) {
- @@ -310,11 +314,13 @@
- for (st = L->top; st < ci->top; st++)
- setnilvalue(st);
- L->top = ci->top;
- +#ifdef LUA_HOOKS
- if (L->hookmask & LUA_MASKCALL) {
- L->savedpc++; /* hooks assume 'pc' is already incremented */
- luaD_callhook(L, LUA_HOOKCALL, -1);
- L->savedpc--; /* correct 'pc' */
- }
- +#endif
- return PCRLUA;
- }
- else { /* if is a C function, call it */
- @@ -327,8 +333,10 @@
- ci->top = L->top + LUA_MINSTACK;
- lua_assert(ci->top <= L->stack_last);
- ci->nresults = nresults;
- +#ifdef LUA_HOOKS
- if (L->hookmask & LUA_MASKCALL)
- luaD_callhook(L, LUA_HOOKCALL, -1);
- +#endif
- lua_unlock(L);
- if (ttisfunction(func))
- n = (*curr_func(L)->c.f)(L); /* do the actual call */
- @@ -345,6 +353,7 @@
- }
-
-
- +#ifdef LUA_HOOKS
- 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);
- @@ -354,14 +363,17 @@
- }
- return restorestack(L, fr);
- }
- +#endif
-
-
- int luaD_poscall (lua_State *L, StkId firstResult) {
- StkId res;
- int wanted, i;
- CallInfo *ci;
- +#ifdef LUA_HOOKS
- if (L->hookmask & LUA_MASKRET)
- firstResult = callrethooks(L, firstResult);
- +#endif
- ci = L->ci--;
- res = ci->func; /* res == final position of 1st result */
- wanted = ci->nresults;
- @@ -474,7 +486,9 @@
- int status;
- unsigned short oldnCcalls = L->nCcalls;
- ptrdiff_t old_ci = saveci(L, L->ci);
- +#ifdef LUA_HOOKS
- lu_byte old_allowhooks = L->allowhook;
- +#endif
- ptrdiff_t old_errfunc = L->errfunc;
- L->errfunc = ef;
- status = luaD_rawrunprotected(L, func, u);
- @@ -486,7 +500,9 @@
- L->ci = restoreci(L, old_ci);
- L->base = L->ci->base;
- L->savedpc = L->ci->savedpc;
- +#ifdef LUA_HOOKS
- L->allowhook = old_allowhooks;
- +#endif
- restore_stack_limit(L);
- }
- L->errfunc = old_errfunc;
- Index: elua-svn/src/lua/lgc.c
- ===================================================================
- --- elua-svn.orig/src/lua/lgc.c 2010-12-02 11:28:05.585727001 +0100
- +++ elua-svn/src/lua/lgc.c 2010-12-02 11:30:17.741727000 +0100
- @@ -461,15 +461,19 @@
- makewhite(g, o);
- tm = fasttm(L, udata->uv.metatable, TM_GC);
- if (tm != NULL) {
- - lu_byte oldah = L->allowhook;
- lu_mem oldt = g->GCthreshold;
- +#ifdef LUA_HOOKS
- + lu_byte oldah = L->allowhook;
- L->allowhook = 0; /* stop debug hooks during GC tag method */
- +#endif
- g->GCthreshold = 2*g->totalbytes; /* avoid GC steps */
- setobj2s(L, L->top, tm);
- setuvalue(L, L->top+1, udata);
- L->top += 2;
- luaD_call(L, L->top - 2, 0);
- +#ifdef LUA_HOOKS
- L->allowhook = oldah; /* restore hooks */
- +#endif
- g->GCthreshold = oldt; /* restore threshold */
- }
- }
- Index: elua-svn/src/lua/lstate.c
- ===================================================================
- --- elua-svn.orig/src/lua/lstate.c 2010-12-02 11:28:05.757727001 +0100
- +++ elua-svn/src/lua/lstate.c 2010-12-02 11:30:17.741727000 +0100
- @@ -93,11 +93,13 @@
- L->stack = NULL;
- L->stacksize = 0;
- L->errorJmp = NULL;
- +#ifdef LUA_HOOKS
- L->hook = NULL;
- L->hookmask = 0;
- L->basehookcount = 0;
- L->allowhook = 1;
- resethookcount(L);
- +#endif
- L->openupval = NULL;
- L->size_ci = 0;
- L->nCcalls = L->baseCcalls = 0;
- @@ -131,10 +133,12 @@
- preinit_state(L1, G(L));
- stack_init(L1, L); /* init stack */
- setobj2n(L, gt(L1), gt(L)); /* share table of globals */
- +#ifdef LUA_HOOKS
- L1->hookmask = L->hookmask;
- L1->basehookcount = L->basehookcount;
- L1->hook = L->hook;
- resethookcount(L1);
- +#endif
- lua_assert(!isdead(G(L), obj2gco(L1)));
- L->top--; /* remove thread from stack */
- return L1;
- @@ -233,7 +237,9 @@
- LUA_API void lua_close (lua_State *L) {
- #ifndef LUA_CROSS_COMPILER
- int oldstate = platform_cpu_set_global_interrupts( PLATFORM_CPU_DISABLE );
- +#ifdef LUA_HOOKS
- lua_sethook( L, NULL, 0, 0 );
- +#endif
- lua_crtstate = NULL;
- lua_pushnil( L );
- lua_rawseti( L, LUA_REGISTRYINDEX, LUA_INT_HANDLER_KEY );
- Index: elua-svn/src/lua/lstate.h
- ===================================================================
- --- elua-svn.orig/src/lua/lstate.h 2010-12-02 11:28:05.609727001 +0100
- +++ elua-svn/src/lua/lstate.h 2010-12-02 11:30:17.741727000 +0100
- @@ -116,11 +116,13 @@
- int size_ci; /* size of array `base_ci' */
- unsigned short nCcalls; /* number of nested C calls */
- unsigned short baseCcalls; /* nested C calls when resuming coroutine */
- +#ifdef LUA_HOOKS
- lu_byte hookmask;
- lu_byte allowhook;
- int basehookcount;
- int hookcount;
- lua_Hook hook;
- +#endif
- TValue l_gt; /* table of globals */
- TValue env; /* temporary place for environments */
- GCObject *openupval; /* list of open upvalues in this stack */
- Index: elua-svn/src/lua/lvm.c
- ===================================================================
- --- elua-svn.orig/src/lua/lvm.c 2010-12-02 11:28:05.653727001 +0100
- +++ elua-svn/src/lua/lvm.c 2010-12-02 11:30:17.745727000 +0100
- @@ -76,7 +76,7 @@
- }
- }
-
- -
- +#ifdef LUA_HOOKS
- static void traceexec (lua_State *L, const Instruction *pc) {
- lu_byte mask = L->hookmask;
- const Instruction *oldpc = L->savedpc;
- @@ -95,6 +95,7 @@
- luaD_callhook(L, LUA_HOOKLINE, newline);
- }
- }
- +#endif
-
-
- static void callTMres (lua_State *L, StkId res, const TValue *f,
- @@ -435,6 +436,7 @@
- for (;;) {
- const Instruction i = *pc++;
- StkId ra;
- +#ifdef LUA_HOOKS
- if ((L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)) &&
- (--L->hookcount == 0 || L->hookmask & LUA_MASKLINE)) {
- traceexec(L, pc);
- @@ -444,6 +446,7 @@
- }
- base = L->base;
- }
- +#endif
- /* warning!! several calls may realloc the stack and invalidate `ra' */
- ra = RA(i);
- lua_assert(base == L->base && L->base == L->ci->base);
- Index: elua-svn/src/lua/lua.c
- ===================================================================
- --- elua-svn.orig/src/lua/lua.c 2010-12-02 11:28:15.325727001 +0100
- +++ elua-svn/src/lua/lua.c 2010-12-02 11:32:23.141727000 +0100
- @@ -25,17 +25,21 @@
-
-
-
- +#ifdef LUA_HOOKS
- static void lstop (lua_State *L, lua_Debug *ar) {
- (void)ar; /* unused arg. */
- lua_sethook(L, NULL, 0, 0);
- luaL_error(L, "interrupted!");
- }
- +#endif
-
-
- static void laction (int i) {
- signal(i, SIG_DFL); /* if another SIGINT happens before lstop,
- terminate process (default action) */
- +#ifdef LUA_HOOKS
- lua_sethook(globalL, lstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1);
- +#endif
- }
-
-