* 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
This commit is contained in:
matz 2003-05-21 08:48:05 +00:00
parent 564c80b10a
commit 062351e6bb
6 changed files with 32 additions and 13 deletions

View File

@ -1,3 +1,13 @@
Wed May 21 17:44:16 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
* 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 <nobu.nokada@softhome.net> Wed May 21 13:26:08 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* lib/optparse.rb: get rid of warnings. * lib/optparse.rb: get rid of warnings.

View File

@ -184,6 +184,7 @@ lib/observer.rb
lib/open-uri.rb lib/open-uri.rb
lib/open3.rb lib/open3.rb
lib/optparse.rb lib/optparse.rb
lib/optparse/date.rb
lib/optparse/shellwords.rb lib/optparse/shellwords.rb
lib/optparse/time.rb lib/optparse/time.rb
lib/optparse/uri.rb lib/optparse/uri.rb

27
error.c
View File

@ -541,21 +541,29 @@ syserr_initialize(argc, argv, self)
#endif #endif
char *err; char *err;
char *buf; char *buf;
VALUE error, mesg; VALUE mesg, error;
VALUE klass = rb_obj_class(self); VALUE klass = rb_obj_class(self);
rb_scan_args(argc, argv, klass == rb_eSystemCallError ? "11" : "02", if (klass == rb_eSystemCallError) {
&mesg, &error); rb_scan_args(argc, argv, "11", &mesg, &error);
if (argc == 1 && FIXNUM_P(mesg)) { if (argc == 1 && FIXNUM_P(mesg)) {
error = mesg; error = mesg; mesg = Qnil;
mesg = Qnil;
} }
if (klass != rb_eSystemCallError && NIL_P(error)) { 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;
}
}
else {
rb_scan_args(argc, argv, "01", &mesg);
error = rb_const_get_at(klass, rb_intern("Errno")); error = rb_const_get_at(klass, rb_intern("Errno"));
} }
err = strerror(NUM2LONG(error)); if (!NIL_P(error)) err = strerror(NUM2LONG(error));
if (!err) err = "Unknown error"; else err = "unknown error";
if (RTEST(mesg)) { if (!NIL_P(mesg)) {
StringValue(mesg); StringValue(mesg);
buf = ALLOCA_N(char, strlen(err)+RSTRING(mesg)->len+4); buf = ALLOCA_N(char, strlen(err)+RSTRING(mesg)->len+4);
sprintf(buf, "%s - %s", err, RSTRING(mesg)->ptr); sprintf(buf, "%s - %s", err, RSTRING(mesg)->ptr);
@ -564,7 +572,6 @@ syserr_initialize(argc, argv, self)
else { else {
mesg = rb_str_new2(err); mesg = rb_str_new2(err);
} }
exc_initialize(1, &mesg, self); exc_initialize(1, &mesg, self);
rb_iv_set(self, "errno", error); rb_iv_set(self, "errno", error);
return self; return self;

1
eval.c
View File

@ -7982,7 +7982,6 @@ rb_thread_save_context(th)
th->stk_pos = (rb_gc_stack_start<pos)?rb_gc_stack_start th->stk_pos = (rb_gc_stack_start<pos)?rb_gc_stack_start
:rb_gc_stack_start - len; :rb_gc_stack_start - len;
if (len > th->stk_max) { if (len > th->stk_max) {
rb_gc();
REALLOC_N(th->stk_ptr, VALUE, len); REALLOC_N(th->stk_ptr, VALUE, len);
th->stk_max = len; th->stk_max = len;
} }

2
gc.c
View File

@ -1522,6 +1522,7 @@ run_final(obj)
int status; int status;
VALUE args[2], table; VALUE args[2], table;
DEFER_INTS;
args[1] = rb_ary_new3(1, rb_obj_id(obj)); /* make obj into id */ args[1] = rb_ary_new3(1, rb_obj_id(obj)); /* make obj into id */
for (i=0; i<RARRAY(finalizers)->len; i++) { for (i=0; i<RARRAY(finalizers)->len; i++) {
args[0] = RARRAY(finalizers)->ptr[i]; args[0] = RARRAY(finalizers)->ptr[i];
@ -1533,6 +1534,7 @@ run_final(obj)
rb_protect((VALUE(*)_((VALUE)))run_single_final, (VALUE)args, &status); rb_protect((VALUE(*)_((VALUE)))run_single_final, (VALUE)args, &status);
} }
} }
ENABLE_INTS;
} }
void void

View File

@ -77,7 +77,7 @@ SimpleDelegater = SimpleDelegator
def DelegateClass(superclass) def DelegateClass(superclass)
klass = Class.new klass = Class.new
methods = superclass.public_instance_methods(true) methods = superclass.public_instance_methods(true)
methods -= ::Kernel.public_instance_methods methods -= ::Kernel.public_instance_methods(false)
methods |= ["to_s","to_a","inspect","==","=~","==="] methods |= ["to_s","to_a","inspect","==","=~","==="]
klass.module_eval <<-EOS klass.module_eval <<-EOS
def initialize(obj) def initialize(obj)