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

ruby-changes:32915

From: normal <ko1@a...>
Date: Sun, 16 Feb 2014 12:45:20 +0900 (JST)
Subject: [ruby-changes:32915] normal:r44994 (trunk): marshal.c: use rb_gc_force_recycle for GC-safety

normal	2014-02-16 12:45:15 +0900 (Sun, 16 Feb 2014)

  New Revision: 44994

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

  Log:
    marshal.c: use rb_gc_force_recycle for GC-safety
    
    Putting rb_gc_force_recycle at the end of the function has a nice
    side-effect of keeping wrapper visible to GC until the moment of
    recycle, preventing GC from prematurely killing live objects.
    volatile is a common source of compiler bugs/differences, avoid it.

  Modified files:
    trunk/ChangeLog
    trunk/marshal.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 44993)
+++ ChangeLog	(revision 44994)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Feb 16 11:55:14 2014  Eric Wong  <e@8...>
+
+	* marshal.c (marshal_dump): use rb_gc_force_recycle for GC-safety
+	  (marshal_load): ditto
+	  [ruby-core:60730] [Bug #7805]
+
 Sun Feb 16 08:11:23 2014  Zachary Scott  <e@z...>
 
 	* README.EXT.ja: [DOC] Fix typo by @utenmiki [Fixes GH-534]
Index: marshal.c
===================================================================
--- marshal.c	(revision 44993)
+++ marshal.c	(revision 44994)
@@ -950,7 +950,7 @@ marshal_dump(int argc, VALUE *argv) https://github.com/ruby/ruby/blob/trunk/marshal.c#L950
     VALUE obj, port, a1, a2;
     int limit = -1;
     struct dump_arg *arg;
-    volatile VALUE wrapper;
+    VALUE wrapper; /* used to avoid memory leak in case of exception */
 
     port = Qnil;
     rb_scan_args(argc, argv, "12", &obj, &a1, &a2);
@@ -964,7 +964,7 @@ marshal_dump(int argc, VALUE *argv) https://github.com/ruby/ruby/blob/trunk/marshal.c#L964
 	else if (NIL_P(a1)) io_needed();
 	else port = a1;
     }
-    RB_GC_GUARD(wrapper) = TypedData_Make_Struct(rb_cData, struct dump_arg, &dump_arg_data, arg);
+    wrapper = TypedData_Make_Struct(rb_cData, struct dump_arg, &dump_arg_data, arg);
     arg->dest = 0;
     arg->symbols = st_init_numtable();
     arg->data    = st_init_numtable();
@@ -993,8 +993,8 @@ marshal_dump(int argc, VALUE *argv) https://github.com/ruby/ruby/blob/trunk/marshal.c#L993
 	rb_io_write(arg->dest, arg->str);
 	rb_str_resize(arg->str, 0);
     }
-    clear_dump_arg(arg);
-    RB_GC_GUARD(wrapper);
+    free_dump_arg(arg);
+    rb_gc_force_recycle(wrapper); /* also guards from premature GC */
 
     return port;
 }
@@ -1957,7 +1957,7 @@ marshal_load(int argc, VALUE *argv) https://github.com/ruby/ruby/blob/trunk/marshal.c#L1957
     VALUE port, proc;
     int major, minor, infection = 0;
     VALUE v;
-    volatile VALUE wrapper;
+    VALUE wrapper; /* used to avoid memory leak in case of exception */
     struct load_arg *arg;
 
     rb_scan_args(argc, argv, "11", &port, &proc);
@@ -1973,7 +1973,7 @@ marshal_load(int argc, VALUE *argv) https://github.com/ruby/ruby/blob/trunk/marshal.c#L1973
     else {
 	io_needed();
     }
-    RB_GC_GUARD(wrapper) = TypedData_Make_Struct(rb_cData, struct load_arg, &load_arg_data, arg);
+    wrapper = TypedData_Make_Struct(rb_cData, struct load_arg, &load_arg_data, arg);
     arg->infection = infection;
     arg->src = port;
     arg->offset = 0;
@@ -2004,8 +2004,8 @@ marshal_load(int argc, VALUE *argv) https://github.com/ruby/ruby/blob/trunk/marshal.c#L2004
 
     if (!NIL_P(proc)) arg->proc = proc;
     v = r_object(arg);
-    clear_load_arg(arg);
-    RB_GC_GUARD(wrapper);
+    free_load_arg(arg);
+    rb_gc_force_recycle(wrapper); /* also guards from premature GC */
 
     return v;
 }

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

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