From 96240c6d2d09bb186ebfba2f414348663b806010 Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 12 Mar 2008 05:47:10 +0000 Subject: [PATCH] * eval_intern.h (rb_thread_raised_set): use generic flags. * eval.c (rb_longjmp): clear all raised flags. * eval.c (stack_check): leave clearing flag to rb_longjmp. * gc.c (rb_memerror): use thread raised flag instead of static flag. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15756 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 10 ++++++++++ common.mk | 2 +- eval.c | 15 ++++----------- eval_intern.h | 17 +++++++++-------- gc.c | 9 +++++---- 5 files changed, 29 insertions(+), 24 deletions(-) diff --git a/ChangeLog b/ChangeLog index 987ac81d1b..eb2b49c644 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +Wed Mar 12 14:47:07 2008 Nobuyoshi Nakada + + * eval_intern.h (rb_thread_raised_set): use generic flags. + + * eval.c (rb_longjmp): clear all raised flags. + + * eval.c (stack_check): leave clearing flag to rb_longjmp. + + * gc.c (rb_memerror): use thread raised flag instead of static flag. + Tue Mar 11 23:38:39 2008 Yukihiro Matsumoto * array.c (rb_ary_combination): argument check before creating diff --git a/common.mk b/common.mk index 9838fe23ae..cf0055dd0e 100644 --- a/common.mk +++ b/common.mk @@ -473,7 +473,7 @@ gc.$(OBJEXT): {$(VPATH)}gc.c {$(VPATH)}ruby.h {$(VPATH)}config.h \ {$(VPATH)}regex.h {$(VPATH)}oniguruma.h {$(VPATH)}io.h \ {$(VPATH)}encoding.h {$(VPATH)}vm_core.h {$(VPATH)}debug.h \ {$(VPATH)}vm_opts.h {$(VPATH)}id.h {$(VPATH)}thread_$(THREAD_MODEL).h \ - {$(VPATH)}gc.h + {$(VPATH)}gc.h {$(VPATH)}eval_intern.h hash.$(OBJEXT): {$(VPATH)}hash.c {$(VPATH)}ruby.h {$(VPATH)}config.h \ {$(VPATH)}defines.h {$(VPATH)}missing.h {$(VPATH)}intern.h \ {$(VPATH)}st.h {$(VPATH)}util.h {$(VPATH)}signal.h diff --git a/eval.c b/eval.c index 872eb2ccca..69d5488738 100644 --- a/eval.c +++ b/eval.c @@ -715,7 +715,7 @@ rb_longjmp(int tag, VALUE mesg) 0 /* TODO: id */, 0 /* TODO: klass */); } - rb_thread_reset_raised(th); + rb_thread_raised_clear(th); JUMP_TAG(tag); } @@ -1243,16 +1243,9 @@ stack_check(void) { rb_thread_t *th = GET_THREAD(); - if (!rb_thread_stack_overflowing_p(th) && ruby_stack_check()) { - int state; - rb_thread_set_stack_overflow(th); - PUSH_TAG(); - if ((state = EXEC_TAG()) == 0) { - rb_exc_raise(sysstack_error); - } - POP_TAG(); - rb_thread_reset_stack_overflow(th); - JUMP_TAG(state); + if (!rb_thread_raised_p(th, RAISED_STACKOVERFLOW) && ruby_stack_check()) { + rb_thread_raised_set(th, RAISED_STACKOVERFLOW); + rb_exc_raise(sysstack_error); } } diff --git a/eval_intern.h b/eval_intern.h index b5133f0460..0c50331b3e 100644 --- a/eval_intern.h +++ b/eval_intern.h @@ -195,16 +195,17 @@ while (0) void rb_thread_cleanup(void); void rb_thread_wait_other_threads(void); -#define RAISED_EXCEPTION 1 -#define RAISED_STACKOVERFLOW 2 +enum { + RAISED_EXCEPTION = 1, + RAISED_STACKOVERFLOW, + RAISED_NOMEMORY, +}; int rb_thread_set_raised(rb_thread_t *th); int rb_thread_reset_raised(rb_thread_t *th); -#define rb_thread_set_stack_overflow(th) \ - ((th)->raised_flag |= RAISED_STACKOVERFLOW) -#define rb_thread_reset_stack_overflow(th) \ - ((th)->raised_flag &= ~RAISED_STACKOVERFLOW) -#define rb_thread_stack_overflowing_p(th) \ - (((th)->raised_flag & RAISED_STACKOVERFLOW) != 0) +#define rb_thread_raised_set(th, f) ((th)->raised_flag |= (f)) +#define rb_thread_raised_reset(th, f) ((th)->raised_flag &= ~(f)) +#define rb_thread_raised_p(th, f) (((th)->raised_flag & (f)) != 0) +#define rb_thread_raised_clear(th) ((th)->raised_flag = 0) VALUE rb_f_eval(int argc, VALUE *argv, VALUE self); VALUE rb_make_exception(int argc, VALUE *argv); diff --git a/gc.c b/gc.c index 56dbb3efb8..22f2327416 100644 --- a/gc.c +++ b/gc.c @@ -18,6 +18,7 @@ #include "ruby/re.h" #include "ruby/io.h" #include "ruby/util.h" +#include "eval_intern.h" #include "vm_core.h" #include "gc.h" #include @@ -190,13 +191,13 @@ rb_global_variable(VALUE *var) void rb_memerror(void) { - static int recurse = 0; - - if (!nomem_error || (recurse > 0 && rb_safe_level() < 4)) { + rb_thread_t *th = GET_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); } - recurse++; + rb_thread_raised_set(th, RAISED_NOMEMORY); rb_exc_raise(nomem_error); }