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 --- error.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'error.c') diff --git a/error.c b/error.c index a7342de4e5..6297584ecd 100644 --- a/error.c +++ b/error.c @@ -608,13 +608,10 @@ exc_equal(VALUE exc, VALUE obj) CONST_ID(id_message, "message"); CONST_ID(id_backtrace, "backtrace"); - if (rb_respond_to(obj, id_message) && rb_respond_to(obj, id_backtrace)) { - mesg = rb_funcall(obj, id_message, 0, 0); - backtrace = rb_funcall(obj, id_backtrace, 0, 0); - } - else { - return Qfalse; - } + mesg = rb_check_funcall(obj, id_message, 0, 0); + if (mesg == Qundef) return Qfalse; + backtrace = rb_check_funcall(obj, id_backtrace, 0, 0); + if (backtrace == Qundef) return Qfalse; } else { mesg = rb_attr_get(obj, id_mesg); @@ -794,8 +791,8 @@ static const rb_data_type_t name_err_mesg_data_type = { }; /* :nodoc: */ -static VALUE -name_err_mesg_new(VALUE obj, VALUE mesg, VALUE recv, VALUE method) +VALUE +rb_name_err_mesg_new(VALUE obj, VALUE mesg, VALUE recv, VALUE method) { VALUE *ptr = ALLOC_N(VALUE, NAME_ERR_MESG_COUNT); @@ -1112,7 +1109,7 @@ Init_Exception(void) rb_define_method(rb_eNameError, "name", name_err_name, 0); rb_define_method(rb_eNameError, "to_s", name_err_to_s, 0); rb_cNameErrorMesg = rb_define_class_under(rb_eNameError, "message", rb_cData); - rb_define_singleton_method(rb_cNameErrorMesg, "!", name_err_mesg_new, NAME_ERR_MESG_COUNT); + rb_define_singleton_method(rb_cNameErrorMesg, "!", rb_name_err_mesg_new, NAME_ERR_MESG_COUNT); rb_define_method(rb_cNameErrorMesg, "==", name_err_mesg_equal, 1); rb_define_method(rb_cNameErrorMesg, "to_str", name_err_mesg_to_str, 0); rb_define_method(rb_cNameErrorMesg, "_dump", name_err_mesg_to_str, 1); -- cgit v1.2.3