summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-11-22 09:14:24 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-11-22 09:14:24 +0000
commite2d384d628c8e4bd59300844e9111645d1070d5a (patch)
treecce3e69dea4b7f93481a4cdc5d16c61558cfa546
parent8347974c9fd6fcfd6af8d06f5c8ceca3bce76057 (diff)
* file.c (rb_find_file_ext): should not terminate searching with
empty path, just ignore. * dir.c: remove <sys/parm.h> inclusion. * compar.c (cmp_eq,cmp_gt,cmp_ge,cmp_lt,cmp_le): check using rb_cmpint(). * error.c (init_syserr): remove sys_nerr dependency. * numeric.c (num_cmp): added to satisfy Comparable assumption. * eval.c (rb_add_method): "initialize" should be public if it is a singleton method. * regex.c (re_match): avoid dereferencing if size == 0. (ruby-bugs-ja:PR#360) * 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3076 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog34
-rw-r--r--array.c14
-rw-r--r--compar.c46
-rw-r--r--dir.c5
-rw-r--r--dln.c6
-rw-r--r--enum.c1
-rw-r--r--error.c5
-rw-r--r--eval.c2
-rw-r--r--file.c25
-rw-r--r--intern.h3
-rw-r--r--lib/irb/locale.rb20
-rw-r--r--numeric.c9
-rw-r--r--regex.c1
-rw-r--r--time.c23
14 files changed, 103 insertions, 91 deletions
diff --git a/ChangeLog b/ChangeLog
index fa9342450d..668f8c7ab7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -20,6 +20,40 @@ Thu Nov 21 20:01:33 2002 Minero Aoki <aamine@loveruby.net>
* lib/net/http.rb: support Proxy-Authorization.
(This patch is contributed by Alexander Bokovoy)
+Thu Nov 21 11:03:39 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * 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 <matz@ruby-lang.org>
+
+ * 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 <matz@ruby-lang.org>
+
+ * 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 <matz@ruby-lang.org>
+
+ * regex.c (re_match): avoid dereferencing if size == 0.
+ (ruby-bugs-ja:PR#360)
+
+Tue Nov 19 20:40:39 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * 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 <matz@ruby-lang.org>
* array.c (rb_ary_zip): iterates over items in the receiver.
diff --git a/array.c b/array.c
index 9f6362d3d9..7b3dc52129 100644
--- a/array.c
+++ b/array.c
@@ -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;
diff --git a/compar.c b/compar.c
index 3647f9b376..65347e5f22 100644
--- a/compar.c
+++ b/compar.c
@@ -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;
}
diff --git a/dir.c b/dir.c
index fa1f6fbc39..0aa41fb89c 100644
--- a/dir.c
+++ b/dir.c
@@ -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
diff --git a/dln.c b/dln.c
index 3bb37f5790..c42badc73e 100644
--- a/dln.c
+++ b/dln.c
@@ -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;
diff --git a/enum.c b/enum.c
index 1200ce35e6..24b6e9e065 100644
--- a/enum.c
+++ b/enum.c
@@ -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));
}
diff --git a/error.c b/error.c
index d5a3480eec..edd86f065f 100644
--- a/error.c
+++ b/error.c
@@ -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);
}
diff --git a/eval.c b/eval.c
index 79cde66aa0..0dd0e207fa 100644
--- a/eval.c
+++ b/eval.c
@@ -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");
diff --git a/file.c b/file.c
index 565de7c2b6..04af8db766 100644
--- a/file.c
+++ b/file.c
@@ -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);
diff --git a/intern.h b/intern.h
index 3fcb60c43b..aa0d9e4b9d 100644
--- a/intern.h
+++ b/intern.h
@@ -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
diff --git a/numeric.c b/numeric.c
index 553573b51d..9bf953999a 100644
--- a/numeric.c
+++ b/numeric.c
@@ -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);
diff --git a/regex.c b/regex.c
index 8c795051a7..28fefcb228 100644
--- a/regex.c
+++ b/regex.c
@@ -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;
}
diff --git a/time.c b/time.c
index 30b13fb674..adb92c7eba 100644
--- a/time.c
+++ b/time.c
@@ -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