From aae36756dcc4d5debcaabd03379796bc41360bc4 Mon Sep 17 00:00:00 2001 From: matz Date: Sun, 3 Nov 2002 11:04:35 +0000 Subject: * 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 --- ChangeLog | 26 ++++++++ array.c | 28 +++++++++ enum.c | 58 ++++++++++++++++++ error.c | 174 ++++++++---------------------------------------------- eval.c | 4 +- lib/ostruct.rb | 13 ++-- misc/ruby-mode.el | 7 ++- numeric.c | 13 ++++ object.c | 15 ++++- string.c | 1 + 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 + + * 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 + + * 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 + + * error.c (init_syserr): remove sys_nerr dependency. + +Thu Oct 31 09:31:51 2002 K.Kosako + + * eval.c (rb_export_method): undef'ed method visibility should not + be changed. + Wed Oct 30 17:00:47 2002 Yukihiro Matsumoto * 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 @@ -1299,6 +1299,33 @@ rb_ary_delete_if(ary) return 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; ilen > len) len = RARRAY(argv[i])->len; + } + result = rb_ary_new2(len); + for (i=0; iu1.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; iptr[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; ilen > len) len = RARRAY(argv[i])->len; + } + result = rb_ary_new2(len); + for (i=0; i #ifdef HAVE_STDARG_PROTOTYPES @@ -23,13 +24,6 @@ #define va_init_list(a,b) va_start(a) #endif -#if defined __CYGWIN__ -# include -# 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 @@ -1524,6 +1524,18 @@ fix_id2name(fix) return Qnil; } +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 @@ -73,6 +73,14 @@ rb_obj_id(obj) return (VALUE)((long)obj|FIXNUM_FLAG); } +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); -- cgit v1.2.3