Skip to content

Commit

Permalink
* error.c (syserr_initialize): prohibit specifying errno for
Browse files Browse the repository at this point in the history
  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
  • Loading branch information
matz committed May 21, 2003
1 parent 564c80b commit 062351e
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 13 deletions.
10 changes: 10 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
Wed May 21 17:44:16 2003 Yukihiro Matsumoto <[email protected]>

* 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 <[email protected]>

* lib/optparse.rb: get rid of warnings.
Expand Down
1 change: 1 addition & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 18 additions & 11 deletions error.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down
1 change: 0 additions & 1 deletion eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -7982,7 +7982,6 @@ rb_thread_save_context(th)
th->stk_pos = (rb_gc_stack_start<pos)?rb_gc_stack_start
:rb_gc_stack_start - len;
if (len > th->stk_max) {
rb_gc();
REALLOC_N(th->stk_ptr, VALUE, len);
th->stk_max = len;
}
Expand Down
2 changes: 2 additions & 0 deletions gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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; i<RARRAY(finalizers)->len; i++) {
args[0] = RARRAY(finalizers)->ptr[i];
Expand All @@ -1533,6 +1534,7 @@ run_final(obj)
rb_protect((VALUE(*)_((VALUE)))run_single_final, (VALUE)args, &status);
}
}
ENABLE_INTS;
}

void
Expand Down
2 changes: 1 addition & 1 deletion lib/delegate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def __setobj__(obj)
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)
Expand Down

0 comments on commit 062351e

Please sign in to comment.