From 02337b089e76a70ffc269beda8d778a175d575d3 Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 18 Jun 2008 03:05:33 +0000 Subject: [PATCH] * marshal.c (w_object, marshal_dump, r_object0, marshal_load): search public methods only. [ruby-core:17283] * object.c (convert_type): ditto. * lib/singleton.rb (Singleton#_dump): conversion method should be public. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17396 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 10 ++++++++++ lib/singleton.rb | 2 -- marshal.c | 22 +++++++++++----------- object.c | 2 +- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0e7e46dea3..f3c0702485 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +Wed Jun 18 12:05:30 2008 Nobuyoshi Nakada + + * marshal.c (w_object, marshal_dump, r_object0, marshal_load): search + public methods only. [ruby-core:17283] + + * object.c (convert_type): ditto. + + * lib/singleton.rb (Singleton#_dump): conversion method should be + public. + Wed Jun 18 10:18:11 2008 Nobuyoshi Nakada * ext/etc/etc.c (etc_passwd, etc_group): fixed rdoc. a patch from diff --git a/lib/singleton.rb b/lib/singleton.rb index a5c7eb164d..c6a2527d9a 100644 --- a/lib/singleton.rb +++ b/lib/singleton.rb @@ -71,8 +71,6 @@ module Singleton raise TypeError, "can't dup instance of singleton #{self.class}" end - private - # default marshalling strategy def _dump(depth = -1) '' diff --git a/marshal.c b/marshal.c index 692b37de93..c9170c6f37 100644 --- a/marshal.c +++ b/marshal.c @@ -582,7 +582,7 @@ w_object(VALUE obj, struct dump_arg *arg, int limit) else { if (OBJ_TAINTED(obj)) 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); @@ -594,7 +594,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; @@ -759,7 +759,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)); @@ -856,13 +856,13 @@ marshal_dump(int argc, VALUE *argv) } arg.dest = 0; 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"); } arg.str = rb_str_buf_new(0); arg.dest = port; - if (rb_obj_respond_to(port, s_binmode, Qtrue)) { + if (rb_respond_to(port, s_binmode)) { rb_funcall2(port, s_binmode, 0, 0); } } @@ -1420,7 +1420,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)); } @@ -1448,7 +1448,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)); } @@ -1475,7 +1475,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'"); @@ -1491,7 +1491,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)); @@ -1596,8 +1596,8 @@ marshal_load(int argc, VALUE *argv) arg.taint = OBJ_TAINTED(port); /* original taintedness */ 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; diff --git a/object.c b/object.c index 0d18ea5b29..e4f513763e 100644 --- a/object.c +++ b/object.c @@ -1904,7 +1904,7 @@ convert_type(VALUE val, const char *tname, const char *method, int raise) ID m; m = rb_intern(method); - if (!rb_obj_respond_to(val, m, Qtrue)) { + if (!rb_respond_to(val, m)) { if (raise) { rb_raise(rb_eTypeError, "can't convert %s into %s", NIL_P(val) ? "nil" :