Project

General

Profile

Actions

Bug #12907

closed

rb_respond_to() return value is incorrect

Added by ohler (Peter Ohler) about 8 years ago. Updated over 5 years ago.

Status:
Closed
Target version:
-
[ruby-core:78029]

Description

As of Ruby 2.3.0 rb_respond_to incorrectly reports non-zero for methods that are not supported. This occurs with subclasses of BasicObject. This occurs with Oj when but should occur with other C code. A simple sample that demonstrates the failure in below. It works fine on all versions of Ruby until 2.3.0.

require 'oj'

class A < BasicObject
  def initialize(data)
    @data = data
  end
end

a = A.new("xyz")

json = Oj.dump(a, mode: :compat, use_to_json: true)
#=> NoMethodError: undefined method `to_hash' for #<A:0x007fae03de1dc8>

In the C code the rb_respond_to() function is called to determine if an instance of A responds to "to_hash". 1 is returned in Ruby 2.3.x while previous versions correctly returned 0.

Updated by eugene (Eugene Pimenov) almost 8 years ago

  • ruby -v changed from 2.3.0, 2.3.1 to 2.3.0-3

We did hit this bug on our system and did a deep dive in it yesterday.

The code to reproduce the issue is:

rb_respond_to(rb_eval_string("BasicObject.new"), rb_intern("anythinghere"))

It always returns 1 (TRUE) in ruby 2.3.x. It's caused by [the following line]. Because respond_to method doesn't exist in BasicObject. The correct code was reverted in [r55869 ] because it breaks ActiveSupport 4.1.

As far as I can tell the issue is fixed in trunk and 2.4.x betas.

Updated by shyouhei (Shyouhei Urabe) almost 8 years ago

  • Status changed from Open to Assigned
  • Assignee set to nagachika (Tomoyuki Chikanaga)

Chikanaga-san please handle this because it seems 2.3 only.

Actions #3

Updated by jeremyevans0 (Jeremy Evans) over 5 years ago

  • Status changed from Assigned to Closed
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0