[ruby-dev:24362] Re: finalizer

From: nobu@...
Date: 2004-09-27 08:29:19 UTC
List: ruby-dev #24362
なかだです。

At Mon, 27 Sep 2004 15:06:32 +0900,
Tanaka Akira wrote in [ruby-dev:24361]:
> > なるほど。全ノードごとにコストが増えるのは避けたいので、stack
> > checkと同じタイミングに入れてみました。
> 
> えぇと、試してませんが、組み込みライブラリ等から明示的に rb_gc を呼び
> 出すときには、finalizer の実行による資源の開放を期待している - 具体的
> にいえば file descriptor の開放を期待している - ようなので、rb_gc とい
> う関数自体は finalizer を実行したほうがいいかも。

finalizerを実行しないのは、rb_{newobj,xmalloc,xrealloc}のみ?


--- gc.c~	2004-09-27 13:30:24.000000000 +0900
+++ gc.c	2004-09-27 15:43:05.000000000 +0900
@@ -93,4 +93,5 @@ static unsigned long malloc_limit = GC_M
 static void run_final();
 static VALUE nomem_error;
+static void gc_internal();
 
 void
@@ -120,9 +121,9 @@ ruby_xmalloc(size)
 
     if (malloc_increase > malloc_limit) {
-	rb_gc();
+	gc_internal();
     }
     RUBY_CRITICAL(mem = malloc(size));
     if (!mem) {
-	rb_gc();
+	gc_internal();
 	RUBY_CRITICAL(mem = malloc(size));
 	if (!mem) {
@@ -161,5 +162,5 @@ ruby_xrealloc(ptr, size)
     RUBY_CRITICAL(mem = realloc(ptr, size));
     if (!mem) {
-	rb_gc();
+	gc_internal();
 	RUBY_CRITICAL(mem = realloc(ptr, size));
 	if (!mem) {
@@ -386,5 +387,5 @@ rb_newobj()
     VALUE obj;
 
-    if (!freelist) rb_gc();
+    if (!freelist) gc_internal();
 
     obj = (VALUE)freelist;
@@ -1301,6 +1302,6 @@ int rb_setjmp (rb_jmp_buf);
 #endif /* __GNUC__ */
 
-void
-rb_gc()
+static void
+gc_internal()
 {
     struct gc_list *list;
@@ -1419,4 +1420,11 @@ rb_gc()
 }
 
+void
+rb_gc()
+{
+    gc_internal();
+    rb_gc_finalize_deferred();
+}
+
 /*
  *  call-seq:


-- 
--- 僕の前にBugはない。
--- 僕の後ろにBugはできる。
    中田 伸悦

In This Thread