[ruby/stringio] Implement write barrier on StringIO

It only has a single reference set in 3 places which
makes it fairly easy to implement.

https://github.com/ruby/stringio/commit/009896b973
This commit is contained in:
Jean Boussier 2023-02-03 13:22:31 +01:00 коммит произвёл git
Родитель ad679ec9e5
Коммит 71dae78b89
1 изменённых файлов: 5 добавлений и 4 удалений

Просмотреть файл

@ -171,7 +171,7 @@ static const rb_data_type_t strio_data_type = {
strio_free, strio_free,
strio_memsize, 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)) #define check_strio(self) ((struct StringIO*)rb_check_typeddata((self), &strio_data_type))
@ -379,7 +379,7 @@ strio_init(int argc, VALUE *argv, struct StringIO *ptr, VALUE self)
if (ptr->flags & FMODE_TRUNC) { if (ptr->flags & FMODE_TRUNC) {
rb_str_resize(string, 0); rb_str_resize(string, 0);
} }
ptr->string = string; RB_OBJ_WRITE(self, &ptr->string, string);
if (argc == 1) { if (argc == 1) {
ptr->enc = rb_enc_get(string); ptr->enc = rb_enc_get(string);
} }
@ -397,7 +397,7 @@ static VALUE
strio_finalize(VALUE self) strio_finalize(VALUE self)
{ {
struct StringIO *ptr = StringIO(self); struct StringIO *ptr = StringIO(self);
ptr->string = Qnil; RB_OBJ_WRITE(self, &ptr->string, Qnil);
ptr->flags &= ~FMODE_READWRITE; ptr->flags &= ~FMODE_READWRITE;
return self; return self;
} }
@ -563,7 +563,8 @@ strio_set_string(VALUE self, VALUE string)
ptr->flags = OBJ_FROZEN(string) ? FMODE_READABLE : FMODE_READWRITE; ptr->flags = OBJ_FROZEN(string) ? FMODE_READABLE : FMODE_READWRITE;
ptr->pos = 0; ptr->pos = 0;
ptr->lineno = 0; ptr->lineno = 0;
return ptr->string = string; RB_OBJ_WRITE(self, &ptr->string, string);
return string;
} }
/* /*