1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* error.c (exit_initialize): add SystemExit#initialize to set

instance variable status.  (ruby-bugs-ja:PR#362)
  Now accepts status as optional first argument.

* 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.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3087 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2002-11-26 22:32:11 +00:00
parent dc260404fe
commit 5bf245eeb9
3 changed files with 40 additions and 9 deletions

View file

@ -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.

20
error.c
View file

@ -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;
@ -399,6 +400,22 @@ exc_set_backtrace(exc, bt)
return rb_iv_set(exc, "bt", check_backtrace(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);

18
eval.c
View file

@ -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);