summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-30 08:43:42 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-30 08:43:42 +0000
commit1dbc720c0d91bfdb39dbef75606d5cd4ef4d9884 (patch)
tree30b8d0c9866957f05473bbed5e49fa45b98a4621
parent981f9c52c6b0d7197e098ae9a0375485cf0c9c0c (diff)
string.c: always fixed value
* string.c (rb_str_cmp_m): return fixed value, one of -1,0,+1 always. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38042 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog12
-rw-r--r--string.c9
-rw-r--r--test/ruby/test_string.rb2
3 files changed, 16 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 57554fb209..f04f4ff1d7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+Fri Nov 30 17:43:39 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * string.c (rb_str_cmp_m): return fixed value, one of -1,0,+1 always.
+
+ * string.c (rb_str_cmp_m): try to compare with to_str result if
+ possible before calling <=> method. [ruby-core:49279] [Bug #7342]
+
+ * string.c (rb_str_cmp_m): use rb_check_funcall instead of respond_to
+ and call.
+
+ * string.c (rb_str_cmp_m): return fixed value, one of -1,0,+1 always.
+
Fri Nov 30 16:19:14 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
* vm_dump.c (rb_vm_bugreport): get rid of calling methods in sigsegv
diff --git a/string.c b/string.c
index 0c30ee4bc2..4270460e16 100644
--- a/string.c
+++ b/string.c
@@ -2382,7 +2382,7 @@ rb_str_eql(VALUE str1, VALUE str2)
static VALUE
rb_str_cmp_m(VALUE str1, VALUE str2)
{
- long result;
+ int result;
if (!RB_TYPE_P(str2, T_STRING)) {
if (!rb_respond_to(str2, rb_intern("to_str"))) {
@@ -2395,16 +2395,13 @@ rb_str_cmp_m(VALUE str1, VALUE str2)
VALUE tmp = rb_funcall(str2, rb_intern("<=>"), 1, str1);
if (NIL_P(tmp)) return Qnil;
- if (!FIXNUM_P(tmp)) {
- return rb_funcall(LONG2FIX(0), '-', 1, tmp);
- }
- result = -FIX2LONG(tmp);
+ result = -rb_cmpint(tmp, str1, str2);
}
}
else {
result = rb_str_cmp(str1, str2);
}
- return LONG2NUM(result);
+ return INT2FIX(result);
}
/*
diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb
index e4e6c39663..6c73a7ccc7 100644
--- a/test/ruby/test_string.rb
+++ b/test/ruby/test_string.rb
@@ -181,7 +181,7 @@ class TestString < Test::Unit::TestCase
class << o;remove_method :<=>;end
def o.<=>(x); 2**100; end
- assert_equal(-(2**100), "foo" <=> o)
+ assert_equal(-1, "foo" <=> o)
end
def test_EQUAL # '=='