Created
April 19, 2009 19:24
-
-
Save methodmissing/98183 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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