ext/jsonnet/jsonnet.c in jsonnet-0.0.2 vs ext/jsonnet/jsonnet.c in jsonnet-0.1.0
- old
+ new
@@ -22,15 +22,16 @@
struct JsonnetVm *vm;
VALUE callback;
};
static void vm_free(void *ptr);
+static void vm_mark(void *ptr);
static const rb_data_type_t jsonnet_vm_type = {
"JsonnetVm",
{
- /* dmark = */ 0,
+ /* dmark = */ vm_mark,
/* dfree = */ vm_free,
/* dsize = */ 0,
},
/* parent = */ 0,
/* data = */ 0,
@@ -133,22 +134,31 @@
{
return rb_usascii_str_new_cstr(jsonnet_version());
}
static VALUE
-vm_s_new(VALUE mod) {
+vm_s_new(VALUE mod)
+{
struct jsonnet_vm_wrap *vm;
VALUE self = TypedData_Make_Struct(cVM, struct jsonnet_vm_wrap, &jsonnet_vm_type, vm);
vm->vm = jsonnet_make();
vm->callback = Qnil;
return self;
}
static void
-vm_free(void *ptr) {
+vm_free(void *ptr)
+{
struct jsonnet_vm_wrap *vm = (struct jsonnet_vm_wrap*)ptr;
jsonnet_destroy(vm->vm);
REALLOC_N(vm, struct jsonnet_vm_wrap, 0);
+}
+
+static void
+vm_mark(void *ptr)
+{
+ struct jsonnet_vm_wrap *vm = (struct jsonnet_vm_wrap*)ptr;
+ rb_gc_mark(vm->callback);
}
static VALUE
vm_evaluate_file(VALUE self, VALUE fname, VALUE encoding, VALUE multi_p)
{