commit a051b3323ef6d12677e78ec0a47d1731bd424d38
parent c4e01c568aa498fbf141c13589c3cefdd7d9457e
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Wed, 16 Dec 2015 14:39:41 -0200
comments (about hooks vs signals)
Diffstat:
2 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/ldebug.c b/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
** 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) {
if (func == NULL || mask == 0) { /* turn off hooks? */
diff --git a/ldo.c b/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
** 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) {
lua_Hook hook = L->hook;
- if (hook && L->allowhook) {
+ if (hook && L->allowhook) { /* make sure there is a hook */
CallInfo *ci = L->ci;
ptrdiff_t top = savestack(L, L->top);
ptrdiff_t ci_top = savestack(L, ci->top);