From 0580ba06110f7998fdaead724907a4c8d6540107 Mon Sep 17 00:00:00 2001 From: matz Date: Thu, 29 Oct 2009 04:55:10 +0000 Subject: * array.c (rb_ary_to_ary): do not use #respond_to? to detect to_ary. Just call. [ruby-core:23738] * eval.c (rb_check_funcall): new function with method existence check. returns Qundef when the method does not exist. * enumerator.c (enumerator_rewind): just call method, using rb_check_funcall(). [ruby-core:23738] * error.c (exc_equal): ditto. * object.c (convert_type): ditto. * error.c (rb_name_err_mesg_new): export function. * eval.c (make_exception): ditto. * io.c (pop_last_hash): return early when the last argument is nil. * io.c (rb_io_puts): treat T_STRING specially for small optimization. * vm_eval.c (raise_method_missing): skip method call if possible using rb_method_basic_definition_p(). * vm_eval.c (method_missing): ditto. * test/ruby/test_rubyoptions.rb (TestRubyOptions#test_debug): test suites changed to ignore exceptions caused by just-call policy. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25556 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- object.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'object.c') diff --git a/object.c b/object.c index 9f7537f12b..23e5d9ec81 100644 --- a/object.c +++ b/object.c @@ -2005,6 +2005,8 @@ convert_type(VALUE val, const char *tname, const char *method, int raise) { ID m = 0; int i; + VALUE args[4]; + VALUE r; for (i=0; conv_method_names[i].method; i++) { if (conv_method_names[i].method[0] == method[0] && @@ -2014,7 +2016,12 @@ convert_type(VALUE val, const char *tname, const char *method, int raise) } } if (!m) m = rb_intern(method); - if (!rb_respond_to(val, m)) { + args[0] = val; + args[1] = (VALUE)m; + args[2] = (VALUE)raise; + args[3] = (VALUE)tname; + r = rb_check_funcall(val, m, 0, 0); + if (r == Qundef) { if (raise) { rb_raise(rb_eTypeError, "can't convert %s into %s", NIL_P(val) ? "nil" : @@ -2023,11 +2030,9 @@ convert_type(VALUE val, const char *tname, const char *method, int raise) rb_obj_classname(val), tname); } - else { - return Qnil; - } + return Qnil; } - return rb_funcall(val, m, 0); + return r; } VALUE -- cgit v1.2.3