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

ruby-changes:20439

From: tadf <ko1@a...>
Date: Sun, 10 Jul 2011 14:59:24 +0900 (JST)
Subject: [ruby-changes:20439] tadf:r32487 (trunk): * ext/date/date_core.c: canonicalizes nth and sf.

tadf	2011-07-10 14:59:12 +0900 (Sun, 10 Jul 2011)

  New Revision: 32487

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

  Log:
    * ext/date/date_core.c: canonicalizes nth and sf.

  Modified files:
    trunk/ChangeLog
    trunk/ext/date/date_core.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 32486)
+++ ChangeLog	(revision 32487)
@@ -1,3 +1,7 @@
+Sun Jul 10 14:57:36 2011  Tadayoshi Funaba  <tadf@d...>
+
+	* ext/date/date_core.c: canonicalizes nth and sf.
+
 Sun Jul 10 14:13:50 2011  Koichi Sasada  <ko1@a...>
 
 	* internal.h (rb_thread_call_with_gvl, rb_thread_call_without_gvl):
Index: ext/date/date_core.c
===================================================================
--- ext/date/date_core.c	(revision 32486)
+++ ext/date/date_core.c	(revision 32487)
@@ -308,10 +308,21 @@
     Data_Get_Struct(x, union DateData, adat);\
     Data_Get_Struct(y, union DateData, bdat);
 
+inline static VALUE
+canon(VALUE x)
+{
+    if (TYPE(x) == T_RATIONAL) {
+	VALUE den = RRATIONAL(x)->den;
+	if (FIXNUM_P(den) && FIX2LONG(den) == 1)
+	    return RRATIONAL(x)->num;
+    }
+    return x;
+}
+
 #ifndef USE_PACK
 #define set_to_simple(x, _nth, _jd ,_sg, _year, _mon, _mday, _flags) \
 {\
-    (x)->nth = _nth;\
+    (x)->nth = canon(_nth);\
     (x)->jd = _jd;\
     (x)->sg = (sg_cast)(_sg);\
     (x)->year = _year;\
@@ -322,7 +333,7 @@
 #else
 #define set_to_simple(x, _nth, _jd ,_sg, _year, _mon, _mday, _flags) \
 {\
-    (x)->nth = _nth;\
+    (x)->nth = canon(_nth);\
     (x)->jd = _jd;\
     (x)->sg = (sg_cast)(_sg);\
     (x)->year = _year;\
@@ -335,10 +346,10 @@
 #define set_to_complex(x, _nth, _jd ,_df, _sf, _of, _sg,\
 _year, _mon, _mday, _hour, _min, _sec, _flags) \
 {\
-    (x)->nth = _nth;\
+    (x)->nth = canon(_nth);\
     (x)->jd = _jd;\
     (x)->df = _df;\
-    (x)->sf = _sf;\
+    (x)->sf = canon(_sf);\
     (x)->of = _of;\
     (x)->sg = (sg_cast)(_sg);\
     (x)->year = _year;\
@@ -353,10 +364,10 @@
 #define set_to_complex(x, _nth, _jd ,_df, _sf, _of, _sg,\
 _year, _mon, _mday, _hour, _min, _sec, _flags) \
 {\
-    (x)->nth = _nth;\
+    (x)->nth = canon(_nth);\
     (x)->jd = _jd;\
     (x)->df = _df;\
-    (x)->sf = _sf;\
+    (x)->sf = canon(_sf);\
     (x)->of = _of;\
     (x)->sg = (sg_cast)(_sg);\
     (x)->year = _year;\

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

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