summaryrefslogtreecommitdiff
path: root/re.c
diff options
context:
space:
mode:
authorJean Boussier <byroot@ruby-lang.org>2023-02-10 14:32:46 +0100
committerJean Boussier <jean.boussier@gmail.com>2023-02-10 16:12:22 +0100
commit46298955e42600eeeffd53dd683961d5f725e253 (patch)
treeb50310d5c7a19d34316b6b0d4cd5e7be9f17fa86 /re.c
parent11e0f62148de721538e69c174edc981b05079cda (diff)
downloadruby-46298955e42600eeeffd53dd683961d5f725e253.tar.gz
Implement Write Barrier for RMatch objects
They only have two references.
Diffstat (limited to 're.c')
-rw-r--r--re.c25
1 files changed, 12 insertions, 13 deletions
diff --git a/re.c b/re.c
index 308c7960ac..3b06caa1c4 100644
--- a/re.c
+++ b/re.c
@@ -961,11 +961,11 @@ VALUE rb_cMatch;
static VALUE
match_alloc(VALUE klass)
{
- NEWOBJ_OF(match, struct RMatch, klass, T_MATCH);
+ NEWOBJ_OF(match, struct RMatch, klass, T_MATCH | (RGENGC_WB_PROTECTED_MATCH ? FL_WB_PROTECTED : 0));
- match->str = 0;
+ match->str = Qfalse;
match->rmatch = 0;
- match->regexp = 0;
+ match->regexp = Qfalse;
match->rmatch = ZALLOC(struct rmatch);
return (VALUE)match;
@@ -1083,8 +1083,8 @@ match_init_copy(VALUE obj, VALUE orig)
if (!OBJ_INIT_COPY(obj, orig)) return obj;
- RMATCH(obj)->str = RMATCH(orig)->str;
- RMATCH(obj)->regexp = RMATCH(orig)->regexp;
+ RB_OBJ_WRITE(obj, &RMATCH(obj)->str, RMATCH(orig)->str);
+ RB_OBJ_WRITE(obj, &RMATCH(obj)->regexp, RMATCH(orig)->regexp);
rm = RMATCH(obj)->rmatch;
if (rb_reg_region_copy(&rm->regs, RMATCH_REGS(orig)))
@@ -1124,7 +1124,7 @@ match_regexp(VALUE match)
if (NIL_P(regexp)) {
VALUE str = rb_reg_nth_match(0, match);
regexp = rb_reg_regcomp(rb_reg_quote(str));
- RMATCH(match)->regexp = regexp;
+ RB_OBJ_WRITE(match, &RMATCH(match)->regexp, regexp);
}
return regexp;
}
@@ -1475,8 +1475,8 @@ match_set_string(VALUE m, VALUE string, long pos, long len)
struct RMatch *match = (struct RMatch *)m;
struct rmatch *rmatch = match->rmatch;
- match->str = string;
- match->regexp = Qnil;
+ RB_OBJ_WRITE(match, &RMATCH(match)->str, string);
+ RB_OBJ_WRITE(match, &RMATCH(match)->regexp, Qnil);
int err = onig_region_resize(&rmatch->regs, 1);
if (err) rb_memerror();
rmatch->regs.beg[0] = pos;
@@ -1737,7 +1737,7 @@ rb_reg_search_set_match(VALUE re, VALUE str, long pos, int reverse, int set_back
memcpy(RMATCH_REGS(match), regs, sizeof(struct re_registers));
if (set_backref_str) {
- RMATCH(match)->str = rb_str_new4(str);
+ RB_OBJ_WRITE(match, &RMATCH(match)->str, rb_str_new4(str));
}
else {
/* Note that a MatchData object with RMATCH(match)->str == 0 is incomplete!
@@ -1747,7 +1747,7 @@ rb_reg_search_set_match(VALUE re, VALUE str, long pos, int reverse, int set_back
rb_obj_hide(match);
}
- RMATCH(match)->regexp = re;
+ RB_OBJ_WRITE(match, &RMATCH(match)->regexp, re);
rb_backref_set(match);
if (set_match) *set_match = match;
@@ -1831,9 +1831,8 @@ rb_reg_start_with_p(VALUE re, VALUE str)
if (err) rb_memerror();
}
- RMATCH(match)->str = rb_str_new4(str);
-
- RMATCH(match)->regexp = re;
+ RB_OBJ_WRITE(match, &RMATCH(match)->str, rb_str_new4(str));
+ RB_OBJ_WRITE(match, &RMATCH(match)->regexp, re);
rb_backref_set(match);
return true;