summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog11
-rw-r--r--error.c20
-rw-r--r--eval.c18
3 files changed, 40 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 69a6be5fd6..3196238e4f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+Wed Nov 27 06:43:26 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
+
+ * error.c (exit_initialize): add SystemExit#initialize to set
+ instance variable status. (ruby-bugs-ja:PR#362)
+
+ * eval.c (error_handle): now SystemExit have status always.
+
+ * eval.c (system_exit): just instantiate SystemExit without raise.
+
+ * eval.c (rb_thread_start_0): initialize SystemExit properly.
+
Mon Nov 25 19:55:38 2002 WATANABE Hirofumi <eban@ruby-lang.org>
* ext/extmk.rb (extmake): return true if not dynamic and not static.
diff --git a/error.c b/error.c
index edd86f065f..0c7d2bc69d 100644
--- a/error.c
+++ b/error.c
@@ -28,8 +28,9 @@ int ruby_nerrs;
static void
err_snprintf(buf, len, fmt, args)
- char *buf, *fmt;
+ char *buf;
long len;
+ const char *fmt;
va_list args;
{
long n;
@@ -400,6 +401,22 @@ exc_set_backtrace(exc, bt)
}
static VALUE
+exit_initialize(argc, argv, exc)
+ int argc;
+ VALUE *argv;
+ VALUE exc;
+{
+ VALUE status = INT2NUM(0);
+ if (argc > 0 && FIXNUM_P(argv[0])) {
+ status = *argv++;
+ --argc;
+ }
+ exc_initialize(argc, argv, exc);
+ rb_iv_set(exc, "status", status);
+ return exc;
+}
+
+static VALUE
exit_status(exc)
VALUE exc;
{
@@ -530,6 +547,7 @@ Init_Exception()
rb_define_method(rb_eException, "set_backtrace", exc_set_backtrace, 1);
rb_eSystemExit = rb_define_class("SystemExit", rb_eException);
+ rb_define_method(rb_eSystemExit, "initialize", exit_initialize, -1);
rb_define_method(rb_eSystemExit, "status", exit_status, 0);
rb_eFatal = rb_define_class("fatal", rb_eException);
diff --git a/eval.c b/eval.c
index 60e0d73a39..40470de3ff 100644
--- a/eval.c
+++ b/eval.c
@@ -1181,7 +1181,7 @@ error_handle(ex)
case TAG_FATAL:
if (rb_obj_is_kind_of(ruby_errinfo, rb_eSystemExit)) {
VALUE st = rb_iv_get(ruby_errinfo, "status");
- ex = NIL_P(st) ? 1 : NUM2INT(st);
+ ex = NUM2INT(st);
}
else {
error_print();
@@ -3562,17 +3562,19 @@ rb_mod_protected_method_defined(mod, mid)
return Qfalse;
}
-NORETURN(static void terminate_process _((int, const char*, long)));
-static void
-terminate_process(status, mesg, mlen)
+#define terminate_process(status, mesg, mlen) rb_exc_raise(system_exit(status, mesg, mlen))
+
+static VALUE
+system_exit(status, mesg, mlen)
int status;
const char *mesg;
long mlen;
{
- VALUE exit = rb_exc_new(rb_eSystemExit, mesg, mlen);
+ VALUE args[2];
+ args[0] = INT2NUM(status);
+ args[1] = rb_str_new(mesg, mlen);
- rb_iv_set(exit, "status", INT2NUM(status));
- rb_exc_raise(exit);
+ return rb_class_new_instance(2, args, rb_eSystemExit);
}
void
@@ -8869,7 +8871,7 @@ rb_thread_start_0(fn, arg, th_arg)
}
}
else if (th->safe < 4 && (thread_abort || th->abort || RTEST(ruby_debug))) {
- VALUE err = rb_exc_new(rb_eSystemExit, 0, 0);
+ VALUE err = system_exit(1, 0, 0);
error_print();
/* exit on main_thread */
rb_thread_raise(1, &err, main_thread);