From b60e4df3d9aef958d5ec4316968ebb3e65bf49a2 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Wed, 16 Oct 2013 11:21:41 +0900 Subject: [PATCH] add pic_realloc --- include/picrin.h | 1 + src/gc.c | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/include/picrin.h b/include/picrin.h index 8b11b64f..80bb4e91 100644 --- a/include/picrin.h +++ b/include/picrin.h @@ -31,6 +31,7 @@ typedef struct { typedef pic_value (*pic_func_t)(pic_state *); void *pic_alloc(pic_state *, size_t); +void *pic_realloc(pic_state *, void *, size_t); struct pic_object *pic_obj_alloc(pic_state *, size_t, enum pic_tt); void pic_free(pic_state *, void *); diff --git a/src/gc.c b/src/gc.c index cf3bd75b..d883d216 100644 --- a/src/gc.c +++ b/src/gc.c @@ -43,6 +43,16 @@ pic_alloc(pic_state *pic, size_t size) return ptr; } +void * +pic_realloc(pic_state *pic, void *ptr, size_t size) +{ + ptr = realloc(ptr, size); + if (ptr == NULL) { + pic_raise(pic, "memory exhausted"); + } + return ptr; +} + void pic_free(pic_state *pic, void *ptr) {