Skip to content

Commit

Permalink
Implement write barrier on StringIO
Browse files Browse the repository at this point in the history
It only has a single reference set in 3 places which
makes it fairly easy to implement.
  • Loading branch information
byroot authored and nobu committed Feb 28, 2023
1 parent 60bb320 commit 009896b
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions ext/stringio/stringio.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ static const rb_data_type_t strio_data_type = {
strio_free,
strio_memsize,
},
0, 0, RUBY_TYPED_FREE_IMMEDIATELY
0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED
};

#define check_strio(self) ((struct StringIO*)rb_check_typeddata((self), &strio_data_type))
Expand Down Expand Up @@ -379,7 +379,7 @@ strio_init(int argc, VALUE *argv, struct StringIO *ptr, VALUE self)
if (ptr->flags & FMODE_TRUNC) {
rb_str_resize(string, 0);
}
ptr->string = string;
RB_OBJ_WRITE(self, &ptr->string, string);
if (argc == 1) {
ptr->enc = rb_enc_get(string);
}
Expand All @@ -397,7 +397,7 @@ static VALUE
strio_finalize(VALUE self)
{
struct StringIO *ptr = StringIO(self);
ptr->string = Qnil;
RB_OBJ_WRITE(self, &ptr->string, Qnil);
ptr->flags &= ~FMODE_READWRITE;
return self;
}
Expand Down Expand Up @@ -563,7 +563,8 @@ strio_set_string(VALUE self, VALUE string)
ptr->flags = OBJ_FROZEN(string) ? FMODE_READABLE : FMODE_READWRITE;
ptr->pos = 0;
ptr->lineno = 0;
return ptr->string = string;
RB_OBJ_WRITE(self, &ptr->string, string);
return string;
}

/*
Expand Down

0 comments on commit 009896b

Please sign in to comment.