Skip to content

Commit

Permalink
merge revision(s) r32855,r32857,r33493,r34554:
Browse files Browse the repository at this point in the history
	* vm_eval.c (check_funcall): try respond_to? first if redefined.
	  [Bug ruby#5158]

	* test/ruby/test_object.rb: tests that respond_to? returns false.

	* vm_eval.c (check_funcall): set array elements one-by-one to fix
	  compile error with Fujitsu C Compiler 5.6 on Solaris 10 on Sparc.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@34615 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nobu committed Feb 15, 2012
1 parent 50a470b commit afcd556
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 7 deletions.
14 changes: 14 additions & 0 deletions ChangeLog
@@ -1,3 +1,17 @@
Wed Feb 15 10:25:22 2012 Naohisa Goto <ngotogenome@gmail.com>

* vm_eval.c (check_funcall): set array elements one-by-one to fix
compile error with Fujitsu C Compiler 5.6 on Solaris 10 on Sparc.

Wed Feb 15 10:25:22 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>

* test/ruby/test_object.rb: tests that respond_to? returns false.

Wed Feb 15 10:25:22 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>

* vm_eval.c (check_funcall): try respond_to? first if redefined.
[Bug #5158]

Wed Feb 15 07:15:50 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>

* compile.c (defined_expr): guard the whole expression.
Expand Down
37 changes: 37 additions & 0 deletions test/ruby/test_object.rb
Expand Up @@ -181,18 +181,30 @@ def test_convert_type
o = Object.new
def o.to_s; 1; end
assert_raise(TypeError) { String(o) }
def o.to_s; "o"; end
assert_equal("o", String(o))
def o.respond_to?(*) false; end
assert_raise(TypeError) { String(o) }
end

def test_check_convert_type
o = Object.new
def o.to_a; 1; end
assert_raise(TypeError) { Array(o) }
def o.to_a; [1]; end
assert_equal([1], Array(o))
def o.respond_to?(*) false; end
assert_equal([o], Array(o))
end

def test_to_integer
o = Object.new
def o.to_i; nil; end
assert_raise(TypeError) { Integer(o) }
def o.to_i; 42; end
assert_equal(42, Integer(o))
def o.respond_to?(*) false; end
assert_raise(TypeError) { Integer(o) }
end

class MyInteger
Expand Down Expand Up @@ -383,6 +395,31 @@ def method_missing(id,*args)
end
end

def test_implicit_respond_to
bug5158 = '[ruby-core:38799]'

p = Object.new

called = []
p.singleton_class.class_eval do
define_method(:to_ary) do
called << [:to_ary, bug5158]
end
end
[[p]].flatten
assert_equal([[:to_ary, bug5158]], called, bug5158)

called = []
p.singleton_class.class_eval do
define_method(:respond_to?) do |*a|
called << [:respond_to?, *a]
false
end
end
[[p]].flatten
assert_equal([[:respond_to?, :to_ary, true]], called, bug5158)
end

def test_method_missing_passed_block
bug5731 = '[ruby-dev:44961]'

Expand Down
2 changes: 1 addition & 1 deletion test/ruby/test_proc.rb
Expand Up @@ -787,7 +787,7 @@ def test_attr_source_location
end

def test_splat_without_respond_to
def (obj = Object.new).respond_to?(m); false end
def (obj = Object.new).respond_to?(m,*); false end
[obj].each do |a, b|
assert_equal([obj, nil], [a, b], '[ruby-core:24139]')
end
Expand Down
2 changes: 1 addition & 1 deletion version.h
@@ -1,5 +1,5 @@
#define RUBY_VERSION "1.9.3"
#define RUBY_PATCHLEVEL 117
#define RUBY_PATCHLEVEL 118

#define RUBY_RELEASE_DATE "2012-02-15"
#define RUBY_RELEASE_YEAR 2012
Expand Down
24 changes: 19 additions & 5 deletions vm_eval.c
Expand Up @@ -204,7 +204,7 @@ stack_check(void)
}

static inline rb_method_entry_t *rb_search_method_entry(VALUE recv, ID mid);
static inline int rb_method_call_status(rb_thread_t *th, rb_method_entry_t *me, call_type scope, VALUE self);
static inline int rb_method_call_status(rb_thread_t *th, const rb_method_entry_t *me, call_type scope, VALUE self);
#define NOEX_OK NOEX_NOSUPER

/*!
Expand Down Expand Up @@ -266,12 +266,26 @@ check_funcall_failed(struct rescue_funcall_args *args, VALUE e)
static VALUE
check_funcall(VALUE recv, ID mid, int argc, VALUE *argv)
{
rb_method_entry_t *me = rb_search_method_entry(recv, mid);
VALUE klass = CLASS_OF(recv);
const rb_method_entry_t *me;
rb_thread_t *th = GET_THREAD();
int call_status = rb_method_call_status(th, me, CALL_FCALL, Qundef);
int call_status;

me = rb_method_entry(klass, idRespond_to);
if (me && !(me->flag & NOEX_BASIC)) {
VALUE args[2];

args[0] = ID2SYM(mid);
args[1] = Qtrue;
if (!RTEST(vm_call0(th, recv, idRespond_to, 2, args, me))) {
return Qundef;
}
}

me = rb_search_method_entry(recv, mid);
call_status = rb_method_call_status(th, me, CALL_FCALL, Qundef);
if (call_status != NOEX_OK) {
if (rb_method_basic_definition_p(CLASS_OF(recv), idMethodMissing)) {
if (rb_method_basic_definition_p(klass, idMethodMissing)) {
return Qundef;
}
else {
Expand Down Expand Up @@ -376,7 +390,7 @@ rb_search_method_entry(VALUE recv, ID mid)
}

static inline int
rb_method_call_status(rb_thread_t *th, rb_method_entry_t *me, call_type scope, VALUE self)
rb_method_call_status(rb_thread_t *th, const rb_method_entry_t *me, call_type scope, VALUE self)
{
VALUE klass;
ID oid;
Expand Down

0 comments on commit afcd556

Please sign in to comment.