@@ -23,6 +23,7 @@
#include <stdlib.h>
#include "auxiliar.h"
+#include "lua_compat.h"
#define WAIT 1
@@ -6,6 +6,7 @@
*/
#include <lua.h>
+#include "lua_compat.h"
/*
* These LuaJIT/Lua 5.1 compatibility functions are taken from
@@ -21,6 +21,7 @@
#include "lauxlib.h"
#include "lualib.h"
#include "lua_util.h"
+#include "lua_compat.h"
#include "util.h"
#include "handler.h"
#include "bootloader.h"
new file mode 100644
@@ -0,0 +1,59 @@
+/*
+ * (C) Copyright 2024 Stefano Babic <stefano.babic@swupdate.org>
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+#pragma once
+#include <string.h>
+#include <stdio.h>
+#include <stdbool.h>
+#include <lua.h>
+#include "lauxlib.h"
+#include "lualib.h"
+
+#if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM == 501
+#define LUA_OK 0
+#if !defined(luaL_newlib)
+#define luaL_newlib(L, l) (lua_newtable((L)),luaL_setfuncs((L), (l), 0))
+#endif
+
+void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup);
+void luaL_requiref(lua_State *L, char const* modname, lua_CFunction openf, int glb);
+
+
+/*
+ * See https://github.com/keplerproject/lua-compat-5.3/wiki/luaL_Stream
+ * on the reason for the absence of luaL_Stream's closef member and
+ * compatibility with LuaJIT / Lua 5.1.
+ */
+typedef struct luaL_Stream {
+ FILE *f;
+} luaL_Stream;
+
+typedef struct luaL_Buffer_52 {
+ luaL_Buffer b; /* make incorrect code crash! */
+ char *ptr;
+ size_t nelems;
+ size_t capacity;
+ lua_State *L2;
+} luaL_Buffer_52;
+#define luaL_Buffer luaL_Buffer_52
+
+#define luaL_prepbuffsize luaL_prepbuffsize_52
+char *luaL_prepbuffsize(luaL_Buffer_52 *B, size_t s);
+
+#define luaL_buffinit luaL_buffinit_52
+void luaL_buffinit(lua_State *L, luaL_Buffer_52 *B);
+
+#undef luaL_addsize
+#define luaL_addsize(B, s) ((B)->nelems += (s))
+
+#define luaL_pushresult luaL_pushresult_52
+void luaL_pushresult(luaL_Buffer_52 *B);
+
+#define luaL_checkversion(L) ((void)0)
+#define lua_rawlen(L, i) lua_objlen(L, i)
+
+#endif
+
@@ -55,50 +55,6 @@ static inline int lua_isinteger (lua_State *L, int index) {
#define lua_setuservalue(L,idx) lua_setiuservalue(L,idx,1)
#endif
-#if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM == 501
-#define LUA_OK 0
-#if !defined(luaL_newlib)
-#define luaL_newlib(L, l) (lua_newtable((L)),luaL_setfuncs((L), (l), 0))
-#endif
-
-void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup);
-void luaL_requiref(lua_State *L, char const* modname, lua_CFunction openf, int glb);
-
-
-/*
- * See https://github.com/keplerproject/lua-compat-5.3/wiki/luaL_Stream
- * on the reason for the absence of luaL_Stream's closef member and
- * compatibility with LuaJIT / Lua 5.1.
- */
-typedef struct luaL_Stream {
- FILE *f;
-} luaL_Stream;
-
-typedef struct luaL_Buffer_52 {
- luaL_Buffer b; /* make incorrect code crash! */
- char *ptr;
- size_t nelems;
- size_t capacity;
- lua_State *L2;
-} luaL_Buffer_52;
-#define luaL_Buffer luaL_Buffer_52
-
-#define luaL_prepbuffsize luaL_prepbuffsize_52
-char *luaL_prepbuffsize(luaL_Buffer_52 *B, size_t s);
-
-#define luaL_buffinit luaL_buffinit_52
-void luaL_buffinit(lua_State *L, luaL_Buffer_52 *B);
-
-#undef luaL_addsize
-#define luaL_addsize(B, s) ((B)->nelems += (s))
-
-#define luaL_pushresult luaL_pushresult_52
-void luaL_pushresult(luaL_Buffer_52 *B);
-
-#define luaL_checkversion(L) ((void)0)
-#define lua_rawlen(L, i) lua_objlen(L, i)
-#endif
-
#else
struct img_type;
Commit 3f0ee9b19 was meant to fix license issue because a GPLv2 header (lua_util.h) is used in swupdate_lua library, that is licensed under LGPLv2.1. However, removing the header breaks on system with Lua 5.1 or LuaJit (even based on Lua 5.1). This patch moves definitions for older Lua to a separate header (licensed under LGPLv2.1). Signed-off-by: Stefano Babic <stefano.babic@swupdate.org> Reported-by: Michael Adler <michael.adler@siemens.com> Reported-by: Mark Jonas <mark.jonas@de.bosch.com> --- bindings/lua_swupdate.c | 1 + corelib/lua_compat.c | 1 + corelib/lua_interface.c | 1 + include/lua_compat.h | 59 +++++++++++++++++++++++++++++++++++++++++ include/lua_util.h | 44 ------------------------------ 5 files changed, 62 insertions(+), 44 deletions(-) create mode 100644 include/lua_compat.h -- 2.34.1