add pic_calloc

This commit is contained in:
Yuichi Nishiwaki 2013-10-24 00:32:03 +09:00
parent 0fd1bbeae9
commit ec0f0d3572
2 changed files with 13 additions and 0 deletions

View File

@ -54,6 +54,7 @@ typedef pic_value (*pic_func_t)(pic_state *);
void *pic_alloc(pic_state *, size_t); void *pic_alloc(pic_state *, size_t);
void *pic_realloc(pic_state *, void *, 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(pic_state *, size_t, enum pic_tt);
void pic_free(pic_state *, void *); void pic_free(pic_state *, void *);

View File

@ -57,6 +57,18 @@ pic_realloc(pic_state *pic, void *ptr, size_t size)
return ptr; 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 void
pic_free(pic_state *pic, void *ptr) pic_free(pic_state *pic, void *ptr)
{ {