[前][次][番号順一覧][スレッド一覧]

ruby-changes:74313

From: Aaron <ko1@a...>
Date: Wed, 2 Nov 2022 07:39:18 +0900 (JST)
Subject: [ruby-changes:74313] 70173a72a2 (master): Ivar copy needs to happen _before_ setting the shape

https://git.ruby-lang.org/ruby.git/commit/?id=70173a72a2

From 70173a72a29474b6fd8fdc629954a95a4b0a3793 Mon Sep 17 00:00:00 2001
From: Aaron Patterson <tenderlove@r...>
Date: Tue, 1 Nov 2022 12:31:24 -0700
Subject: Ivar copy needs to happen _before_ setting the shape

When we copy instance variables, it is possible for the GC to be kicked
off.  The GC looks at the shape to determine what slots to mark inside
the object.  If the shape is set too soon, the GC could think that there
are more instance variables on the object than there actually are at
that moment.
---
 misc/lldb_rb/rb_base_command.py | 4 ++--
 object.c                        | 8 ++++----
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/misc/lldb_rb/rb_base_command.py b/misc/lldb_rb/rb_base_command.py
index bf98b67612..de90a1617c 100644
--- a/misc/lldb_rb/rb_base_command.py
+++ b/misc/lldb_rb/rb_base_command.py
@@ -19,8 +19,8 @@ class RbBaseCommand: https://github.com/ruby/ruby/blob/trunk/misc/lldb_rb/rb_base_command.py#L19
 
         imemo_types = target.FindFirstType("enum imemo_type")
 
-        for member in imemo_types.GetEnumMembers():
-            g[member.GetName()] = member.GetValueAsUnsigned()
+        #for member in imemo_types.GetEnumMembers():
+        #    g[member.GetName()] = member.GetValueAsUnsigned()
 
         for enum in target.FindFirstGlobalVariable("ruby_dummy_gdb_enums"):
             enum = enum.GetType()
diff --git a/object.c b/object.c
index 5f8568e3b4..aa337ea2ce 100644
--- a/object.c
+++ b/object.c
@@ -298,6 +298,10 @@ init_copy(VALUE dest, VALUE obj) https://github.com/ruby/ruby/blob/trunk/object.c#L298
     rb_copy_generic_ivar(dest, obj);
     rb_gc_copy_finalizer(dest, obj);
 
+    if (RB_TYPE_P(obj, T_OBJECT)) {
+        rb_obj_copy_ivar(dest, obj);
+    }
+
     if (!RB_TYPE_P(obj, T_CLASS) && !RB_TYPE_P(obj, T_MODULE)) {
         rb_shape_t *shape_to_set = rb_shape_get_shape(obj);
 
@@ -310,10 +314,6 @@ init_copy(VALUE dest, VALUE obj) https://github.com/ruby/ruby/blob/trunk/object.c#L314
         // shape ids are different
         rb_shape_set_shape(dest, shape_to_set);
     }
-
-    if (RB_TYPE_P(obj, T_OBJECT)) {
-        rb_obj_copy_ivar(dest, obj);
-    }
 }
 
 static VALUE immutable_obj_clone(VALUE obj, VALUE kwfreeze);
-- 
cgit v1.2.3


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]