diff --git a/include/picrin.h b/include/picrin.h index 6c18fe27..0d250f7b 100644 --- a/include/picrin.h +++ b/include/picrin.h @@ -121,7 +121,7 @@ struct pic_object *pic_obj_alloc_unsafe(pic_state *, size_t, enum pic_tt); void pic_free(pic_state *, void *); void pic_gc_run(pic_state *); -void pic_gc_protect(pic_state *, pic_value); +pic_value pic_gc_protect(pic_state *, pic_value); int pic_gc_arena_preserve(pic_state *); void pic_gc_arena_restore(pic_state *, int); diff --git a/src/gc.c b/src/gc.c index 97b45195..2d42ade6 100644 --- a/src/gc.c +++ b/src/gc.c @@ -183,17 +183,19 @@ gc_protect(pic_state *pic, struct pic_object *obj) pic->arena[pic->arena_idx++] = obj; } -void +pic_value pic_gc_protect(pic_state *pic, pic_value v) { struct pic_object *obj; if (pic_vtype(v) != PIC_VTYPE_HEAP) { - return; + return v; } obj = pic_obj_ptr(v); gc_protect(pic, obj); + + return v; } int