diff options
-rw-r--r-- | ChangeLog | 34 | ||||
-rw-r--r-- | array.c | 14 | ||||
-rw-r--r-- | compar.c | 46 | ||||
-rw-r--r-- | dir.c | 5 | ||||
-rw-r--r-- | dln.c | 6 | ||||
-rw-r--r-- | enum.c | 1 | ||||
-rw-r--r-- | error.c | 5 | ||||
-rw-r--r-- | eval.c | 2 | ||||
-rw-r--r-- | file.c | 25 | ||||
-rw-r--r-- | intern.h | 3 | ||||
-rw-r--r-- | lib/irb/locale.rb | 20 | ||||
-rw-r--r-- | numeric.c | 9 | ||||
-rw-r--r-- | regex.c | 1 | ||||
-rw-r--r-- | time.c | 23 |
14 files changed, 103 insertions, 91 deletions
@@ -20,6 +20,40 @@ Thu Nov 21 20:01:33 2002 Minero Aoki <[email protected]> * lib/net/http.rb: support Proxy-Authorization. (This patch is contributed by Alexander Bokovoy) +Thu Nov 21 11:03:39 2002 Yukihiro Matsumoto <[email protected]> + + * file.c (rb_find_file_ext): should not terminate searching with + empty path, just ignore. + + * dir.c: remove <sys/parm.h> inclusion. + +Wed Nov 20 02:07:12 2002 Yukihiro Matsumoto <[email protected]> + + * compar.c (cmp_eq,cmp_gt,cmp_ge,cmp_lt,cmp_le): check using + rb_cmpint(). + + * error.c (init_syserr): remove sys_nerr dependency. + +Wed Nov 20 01:52:21 2002 Yukihiro Matsumoto <[email protected]> + + * numeric.c (num_cmp): added to satisfy Comparable assumption. + + * eval.c (rb_add_method): "initialize" should be public if it is a + singleton method. + +Tue Nov 19 22:37:23 2002 Yukihiro Matsumoto <[email protected]> + + * regex.c (re_match): avoid dereferencing if size == 0. + (ruby-bugs-ja:PR#360) + +Tue Nov 19 20:40:39 2002 Yukihiro Matsumoto <[email protected]> + + * time.c (time_cmp): should return nil if an operand is not a + number nor time. (ruby-bugs-ja:PR#359) + + * file.c (rb_stat_cmp): should return nil if an operand is not + File::Stat. + Tue Nov 19 14:35:09 2002 Yukihiro Matsumoto <[email protected]> * array.c (rb_ary_zip): iterates over items in the receiver. @@ -1029,20 +1029,6 @@ rb_ary_reverse_m(ary) return rb_ary_reverse(rb_ary_dup(ary)); } -int -rb_cmpint(cmp) - VALUE cmp; -{ - if (FIXNUM_P(cmp)) return FIX2INT(cmp); - if (TYPE(cmp) == T_BIGNUM) { - if (RBIGNUM(cmp)->sign) return 1; - return -1; - } - if (RTEST(rb_funcall(cmp, '>', 1, INT2FIX(0)))) return 1; - if (RTEST(rb_funcall(cmp, '<', 1, INT2FIX(0)))) return -1; - return 0; -} - static int sort_1(a, b) VALUE *a, *b; @@ -16,17 +16,31 @@ VALUE rb_mComparable; static ID cmp; +int +rb_cmpint(val) + VALUE val; +{ + if (FIXNUM_P(val)) return FIX2INT(val); + if (TYPE(val) == T_BIGNUM) { + if (RBIGNUM(val)->sign) return 1; + return -1; + } + if (RTEST(rb_funcall(val, '>', 1, INT2FIX(0)))) return 1; + if (RTEST(rb_funcall(val, '<', 1, INT2FIX(0)))) return -1; + return 0; +} + static VALUE cmp_equal(x, y) VALUE x, y; { - VALUE c = rb_funcall(x, cmp, 1, y); + int c; + if (x == y) return Qtrue; + c = rb_funcall(x, cmp, 1, y); if (NIL_P(c)) return Qfalse; if (c == INT2FIX(0)) return Qtrue; - if (TYPE(c) == T_BIGNUM) { - if (rb_big_norm(c) == INT2FIX(0)) return Qtrue; - } + if (rb_cmpint(c) == 0) return Qtrue; return Qfalse; } @@ -37,11 +51,7 @@ cmp_gt(x, y) VALUE c = rb_funcall(x, cmp, 1, y); if (NIL_P(c)) return Qfalse; - if (FIXNUM_P(c) && FIX2INT(c) > 0) return Qtrue; - if (TYPE(c) == T_BIGNUM) { - if (rb_big_norm(x) == INT2FIX(0)) return Qfalse; - if (RBIGNUM(c)->sign) return Qtrue; - } + if (rb_cmpint(c) > 0) return Qtrue; return Qfalse; } @@ -52,11 +62,7 @@ cmp_ge(x, y) VALUE c = rb_funcall(x, cmp, 1, y); if (NIL_P(c)) return Qfalse; - if (FIXNUM_P(c) && FIX2INT(c) >= 0) return Qtrue; - if (TYPE(c) == T_BIGNUM) { - if (rb_big_norm(x) == INT2FIX(0)) return Qtrue; - if (RBIGNUM(c)->sign) return Qtrue; - } + if (rb_cmpint(c) >= 0) return Qtrue; return Qfalse; } @@ -66,11 +72,7 @@ cmp_lt(x, y) { VALUE c = rb_funcall(x, cmp, 1, y); - if (FIXNUM_P(c) && FIX2INT(c) < 0) return Qtrue; - if (TYPE(c) == T_BIGNUM) { - if (rb_big_norm(x) == INT2FIX(0)) return Qfalse; - if (!RBIGNUM(c)->sign) return Qtrue; - } + if (rb_cmpint(c) < 0) return Qtrue; return Qfalse; } @@ -81,11 +83,7 @@ cmp_le(x, y) VALUE c = rb_funcall(x, cmp, 1, y); if (NIL_P(c)) return Qfalse; - if (FIXNUM_P(c) && FIX2INT(c) <= 0) return Qtrue; - if (TYPE(c) == T_BIGNUM) { - if (rb_big_norm(x) == INT2FIX(0)) return Qtrue; - if (!RBIGNUM(c)->sign) return Qtrue; - } + if (rb_cmpint(c) <= 0) return Qtrue; return Qfalse; } @@ -17,11 +17,6 @@ #include <sys/types.h> #include <sys/stat.h> -#ifdef HAVE_SYS_PARAM_H -# include <sys/param.h> -#else -# define MAXPATHLEN 1024 -#endif #ifdef HAVE_UNISTD_H #include <unistd.h> #endif @@ -60,8 +60,6 @@ void *xrealloc(); #ifdef HAVE_SYS_PARAM_H # include <sys/param.h> -#else -# define MAXPATHLEN 1024 #endif #ifdef HAVE_UNISTD_H @@ -354,6 +352,10 @@ sym_hash(hdrp, syms) return tbl; } +#ifndef MAXPATHLEN +# define MAXPATHLEN 1024 +#endif + static int dln_init(prog) const char *prog; @@ -499,7 +499,6 @@ zip_i(val, memo) tmp = rb_ary_new2(RARRAY(args)->len + 1); rb_ary_store(tmp, 0, val); - RARRAY(tmp)->ptr[0] = val; for (i=0; i<RARRAY(args)->len; i++) { rb_ary_push(tmp, rb_ary_entry(RARRAY(args)->ptr[i], idx)); } @@ -452,7 +452,7 @@ rb_invalid_str(str, type) rb_raise(rb_eArgError, "invalid value for %s: %s", type, RSTRING(s)->ptr); } -static st_table *syserr_tbl = 0; +static st_table *syserr_tbl; static VALUE set_syserr(n, name) @@ -653,8 +653,7 @@ rb_sys_fail(mesg) } errno = 0; - ee = get_syserr(n); - ee = rb_exc_new2(ee, buf); + ee = rb_exc_new2(get_syserr(n), buf); rb_iv_set(ee, "errno", INT2NUM(n)); rb_exc_raise(ee); } @@ -247,7 +247,7 @@ rb_add_method(klass, mid, node, noex) if (ruby_safe_level >= 4 && (klass == rb_cObject || !OBJ_TAINTED(klass))) { rb_raise(rb_eSecurityError, "Insecure: can't define method"); } - if (mid == init) { + if (mid == init && !FL_TEST(klass, FL_SINGLETON) && nd_type(node) != NODE_ZSUPER) { noex = NOEX_PRIVATE | (noex & NOEX_NOSUPER); } if (OBJ_FROZEN(klass)) rb_error_frozen("class/module"); @@ -34,7 +34,8 @@ int flock _((int, int)); #ifdef HAVE_SYS_PARAM_H # include <sys/param.h> -#else +#endif +#ifndef MAXPATHLEN # define MAXPATHLEN 1024 #endif @@ -158,7 +159,7 @@ rb_stat_cmp(self, other) else return INT2FIX(1); } - rb_raise(rb_eTypeError, "operand is not File::Stat"); + return Qnil; } static VALUE @@ -1436,7 +1437,7 @@ rb_file_s_expand_path(argc, argv) if (!dir) { rb_raise(rb_eArgError, "couldn't find HOME environment -- expanding `%s'", s); } - BUFCHECK (strlen(dir) > buflen); + BUFCHECK(strlen(dir) > buflen); strcpy(buf, dir); p = buf + strlen(dir); s++; @@ -1451,7 +1452,7 @@ rb_file_s_expand_path(argc, argv) while (*s && !isdirsep(*s)) { s = CharNext(s); } - BUFCHECK (p + (s-b) >= pend); + BUFCHECK(p + (s-b) >= pend); memcpy(p, b, s-b); p += s-b; *p = '\0'; @@ -1461,7 +1462,7 @@ rb_file_s_expand_path(argc, argv) endpwent(); rb_raise(rb_eArgError, "user %s doesn't exist", buf); } - BUFCHECK (strlen(pwPtr->pw_dir) > buflen); + BUFCHECK(strlen(pwPtr->pw_dir) > buflen); strcpy(buf, pwPtr->pw_dir); p = buf + strlen(pwPtr->pw_dir); endpwent(); @@ -1475,7 +1476,7 @@ rb_file_s_expand_path(argc, argv) while (*s && !isdirsep(*s)) { s = CharNext(s); } - BUFCHECK (p + (s-b) >= pend); + BUFCHECK(p + (s-b) >= pend); memcpy(p, b, s-b); p += s-b; } @@ -1484,7 +1485,7 @@ rb_file_s_expand_path(argc, argv) if (!NIL_P(dname)) { dname = rb_file_s_expand_path(1, &dname); if (OBJ_TAINTED(dname)) tainted = 1; - BUFCHECK (RSTRING(dname)->len > buflen); + BUFCHECK(RSTRING(dname)->len > buflen); memcpy(buf, RSTRING(dname)->ptr, RSTRING(dname)->len); p += RSTRING(dname)->len; } @@ -1492,7 +1493,7 @@ rb_file_s_expand_path(argc, argv) char *dir = my_getcwd(); tainted = 1; - BUFCHECK (strlen(dir) > buflen); + BUFCHECK(strlen(dir) > buflen); strcpy(buf, dir); free(dir); p = &buf[strlen(buf)]; @@ -1502,7 +1503,7 @@ rb_file_s_expand_path(argc, argv) else { while (*s && isdirsep(*s)) { *p++ = '/'; - BUFCHECK (p >= pend); + BUFCHECK(p >= pend); s++; } if (p > buf && *s) p--; @@ -1548,7 +1549,7 @@ rb_file_s_expand_path(argc, argv) case '\\': #endif if (s > b) { - BUFCHECK (p + (s-b+1) >= pend); + BUFCHECK(p + (s-b+1) >= pend); memcpy(++p, b, s-b); p += s-b; *p = '/'; @@ -1562,7 +1563,7 @@ rb_file_s_expand_path(argc, argv) } if (s > b) { - BUFCHECK (p + (s-b) >= pend); + BUFCHECK(p + (s-b) >= pend); memcpy(++p, b, s-b); p += s-b; } @@ -2476,7 +2477,7 @@ rb_find_file_ext(filep, ext) VALUE str = RARRAY(rb_load_path)->ptr[i]; SafeStringValue(str); - if (RSTRING(str)->len == 0) return 0; + if (RSTRING(str)->len == 0) continue; path = RSTRING(str)->ptr; for (j=0; ext[j]; j++) { fname = rb_str_dup(*filep); @@ -40,7 +40,6 @@ VALUE rb_ary_join _((VALUE, VALUE)); VALUE rb_ary_print_on _((VALUE, VALUE)); VALUE rb_ary_reverse _((VALUE)); VALUE rb_ary_sort _((VALUE)); -int rb_cmpint _((VALUE)); VALUE rb_ary_sort_bang _((VALUE)); VALUE rb_ary_delete _((VALUE, VALUE)); VALUE rb_ary_delete_at _((VALUE, long)); @@ -118,6 +117,8 @@ void rb_define_private_method _((VALUE, const char*, VALUE (*)(ANYARGS), int)); void rb_define_singleton_method _((VALUE, const char*, VALUE(*)(ANYARGS), int)); void rb_define_private_method _((VALUE, const char*, VALUE(*)(ANYARGS), int)); VALUE rb_singleton_class _((VALUE)); +/* compar.c */ +int rb_cmpint _((VALUE)); /* enum.c */ /* error.c */ EXTERN int ruby_nerrs; diff --git a/lib/irb/locale.rb b/lib/irb/locale.rb index 0e36359f5b..dad6b2f075 100644 --- a/lib/irb/locale.rb +++ b/lib/irb/locale.rb @@ -27,20 +27,20 @@ module IRB attr_reader :lang + @@LC2KCONV = { + # "ja" => Kconv::JIS, + # "ja_JP" => Kconv::JIS, + "ja_JP.ujis" => Kconv::EUC, + "ja_JP.euc" => Kconv::EUC, + "ja_JP.eucJP" => Kconv::EUC, + "ja_JP.sjis" => Kconv::SJIS, + "ja_JP.SJIS" => Kconv::SJIS, + } + def String(mes) mes = super(mes) case @lang when /^ja/ - @@LC2KCONV = { - # "ja" => Kconv::JIS, - # "ja_JP" => Kconv::JIS, - "ja_JP.ujis" => Kconv::EUC, - "ja_JP.euc" => Kconv::EUC, - "ja_JP.eucJP" => Kconv::EUC, - "ja_JP.sjis" => Kconv::SJIS, - "ja_JP.SJIS" => Kconv::SJIS, - } unless defined? @@LC2KCONV - mes = Kconv::kconv(mes, @@LC2KCONV[@lang]) else mes @@ -438,6 +438,14 @@ num_eql(x, y) } static VALUE +num_cmp(x, y) + VALUE x, y; +{ + if (x == y) return INT2FIX(0); + return Qnil; +} + +static VALUE num_equal(x, y) VALUE x, y; { @@ -1647,6 +1655,7 @@ Init_Numeric() rb_define_method(rb_cNumeric, "+@", num_uplus, 0); rb_define_method(rb_cNumeric, "-@", num_uminus, 0); rb_define_method(rb_cNumeric, "===", num_equal, 1); + rb_define_method(rb_cNumeric, "<=>", num_cmp, 1); rb_define_method(rb_cNumeric, "eql?", num_eql, 1); rb_define_method(rb_cNumeric, "/", num_div, 1); rb_define_method(rb_cNumeric, "divmod", num_divmod, 1); @@ -4121,6 +4121,7 @@ re_match(bufp, string_arg, size, pos, regs) case wordbound: if (AT_STRINGS_BEG(d)) { + if (AT_STRINGS_END(d)) goto fail; if (IS_A_LETTER(d)) break; else goto fail; } @@ -713,6 +713,10 @@ time_cmp(time1, time2) case T_FLOAT: return rb_dbl_cmp((double)tobj1->tv.tv_sec + (double)tobj1->tv.tv_usec*1e-6, RFLOAT(time2)->value); + + case T_BIGNUM: + return rb_dbl_cmp((double)tobj1->tv.tv_sec + (double)tobj1->tv.tv_usec*1e-6, + rb_big2dbl(time2)); } if (TYPE(time2) == T_DATA && RDATA(time2)->dfree == time_free) { @@ -725,24 +729,7 @@ time_cmp(time1, time2) if (tobj1->tv.tv_sec > tobj2->tv.tv_sec) return INT2FIX(1); return INT2FIX(-1); } - if (TYPE(time2) == T_BIGNUM) { - double a = (double)tobj1->tv.tv_sec+(double)tobj1->tv.tv_usec/1e6; - double b = rb_big2dbl(time2); - - if (a == b) return INT2FIX(0); - if (a > b) return INT2FIX(1); - if (a < b) return INT2FIX(-1); - } - i = NUM2LONG(time2); - if (tobj1->tv.tv_sec == i) { - if (tobj1->tv.tv_usec == 0) - return INT2FIX(0); - if (tobj1->tv.tv_usec > 0) - return INT2FIX(1); - return INT2FIX(-1); - } - if (tobj1->tv.tv_sec > i) return INT2FIX(1); - return INT2FIX(-1); + return Qnil; } static VALUE |