Check that the Lua stack is empty in the main loop

The Lua stack is a finite resource and everything that pushes something there
should also clean up. This is not a problem for functions that are called by
Lua, because their "stack frame" is freed when they return. However, in global
context, Lua does not and cannot automatically clean up for us. Thus, it makes
sense to print a warning in this case.

(Additionally, this cleans up the stack if something is left)

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2016-02-17 18:40:01 +01:00
parent a6dd6b4a20
commit 68691ff818

View file

@ -352,10 +352,18 @@ a_glib_poll(GPollFD *ufds, guint nfsd, gint timeout)
guint res; guint res;
struct timeval now, length_time; struct timeval now, length_time;
float length; float length;
lua_State *L = globalconf_get_lua_State();
/* Do all deferred work now */ /* Do all deferred work now */
awesome_refresh(); awesome_refresh();
/* Check if the Lua stack is the way it should be */
if (lua_gettop(L) != 0) {
warn("Something was left on the Lua stack, this is a bug!");
luaA_dumpstack(L);
lua_settop(L, 0);
}
/* Check how long this main loop iteration took */ /* Check how long this main loop iteration took */
gettimeofday(&now, NULL); gettimeofday(&now, NULL);
timersub(&now, &last_wakeup, &length_time); timersub(&now, &last_wakeup, &length_time);