[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Avoiding scm_protect_object
From: |
gregory benison |
Subject: |
Re: Avoiding scm_protect_object |
Date: |
Mon, 30 Oct 2006 21:58:50 -0800 |
I just checked in an implementation of scm_glib_gc_protect_object, and
its unprotect counterpart, into the guile-gnome repository. It seems to
fix the GC problems that were first found by Gregory.
One quick question about the new code in gc.c -- is it better to
export the symbol
'scm_init_gnome_gobject_gc', with the "clients" of the code
responsible for calling that before using
scm_glib_gc_[un]protect_object, or is it better to have an
initialization function more like the *_get_type() functions from gtk-
something that gets called frequently but just returns quickly after
the first time. To me that seems like a very small hit in performance
in exchange for no chance later of bugs due to "forgetting to call
scm_init_gnome_gobject_gc"- any thoughts?
=== modified file 'gnome/gobject/gc.c'
--- gnome/gobject/gc.c 2006-10-30 16:42:54 +0000
+++ gnome/gobject/gc.c 2006-10-31 05:41:50 +0000
@@ -50,6 +50,8 @@
{
gpointer key = SCM_TO_GPOINTER (obj);
gpointer val;
+
+ scm_init_gnome_gobject_gc();
G_LOCK (glib_gc_marker_hash_lock);
val = g_hash_table_lookup (glib_gc_marker_hash, key);
@@ -65,6 +67,8 @@
{
gpointer key = SCM_TO_GPOINTER (obj);
gpointer val;
+
+ scm_init_gnome_gobject_gc();
G_LOCK (glib_gc_marker_hash_lock);
val = g_hash_table_lookup (glib_gc_marker_hash, key);
@@ -101,9 +105,14 @@
return 1;
}
-void
+static void
scm_init_gnome_gobject_gc (void)
{
+
+ static gboolean is_initialized = FALSE;
+ if (is_initialized) return;
+ is_initialized = TRUE;
+
scm_tc16_glib_gc_marker = scm_make_smob_type ("%glib-gc-marker", 0);
scm_set_smob_mark (scm_tc16_glib_gc_marker, glib_gc_marker_mark);
scm_set_smob_print (scm_tc16_glib_gc_marker, glib_gc_marker_print);
======================
Gregory Benison
Oregon State University
(541)-737-1876
gbenison at gmail dot com
======================