Skip to content

Instantly share code, notes, and snippets.

@methodmissing
Created April 19, 2009 19:24
Show Gist options
  • Select an option

  • Save methodmissing/98183 to your computer and use it in GitHub Desktop.

Select an option

Save methodmissing/98183 to your computer and use it in GitHub Desktop.
void
rb_memerror()
{
rb_thread_t th = rb_curr_thread;
if (!nomem_error ||
(rb_thread_raised_p(th, RAISED_NOMEMORY) && rb_safe_level() < 4)) {
fprintf(stderr, "[FATAL] failed to allocate memory\n");
exit(1);
}
if (rb_thread_raised_p(th, RAISED_NOMEMORY)) {
rb_exc_jump(nomem_error);
}
rb_thread_raised_set(th, RAISED_NOMEMORY);
rb_exc_raise(nomem_error);
}
void *
ruby_xmalloc(size)
long size;
{
void *mem;
if (size < 0) {
rb_raise(rb_eNoMemError, "negative allocation size (or too big)");
}
if (size == 0) size = 1;
if ((malloc_increase+size) > malloc_limit) {
garbage_collect();
}
RUBY_CRITICAL(mem = malloc(size));
if (!mem) {
garbage_collect();
RUBY_CRITICAL(mem = malloc(size));
if (!mem) {
rb_memerror();
}
}
malloc_increase += size;
return mem;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment