summaryrefslogtreecommitdiff
path: root/error.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-11-03 11:04:35 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-11-03 11:04:35 +0000
commitaae36756dcc4d5debcaabd03379796bc41360bc4 (patch)
treeff4ed4df6473229d846ff4f658094fcf66c4c744 /error.c
parentc960141333a9bc384bafbcfaa49672e48677d6dd (diff)
* object.c (Init_Object): added Object#object_id, new name for
Object#id. [new] * object.c (rb_obj_id_obsolete): give warning for Object#id. * numeric.c (fix_intern): added Fixnum#to_sym. [new] * object.c (sym_to_sym): rename from Symbol#intern * enum.c (enum_zip): added Enumerable#zip. [new] * array.c (rb_ary_zip): added Array#zip. * error.c (init_syserr): remove sys_nerr dependency. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3020 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'error.c')
-rw-r--r--error.c174
1 files changed, 24 insertions, 150 deletions
diff --git a/error.c b/error.c
index dfa9482794..d5a3480eec 100644
--- a/error.c
+++ b/error.c
@@ -13,6 +13,7 @@
#include "ruby.h"
#include "env.h"
#include "version.h"
+#include "st.h"
#include <stdio.h>
#ifdef HAVE_STDARG_PROTOTYPES
@@ -23,13 +24,6 @@
#define va_init_list(a,b) va_start(a)
#endif
-#if defined __CYGWIN__
-# include <cygwin/version.h>
-# if (CYGWIN_VERSION_API_MAJOR > 0) || (CYGWIN_VERSION_API_MINOR >= 8)
-# define sys_nerr _sys_nerr
-# endif
-#endif
-
int ruby_nerrs;
static void
@@ -458,99 +452,34 @@ rb_invalid_str(str, type)
rb_raise(rb_eArgError, "invalid value for %s: %s", type, RSTRING(s)->ptr);
}
-#ifdef __BEOS__
-typedef struct {
- VALUE *list;
- int n;
-} syserr_list_entry;
-
-typedef struct {
- int ix;
- int n;
-} syserr_index_entry;
-
-static VALUE syserr_error;
-static VALUE syserr_list_b_general[16+1];
-static VALUE syserr_list_b_os0[2+1];
-static VALUE syserr_list_b_os1[5+1];
-static VALUE syserr_list_b_os2[2+1];
-static VALUE syserr_list_b_os3[3+1];
-static VALUE syserr_list_b_os4[1+1];
-static VALUE syserr_list_b_app[15+1];
-static VALUE syserr_list_b_interface[0+1];
-static VALUE syserr_list_b_media[8+1];
-static VALUE syserr_list_b_midi[0+1];
-static VALUE syserr_list_b_storage[15+1];
-static VALUE syserr_list_b_posix[38+1];
-static VALUE syserr_list_b_mail[8+1];
-static VALUE syserr_list_b_print[1+1];
-static VALUE syserr_list_b_device[14+1];
-
-# define SYSERR_LIST_B(n) {(n), sizeof(n)/sizeof(VALUE)}
-static const syserr_list_entry syserr_list[] = {
- SYSERR_LIST_B(syserr_list_b_general),
- SYSERR_LIST_B(syserr_list_b_os0),
- SYSERR_LIST_B(syserr_list_b_os1),
- SYSERR_LIST_B(syserr_list_b_os2),
- SYSERR_LIST_B(syserr_list_b_os3),
- SYSERR_LIST_B(syserr_list_b_os4),
- SYSERR_LIST_B(syserr_list_b_app),
- SYSERR_LIST_B(syserr_list_b_interface),
- SYSERR_LIST_B(syserr_list_b_media),
- SYSERR_LIST_B(syserr_list_b_midi),
- SYSERR_LIST_B(syserr_list_b_storage),
- SYSERR_LIST_B(syserr_list_b_posix),
- SYSERR_LIST_B(syserr_list_b_mail),
- SYSERR_LIST_B(syserr_list_b_print),
- SYSERR_LIST_B(syserr_list_b_device),
-};
-# undef SYSERR_LIST_B
+static st_table *syserr_tbl = 0;
-static const syserr_index_entry syserr_index[]= {
- {0, 1}, {1, 5}, {6, 1}, {7, 1}, {8, 1}, {9, 1}, {10, 1}, {11, 1},
- {12, 1}, {13, 1}, {14, 1}, {0, 0},
-};
-#else
-static VALUE *syserr_list;
-#endif
+static VALUE
+set_syserr(n, name)
+ int n;
+ const char *name;
+{
+ VALUE error;
-#if !HAVE_DECL_SYS_NERR
-extern int sys_nerr;
-#endif
+ if (!st_lookup(syserr_tbl, n, &error)) {
+ error = rb_define_class_under(rb_mErrno, name, rb_eSystemCallError);;
+ rb_define_const(error, "Errno", INT2NUM(n));
+ st_add_direct(syserr_tbl, n, error);
+ }
+ return error;
+}
static VALUE
-set_syserr(i, name)
- int i;
- const char *name;
+get_syserr(int n)
{
-#ifdef __BEOS__
- VALUE *list;
- int ix, offset;
-#endif
- VALUE error = rb_define_class_under(rb_mErrno, name, rb_eSystemCallError);
- rb_define_const(error, "Errno", INT2NUM(i));
-#ifdef __BEOS__
- if (i == B_ERROR) {
- syserr_error = error;
- rb_global_variable(&syserr_error);
- return error;
- }
- i -= B_GENERAL_ERROR_BASE;
- ix = (i >> 12) & 0xf;
- offset = (i >> 8) & 0xf;
- if (offset < syserr_index[ix].n) {
- ix = syserr_index[ix].ix;
- if ((i & 0xff) < syserr_list[ix + offset].n) {
- list = syserr_list[ix + offset].list;
- list[i & 0xff] = error;
- rb_global_variable(&list[i & 0xff]);
- }
- }
-#else
- if (i <= sys_nerr) {
- syserr_list[i] = error;
+ VALUE error;
+
+ if (!st_lookup(syserr_tbl, n, &error)) {
+ char name[6];
+
+ sprintf(name, "E%03d", n);
+ error = set_syserr(n, name);
}
-#endif
return error;
}
@@ -584,28 +513,6 @@ syserr_eqq(self, exc)
return Qfalse;
}
-#ifdef __BEOS__
-static VALUE
-get_syserr(int i)
-{
- VALUE *list;
- int ix, offset;
-
- if (i == B_ERROR) return syserr_error;
- i -= B_GENERAL_ERROR_BASE;
- ix = (i >> 12) & 0xf;
- offset = (i >> 8) & 0xf;
- if (offset < syserr_index[ix].n) {
- ix = syserr_index[ix].ix;
- if ((i & 0xff) < syserr_list[ix + offset].n) {
- list = syserr_list[ix + offset].list;
- return list[i & 0xff];
- }
- }
- return 0;
-}
-#endif /* __BEOS__ */
-
static void init_syserr _((void));
void
@@ -746,25 +653,7 @@ rb_sys_fail(mesg)
}
errno = 0;
-#ifdef __BEOS__
ee = get_syserr(n);
- if (!ee) {
- char name[12];
-
- sprintf(name, "E%03d", n);
- ee = set_syserr(n, name);
- }
-#else
- if (n > sys_nerr || !syserr_list[n]) {
- char name[12];
-
- sprintf(name, "E%03d", n);
- ee = set_syserr(n, name);
- }
- else {
- ee = syserr_list[n];
- }
-#endif
ee = rb_exc_new2(ee, buf);
rb_iv_set(ee, "errno", INT2NUM(n));
rb_exc_raise(ee);
@@ -820,27 +709,12 @@ rb_check_frozen(obj)
static void
init_syserr()
{
-#ifdef __BEOS__
- int i, ix, offset;
-#endif
+ syserr_tbl = st_init_numtable();
rb_eSystemCallError = rb_define_class("SystemCallError", rb_eStandardError);
rb_define_method(rb_eSystemCallError, "errno", syserr_errno, 0);
rb_define_singleton_method(rb_eSystemCallError, "===", syserr_eqq, 1);
rb_mErrno = rb_define_module("Errno");
-#ifdef __BEOS__
- for (i = 0; syserr_index[i].n != 0; i++) {
- ix = syserr_index[i].ix;
- for (offset = 0; offset < syserr_index[i].n; offset++) {
- MEMZERO(syserr_list[ix + offset].list, VALUE, syserr_list[ix + offset].n);
- }
- }
- set_syserr(B_ERROR, "ERROR");
-#else
- syserr_list = ALLOC_N(VALUE, sys_nerr+1);
- MEMZERO(syserr_list, VALUE, sys_nerr+1);
-#endif
-
#ifdef EPERM
set_syserr(EPERM, "EPERM");
#endif