Skip to content

Commit

Permalink
should not search the private methods with rb_obj_respond_to()
Browse files Browse the repository at this point in the history
  • Loading branch information
Watson1978 committed Jul 1, 2012
1 parent 960fa9b commit fa3b9df
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions marshal.c
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ w_object(VALUE obj, struct dump_arg *arg, int limit)
arg->taint = Qtrue;
}

if (rb_obj_respond_to(obj, s_mdump, Qtrue)) {
if (rb_respond_to(obj, s_mdump)) {
volatile VALUE v;

st_add_direct(arg->data, obj, arg->data->num_entries);
Expand All @@ -655,7 +655,7 @@ w_object(VALUE obj, struct dump_arg *arg, int limit)
if (hasiv) w_ivar(obj, 0, &c_arg);
return;
}
if (rb_obj_respond_to(obj, s_dump, Qtrue)) {
if (rb_respond_to(obj, s_dump)) {
VALUE v;
st_table *ivtbl2 = 0;
int hasiv2;
Expand Down Expand Up @@ -842,7 +842,7 @@ w_object(VALUE obj, struct dump_arg *arg, int limit)
{
VALUE v;

if (!rb_obj_respond_to(obj, s_dump_data, Qtrue)) {
if (!rb_respond_to(obj, s_dump_data)) {
rb_raise(rb_eTypeError,
"no marshal_dump is defined for class %s",
rb_obj_classname(obj));
Expand Down Expand Up @@ -954,15 +954,15 @@ marshal_dump(VALUE self, SEL sel, int argc, VALUE *argv)
arg->dest = 0;
bool got_io = false;
if (!NIL_P(port)) {
if (!rb_obj_respond_to(port, s_write, Qtrue)) {
if (!rb_respond_to(port, s_write)) {
type_error:
rb_raise(rb_eTypeError, "instance of IO needed");
}
GC_WB(&arg->str, rb_bstr_new());
#if 0 // unused
GC_WB(&arg->dest, port);
#endif
if (rb_obj_respond_to(port, s_binmode, Qtrue)) {
if (rb_respond_to(port, s_binmode)) {
rb_funcall2(port, s_binmode, 0, 0);
}
got_io = true;
Expand Down Expand Up @@ -1547,7 +1547,7 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
VALUE klass = path2class(r_unique(arg));
VALUE data;

if (!rb_obj_respond_to(klass, s_load, Qtrue)) {
if (!rb_respond_to(klass, s_load)) {
rb_raise(rb_eTypeError, "class %s needs to have method `_load'",
rb_class2name(klass));
}
Expand Down Expand Up @@ -1575,7 +1575,7 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
rb_extend_object(v, m);
}
}
if (!rb_obj_respond_to(v, s_mload, Qtrue)) {
if (!rb_respond_to(v, s_mload)) {
rb_raise(rb_eTypeError, "instance of %s needs to have method `marshal_load'",
rb_class2name(klass));
}
Expand Down Expand Up @@ -1603,7 +1603,7 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
case TYPE_DATA:
{
VALUE klass = path2class(r_unique(arg));
if (rb_obj_respond_to(klass, s_alloc, Qtrue)) {
if (rb_respond_to(klass, s_alloc)) {
static int warn = Qtrue;
if (warn) {
rb_warn("define `allocate' instead of `_alloc'");
Expand All @@ -1619,7 +1619,7 @@ r_object0(struct load_arg *arg, int *ivp, VALUE extmod)
rb_raise(rb_eArgError, "dump format error");
}
v = r_entry(v, arg);
if (!rb_obj_respond_to(v, s_load_data, Qtrue)) {
if (!rb_respond_to(v, s_load_data)) {
rb_raise(rb_eTypeError,
"class %s needs to have instance method `_load_data'",
rb_class2name(klass));
Expand Down Expand Up @@ -1728,9 +1728,8 @@ marshal_load(VALUE self, SEL sel, int argc, VALUE *argv)
v = rb_str_bstr(v);
port = v;
}
else if (rb_obj_respond_to(port, s_getbyte, Qtrue)
&& rb_obj_respond_to(port, s_read, Qtrue)) {
if (rb_obj_respond_to(port, s_binmode, Qtrue)) {
else if (rb_respond_to(port, s_getbyte) && rb_respond_to(port, s_read)) {
if (rb_respond_to(port, s_binmode)) {
rb_funcall2(port, s_binmode, 0, 0);
}
arg->taint = Qtrue;
Expand Down

0 comments on commit fa3b9df

Please sign in to comment.