From 7acc7867a8ebee0a3467a382b6998cb4e95580ed Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Mon, 17 Mar 2025 14:54:56 +0100 Subject: Fix test "allocator = " not failing against LuaJIT like it should --- src/state.cpp | 2 +- src/universe.cpp | 10 +++++----- src/universe.hpp | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/state.cpp b/src/state.cpp index b558d11..fc7f5ef 100644 --- a/src/state.cpp +++ b/src/state.cpp @@ -158,7 +158,7 @@ namespace state { // for some reason, LuaJIT 64 bits does not support creating a state with lua_newstate... return luaL_newstate(); } else { - lanes::AllocatorDefinition const _def{ U->resolveAllocator(from, hint) }; + lanes::AllocatorDefinition const _def{ U->resolveAndValidateAllocator(from, hint) }; return _def.newState(); } } diff --git a/src/universe.cpp b/src/universe.cpp index dd7bc4b..db00b72 100644 --- a/src/universe.cpp +++ b/src/universe.cpp @@ -244,7 +244,7 @@ void Universe::initializeAllocatorFunction(lua_State* const L_) provideAllocator = lua_tocfunction(L_, -1); // L_: settings allocator if (provideAllocator != nullptr) { // make sure the function doesn't have upvalues - char const* _upname = lua_getupvalue(L_, -1, 1); // L_: settings allocator upval? + char const* _upname{ lua_getupvalue(L_, -1, 1) }; // L_: settings allocator upval? if (_upname != nullptr) { // should be "" for C functions with upvalues if any raise_luaL_error(L_, "config.allocator() shouldn't have upvalues"); } @@ -266,11 +266,11 @@ void Universe::initializeAllocatorFunction(lua_State* const L_) std::ignore = luaG_getfield(L_, kIdxTop, "internal_allocator"); // L_: settings "libc"|"allocator" LUA_ASSERT(L_, lua_isstring(L_, kIdxTop)); // should be the case due to lanes.lua parameter validation std::string_view const _allocator{ luaG_tostring(L_, kIdxTop) }; + // use whatever the provider provides. This performs validation of what provideAllocator is giving + // we do this even if _allocator == "libc", to have the validation part + internalAllocator = resolveAndValidateAllocator(L_, "internal"); if (_allocator == "libc") { internalAllocator = lanes::AllocatorDefinition{ libc_lua_Alloc, nullptr }; - } else { - // use whatever the provider provides - internalAllocator = resolveAllocator(L_, "internal"); } lua_pop(L_, 1); // L_: settings STACK_CHECK(L_, 1); @@ -331,7 +331,7 @@ void Universe::initializeOnStateCreate(lua_State* const L_) // ################################################################################################# -lanes::AllocatorDefinition Universe::resolveAllocator(lua_State* const L_, std::string_view const& hint_) const +lanes::AllocatorDefinition Universe::resolveAndValidateAllocator(lua_State* const L_, std::string_view const& hint_) const { lanes::AllocatorDefinition _ret{ protectedAllocator }; if (provideAllocator == nullptr) { diff --git a/src/universe.hpp b/src/universe.hpp index 2a3085d..42a3d83 100644 --- a/src/universe.hpp +++ b/src/universe.hpp @@ -151,7 +151,7 @@ class Universe final static int InitializeFinalizer(lua_State* L_); void initializeOnStateCreate(lua_State* L_); [[nodiscard]] - lanes::AllocatorDefinition resolveAllocator(lua_State* L_, std::string_view const& hint_) const; + lanes::AllocatorDefinition resolveAndValidateAllocator(lua_State* L_, std::string_view const& hint_) const; static inline void Store(lua_State* L_, Universe* U_); [[nodiscard]] bool terminateFreeRunningLanes(lua_Duration shutdownTimeout_, CancelOp op_); -- cgit v1.2.3-55-g6feb