Browse Source

Add cleanup for `UnflectApi`

develop
Anton Tarasenko 2 years ago
parent
commit
70c41a5926
  1. 22
      sources/BaseAPI/API/Unflect/UnflectApi.uc
  2. 5
      sources/BaseAPI/Global.uc

22
sources/BaseAPI/API/Unflect/UnflectApi.uc

@ -50,6 +50,7 @@ protected function Constructor() {
}
protected function Finalizer() {
_drop();
_.memory.Free(completedReplacements);
_.memory.Free(originalScriptCodes);
completedReplacements = none;
@ -57,6 +58,26 @@ protected function Finalizer() {
functionCaster = none;
}
public final function bool _drop() {
local UFunction nextFunctionInstance;
local Text nextFunctionName;
local HashTableIterator iter;
local ByteArrayBox nextSources;
// Drop is called when Acedia is shutting down, so releasing references isn't necessary
iter = HashTableIterator(completedReplacements.Iterate());
while (!iter.HasFinished()) {
nextFunctionName = Text(iter.GetKey());
nextSources = ByteArrayBox(originalScriptCodes.GetItem(nextFunctionName));
if (nextSources != none ) {
nextFunctionInstance = FindFunction(nextFunctionName);
}
if (nextFunctionInstance != none) {
nextFunctionInstance.script = nextSources.Get();
}
}
}
/// Reverts the replacement of the function's code, restoring its original behavior.
///
/// The function to be reverted should be specified using its full path, in the format
@ -306,7 +327,6 @@ private final function bool _replaceFunction(Text oldFunctionLowerCase, Text new
_.memory.Free(initialCode);
}
replace.script = with.script;
Log("TRULLY!" @ replace @ with);
return true;
}

5
sources/BaseAPI/Global.uc

@ -104,10 +104,14 @@ protected function Initialize() {
/// Drops references to all API from base realm, including self-reference, previously returned by
/// [`Global::GetInstance()`] method.
public function DropCoreAPI() {
unflect._drop();
memory = none;
unflect = none;
sideEffects = none;
ref = none;
box = none;
text = none;
math = none;
collections = none;
logger = none;
alias = none;
@ -120,6 +124,7 @@ public function DropCoreAPI() {
scheduler = none;
commands = none;
avarice = none;
environment = none;
default.myself = none;
}

Loading…
Cancel
Save