diff options
-rw-r--r-- | ChangeLog | 15 | ||||
-rw-r--r-- | compar.c | 12 | ||||
-rw-r--r-- | parse.y | 2 | ||||
-rw-r--r-- | string.c | 24 |
4 files changed, 41 insertions, 12 deletions
@@ -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 @@ -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; } @@ -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 '.'; @@ -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); + } + } + else { + result = rb_str_cmp(str1, str2); } - result = rb_str_cmp(str1, str2); - return INT2FIX(result); + return LONG2FIX(result); } static VALUE |