summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-08-18 05:07:50 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-08-18 05:07:50 +0000
commit54a470d09ea5bede6ca7a4ba70dd9ce345bfb3b5 (patch)
treef75bd0669dac37c03dda4660490a6a11e6355040 /string.c
parent9ab43c7a6c0dc3c661ffb621714ee0c62bdd4566 (diff)
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
Diffstat (limited to 'string.c')
-rw-r--r--string.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/string.c b/string.c
index 1d1cd2fb06..0caea99096 100644
--- a/string.c
+++ b/string.c
@@ -7949,9 +7949,13 @@ rb_str_split_m(int argc, VALUE *argv, VALUE str)
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)
}
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);