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

ruby-changes:30589

From: akr <ko1@a...>
Date: Fri, 23 Aug 2013 21:06:10 +0900 (JST)
Subject: [ruby-changes:30589] akr:r42668 (trunk): * process.c (timetick_int_t): Renamed from timetick_giga_count_t.

akr	2013-08-23 21:06:02 +0900 (Fri, 23 Aug 2013)

  New Revision: 42668

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

  Log:
    * process.c (timetick_int_t): Renamed from timetick_giga_count_t.
      (gcd_timtick_int): Renamed from gcd_ul and make the arguments
      timetick_giga_count_t.
      (reduce_fraction): Make the arguments timetick_int_t.
      (timetick2integer): Ditto.
      (make_clock_result): Ditto.
      (timetick2dblnum): Fix the return type.
      (rb_clock_gettime): Use timetick_int_t.

  Modified files:
    trunk/ChangeLog
    trunk/process.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 42667)
+++ ChangeLog	(revision 42668)
@@ -1,3 +1,14 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Aug 23 21:00:55 2013  Tanaka Akira  <akr@f...>
+
+	* process.c (timetick_int_t): Renamed from timetick_giga_count_t.
+	  (gcd_timtick_int): Renamed from gcd_ul and make the arguments
+	  timetick_giga_count_t.
+	  (reduce_fraction): Make the arguments timetick_int_t.
+	  (timetick2integer): Ditto.
+	  (make_clock_result): Ditto.
+	  (timetick2dblnum): Fix the return type.
+	  (rb_clock_gettime): Use timetick_int_t.
+
 Fri Aug 23 20:50:40 2013  Tanaka Akira  <akr@f...>
 
 	* process.c (gcd_ul): New function.
Index: process.c
===================================================================
--- process.c	(revision 42667)
+++ process.c	(revision 42668)
@@ -6667,10 +6667,22 @@ rb_proc_times(VALUE obj) https://github.com/ruby/ruby/blob/trunk/process.c#L6667
 #define rb_proc_times rb_f_notimplement
 #endif
 
