Skip to content

Commit

Permalink
* file.c (rb_find_file_ext): should not terminate searching with
Browse files Browse the repository at this point in the history
  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
  • Loading branch information
matz committed Nov 22, 2002
1 parent 8347974 commit e2d384d
Show file tree
Hide file tree
Showing 14 changed files with 103 additions and 91 deletions.
34 changes: 34 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 0 additions & 14 deletions array.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
46 changes: 22 additions & 24 deletions compar.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down
5 changes: 0 additions & 5 deletions dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions dln.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ void *xrealloc();

#ifdef HAVE_SYS_PARAM_H
# include <sys/param.h>
#else
# define MAXPATHLEN 1024
#endif

#ifdef HAVE_UNISTD_H
Expand Down Expand Up @@ -354,6 +352,10 @@ sym_hash(hdrp, syms)
return tbl;
}

#ifndef MAXPATHLEN
# define MAXPATHLEN 1024
#endif

static int
dln_init(prog)
const char *prog;
Expand Down
1 change: 0 additions & 1 deletion enum.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
5 changes: 2 additions & 3 deletions error.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
25 changes: 13 additions & 12 deletions file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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++;
Expand All @@ -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';
Expand All @@ -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();
Expand All @@ -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;
}
Expand All @@ -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)];
Expand All @@ -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--;
Expand Down Expand Up @@ -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 = '/';
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion intern.h
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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;
Expand Down
20 changes: 10 additions & 10 deletions lib/irb/locale.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions numeric.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,14 @@ num_eql(x, y)
return rb_equal(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;
Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit e2d384d

Please sign in to comment.