Skip to content

Commit

Permalink
lua: update deprecated lua_open to luaL_newstate (#14297)
Browse files Browse the repository at this point in the history
 lua_open is deprecated in Lua 5.1 and removed in the later version,
 though LuaJIT might keep the API unchanged.

 In LuaJIT, lua_open is just an alias of luaL_newstate.

Signed-off-by: spacewander <[email protected]>
  • Loading branch information
spacewander authored Dec 8, 2020
1 parent 5cd2d42 commit fa80297
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 4 additions & 2 deletions source/extensions/filters/common/lua/lua.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ ThreadLocalState::ThreadLocalState(const std::string& code, ThreadLocal::SlotAll
: tls_slot_(ThreadLocal::TypedSlot<LuaThreadLocal>::makeUnique(tls)) {

// First verify that the supplied code can be parsed.
CSmartPtr<lua_State, lua_close> state(lua_open());
CSmartPtr<lua_State, lua_close> state(luaL_newstate());
RELEASE_ASSERT(state.get() != nullptr, "unable to create new Lua state object");
luaL_openlibs(state.get());

Expand Down Expand Up @@ -90,7 +90,9 @@ CoroutinePtr ThreadLocalState::createCoroutine() {
return std::make_unique<Coroutine>(std::make_pair(lua_newthread(state), state));
}

ThreadLocalState::LuaThreadLocal::LuaThreadLocal(const std::string& code) : state_(lua_open()) {
ThreadLocalState::LuaThreadLocal::LuaThreadLocal(const std::string& code)
: state_(luaL_newstate()) {

RELEASE_ASSERT(state_.get() != nullptr, "unable to create new Lua state object");
luaL_openlibs(state_.get());
int rc = luaL_dostring(state_.get(), code.c_str());
Expand Down
4 changes: 3 additions & 1 deletion test/extensions/filters/http/lua/lua_integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,9 @@ TEST_P(LuaIntegrationTest, BasicTestOfLuaPerRoute) {
// Test whether Rds can correctly deliver LuaPerRoute configuration.
TEST_P(LuaIntegrationTest, RdsTestOfLuaPerRoute) {
// When the route configuration is updated dynamically via RDS and the configuration contains an
// inline Lua code, Envoy may call lua_open in multiple threads to create new lua_State objects.
// inline Lua code, Envoy may call `luaL_newstate`
// (https://www.lua.org/manual/5.1/manual.html#luaL_newstate) in multiple threads to create new
// lua_State objects.
// During lua_State creation, 'LuaJIT' uses some static local variables shared by multiple threads
// to aid memory allocation. Although 'LuaJIT' itself guarantees that there is no thread safety
// issue here, the use of these static local variables by multiple threads will cause a TSAN alarm.
Expand Down

0 comments on commit fa80297

Please sign in to comment.