diff --git a/ChangeLog b/ChangeLog index 744f7a36fb..3e27c12dad 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +Sun Jun 15 18:17:03 2008 Nobuyoshi Nakada + + * vm_core.h (rb_vm_t), vm.c (rb_vm_mark): moved preallocated special + exceptions. + + * eval.c (Init_eval), gc.c (Init_GC), proc.c (Init_Proc): freeze + preallocated special exceptions. + + * eval.c (rb_longjmp): duplicate the thrown exception to set backtrace + if it was frozen. + + * gc.c (rb_memerror): raise nomem_error without backtrace if failed to + make backtrace. + Sat Jun 14 22:52:35 2008 Nobuyoshi Nakada * ext/stringio/stringio.c (strio_sysread): should not raise at empty diff --git a/eval.c b/eval.c index bb1e43bb73..f6424372f7 100644 --- a/eval.c +++ b/eval.c @@ -20,9 +20,8 @@ NORETURN(void rb_raise_jump(VALUE)); ID rb_frame_callee(void); VALUE rb_eLocalJumpError; VALUE rb_eSysStackError; -VALUE sysstack_error; -static VALUE exception_error; +#define exception_error GET_VM()->special_exceptions[ruby_error_reenter] #include "eval_error.c" #include "eval_safe.c" @@ -372,6 +371,9 @@ rb_longjmp(int tag, VALUE mesg) at = get_backtrace(mesg); if (NIL_P(at)) { at = rb_make_backtrace(); + if (OBJ_FROZEN(mesg)) { + mesg = rb_obj_dup(mesg); + } set_backtrace(mesg, at); } } @@ -1198,7 +1200,8 @@ Init_eval(void) exception_error = rb_exc_new2(rb_eFatal, "exception reentered"); rb_ivar_set(exception_error, idThrowState, INT2FIX(TAG_FATAL)); - rb_register_mark_object(exception_error); + OBJ_TAINT(exception_error); + OBJ_FREEZE(exception_error); } diff --git a/gc.c b/gc.c index af88862393..20af24f82d 100644 --- a/gc.c +++ b/gc.c @@ -84,7 +84,7 @@ void *alloca (); #endif #endif -static VALUE nomem_error; +#define nomem_error GET_VM()->special_exceptions[ruby_error_nomemory] #define MARK_STACK_MAX 1024 @@ -265,6 +265,11 @@ rb_memerror(void) fprintf(stderr, "[FATAL] failed to allocate memory\n"); exit(EXIT_FAILURE); } + if (rb_thread_raised_p(th, RAISED_NOMEMORY)) { + rb_thread_raised_clear(th); + GET_THREAD()->errinfo = nomem_error; + JUMP_TAG(TAG_RAISE); + } rb_thread_raised_set(th, RAISED_NOMEMORY); rb_exc_raise(nomem_error); } @@ -2394,8 +2399,9 @@ Init_GC(void) rb_define_module_function(rb_mObSpace, "_id2ref", id2ref, 1); - rb_global_variable(&nomem_error); nomem_error = rb_exc_new2(rb_eNoMemError, "failed to allocate memory"); + OBJ_TAINT(nomem_error); + OBJ_FREEZE(nomem_error); rb_define_method(rb_mKernel, "hash", rb_obj_id, 0); rb_define_method(rb_mKernel, "__id__", rb_obj_id, 0); diff --git a/proc.c b/proc.c index 3234c0e03c..eecff7ae12 100644 --- a/proc.c +++ b/proc.c @@ -1756,7 +1756,7 @@ Init_Proc(void) rb_eSysStackError = rb_define_class("SystemStackError", rb_eException); sysstack_error = rb_exc_new2(rb_eSysStackError, "stack level too deep"); OBJ_TAINT(sysstack_error); - rb_register_mark_object(sysstack_error); + OBJ_FREEZE(sysstack_error); /* utility functions */ rb_define_global_function("proc", rb_block_proc, 0); diff --git a/version.h b/version.h index 497179ad96..43eea68393 100644 --- a/version.h +++ b/version.h @@ -1,7 +1,7 @@ #define RUBY_VERSION "1.9.0" -#define RUBY_RELEASE_DATE "2008-06-14" +#define RUBY_RELEASE_DATE "2008-06-15" #define RUBY_VERSION_CODE 190 -#define RUBY_RELEASE_CODE 20080614 +#define RUBY_RELEASE_CODE 20080615 #define RUBY_PATCHLEVEL 0 #define RUBY_VERSION_MAJOR 1 @@ -9,7 +9,7 @@ #define RUBY_VERSION_TEENY 0 #define RUBY_RELEASE_YEAR 2008 #define RUBY_RELEASE_MONTH 6 -#define RUBY_RELEASE_DAY 14 +#define RUBY_RELEASE_DAY 15 #ifdef RUBY_EXTERN RUBY_EXTERN const char ruby_version[]; diff --git a/vm.c b/vm.c index 64fbe2d1c9..bb1ba4cb59 100644 --- a/vm.c +++ b/vm.c @@ -1393,6 +1393,7 @@ rb_vm_mark(void *ptr) RUBY_MARK_UNLESS_NULL(vm->load_path); RUBY_MARK_UNLESS_NULL(vm->loaded_features); RUBY_MARK_UNLESS_NULL(vm->top_self); + rb_gc_mark_locations(vm->special_exceptions, vm->special_exceptions + ruby_special_error_count - 1); if (vm->loading_table) { rb_mark_tbl(vm->loading_table); diff --git a/vm_core.h b/vm_core.h index b001491f00..18d1771035 100644 --- a/vm_core.h +++ b/vm_core.h @@ -281,6 +281,13 @@ struct rb_iseq_struct { struct iseq_compile_data *compile_data; }; +enum ruby_special_exceptions { + ruby_error_reenter, + ruby_error_nomemory, + ruby_error_sysstack, + ruby_special_error_count +}; + typedef struct rb_iseq_struct rb_iseq_t; #define GetVMPtr(obj, ptr) \ @@ -307,6 +314,8 @@ struct rb_vm_struct /* object management */ VALUE mark_object_ary; + VALUE special_exceptions[ruby_special_error_count]; + /* load */ VALUE top_self; VALUE load_path; @@ -648,7 +657,7 @@ VALUE vm_make_env_object(rb_thread_t *th, rb_control_frame_t *cfp); NOINLINE(void rb_gc_save_machine_context(rb_thread_t *)); -RUBY_EXTERN VALUE sysstack_error; +#define sysstack_error GET_VM()->special_exceptions[ruby_error_sysstack] /* for thread */