[前][次][番号順一覧][スレッド一覧]

ruby-changes:38439

From: nobu <ko1@a...>
Date: Sun, 17 May 2015 14:59:42 +0900 (JST)
Subject: [ruby-changes:38439] nobu:r50520 (trunk): numeric.c: compare_with_zero

nobu	2015-05-17 14:59:36 +0900 (Sun, 17 May 2015)

  New Revision: 50520

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=50520

  Log:
    numeric.c: compare_with_zero
    
    * numeric.c (compare_with_zero): raise TypeError when not
      comparable with 0.

  Modified files:
    trunk/numeric.c
Index: numeric.c
===================================================================
--- numeric.c	(revision 50519)
+++ numeric.c	(revision 50520)
@@ -162,6 +162,17 @@ rb_num_to_uint(VALUE val, unsigned int * https://github.com/ruby/ruby/blob/trunk/numeric.c#L162
 
 #define method_basic_p(klass) rb_method_basic_definition_p(klass, mid)
 
+static VALUE
+compare_with_zero(VALUE num, ID mid)
+{
+    VALUE zero = INT2FIX(0);
+    VALUE r = rb_check_funcall(num, mid, 1, &zero);
+    if (r == Qundef) {
+	rb_cmperr(mid, zero);
+    }
+    return r;
+}
+
 static inline int
 positive_int_p(VALUE num)
 {
@@ -175,7 +186,7 @@ positive_int_p(VALUE num) https://github.com/ruby/ruby/blob/trunk/numeric.c#L186
 	if (method_basic_p(rb_cBignum))
 	    return BIGNUM_POSITIVE_P(num);
     }
-    return RTEST(rb_funcall(num, mid, 1, INT2FIX(0)));
+    return RTEST(compare_with_zero(num, mid));
 }
 
 static inline int
@@ -191,7 +202,7 @@ negative_int_p(VALUE num) https://github.com/ruby/ruby/blob/trunk/numeric.c#L202
 	if (method_basic_p(rb_cBignum))
 	    return BIGNUM_NEGATIVE_P(num);
     }
-    return RTEST(rb_funcall(num, mid, 1, INT2FIX(0)));
+    return RTEST(compare_with_zero(num, mid));
 }
 
 int

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]