diff --git a/include/picrin.h b/include/picrin.h index 189a295b..ba528020 100644 --- a/include/picrin.h +++ b/include/picrin.h @@ -82,6 +82,7 @@ void *pic_alloc(pic_state *, size_t); void *pic_realloc(pic_state *, void *, size_t); void *pic_calloc(pic_state *, unsigned, size_t); struct pic_object *pic_obj_alloc(pic_state *, size_t, enum pic_tt); +struct pic_object *pic_obj_alloc_unsafe(pic_state *, size_t, enum pic_tt); void pic_free(pic_state *, void *); void pic_gc_protect(pic_state *, pic_value); diff --git a/src/gc.c b/src/gc.c index d7b9234b..367fa082 100644 --- a/src/gc.c +++ b/src/gc.c @@ -466,7 +466,7 @@ pic_gc_run(pic_state *pic) } struct pic_object * -pic_obj_alloc(pic_state *pic, size_t size, enum pic_tt tt) +pic_obj_alloc_unsafe(pic_state *pic, size_t size, enum pic_tt tt) { struct pic_object *obj; @@ -483,6 +483,16 @@ pic_obj_alloc(pic_state *pic, size_t size, enum pic_tt tt) } obj->tt = tt; + return obj; +} + +struct pic_object * +pic_obj_alloc(pic_state *pic, size_t size, enum pic_tt tt) +{ + struct pic_object *obj; + + obj = pic_obj_alloc_unsafe(pic, size, tt); + gc_protect(pic, obj); return obj; }