ruby-changes:14173
From: matz <ko1@a...>
Date: Fri, 4 Dec 2009 16:37:27 +0900 (JST)
Subject: [ruby-changes:14173] Ruby:r25991 (trunk): * time.c (num_exact): should not accept strings as operands, even
matz 2009-12-04 16:37:10 +0900 (Fri, 04 Dec 2009) New Revision: 25991 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=25991 Log: * time.c (num_exact): should not accept strings as operands, even though they respond to #to_r. ideally, strict rational conversion should be done by a method like #to_rational, not #to_r. [ruby-core:23729] Modified files: trunk/ChangeLog trunk/time.c Index: time.c =================================================================== --- time.c (revision 25990) +++ time.c (revision 25991) @@ -214,19 +214,22 @@ v = rb_convert_type(v, T_RATIONAL, "Rational", "to_r"); break; + case T_STRING: case T_NIL: goto typeerror; default: { VALUE tmp; - if (!NIL_P(tmp = rb_check_convert_type(v, T_RATIONAL, "Rational", "to_r"))) + if (!NIL_P(tmp = rb_check_convert_type(v, T_RATIONAL, "Rational", "to_r"))) { + if (rb_respond_to(v, rb_intern("to_str"))) goto typeerror; v = tmp; + } else if (!NIL_P(tmp = rb_check_to_integer(v, "to_int"))) v = tmp; else { typeerror: rb_raise(rb_eTypeError, "can't convert %s into an exact number", - rb_obj_classname(v)); + NIL_P(v) ? "nil" : rb_obj_classname(v)); } break; } Index: ChangeLog =================================================================== --- ChangeLog (revision 25990) +++ ChangeLog (revision 25991) @@ -3,6 +3,13 @@ * vm_eval.c (yield_under): does not yield self, and passes blockptr instead of &block to vm_cref_push(). [ruby-dev:39833] +Fri Dec 4 15:15:43 2009 Yukihiro Matsumoto <matz@r...> + + * time.c (num_exact): should not accept strings as operands, even + though they respond to #to_r. ideally, strict rational + conversion should be done by a method like #to_rational, not #to_r. + [ruby-core:23729] + Fri Dec 4 13:10:23 2009 NAKAMURA, Hiroshi <nahi@r...> * ext/stringio/stringio.c (ungetc): RDoc updated. trunk allows -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/