add mrb_malloc_simple() that returns NULL on error

This commit is contained in:
Yukihiro "Matz" Matsumoto
2013-06-25 15:38:28 +09:00
parent d90c5c8e84
commit 3ceeb0be95
2 changed files with 17 additions and 3 deletions
+13
View File
@@ -182,6 +182,19 @@ mrb_malloc(mrb_state *mrb, size_t len)
return mrb_realloc(mrb, 0, len);
}
void*
mrb_malloc_simple(mrb_state *mrb, size_t len)
{
void *p2;
p2 = (mrb->allocf)(mrb, 0, len, mrb->ud);
if (!p2 && len > 0 && mrb->heaps) {
mrb_garbage_collect(mrb);
p2 = (mrb->allocf)(mrb, 0, len, mrb->ud);
}
return p2;
}
void*
mrb_calloc(mrb_state *mrb, size_t nelem, size_t len)
{