ruby-changes:33239
From: normal <ko1@a...>
Date: Wed, 12 Mar 2014 07:28:41 +0900 (JST)
Subject: [ruby-changes:33239] normal:r45318 (trunk): insns.def (opt_regexpmatch2): respect redefined match op
normal 2014-03-12 07:28:33 +0900 (Wed, 12 Mar 2014) New Revision: 45318 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45318 Log: insns.def (opt_regexpmatch2): respect redefined match op * insns.def (opt_regexpmatch2): respect redefined match op Thanks to Sam Rawlins for the fix. * test/ruby/test_string.rb: test based on Tsuyoshi Sawada's report [Bug #9581] Modified files: trunk/ChangeLog trunk/insns.def trunk/test/ruby/test_string.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 45317) +++ ChangeLog (revision 45318) @@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed Mar 12 07:26:05 2014 Eric Wong <e@8...> + + * insns.def (opt_regexpmatch2): respect redefined match op + Thanks to Sam Rawlins for the fix. + * test/ruby/test_string.rb: test based on Tsuyoshi Sawada's report + [Bug #9581] + Tue Mar 11 22:31:25 2014 Kazuki Tsujimoto <kazuki@c...> * ext/.document: add objspace/objspace_dump.c to document file. Index: insns.def =================================================================== --- insns.def (revision 45317) +++ insns.def (revision 45318) @@ -2154,7 +2154,7 @@ opt_regexpmatch2 https://github.com/ruby/ruby/blob/trunk/insns.def#L2154 (VALUE obj2, VALUE obj1) (VALUE val) { - if (RB_TYPE_P(obj2, T_STRING) && + if (CLASS_OF(obj2) == rb_cString && BASIC_OP_UNREDEFINED_P(BOP_MATCH, STRING_REDEFINED_OP_FLAG)) { val = rb_reg_match(obj1, obj2); } Index: test/ruby/test_string.rb =================================================================== --- test/ruby/test_string.rb (revision 45317) +++ test/ruby/test_string.rb (revision 45318) @@ -2219,6 +2219,19 @@ class TestString < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_string.rb#L2219 assert_equal("foo", "" =~ //) RUBY end + + class Bug9581 < String + def =~ re; :foo end + end + + def test_regexp_match_subclass + s = Bug9581.new("abc") + r = /abc/ + assert_equal(:foo, s =~ r) + assert_equal(:foo, s.send(:=~, r)) + assert_equal(:foo, s.send(:=~, /abc/)) + assert_equal(:foo, s =~ /abc/, "should not use optimized instruction") + end end class TestString2 < TestString -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/