[前][次][番号順一覧][スレッド一覧]

ruby-changes:30971

From: charliesome <ko1@a...>
Date: Thu, 26 Sep 2013 16:39:58 +0900 (JST)
Subject: [ruby-changes:30971] charliesome:r43050 (trunk): * insns.def (opt_regexpmatch1): check Regexp#=~ is not defined before

charliesome	2013-09-26 16:39:48 +0900 (Thu, 26 Sep 2013)

  New Revision: 43050

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43050

  Log:
    * insns.def (opt_regexpmatch1): check Regexp#=~ is not defined before
      calling rb_reg_match()
    
    * test/ruby/test_regexp.rb: add test
    
    * vm.c (ruby_vm_redefined_flag): change type to short[]
    
    * vm.c (vm_redefinition_check_flag): return REGEXP_REDEFINED_OP_FLAG if
      klass == rb_cRegexp
    
    * vm.c (vm_init_redefined_flag): setup BOP flag for Regexp#=~
    
    * vm_insnhelper.h: add REGEXP_REDEFINED_OP_FLAG
    
    [ruby-core:57385] [Bug #8953]

  Modified files:
    trunk/ChangeLog
    trunk/insns.def
    trunk/test/ruby/test_regexp.rb
    trunk/vm.c
    trunk/vm_insnhelper.h
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 43049)
+++ ChangeLog	(revision 43050)
@@ -1,3 +1,21 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Sep 26 16:24:00 2013  Charlie Somerville  <charliesome@r...>
+
+	* insns.def (opt_regexpmatch1): check Regexp#=~ is not defined before
+	  calling rb_reg_match()
+
+	* test/ruby/test_regexp.rb: add test
+
+	* vm.c (ruby_vm_redefined_flag): change type to short[]
+
+	* vm.c (vm_redefinition_check_flag): return REGEXP_REDEFINED_OP_FLAG if
+	  klass == rb_cRegexp
+
+	* vm.c (vm_init_redefined_flag): setup BOP flag for Regexp#=~
+
+	* vm_insnhelper.h: add REGEXP_REDEFINED_OP_FLAG
+
+	[ruby-core:57385] [Bug #8953]
+
 Thu Sep 26 14:46:49 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* gc.c (mark_locations_array): disable AddressSanitizer.  based on a
Index: insns.def
===================================================================
--- insns.def	(revision 43049)
+++ insns.def	(revision 43050)
@@ -2080,7 +2080,11 @@ opt_regexpmatch1 https://github.com/ruby/ruby/blob/trunk/insns.def#L2080
 (VALUE obj)
 (VALUE val)
 {
-    val = rb_reg_match(r, obj);
+    if (BASIC_OP_UNREDEFINED_P(BOP_MATCH, REGEXP_REDEFINED_OP_FLAG)) {
+	val = rb_reg_match(r, obj);
+    } else {
+	val = rb_funcall(r, idEqTilde, 1, obj);
+    }
 }
 
 /**
Index: vm.c
===================================================================
--- vm.c	(revision 43049)
+++ vm.c	(revision 43050)
@@ -99,7 +99,7 @@ VALUE rb_cEnv; https://github.com/ruby/ruby/blob/trunk/vm.c#L99
 VALUE rb_mRubyVMFrozenCore;
 
 VALUE ruby_vm_const_missing_count = 0;
-char ruby_vm_redefined_flag[BOP_LAST_];
+short ruby_vm_redefined_flag[BOP_LAST_];
 rb_thread_t *ruby_current_thread = 0;
 rb_vm_t *ruby_current_vm = 0;
 rb_event_flag_t ruby_vm_event_flags;
@@ -1016,6 +1016,7 @@ vm_redefinition_check_flag(VALUE klass) https://github.com/ruby/ruby/blob/trunk/vm.c#L1016
     if (klass == rb_cBignum) return BIGNUM_REDEFINED_OP_FLAG;
     if (klass == rb_cSymbol) return SYMBOL_REDEFINED_OP_FLAG;
     if (klass == rb_cTime)   return TIME_REDEFINED_OP_FLAG;
+    if (klass == rb_cRegexp) return REGEXP_REDEFINED_OP_FLAG;
     return 0;
 }
 
@@ -1094,6 +1095,7 @@ vm_init_redefined_flag(void) https://github.com/ruby/ruby/blob/trunk/vm.c#L1095
     OP(Size, SIZE), (C(Array), C(String), C(Hash));
     OP(EmptyP, EMPTY_P), (C(Array), C(String), C(Hash));
     OP(Succ, SUCC), (C(Fixnum), C(String), C(Time));
+    OP(EqTilde, MATCH), (C(Regexp));
 #undef C
 #undef OP
 }
Index: vm_insnhelper.h
===================================================================
--- vm_insnhelper.h	(revision 43049)
+++ vm_insnhelper.h	(revision 43050)
@@ -55,11 +55,12 @@ enum { https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.h#L55
   BOP_GE,
   BOP_NOT,
   BOP_NEQ,
+  BOP_MATCH,
 
   BOP_LAST_
 };
 
-extern char ruby_vm_redefined_flag[BOP_LAST_];
+extern short ruby_vm_redefined_flag[BOP_LAST_];
 extern VALUE ruby_vm_const_missing_count;
 
 #if VM_COLLECT_USAGE_DETAILS
@@ -237,6 +238,7 @@ enum vm_regan_acttype { https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.h#L238
 #define BIGNUM_REDEFINED_OP_FLAG (1 << 5)
 #define SYMBOL_REDEFINED_OP_FLAG (1 << 6)
 #define TIME_REDEFINED_OP_FLAG   (1 << 7)
+#define REGEXP_REDEFINED_OP_FLAG (1 << 8)
 
 #define BASIC_OP_UNREDEFINED_P(op, klass) (LIKELY((ruby_vm_redefined_flag[(op)]&(klass)) == 0))
 
Index: test/ruby/test_regexp.rb
===================================================================
--- test/ruby/test_regexp.rb	(revision 43049)
+++ test/ruby/test_regexp.rb	(revision 43050)
@@ -1011,6 +1011,18 @@ class TestRegexp < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_regexp.rb#L1011
     assert_equal(1, pr4.call(1))
   end
 
+  def test_eq_tilde_can_be_overridden
+    assert_in_out_err([], <<-RUBY, ["foo"], [])
+      class Regexp
+        def =~(str)
+          "foo"
+        end
+      end
+
+      puts // =~ ""
+    RUBY
+  end
+
   # This assertion is for porting x2() tests in testpy.py of Onigmo.
   def assert_match_at(re, str, positions, msg = nil)
     re = Regexp.new(re) unless re.is_a?(Regexp)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]