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

ruby-changes:45559

From: normal <ko1@a...>
Date: Wed, 15 Feb 2017 09:42:57 +0900 (JST)
Subject: [ruby-changes:45559] normal:r57631 (trunk): marshal.c: use hidden objects to allow recycling

normal	2017-02-15 09:42:51 +0900 (Wed, 15 Feb 2017)

  New Revision: 57631

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

  Log:
    marshal.c: use hidden objects to allow recycling
    
    Hidden objects (klass == 0) are not visible to Ruby code invoked
    from other threads or signal handlers, so they can never be
    accessed from other contexts.  This makes it safe to call
    rb_gc_force_recycle on the object slot after releasing malloc
    memory.
    
    * marshal.c (rb_marshal_dump_limited): hide dump_arg and recycle when done
      (rb_marshal_load_with_proc): hide load_arg and recycle when done
      [ruby-core:79518]

  Modified files:
    trunk/marshal.c
Index: marshal.c
===================================================================
--- marshal.c	(revision 57630)
+++ marshal.c	(revision 57631)
@@ -1026,7 +1026,7 @@ rb_marshal_dump_limited(VALUE obj, VALUE https://github.com/ruby/ruby/blob/trunk/marshal.c#L1026
     struct dump_arg *arg;
     VALUE wrapper; /* used to avoid memory leak in case of exception */
 
-    wrapper = TypedData_Make_Struct(rb_cData, struct dump_arg, &dump_arg_data, arg);
+    wrapper = TypedData_Make_Struct(0, struct dump_arg, &dump_arg_data, arg);
     arg->dest = 0;
     arg->symbols = st_init_numtable();
     arg->data    = rb_init_identtable();
@@ -1053,8 +1053,8 @@ rb_marshal_dump_limited(VALUE obj, VALUE https://github.com/ruby/ruby/blob/trunk/marshal.c#L1053
 	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);
 
     return port;
 }
@@ -2053,7 +2053,7 @@ rb_marshal_load_with_proc(VALUE port, VA https://github.com/ruby/ruby/blob/trunk/marshal.c#L2053
     else {
 	io_needed();
     }
-    wrapper = TypedData_Make_Struct(rb_cData, struct load_arg, &load_arg_data, arg);
+    wrapper = TypedData_Make_Struct(0, struct load_arg, &load_arg_data, arg);
     arg->infection = infection;
     arg->src = port;
     arg->offset = 0;
@@ -2084,8 +2084,8 @@ rb_marshal_load_with_proc(VALUE port, VA https://github.com/ruby/ruby/blob/trunk/marshal.c#L2084
 
     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);
 
     return v;
 }

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

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