From 99fdafd8c03a7baee265ce3dd22af5b2d02fdeb6 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Tue, 7 Dec 2021 13:40:51 +0100 Subject: vm: introduce value registry Introduce a new, lazily allocated value registry which can be used by C code to store values which should not be garbage collected. The registry is a plain ucode object internally and treated as GC root but not exposed to ucode script code, this allows it to retain references to values which are otherwise completely unreachable from ucode scripts. Signed-off-by: Jo-Philipp Wich --- vm.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'vm.c') diff --git a/vm.c b/vm.c index a1be51b..e21bc4b 100644 --- a/vm.c +++ b/vm.c @@ -2480,3 +2480,34 @@ uc_vm_trace_set(uc_vm_t *vm, uint32_t level) { vm->trace = level; } + +bool +uc_vm_registry_exists(uc_vm_t *vm, const char *key) +{ + bool exists; + + ucv_object_get(vm->registry, key, &exists); + + return exists; +} + +uc_value_t * +uc_vm_registry_get(uc_vm_t *vm, const char *key) +{ + return ucv_object_get(vm->registry, key, NULL); +} + +void +uc_vm_registry_set(uc_vm_t *vm, const char *key, uc_value_t *value) +{ + if (!vm->registry) + vm->registry = ucv_object_new(vm); + + ucv_object_add(vm->registry, key, value); +} + +bool +uc_vm_registry_delete(uc_vm_t *vm, const char *key) +{ + return ucv_object_delete(vm->registry, key); +} -- cgit v1.2.3