1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44994 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
normal 2014-02-16 03:45:15 +00:00
parent 401cf928c1
commit f97051512a
2 changed files with 14 additions and 8 deletions

View file

@ -1,3 +1,9 @@
Sun Feb 16 11:55:14 2014 Eric Wong <e@80x24.org>
* 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@zzak.io> Sun Feb 16 08:11:23 2014 Zachary Scott <e@zzak.io>
* README.EXT.ja: [DOC] Fix typo by @utenmiki [Fixes GH-534] * README.EXT.ja: [DOC] Fix typo by @utenmiki [Fixes GH-534]

View file

@ -950,7 +950,7 @@ marshal_dump(int argc, VALUE *argv)
VALUE obj, port, a1, a2; VALUE obj, port, a1, a2;
int limit = -1; int limit = -1;
struct dump_arg *arg; struct dump_arg *arg;
volatile VALUE wrapper; VALUE wrapper; /* used to avoid memory leak in case of exception */
port = Qnil; port = Qnil;
rb_scan_args(argc, argv, "12", &obj, &a1, &a2); rb_scan_args(argc, argv, "12", &obj, &a1, &a2);
@ -964,7 +964,7 @@ marshal_dump(int argc, VALUE *argv)
else if (NIL_P(a1)) io_needed(); else if (NIL_P(a1)) io_needed();
else port = a1; 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->dest = 0;
arg->symbols = st_init_numtable(); arg->symbols = st_init_numtable();
arg->data = st_init_numtable(); arg->data = st_init_numtable();
@ -993,8 +993,8 @@ marshal_dump(int argc, VALUE *argv)
rb_io_write(arg->dest, arg->str); rb_io_write(arg->dest, arg->str);
rb_str_resize(arg->str, 0); rb_str_resize(arg->str, 0);
} }
clear_dump_arg(arg); free_dump_arg(arg);
RB_GC_GUARD(wrapper); rb_gc_force_recycle(wrapper); /* also guards from premature GC */
return port; return port;
} }
@ -1957,7 +1957,7 @@ marshal_load(int argc, VALUE *argv)
VALUE port, proc; VALUE port, proc;
int major, minor, infection = 0; int major, minor, infection = 0;
VALUE v; VALUE v;
volatile VALUE wrapper; VALUE wrapper; /* used to avoid memory leak in case of exception */
struct load_arg *arg; struct load_arg *arg;
rb_scan_args(argc, argv, "11", &port, &proc); rb_scan_args(argc, argv, "11", &port, &proc);
@ -1973,7 +1973,7 @@ marshal_load(int argc, VALUE *argv)
else { else {
io_needed(); 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->infection = infection;
arg->src = port; arg->src = port;
arg->offset = 0; arg->offset = 0;
@ -2004,8 +2004,8 @@ marshal_load(int argc, VALUE *argv)
if (!NIL_P(proc)) arg->proc = proc; if (!NIL_P(proc)) arg->proc = proc;
v = r_object(arg); v = r_object(arg);
clear_load_arg(arg); free_load_arg(arg);
RB_GC_GUARD(wrapper); rb_gc_force_recycle(wrapper); /* also guards from premature GC */
return v; return v;
} }