From 2b205913b8f4aaa812e9838cf9a3188963b11170 Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 16 Sep 2005 13:44:59 +0000 Subject: * gc.c (rb_memerror, ruby_xmalloc, ruby_xrealloc, rb_newobj): just abondon if no memoray available, when interpreter is not running. [ruby-dev:27104] * gc.c (garbage_collect): return whether GC could run. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9183 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 8 +++++++- gc.c | 24 +++++++++++++++--------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0f83e5f98d..4e6085930f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,4 @@ -Fri Sep 16 22:41:18 2005 Nobuyoshi Nakada +Fri Sep 16 22:44:47 2005 Nobuyoshi Nakada * file.c (rb_file_s_extname): empty string for path name ending with a period. fixed: [ruby-core:05651] @@ -6,6 +6,12 @@ Fri Sep 16 22:41:18 2005 Nobuyoshi Nakada * file.c (rb_file_join): smarter behavior at edge cases. fixed: [ruby-core:05706] + * gc.c (rb_memerror, ruby_xmalloc, ruby_xrealloc, rb_newobj): just + abondon if no memoray available, when interpreter is not running. + [ruby-dev:27104] + + * gc.c (garbage_collect): return whether GC could run. + Fri Sep 16 18:34:01 2005 Yukihiro Matsumoto * ext/syck/node.c (syck_replace_str): was using return from the diff --git a/gc.c b/gc.c index c9b670435e..11895c2123 100644 --- a/gc.c +++ b/gc.c @@ -91,14 +91,14 @@ static unsigned long malloc_increase = 0; static unsigned long malloc_limit = GC_MALLOC_LIMIT; static void run_final(VALUE obj); static VALUE nomem_error; -static void garbage_collect(void); +static int garbage_collect(void); void rb_memerror(void) { static int recurse = 0; - if (recurse > 0 && rb_safe_level() < 4) { + if (!nomem_error || (recurse > 0 && rb_safe_level() < 4)) { fprintf(stderr, "[FATAL] failed to allocate memory\n"); exit(1); } @@ -122,8 +122,9 @@ ruby_xmalloc(long size) } RUBY_CRITICAL(mem = malloc(size)); if (!mem) { - garbage_collect(); - RUBY_CRITICAL(mem = malloc(size)); + if (garbage_collect()) { + RUBY_CRITICAL(mem = malloc(size)); + } if (!mem) { rb_memerror(); } @@ -156,8 +157,9 @@ ruby_xrealloc(void *ptr, long size) malloc_increase += size; RUBY_CRITICAL(mem = realloc(ptr, size)); if (!mem) { - garbage_collect(); - RUBY_CRITICAL(mem = realloc(ptr, size)); + if (garbage_collect()) { + RUBY_CRITICAL(mem = realloc(ptr, size)); + } if (!mem) { rb_memerror(); } @@ -372,7 +374,8 @@ rb_newobj(void) { VALUE obj; - if (!freelist) garbage_collect(); + if (!freelist && !garbage_collect()) + rb_memerror(); obj = (VALUE)freelist; freelist = freelist->as.free.next; @@ -1244,7 +1247,7 @@ int rb_setjmp (rb_jmp_buf); #endif /* __human68k__ or DJGPP */ #endif /* __GNUC__ */ -static void +static int garbage_collect(void) { struct gc_list *list; @@ -1252,6 +1255,7 @@ garbage_collect(void) jmp_buf save_regs_gc_mark; SET_STACK_END; + if (!heaps) return Qfalse; #ifdef HAVE_NATIVETHREAD if (!is_ruby_native_thread()) { rb_bug("cross-thread violation on rb_gc()"); @@ -1261,7 +1265,7 @@ garbage_collect(void) if (!freelist) { add_heap(); } - return; + return Qfalse; } if (during_gc) return; during_gc++; @@ -1355,6 +1359,8 @@ garbage_collect(void) } } gc_sweep(); + + return Qtrue; } void -- cgit v1.2.3