mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* string.c (rb_str_cmp_m): return nil if str2 does not respond to
both "to_str" and "<=>". * compar.c (cmp_gt): return nil if "<=>" returns nil (means incomparable). * compar.c (cmp_ge): ditto. * compar.c (cmp_lt): ditto. * compar.c (cmp_between): use RTEST(), since cmp_lt and cmp_gt may return nil. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3517 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
697462490a
commit
64db238388
4 changed files with 41 additions and 12 deletions
15
ChangeLog
15
ChangeLog
|
@ -1,3 +1,18 @@
|
|||
Fri Feb 21 05:16:14 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* string.c (rb_str_cmp_m): return nil if str2 does not respond to
|
||||
both "to_str" and "<=>".
|
||||
|
||||
* compar.c (cmp_gt): return nil if "<=>" returns nil (means
|
||||
incomparable).
|
||||
|
||||
* compar.c (cmp_ge): ditto.
|
||||
|
||||
* compar.c (cmp_lt): ditto.
|
||||
|
||||
* compar.c (cmp_between): use RTEST(), since cmp_lt and cmp_gt may
|
||||
return nil.
|
||||
|
||||
Thu Feb 20 19:05:51 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* eval.c (rb_thread_remove): thread may die in the process of
|
||||
|
|
12
compar.c
12
compar.c
|
@ -50,7 +50,7 @@ cmp_gt(x, y)
|
|||
{
|
||||
VALUE c = rb_funcall(x, cmp, 1, y);
|
||||
|
||||
if (NIL_P(c)) return Qfalse;
|
||||
if (NIL_P(c)) return Qnil;
|
||||
if (rb_cmpint(c) > 0) return Qtrue;
|
||||
return Qfalse;
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ cmp_ge(x, y)
|
|||
{
|
||||
VALUE c = rb_funcall(x, cmp, 1, y);
|
||||
|
||||
if (NIL_P(c)) return Qfalse;
|
||||
if (NIL_P(c)) return Qnil;
|
||||
if (rb_cmpint(c) >= 0) return Qtrue;
|
||||
return Qfalse;
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ cmp_lt(x, y)
|
|||
{
|
||||
VALUE c = rb_funcall(x, cmp, 1, y);
|
||||
|
||||
if (NIL_P(c)) return Qfalse;
|
||||
if (NIL_P(c)) return Qnil;
|
||||
if (rb_cmpint(c) < 0) return Qtrue;
|
||||
return Qfalse;
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ cmp_le(x, y)
|
|||
{
|
||||
VALUE c = rb_funcall(x, cmp, 1, y);
|
||||
|
||||
if (NIL_P(c)) return Qfalse;
|
||||
if (NIL_P(c)) return Qnil;
|
||||
if (rb_cmpint(c) <= 0) return Qtrue;
|
||||
return Qfalse;
|
||||
}
|
||||
|
@ -92,8 +92,8 @@ static VALUE
|
|||
cmp_between(x, min, max)
|
||||
VALUE x, min, max;
|
||||
{
|
||||
if (cmp_lt(x, min)) return Qfalse;
|
||||
if (cmp_gt(x, max)) return Qfalse;
|
||||
if (RTEST(cmp_lt(x, min))) return Qfalse;
|
||||
if (RTEST(cmp_gt(x, max))) return Qfalse;
|
||||
return Qtrue;
|
||||
}
|
||||
|
||||
|
|
2
parse.y
2
parse.y
|
@ -3700,7 +3700,7 @@ yylex()
|
|||
}
|
||||
pushback(c);
|
||||
if (ISDIGIT(c)) {
|
||||
rb_warning("no .<digit> floating literal anymore; put 0 before dot");
|
||||
yyerror("no .<digit> floating literal anymore; put 0 before dot");
|
||||
}
|
||||
lex_state = EXPR_DOT;
|
||||
return '.';
|
||||
|
|
24
string.c
24
string.c
|
@ -804,14 +804,28 @@ static VALUE
|
|||
rb_str_cmp_m(str1, str2)
|
||||
VALUE str1, str2;
|
||||
{
|
||||
int result;
|
||||
long result;
|
||||
|
||||
if (TYPE(str2) != T_STRING) {
|
||||
str2 = rb_check_string_type(str2);
|
||||
if (NIL_P(str2)) return Qnil;
|
||||
if (!rb_respond_to(str2, rb_intern("to_str"))) {
|
||||
return Qnil;
|
||||
}
|
||||
else if (!rb_respond_to(str2, rb_intern("<=>"))) {
|
||||
return Qnil;
|
||||
}
|
||||
else {
|
||||
VALUE tmp = rb_funcall(str2, rb_intern("<=>"), 1, str1);
|
||||
|
||||
if (!FIXNUM_P(tmp)) {
|
||||
return rb_funcall(LONG2FIX(0), '-', tmp);
|
||||
}
|
||||
result = FIX2LONG(tmp);
|
||||
}
|
||||
}
|
||||
result = rb_str_cmp(str1, str2);
|
||||
return INT2FIX(result);
|
||||
else {
|
||||
result = rb_str_cmp(str1, str2);
|
||||
}
|
||||
return LONG2FIX(result);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
|
|
Loading…
Reference in a new issue