Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adjust interpose_list semantics #4831

Merged
merged 1 commit into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Template for new versions:
- ``Units::getReadableName``: correct display of ghost+curse names w/r/t each other and unit prof, use ``curse.name`` instead of iterating syndrome name effects
- `autodump`: cancel active job on dumped items
- `add-spatter`: fix a crash related to unloading a savegame with add-spatter reactions, then loading a second savegame with add-spatter reactions
- adjust semantics of vmethod interpose maps to avoid inserting null pointers

## Misc Improvements
- `tweak`: improve performance of ``adamantine-cloth-wear`` tweak
Expand Down
14 changes: 8 additions & 6 deletions library/VTableInterpose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ void VMethodInterposeLinkBase::on_host_delete(const virtual_identity *from)
{
// Otherwise, drop the link to that child:
assert(child_hosts.count(from) != 0 &&
from->interpose_list[vmethod_idx] == this);
from->interpose_list[vmethod_idx] == this); // while mutating this gets cleaned up below so machts nichts

// Find and restore the original vmethod ptr
auto last = this;
Expand All @@ -412,7 +412,7 @@ void VMethodInterposeLinkBase::on_host_delete(const virtual_identity *from)

// Unlink the chains
child_hosts.erase(from);
from->interpose_list[vmethod_idx] = NULL;
from->interpose_list.erase(vmethod_idx);
}
}

Expand All @@ -434,8 +434,10 @@ bool VMethodInterposeLinkBase::apply(bool enable)
}

// Retrieve the current vtable entry
VMethodInterposeLinkBase *old_link = host->interpose_list[vmethod_idx];
VMethodInterposeLinkBase *next_link = NULL;
auto l = host->interpose_list.find(vmethod_idx);

VMethodInterposeLinkBase* old_link = (l != host->interpose_list.end()) ? (l->second) : nullptr;
VMethodInterposeLinkBase* next_link = NULL;

while (old_link && old_link->host == host && old_link->priority > priority)
{
Expand Down Expand Up @@ -529,7 +531,7 @@ bool VMethodInterposeLinkBase::apply(bool enable)
for (auto it = child_hosts.begin(); it != child_hosts.end(); ++it)
{
auto nhost = *it;
assert(nhost->interpose_list[vmethod_idx] == old_link);
assert(nhost->interpose_list[vmethod_idx] == old_link); // acceptable due to assign below
nhost->set_vmethod_ptr(patcher, vmethod_idx, interpose_method);
nhost->interpose_list[vmethod_idx] = this;
}
Expand Down Expand Up @@ -586,7 +588,7 @@ void VMethodInterposeLinkBase::remove()
for (auto it = child_hosts.begin(); it != child_hosts.end(); ++it)
{
auto nhost = *it;
assert(nhost->interpose_list[vmethod_idx] == this);
assert(nhost->interpose_list[vmethod_idx] == this); // acceptable due to assign below
nhost->interpose_list[vmethod_idx] = prev;
nhost->set_vmethod_ptr(patcher, vmethod_idx, saved_chain);
if (prev)
Expand Down