diff options
Diffstat (limited to 'src/universe.cpp')
-rw-r--r-- | src/universe.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
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) { |