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

ruby-changes:69521

From: Matt <ko1@a...>
Date: Sat, 30 Oct 2021 00:58:36 +0900 (JST)
Subject: [ruby-changes:69521] d7279f0894 (master): make obj_free return true when it frees an object

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

From d7279f0894d94da41367fe96d9b08ebfee6122d4 Mon Sep 17 00:00:00 2001
From: Matt Valentine-House <matt@e...>
Date: Fri, 29 Oct 2021 14:23:29 +0100
Subject: make obj_free return true when it frees an object

Previously obj_free returned true when it could not free a slot because
of a finalizer, and false when it successfully frees a slot.
---
 gc.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/gc.c b/gc.c
index 48b7b80b4bb..3fa1abb59a7 100644
--- a/gc.c
+++ b/gc.c
@@ -3247,7 +3247,7 @@ obj_free(rb_objspace_t *objspace, VALUE obj) https://github.com/ruby/ruby/blob/trunk/gc.c#L3247
 		else {
 		    make_zombie(objspace, obj, dfree, data);
                     RB_DEBUG_COUNTER_INC(obj_data_zombie);
-		    return 1;
+		    return FALSE;
 		}
 	    }
             else {
@@ -3281,7 +3281,7 @@ obj_free(rb_objspace_t *objspace, VALUE obj) https://github.com/ruby/ruby/blob/trunk/gc.c#L3281
 	if (RANY(obj)->as.file.fptr) {
 	    make_io_zombie(objspace, obj);
             RB_DEBUG_COUNTER_INC(obj_file_ptr);
-	    return 1;
+	    return FALSE;
 	}
 	break;
       case T_RATIONAL:
@@ -3403,7 +3403,7 @@ obj_free(rb_objspace_t *objspace, VALUE obj) https://github.com/ruby/ruby/blob/trunk/gc.c#L3403
             RB_DEBUG_COUNTER_INC(obj_imemo_constcache);
             break;
 	}
-	return 0;
+	return TRUE;
 
       default:
 	rb_bug("gc_sweep(): unknown data type 0x%x(%p) 0x%"PRIxVALUE,
@@ -3412,10 +3412,10 @@ obj_free(rb_objspace_t *objspace, VALUE obj) https://github.com/ruby/ruby/blob/trunk/gc.c#L3412
 
     if (FL_TEST(obj, FL_FINALIZE)) {
         make_zombie(objspace, obj, 0, 0);
-	return 1;
+	return FALSE;
     }
     else {
-	return 0;
+	return TRUE;
     }
 }
 
@@ -5343,9 +5343,6 @@ gc_plane_sweep(rb_objspace_t *objspace, rb_heap_t *heap, uintptr_t p, bits_t bit https://github.com/ruby/ruby/blob/trunk/gc.c#L5343
                     }
 #endif
                     if (obj_free(objspace, vp)) {
-                        ctx->final_slots++;
-                    }
-                    else {
                         if (heap->compact_cursor) {
                             /* We *want* to fill this slot */
                             MARK_IN_BITMAP(GET_HEAP_PINNED_BITS(vp), vp);
@@ -5356,7 +5353,9 @@ gc_plane_sweep(rb_objspace_t *objspace, rb_heap_t *heap, uintptr_t p, bits_t bit https://github.com/ruby/ruby/blob/trunk/gc.c#L5353
                             gc_report(3, objspace, "page_sweep: %s is added to freelist\n", obj_info(vp));
                             ctx->freed_slots++;
                         }
-
+                    }
+                    else {
+                        ctx->final_slots++;
                     }
                     break;
 
-- 
cgit v1.2.1


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

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