From bcc3de469e6ae09489e1d6fb8bad4cdc0e1192cd Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Tue, 13 Jun 2017 01:59:30 +0200 Subject: [PATCH] Fix menubar under Lua 5.1 (#1838) LGI's async support was trying to yield inside a protected call. Lua 5.1 cannot do that. Work around this by reverting to the behaviour before commit 50cfa6c: Only call the callback in a protected context. Fixes: https://github.com/awesomeWM/awesome/issues/1837 Signed-off-by: Uli Schlachter --- lib/menubar/utils.lua | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/menubar/utils.lua b/lib/menubar/utils.lua index d0abca75..6d5ec423 100644 --- a/lib/menubar/utils.lua +++ b/lib/menubar/utils.lua @@ -43,6 +43,28 @@ utils.wm_name = "awesome" -- Private section +local do_protected_call, call_callback +do + -- Lua 5.1 cannot yield across a protected call. Instead of hardcoding a + -- check, we check for this problem: The following coroutine yields true on + -- success (so resume() returns true, true). On failure, pcall returns + -- false and a message, so resume() returns true, false, message. + local _, has_yieldable_pcall = coroutine.resume(coroutine.create(function() + return pcall(coroutine.yield, true) + end)) + if has_yieldable_pcall then + do_protected_call = protected_call.call + call_callback = function(callback, ...) + return callback(...) + end + else + do_protected_call = function(f, ...) + return f(...) + end + call_callback = protected_call.call + end +end + local all_icon_sizes = { '128x128' , '96x96', @@ -298,10 +320,10 @@ function utils.parse_dir(dir_path, callback) enum:async_close() end - gio.Async.start(protected_call.call)(function() + gio.Async.start(do_protected_call)(function() local result = {} parser(gio.File.new_for_path(dir_path), result) - callback(result) + call_callback(callback, result) end) end