Replace c style linked lists - #1
Merged
Merged
Conversation
Replaced all intrusive doubly-linked list infrastructure with C++ STL
containers across the entire codebase (~150 files, -2185 net lines).
Removed macros:
- LINK, LINK1, INSERT, UNLINK, CHECK_LINKS, FOREACH, FOREACHR
Struct changes (~95 header files):
- Removed next/prev pointers from all structs (char_data, obj_data,
room_index_data, ship_data, space_data, planet_data, clan_data,
descriptor_data, and ~85 others)
- Converted first_/last_ pointer pairs to std::list<T*> members
(e.g. ch->first_carrying/last_carrying -> ch->carrying)
- MPROG_DATA lost its next pointer; mudprogs field is now
std::list<MPROG_DATA*> on mob/obj/room index data
- LCNV_DATA lost next/prev; LANG_DATA converted to std::list<LCNV_DATA*>
Global list changes (mud.h + definition files):
- 44 extern first_/last_ pointer pairs replaced with std::list<T*> globals
(e.g. first_char/last_char -> char_list)
- 3 hash tables converted to std::forward_list<T*> arrays
(mob_index_hash, obj_index_hash, room_index_hash)
- Local vroom_hash in act_move.cpp also converted to std::forward_list
- Extracted object/char queues converted to std::list
- ILD_CREATE/ILD_FREE/ILIST macros in swxml.h rewritten for std::list
Code conversion patterns applied across ~50 .cpp files:
- FOREACH(var, first_X) -> for (auto* var : X_list)
- LINK(item, first, last, next, prev) -> list.push_back(item)
- UNLINK(item, first, last, next, prev) -> list.remove(item)
- Raw for (x = first_X; x; x = x->next) -> range-based for
- Drain loops -> while(!list.empty()) { list.front(); list.remove(); }
- Reverse iteration (gch_prev/gobj_prev) -> snapshot reverse iteration
- Safe modification during iteration -> snapshot copy pattern
- Indexed access -> std::advance with iterators
- Hash bucket removal (foldarea) -> forward_list::remove_if with lambdas
- OLC prev/next navigation -> std::find + std::prev/std::next
- Mudprog chain operations (count/delete/copy/edit) -> std::list iterators
Memory management preserved:
- std::list<T*> is non-owning; existing DISPOSE/free_* calls unchanged
- No ownership semantics changed; no memory leaks introduced
Also added:
- .github/workflows/compile_and_link.yml: CI build on ubuntu-latest
The previous commit (0ee4564) replaced C-style intrusive linked lists with std::list/std::forward_list but left numerous compilation errors, warnings, and API mismatches. This commit fixes all of them: Struct/member conflicts: - Rename ship_data::cargo list to cargo_list (conflicts with int cargo) - Rename pc_data::fevents list to fevents_list (conflicts with int fevents) - Convert warehouse_data first_cargo/last_cargo to std::list<CARGO_DATA*> - Restore mob_prog_act_list::next pointer (still used via mpact) API and signature fixes: - Rewrite swpqxx.h for pqxx7 string_traits API (string_view-based) - Remove connection::disconnect() call (handled by pqxx destructor) - Update fun_decls.h signatures for std::list parameters (get_extra_descr, show_list_to_char, count_obj_list) - Remove redundant atoi declarations conflicting with system headers - Rename __itoa to sw_itoa (avoids macOS reserved symbol clash) C++20 upgrade: - Bump -std=c++17 to -std=c++20 (needed for std::ranges::reverse_view) - Qualify ::format_string to avoid ambiguity with std::format_string - Remove set_unexpected() call (removed in C++17) Linked list iteration rewrites: - Rewrite mob_act_list loop in update.cpp for std::list - Use forward_list::erase_after with before_begin in db.cpp delete_room - Use std::advance for index-based list access in dialogs.cpp - Replace first_script_prog traversal with script_prog_list iteration - Fix mudprogs pointer-vs-list mismatches in mud_comm.cpp, olc_misc.cpp - Fix ILD_CREATE macro call in olc_misc.cpp Bug fixes: - Fix UNclan->member_list typo in clans.cpp (was operating on wrong clan) - Fix UNship-> typos in space.cpp (3 occurrences) - Add missing bool found declaration in bounty.cpp - Fix const.cpp initializer lists for removed next/prev pointers - Add SWInt.h/SWInt64.h includes to SWDbArray.h ISO-8859-2 encoding preservation: - Replace UTF-8 corrupted Polish character literals with \xNN hex escapes - Use string literal concatenation where hex-valid chars follow escapes - Fixed across ~15 files: act_wiz, ciapek, comm, interp, db, flags, SWDate, SWPazaak, pazaak, stock_market, and others Unused variable cleanup (~665 warnings): - Remove unused _next snapshot variables from list conversion - Remove shadowed and genuinely unused local variables - Verified each removal across ~45 files
Range-for loop variable shadowing (~20 instances across 15 files): The std::list conversion introduced range-for loops like `for (auto* x : list)` that shadowed outer variables of the same name. Unlike the old C-style `for (x = first; x; x = x->next)` which set x to NULL on completion, range-for scopes the variable to the loop body, leaving the outer variable uninitialized. Fix: initialize outer variable to nullptr, rename loop variable, assign outer on match before break. - act_info.cpp: obj2, mob - act_wiz.cpp: victim, d (in fquit and destroy) - boards.cpp: pnote, board (in bset and bstat) - clans.cpp: politics - misc.cpp: obj (do_drink), mob (do_train) - olc_misc.cpp: tarea (find_area), ed (oedit and redit) - quest.cpp: pQuest - skills.cpp: obj (detrap, search), pobj, wobj (poison_weapon) - swskills.cpp: obj - update.cpp: inf, owner Bug fixes found via warnings: - space.cpp: for loop missing braces - only first of four conditions (pilot) was inside the loop; copilot/owner/engineer checks used the loop variable after it went out of scope - SWFake.h: setDesc() self-assigned `this->desc = desc` instead of using parameter `Desc` (capital D) - handler.cpp: `first` variable uninitialized when AFF_POISON check was false; initialized to true - skills.cpp: ambiguous operator precedence `&& ... || ...` in search function; added explicit parentheses Unused variable removal: - fight.cpp: cnt (set but never read in death handler) - shops.cpp: oref (incremented but never read in do_list) - clans.cpp: pCount (incremented but never read in do_capture) Type and qualifier fixes: - act_info.cpp: explicit (int) cast for CHANNEL_OLCTALK (BV31 is int64, bit variable is int; bit pattern is preserved) - crimes.cpp: `const SPEC_FUN*` -> `SPEC_FUN* const` (const on function type has no effect; intent was const pointer) - force.cpp: fevent_trigger parameter changed from fe_trigger to int to fix undefined behavior with va_start on promoted enum type - SWDataBase.cpp: cast nodiscard column_number() result to (void) Warning suppression cleanup: - save.cpp: convert #warning directives to /* TODO */ comments - string.cpp: wrap GCC-specific -Wstringop-truncation pragma in #if defined(__GNUC__) && !defined(__clang__) - act_info.cpp, act_wiz.cpp, crimes.cpp: remove extraneous outer parentheses in equality comparisons
- misc.cpp: fix NULL dereference in pullorpush() — to_room->people was used but to_room is only set in an early-return path; replaced with pexit->to_room->people (the room on the other side of the exit) - update.cpp: initialize owner and found in update_rat() to fix -Wmaybe-uninitialized
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.