From 042055968ab0c48faec607889814e38c50c09efa Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Fri, 4 Jul 2025 13:50:53 +0200 Subject: Changed lua wrapper prefixes from luaG_ to luaW_ (w as in wrapper!) --- src/universe.cpp | 56 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) (limited to 'src/universe.cpp') diff --git a/src/universe.cpp b/src/universe.cpp index 3255c7f..044c841 100644 --- a/src/universe.cpp +++ b/src/universe.cpp @@ -111,18 +111,18 @@ void Universe::callOnStateCreate(lua_State* const L_, lua_State* const from_, Lo } kConfigRegKey.pushValue(L_); // L_: config STACK_CHECK(L_, 1); - LuaType const _funcType{ luaG_getfield(L_, kIdxTop, kOnStateCreate) }; // L_: config on_state_create() + LuaType const _funcType{ luaW_getfield(L_, kIdxTop, kOnStateCreate) }; // L_: config on_state_create() if (_funcType != LuaType::FUNCTION) { - raise_luaL_error(L_, "INTERNAL ERROR: %s is a %s, not a function", kOnStateCreate.data(), luaG_typename(L_, _funcType).data()); + raise_luaL_error(L_, "INTERNAL ERROR: %s is a %s, not a function", kOnStateCreate.data(), luaW_typename(L_, _funcType).data()); } lua_remove(L_, -2); // L_: on_state_create() } STACK_CHECK(L_, 1); // capture error and raise it in caller state std::string_view const _stateType{ mode_ == LookupMode::LaneBody ? "lane" : "keeper" }; - luaG_pushstring(L_, _stateType); // L_: on_state_create() "" + luaW_pushstring(L_, _stateType); // L_: on_state_create() "" if (lua_pcall(L_, 1, 0, 0) != LUA_OK) { - raise_luaL_error(from_, "%s failed in %s: \"%s\"", kOnStateCreate.data(), _stateType.data(), lua_isstring(L_, -1) ? luaG_tostring(L_, kIdxTop).data() : luaG_typename(L_, kIdxTop).data()); + raise_luaL_error(from_, "%s failed in %s: \"%s\"", kOnStateCreate.data(), _stateType.data(), lua_isstring(L_, -1) ? luaW_tostring(L_, kIdxTop).data() : luaW_typename(L_, kIdxTop).data()); } STACK_CHECK(L_, 0); } @@ -137,14 +137,14 @@ Universe* Universe::Create(lua_State* const L_) static constexpr StackIndex kIdxSettings{ 1 }; LUA_ASSERT(L_, lua_gettop(L_) == 1 && lua_istable(L_, 1)); STACK_CHECK_START_REL(L_, 0); // L_: settings - std::ignore = luaG_getfield(L_, kIdxSettings, "nb_user_keepers"); // L_: settings nb_user_keepers + std::ignore = luaW_getfield(L_, kIdxSettings, "nb_user_keepers"); // L_: settings nb_user_keepers int const _nbUserKeepers{ static_cast(lua_tointeger(L_, -1)) + 1}; lua_pop(L_, 1); // L_: settings if (_nbUserKeepers < 1) { raise_luaL_error(L_, "Bad number of additional keepers (%d)", _nbUserKeepers); } STACK_CHECK(L_, 0); - std::ignore = luaG_getfield(L_, kIdxSettings, "keepers_gc_threshold"); // L_: settings keepers_gc_threshold + std::ignore = luaW_getfield(L_, kIdxSettings, "keepers_gc_threshold"); // L_: settings keepers_gc_threshold int const _keepers_gc_threshold{ static_cast(lua_tointeger(L_, -1)) }; lua_pop(L_, 1); // L_: settings STACK_CHECK(L_, 0); @@ -157,30 +157,30 @@ Universe* Universe::Create(lua_State* const L_) DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ _U }); lua_createtable(L_, 0, 1); // L_: settings universe {mt} - std::ignore = luaG_getfield(L_, kIdxSettings, "shutdown_timeout"); // L_: settings universe {mt} shutdown_timeout + std::ignore = luaW_getfield(L_, kIdxSettings, "shutdown_timeout"); // L_: settings universe {mt} shutdown_timeout lua_pushcclosure(L_, UniverseGC, 1); // L_: settings universe {mt} UniverseGC lua_setfield(L_, -2, "__gc"); // L_: settings universe {mt} lua_setmetatable(L_, -2); // L_: settings universe lua_pop(L_, 1); // L_: settings - std::ignore = luaG_getfield(L_, kIdxSettings, "linda_wake_period"); // L_: settings linda_wake_period - if (luaG_type(L_, kIdxTop) == LuaType::NUMBER) { + std::ignore = luaW_getfield(L_, kIdxSettings, "linda_wake_period"); // L_: settings linda_wake_period + if (luaW_type(L_, kIdxTop) == LuaType::NUMBER) { _U->lindaWakePeriod = lua_Duration{ lua_tonumber(L_, kIdxTop) }; } else { - LUA_ASSERT(L_, luaG_tostring(L_, kIdxTop) == "never"); + LUA_ASSERT(L_, luaW_tostring(L_, kIdxTop) == "never"); } lua_pop(L_, 1); // L_: settings - std::ignore = luaG_getfield(L_, kIdxSettings, "strip_functions"); // L_: settings strip_functions + std::ignore = luaW_getfield(L_, kIdxSettings, "strip_functions"); // L_: settings strip_functions _U->stripFunctions = lua_toboolean(L_, -1) ? true : false; lua_pop(L_, 1); // L_: settings - std::ignore = luaG_getfield(L_, kIdxSettings, "verbose_errors"); // L_: settings verbose_errors + std::ignore = luaW_getfield(L_, kIdxSettings, "verbose_errors"); // L_: settings verbose_errors _U->verboseErrors = lua_toboolean(L_, -1) ? true : false; lua_pop(L_, 1); // L_: settings // tracking - std::ignore = luaG_getfield(L_, kIdxSettings, "track_lanes"); // L_: settings track_lanes + std::ignore = luaW_getfield(L_, kIdxSettings, "track_lanes"); // L_: settings track_lanes if (lua_toboolean(L_, -1)) { _U->tracker.activate(); } @@ -217,7 +217,7 @@ static void* libc_lua_Alloc([[maybe_unused]] void* const ud_, [[maybe_unused]] v // ################################################################################################# [[nodiscard]] -static int luaG_provide_protected_allocator(lua_State* const L_) +static int luaW_provide_protected_allocator(lua_State* const L_) { Universe* const _U{ Universe::Get(L_) }; // push a new full userdata on the stack, giving access to the universe's protected allocator @@ -245,17 +245,17 @@ void Universe::initializeAllocatorFunction(lua_State* const L_) // start by just grabbing whatever allocator was provided to the master state protectedAllocator.initFrom(L_); STACK_CHECK_START_REL(L_, 1); // L_: settings - switch (luaG_getfield(L_, kIdxTop, "allocator")) { // L_: settings allocator|nil|"protected" + switch (luaW_getfield(L_, kIdxTop, "allocator")) { // L_: settings allocator|nil|"protected" case LuaType::NIL: // nothing else to do break; case LuaType::STRING: - LUA_ASSERT(L_, luaG_tostring(L_, kIdxTop) == "protected"); + LUA_ASSERT(L_, luaW_tostring(L_, kIdxTop) == "protected"); // set the original allocator to call from inside protection by the mutex protectedAllocator.installIn(L_); // before a state is created, this function will be called to obtain the allocator - provideAllocator = luaG_provide_protected_allocator; + provideAllocator = luaW_provide_protected_allocator; break; case LuaType::FUNCTION: @@ -276,14 +276,14 @@ void Universe::initializeAllocatorFunction(lua_State* const L_) break; default: // should be filtered out in lanes.lua - raise_luaL_error(L_, "Bad config.allocator type %s", luaG_typename(L_, kIdxTop).data()); + raise_luaL_error(L_, "Bad config.allocator type %s", luaW_typename(L_, kIdxTop).data()); } lua_pop(L_, 1); // L_: settings STACK_CHECK(L_, 1); - std::ignore = luaG_getfield(L_, kIdxTop, "internal_allocator"); // L_: settings "libc"|"allocator" + std::ignore = luaW_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) }; + std::string_view const _allocator{ luaW_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"); @@ -305,7 +305,7 @@ int Universe::InitializeFinalizer(lua_State* const L_) // make sure we are only called from the Master Lua State! kUniverseFullRegKey.pushValue(L_); // L_: f U - if (luaG_type(L_, kIdxTop) != LuaType::USERDATA) { + if (luaW_type(L_, kIdxTop) != LuaType::USERDATA) { raise_luaL_error(L_, "lanes.%s called from inside a lane", kFinally); } lua_pop(L_, 1); // L_: f @@ -321,8 +321,8 @@ int Universe::InitializeFinalizer(lua_State* const L_) void Universe::initializeOnStateCreate(lua_State* const L_) { STACK_CHECK_START_REL(L_, 0); // L_: settings - if (luaG_getfield(L_, kIdxTop, kOnStateCreate) != LuaType::NIL) { // L_: settings on_state_create|nil - LUA_ASSERT(L_, luaG_type(L_, kIdxTop) == LuaType::FUNCTION); // ensured by lanes.lua parameter validation + if (luaW_getfield(L_, kIdxTop, kOnStateCreate) != LuaType::NIL) { // L_: settings on_state_create|nil + LUA_ASSERT(L_, luaW_type(L_, kIdxTop) == LuaType::FUNCTION); // ensured by lanes.lua parameter validation // store C function pointer in an internal variable lua_CFunction const _func{ lua_tocfunction(L_, -1) }; // L_: settings on_state_create if (_func) { @@ -335,7 +335,7 @@ void Universe::initializeOnStateCreate(lua_State* const L_) // remove this C function from the config table so that it doesn't cause problems // when we transfer the config table in newly created Lua states lua_pushnil(L_); // L_: settings on_state_create nil - luaG_setfield(L_, StackIndex{ -3 }, kOnStateCreate); // L_: settings on_state_create + luaW_setfield(L_, StackIndex{ -3 }, kOnStateCreate); // L_: settings on_state_create } else { // the function is still in the config table. we indicate this with the uintptr_t alternative (actual value is irrelevant) onStateCreateFunc.emplace(std::bit_cast(kOnStateCreate.data())); @@ -358,7 +358,7 @@ lanes::AllocatorDefinition Universe::resolveAndValidateAllocator(lua_State* cons STACK_CHECK_START_REL(L_, 0); // here, we have a function we can call to obtain an allocator lua_pushcclosure(L_, provideAllocator, 0); // L_: provideAllocator() - luaG_pushstring(L_, hint_); // L_: provideAllocator() "" + luaW_pushstring(L_, hint_); // L_: provideAllocator() "" lua_call(L_, 1, 1); // L_: result // make sure we have a valid AllocatorDefinition on the stack (an error is raised instead if it is not the case) _ret = lanes::AllocatorDefinition::Validated(L_, kIdxTop); @@ -433,7 +433,7 @@ int Universe::UniverseGC(lua_State* const L_) { lua_Duration const _shutdown_timeout{ lua_tonumber(L_, lua_upvalueindex(1)) }; STACK_CHECK_START_ABS(L_, 1); - Universe* const _U{ luaG_tofulluserdata(L_, StackIndex{ 1 }) }; // L_: U + Universe* const _U{ luaW_tofulluserdata(L_, StackIndex{ 1 }) }; // L_: U // attempt to terminate all lanes with increasingly stronger cancel methods bool const _allLanesTerminated{ @@ -456,7 +456,7 @@ int Universe::UniverseGC(lua_State* const L_) if (lua_isnil(L_, kIdxTop)) { lua_pop(L_, 1); // L_: U // no finalizer, or it returned no value: push some default message on the stack, in case it is necessary - luaG_pushstring(L_, "uncooperative lanes detected at shutdown"); // L_: U "msg" + luaW_pushstring(L_, "uncooperative lanes detected at shutdown"); // L_: U "msg" } STACK_CHECK(L_, 2); @@ -466,7 +466,7 @@ int Universe::UniverseGC(lua_State* const L_) bool const _detectedUncooperativeLanes{ _U->selfdestructFirst != SELFDESTRUCT_END }; if (_detectedUncooperativeLanes) { _U->flagDanglingLanes(); - if (luaG_tostring(L_, kIdxTop) == "freeze") { + if (luaW_tostring(L_, kIdxTop) == "freeze") { std::this_thread::sleep_until(std::chrono::time_point::max()); } else { // take the value returned by the finalizer (or our default message) and throw it as an error -- cgit v1.2.3-55-g6feb