refcount: globals, modules and stdlib own their values
Extend the ownership discipline to the VM's global table and the non-container value producers: - cat_vm_set_global_owned: takes ownership of a freshly-created value (used for the native-registered globals and the `module` table). - cat_vm_free releases the saved `module` stack entries and the globals table (which cascades: each stored value drops its reference). - module enter/leave retains the saved `module` while it is off-global. - stdlib/ffi/file build their tables with owned values and drop the transient reference after a store. Suite stays 130 green.
This commit is contained in:
1 parent
ee5861a25c
commit
a73600e221
6 files changed
+73
-29
No files matched your search
@@ -88,6 +88,12 @@ int cat_vm_frame_run(CAT_VM_State *vm, CAT_VM_Frame *f, CAT_VALUE_Value **out);
|
||||
CAT_VALUE_Value *cat_vm_get_global(CAT_VM_State *vm, const char *name);
|
||||
int cat_vm_set_global(CAT_VM_State *vm, const char *name, CAT_VALUE_Value *v);
|
||||
|
||||
/* Like cat_vm_set_global, but the caller hands over its reference: the
|
||||
* globals table takes ownership and the caller's ref is dropped. Use
|
||||
* with an inline-created value. */
|
||||
int cat_vm_set_global_owned(CAT_VM_State *vm, const char *name,
|
||||
CAT_VALUE_Value *v);
|
||||
|
||||
void cat_vm_free(CAT_VM_State *vm);
|
||||
|
||||
#endif /* CAT_VM_H */
|
||||
Reference in new issue
Block a user