Skip to content

Commit

Permalink
Merge pull request #4831 from ab9rf/virtual_identity
Browse files Browse the repository at this point in the history
adjust `interpose_list` semantics
  • Loading branch information
myk002 authored Aug 2, 2024
2 parents fd85cb3 + eeb7c4b commit 400813b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
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

0 comments on commit 400813b

Please sign in to comment.