From ec0f0d35720399fd6981086125f78e3b6c04a2a1 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Thu, 24 Oct 2013 00:32:03 +0900 Subject: [PATCH] add pic_calloc --- include/picrin.h | 1 + src/gc.c | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/include/picrin.h b/include/picrin.h index 80351abf..30f1a707 100644 --- a/include/picrin.h +++ b/include/picrin.h @@ -54,6 +54,7 @@ typedef pic_value (*pic_func_t)(pic_state *); 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); void pic_free(pic_state *, void *); diff --git a/src/gc.c b/src/gc.c index 53685773..caca103a 100644 --- a/src/gc.c +++ b/src/gc.c @@ -57,6 +57,18 @@ pic_realloc(pic_state *pic, void *ptr, size_t size) return ptr; } +void * +pic_calloc(pic_state *pic, unsigned count, size_t size) +{ + void *ptr; + + ptr = calloc(count ,size); + if (ptr == NULL) { + pic_abort(pic, "memory exhausted"); + } + return ptr; +} + void pic_free(pic_state *pic, void *ptr) {