Skip to content

Commit

Permalink
fix(zscript): object fields not being available in dtor
Browse files Browse the repository at this point in the history
This regressed because of the recent GC changes.
  • Loading branch information
connorjclark committed Apr 24, 2024
1 parent c58661f commit 7feb9af
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 19 deletions.
8 changes: 0 additions & 8 deletions src/user_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ void user_object::save_arrays(std::map<int32_t,ZScriptArray>& arrs)
void user_object::clear_nodestruct()
{
disown();
// TODO: move to dtor
if(data.size() > owned_vars) //owns arrays!
{
for(auto ind = owned_vars; ind < data.size(); ++ind)
Expand All @@ -208,10 +207,3 @@ void user_object::clear_nodestruct()
owned_vars = 0;
destruct.clear();
}

user_object::~user_object()
{
if (fake) return;
destruct.execute();
clear_nodestruct();
}
1 change: 0 additions & 1 deletion src/user_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ struct user_object : public user_abstract_obj

#ifdef IS_PLAYER
void clear_nodestruct();
~user_object();
#endif
};
struct saved_user_object
Expand Down
3 changes: 3 additions & 0 deletions src/zc/ffscript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@ static void delete_script_object(uint32_t id)
if (usr_object->isMemberObjectType(i))
script_object_ref_dec(usr_object->data[i]);
}

usr_object->destruct.execute();
usr_object->clear_nodestruct();
}

util::remove_if_exists(script_object_ids_by_type[object->type], id);
Expand Down
4 changes: 2 additions & 2 deletions tests/replays/playground.qst
Git LFS file not shown
4 changes: 2 additions & 2 deletions tests/replays/playground_classes.zplay
Git LFS file not shown
2 changes: 1 addition & 1 deletion tests/scripts/classes.zs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Car

~Car()
{
Trace(-1);
Trace(-speed);
}
}

Expand Down
6 changes: 4 additions & 2 deletions tests/scripts/classes_expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Compile finished with exit code '0' (success)
{
"currentFileSymbols": 10,
"symbols": 8,
"identifiers": 13
"identifiers": 14
}
PUSHR REFFFC; void run() Body Start
PUSHARGSV 0 0.0003
Expand Down Expand Up @@ -77,7 +77,9 @@ POP CLASS_THISKEY
RETURNFUNC; Func[Car Car::Car(int)] Body End
STARTDESTRUCTOR "Car"; Func[void ~Car::Car()] Body Start
SETR D4 SP2
TRACEV -1; InlineFunc[void Trace(untyped)] Params AND InlineFunc[void Trace(untyped)] Body
ZCLASS_READ CLASS_THISKEY 0; InlineFunc[void Trace(untyped)] Params Start
SUBV2 0 D2; InlineFunc[void Trace(untyped)] Params End
TRACER D2; InlineFunc[void Trace(untyped)] Body
RETURNFUNC; Func[void ~Car::Car()] Body End


Expand Down
4 changes: 2 additions & 2 deletions tests/snapshots/jit/playground/zasm-ffc-10-Classes.txt
Git LFS file not shown
2 changes: 1 addition & 1 deletion tests/snapshots/optimize_zasm/playground.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ Finished optimizing scripts:
[propagate_values] saved 254 instr (1.2%)
[unreachable_blocks_2] saved 42 instr (0.2%)
[dead_code] saved 379 instr (1.8%)
[total] saved 2595 instr (12.4%)
[total] saved 2595 instr (12.3%)

0 comments on commit 7feb9af

Please sign in to comment.