summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog19
-rw-r--r--error.c63
-rw-r--r--eval.c53
-rw-r--r--ext/socket/socket.c4
-rw-r--r--io.c11
-rw-r--r--lib/e2mmap.rb4
-rw-r--r--lib/ftplib.rb2
-rw-r--r--lib/sync.rb2
-rw-r--r--lib/thread.rb2
-rw-r--r--numeric.c4
-rw-r--r--re.c5
-rw-r--r--ruby.c11
-rw-r--r--string.c1
-rw-r--r--util.c42
14 files changed, 129 insertions, 94 deletions
diff --git a/ChangeLog b/ChangeLog
index 0012feeff3..a1352d4870 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+Fri May 1 00:35:51 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * error.c (exception): last argument may be the superclass of the
+ defining exception(s).
+
+ * io.c (Init_IO): EOFError is now subclass of the IOError.
+
+ * io.c (Init_IO): forgot to define IOError.
+
+ * error.c (Init_Exception): old Exception class renamed to
+ StandardError. Exception now replaces old GlobalExit.
+
+ * error.c (Init_Exception): Exception is now the root of the
+ Global Exits. There's no longer GlobalExit class.
+
+ * util.c (ruby_mktemp): check TMP, TMPDIR first.
+
Thu Apr 30 01:08:35 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
* lib/tk.rb: call 'unknown', if proc not defined.
@@ -5,7 +22,7 @@ Thu Apr 30 01:08:35 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
* eval.c (handle_rescue): default rescue handles `Exceptional' not
only the instance of the `Exception's.
- * eval.c (errinfo_setter): $! can be any `Throwable' object.
+ * eval.c (f_raise): exception can be any object.
* time.c (time_gm_or_local): call time_gmtime or time_localtime.
diff --git a/error.c b/error.c
index dcbec0b336..f54fbc3b41 100644
--- a/error.c
+++ b/error.c
@@ -212,9 +212,10 @@ rb_check_type(x, t)
#include "errno.h"
extern VALUE cString;
-VALUE eThrowable, eExceptional;
-VALUE eGlobalExit, eException;
+VALUE eException;
VALUE eSystemExit, eInterrupt, eFatal;
+VALUE eDefaultRescue;
+VALUE eStandardError;
VALUE eRuntimeError;
VALUE eSyntaxError;
VALUE eTypeError;
@@ -328,6 +329,7 @@ exception(argc, argv)
VALUE *argv;
{
void ArgError();
+ VALUE etype = eStandardError;
VALUE v = Qnil;
int i;
ID id;
@@ -335,6 +337,10 @@ exception(argc, argv)
if (argc == 0) {
ArgError("wrong # of arguments");
}
+ if (TYPE(argv[argc-1]) == T_CLASS) {
+ etype = argv[argc-1];
+ argc--; argv++;
+ }
for (i=0; i<argc; i++) { /* argument check */
id = rb_to_id(argv[i]);
if (!rb_id2name(id)) {
@@ -345,7 +351,9 @@ exception(argc, argv)
}
}
for (i=0; i<argc; i++) {
- v = rb_define_class_under(the_class, rb_id2name(rb_to_id(argv[i])), eException);
+ v = rb_define_class_under(the_class,
+ rb_id2name(rb_to_id(argv[i])),
+ etype);
}
return v;
}
@@ -372,31 +380,28 @@ static void init_syserr();
void
Init_Exception()
{
- eThrowable = rb_define_module("Throwable");
- eGlobalExit = rb_define_class("GlobalExit", cString);
- rb_include_module(eGlobalExit, eThrowable);
- rb_define_singleton_method(eGlobalExit, "new", exc_s_new, -1);
- rb_define_method(eGlobalExit, "new", exc_new_method, 1);
- rb_define_method(eGlobalExit, "inspect", exc_inspect, 0);
-
- eSystemExit = rb_define_class("SystemExit", eGlobalExit);
- eFatal = rb_define_class("fatal", eGlobalExit);
- eInterrupt = rb_define_class("Interrupt", eGlobalExit);
-
- eExceptional = rb_define_module("Exceptional");
- rb_include_module(eExceptional, eThrowable);
- eException = rb_define_class("Exception", eGlobalExit);
- rb_include_module(eException, eExceptional);
- eSyntaxError = rb_define_class("SyntaxError", eException);
- eTypeError = rb_define_class("TypeError", eException);
- eArgError = rb_define_class("ArgumentError", eException);
- eNameError = rb_define_class("NameError", eException);
- eIndexError = rb_define_class("IndexError", eException);
- eNotImpError = rb_define_class("NotImplementError", eException);
- eLoadError = rb_define_class("LoadError", eException);
-
- eRuntimeError = rb_define_class("RuntimeError", eException);
- eSecurityError = rb_define_class("SecurityError", eException);
+ eException = rb_define_class("Exception", cString);
+ rb_define_singleton_method(eException, "new", exc_s_new, -1);
+ rb_define_method(eException, "new", exc_new_method, 1);
+ rb_define_method(eException, "inspect", exc_inspect, 0);
+
+ eSystemExit = rb_define_class("SystemExit", eException);
+ eFatal = rb_define_class("fatal", eException);
+ eInterrupt = rb_define_class("Interrupt", eException);
+
+ eDefaultRescue = rb_define_module("DefaultRescue");
+ eStandardError = rb_define_class("StandardError", eException);
+ rb_include_module(eStandardError, eDefaultRescue);
+ eSyntaxError = rb_define_class("SyntaxError", eStandardError);
+ eTypeError = rb_define_class("TypeError", eStandardError);
+ eArgError = rb_define_class("ArgumentError", eStandardError);
+ eNameError = rb_define_class("NameError", eStandardError);
+ eIndexError = rb_define_class("IndexError", eStandardError);
+ eNotImpError = rb_define_class("NotImplementError", eStandardError);
+ eLoadError = rb_define_class("LoadError", eStandardError);
+
+ eRuntimeError = rb_define_class("RuntimeError", eStandardError);
+ eSecurityError = rb_define_class("SecurityError", eStandardError);
init_syserr();
@@ -524,7 +529,7 @@ rb_sys_fail(mesg)
static void
init_syserr()
{
- eSystemCallError = rb_define_class("SystemCallError", eException);
+ eSystemCallError = rb_define_class("SystemCallError", eStandardError);
mErrno = rb_define_module("Errno");
syserr_list = ALLOC_N(VALUE, sys_nerr+1);
MEMZERO(syserr_list, VALUE, sys_nerr+1);
diff --git a/eval.c b/eval.c
index 7184f10173..b0b929925a 100644
--- a/eval.c
+++ b/eval.c
@@ -362,8 +362,8 @@ extern int nerrs;
extern VALUE mKernel;
extern VALUE cModule;
extern VALUE eFatal;
-extern VALUE eThrowable;
-extern VALUE eExceptional;
+extern VALUE eDefaultRescue;
+extern VALUE eStandardError;
extern VALUE eInterrupt;
extern VALUE eSystemExit;
extern VALUE eException;
@@ -1806,6 +1806,7 @@ rb_eval(self, node)
POP_TAG();
if (state == TAG_RAISE) {
NODE * volatile resq = node->nd_resq;
+
while (resq) {
if (handle_rescue(self, resq)) {
state = 0;
@@ -2708,15 +2709,7 @@ rb_longjmp(tag, mesg, at)
}
if (!NIL_P(mesg)) {
- if (obj_is_kind_of(mesg, eThrowable)) {
- errinfo = mesg;
- }
- else {
- errinfo = exc_new3(eRuntimeError, mesg);
- }
- if (TYPE(errinfo) == T_STRING) {
- str_freeze(errinfo);
- }
+ errinfo = mesg;
}
trap_restore_mask();
@@ -2765,23 +2758,16 @@ f_raise(argc, argv)
case 2:
case 3:
etype = arg1;
- if (obj_is_kind_of(etype, eThrowable)) {
- etype = CLASS_OF(etype);
- }
- else {
- Check_Type(etype, T_CLASS);
- }
mesg = arg2;
break;
}
if (!NIL_P(mesg)) {
- if (n >= 2 || !obj_is_kind_of(mesg, eThrowable)) {
+ if (n >= 2) {
mesg = rb_funcall(etype, rb_intern("new"), 1, mesg);
}
- if (!obj_is_kind_of(mesg, eThrowable)) {
- TypeError("should be Throwable, %s given",
- rb_class2name(CLASS_OF(mesg)));
+ else if (TYPE(mesg) == T_STRING) {
+ mesg = exc_new3(eRuntimeError, mesg);
}
}
@@ -3051,7 +3037,7 @@ handle_rescue(self, node)
TMP_PROTECT;
if (!node->nd_args) {
- return obj_is_kind_of(errinfo, eExceptional);
+ return obj_is_kind_of(errinfo, eDefaultRescue);
}
PUSH_ITER(ITER_NOT);
@@ -3080,7 +3066,7 @@ rb_rescue(b_proc, data1, r_proc, data2)
retry_entry:
result = (*b_proc)(data1);
}
- else if (state == TAG_RAISE && obj_is_kind_of(errinfo, eExceptional)) {
+ else if (state == TAG_RAISE && obj_is_kind_of(errinfo, eDefaultRescue)) {
if (r_proc) {
PUSH_TAG(PROT_NONE);
if ((state = EXEC_TAG()) == 0) {
@@ -4497,19 +4483,6 @@ errat_setter(val, id, var)
*var = check_errat(val);
}
-static void
-errinfo_setter(val, id, var)
- VALUE val;
- ID id;
- VALUE *var;
-{
- if (!obj_is_kind_of(val, eThrowable)) {
- TypeError("$! should be Throwable, %s given",
- rb_class2name(CLASS_OF(val)));
- }
- *var = val;
-}
-
VALUE f_global_variables();
VALUE f_instance_variables();
@@ -4617,7 +4590,7 @@ Init_eval()
rb_global_variable((VALUE*)&the_dyna_vars);
rb_define_hooked_variable("$@", &errat, 0, errat_setter);
- rb_define_hooked_variable("$!", &errinfo, 0, errinfo_setter);
+ rb_define_variable("$!", &errinfo);
rb_define_global_function("eval", f_eval, -1);
rb_define_global_function("iterator?", f_iterator_p, 0);
@@ -5188,8 +5161,8 @@ method_proc(method)
void
Init_Proc()
{
- eLocalJumpError = rb_define_class("LocalJumpError", eException);
- eSysStackError = rb_define_class("SystemStackError", eException);
+ eLocalJumpError = rb_define_class("LocalJumpError", eStandardError);
+ eSysStackError = rb_define_class("SystemStackError", eStandardError);
cProc = rb_define_class("Proc", cObject);
rb_define_singleton_method(cProc, "new", proc_s_new, 0);
@@ -6402,7 +6375,7 @@ thread_loading_done()
void
Init_Thread()
{
- eThreadError = rb_define_class("ThreadError", eException);
+ eThreadError = rb_define_class("ThreadError", eStandardError);
cThread = rb_define_class("Thread", cObject);
rb_define_singleton_method(cThread, "new", thread_start, 0);
diff --git a/ext/socket/socket.c b/ext/socket/socket.c
index d35e029f34..481b9ffa2a 100644
--- a/ext/socket/socket.c
+++ b/ext/socket/socket.c
@@ -48,7 +48,7 @@ VALUE cUNIXserver;
#endif
VALUE cSocket;
-extern VALUE eException;
+extern VALUE eStandardError;
static VALUE eSocket;
#ifdef SOCKS
@@ -1394,7 +1394,7 @@ sock_define_const(name, value)
Init_socket()
{
- eSocket = rb_define_class("SocketError", eException);
+ eSocket = rb_define_class("SocketError", eStandardError);
cBasicSocket = rb_define_class("BasicSocket", cIO);
rb_undef_method(CLASS_OF(cBasicSocket), "new");
diff --git a/io.c b/io.c
index b2acba401a..ac8e51aabb 100644
--- a/io.c
+++ b/io.c
@@ -2405,14 +2405,15 @@ opt_i_set(val)
inplace = RSTRING(val)->ptr;
}
+extern VALUE mKernel;
+extern VALUE mEnumerable;
+extern VALUE eStandardError;
+
void
Init_IO()
{
- extern VALUE mKernel;
- extern VALUE mEnumerable;
- extern VALUE eException;
-
- eEOFError = rb_define_class("EOFError", eException);
+ eIOError = rb_define_class("IOError", eStandardError);
+ eEOFError = rb_define_class("EOFError", eIOError);
id_write = rb_intern("write");
diff --git a/lib/e2mmap.rb b/lib/e2mmap.rb
index d10657bbad..d9acf5603a 100644
--- a/lib/e2mmap.rb
+++ b/lib/e2mmap.rb
@@ -72,11 +72,11 @@ else
# def_exception(c, m)
# n: exception_name
# m: message_form
- # s: 例外スーパークラス(デフォルト: Exception)
+ # s: 例外スーパークラス(デフォルト: StandardError)
# 例外名``c''をもつ例外を定義し, そのメッセージをmとする.
#
#def def_exception(n, m)
- def self.def_exception(n, m, s = Exception)
+ def self.def_exception(n, m, s = StandardError)
n = n.id2name if n.kind_of?(Fixnum)
e = Class.new(s)
const_set(n, e)
diff --git a/lib/ftplib.rb b/lib/ftplib.rb
index e79868b0ef..f0c3f10930 100644
--- a/lib/ftplib.rb
+++ b/lib/ftplib.rb
@@ -8,7 +8,7 @@
require "socket"
require "monitor"
-class FTPError < Exception; end
+class FTPError < StandardError; end
class FTPReplyError < FTPError; end
class FTPTempError < FTPError; end
class FTPPermError < FTPError; end
diff --git a/lib/sync.rb b/lib/sync.rb
index 6d79cc26bf..9f9706d9ee 100644
--- a/lib/sync.rb
+++ b/lib/sync.rb
@@ -55,7 +55,7 @@ module Sync_m
EX = :EX
# 例外定義
- class Err < Exception
+ class Err < StandardError
def Err.Fail(*opt)
fail self, sprintf(self::Message, *opt)
end
diff --git a/lib/thread.rb b/lib/thread.rb
index 709aa83c25..7706d59cbb 100644
--- a/lib/thread.rb
+++ b/lib/thread.rb
@@ -9,7 +9,7 @@ unless defined? Thread
end
unless defined? ThreadError
- class ThreadError<Exception
+ class ThreadError<StandardError
end
end
diff --git a/numeric.c b/numeric.c
index 053ad10151..72c1137e3a 100644
--- a/numeric.c
+++ b/numeric.c
@@ -1253,7 +1253,7 @@ fix_zero_p(num)
}
extern VALUE mComparable;
-extern VALUE eException;
+extern VALUE eStandardError;
void
Init_Numeric()
@@ -1261,7 +1261,7 @@ Init_Numeric()
coerce = rb_intern("coerce");
to_i = rb_intern("to_i");
- eZeroDiv = rb_define_class("ZeroDivisionError", eException);
+ eZeroDiv = rb_define_class("ZeroDivisionError", eStandardError);
cNumeric = rb_define_class("Numeric", cObject);
rb_include_module(cNumeric, mComparable);
diff --git a/re.c b/re.c
index 2934091a81..daf285708c 100644
--- a/re.c
+++ b/re.c
@@ -1047,13 +1047,12 @@ match_setter(val)
}
VALUE any_to_s();
+extern VALUE eStandardError;
void
Init_Regexp()
{
- extern VALUE eException;
-
- eRegxpError = rb_define_class("RegxpError", eException);
+ eRegxpError = rb_define_class("RegxpError", eStandardError);
re_set_syntax(RE_NO_BK_PARENS | RE_NO_BK_VBAR
| RE_INTERVALS
diff --git a/ruby.c b/ruby.c
index eed46d2657..0a947472d9 100644
--- a/ruby.c
+++ b/ruby.c
@@ -30,6 +30,8 @@ char *strrchr();
char *strstr();
#endif
+char *ruby_mktemp _((void));
+
char *getenv();
static int version, copyright;
@@ -231,13 +233,12 @@ proc_options(argcp, argvp)
case 'e':
forbid_setid("-e");
if (!e_fp) {
- e_tmpname = strdup("rbXXXXXX");
- mktemp(e_tmpname);
- if (!*e_tmpname)
- Fatal("Can't mktemp(%s)", e_tmpname);
+ e_tmpname = ruby_mktemp();
+ if (!e_tmpname) Fatal("Can't mktemp");
e_fp = fopen(e_tmpname, "w");
- if (!e_fp)
+ if (!e_fp) {
Fatal("Cannot open temporary file: %s", e_tmpname);
+ }
if (script == 0) script = e_tmpname;
}
if (argv[1]) {
diff --git a/string.c b/string.c
index cedf53acee..f94e457cef 100644
--- a/string.c
+++ b/string.c
@@ -2619,7 +2619,6 @@ str_center(str, w)
extern VALUE mKernel;
extern VALUE mComparable;
extern VALUE mEnumerable;
-extern VALUE eGlobalExit;
void
Init_String()
diff --git a/util.c b/util.c
index 527ce87d03..8dea777ffa 100644
--- a/util.c
+++ b/util.c
@@ -86,6 +86,47 @@ int *retlen;
return retval;
}
+#include <sys/types.h>
+#include <sys/stat.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#ifndef S_ISDIR
+# define S_ISDIR(m) ((m & S_IFMT) == S_IFDIR)
+#endif
+
+static char *
+check_dir(dir)
+ char *dir;
+{
+ struct stat st;
+
+ if (dir == NULL) return NULL;
+ if (stat(dir, &st) < 0) return NULL;
+ if (!S_ISDIR(st.st_mode)) return NULL;
+ if (eaccess(dir, W_OK) < 0) return NULL;
+ return dir;
+}
+
+char *
+ruby_mktemp()
+{
+ char *dir;
+ char *buf;
+
+ dir = check_dir(getenv("TMP"));
+ if (!dir) dir = check_dir(getenv("TMPDIR"));
+ if (!dir) dir = "/tmp";
+
+ buf = ALLOC_N(char,strlen(dir)+10);
+ sprintf(buf, "%s/rbXXXXXX", dir);
+ dir = mktemp(buf);
+ if (dir == NULL) free(buf);
+
+ return dir;
+}
+
#if defined(MSDOS) || defined(__CYGWIN32__) || defined(NT)
#include <fcntl.h>
/*
@@ -267,7 +308,6 @@ valid_filename(char *s)
#include <go32.h>
#include <dpmi.h> /* For dpmisim */
#include <crt0.h> /* For crt0 flags */
-#include <sys/stat.h>
#include <libc/dosio.h>
static unsigned use_lfn;