summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-07-16 02:17:59 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-07-16 02:17:59 +0000
commit797aea65cbe0580f8c27dd05212777aab8489c83 (patch)
treed2ef664b654cd70939261c36b9c646fcab8d369c
parent7aa94d402565509ca1cf4c5082b18a70ffbab605 (diff)
* 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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@6644 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog11
-rw-r--r--error.c43
2 files changed, 45 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 85552702e5..26486fcccf 100644
--- a/ChangeLog
+++ b/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
diff --git a/error.c b/error.c
index 06fb929132..178c4b7b29 100644
--- a/error.c
+++ b/error.c
@@ -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[];
@@ -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
@@ -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;
@@ -563,7 +569,6 @@ exit_initialize(argc, argv, exc)
* Return the status value associated with this system exit.
*/
-
static VALUE
exit_status(exc)
VALUE exc;
@@ -571,6 +576,24 @@ exit_status(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, ...)
@@ -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);
@@ -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);
@@ -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);