summaryrefslogtreecommitdiffhomepage
path: root/types.c
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2022-08-12 00:19:50 +0200
committerJo-Philipp Wich <jo@mein.io>2022-08-12 01:03:00 +0200
commit47528f02e7376f1fbb205c5cf69d17d55619fcb1 (patch)
tree4a6255f3c741cbcbb33b42605177e200122e1ff2 /types.c
parent381cc7508f797e5158bbd1620d6154ef4a11b76c (diff)
vm: support automatic periodic GC runs
Introduce two new VM api functions uc_vm_gc_start() and uc_vm_gc_stop() which allow starting and stopping automatic periodic garbage collection of cyclic objects in the VM context. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'types.c')
-rw-r--r--types.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/types.c b/types.c
index 983bda3..e05d685 100644
--- a/types.c
+++ b/types.c
@@ -705,8 +705,10 @@ ucv_array_new_length(uc_vm_t *vm, size_t length)
uc_vector_grow(array);
- if (vm)
+ if (vm) {
ucv_ref(&vm->values, &array->ref);
+ vm->alloc_refs++;
+ }
return &array->header;
}
@@ -901,8 +903,10 @@ ucv_object_new(uc_vm_t *vm)
object->header.refcount = 1;
object->table = table;
- if (vm)
+ if (vm) {
ucv_ref(&vm->values, &object->ref);
+ vm->alloc_refs++;
+ }
return &object->header;
}
@@ -1022,8 +1026,10 @@ ucv_closure_new(uc_vm_t *vm, uc_function_t *function, bool arrow_fn)
closure->is_arrow = arrow_fn;
closure->upvals = function->nupvals ? (uc_upvalref_t **)((uintptr_t)closure + ALIGN(sizeof(*closure))) : NULL;
- if (vm)
+ if (vm) {
ucv_ref(&vm->values, &closure->ref);
+ vm->alloc_refs++;
+ }
uc_program_get(function->program);