From a4045e27b413aa096df19ac3547b61bc9bd34cf5 Mon Sep 17 00:00:00 2001 From: matz Date: Sun, 22 Oct 2006 22:24:14 +0000 Subject: [PATCH] * marshal.c (r_object0): use return value from prov given as the second argument to Marshal#load() to allow value replacement in the restoring data. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11211 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ marshal.c | 49 ++++++++++++++++++++++++++----------------------- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/ChangeLog b/ChangeLog index 21e62a5eb5..dafdc244a9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Mon Oct 23 04:30:04 2006 Yukihiro Matsumoto + + * marshal.c (r_object0): use return value from prov given as the + second argument to Marshal#load() to allow value replacement in + the restoring data. + Sun Oct 22 14:48:31 2006 Yukihiro Matsumoto * signal.c (Init_signal): avoid duplicated installation of SIGCHLD diff --git a/marshal.c b/marshal.c index 0d9e85268b..c59053439b 100644 --- a/marshal.c +++ b/marshal.c @@ -890,6 +890,9 @@ r_entry(VALUE v, struct load_arg *arg) { rb_hash_aset(arg->data, INT2FIX(RHASH(arg->data)->tbl->num_entries), v); if (arg->taint) OBJ_TAINT(v); + if (arg->proc) { + v = rb_funcall(arg->proc, rb_intern("call"), 1, v); + } return v; } @@ -931,7 +934,7 @@ path2module(const char *path) } static VALUE -r_object0(struct load_arg *arg, VALUE proc, int *ivp, VALUE extmod) +r_object0(struct load_arg *arg, int *ivp, VALUE extmod) { VALUE v = Qnil; int type = r_byte(arg); @@ -944,13 +947,16 @@ r_object0(struct load_arg *arg, VALUE proc, int *ivp, VALUE extmod) if (NIL_P(v)) { rb_raise(rb_eArgError, "dump format error (unlinked)"); } - return v; + if (arg->proc) { + v = rb_funcall(arg->proc, rb_intern("call"), 1, v); + } + break; case TYPE_IVAR: { int ivar = Qtrue; - v = r_object0(arg, 0, &ivar, extmod); + v = r_object0(arg, &ivar, extmod); if (ivar) r_ivar(v, arg); } break; @@ -962,7 +968,7 @@ r_object0(struct load_arg *arg, VALUE proc, int *ivp, VALUE extmod) if (NIL_P(extmod)) extmod = rb_ary_new2(0); rb_ary_push(extmod, m); - v = r_object0(arg, 0, 0, extmod); + v = r_object0(arg, 0, extmod); while (RARRAY_LEN(extmod) > 0) { m = rb_ary_pop(extmod); rb_extend_object(v, m); @@ -977,7 +983,7 @@ r_object0(struct load_arg *arg, VALUE proc, int *ivp, VALUE extmod) if (FL_TEST(c, FL_SINGLETON)) { rb_raise(rb_eTypeError, "singleton can't be loaded"); } - v = r_object0(arg, 0, 0, extmod); + v = r_object0(arg, 0, extmod); if (rb_special_const_p(v) || TYPE(v) == T_OBJECT || TYPE(v) == T_CLASS) { format_error: rb_raise(rb_eArgError, "dump format error (user class)"); @@ -1031,7 +1037,7 @@ r_object0(struct load_arg *arg, VALUE proc, int *ivp, VALUE extmod) d = load_mantissa(d, e, RSTRING_LEN(str) - (e - ptr)); } v = rb_float_new(d); - r_entry(v, arg); + v = r_entry(v, arg); } break; @@ -1076,7 +1082,7 @@ r_object0(struct load_arg *arg, VALUE proc, int *ivp, VALUE extmod) len--; } v = rb_big_norm((VALUE)big); - r_entry(v, arg); + v = r_entry(v, arg); } break; @@ -1097,7 +1103,7 @@ r_object0(struct load_arg *arg, VALUE proc, int *ivp, VALUE extmod) volatile long len = r_long(arg); /* gcc 2.7.2.3 -O2 bug?? */ v = rb_ary_new2(len); - r_entry(v, arg); + v = r_entry(v, arg); while (len--) { rb_ary_push(v, r_object(arg)); } @@ -1110,7 +1116,7 @@ r_object0(struct load_arg *arg, VALUE proc, int *ivp, VALUE extmod) long len = r_long(arg); v = rb_hash_new(); - r_entry(v, arg); + v = r_entry(v, arg); while (len--) { VALUE key = r_object(arg); VALUE value = r_object(arg); @@ -1141,7 +1147,7 @@ r_object0(struct load_arg *arg, VALUE proc, int *ivp, VALUE extmod) rb_ary_push(values, Qnil); } v = rb_struct_alloc(klass, values); - r_entry(v, arg); + v = r_entry(v, arg); for (i=0; iproc, 0, Qnil); + return r_object0(arg, 0, Qnil); } static VALUE