From 6fa2ad4922ce296a26bdd9f54622a491209ec3cd Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Thu, 6 Sep 2018 16:24:24 +0200 Subject: [PATCH 1/1] Lua: remove various logging functions (debug, warn, etc.) The "debug" logging function overwrites the "debug" package which breaks luacov: https://github.com/keplerproject/luacov/issues/55 Change-Id: I9b6025c060733198bfff8ea959444c09d6e08709 Reviewed-on: https://code.wireshark.org/review/29449 Petri-Dish: Peter Wu Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman --- docbook/release-notes.asciidoc | 4 ++- epan/wslua/console.lua | 31 ++++++++----------- epan/wslua/template-init.lua | 8 ----- epan/wslua/wslua.h | 1 - epan/wslua/wslua_util.c | 54 ---------------------------------- test/lua/globals_2.2.txt | 5 ---- 6 files changed, 16 insertions(+), 87 deletions(-) diff --git a/docbook/release-notes.asciidoc b/docbook/release-notes.asciidoc index f8aae43a2d..0fbc11cf92 100644 --- a/docbook/release-notes.asciidoc +++ b/docbook/release-notes.asciidoc @@ -109,7 +109,9 @@ A new extcap has been added: dpauxmon. It allows capturing DisplayPort AUX chann data from linux kernel drivers. -- -//=== Major API Changes +=== Major API Changes +* Lua: the various logging functions (debug, info, message, warn and critical) + have been removed. Use the print function instead for debugging purposes. == Getting Wireshark diff --git a/epan/wslua/console.lua b/epan/wslua/console.lua index 023016e51c..2af50d3587 100644 --- a/epan/wslua/console.lua +++ b/epan/wslua/console.lua @@ -57,34 +57,29 @@ if (gui_enabled()) then local w = TextWindow.new("Console") -- save original logger functions - local orig = { - critical = critical, - warn = warn, - message = message, - info = info, - debug = debug - } + local orig_print = print -- define new logger functions that append text to the window - function critical(x) w:append( date() .. " CRITICAL: " .. tostring(x) .. "\n") end - function warn(x) w:append( date() .. " WARN: " .. tostring(x) .. "\n") end - function message(x) w:append( date() .. " MESSAGE: " .. tostring(x) .. "\n") end - function info(x) w:append( date() .. " INFO: " .. tostring(x) .. "\n") end - function debug(x) w:append( date() .. " DEBUG: " .. tostring(x) .. "\n") end + function print(...) + local arg = {...} + local n = #arg + w:append(date() .. " ") + for i=1, n do + if i > 1 then w:append("\t") end + w:append(tostring(arg[i])) + end + w:append("\n") + end -- when the window gets closed restore the original logger functions local function at_close() - critical = orig.critical - warn = orig.warn - message = orig.message - info = orig.info - debug = orig.debug + print = old_print console_open = false end w:set_atclose(at_close) - info("Console opened") + print("Console opened") end function ref_manual() diff --git a/epan/wslua/template-init.lua b/epan/wslua/template-init.lua index 9be7050fed..a06f62265e 100644 --- a/epan/wslua/template-init.lua +++ b/epan/wslua/template-init.lua @@ -38,13 +38,6 @@ if running_superuser then file = disabled_lib end --- to avoid output to stdout which can cause problems lua's print () --- has been suppresed so that it yields an error. --- have print() call info() instead. -if gui_enabled() then - print = info -end - function typeof(obj) local mt = getmetatable(obj) return mt and mt.__typeof or obj.__typeof or type(obj) @@ -74,7 +67,6 @@ end -- -- since 1.11.3 function package.prepend_path(name) - local debug = require "debug" -- get the function calling this package.prepend_path function local dt = debug.getinfo(2, "f") if not dt then diff --git a/epan/wslua/wslua.h b/epan/wslua/wslua.h index 3c12ce283c..b0373f2497 100644 --- a/epan/wslua/wslua.h +++ b/epan/wslua/wslua.h @@ -53,7 +53,6 @@ #define WSLUA_INIT_ROUTINES "init_routines" #define WSLUA_PREFS_CHANGED "prefs_changed" -#define LOG_DOMAIN_LUA "wslua" typedef void (*wslua_logger_t)(const gchar *, GLogLevelFlags, const gchar *, gpointer); extern wslua_logger_t wslua_logger; diff --git a/epan/wslua/wslua_util.c b/epan/wslua/wslua_util.c index bd706071d7..9d37efd949 100644 --- a/epan/wslua/wslua_util.c +++ b/epan/wslua/wslua_util.c @@ -129,60 +129,6 @@ WSLUA_FUNCTION wslua_report_failure(lua_State* LS) { /* Reports a failure to the return 0; } -static int wslua_log(lua_State* L, GLogLevelFlags log_level) { - GString* str = g_string_new(""); - int n = lua_gettop(L); /* Number of arguments */ - int i; - - lua_getglobal(L, "tostring"); - for (i=1; i<=n; i++) { - const char *s; - lua_pushvalue(L, -1); /* function to be called */ - lua_pushvalue(L, i); /* value to print */ - lua_call(L, 1, 1); - s = lua_tostring(L, -1); /* get result */ - if (s == NULL) - return luaL_error(L, "`tostring' must return a string"); - - if (i>1) g_string_append(str,"\t"); - g_string_append(str,s); - - lua_pop(L, 1); /* pop result */ - } - g_string_append_c(str, '\n'); - - wslua_logger(LOG_DOMAIN_LUA, log_level, str->str, NULL); - g_string_free(str,TRUE); - - return 0; -} - -WSLUA_FUNCTION wslua_critical( lua_State* L ) { /* Will add a log entry with critical severity. */ -/* WSLUA_MOREARGS critical objects to be printed */ - wslua_log(L,G_LOG_LEVEL_CRITICAL); - return 0; -} -WSLUA_FUNCTION wslua_warn( lua_State* L ) { /* Will add a log entry with warn severity. */ -/* WSLUA_MOREARGS warn objects to be printed */ - wslua_log(L,G_LOG_LEVEL_WARNING); - return 0; -} -WSLUA_FUNCTION wslua_message( lua_State* L ) { /* Will add a log entry with message severity. */ -/* WSLUA_MOREARGS message objects to be printed */ - wslua_log(L,G_LOG_LEVEL_MESSAGE); - return 0; -} -WSLUA_FUNCTION wslua_info( lua_State* L ) { /* Will add a log entry with info severity. */ -/* WSLUA_MOREARGS info objects to be printed */ - wslua_log(L,G_LOG_LEVEL_INFO); - return 0; -} -WSLUA_FUNCTION wslua_debug( lua_State* L ) { /* Will add a log entry with debug severity. */ -/* WSLUA_MOREARGS debug objects to be printed */ - wslua_log(L,G_LOG_LEVEL_DEBUG); - return 0; -} - /* The returned filename is g_malloc()'d so the caller must free it */ /* except when NULL is returned if file doesn't exist */ char* wslua_get_actual_filename(const char* fname) { diff --git a/test/lua/globals_2.2.txt b/test/lua/globals_2.2.txt index 762e497238..efa744c8b0 100644 --- a/test/lua/globals_2.2.txt +++ b/test/lua/globals_2.2.txt @@ -716,9 +716,7 @@ ["wrap"] = '', ["yield"] = '' }, - ["critical"] = '', ["datafile_path"] = '', - ["debug"] = '', ["deregister_filehandler"] = '', ["dofile"] = '', ["enable_lua"] = true, @@ -811,7 +809,6 @@ [2] = "H225_OTHERS", [0] = "H225_RAS" }, - ["info"] = '', ["init_routines"] = {}, ["io"] = { ["close"] = '', @@ -865,7 +862,6 @@ ["tan"] = '', ["tanh"] = '' }, - ["message"] = '', ["module"] = '', ["new_dialog"] = '', ["next"] = '', @@ -953,7 +949,6 @@ ["type"] = '', ["typeof"] = '', ["unpack"] = '', - ["warn"] = '', ["wtap"] = { ["APPLE_IP_OVER_IEEE1394"] = 62, ["ARCNET"] = 8, -- 2.34.1