From 47528f02e7376f1fbb205c5cf69d17d55619fcb1 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Fri, 12 Aug 2022 00:19:50 +0200 Subject: 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 --- types.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'types.c') 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); -- cgit v1.2.3