diff mbox series

lua: fix build with LuaJit and license issue

Message ID 20240907212554.3547568-1-stefano.babic@swupdate.org
State Accepted
Headers show
Series lua: fix build with LuaJit and license issue | expand

Commit Message

Stefano Babic Sept. 7, 2024, 9:25 p.m. UTC
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
diff mbox series

Patch

diff --git a/bindings/lua_swupdate.c b/bindings/lua_swupdate.c
index b7f2a2e8..0a5dc9fa 100644
--- a/bindings/lua_swupdate.c
+++ b/bindings/lua_swupdate.c
@@ -23,6 +23,7 @@ 
 #include <stdlib.h>

 #include "auxiliar.h"
+#include "lua_compat.h"

 #define WAIT 1

diff --git a/corelib/lua_compat.c b/corelib/lua_compat.c
index c5f763f5..6c1d5f0e 100644
--- a/corelib/lua_compat.c
+++ b/corelib/lua_compat.c
@@ -6,6 +6,7 @@ 
  */

 #include <lua.h>
+#include "lua_compat.h"

 /*
  * These LuaJIT/Lua 5.1 compatibility functions are taken from
diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c
index 35433b9c..1460b5ec 100644
--- a/corelib/lua_interface.c
+++ b/corelib/lua_interface.c
@@ -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"
diff --git a/include/lua_compat.h b/include/lua_compat.h
new file mode 100644
index 00000000..10075abe
--- /dev/null
+++ b/include/lua_compat.h
@@ -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
+
diff --git a/include/lua_util.h b/include/lua_util.h
index b3a0c564..92bf1d19 100644
--- a/include/lua_util.h
+++ b/include/lua_util.h
@@ -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;