Permalink
Browse files

* 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: http://svn.ruby-lang.org/repos/ruby/trunk@3076 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
1 parent c5c1bc0 commit 33a031bcbb66d412691c5dcbb5060841d18f31b3 matz committed Nov 22, 2002
Showing with 103 additions and 91 deletions.
  1. +34 −0 ChangeLog
  2. +0 −14 array.c
  3. +22 −24 compar.c
  4. +0 −5 dir.c
  5. +4 −2 dln.c
  6. +0 −1 enum.c
  7. +2 −3 error.c
  8. +1 −1 eval.c
  9. +13 −12 file.c
  10. +2 −1 intern.h
  11. +10 −10 lib/irb/locale.rb
  12. +9 −0 numeric.c
  13. +1 −0 regex.c
  14. +5 −18 time.c
View
@@ -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.
View
@@ -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;
View
@@ -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;
}
View
@@ -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
View
@@ -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;
View
@@ -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));
}
View
@@ -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);
}
View
@@ -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");
View
@@ -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,15 +1485,15 @@ 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;
}
else {
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);
View
@@ -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;
View
@@ -27,20 +27,20 @@ def initialize(locale = nil)
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
View
@@ -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);
Oops, something went wrong.

0 comments on commit 33a031b

Please sign in to comment.