-static unsigned long
-gcd_ul(unsigned long a, unsigned long b)
+#ifdef HAVE_LONG_LONG
+typedef LONG_LONG timetick_int_t;
+#define TIMETICK_INT_MIN LLONG_MIN
+#define TIMETICK_INT_MAX LLONG_MAX
+#define TIMETICK_INT2NUM(v) LL2NUM(v)
+#else
+typedef long timetick_int_t;
+#define TIMETICK_INT_MIN LONG_MIN
+#define TIMETICK_INT_MAX LONG_MAX
+#define TIMETICK_INT2NUM(v) LONG2NUM(v)
+#endif
+
+static timetick_int_t
+gcd_timtick_int(timetick_int_t a, timetick_int_t b)
 {
-    unsigned long t;
+    timetick_int_t t;
 
     if (a < b) {
         t = a;
@@ -6688,34 +6700,22 @@ gcd_ul(unsigned long a, unsigned long b) https://github.com/ruby/ruby/blob/trunk/process.c#L6700
 }
 
 static void
-reduce_fraction(unsigned long *np, unsigned long *dp)
+reduce_fraction(timetick_int_t *np, timetick_int_t *dp)
 {
-    unsigned long gcd = gcd_ul(*np, *dp);
+    timetick_int_t gcd = gcd_timtick_int(*np, *dp);
     if (gcd != 1) {
         *np /= gcd;
         *dp /= gcd;
     }
 }
 
-#ifdef HAVE_LONG_LONG
-typedef LONG_LONG timetick_giga_count_t;
-#define TIMETICK_GIGA_COUNT_MIN LLONG_MIN
-#define TIMETICK_GIGA_COUNT_MAX LLONG_MAX
-#define TIMETICK_GIGA_COUNT2NUM(v) LL2NUM(v)
-#else
-typedef long timetick_giga_count_t;
-#define TIMETICK_GIGA_COUNT_MIN LONG_MIN
-#define TIMETICK_GIGA_COUNT_MAX LONG_MAX
-#define TIMETICK_GIGA_COUNT2NUM(v) LONG2NUM(v)
-#endif
-
 struct timetick {
-    timetick_giga_count_t giga_count;
-    long count; /* 0 .. 999999999 */
+    timetick_int_t giga_count;
+    int32_t count; /* 0 .. 999999999 */
 };
 
-static double
-timetick2dblnum(struct timetick *ttp, unsigned long numerator, unsigned long denominator, unsigned long factor)
+static VALUE
+timetick2dblnum(struct timetick *ttp, timetick_int_t numerator, timetick_int_t denominator, timetick_int_t factor)
 {
     if (factor != 1 && denominator != 1)
         reduce_fraction(&factor, &denominator);
@@ -6728,7 +6728,7 @@ timetick2dblnum(struct timetick *ttp, un https://github.com/ruby/ruby/blob/trunk/process.c#L6728
 #define DIV(n,d) ((n)<0 ? NDIV((n),(d)) : (n)/(d))
 
 static VALUE
-timetick2integer(struct timetick *ttp, unsigned long numerator, unsigned long denominator, unsigned long factor)
+timetick2integer(struct timetick *ttp, timetick_int_t numerator, timetick_int_t denominator, timetick_int_t factor)
 {
     VALUE v;
 
@@ -6737,34 +6737,32 @@ timetick2integer(struct timetick *ttp, u https://github.com/ruby/ruby/blob/trunk/process.c#L6737
     if (denominator != 1 && numerator != 1)
         reduce_fraction(&numerator, &denominator);
 
-    if (numerator <= LONG_MAX && factor <= LONG_MAX) {
-        if (!MUL_OVERFLOW_SIGNED_INTEGER_P(1000000000, ttp->giga_count,
-                    TIMETICK_GIGA_COUNT_MIN, TIMETICK_GIGA_COUNT_MAX-ttp->count)) {
-            timetick_giga_count_t t = ttp->giga_count * 1000000000 + ttp->count;
-            if (!MUL_OVERFLOW_SIGNED_INTEGER_P((long)numerator, t,
-                        TIMETICK_GIGA_COUNT_MIN, TIMETICK_GIGA_COUNT_MAX)) {
-                t *= numerator;
-                if (!MUL_OVERFLOW_SIGNED_INTEGER_P((long)factor, t,
-                            TIMETICK_GIGA_COUNT_MIN, TIMETICK_GIGA_COUNT_MAX)) {
-                    t *= factor;
-                    t = DIV(t, denominator);
-                    return TIMETICK_GIGA_COUNT2NUM(t);
-                }
+    if (!MUL_OVERFLOW_SIGNED_INTEGER_P(1000000000, ttp->giga_count,
+                TIMETICK_INT_MIN, TIMETICK_INT_MAX-ttp->count)) {
+        timetick_int_t t = ttp->giga_count * 1000000000 + ttp->count;
+        if (!MUL_OVERFLOW_SIGNED_INTEGER_P(numerator, t,
+                    TIMETICK_INT_MIN, TIMETICK_INT_MAX)) {
+            t *= numerator;
+            if (!MUL_OVERFLOW_SIGNED_INTEGER_P(factor, t,
+                        TIMETICK_INT_MIN, TIMETICK_INT_MAX)) {
+                t *= factor;
+                t = DIV(t, denominator);
+                return TIMETICK_INT2NUM(t);
             }
         }
     }
 
-    v = TIMETICK_GIGA_COUNT2NUM(ttp->giga_count);
+    v = TIMETICK_INT2NUM(ttp->giga_count);
     v = rb_funcall(v, '*', 1, LONG2FIX(1000000000));
     v = rb_funcall(v, '+', 1, LONG2FIX(ttp->count));
-    v = rb_funcall(v, '*', 1, ULONG2NUM(numerator));
-    v = rb_funcall(v, '*', 1, ULONG2NUM(factor));
-    v = rb_funcall(v, '/', 1, ULONG2NUM(denominator)); /* Ruby's '/' is div. */
+    v = rb_funcall(v, '*', 1, TIMETICK_INT2NUM(numerator));
+    v = rb_funcall(v, '*', 1, TIMETICK_INT2NUM(factor));
+    v = rb_funcall(v, '/', 1, TIMETICK_INT2NUM(denominator)); /* Ruby's '/' is div. */
     return v;
 }
 
 static VALUE
-make_clock_result(struct timetick *ttp, unsigned long numerator, unsigned long denominator, VALUE unit)
+make_clock_result(struct timetick *ttp, timetick_int_t numerator, timetick_int_t denominator, VALUE unit)
 {
     if (unit == ID2SYM(rb_intern("nanosecond")))
         return timetick2integer(ttp, numerator, denominator, 1000000000);
@@ -6892,8 +6890,8 @@ rb_clock_gettime(int argc, VALUE *argv) https://github.com/ruby/ruby/blob/trunk/process.c#L6890
     int ret;
 
     struct timetick tt;
-    unsigned long numerator;
-    unsigned long denominator;
+    timetick_int_t numerator;
+    timetick_int_t denominator;
 
     rb_scan_args(argc, argv, "11", &clk_id, &unit);
 
@@ -7005,7 +7003,7 @@ rb_clock_gettime(int argc, VALUE *argv) https://github.com/ruby/ruby/blob/trunk/process.c#L7003
             tt.count = t % 1000000000;
             tt.giga_count = t / 1000000000;
             numerator = sTimebaseInfo.numer;
-            denominator = sTimebaseInfo.denom * 1000000000;
+            denominator = sTimebaseInfo.denom * (timetick_int_t)1000000000;
             goto success;
         }
 #endif

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

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