From f506eac3ddfcd585e80a267eb222252d5d8f15b5 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Fri, 15 Nov 2013 19:30:53 +0900 Subject: [PATCH] add pic_obj_alloc_unsafe; preparation for yy_arena --- include/picrin.h | 1 + src/gc.c | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) 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; }