From 409a13e9ea018bbfa9dfc71c3427eff2dc4c4bd2 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Wed, 3 May 2023 14:19:17 +0900 Subject: [PATCH] [ruby/stringio] Update write-barrier at copying http://ci.rvm.jp/results/trunk-asserts@ruby-sp2-docker/4552803 ``` verify_internal_consistency_reachable_i: WB miss (O->Y) 0x00007f752ddd5550 [3LM ] strio (StringIO)strio -> 0x00007f752d19b7d0 [0 ] T_STRING (String) len: 8, capa: 15 "to_strio" :53: [BUG] gc_verify_internal_consistency: found internal inconsistency. ``` https://github.com/ruby/stringio/commit/2e8ab43cba --- ext/stringio/stringio.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c index 96e82ff5c1..99a19ead0d 100644 --- a/ext/stringio/stringio.c +++ b/ext/stringio/stringio.c @@ -698,15 +698,19 @@ strio_eof(VALUE self) static VALUE strio_copy(VALUE copy, VALUE orig) { - struct StringIO *ptr; + struct StringIO *ptr, *old_ptr; + VALUE old_string = Qundef; orig = rb_convert_type(orig, T_DATA, "StringIO", "to_strio"); if (copy == orig) return copy; ptr = StringIO(orig); - if (check_strio(copy)) { - strio_free(DATA_PTR(copy)); + old_ptr = check_strio(copy); + if (old_ptr) { + old_string = old_ptr->string; + strio_free(old_ptr); } DATA_PTR(copy) = ptr; + RB_OBJ_WRITTEN(copy, old_string, ptr->string); RBASIC(copy)->flags &= ~STRIO_READWRITE; RBASIC(copy)->flags |= RBASIC(orig)->flags & STRIO_READWRITE; ++ptr->count;