* [PATCH] marshal.c: use hidden objects to allow recycling
@ 2017-02-15 0:30 Eric Wong
0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2017-02-15 0:30 UTC (permalink / raw)
To: spew
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]
---
marshal.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/marshal.c b/marshal.c
index a9926acf56..b9c9e6a03e 100644
--- a/marshal.c
+++ b/marshal.c
@@ -1026,7 +1026,7 @@ rb_marshal_dump_limited(VALUE obj, VALUE port, int limit)
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 port, int limit)
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, VALUE proc)
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, VALUE proc)
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;
}
--
EW
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2017-02-15 0:30 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-15 0:30 [PATCH] marshal.c: use hidden objects to allow recycling Eric Wong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).