From 42bd18111b44e3dde3475b6c7e1902439556aca40ed33187e55a841d36f085b4 Mon Sep 17 00:00:00 2001 From: Callum Farmer Date: Wed, 9 Mar 2022 10:14:38 +0000 Subject: [PATCH] Accepting request 960438 from home:gmbr3:Lua - Added patches from upstream: * luabugs1.patch * luabugs2.patch - Adjust buildsystem so that it matches upstream git (testes??) OBS-URL: https://build.opensuse.org/request/show/960438 OBS-URL: https://build.opensuse.org/package/show/devel:languages:lua/lua54?expand=0&rev=52 --- attrib_test.patch | 4 +- files_test.patch | 4 +- lua54.changes | 8 ++++ lua54.spec | 18 ++++----- luabugs1.patch | 94 +++++++++++++++++++++++++++++++++++++++++++++++ luabugs2.patch | 43 ++++++++++++++++++++++ main_test.patch | 4 +- 7 files changed, 159 insertions(+), 16 deletions(-) create mode 100644 luabugs1.patch create mode 100644 luabugs2.patch diff --git a/attrib_test.patch b/attrib_test.patch index 5f6f84f..d5fd3be 100644 --- a/attrib_test.patch +++ b/attrib_test.patch @@ -1,5 +1,5 @@ ---- a/attrib.lua -+++ b/attrib.lua +--- a/testes/attrib.lua ++++ b/testes/attrib.lua @@ -269,7 +269,7 @@ local p = "" -- On Mac OS X, redefine local st, err, when = package.loadlib(DC"lib1", "*") if not st then diff --git a/files_test.patch b/files_test.patch index 64ab3f3..035da1b 100644 --- a/files_test.patch +++ b/files_test.patch @@ -1,7 +1,7 @@ Index: lua/files.lua =================================================================== ---- lua.orig/files.lua -+++ lua/files.lua +--- lua.orig/testes/files.lua ++++ lua/testes/files.lua @@ -81,7 +81,7 @@ assert(io.output() ~= io.stdout) if not _port then -- invalid seek diff --git a/lua54.changes b/lua54.changes index 0da7f6b..fcd476d 100644 --- a/lua54.changes +++ b/lua54.changes @@ -1,3 +1,11 @@ +------------------------------------------------------------------- +Wed Mar 9 10:12:55 UTC 2022 - Callum Farmer + +- Added patches from upstream: + * luabugs1.patch + * luabugs2.patch +- Adjust buildsystem so that it matches upstream git (testes??) + ------------------------------------------------------------------- Mon Mar 7 10:19:17 UTC 2022 - Bjørn Lie diff --git a/lua54.spec b/lua54.spec index d40fa91..58b0b22 100644 --- a/lua54.spec +++ b/lua54.spec @@ -43,6 +43,10 @@ Patch1: attrib_test.patch Patch2: files_test.patch Patch3: main_test.patch Patch6: shared_link.patch +# PATCH-FIX-UPSTREAM luabugsX.patch https://www.lua.org/bugs.html#5.4.4-X +Patch7: luabugs1.patch +Patch8: luabugs2.patch +# %if "%{flavor}" == "test" BuildRequires: lua54 %else @@ -137,16 +141,9 @@ scripting, and rapid prototyping. Lua is implemented as a small library of C functions, written in ANSI C. %prep -%if "%{flavor}" == "test" -%setup -T -q -b1 -n lua-%{version}-tests -%patch1 -p1 -%patch2 -p1 -%patch3 -p1 -%else -%setup -q -n lua-%{version} -%patch0 -p1 -%patch6 -p1 -%endif +%setup -q -n lua-%{version} -a1 +mv lua-%{version}-tests testes +%autopatch -p1 # manpage %if "%{flavor}" != "test" @@ -206,6 +203,7 @@ touch %{buildroot}%{_sysconfdir}/alternatives/lua.pc ln -sf %{_sysconfdir}/alternatives/lua.pc %{buildroot}%{_libdir}/pkgconfig/lua.pc %else %check +cd testes LD_LIBRARY_PATH=%{_libdir} %{_bindir}/lua%{major_version} all.lua %endif diff --git a/luabugs1.patch b/luabugs1.patch new file mode 100644 index 0000000..70a3feb --- /dev/null +++ b/luabugs1.patch @@ -0,0 +1,94 @@ +From 25b143dd34fb587d1e35290c4b25bc08954800e2 Mon Sep 17 00:00:00 2001 +From: Roberto Ierusalimschy +Date: Mon, 7 Feb 2022 10:16:35 -0300 +Subject: [PATCH] Bug: lua.c assumes that argv has at least one element + +--- + lua.c | 35 +++++++++++++++++++++++------------ + 1 file changed, 23 insertions(+), 12 deletions(-) + +diff --git a/lua.c b/lua.c +index 0f1900444..7f7dc2b22 100644 +--- a/src/lua.c ++++ b/src/lua.c +@@ -177,10 +177,11 @@ static void print_version (void) { + ** to the script (everything after 'script') go to positive indices; + ** other arguments (before the script name) go to negative indices. + ** If there is no script name, assume interpreter's name as base. ++** (If there is no interpreter's name either, 'script' is -1, so ++** table sizes are zero.) + */ + static void createargtable (lua_State *L, char **argv, int argc, int script) { + int i, narg; +- if (script == argc) script = 0; /* no script name? */ + narg = argc - (script + 1); /* number of positive indices */ + lua_createtable(L, narg, script + 1); + for (i = 0; i < argc; i++) { +@@ -268,14 +269,23 @@ static int handle_script (lua_State *L, char **argv) { + + /* + ** Traverses all arguments from 'argv', returning a mask with those +-** needed before running any Lua code (or an error code if it finds +-** any invalid argument). 'first' returns the first not-handled argument +-** (either the script name or a bad argument in case of error). ++** needed before running any Lua code or an error code if it finds any ++** invalid argument. In case of error, 'first' is the index of the bad ++** argument. Otherwise, 'first' is -1 if there is no program name, ++** 0 if there is no script name, or the index of the script name. + */ + static int collectargs (char **argv, int *first) { + int args = 0; + int i; +- for (i = 1; argv[i] != NULL; i++) { ++ if (argv[0] != NULL) { /* is there a program name? */ ++ if (argv[0][0]) /* not empty? */ ++ progname = argv[0]; /* save it */ ++ } ++ else { /* no program name */ ++ *first = -1; ++ return 0; ++ } ++ for (i = 1; argv[i] != NULL; i++) { /* handle arguments */ + *first = i; + if (argv[i][0] != '-') /* not an option? */ + return args; /* stop handling options */ +@@ -316,7 +326,7 @@ static int collectargs (char **argv, int *first) { + return has_error; + } + } +- *first = i; /* no script name */ ++ *first = 0; /* no script name */ + return args; + } + +@@ -609,8 +619,8 @@ static int pmain (lua_State *L) { + char **argv = (char **)lua_touserdata(L, 2); + int script; + int args = collectargs(argv, &script); ++ int optlim = (script > 0) ? script : argc; /* first argv not an option */ + luaL_checkversion(L); /* check that interpreter has correct version */ +- if (argv[0] && argv[0][0]) progname = argv[0]; + if (args == has_error) { /* bad arg? */ + print_usage(argv[script]); /* 'script' has index of bad arg. */ + return 0; +@@ -628,14 +638,15 @@ static int pmain (lua_State *L) { + if (handle_luainit(L) != LUA_OK) /* run LUA_INIT */ + return 0; /* error running LUA_INIT */ + } +- if (!runargs(L, argv, script)) /* execute arguments -e and -l */ ++ if (!runargs(L, argv, optlim)) /* execute arguments -e and -l */ + return 0; /* something failed */ +- if (script < argc && /* execute main script (if there is one) */ +- handle_script(L, argv + script) != LUA_OK) +- return 0; ++ if (script > 0) { /* execute main script (if there is one) */ ++ if (handle_script(L, argv + script) != LUA_OK) ++ return 0; /* interrupt in case of error */ ++ } + if (args & has_i) /* -i option? */ + doREPL(L); /* do read-eval-print loop */ +- else if (script == argc && !(args & (has_e | has_v))) { /* no arguments? */ ++ else if (script < 1 && !(args & (has_e | has_v))) { /* no active option? */ + if (lua_stdin_is_tty()) { /* running in interactive mode? */ + print_version(); + doREPL(L); /* do read-eval-print loop */ diff --git a/luabugs2.patch b/luabugs2.patch new file mode 100644 index 0000000..8839c1e --- /dev/null +++ b/luabugs2.patch @@ -0,0 +1,43 @@ +From 1f3c6f4534c6411313361697d98d1145a1f030fa Mon Sep 17 00:00:00 2001 +From: Roberto Ierusalimschy +Date: Tue, 15 Feb 2022 12:28:46 -0300 +Subject: [PATCH] Bug: Lua can generate wrong code when _ENV is + +--- + lparser.c | 1 + + testes/attrib.lua | 10 ++++++++++ + 2 files changed, 11 insertions(+) + +diff --git a/lparser.c b/lparser.c +index 3abe3d751..a5cd55257 100644 +--- a/src/lparser.c ++++ b/src/lparser.c +@@ -468,6 +468,7 @@ static void singlevar (LexState *ls, expdesc *var) { + expdesc key; + singlevaraux(fs, ls->envn, var, 1); /* get environment variable */ + lua_assert(var->k != VVOID); /* this one must exist */ ++ luaK_exp2anyregup(fs, var); /* but could be a constant */ + codestring(&key, varname); /* key is variable name */ + luaK_indexed(fs, var, &key); /* env[varname] */ + } +diff --git a/testes/attrib.lua b/testes/attrib.lua +index b1076c768..83821c069 100644 +--- a/testes/attrib.lua ++++ b/testes/attrib.lua +@@ -434,6 +434,16 @@ a.aVeryLongName012345678901234567890123456789012345678901234567890123456789 == + 10) + + ++do ++ -- _ENV constant ++ local function foo () ++ local _ENV = 11 ++ X = "hi" ++ end ++ local st, msg = pcall(foo) ++ assert(not st and string.find(msg, "number")) ++end ++ + + -- test of large float/integer indices + diff --git a/main_test.patch b/main_test.patch index 89f08a4..6ca0618 100644 --- a/main_test.patch +++ b/main_test.patch @@ -1,5 +1,5 @@ ---- a/main.lua -+++ b/main.lua +--- a/testes/main.lua ++++ b/testes/main.lua @@ -47,7 +47,7 @@ assert(string.sub(s, -1) == "\n") local t = getoutput()