From 20c98c29c1200d64d7356a77a58019e5a1625b73 Mon Sep 17 00:00:00 2001 From: Roman Gershman Date: Sat, 25 May 2024 23:11:27 +0300 Subject: [PATCH] fix: increase lua stack limit to 8KB (#3080) Before that 'lua_checkstack(lua(), 7000)' would not pass because we limited lua stack to 4KB. 7000 is the max limit used by bullmq, so we raising it to support this case. Signed-off-by: Roman Gershman --- patches/lua-v5.4.4.patch | 48 ------------------------------------ src/CMakeLists.txt | 2 +- src/core/interpreter_test.cc | 22 +++++++++++++++++ 3 files changed, 23 insertions(+), 49 deletions(-) delete mode 100644 patches/lua-v5.4.4.patch diff --git a/patches/lua-v5.4.4.patch b/patches/lua-v5.4.4.patch deleted file mode 100644 index dc6d20e6c..000000000 --- a/patches/lua-v5.4.4.patch +++ /dev/null @@ -1,48 +0,0 @@ -diff --git a/luaconf.h b/luaconf.h -index d42d14b7..75647e72 100644 ---- a/luaconf.h -+++ b/luaconf.h -@@ -731,7 +731,7 @@ - ** (It must fit into max(size_t)/32.) - */ - #if LUAI_IS32INT --#define LUAI_MAXSTACK 1000000 -+#define LUAI_MAXSTACK 4096 - #else - #define LUAI_MAXSTACK 15000 - #endif -diff --git a/makefile b/makefile -index d46e650c..c27e5677 100644 ---- a/makefile -+++ b/makefile -@@ -66,13 +66,26 @@ LOCAL = $(TESTS) $(CWARNS) - - - # enable Linux goodies --MYCFLAGS= $(LOCAL) -std=c99 -DLUA_USE_LINUX -DLUA_USE_READLINE -+MYCFLAGS= $(LOCAL) -std=c99 -g -O2 -DLUA_USE_LINUX --MYLDFLAGS= $(LOCAL) -Wl,-E -+# Commenting out dynamic linking flags because we link statically -+# and this does not work on MacOS: MYLDFLAGS= $(LOCAL) -Wl,-E --MYLIBS= -ldl -lreadline -+MYLIBS= -ldl - -+uname_m := $(shell uname -m) -+ -+# equivalent to: if $(uname_m) == x86_64 || $(uname_m) == amd64 -+ifneq (, $(filter $(uname_m),x86_64 amd64)) -+OPTFLAGS= -march=sandybridge -+else ifneq (, $(filter $(uname_m),aarch64 arm64)) -+OPTFLAGS= -march=armv8.2-a+fp16+rcpc+dotprod+crypto -+else ifeq ($(uname_m), s390x) -+OPTFLAGS= -march=native -+else -+ $(error ERROR: unknown architecture $(uname_m)) -+endif - - CC= gcc --CFLAGS= -Wall -O2 $(MYCFLAGS) -fno-stack-protector -fno-common -march=native -+CFLAGS= -Wall -O2 $(MYCFLAGS) -fno-stack-protector -fno-common $(OPTFLAGS) - AR= ar rc - RANLIB= ranlib - RM= rm -f diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 062f91122..3497c61b6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -8,7 +8,7 @@ endif() add_third_party( lua GIT_REPOSITORY https://github.com/dragonflydb/lua - GIT_TAG Dragonfly-5.4.6 + GIT_TAG Dragonfly-5.4.6a CONFIGURE_COMMAND echo BUILD_IN_SOURCE 1 BUILD_COMMAND ${DFLY_TOOLS_MAKE} all diff --git a/src/core/interpreter_test.cc b/src/core/interpreter_test.cc index 8a1e4a95b..818e645cc 100644 --- a/src/core/interpreter_test.cc +++ b/src/core/interpreter_test.cc @@ -89,6 +89,7 @@ class InterpreterTest : public ::testing::Test { void SetGlobalArray(const char* name, const vector& vec); + // returns true if script run successfully. bool Execute(string_view script); Interpreter intptr_; @@ -492,4 +493,25 @@ TEST_F(InterpreterTest, Robust) { EXPECT_EQ("", ser_.res); } +TEST_F(InterpreterTest, Unpack) { + auto cb = [](Interpreter::CallArgs ca) { + auto* reply = ca.translator; + reply->OnInt(1); + }; + intptr_.SetRedisFunc(cb); + ASSERT_TRUE(lua_checkstack(lua(), 7000)); + bool res = Execute(R"( +local N = 7000 + +local stringTable = {} +for i = 1, N do + stringTable[i] = "String " .. i +end + return redis.pcall('func', unpack(stringTable)) +)"); + + ASSERT_TRUE(res) << error_; + EXPECT_EQ("i(1)", ser_.res); +} + } // namespace dfly