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

ruby-changes:35466

From: usa <ko1@a...>
Date: Fri, 12 Sep 2014 11:36:39 +0900 (JST)
Subject: [ruby-changes:35466] usa:r47548 (ruby_2_0_0): merge revision(s) 46501, 47372, 47460: [Backport #10191]

usa	2014-09-12 11:36:28 +0900 (Fri, 12 Sep 2014)

  New Revision: 47548

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

  Log:
    merge revision(s) 46501,47372,47460: [Backport #10191]
    
    * object.c (rb_obj_copy_ivar): extract function to copy instance
      variables only for T_OBJECT from init_copy.
    
    * object.c (rb_obj_copy_ivar): allocate no memory for empty
      instance variables.  [ruby-core:64700] [Bug #10191]
    
    * test/ruby/test_object.rb: extend timeout.

  Modified directories:
    branches/ruby_2_0_0/
  Modified files:
    branches/ruby_2_0_0/ChangeLog
    branches/ruby_2_0_0/internal.h
    branches/ruby_2_0_0/object.c
    branches/ruby_2_0_0/test/ruby/test_object.rb
    branches/ruby_2_0_0/version.h
Index: ruby_2_0_0/ChangeLog
===================================================================
--- ruby_2_0_0/ChangeLog	(revision 47547)
+++ ruby_2_0_0/ChangeLog	(revision 47548)
@@ -1,3 +1,17 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ChangeLog#L1
+Fri Sep 12 11:34:39 2014  Koichi Sasada  <ko1@a...>
+
+	* test/ruby/test_object.rb: extend timeout.
+
+Fri Sep 12 11:34:39 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* object.c (rb_obj_copy_ivar): allocate no memory for empty
+	  instance variables.  [ruby-core:64700] [Bug #10191]
+
+Fri Sep 12 11:34:39 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* object.c (rb_obj_copy_ivar): extract function to copy instance
+	  variables only for T_OBJECT from init_copy.
+
 Fri Sep 12 11:30:50 2014  NAKAMURA Usaku  <usa@r...>
 
 	* regcomp.c: Merge Onigmo 988517a4f16f14acbd7cc9d5b51a096d5153992c.
Index: ruby_2_0_0/object.c
===================================================================
--- ruby_2_0_0/object.c	(revision 47547)
+++ ruby_2_0_0/object.c	(revision 47548)
@@ -219,6 +219,33 @@ rb_obj_singleton_class(VALUE obj) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/object.c#L219
     return rb_singleton_class(obj);
 }
 
+void
+rb_obj_copy_ivar(VALUE dest, VALUE obj)
+{
+    if (!(RBASIC(dest)->flags & ROBJECT_EMBED) && ROBJECT_IVPTR(dest)) {
+	xfree(ROBJECT_IVPTR(dest));
+	ROBJECT(dest)->as.heap.ivptr = 0;
+	ROBJECT(dest)->as.heap.numiv = 0;
+	ROBJECT(dest)->as.heap.iv_index_tbl = 0;
+    }
+    if (RBASIC(obj)->flags & ROBJECT_EMBED) {
+	MEMCPY(ROBJECT(dest)->as.ary, ROBJECT(obj)->as.ary, VALUE, ROBJECT_EMBED_LEN_MAX);
+	RBASIC(dest)->flags |= ROBJECT_EMBED;
+    }
+    else {
+	long len = ROBJECT(obj)->as.heap.numiv;
+	VALUE *ptr = 0;
+	if (len > 0) {
+	    ptr = ALLOC_N(VALUE, len);
+	    MEMCPY(ptr, ROBJECT(obj)->as.heap.ivptr, VALUE, len);
+	}
+	ROBJECT(dest)->as.heap.ivptr = ptr;
+	ROBJECT(dest)->as.heap.numiv = len;
+	ROBJECT(dest)->as.heap.iv_index_tbl = ROBJECT(obj)->as.heap.iv_index_tbl;
+	RBASIC(dest)->flags &= ~ROBJECT_EMBED;
+    }
+}
+
 static void
 init_copy(VALUE dest, VALUE obj)
 {
@@ -231,25 +258,7 @@ init_copy(VALUE dest, VALUE obj) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/object.c#L258
     rb_gc_copy_finalizer(dest, obj);
     switch (TYPE(obj)) {
       case T_OBJECT:
-        if (!(RBASIC(dest)->flags & ROBJECT_EMBED) && ROBJECT_IVPTR(dest)) {
-            xfree(ROBJECT_IVPTR(dest));
-            ROBJECT(dest)->as.heap.ivptr = 0;
-            ROBJECT(dest)->as.heap.numiv = 0;
-            ROBJECT(dest)->as.heap.iv_index_tbl = 0;
-        }
-        if (RBASIC(obj)->flags & ROBJECT_EMBED) {
-            MEMCPY(ROBJECT(dest)->as.ary, ROBJECT(obj)->as.ary, VALUE, ROBJECT_EMBED_LEN_MAX);
-            RBASIC(dest)->flags |= ROBJECT_EMBED;
-        }
-        else {
-            long len = ROBJECT(obj)->as.heap.numiv;
-            VALUE *ptr = ALLOC_N(VALUE, len);
-            MEMCPY(ptr, ROBJECT(obj)->as.heap.ivptr, VALUE, len);
-            ROBJECT(dest)->as.heap.ivptr = ptr;
-            ROBJECT(dest)->as.heap.numiv = len;
-            ROBJECT(dest)->as.heap.iv_index_tbl = ROBJECT(obj)->as.heap.iv_index_tbl;
-            RBASIC(dest)->flags &= ~ROBJECT_EMBED;
-        }
+	rb_obj_copy_ivar(dest, obj);
         break;
       case T_CLASS:
       case T_MODULE:
Index: ruby_2_0_0/internal.h
===================================================================
--- ruby_2_0_0/internal.h	(revision 47547)
+++ ruby_2_0_0/internal.h	(revision 47548)
@@ -182,6 +182,7 @@ VALUE rb_int_succ(VALUE num); https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/internal.h#L182
 VALUE rb_int_pred(VALUE num);
 
 /* object.c */
+void rb_obj_copy_ivar(VALUE dest, VALUE obj);
 VALUE rb_obj_equal(VALUE obj1, VALUE obj2);
 VALUE rb_class_search_ancestor(VALUE klass, VALUE super);
 
Index: ruby_2_0_0/version.h
===================================================================
--- ruby_2_0_0/version.h	(revision 47547)
+++ ruby_2_0_0/version.h	(revision 47548)
@@ -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 "2014-09-12"
-#define RUBY_PATCHLEVEL 569
+#define RUBY_PATCHLEVEL 570
 
 #define RUBY_RELEASE_YEAR 2014
 #define RUBY_RELEASE_MONTH 9
Index: ruby_2_0_0/test/ruby/test_object.rb
===================================================================
--- ruby_2_0_0/test/ruby/test_object.rb	(revision 47547)
+++ ruby_2_0_0/test/ruby/test_object.rb	(revision 47548)
@@ -898,4 +898,14 @@ class TestObject < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_object.rb#L898
     err = assert_raise(TypeError){ [].first([42]) }
     assert_equal 'no implicit conversion of Array into Integer', err.message, issue
   end
+
+  def test_copied_ivar_memory_leak
+    bug10191 = '[ruby-core:64700] [Bug #10191]'
+    assert_no_memory_leak([], <<-"end;", <<-"end;", bug10191, rss: true, timeout: 60)
+      def (a = Object.new).set; @v = nil; end
+      num = 500_000
+    end;
+      num.times {a.clone.set}
+    end;
+  end
 end

Property changes on: ruby_2_0_0
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r46501,47372,47460


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

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