Skip to content

Commit

Permalink
* error.c (exit_initialize): use EXIT_SUCCESS instead of 0.
Browse files Browse the repository at this point in the history
  [ruby-dev:23913]

* error.c (exit_success_p): new method SystemExit#success?.
  [ruby-dev:23912]

* error.c (syserr_initialize): initialization for subclasses.
  [ruby-dev:23912]


git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8@6644 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nobu committed Jul 16, 2004
1 parent b498533 commit 665b520
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 9 deletions.
11 changes: 11 additions & 0 deletions ChangeLog
@@ -1,3 +1,14 @@
Fri Jul 16 11:17:38 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>

* error.c (exit_initialize): use EXIT_SUCCESS instead of 0.
[ruby-dev:23913]

* error.c (exit_success_p): new method SystemExit#success?.
[ruby-dev:23912]

* error.c (syserr_initialize): initialization for subclasses.
[ruby-dev:23912]

Thu Jul 15 23:53:38 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>

* lib/optparse.rb (OptionParser#warn, OptionParser#abort): Exception
Expand Down
43 changes: 34 additions & 9 deletions error.c
Expand Up @@ -22,6 +22,12 @@
#include <varargs.h>
#define va_init_list(a,b) va_start(a)
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifndef EXIT_SUCCESS
#define EXIT_SUCCESS 0
#endif

extern const char ruby_version[], ruby_release_date[], ruby_platform[];

Expand Down Expand Up @@ -516,7 +522,7 @@ check_backtrace(bt)

/*
* call-seq:
* exc.set_backtrace(array_ => array
* exc.set_backtrace(array) => array
*
* Sets the backtrace information associated with <i>exc</i>. The
* argument must be an array of <code>String</code> objects in the
Expand Down Expand Up @@ -545,7 +551,7 @@ exit_initialize(argc, argv, exc)
VALUE *argv;
VALUE exc;
{
VALUE status = INT2NUM(0);
VALUE status = INT2FIX(EXIT_SUCCESS);
if (argc > 0 && FIXNUM_P(argv[0])) {
status = *argv++;
--argc;
Expand All @@ -563,14 +569,31 @@ exit_initialize(argc, argv, exc)
* Return the status value associated with this system exit.
*/


static VALUE
exit_status(exc)
VALUE exc;
{
return rb_attr_get(exc, rb_intern("status"));
}


/*
* call-seq:
* system_exit.success? => true or false
*
* Returns +true+ if exiting successful, +false+ if not.
*/

static VALUE
exit_success_p(exc)
VALUE exc;
{
VALUE status = rb_attr_get(exc, rb_intern("status"));
if (NIL_P(status)) return Qtrue;
if (status == INT2FIX(EXIT_SUCCESS)) return Qtrue;
return Qfalse;
}

void
#ifdef HAVE_STDARG_PROTOTYPES
rb_name_error(ID id, const char *fmt, ...)
Expand Down Expand Up @@ -863,7 +886,6 @@ syserr_initialize(argc, argv, self)
char *strerror();
#endif
char *err;
char *buf;
VALUE mesg, error;
VALUE klass = rb_obj_class(self);

Expand All @@ -882,15 +904,17 @@ syserr_initialize(argc, argv, self)
}
else {
rb_scan_args(argc, argv, "01", &mesg);
error = rb_const_get_at(klass, rb_intern("Errno"));
error = rb_const_get(klass, rb_intern("Errno"));
}
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, (int)RSTRING(mesg)->len, RSTRING(mesg)->ptr);
mesg = rb_str_new2(buf);
VALUE str = mesg;
StringValue(str);
mesg = rb_str_new(0, strlen(err)+RSTRING(mesg)->len+3);
sprintf(RSTRING(mesg)->ptr, "%s - %.*s", err,
(int)RSTRING(str)->len, RSTRING(str)->ptr);
rb_str_resize(mesg, strlen(RSTRING(mesg)->ptr));
}
else {
mesg = rb_str_new2(err);
Expand Down Expand Up @@ -974,6 +998,7 @@ Init_Exception()
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_define_method(rb_eSystemExit, "success?", exit_success_p, 0);

rb_eFatal = rb_define_class("fatal", rb_eException);
rb_eSignal = rb_define_class("SignalException", rb_eException);
Expand Down

0 comments on commit 665b520

Please sign in to comment.