From 062351e6bb492d206c305840f4a69c70efcb5131 Mon Sep 17 00:00:00 2001 From: matz Date: Wed, 21 May 2003 08:48:05 +0000 Subject: * error.c (syserr_initialize): prohibit specifying errno for subclasses of SystemCallError. in addition, if initialize is called for SystenCallError instance, its class be changed. [ruby-dev:20257] * gc.c (run_final): to protect thread context switch, finalizers are wrapped in DEFER_INTS/ENABLE_INTS. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3839 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 10 ++++++++++ MANIFEST | 1 + error.c | 29 ++++++++++++++++++----------- eval.c | 1 - gc.c | 2 ++ lib/delegate.rb | 2 +- 6 files changed, 32 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index c2738d0a65..8af4911d0f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +Wed May 21 17:44:16 2003 Yukihiro Matsumoto + + * error.c (syserr_initialize): prohibit specifying errno for + subclasses of SystemCallError. in addition, if initialize is + called for SystenCallError instance, its class be changed. + [ruby-dev:20257] + + * gc.c (run_final): to protect thread context switch, finalizers + are wrapped in DEFER_INTS/ENABLE_INTS. + Wed May 21 13:26:08 2003 Nobuyoshi Nakada * lib/optparse.rb: get rid of warnings. diff --git a/MANIFEST b/MANIFEST index f6121203f6..d7bb8dfbdf 100644 --- a/MANIFEST +++ b/MANIFEST @@ -184,6 +184,7 @@ lib/observer.rb lib/open-uri.rb lib/open3.rb lib/optparse.rb +lib/optparse/date.rb lib/optparse/shellwords.rb lib/optparse/time.rb lib/optparse/uri.rb diff --git a/error.c b/error.c index 26dec201cd..a90167cf2e 100644 --- a/error.c +++ b/error.c @@ -541,21 +541,29 @@ syserr_initialize(argc, argv, self) #endif char *err; char *buf; - VALUE error, mesg; + VALUE mesg, error; VALUE klass = rb_obj_class(self); - rb_scan_args(argc, argv, klass == rb_eSystemCallError ? "11" : "02", - &mesg, &error); - if (argc == 1 && FIXNUM_P(mesg)) { - error = mesg; - mesg = Qnil; + if (klass == rb_eSystemCallError) { + rb_scan_args(argc, argv, "11", &mesg, &error); + if (argc == 1 && FIXNUM_P(mesg)) { + error = mesg; mesg = Qnil; + } + if (!NIL_P(error) && st_lookup(syserr_tbl, NUM2LONG(error), &klass)) { + /* change class */ + if (TYPE(self) != T_OBJECT) { /* insurance to avoid type crash */ + rb_raise(rb_eTypeError, "invalid instance type"); + } + RBASIC(self)->klass = klass; + } } - if (klass != rb_eSystemCallError && NIL_P(error)) { + else { + rb_scan_args(argc, argv, "01", &mesg); error = rb_const_get_at(klass, rb_intern("Errno")); } - err = strerror(NUM2LONG(error)); - if (!err) err = "Unknown error"; - if (RTEST(mesg)) { + if (!NIL_P(error)) err = strerror(NUM2LONG(error)); + else err = "unknown error"; + if (!NIL_P(mesg)) { StringValue(mesg); buf = ALLOCA_N(char, strlen(err)+RSTRING(mesg)->len+4); sprintf(buf, "%s - %s", err, RSTRING(mesg)->ptr); @@ -564,7 +572,6 @@ syserr_initialize(argc, argv, self) else { mesg = rb_str_new2(err); } - exc_initialize(1, &mesg, self); rb_iv_set(self, "errno", error); return self; diff --git a/eval.c b/eval.c index f7bc8d2c1f..3b8986aa8d 100644 --- a/eval.c +++ b/eval.c @@ -7982,7 +7982,6 @@ rb_thread_save_context(th) th->stk_pos = (rb_gc_stack_start th->stk_max) { - rb_gc(); REALLOC_N(th->stk_ptr, VALUE, len); th->stk_max = len; } diff --git a/gc.c b/gc.c index 8a71ece020..8fe85689fa 100644 --- a/gc.c +++ b/gc.c @@ -1522,6 +1522,7 @@ run_final(obj) int status; VALUE args[2], table; + DEFER_INTS; args[1] = rb_ary_new3(1, rb_obj_id(obj)); /* make obj into id */ for (i=0; ilen; i++) { args[0] = RARRAY(finalizers)->ptr[i]; @@ -1533,6 +1534,7 @@ run_final(obj) rb_protect((VALUE(*)_((VALUE)))run_single_final, (VALUE)args, &status); } } + ENABLE_INTS; } void diff --git a/lib/delegate.rb b/lib/delegate.rb index 88d2256a2f..651164e274 100644 --- a/lib/delegate.rb +++ b/lib/delegate.rb @@ -77,7 +77,7 @@ SimpleDelegater = SimpleDelegator def DelegateClass(superclass) klass = Class.new methods = superclass.public_instance_methods(true) - methods -= ::Kernel.public_instance_methods + methods -= ::Kernel.public_instance_methods(false) methods |= ["to_s","to_a","inspect","==","=~","==="] klass.module_eval <<-EOS def initialize(obj) -- cgit v1.2.3