Browse Source

comments (about hooks vs signals)

Roberto Ierusalimschy 9 years ago
parent
commit
a051b3323e
2 changed files with 15 additions and 4 deletions
  1. 8 2
      ldebug.c
  2. 7 2
      ldo.c

+ 8 - 2
ldebug.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: ldebug.c,v 2.116 2015/10/22 14:40:47 roberto Exp roberto $
+** $Id: ldebug.c,v 2.117 2015/11/02 18:48:07 roberto Exp roberto $
 ** Debug Interface
 ** Debug Interface
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -69,7 +69,13 @@ static void swapextra (lua_State *L) {
 
 
 
 
 /*
 /*
-** this function can be called asynchronous (e.g. during a signal)
+** This function can be called asynchronous (e.g. during a signal).
+** Fields 'oldpc', 'basehookcount', and 'hookcount' (set by
+** 'resethookcount') are for debug only, and it is no problem if they
+** get arbitrary values (causes at most one wrong hook call). 'hookmask'
+** is an atomic value. We assume that pointers are atomic too (e.g., gcc
+** ensures that for all platforms where it runs). Moreover, 'hook' is
+** always checked before being called (see 'luaD_hook').
 */
 */
 LUA_API void lua_sethook (lua_State *L, lua_Hook func, int mask, int count) {
 LUA_API void lua_sethook (lua_State *L, lua_Hook func, int mask, int count) {
   if (func == NULL || mask == 0) {  /* turn off hooks? */
   if (func == NULL || mask == 0) {  /* turn off hooks? */

+ 7 - 2
ldo.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: ldo.c,v 2.149 2015/11/13 13:24:26 roberto Exp roberto $
+** $Id: ldo.c,v 2.150 2015/11/19 19:16:22 roberto Exp roberto $
 ** Stack and Call structure of Lua
 ** Stack and Call structure of Lua
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -242,9 +242,14 @@ void luaD_inctop (lua_State *L) {
 /* }================================================================== */
 /* }================================================================== */
 
 
 
 
+/*
+** Call a hook for the given event. Make sure there is a hook to be
+** called. (Both 'L->hook' and 'L->hookmask', which triggers this
+** function, can be changed asynchronously by signals.)
+*/
 void luaD_hook (lua_State *L, int event, int line) {
 void luaD_hook (lua_State *L, int event, int line) {
   lua_Hook hook = L->hook;
   lua_Hook hook = L->hook;
-  if (hook && L->allowhook) {
+  if (hook && L->allowhook) {  /* make sure there is a hook */
     CallInfo *ci = L->ci;
     CallInfo *ci = L->ci;
     ptrdiff_t top = savestack(L, L->top);
     ptrdiff_t top = savestack(L, L->top);
     ptrdiff_t ci_top = savestack(L, ci->top);
     ptrdiff_t ci_top = savestack(L, ci->top);