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

ruby-changes:35438

From: nagachika <ko1@a...>
Date: Wed, 10 Sep 2014 23:57:58 +0900 (JST)
Subject: [ruby-changes:35438] nagachika:r47520 (ruby_2_1): merge revision(s) r46501, r47372, r47460: [Backport #10191]

nagachika	2014-09-10 23:57:42 +0900 (Wed, 10 Sep 2014)

  New Revision: 47520

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

  Log:
    merge revision(s) r46501,r47372,r47460: [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_1/
  Modified files:
    branches/ruby_2_1/ChangeLog
    branches/ruby_2_1/internal.h
    branches/ruby_2_1/object.c
    branches/ruby_2_1/test/ruby/test_object.rb
    branches/ruby_2_1/version.h
Index: ruby_2_1/ChangeLog
===================================================================
--- ruby_2_1/ChangeLog	(revision 47519)
+++ ruby_2_1/ChangeLog	(revision 47520)
@@ -1,3 +1,17 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ChangeLog#L1
+Wed Sep 10 23:36:38 2014  Koichi Sasada  <ko1@a...>
+
+	* test/ruby/test_object.rb: extend timeout.
+
+Wed Sep 10 23:36:38 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* object.c (rb_obj_copy_ivar): allocate no memory for empty
+	  instance variables.  [ruby-core:64700] [Bug #10191]
+
+Wed Sep 10 23:36:38 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* object.c (rb_obj_copy_ivar): extract function to copy instance
+	  variables only for T_OBJECT from init_copy.
+
 Wed Sep 10 23:14:42 2014  NARUSE, Yui  <naruse@r...>
 
 	merge r46831 partially. extracted commits are as follows. [Bug #9344]
Index: ruby_2_1/object.c
===================================================================
--- ruby_2_1/object.c	(revision 47519)
+++ ruby_2_1/object.c	(revision 47520)
@@ -252,6 +252,33 @@ rb_obj_singleton_class(VALUE obj) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/object.c#L252
     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)
 {
@@ -264,25 +291,7 @@ init_copy(VALUE dest, VALUE obj) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/object.c#L291
     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_1/internal.h
===================================================================
--- ruby_2_1/internal.h	(revision 47519)
+++ ruby_2_1/internal.h	(revision 47520)
@@ -595,6 +595,7 @@ rb_float_new_inline(double d) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/internal.h#L595
 #define rb_float_new(d)   rb_float_new_inline(d)
 
 /* 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_1/version.h
===================================================================
--- ruby_2_1/version.h	(revision 47519)
+++ ruby_2_1/version.h	(revision 47520)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/version.h#L1
 #define RUBY_VERSION "2.1.2"
 #define RUBY_RELEASE_DATE "2014-09-10"
-#define RUBY_PATCHLEVEL 234
+#define RUBY_PATCHLEVEL 235
 
 #define RUBY_RELEASE_YEAR 2014
 #define RUBY_RELEASE_MONTH 9
Index: ruby_2_1/test/ruby/test_object.rb
===================================================================
--- ruby_2_1/test/ruby/test_object.rb	(revision 47519)
+++ ruby_2_1/test/ruby/test_object.rb	(revision 47520)
@@ -805,4 +805,14 @@ class TestObject < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_object.rb#L805
     assert_raise_with_message(TypeError, "can't convert Array into Integer") {Integer([42])}
     assert_raise_with_message(TypeError, 'no implicit conversion of Array into Integer') {[].first([42])}
   end
+
+  def test_copied_ivar_memory_leak
+    bug10191 = '[ruby-core:64700] [Bug #10191]'
+    assert_no_memory_leak([], <<-"end;", <<-"end;", bug10191, rss: true, timeout: 60, limit: 2.5)
+      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_1
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r46501,47372,47460


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

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