Merge pull request #18 from kichikuou/GlobalLoad

system.GlobalLoad() should not call destructors
This commit is contained in:
Nunuhara Cabbage
2021-03-07 09:17:33 -08:00
committed by GitHub
3 changed files with 9 additions and 4 deletions
+1 -1
View File
@@ -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);
+3 -1
View File
@@ -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)++;
}
+5 -2
View File
@@ -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;