diff options
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 9 |
1 files changed, 5 insertions, 4 deletions
@@ -5866,8 +5866,7 @@ rb_str_sub(int argc, VALUE *argv, VALUE str) static VALUE str_gsub(int argc, VALUE *argv, VALUE str, int bang) { - VALUE pat, val = Qnil, repl, match, match0 = Qnil, dest, hash = Qnil; - struct re_registers *regs; + VALUE pat, val = Qnil, repl, match0 = Qnil, dest, hash = Qnil; long beg, beg0, end0; long offset, blen, slen, len, last; enum {STR, ITER, MAP} mode = STR; @@ -5912,8 +5911,8 @@ str_gsub(int argc, VALUE *argv, VALUE str, int bang) ENC_CODERANGE_SET(dest, rb_enc_asciicompat(str_enc) ? ENC_CODERANGE_7BIT : ENC_CODERANGE_VALID); do { - match = rb_backref_get(); - regs = RMATCH_REGS(match); + VALUE match = rb_backref_get(); + struct re_registers *regs = RMATCH_REGS(match); if (RB_TYPE_P(pat, T_STRING)) { beg0 = beg; end0 = beg0 + RSTRING_LEN(pat); @@ -5970,6 +5969,8 @@ str_gsub(int argc, VALUE *argv, VALUE str, int bang) cp = RSTRING_PTR(str) + offset; if (offset > RSTRING_LEN(str)) break; beg = rb_pat_search(pat, str, offset, need_backref); + + RB_GC_GUARD(match); } while (beg >= 0); if (RSTRING_LEN(str) > offset) { rb_enc_str_buf_cat(dest, cp, RSTRING_LEN(str) - offset, str_enc); |