itstommymorgan / asari

a Ruby wrapper for AWS CloudSearch.
52 stars 54 forks source link

Add support for Ruby 2.3 #52

Closed anolson closed 6 years ago

anolson commented 6 years ago

Why

In Ruby 2.3 a regression was introduced in the code that checks if an object responds to a method.

More info: https://bugs.ruby-lang.org/issues/12353

The issue is that as of Ruby 2.3, Marshal.dump no longer works with objects that inherit from BasicObject and do not directly define a respond_to? method. This is because vm_respond_to() in vm_method.c returns true if it can not find a method table entry for the respond_to? method, so w_object() in marshal.c tries to call marshal_dump. In Ruby 2.2 and prior, rb_obj_respond_to() would just call respond_to? instead of checking for a method table entry, so method_missing could receive the respond_to?.

Before (on master)

$ ruby -Ilib -rasari -e "p Marshal.dump Asari::Collection.sandbox_fake"
/Users/andrew/Code/ruby/asari/lib/asari/collection.rb:77:in `method_missing': undefined method `marshal_dump' for []:Array (NoMethodError)
    from -e:1:in `dump'
    from -e:1:in `<main>'

After (this branch)

$ ruby -Ilib -rasari -e "p Marshal.dump Asari::Collection.sandbox_fake"
"\x04\bo:\x16Asari::Collection\n:\x13@total_entriesi\x00:\x0F@page_sizei\x0F:\x11@total_pagesi\x06:\x12@current_pagei\x06:\n@data[\x00"

What

This adds a workaround for the issue mentioned above by implementing respond_to? in Asari::Collection – Another solution might be to change Asari::Collection so it subclasses Object instead of BasicObject

anolson commented 6 years ago

We should probably update the Travis config. Can we drop any of the older Ruby versions (1.9.3, etc)?