From db2c62ff83f57da0a0afc740d06b877f2ed361e9 Mon Sep 17 00:00:00 2001 From: matz Date: Thu, 19 Dec 2002 09:20:20 +0000 Subject: * numeric.c (num_step): use DBL_EPSILON. * array.c (rb_check_array_type): new function: return an array (convert if possible), or nil. * string.c (rb_check_string_type): new function: return a string (convert if possible), or nil. * numeric.c (rb_dbl_cmp): returns nil if values are not comparable. * numeric.c (fix_cmp,flo_cmp): use rb_num_coerce_cmp() * bignum.c (rb_big_cmp): ditto. * numeric.c (rb_num_coerce_cmp): new coercing function for "<=>", which does not raise TypeError. * numeric.c (do_coerce): can be supress exception now. * object.c (rb_mod_cmp): should return nil for non class/module objects. * re.c (rb_reg_eqq): return false if the argument is not a string. now returns boolean value. * class.c (rb_include_module): argument should be T_MODULE, not T_class, nor T_ICLASS. * eval.c (is_defined): "defined?" should return "assignment" for attribute assignment (e.g. a.foo=b) and indexed assignment (e.g. a[2] = 44). * parse.y (aryset): use NODE_ATTRASGN. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@3169 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- string.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'string.c') diff --git a/string.c b/string.c index 26d1cbf2a..23a804a82 100644 --- a/string.c +++ b/string.c @@ -468,6 +468,13 @@ rb_string_value_ptr(ptr) return RSTRING(s)->ptr; } +VALUE +rb_check_string_type(str) + VALUE str; +{ + return rb_check_convert_type(str, T_STRING, "String", "to_str"); +} + VALUE rb_str_substr(str, beg, len) VALUE str; @@ -763,7 +770,7 @@ rb_str_equal(str1, str2) { if (str1 == str2) return Qtrue; if (TYPE(str2) != T_STRING) { - str2 = rb_check_convert_type(str2, T_STRING, "String", "to_str"); + str2 = rb_check_string_type(str2); if (NIL_P(str2)) return Qfalse; } @@ -794,7 +801,10 @@ rb_str_cmp_m(str1, str2) { int result; - StringValue(str2); + if (TYPE(str2) != T_STRING) { + str2 = rb_check_string_type(str2); + if (NIL_P(str2)) return Qnil; + } result = rb_str_cmp(str1, str2); return INT2FIX(result); } @@ -1428,7 +1438,7 @@ get_pat(pat, quote) break; default: - val = rb_check_convert_type(pat, T_STRING, "String", "to_str"); + val = rb_check_string_type(pat); if (NIL_P(val)) { Check_Type(pat, T_REGEXP); } -- cgit