diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/state.cpp | 2 | ||||
-rw-r--r-- | src/universe.cpp | 10 | ||||
-rw-r--r-- | src/universe.hpp | 2 |
3 files changed, 7 insertions, 7 deletions
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 { | |||
158 | // for some reason, LuaJIT 64 bits does not support creating a state with lua_newstate... | 158 | // for some reason, LuaJIT 64 bits does not support creating a state with lua_newstate... |
159 | return luaL_newstate(); | 159 | return luaL_newstate(); |
160 | } else { | 160 | } else { |
161 | lanes::AllocatorDefinition const _def{ U->resolveAllocator(from, hint) }; | 161 | lanes::AllocatorDefinition const _def{ U->resolveAndValidateAllocator(from, hint) }; |
162 | return _def.newState(); | 162 | return _def.newState(); |
163 | } | 163 | } |
164 | } | 164 | } |
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_) | |||
244 | provideAllocator = lua_tocfunction(L_, -1); // L_: settings allocator | 244 | provideAllocator = lua_tocfunction(L_, -1); // L_: settings allocator |
245 | if (provideAllocator != nullptr) { | 245 | if (provideAllocator != nullptr) { |
246 | // make sure the function doesn't have upvalues | 246 | // make sure the function doesn't have upvalues |
247 | char const* _upname = lua_getupvalue(L_, -1, 1); // L_: settings allocator upval? | 247 | char const* _upname{ lua_getupvalue(L_, -1, 1) }; // L_: settings allocator upval? |
248 | if (_upname != nullptr) { // should be "" for C functions with upvalues if any | 248 | if (_upname != nullptr) { // should be "" for C functions with upvalues if any |
249 | raise_luaL_error(L_, "config.allocator() shouldn't have upvalues"); | 249 | raise_luaL_error(L_, "config.allocator() shouldn't have upvalues"); |
250 | } | 250 | } |
@@ -266,11 +266,11 @@ void Universe::initializeAllocatorFunction(lua_State* const L_) | |||
266 | std::ignore = luaG_getfield(L_, kIdxTop, "internal_allocator"); // L_: settings "libc"|"allocator" | 266 | std::ignore = luaG_getfield(L_, kIdxTop, "internal_allocator"); // L_: settings "libc"|"allocator" |
267 | LUA_ASSERT(L_, lua_isstring(L_, kIdxTop)); // should be the case due to lanes.lua parameter validation | 267 | LUA_ASSERT(L_, lua_isstring(L_, kIdxTop)); // should be the case due to lanes.lua parameter validation |
268 | std::string_view const _allocator{ luaG_tostring(L_, kIdxTop) }; | 268 | std::string_view const _allocator{ luaG_tostring(L_, kIdxTop) }; |
269 | // use whatever the provider provides. This performs validation of what provideAllocator is giving | ||
270 | // we do this even if _allocator == "libc", to have the validation part | ||
271 | internalAllocator = resolveAndValidateAllocator(L_, "internal"); | ||
269 | if (_allocator == "libc") { | 272 | if (_allocator == "libc") { |
270 | internalAllocator = lanes::AllocatorDefinition{ libc_lua_Alloc, nullptr }; | 273 | internalAllocator = lanes::AllocatorDefinition{ libc_lua_Alloc, nullptr }; |
271 | } else { | ||
272 | // use whatever the provider provides | ||
273 | internalAllocator = resolveAllocator(L_, "internal"); | ||
274 | } | 274 | } |
275 | lua_pop(L_, 1); // L_: settings | 275 | lua_pop(L_, 1); // L_: settings |
276 | STACK_CHECK(L_, 1); | 276 | STACK_CHECK(L_, 1); |
@@ -331,7 +331,7 @@ void Universe::initializeOnStateCreate(lua_State* const L_) | |||
331 | 331 | ||
332 | // ################################################################################################# | 332 | // ################################################################################################# |
333 | 333 | ||
334 | lanes::AllocatorDefinition Universe::resolveAllocator(lua_State* const L_, std::string_view const& hint_) const | 334 | lanes::AllocatorDefinition Universe::resolveAndValidateAllocator(lua_State* const L_, std::string_view const& hint_) const |
335 | { | 335 | { |
336 | lanes::AllocatorDefinition _ret{ protectedAllocator }; | 336 | lanes::AllocatorDefinition _ret{ protectedAllocator }; |
337 | if (provideAllocator == nullptr) { | 337 | 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 | |||
151 | static int InitializeFinalizer(lua_State* L_); | 151 | static int InitializeFinalizer(lua_State* L_); |
152 | void initializeOnStateCreate(lua_State* L_); | 152 | void initializeOnStateCreate(lua_State* L_); |
153 | [[nodiscard]] | 153 | [[nodiscard]] |
154 | lanes::AllocatorDefinition resolveAllocator(lua_State* L_, std::string_view const& hint_) const; | 154 | lanes::AllocatorDefinition resolveAndValidateAllocator(lua_State* L_, std::string_view const& hint_) const; |
155 | static inline void Store(lua_State* L_, Universe* U_); | 155 | static inline void Store(lua_State* L_, Universe* U_); |
156 | [[nodiscard]] | 156 | [[nodiscard]] |
157 | bool terminateFreeRunningLanes(lua_Duration shutdownTimeout_, CancelOp op_); | 157 | bool terminateFreeRunningLanes(lua_Duration shutdownTimeout_, CancelOp op_); |