summaryrefslogtreecommitdiff
path: root/error.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-05-21 08:48:05 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-05-21 08:48:05 +0000
commit062351e6bb492d206c305840f4a69c70efcb5131 (patch)
tree7573699c85deee5831cc5538b2f53ce47ed91011 /error.c
parent564c80b10a116c49ac0dbcfe620e3f776c0d3845 (diff)
* 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
Diffstat (limited to 'error.c')
-rw-r--r--error.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/error.c b/error.c
index 26dec20..a90167c 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;