summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-11-13 04:29:30 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-11-13 04:29:30 +0000
commit8655d0735fe08a38b290d7b83c2f9c9901800544 (patch)
tree1550e23b3fed6374f21d1120f14fb7ef3f1e3c64
parent53ad55e4caf90172cc44f9c9cc9930235bb22116 (diff)
date_core.c: keep COMPLEX_DAT bit
* ext/date/date_core.c (d_lite_initialize_copy): do not change COMPLEX_DAT bit, as the structure does not change. initialize member-wise instead. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65697 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ext/date/date_core.c25
-rw-r--r--test/date/test_date_new.rb8
2 files changed, 30 insertions, 3 deletions
diff --git a/ext/date/date_core.c b/ext/date/date_core.c
index 4fd35c9..ab00f67 100644
--- a/ext/date/date_core.c
+++ b/ext/date/date_core.c
@@ -4768,8 +4768,28 @@ d_lite_initialize_copy(VALUE copy, VALUE date)
{
get_d2(copy, date);
if (simple_dat_p(bdat)) {
- adat->s = bdat->s;
- adat->s.flags &= ~COMPLEX_DAT;
+ if (simple_dat_p(adat)) {
+ adat->s = bdat->s;
+ }
+ else {
+ adat->c.flags = bdat->s.flags | COMPLEX_DAT;
+ adat->c.nth = bdat->s.nth;
+ adat->c.jd = bdat->s.jd;
+ adat->c.df = 0;
+ adat->c.sf = INT2FIX(0);
+ adat->c.of = 0;
+ adat->c.sg = bdat->s.sg;
+ adat->c.year = bdat->s.year;
+#ifndef USE_PACK
+ adat->c.mon = bdat->s.mon;
+ adat->c.mday = bdat->s.mday;
+ adat->c.hour = bdat->s.hour;
+ adat->c.min = bdat->s.min;
+ adat->c.sec = bdat->s.sec;
+#else
+ adat->c.pc = bdat->s.pc;
+#endif
+ }
}
else {
if (!complex_dat_p(adat))
@@ -4777,7 +4797,6 @@ d_lite_initialize_copy(VALUE copy, VALUE date)
"cannot load complex into simple");
adat->c = bdat->c;
- adat->c.flags |= COMPLEX_DAT;
}
}
return copy;
diff --git a/test/date/test_date_new.rb b/test/date/test_date_new.rb
index fe9a631..6ea9c69 100644
--- a/test/date/test_date_new.rb
+++ b/test/date/test_date_new.rb
@@ -267,4 +267,12 @@ class TestDateNew < Test::Unit::TestCase
assert_in_delta(t, t2, t - z + 2)
end
+ def test_memsize
+ require 'objspace'
+ t = DateTime.now
+ size = ObjectSpace.memsize_of(t)
+ t.__send__(:initialize_copy, Date.today)
+ assert_instance_of(DateTime, t)
+ assert_equal(size, ObjectSpace.memsize_of(t), "not reallocated but memsize changed")
+ end
end