diff options
author | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-12-08 02:51:38 +0000 |
---|---|---|
committer | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-12-08 02:51:38 +0000 |
commit | f0680bdee869d37c0b654d0226ae665e6adc934e (patch) | |
tree | d9eecce90301c7aa9713e27063f8c373f42a011f /marshal.c | |
parent | 0399a3d47b4e784918f95a36c2987633c29f8690 (diff) |
merge revision(s) 52856,52906: [Backport #11760]
* encoding.c (enc_m_loader): defer finding encoding object not to
be infected by marshal source. [ruby-core:71793] [Bug #11760]
* marshal.c (r_object0): enable compatible loader on USERDEF
class. the loader function is called with the class itself,
instead of an allocated object, and the loaded data.
* marshal.c (compat_allocator_table): intialize
compat_allocator_tbl on demand.
* object.c (rb_undefined_alloc): extract from rb_obj_alloc.
* marshal.c (compat_allocator_table): initialize
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@52933 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'marshal.c')
-rw-r--r-- | marshal.c | 17 |
1 files changed, 15 insertions, 2 deletions
@@ -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 |