From 68691ff81846e4a9cb4a77892b0eb211549e69db Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Wed, 17 Feb 2016 18:40:01 +0100 Subject: [PATCH] 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 --- awesome.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/awesome.c b/awesome.c index 3cc22c10..8ee56341 100644 --- a/awesome.c +++ b/awesome.c @@ -352,10 +352,18 @@ a_glib_poll(GPollFD *ufds, guint nfsd, gint timeout) guint res; struct timeval now, length_time; float length; + lua_State *L = globalconf_get_lua_State(); /* Do all deferred work now */ 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 */ gettimeofday(&now, NULL); timersub(&now, &last_wakeup, &length_time);