Skip to content

Commit

Permalink
* gc.c (rb_memerror, ruby_xmalloc, ruby_xrealloc, rb_newobj): just
Browse files Browse the repository at this point in the history
  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
  • Loading branch information
nobu committed Sep 16, 2005
1 parent c8b2171 commit 2b20591
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
8 changes: 7 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
Fri Sep 16 22:41:18 2005 Nobuyoshi Nakada <[email protected]>
Fri Sep 16 22:44:47 2005 Nobuyoshi Nakada <[email protected]>

* file.c (rb_file_s_extname): empty string for path name ending with a
period. fixed: [ruby-core:05651]

* 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 <[email protected]>

* ext/syck/node.c (syck_replace_str): was using return from the
Expand Down
24 changes: 15 additions & 9 deletions gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1244,14 +1247,15 @@ int rb_setjmp (rb_jmp_buf);
#endif /* __human68k__ or DJGPP */
#endif /* __GNUC__ */

static void
static int
garbage_collect(void)
{
struct gc_list *list;
struct FRAME * volatile frame; /* gcc 2.7.2.3 -O2 bug?? */
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()");
Expand All @@ -1261,7 +1265,7 @@ garbage_collect(void)
if (!freelist) {
add_heap();
}
return;
return Qfalse;
}
if (during_gc) return;
during_gc++;
Expand Down Expand Up @@ -1355,6 +1359,8 @@ garbage_collect(void)
}
}
gc_sweep();

return Qtrue;
}

void
Expand Down

0 comments on commit 2b20591

Please sign in to comment.