diff options
author | tadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-07-10 05:59:12 +0000 |
---|---|---|
committer | tadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-07-10 05:59:12 +0000 |
commit | 32af4ed47f18839d3d783c3d2ab6f8895a81d6be (patch) | |
tree | e65403ec7a7957b173018f22f46d936212b832e5 /ext | |
parent | 919978a8d9e25d52697c0677c1f2c0ccb50b4492 (diff) | |
download | ruby-32af4ed47f18839d3d783c3d2ab6f8895a81d6be.tar.gz |
* ext/date/date_core.c: canonicalizes nth and sf.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32487 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r-- | ext/date/date_core.c | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/ext/date/date_core.c b/ext/date/date_core.c index 2bdfebb4c6..540b9f7387 100644 --- a/ext/date/date_core.c +++ b/ext/date/date_core.c @@ -308,10 +308,21 @@ union DateData { 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 @@ union DateData { #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 @@ union DateData { #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 @@ _year, _mon, _mday, _hour, _min, _sec, _flags) \ #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;\ |