summaryrefslogtreecommitdiff
path: root/marshal.c
diff options
context:
space:
mode:
Diffstat (limited to 'marshal.c')
-rw-r--r--marshal.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/marshal.c b/marshal.c
index 4cf4edc88b..9aba5e3204 100644
--- a/marshal.c
+++ b/marshal.c
@@ -109,6 +109,8 @@ mark_marshal_compat_t(void *tbl)
st_foreach(tbl, mark_marshal_compat_i, 0);
}
+static st_table *compat_allocator_table(void);
+
void
rb_marshal_define_compat(VALUE newclass, VALUE oldclass, VALUE (*dumper)(VALUE), VALUE (*loader)(VALUE, VALUE))
{
@@ -127,7 +129,7 @@ rb_marshal_define_compat(VALUE newclass, VALUE oldclass, VALUE (*dumper)(VALUE),
compat->dumper = dumper;
compat->loader = loader;
- st_insert(compat_allocator_tbl, (st_data_t)allocator, (st_data_t)compat);
+ st_insert(compat_allocator_table(), (st_data_t)allocator, (st_data_t)compat);
}
#define MARSHAL_INFECTION FL_TAINT
@@ -1753,6 +1755,7 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
{
VALUE klass = path2class(r_unique(arg));
VALUE data;
+ st_data_t d;
if (!rb_obj_respond_to(klass, s_load, TRUE)) {
rb_raise(rb_eTypeError, "class %s needs to have method `_load'",
@@ -1766,7 +1769,11 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
v = rb_funcall2(klass, s_load, 1, &data);
check_load_arg(arg, s_load);
v = r_entry(v, arg);
- v = r_leave(v, arg);
+ if (st_lookup(compat_allocator_tbl, (st_data_t)rb_get_alloc_func(klass), &d)) {
+ marshal_compat_t *compat = (marshal_compat_t*)d;
+ v = compat->loader(klass, v);
+ }
+ v = r_post_proc(v, arg);
}
break;
@@ -2128,11 +2135,17 @@ Init_marshal(void)
rb_define_const(rb_mMarshal, "MAJOR_VERSION", INT2FIX(MARSHAL_MAJOR));
/* minor version */
rb_define_const(rb_mMarshal, "MINOR_VERSION", INT2FIX(MARSHAL_MINOR));
+}
+static st_table *
+compat_allocator_table(void)
+{
+ if (compat_allocator_tbl) return compat_allocator_tbl;
compat_allocator_tbl = st_init_numtable();
compat_allocator_tbl_wrapper =
Data_Wrap_Struct(rb_cData, mark_marshal_compat_t, 0, compat_allocator_tbl);
rb_gc_register_mark_object(compat_allocator_tbl_wrapper);
+ return compat_allocator_tbl;
}
VALUE