ext/jsonnet/vm.c in jsonnet-0.5.2 vs ext/jsonnet/vm.c in jsonnet-0.5.3

- old
+ new

@@ -57,20 +57,19 @@ return vm; } static VALUE -vm_s_new(int argc, const VALUE *argv, VALUE klass) +vm_s_allocate(VALUE klass) { struct jsonnet_vm_wrap *vm; - VALUE self = TypedData_Make_Struct(cVM, struct jsonnet_vm_wrap, &jsonnet_vm_type, vm); + VALUE self = TypedData_Make_Struct(klass, struct jsonnet_vm_wrap, &jsonnet_vm_type, vm); vm->vm = jsonnet_make(); vm->import_callback = Qnil; vm->native_callbacks.len = 0; vm->native_callbacks.contexts = NULL; - rb_obj_call_init(self, argc, argv); return self; } static void vm_free(void *ptr) @@ -79,15 +78,14 @@ struct jsonnet_vm_wrap *vm = (struct jsonnet_vm_wrap *)ptr; jsonnet_destroy(vm->vm); for (i = 0; i < vm->native_callbacks.len; ++i) { struct native_callback_ctx *ctx = vm->native_callbacks.contexts[i]; - RB_REALLOC_N(ctx, struct native_callback_ctx, 0); + xfree(ctx); } - RB_REALLOC_N(vm->native_callbacks.contexts, struct native_callback_ctx *, 0); - - RB_REALLOC_N(vm, struct jsonnet_vm_wrap, 0); + xfree(vm->native_callbacks.contexts); + xfree(vm); } static void vm_mark(void *ptr) { @@ -388,10 +386,10 @@ void rubyjsonnet_init_vm(VALUE mJsonnet) { cVM = rb_define_class_under(mJsonnet, "VM", rb_cObject); - rb_define_singleton_method(cVM, "new", vm_s_new, -1); + rb_define_alloc_func(cVM, vm_s_allocate); rb_define_private_method(cVM, "eval_file", vm_evaluate_file, 3); rb_define_private_method(cVM, "eval_snippet", vm_evaluate, 3); rb_define_private_method(cVM, "fmt_file", vm_fmt_file, 2); rb_define_private_method(cVM, "fmt_snippet", vm_fmt_snippet, 2); rb_define_method(cVM, "ext_var", vm_ext_var, 2);