diff --git a/include/vm.h b/include/vm.h index 414e956..9a6aa8d 100644 --- a/include/vm.h +++ b/include/vm.h @@ -90,7 +90,7 @@ static inline void stack_push_value(union vm_value v) union vm_value stack_pop(void); union vm_value global_get(int varno); -void global_set(int varno, union vm_value val); +void global_set(int varno, union vm_value val, bool call_dtors); struct page *local_page(void); int vm_string_ref(struct string *s); diff --git a/src/savedata.c b/src/savedata.c index 14e9440..41da0a5 100644 --- a/src/savedata.c +++ b/src/savedata.c @@ -347,7 +347,9 @@ int load_globals(const char *keyname, const char *filename, const char *group_na goto cleanup; } current_global = i; - global_set(i, json_to_vm_value(ain->globals[i].type.data, ain->globals[i].type.struc, ain->globals[i].type.rank, value)); + + bool call_dtors = false; // Destructors for old objects are not called. + global_set(i, json_to_vm_value(ain->globals[i].type.data, ain->globals[i].type.struc, ain->globals[i].type.rank, value), call_dtors); if (n) (*n)++; } diff --git a/src/vm.c b/src/vm.c index be236b9..5bb0474 100644 --- a/src/vm.c +++ b/src/vm.c @@ -134,14 +134,17 @@ union vm_value global_get(int varno) return heap[0].page->values[varno]; } -void global_set(int varno, union vm_value val) +void global_set(int varno, union vm_value val, bool call_dtors) { switch (ain->globals[varno].type.data) { case AIN_STRING: case AIN_STRUCT: case AIN_ARRAY_TYPE: if (heap[0].page->values[varno].i > 0) { - heap_unref(heap[0].page->values[varno].i); + if (call_dtors) + heap_unref(heap[0].page->values[varno].i); + else + exit_unref(heap[0].page->values[varno].i); } default: break;