From: Vladimír Čunát Date: Thu, 4 Apr 2019 12:08:06 +0000 (+0200) Subject: treewide: drop support for other lua versions X-Git-Tag: v4.1.0~21^2~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bbecc52cfbf9555244793b8937833352fb3011c7;p=thirdparty%2Fknot-resolver.git treewide: drop support for other lua versions We're very much depending on LuaJIT, for years already. The removed stuff seems very unlikely to be useful in any LuaJIT in forseeable future. The Lua language is effectively forked. --- diff --git a/.luacheckrc b/.luacheckrc index 13d8989da..837133a87 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -41,7 +41,6 @@ new_read_globals = { 'table_print', '__engine', '_ENV', - '_SANDBOX', } new_globals = { diff --git a/daemon/bindings/cache.c b/daemon/bindings/cache.c index f20d5d9b0..855161a74 100644 --- a/daemon/bindings/cache.c +++ b/daemon/bindings/cache.c @@ -466,7 +466,7 @@ int kr_bindings_cache(lua_State *L) { NULL, NULL } }; - register_lib(L, "cache", lib); + luaL_register(L, "cache", lib); return 1; } diff --git a/daemon/bindings/event.c b/daemon/bindings/event.c index 98180f758..5a4ba633f 100644 --- a/daemon/bindings/event.c +++ b/daemon/bindings/event.c @@ -218,7 +218,7 @@ int kr_bindings_event(lua_State *L) { NULL, NULL } }; - register_lib(L, "event", lib); + luaL_register(L, "event", lib); return 1; } diff --git a/daemon/bindings/impl.c b/daemon/bindings/impl.c index 21a8d7876..624aece45 100644 --- a/daemon/bindings/impl.c +++ b/daemon/bindings/impl.c @@ -49,24 +49,13 @@ int kr_bindings_modules (lua_State *L); /* ./modules.c */ int kr_bindings_net (lua_State *L); /* ./net.c */ int kr_bindings_worker (lua_State *L); /* ./worker.c */ - -static void lualib(lua_State *L, const char *name, lua_CFunction lib_cb) -{ -#if LUA_VERSION_NUM >= 502 - luaL_requiref(L, name, lib_cb, 1); - lua_pop(L, 1); -#else - lib_cb(L); -#endif -} - void kr_bindings_register(lua_State *L) { - lualib(L, "modules", kr_bindings_modules); - lualib(L, "net", kr_bindings_net); - lualib(L, "cache", kr_bindings_cache); - lualib(L, "event", kr_bindings_event); - lualib(L, "worker", kr_bindings_worker); + kr_bindings_cache(L); + kr_bindings_event(L); + kr_bindings_modules(L); + kr_bindings_net(L); + kr_bindings_worker(L); } void lua_error_p(lua_State *L, const char *fmt, ...) diff --git a/daemon/bindings/impl.h b/daemon/bindings/impl.h index 1bd0d4126..860bc612f 100644 --- a/daemon/bindings/impl.h +++ b/daemon/bindings/impl.h @@ -21,20 +21,6 @@ #include #include - -/** @internal Compatibility wrapper for Lua 5.0 - 5.2 - https://www.lua.org/manual/5.2/manual.html#luaL_newlib - */ -#if LUA_VERSION_NUM >= 502 -#define register_lib(L, name, lib) \ - luaL_newlib((L), (lib)) -#else -#define lua_rawlen(L, obj) \ - lua_objlen((L), (obj)) -#define register_lib(L, name, lib) \ - luaL_openlib((L), (name), (lib), 0) -#endif - /** Useful to stringify #defines into error strings. */ #define STR(s) STRINGIFY_TOKEN(s) #define STRINGIFY_TOKEN(s) #s diff --git a/daemon/bindings/modules.c b/daemon/bindings/modules.c index 0177bdce5..2cd44feaa 100644 --- a/daemon/bindings/modules.c +++ b/daemon/bindings/modules.c @@ -85,7 +85,7 @@ int kr_bindings_modules(lua_State *L) { NULL, NULL } }; - register_lib(L, "modules", lib); + luaL_register(L, "modules", lib); return 1; } diff --git a/daemon/bindings/net.c b/daemon/bindings/net.c index 0d7e7d3ab..de7d30838 100644 --- a/daemon/bindings/net.c +++ b/daemon/bindings/net.c @@ -279,7 +279,7 @@ static int net_interfaces(lua_State *L) buf[0] = '\0'; } lua_pushstring(L, buf); - lua_rawseti(L, -2, lua_rawlen(L, -2) + 1); + lua_rawseti(L, -2, lua_objlen(L, -2) + 1); lua_setfield(L, -2, "addr"); /* Hardware address. */ @@ -1030,7 +1030,7 @@ int kr_bindings_net(lua_State *L) { "register_endpoint_kind", net_register_endpoint_kind }, { NULL, NULL } }; - register_lib(L, "net", lib); + luaL_register(L, "net", lib); return 1; } diff --git a/daemon/bindings/worker.c b/daemon/bindings/worker.c index 34035d2dc..41379f45f 100644 --- a/daemon/bindings/worker.c +++ b/daemon/bindings/worker.c @@ -177,7 +177,7 @@ int kr_bindings_worker(lua_State *L) { "stats", wrk_stats }, { NULL, NULL } }; - register_lib(L, "worker", lib); + luaL_register(L, "worker", lib); return 1; } diff --git a/daemon/engine.c b/daemon/engine.c index 036b2fe51..73823f9ff 100644 --- a/daemon/engine.c +++ b/daemon/engine.c @@ -53,11 +53,6 @@ #endif #endif -/** @internal Compatibility wrapper for Lua < 5.2 */ -#if LUA_VERSION_NUM < 502 -#define lua_rawlen(L, obj) lua_objlen((L), (obj)) -#endif - /**@internal Maximum number of incomplete TCP connections in queue. * Default is from Redis and Apache. */ #ifndef TCP_BACKLOG_DEFAULT @@ -306,7 +301,7 @@ static void l_unpack_json(lua_State *L, JsonNode *table) if (node->key) { lua_setfield(L, -2, node->key); } else { - lua_rawseti(L, -2, lua_rawlen(L, -2) + 1); + lua_rawseti(L, -2, lua_objlen(L, -2) + 1); } } } @@ -390,7 +385,7 @@ static int l_fromjson(lua_State *L) /** @internal Throw Lua error if expr is false */ #define expr_checked(expr) \ - if (!(expr)) { lua_pushboolean(L, false); lua_rawseti(L, -2, lua_rawlen(L, -2) + 1); continue; } + if (!(expr)) { lua_pushboolean(L, false); lua_rawseti(L, -2, lua_objlen(L, -2) + 1); continue; } static int l_map(lua_State *L) { @@ -429,12 +424,12 @@ static int l_map(lua_State *L) lua_pushlstring(L, rbuf, rlen); } json_delete(root_node); - lua_rawseti(L, -2, lua_rawlen(L, -2) + 1); + lua_rawseti(L, -2, lua_objlen(L, -2) + 1); continue; } /* Didn't respond */ lua_pushboolean(L, false); - lua_rawseti(L, -2, lua_rawlen(L, -2) + 1); + lua_rawseti(L, -2, lua_objlen(L, -2) + 1); } return 1; } @@ -666,10 +661,6 @@ void engine_deinit(struct engine *engine) int engine_pcall(lua_State *L, int argc) { -#if LUA_VERSION_NUM >= 502 - lua_getglobal(L, "_SANDBOX"); - lua_setupvalue(L, -(2 + argc), 1); -#endif return lua_pcall(L, argc, LUA_MULTRET, 0); } diff --git a/daemon/ffimodule.c b/daemon/ffimodule.c index e46f4f146..f9f6b01ed 100644 --- a/daemon/ffimodule.c +++ b/daemon/ffimodule.c @@ -25,12 +25,6 @@ #include "lib/module.h" #include "lib/layer.h" -#if LUA_VERSION_NUM >= 502 -#define l_resume(L, argc) lua_resume((L), NULL, (argc)) -#else -#define l_resume(L, argc) lua_resume((L), (argc)) -#endif - /** @internal Slots for layer callbacks. * Each slot ID corresponds to Lua reference in module API. */ enum { @@ -65,7 +59,7 @@ static inline lua_State *l_ffi_preface(struct kr_module *module, const char *cal static void l_ffi_resume_cb(uv_idle_t *check) { lua_State *L = check->data; - int status = l_resume(L, 0); + int status = lua_resume(L, 0); if (status != LUA_YIELD) { uv_idle_stop(check); /* Stop coroutine */ uv_close((uv_handle_t *)check, (uv_close_cb)free); diff --git a/daemon/lua/sandbox.lua.in b/daemon/lua/sandbox.lua.in index 6d9d87826..b753d1777 100644 --- a/daemon/lua/sandbox.lua.in +++ b/daemon/lua/sandbox.lua.in @@ -404,12 +404,8 @@ local function make_sandbox(defined) end -- Compatibility sandbox -if setfenv then -- Lua 5.1 and less - _G = make_sandbox(getfenv(0)) - setfenv(0, _G) -else -- Lua 5.2+ - _SANDBOX = make_sandbox(_ENV) -end +_G = make_sandbox(getfenv(0)) +setfenv(0, _G) -- Load embedded modules trust_anchors = require('trust_anchors') diff --git a/modules/bogus_log/bogus_log.c b/modules/bogus_log/bogus_log.c index 09f4d6828..e67dbfe18 100644 --- a/modules/bogus_log/bogus_log.c +++ b/modules/bogus_log/bogus_log.c @@ -12,11 +12,6 @@ #include "lib/layer.h" #include "lib/generic/lru.h" -/** @internal Compatibility wrapper for Lua < 5.2 */ -#if LUA_VERSION_NUM < 502 -#define lua_rawlen(L, obj) lua_objlen((L), (obj)) -#endif - #ifdef LRU_REP_SIZE #define FREQUENT_COUNT LRU_REP_SIZE /* Size of frequent tables */ #else diff --git a/modules/stats/stats.c b/modules/stats/stats.c index add632eba..361147c83 100644 --- a/modules/stats/stats.c +++ b/modules/stats/stats.c @@ -36,11 +36,6 @@ #include "lib/layer.h" #include "lib/resolve.h" -/** @internal Compatibility wrapper for Lua < 5.2 */ -#if LUA_VERSION_NUM < 502 -#define lua_rawlen(L, obj) lua_objlen((L), (obj)) -#endif - /* Defaults */ #define VERBOSE_MSG(qry, ...) QRVERBOSE(qry, "stat", __VA_ARGS__) #define FREQUENT_PSAMPLE 10 /* Sampling rate, 1 in N */