mrb_malloc/calloc/realloc should call mrb_garbage_collect before returning NULL

This commit is contained in:
Yukihiro Matsumoto
2012-06-03 17:34:23 +09:00
parent 479df23bc0
commit 597978c169
+11 -5
View File
@@ -121,25 +121,31 @@ gettimeofday_time(void)
#define GC_STEP_SIZE 1024
void*
mrb_realloc(mrb_state *mrb, void *p, size_t len)
{
return (mrb->allocf)(mrb, p, len);
p = (mrb->allocf)(mrb, p, len);
if (!p && len > 0 && mrb->heaps) {
mrb_garbage_collect(mrb);
p = (mrb->allocf)(mrb, p, len);
}
return p;
}
void*
mrb_malloc(mrb_state *mrb, size_t len)
{
return (mrb->allocf)(mrb, 0, len);
return mrb_realloc(mrb, 0, len);
}
void*
mrb_calloc(mrb_state *mrb, size_t nelem, size_t len)
{
void *p = (mrb->allocf)(mrb, 0, nelem*len);
void *p = mrb_realloc(mrb, 0, nelem*len);
memset(p, 0, nelem*len);
if (len > 0)
memset(p, 0, nelem*len);
return p;
}