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

ruby-changes:57145

From: nagachika <ko1@a...>
Date: Sun, 18 Aug 2019 14:08:10 +0900 (JST)
Subject: [ruby-changes:57145] nagachika: 54a470d09e (ruby_2_6): merge revision(s) f1b76ea63ce40670071a857f408a4747c571f1e9,1d1f98d49c9908f4e3928e582d31fd2e9f252f92: [Backport #16024]

https://git.ruby-lang.org/ruby.git/commit/?id=54a470d09e

From 54a470d09ea5bede6ca7a4ba70dd9ce345bfb3b5 Mon Sep 17 00:00:00 2001
From: nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>
Date: Sun, 18 Aug 2019 05:07:50 +0000
Subject: merge revision(s)
 f1b76ea63ce40670071a857f408a4747c571f1e9,1d1f98d49c9908f4e3928e582d31fd2e9f252f92:
 [Backport #16024]

	Occupy match data

	* string.c (rb_str_split_m): occupy match data not to be modified
	  during yielding the block.  [Bug #16024]

	Reuse match data

	* string.c (rb_str_split_m): reuse occupied match data.  [Bug #16024]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_6@67743 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

diff --git a/internal.h b/internal.h
index 28a2f74..e1e4cc0 100644
--- a/internal.h
+++ b/internal.h
@@ -1989,6 +1989,7 @@ long rb_reg_search0(VALUE, VALUE, long, int, int); https://github.com/ruby/ruby/blob/trunk/internal.h#L1989
 VALUE rb_reg_match_p(VALUE re, VALUE str, long pos);
 bool rb_reg_start_with_p(VALUE re, VALUE str);
 void rb_backref_set_string(VALUE string, long pos, long len);
+void rb_match_unbusy(VALUE);
 int rb_match_count(VALUE match);
 int rb_match_nth_defined(int nth, VALUE match);
 VALUE rb_reg_new_ary(VALUE ary, int options);
diff --git a/re.c b/re.c
index 88d0519..105c02a 100644
--- a/re.c
+++ b/re.c
@@ -1300,6 +1300,12 @@ rb_match_busy(VALUE match) https://github.com/ruby/ruby/blob/trunk/re.c#L1300
     FL_SET(match, MATCH_BUSY);
 }
 
+void
+rb_match_unbusy(VALUE match)
+{
+    FL_UNSET(match, MATCH_BUSY);
+}
+
 int
 rb_match_count(VALUE match)
 {
diff --git a/string.c b/string.c
index 1d1cd2f..0caea99 100644
--- a/string.c
+++ b/string.c
@@ -7949,9 +7949,13 @@ rb_str_split_m(int argc, VALUE *argv, VALUE str) https://github.com/ruby/ruby/blob/trunk/string.c#L7949
 	long idx;
 	int last_null = 0;
 	struct re_registers *regs;
+        VALUE match = 0;
 
-	while ((end = rb_reg_search(spat, str, start, 0)) >= 0) {
-	    regs = RMATCH_REGS(rb_backref_get());
+        for (; (end = rb_reg_search(spat, str, start, 0)) >= 0;
+             (match ? (rb_match_unbusy(match), rb_backref_set(match)) : (void)0)) {
+            match = rb_backref_get();
+            if (!result) rb_match_busy(match);
+            regs = RMATCH_REGS(match);
 	    if (start == end && BEG(0) == END(0)) {
 		if (!ptr) {
 		    SPLIT_STR(0, 0);
@@ -7982,6 +7986,7 @@ rb_str_split_m(int argc, VALUE *argv, VALUE str) https://github.com/ruby/ruby/blob/trunk/string.c#L7986
 	    }
 	    if (!NIL_P(limit) && lim <= ++i) break;
 	}
+        if (match) rb_match_unbusy(match);
     }
     if (RSTRING_LEN(str) > 0 && (!NIL_P(limit) || RSTRING_LEN(str) > beg || lim < 0)) {
 	SPLIT_STR(beg, RSTRING_LEN(str)-beg);
diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb
index aad4277..b8ae50d 100644
--- a/test/ruby/test_string.rb
+++ b/test/ruby/test_string.rb
@@ -1784,6 +1784,9 @@ CODE https://github.com/ruby/ruby/blob/trunk/test/ruby/test_string.rb#L1784
 
     result = []; "".split(//, 1) {|s| result << s}
     assert_equal([], result)
+
+    result = []; "aaa,bbb,ccc,ddd".split(/,/) {|s| result << s.gsub(/./, "A")}
+    assert_equal(["AAA"]*4, result)
   ensure
     $; = fs
   end
diff --git a/version.h b/version.h
index cf71153..f7cc71a 100644
--- a/version.h
+++ b/version.h
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/version.h#L1
 #define RUBY_VERSION "2.6.3"
 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
-#define RUBY_PATCHLEVEL 93
+#define RUBY_PATCHLEVEL 94
 
 #define RUBY_RELEASE_YEAR 2019
 #define RUBY_RELEASE_MONTH 8
-- 
cgit v0.10.2


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

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