[Galago-commits] r2670 - in trunk/libgalago: . libgalago

galago-commits at freedesktop.org galago-commits at freedesktop.org
Tue Apr 4 23:07:21 PDT 2006


Author: chipx86
Date: 2006-04-04 23:07:15 -0700 (Tue, 04 Apr 2006)
New Revision: 2670

Modified:
   trunk/libgalago/ChangeLog
   trunk/libgalago/libgalago/galago-core.c
Log:
Rather than using the GalagoCore refcount to determine the init count, keep an actual init count integer. This prevents callers and things such as the python bindings from stealing a reference to the core and screwing up the init count.


Modified: trunk/libgalago/ChangeLog
===================================================================
--- trunk/libgalago/ChangeLog	2006-04-04 08:14:39 UTC (rev 2669)
+++ trunk/libgalago/ChangeLog	2006-04-05 06:07:15 UTC (rev 2670)
@@ -1,3 +1,11 @@
+Tue Apr 04 23:04:52 PDT 2006  Christian Hammond <chipx86 at chipx86.com>
+
+	* libgalago/galago-core.c:
+	  - Rather than using the GalagoCore refcount to determine the init count,
+	    keep an actual init count integer. This prevents callers and things
+	    such as the python bindings from stealing a reference to the core and
+	    screwing up the init count.
+
 Mon Apr 03 21:21:32 PDT 2006  Christian Hammond <chipx86 at chipx86.com>
 
 	* libgalago/galago-core.c:

Modified: trunk/libgalago/libgalago/galago-core.c
===================================================================
--- trunk/libgalago/libgalago/galago-core.c	2006-04-04 08:14:39 UTC (rev 2669)
+++ trunk/libgalago/libgalago/galago-core.c	2006-04-05 06:07:15 UTC (rev 2670)
@@ -38,6 +38,12 @@
 {
 	GalagoObject parent_object;
 
+	/*
+	 * We don't want to risk a caller reffing the core, so we keep a
+	 * separate init ref count here.
+	 */
+	unsigned int init_ref_count;
+
 	char *app_name;
 	char *conn_obj_path;
 	char *uid;
@@ -118,7 +124,7 @@
 /**************************************************************************
  * Object/Class support
  **************************************************************************/
-static void galago_core_finalize(GObject *gobject);
+static void galago_core_destroy(GalagoObject *gobject);
 
 static GalagoObjectClass *parent_class = NULL;
 static guint signals[LAST_SIGNAL] = {0};
@@ -152,15 +158,13 @@
 static void
 galago_core_class_init(GalagoCoreClass *klass)
 {
-	GObjectClass     *gobject_class = G_OBJECT_CLASS(klass);
 	GalagoObjectClass *object_class = GALAGO_OBJECT_CLASS(klass);
 
 	parent_class = g_type_class_peek_parent(klass);
 
 	object_class->dbus_interface = GALAGO_DBUS_CORE_INTERFACE;
+	object_class->destroy = galago_core_destroy;
 
-	gobject_class->finalize = galago_core_finalize;
-
 	klass->calc_priority_account = _galago_person_real_calc_priority_account;
 
 	signals[REGISTERED] =
@@ -236,10 +240,22 @@
 static void
 galago_core_init(GalagoCore *core)
 {
+	core->init_ref_count = 0;
+	core->app_name = NULL;
+	core->conn_obj_path = NULL;
+	core->uid = NULL;
+	core->dbus_conn = NULL;
+	core->flags = GALAGO_INIT_CLIENT;
+	core->daemon = FALSE;
+	core->registered = FALSE;
+	core->daemon_active = FALSE;
+	core->exit_with_daemon = FALSE;
+	core->registering_connection = FALSE;
+	core->block_signals = 0;
 }
 
 static void
-galago_core_finalize(GObject *object)
+galago_core_destroy(GalagoObject *object)
 {
 	GalagoContext *context;
 
@@ -261,7 +277,7 @@
 	_core = NULL;
 	G_UNLOCK(_core_lock);
 
-	G_OBJECT_CLASS(parent_class)->finalize(object);
+	parent_class->destroy(object);
 }
 
 /**************************************************************************
@@ -862,7 +878,7 @@
 
 	if (_core != NULL)
 	{
-		g_object_ref(_core);
+		_core->init_ref_count++;
 
 		return TRUE;
 	}
@@ -876,6 +892,7 @@
 
 	G_LOCK(_core_lock);
 	_core = g_object_new(GALAGO_TYPE_CORE, NULL);
+	_core->init_ref_count = 1;
 	G_UNLOCK(_core_lock);
 
 	galago_object_set_dbus_path(GALAGO_OBJECT(_core), GALAGO_DBUS_CORE_OBJECT);
@@ -899,8 +916,10 @@
 	if (!galago_is_initted())
 		return;
 
-	/* TODO: Will need to check if the object has been finalized somewhere. */
-	g_object_unref(_core);
+	_core->init_ref_count--;
+
+	if (_core->init_ref_count == 0)
+		galago_object_destroy(GALAGO_OBJECT(_core));
 }
 
 gboolean



More information about the galago-commits mailing list