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

ruby-changes:28230

From: nagachika <ko1@a...>
Date: Sun, 14 Apr 2013 02:37:50 +0900 (JST)
Subject: [ruby-changes:28230] nagachika:r40282 (ruby_2_0_0): merge revision(s) 39766,39769: [Backport #8101]

nagachika	2013-04-14 02:37:39 +0900 (Sun, 14 Apr 2013)

  New Revision: 40282

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

  Log:
    merge revision(s) 39766,39769: [Backport #8101]
    
    * time.c (GetTimeval): check if already initialized instance.
    
    * time.c (GetNewTimeval): check if newly created instance.
    
    * time.c (time_init_0, time_init_1, time_init_copy, time_mload): must
      be newly created instance.  [ruby-core:53436] [Bug #8099]

  Modified directories:
    branches/ruby_2_0_0/
  Modified files:
    branches/ruby_2_0_0/ChangeLog
    branches/ruby_2_0_0/test/ruby/test_object.rb
    branches/ruby_2_0_0/test/ruby/test_time.rb
    branches/ruby_2_0_0/time.c
    branches/ruby_2_0_0/version.h

Index: ruby_2_0_0/time.c
===================================================================
--- ruby_2_0_0/time.c	(revision 40281)
+++ ruby_2_0_0/time.c	(revision 40282)
@@ -1827,10 +1827,11 @@ struct time_object { https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/time.c#L1827
     int tm_got;
 };
 
-#define GetTimeval(obj, tobj) \
-    TypedData_Get_Struct((obj), struct time_object, &time_data_type, (tobj))
+#define GetTimeval(obj, tobj) ((tobj) = get_timeval(obj))
+#define GetNewTimeval(obj, tobj) ((tobj) = get_new_timeval(obj))
 
 #define IsTimeval(obj) rb_typeddata_is_kind_of((obj), &time_data_type)
+#define TIME_INIT_P(tobj) ((tobj)->gmt != -1)
 
 #define TIME_UTC_P(tobj) ((tobj)->gmt == 1)
 #define TIME_SET_UTC(tobj) ((tobj)->gmt = 1)
@@ -1893,12 +1894,35 @@ time_s_alloc(VALUE klass) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/time.c#L1894
     struct time_object *tobj;
 
     obj = TypedData_Make_Struct(klass, struct time_object, &time_data_type, tobj);
+    tobj->gmt = -1;
     tobj->tm_got=0;
     tobj->timew = WINT2FIXWV(0);
 
     return obj;
 }
 
+static struct time_object *
+get_timeval(VALUE obj)
+{
+    struct time_object *tobj;
+    TypedData_Get_Struct(obj, struct time_object, &time_data_type, tobj);
+    if (!TIME_INIT_P(tobj)) {
+	rb_raise(rb_eTypeError, "uninitialized %"PRIsVALUE, CLASS_OF(obj));
+    }
+    return tobj;
+}
+
+static struct time_object *
+get_new_timeval(VALUE obj)
+{
+    struct time_object *tobj;
+    TypedData_Get_Struct(obj, struct time_object, &time_data_type, tobj);
+    if (TIME_INIT_P(tobj)) {
+	rb_raise(rb_eTypeError, "already initialized %"PRIsVALUE, CLASS_OF(obj));
+    }
+    return tobj;
+}
+
 static void
 time_modify(VALUE time)
 {
@@ -1964,7 +1988,8 @@ time_init_0(VALUE time) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/time.c#L1988
     struct timespec ts;
 
     time_modify(time);
-    GetTimeval(time, tobj);
+    GetNewTimeval(time, tobj);
+    tobj->gmt = 0;
     tobj->tm_got=0;
     tobj->timew = WINT2FIXWV(0);
 #ifdef HAVE_CLOCK_GETTIME
@@ -2207,7 +2232,8 @@ time_init_1(int argc, VALUE *argv, VALUE https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/time.c#L2232
     validate_vtm(&vtm);
 
     time_modify(time);
-    GetTimeval(time, tobj);
+    GetNewTimeval(time, tobj);
+    tobj->gmt = 0;
     tobj->tm_got=0;
     tobj->timew = WINT2FIXWV(0);
 
@@ -2324,7 +2350,8 @@ time_new_timew(VALUE klass, wideval_t ti https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/time.c#L2350
     VALUE time = time_s_alloc(klass);
     struct time_object *tobj;
 
-    GetTimeval(time, tobj);
+    tobj = DATA_PTR(time);	/* skip type check */
+    tobj->gmt = 0;
     tobj->timew = timew;
 
     return time;
@@ -3451,7 +3478,7 @@ time_init_copy(VALUE copy, VALUE time) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/time.c#L3478
 
     if (!OBJ_INIT_COPY(copy, time)) return copy;
     GetTimeval(time, tobj);
-    GetTimeval(copy, tcopy);
+    GetNewTimeval(copy, tcopy);
     MEMCPY(tcopy, tobj, struct time_object, 1);
 
     return copy;
@@ -4836,7 +4863,8 @@ end_submicro: ; https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/time.c#L4863
         timew = timegmw(&vtm);
     }
 
-    GetTimeval(time, tobj);
+    GetNewTimeval(time, tobj);
+    tobj->gmt = 0;
     tobj->tm_got = 0;
     tobj->timew = timew;
     if (gmt) {
Index: ruby_2_0_0/ChangeLog
===================================================================
--- ruby_2_0_0/ChangeLog	(revision 40281)
+++ ruby_2_0_0/ChangeLog	(revision 40282)
@@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ChangeLog#L1
+Sun Apr 14 02:32:45 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* time.c (GetTimeval): check if already initialized instance.
+
+	* time.c (GetNewTimeval): check if newly created instance.
+
+	* time.c (time_init_0, time_init_1, time_init_copy, time_mload): must
+	  be newly created instance.  [ruby-core:53436] [Bug #8099]
+
 Sun Apr 14 02:13:25 2013  Marc-Andre Lafortune  <ruby-core@m...>
 
 	* vm_eval.c (check_funcall_respond_to): preserve passed_block, which
Index: ruby_2_0_0/version.h
===================================================================
--- ruby_2_0_0/version.h	(revision 40281)
+++ ruby_2_0_0/version.h	(revision 40282)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/version.h#L1
 #define RUBY_VERSION "2.0.0"
 #define RUBY_RELEASE_DATE "2013-04-14"
-#define RUBY_PATCHLEVEL 122
+#define RUBY_PATCHLEVEL 123
 
 #define RUBY_RELEASE_YEAR 2013
 #define RUBY_RELEASE_MONTH 4
Index: ruby_2_0_0/test/ruby/test_object.rb
===================================================================
--- ruby_2_0_0/test/ruby/test_object.rb	(revision 40281)
+++ ruby_2_0_0/test/ruby/test_object.rb	(revision 40282)
@@ -883,7 +883,6 @@ class TestObject < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_object.rb#L883
     assert_not_initialize_copy {/.*/.match("foo")}
     st = Struct.new(:foo)
     assert_not_initialize_copy {st.new}
-    assert_not_initialize_copy {Time.now}
   end
 
   def test_type_error_message
Index: ruby_2_0_0/test/ruby/test_time.rb
===================================================================
--- ruby_2_0_0/test/ruby/test_time.rb	(revision 40281)
+++ ruby_2_0_0/test/ruby/test_time.rb	(revision 40282)
@@ -408,6 +408,15 @@ class TestTime < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_time.rb#L408
     assert_kind_of(Integer, t2000.hash)
   end
 
+  def test_reinitialize
+    bug8099 = '[ruby-core:53436] [Bug #8099]'
+    t2000 = get_t2000
+    assert_raise(TypeError, bug8099) {
+      t2000.send(:initialize, 2013, 03, 14)
+    }
+    assert_equal(get_t2000, t2000, bug8099)
+  end
+
   def test_init_copy
     t2000 = get_t2000
     assert_equal(t2000, t2000.dup)

Property changes on: ruby_2_0_0
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r39766,39769


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

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