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

ruby-changes:58480

From: Aaron <ko1@a...>
Date: Tue, 29 Oct 2019 08:15:49 +0900 (JST)
Subject: [ruby-changes:58480] da3774e5eb (master): Revert "Protect finalizer references during execution"

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

From da3774e5eb6de9dfe5c2ec6f3444c81d22c0e00a Mon Sep 17 00:00:00 2001
From: Aaron Patterson <tenderlove@r...>
Date: Mon, 28 Oct 2019 16:14:50 -0700
Subject: Revert "Protect finalizer references during execution"

This reverts commit 60a7f9f446604571f8a81499080c57c47baf0e6b.

We can't have Ruby objects pointing at T_ZOMBIE objects otherwise we get
an error in the GC.  We need to find a different way to update
references.

diff --git a/gc.c b/gc.c
index 19551ac..6fcdf2a 100644
--- a/gc.c
+++ b/gc.c
@@ -3370,7 +3370,12 @@ struct force_finalize_list { https://github.com/ruby/ruby/blob/trunk/gc.c#L3370
 static int
 force_chain_object(st_data_t key, st_data_t val, st_data_t arg)
 {
-    rb_ary_push((VALUE)arg, rb_ary_new_from_args(2, (VALUE)key, (VALUE)val));
+    struct force_finalize_list **prev = (struct force_finalize_list **)arg;
+    struct force_finalize_list *curr = ALLOC(struct force_finalize_list);
+    curr->obj = key;
+    curr->table = val;
+    curr->next = *prev;
+    *prev = curr;
     return ST_CONTINUE;
 }
 
@@ -3397,18 +3402,16 @@ rb_objspace_call_finalizer(rb_objspace_t *objspace) https://github.com/ruby/ruby/blob/trunk/gc.c#L3402
 
     /* force to run finalizer */
     while (finalizer_table->num_entries) {
-        long i;
-	VALUE list = rb_ary_new_capa(finalizer_table->num_entries);
-
-	st_foreach(finalizer_table, force_chain_object, (st_data_t)list);
-
-        for (i = 0; i < RARRAY_LEN(list); i++) {
-            VALUE tuple = RARRAY_AREF(list, i);
-            VALUE obj = RARRAY_AREF(tuple, 0);
-            VALUE table = RARRAY_AREF(tuple, 1);
-	    run_finalizer(objspace, obj, table);
+	struct force_finalize_list *list = 0;
+	st_foreach(finalizer_table, force_chain_object, (st_data_t)&list);
+	while (list) {
+	    struct force_finalize_list *curr = list;
+	    st_data_t obj = (st_data_t)curr->obj;
+	    run_finalizer(objspace, curr->obj, curr->table);
 	    st_delete(finalizer_table, &obj, 0);
-        }
+	    list = curr->next;
+	    xfree(curr);
+	}
     }
 
     /* prohibit GC because force T_DATA finalizers can break an object graph consistency */
-- 
cgit v0.10.2


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

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