summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog26
-rw-r--r--array.c28
-rw-r--r--enum.c58
-rw-r--r--error.c174
-rw-r--r--eval.c4
-rw-r--r--lib/ostruct.rb13
-rw-r--r--misc/ruby-mode.el7
-rw-r--r--numeric.c13
-rw-r--r--object.c15
-rw-r--r--string.c1
10 files changed, 173 insertions, 166 deletions
diff --git a/ChangeLog b/ChangeLog
index 6bf80f8e0d..646e179aa3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,29 @@
+Sat Nov 2 00:38:55 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * 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
+
+Fri Nov 1 14:21:06 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * enum.c (enum_zip): added Enumerable#zip. [new]
+
+ * array.c (rb_ary_zip): added Array#zip.
+
+Thu Oct 31 20:10:18 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * error.c (init_syserr): remove sys_nerr dependency.
+
+Thu Oct 31 09:31:51 2002 K.Kosako <kosako@sofnec.co.jp>
+
+ * eval.c (rb_export_method): undef'ed method visibility should not
+ be changed.
+
Wed Oct 30 17:00:47 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (rb_mod_public_method_defined, etc.): new methods:
diff --git a/array.c b/array.c
index ee59769a5c..bed2390282 100644
--- a/array.c
+++ b/array.c
@@ -1300,6 +1300,33 @@ rb_ary_delete_if(ary)
}
static VALUE
+rb_ary_zip(argc, argv, ary)
+ int argc;
+ VALUE *argv;
+ VALUE ary;
+{
+ int i, j, len;
+ VALUE result;
+
+ len = RARRAY(ary)->len;
+ for (i=0; i<argc; i++) {
+ argv[i] = to_ary(argv[i]);
+ if (RARRAY(argv[i])->len > len) len = RARRAY(argv[i])->len;
+ }
+ result = rb_ary_new2(len);
+ for (i=0; i<len; i++) {
+ VALUE tmp = rb_ary_new2(argc+1);
+
+ rb_ary_push(tmp, rb_ary_entry(ary, i));
+ for (j=0; j<argc; j++) {
+ rb_ary_push(tmp, rb_ary_entry(argv[j], i));
+ }
+ rb_ary_push(result, tmp);
+ }
+ return result;
+}
+
+static VALUE
rb_ary_replace(copy, orig)
VALUE copy, orig;
{
@@ -1865,6 +1892,7 @@ Init_Array()
rb_define_method(rb_cArray, "delete_if", rb_ary_delete_if, 0);
rb_define_method(rb_cArray, "reject", rb_ary_reject, 0);
rb_define_method(rb_cArray, "reject!", rb_ary_reject_bang, 0);
+ rb_define_method(rb_cArray, "zip", rb_ary_zip, -1);
rb_define_method(rb_cArray, "replace", rb_ary_replace, 1);
rb_define_method(rb_cArray, "clear", rb_ary_clear, 0);
rb_define_method(rb_cArray, "fill", rb_ary_fill, -1);
diff --git a/enum.c b/enum.c
index c8831fb7b9..c5191fdfba 100644
--- a/enum.c
+++ b/enum.c
@@ -486,6 +486,63 @@ enum_each_with_index(obj)
return obj;
}
+static VALUE
+zip_i(val, memo)
+ VALUE val;
+ NODE *memo;
+{
+ VALUE ary = memo->u1.value;
+ int i = memo->u3.cnt++;
+ int elen = memo->u2.argc+1;
+ VALUE tmp;
+
+ if (i < RARRAY(ary)->len) {
+ tmp = RARRAY(ary)->ptr[i];
+ RARRAY(tmp)->ptr[0] = val;
+ }
+ else {
+ tmp = rb_ary_new2(elen);
+ RARRAY(tmp)->ptr[0] = val;
+ for (i=1; i<elen; i++) {
+ RARRAY(tmp)->ptr[i] = Qnil;
+ }
+ RARRAY(tmp)->len = elen;
+ rb_ary_push(ary, tmp);
+ }
+ return Qnil;
+}
+
+static VALUE
+enum_zip(argc, argv, obj)
+ int argc;
+ VALUE *argv;
+ VALUE obj;
+{
+ int i, j, len;
+ VALUE result;
+ NODE *memo;
+
+ len = 0;
+ for (i=0; i<argc; i++) {
+ argv[i] = rb_convert_type(argv[i], T_ARRAY, "Array", "to_ary");
+ if (RARRAY(argv[i])->len > len) len = RARRAY(argv[i])->len;
+ }
+ result = rb_ary_new2(len);
+ for (i=0; i<len; i++) {
+ VALUE tmp = rb_ary_new2(argc+1);
+
+ rb_ary_push(tmp, Qnil);
+ for (j=0; j<argc; j++) {
+ rb_ary_push(tmp, rb_ary_entry(argv[j], i));
+ }
+ rb_ary_push(result, tmp);
+ }
+ memo = rb_node_newnode(NODE_MEMO, result, argc, 0);
+ rb_iterate(rb_each, obj, zip_i, (VALUE)memo);
+
+ return result;
+}
+
void
Init_Enumerable()
{
@@ -513,6 +570,7 @@ Init_Enumerable()
rb_define_method(rb_mEnumerable,"member?", enum_member, 1);
rb_define_method(rb_mEnumerable,"include?", enum_member, 1);
rb_define_method(rb_mEnumerable,"each_with_index", enum_each_with_index, 0);
+ rb_define_method(rb_mEnumerable, "zip", enum_zip, -1);
id_eqq = rb_intern("===");
id_each = rb_intern("each");
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
diff --git a/eval.c b/eval.c
index c39ece1804..ff8e6f2ad4 100644
--- a/eval.c
+++ b/eval.c
@@ -428,7 +428,7 @@ rb_export_method(klass, name, noex)
if (!body && TYPE(klass) == T_MODULE) {
body = search_method(rb_cObject, name, &origin);
}
- if (!body) {
+ if (!body || !body->nd_body) {
print_undef(klass, name);
}
if (body->nd_noex != noex) {
@@ -9367,7 +9367,7 @@ rb_cont_call(argc, argv, cont)
th->result = Qnil;
break;
case 1:
- th->result = *argv;
+ th->result = argv[0];
break;
default:
th->result = rb_ary_new4(argc, argv);
diff --git a/lib/ostruct.rb b/lib/ostruct.rb
index 9106f6e068..a5c51022d4 100644
--- a/lib/ostruct.rb
+++ b/lib/ostruct.rb
@@ -13,7 +13,7 @@ class OpenStruct
@table = {}
if hash
for k,v in hash
- @table[k] = v
+ @table[k] = v.to_sym
end
end
end
@@ -26,19 +26,16 @@ class OpenStruct
raise ArgumentError, "wrong # of arguments (#{len} for 1)", caller(1)
end
mname.chop!
- @table[mname] = args[0]
+ @table[mname.intern] = args[0]
elsif args.length == 0
- @table[mname]
+ @table[mid]
else
raise NameError, "undefined method `#{mname}'", caller(1)
end
end
-
+
def delete_field(name)
- if name.class == Fixnum
- name = name.id2name
- end
- @table.delete name
+ @table.delete name.to_sym
end
def inspect
diff --git a/misc/ruby-mode.el b/misc/ruby-mode.el
index 411e4af936..408b123680 100644
--- a/misc/ruby-mode.el
+++ b/misc/ruby-mode.el
@@ -866,6 +866,10 @@ An end of a defun is found by moving forward from the beginning of one."
(defvar ruby-font-lock-keywords
(list
+ ;; functions
+ '("^\\s *def\\s +\\([^( ]+\\)"
+ 1 font-lock-function-name-face)
+ ;; keywords
(cons (concat
"\\(^\\|[^_:.@$]\\|\\.\\.\\)\\b\\("
(mapconcat
@@ -925,9 +929,6 @@ An end of a defun is found by moving forward from the beginning of one."
;; constants
'("\\(^\\|[^_]\\)\\b\\([A-Z]+\\(\\w\\|_\\)*\\)"
2 font-lock-type-face)
- ;; functions
- '("^\\s *def\\s +\\([^( ]+\\)"
- 1 font-lock-function-name-face)
;; symbols
'("\\(^\\|[^:]\\)\\(:\\([-+~]@?\\|[/%&|^`]\\|\\*\\*?\\|<\\(<\\|=>?\\)?\\|>[>=]?\\|===?\\|=~\\|\\[\\]=?\\|\\(\\w\\|_\\)+\\([!?=]\\|\\b_*\\)\\|#{[^}\n\\\\]*\\(\\\\.[^}\n\\\\]*\\)*}\\)\\)"
2 font-lock-reference-face)
diff --git a/numeric.c b/numeric.c
index 020fcf6ab0..553573b51d 100644
--- a/numeric.c
+++ b/numeric.c
@@ -1525,6 +1525,18 @@ fix_id2name(fix)
}
static VALUE
+fix_to_sym(fix)
+ VALUE fix;
+{
+ ID id = FIX2UINT(fix);
+
+ if (rb_id2name(id)) {
+ return ID2SYM(id);
+ }
+ return Qnil;
+}
+
+static VALUE
fix_size(fix)
VALUE fix;
{
@@ -1680,6 +1692,7 @@ Init_Numeric()
rb_define_method(rb_cFixnum, "to_s", fix_to_s, -1);
rb_define_method(rb_cFixnum, "id2name", fix_id2name, 0);
+ rb_define_method(rb_cFixnum, "to_sym", fix_to_sym, 0);
rb_define_method(rb_cFixnum, "-@", fix_uminus, 0);
rb_define_method(rb_cFixnum, "+", fix_plus, 1);
diff --git a/object.c b/object.c
index 27e6987b83..80d2d65236 100644
--- a/object.c
+++ b/object.c
@@ -74,6 +74,14 @@ rb_obj_id(obj)
}
VALUE
+rb_obj_id_obsolete(obj)
+ VALUE obj;
+{
+ rb_warning("Object#id will be deprecated; use Object#object_id");
+ return rb_obj_id(obj);
+}
+
+VALUE
rb_class_real(cl)
VALUE cl;
{
@@ -540,7 +548,7 @@ sym_to_s(sym)
}
static VALUE
-sym_intern(sym)
+sym_to_sym(sym)
VALUE sym;
{
return sym;
@@ -1316,8 +1324,9 @@ Init_Object()
rb_define_method(rb_mKernel, "eql?", rb_obj_equal, 1);
rb_define_method(rb_mKernel, "hash", rb_obj_id, 0);
- rb_define_method(rb_mKernel, "id", rb_obj_id, 0);
+ rb_define_method(rb_mKernel, "id", rb_obj_id_obsolete, 0);
rb_define_method(rb_mKernel, "__id__", rb_obj_id, 0);
+ rb_define_method(rb_mKernel, "object_id", rb_obj_id, 0);
rb_define_method(rb_mKernel, "type", rb_obj_type, 0);
rb_define_method(rb_mKernel, "class", rb_obj_class, 0);
@@ -1386,7 +1395,7 @@ Init_Object()
rb_define_method(rb_cSymbol, "inspect", sym_inspect, 0);
rb_define_method(rb_cSymbol, "to_s", sym_to_s, 0);
rb_define_method(rb_cSymbol, "id2name", sym_to_s, 0);
- rb_define_method(rb_cSymbol, "intern", sym_intern, 0);
+ rb_define_method(rb_cSymbol, "to_sym", sym_to_sym, 0);
rb_define_method(rb_cModule, "===", rb_mod_eqq, 1);
rb_define_method(rb_cModule, "==", rb_obj_equal, 1);
diff --git a/string.c b/string.c
index 3f1445fb5e..e5aa6e2ce7 100644
--- a/string.c
+++ b/string.c
@@ -3208,6 +3208,7 @@ Init_String()
rb_define_method(rb_cString, "<<", rb_str_concat, 1);
rb_define_method(rb_cString, "crypt", rb_str_crypt, 1);
rb_define_method(rb_cString, "intern", rb_str_intern, 0);
+ rb_define_method(rb_cString, "to_sym", rb_str_intern, 0);
rb_define_method(rb_cString, "include?", rb_str_include, 1);