From 53eef99942ecca7b1dc43ec6b35d09a5fe6b1b1b Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Tue, 14 May 2024 16:19:54 +0200 Subject: Progressively applying the coding rules --- src/intercopycontext.cpp | 12 ++++++------ src/lane.cpp | 6 +++--- src/lanes.cpp | 12 ++++++------ src/state.cpp | 4 ++-- src/tools.cpp | 12 ++++++------ 5 files changed, 23 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/intercopycontext.cpp b/src/intercopycontext.cpp index 8dd914c..6e5d1d8 100644 --- a/src/intercopycontext.cpp +++ b/src/intercopycontext.cpp @@ -96,8 +96,8 @@ THE SOFTWARE. lua_rawget(L_, -2); // L_: ... v ... {} "f.q.n" } char const* _fqn{ lua_tolstring(L_, -1, len_) }; - DEBUGSPEW_CODE(Universe* const U = universe_get(L_)); - DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "function [C] %s \n" INDENT_END(U), _fqn)); + DEBUGSPEW_CODE(Universe* const _U = universe_get(L_)); + DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "function [C] %s \n" INDENT_END(_U), _fqn)); // popping doesn't invalidate the pointer since this is an interned string gotten from the lookup database lua_pop(L_, (mode_ == LookupMode::FromKeeper) ? 1 : 2); // L_: ... v ... STACK_CHECK(L_, 0); @@ -878,7 +878,7 @@ void InterCopyContext::inter_copy_keyvaluepair() const lua_call(L2, 3, 0); // L2: ... u } else { // regular function DEBUGSPEW_CODE(fprintf(stderr, "FUNCTION %s\n", name)); - DEBUGSPEW_CODE(DebugSpewIndentScope scope{ U }); + DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ U }); copy_cached_func(); // L2: ... f } STACK_CHECK(L2, 1); @@ -1080,7 +1080,7 @@ static char const* vt_names[] = { STACK_CHECK_START_REL(L2, 0); DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "inter_copy_one()\n" INDENT_END(U))); - DEBUGSPEW_CODE(DebugSpewIndentScope scope{ U }); + DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ U }); LuaType _val_type{ lua_type_as_enum(L1, L1_i) }; DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "%s %s: " INDENT_END(U), lua_type_names[static_cast(_val_type)], vt_names[static_cast(vt)])); @@ -1205,7 +1205,7 @@ static char const* vt_names[] = { lua_pop(L1, 1); } else { { - DEBUGSPEW_CODE(DebugSpewIndentScope scope{ U }); + DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ U }); _result = inter_move(1); // moves the entry to L2 STACK_CHECK(L1, 0); } @@ -1235,7 +1235,7 @@ static char const* vt_names[] = { LUA_ASSERT(L1, vt == VT::NORMAL); DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "InterCopyContext::inter_copy()\n" INDENT_END(U))); - DEBUGSPEW_CODE(DebugSpewIndentScope scope{ U }); + DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ U }); int const _top_L1{ lua_gettop(L1) }; if (n_ > _top_L1) { diff --git a/src/lane.cpp b/src/lane.cpp index a03412d..bc82291 100644 --- a/src/lane.cpp +++ b/src/lane.cpp @@ -630,7 +630,7 @@ static void lane_main(Lane* lane_) if (lane_->status == Lane::Pending) { // nothing wrong happened during preparation, we can work // At this point, the lane function and arguments are on the stack int const nargs{ lua_gettop(_L) - 1 }; - DEBUGSPEW_CODE(Universe* U = universe_get(_L)); + DEBUGSPEW_CODE(Universe* _U = universe_get(_L)); lane_->status = Lane::Running; // Pending -> Running // Tie "set_finalizer()" to the state @@ -670,11 +670,11 @@ static void lane_main(Lane* lane_) // in case of error and if it exists, fetch stack trace from registry and push it push_stack_trace(_L, _rc, 1); // L: retvals|error [trace] - DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "Lane %p body: %s (%s)\n" INDENT_END(U), _L, get_errcode_name(_rc), kCancelError.equals(_L, 1) ? "cancelled" : lua_typename(_L, lua_type(_L, 1)))); + DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "Lane %p body: %s (%s)\n" INDENT_END(_U), _L, get_errcode_name(_rc), kCancelError.equals(_L, 1) ? "cancelled" : lua_typename(_L, lua_type(_L, 1)))); // Call finalizers, if the script has set them up. // int _rc2{ run_finalizers(_L, _rc) }; - DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "Lane %p finalizer: %s\n" INDENT_END(U), _L, get_errcode_name(_rc2))); + DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "Lane %p finalizer: %s\n" INDENT_END(_U), _L, get_errcode_name(_rc2))); if (_rc2 != LUA_OK) { // Error within a finalizer! // the finalizer generated an error, and left its own error message [and stack trace] on the stack _rc = _rc2; // we're overruling the earlier script error or normal return diff --git a/src/lanes.cpp b/src/lanes.cpp index a775895..6a84422 100644 --- a/src/lanes.cpp +++ b/src/lanes.cpp @@ -193,12 +193,12 @@ LUAG_FUNC(register) // ignore extra parameters, just in case lua_settop(L_, 2); luaL_argcheck(L_, (_mod_type == LuaType::TABLE) || (_mod_type == LuaType::FUNCTION), 2, "unexpected module type"); - DEBUGSPEW_CODE(Universe* U = universe_get(L_)); + DEBUGSPEW_CODE(Universe* _U = universe_get(L_)); STACK_CHECK_START_REL(L_, 0); // "name" mod_table - DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "lanes.register %s BEGIN\n" INDENT_END(U), _name)); - DEBUGSPEW_CODE(DebugSpewIndentScope scope{ U }); + DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "lanes.register %s BEGIN\n" INDENT_END(_U), _name)); + DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ _U }); populate_func_lookup_table(L_, -1, _name); - DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "lanes.register %s END\n" INDENT_END(U), _name)); + DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "lanes.register %s END\n" INDENT_END(_U), _name)); STACK_CHECK(L_, 0); return 0; } @@ -375,7 +375,7 @@ LUAG_FUNC(lane_new) if (_required_idx != 0) { int _nbRequired{ 1 }; DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "lane_new: require 'required' list\n" INDENT_END(_U))); - DEBUGSPEW_CODE(DebugSpewIndentScope scope{ _U }); + DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ _U }); // should not happen, was checked in lanes.lua before calling lane_new() if (lua_type(L_, _required_idx) != LUA_TTABLE) { raise_luaL_error(L_, "expected required module list as a table, got %s", luaL_typename(L_, _required_idx)); @@ -701,7 +701,7 @@ LUAG_FUNC(configure) STACK_CHECK_START_ABS(L_, 1); // L_: settings DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "%p: lanes.configure() BEGIN\n" INDENT_END(_U), L_)); - DEBUGSPEW_CODE(DebugSpewIndentScope scope{ _U }); + DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ _U }); if (_U == nullptr) { _U = universe_create(L_); // L_: settings universe diff --git a/src/state.cpp b/src/state.cpp index 7309e50..56ac74b 100644 --- a/src/state.cpp +++ b/src/state.cpp @@ -339,7 +339,7 @@ lua_State* luaG_newstate(Universe* U_, SourceState from_, char const* libs_) } DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "luaG_newstate()\n" INDENT_END(U_))); - DEBUGSPEW_CODE(DebugSpewIndentScope scope{ U_ }); + DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ U_ }); // copy settings (for example because it may contain a Lua on_state_create function) copy_one_time_settings(U_, from_, _L); @@ -361,7 +361,7 @@ lua_State* luaG_newstate(Universe* U_, SourceState from_, char const* libs_) DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "opening base library\n" INDENT_END(U_))); #if LUA_VERSION_NUM >= 502 // open base library the same way as in luaL_openlibs() - luaL_requiref(_L, "_G", luaopen_base, 1); + luaL_requiref(_L, LUA_GNAME, luaopen_base, 1); lua_pop(_L, 1); #else // LUA_VERSION_NUM lua_pushcfunction(_L, luaopen_base); diff --git a/src/tools.cpp b/src/tools.cpp index 0cfe1ab..a70fdc9 100644 --- a/src/tools.cpp +++ b/src/tools.cpp @@ -130,7 +130,7 @@ static void update_lookup_entry(DEBUGSPEW_PARAM_COMMA(Universe* U_) lua_State* L DEBUGSPEW_CODE(char const* _newName); DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "update_lookup_entry()\n" INDENT_END(U_))); - DEBUGSPEW_CODE(DebugSpewIndentScope scope{ U_ }); + DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ U_ }); STACK_CHECK_START_REL(L_, 0); // first, raise an error if the function is already known @@ -198,7 +198,7 @@ static void populate_func_lookup_table_recur(DEBUGSPEW_PARAM_COMMA(Universe* U_) // slot dbIdx_ + 2 contains a cache that stores all already visited tables to avoid infinite recursion loops int const _cache{ dbIdx_ + 2 }; DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "populate_func_lookup_table_recur()\n" INDENT_END(U_))); - DEBUGSPEW_CODE(DebugSpewIndentScope scope{ U_ }); + DEBUGSPEW_CODE(DebugSpewIndentScope _scope{ U_ }); STACK_GROW(L_, 6); // slot i_ contains a table where we search for functions (or a full userdata with a metatable) @@ -264,9 +264,9 @@ static void populate_func_lookup_table_recur(DEBUGSPEW_PARAM_COMMA(Universe* U_) ++depth_; lua_pushnil(L_); // L_: ... {i_} {bfc} nil while (lua_next(L_, breadthFirstCache) != 0) { // L_: ... {i_} {bfc} k {} - DEBUGSPEW_CODE(char const* key = (lua_type(L_, -2) == LUA_TSTRING) ? lua_tostring(L_, -2) : "not a string"); - DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "table '%s'\n" INDENT_END(U_), key)); - DEBUGSPEW_CODE(DebugSpewIndentScope scope2{ U_ }); + DEBUGSPEW_CODE(char const* _key = (lua_type(L_, -2) == LUA_TSTRING) ? lua_tostring(L_, -2) : "not a string"); + DEBUGSPEW_CODE(fprintf(stderr, INDENT_BEGIN "table '%s'\n" INDENT_END(U_), _key)); + DEBUGSPEW_CODE(DebugSpewIndentScope _scope2{ U_ }); // un-visit this table in case we do need to process it lua_pushvalue(L_, -1); // L_: ... {i_} {bfc} k {} {} lua_rawget(L_, _cache); // L_: ... {i_} {bfc} k {} n @@ -505,7 +505,7 @@ int luaG_nameof(lua_State* L_) // push a table whose contents are strings that, when concatenated, produce unique name lua_newtable(L_); // L_: o nil {c} {fqn} // {fqn}[1] = "_G" - lua_pushliteral(L_, "_G"); // L_: o nil {c} {fqn} "_G" + lua_pushliteral(L_, LUA_GNAME); // L_: o nil {c} {fqn} "_G" lua_rawseti(L_, -2, 1); // L_: o nil {c} {fqn} // this is where we start the search lua_pushglobaltable(L_); // L_: o nil {c} {fqn} _G -- cgit v1.2.3-55-g6feb