mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* marshal.c (marshal_dump): fixed for check_dump_arg.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19653 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
7558136984
commit
1d54761948
2 changed files with 25 additions and 20 deletions
|
@ -1,4 +1,6 @@
|
|||
Wed Oct 1 18:57:31 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
Wed Oct 1 19:11:48 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* marshal.c (marshal_dump): fixed for check_dump_arg.
|
||||
|
||||
* marshal.c (marshal_dump): initializes dump_arg before any funcall.
|
||||
[ruby-dev:36648]
|
||||
|
|
41
marshal.c
41
marshal.c
|
@ -79,7 +79,7 @@ shortlen(long len, BDIGIT *ds)
|
|||
#define TYPE_LINK '@'
|
||||
|
||||
static ID s_dump, s_load, s_mdump, s_mload;
|
||||
static ID s_dump_data, s_load_data, s_alloc;
|
||||
static ID s_dump_data, s_load_data, s_alloc, s_call;
|
||||
static ID s_getbyte, s_read, s_write, s_binmode;
|
||||
|
||||
ID rb_id_encoding(void);
|
||||
|
@ -150,10 +150,11 @@ struct dump_call_arg {
|
|||
};
|
||||
|
||||
static void
|
||||
check_dump_arg(struct dump_arg *arg)
|
||||
check_dump_arg(struct dump_arg *arg, ID sym)
|
||||
{
|
||||
if (!DATA_PTR(arg->wrapper)) {
|
||||
rb_raise(rb_eRuntimeError, "Marshal.dump reentered");
|
||||
rb_raise(rb_eRuntimeError, "Marshal.dump reentered at %s",
|
||||
rb_id2name(sym));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -591,7 +592,7 @@ w_object(VALUE obj, struct dump_arg *arg, int limit)
|
|||
st_add_direct(arg->data, obj, arg->data->num_entries);
|
||||
|
||||
v = rb_funcall(obj, s_mdump, 0, 0);
|
||||
check_dump_arg(arg);
|
||||
check_dump_arg(arg, s_mdump);
|
||||
w_class(TYPE_USRMARSHAL, obj, arg, Qfalse);
|
||||
w_object(v, arg, limit);
|
||||
if (hasiv) w_ivar(obj, 0, &c_arg);
|
||||
|
@ -603,7 +604,7 @@ w_object(VALUE obj, struct dump_arg *arg, int limit)
|
|||
int hasiv2;
|
||||
|
||||
v = rb_funcall(obj, s_dump, 1, INT2NUM(limit));
|
||||
check_dump_arg(arg);
|
||||
check_dump_arg(arg, s_dump);
|
||||
if (TYPE(v) != T_STRING) {
|
||||
rb_raise(rb_eTypeError, "_dump() must return string");
|
||||
}
|
||||
|
@ -771,7 +772,7 @@ w_object(VALUE obj, struct dump_arg *arg, int limit)
|
|||
rb_obj_classname(obj));
|
||||
}
|
||||
v = rb_funcall(obj, s_dump_data, 0);
|
||||
check_dump_arg(arg);
|
||||
check_dump_arg(arg, s_dump_data);
|
||||
w_class(TYPE_DATA, obj, arg, Qtrue);
|
||||
w_object(v, arg, limit);
|
||||
}
|
||||
|
@ -882,7 +883,7 @@ marshal_dump(int argc, VALUE *argv)
|
|||
arg.dest = port;
|
||||
if (rb_respond_to(port, s_binmode)) {
|
||||
rb_funcall2(port, s_binmode, 0, 0);
|
||||
check_dump_arg(&arg, s_dump_data);
|
||||
check_dump_arg(&arg, s_binmode);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -915,10 +916,11 @@ struct load_arg {
|
|||
};
|
||||
|
||||
static void
|
||||
check_load_arg(struct load_arg *arg)
|
||||
check_load_arg(struct load_arg *arg, ID sym)
|
||||
{
|
||||
if (!DATA_PTR(arg->wrapper)) {
|
||||
rb_raise(rb_eRuntimeError, "Marshal.load reentered");
|
||||
rb_raise(rb_eRuntimeError, "Marshal.load reentered at %s",
|
||||
rb_id2name(sym));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -952,7 +954,7 @@ r_byte(struct load_arg *arg)
|
|||
else {
|
||||
VALUE src = arg->src;
|
||||
VALUE v = rb_funcall2(src, s_getbyte, 0, 0);
|
||||
check_load_arg(arg);
|
||||
check_load_arg(arg, s_getbyte);
|
||||
if (NIL_P(v)) rb_eof_error();
|
||||
c = (unsigned char)NUM2CHR(v);
|
||||
}
|
||||
|
@ -1029,7 +1031,7 @@ r_bytes0(long len, struct load_arg *arg)
|
|||
VALUE src = arg->src;
|
||||
VALUE n = LONG2NUM(len);
|
||||
str = rb_funcall2(src, s_read, 1, &n);
|
||||
check_load_arg(arg);
|
||||
check_load_arg(arg, s_read);
|
||||
if (NIL_P(str)) goto too_short;
|
||||
StringValue(str);
|
||||
if (RSTRING_LEN(str) != len) goto too_short;
|
||||
|
@ -1129,8 +1131,8 @@ r_leave(VALUE v, struct load_arg *arg)
|
|||
v = real_obj;
|
||||
}
|
||||
if (arg->proc) {
|
||||
v = rb_funcall(arg->proc, rb_intern("call"), 1, v);
|
||||
check_load_arg(arg);
|
||||
v = rb_funcall(arg->proc, s_call, 1, v);
|
||||
check_load_arg(arg, s_call);
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
@ -1215,8 +1217,8 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
|
|||
}
|
||||
v = (VALUE)link;
|
||||
if (arg->proc) {
|
||||
v = rb_funcall(arg->proc, rb_intern("call"), 1, v);
|
||||
check_load_arg(arg);
|
||||
v = rb_funcall(arg->proc, s_call, 1, v);
|
||||
check_load_arg(arg, s_call);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -1460,7 +1462,7 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
|
|||
*ivp = Qfalse;
|
||||
}
|
||||
v = rb_funcall(klass, s_load, 1, data);
|
||||
check_load_arg(arg);
|
||||
check_load_arg(arg, s_load);
|
||||
v = r_entry(v, arg);
|
||||
v = r_leave(v, arg);
|
||||
}
|
||||
|
@ -1485,7 +1487,7 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
|
|||
v = r_entry(v, arg);
|
||||
data = r_object(arg);
|
||||
rb_funcall(v, s_mload, 1, data);
|
||||
check_load_arg(arg);
|
||||
check_load_arg(arg, s_mload);
|
||||
v = r_leave(v, arg);
|
||||
}
|
||||
break;
|
||||
|
@ -1512,7 +1514,7 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
|
|||
warn = Qfalse;
|
||||
}
|
||||
v = rb_funcall(klass, s_alloc, 0);
|
||||
check_load_arg(arg);
|
||||
check_load_arg(arg, s_alloc);
|
||||
}
|
||||
else {
|
||||
v = rb_obj_alloc(klass);
|
||||
|
@ -1527,7 +1529,7 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
|
|||
rb_class2name(klass));
|
||||
}
|
||||
rb_funcall(v, s_load_data, 1, r_object0(arg, 0, extmod));
|
||||
check_load_arg(arg);
|
||||
check_load_arg(arg, s_load_data);
|
||||
v = r_leave(v, arg);
|
||||
}
|
||||
break;
|
||||
|
@ -1712,6 +1714,7 @@ Init_marshal(void)
|
|||
s_dump_data = rb_intern("_dump_data");
|
||||
s_load_data = rb_intern("_load_data");
|
||||
s_alloc = rb_intern("_alloc");
|
||||
s_call = rb_intern("call");
|
||||
s_getbyte = rb_intern("getbyte");
|
||||
s_read = rb_intern("read");
|
||||
s_write = rb_intern("write");
|
||||
|
|
Loading…
Reference in a new issue