[Galago-commits] r2663 - in trunk/libgalago: . libgalago tests

galago-commits at freedesktop.org galago-commits at freedesktop.org
Mon Apr 3 01:20:30 PDT 2006


Author: chipx86
Date: 2006-04-03 01:20:17 -0700 (Mon, 03 Apr 2006)
New Revision: 2663

Added:
   trunk/libgalago/tests/test-bug-36.c
Modified:
   trunk/libgalago/ChangeLog
   trunk/libgalago/libgalago/galago-account.c
   trunk/libgalago/libgalago/galago-context.c
   trunk/libgalago/libgalago/galago-object.c
   trunk/libgalago/libgalago/galago-object.h
   trunk/libgalago/libgalago/galago-person.c
   trunk/libgalago/libgalago/galago-presence.c
   trunk/libgalago/libgalago/galago-service.c
   trunk/libgalago/tests/Makefile.am
Log:
- Added galago_object_destroy, and call it from many places where we currently call g_object_unref. galago_object_destroy is much like gtk_widget_destroy/gtk_object_destroy, in that it runs g_object_run_dispose() on the object. This actually solves many issues.
- Added a test case for bug #36.


Modified: trunk/libgalago/ChangeLog
===================================================================
--- trunk/libgalago/ChangeLog	2006-04-03 07:56:38 UTC (rev 2662)
+++ trunk/libgalago/ChangeLog	2006-04-03 08:20:17 UTC (rev 2663)
@@ -1,3 +1,21 @@
+Mon Apr 03 01:18:29 PDT 2006  Christian Hammond <chipx86 at chipx86.com>
+
+	* libgalago/galago-account.c:
+	* libgalago/galago-context.c:
+	* libgalago/galago-object.c:
+	* libgalago/galago-object.h:
+	* libgalago/galago-person.c:
+	* libgalago/galago-presence.c:
+	* libgalago/galago-service.c:
+	* tests/Makefile.am:
+	A tests/test-bug-36.c:
+	  - Added galago_object_destroy, and call it from many places where
+	    we currently call g_object_unref. galago_object_destroy is much
+	    like gtk_widget_destroy/gtk_object_destroy, in that it runs
+	    g_object_run_dispose() on the object. This actually solves many
+	    issues.
+	  - Added a test case for bug #36.
+
 Mon Apr 03 00:55:06 PDT 2006  Christian Hammond <chipx86 at chipx86.com>
 
 	* libgalago/galago-context.c:

Modified: trunk/libgalago/libgalago/galago-account.c
===================================================================
--- trunk/libgalago/libgalago/galago-account.c	2006-04-03 07:56:38 UTC (rev 2662)
+++ trunk/libgalago/libgalago/galago-account.c	2006-04-03 08:20:17 UTC (rev 2663)
@@ -248,19 +248,11 @@
 
 	if (account->priv != NULL)
 	{
-		if (account->priv->presence != NULL &&
-			!GALAGO_OBJECT_HAS_FLAG(account->priv->presence,
-									GALAGO_OBJECT_IN_DESTRUCTION))
-		{
-			g_object_unref(account->priv->presence);
-		}
+		if (account->priv->presence != NULL)
+			galago_object_destroy(GALAGO_OBJECT(account->priv->presence));
 
-		if (account->priv->avatar != NULL &&
-			!GALAGO_OBJECT_HAS_FLAG(account->priv->avatar,
-									GALAGO_OBJECT_IN_DESTRUCTION))
-		{
-			g_object_unref(account->priv->avatar);
-		}
+		if (account->priv->avatar != NULL)
+			galago_object_destroy(GALAGO_OBJECT(account->priv->avatar));
 
 		if (account->priv->contacts_table != NULL)
 			g_hash_table_destroy(account->priv->contacts_table);
@@ -877,11 +869,8 @@
 	if (account->priv->avatar != NULL)
 	{
 		GalagoImage *old_avatar = account->priv->avatar;
-
 		account->priv->avatar = NULL;
-
-		if (!GALAGO_OBJECT_HAS_FLAG(old_avatar, GALAGO_OBJECT_IN_DESTRUCTION))
-			g_object_unref(old_avatar);
+		galago_object_destroy(GALAGO_OBJECT(old_avatar));
 	}
 
 	account->priv->avatar = avatar;
@@ -926,15 +915,9 @@
 	if (account->priv->presence != NULL)
 	{
 		GalagoPresence *old_presence = account->priv->presence;
-
 		account->priv->presence = NULL;
+		galago_object_destroy(GALAGO_OBJECT(old_presence));
 
-		if (!GALAGO_OBJECT_HAS_FLAG(old_presence,
-									GALAGO_OBJECT_IN_DESTRUCTION))
-		{
-			g_object_unref(old_presence);
-		}
-
 		emit_deleted = (presence == NULL);
 	}
 

Modified: trunk/libgalago/libgalago/galago-context.c
===================================================================
--- trunk/libgalago/libgalago/galago-context.c	2006-04-03 07:56:38 UTC (rev 2662)
+++ trunk/libgalago/libgalago/galago-context.c	2006-04-03 08:20:17 UTC (rev 2663)
@@ -175,13 +175,13 @@
 	if (context->priv != NULL)
 	{
 		g_list_foreach(context->priv->local.services,
-					   (GFunc)g_object_run_dispose, NULL);
+					   (GFunc)galago_object_destroy, NULL);
 		g_list_foreach(context->priv->remote.services,
-					   (GFunc)g_object_run_dispose, NULL);
+					   (GFunc)galago_object_destroy, NULL);
 		g_list_foreach(context->priv->local.people,
-					   (GFunc)g_object_run_dispose, NULL);
+					   (GFunc)galago_object_destroy, NULL);
 		g_list_foreach(context->priv->remote.people,
-					   (GFunc)g_object_run_dispose, NULL);
+					   (GFunc)galago_object_destroy, NULL);
 
 		g_hash_table_destroy(context->priv->services_table);
 		g_hash_table_destroy(context->priv->people_table);
@@ -728,9 +728,9 @@
 	{
 		case GALAGO_LOCAL:
 			g_list_foreach(context->priv->local.services,
-						   (GFunc)g_object_run_dispose, NULL);
+						   (GFunc)galago_object_destroy, NULL);
 			g_list_foreach(context->priv->local.people,
-						   (GFunc)g_object_run_dispose, NULL);
+						   (GFunc)galago_object_destroy, NULL);
 
 			context->priv->local.services = NULL;
 			context->priv->local.people   = NULL;
@@ -738,9 +738,9 @@
 
 		case GALAGO_REMOTE:
 			g_list_foreach(context->priv->remote.services,
-						   (GFunc)g_object_run_dispose, NULL);
+						   (GFunc)galago_object_destroy, NULL);
 			g_list_foreach(context->priv->remote.people,
-						   (GFunc)g_object_run_dispose, NULL);
+						   (GFunc)galago_object_destroy, NULL);
 
 			context->priv->remote.services = NULL;
 			context->priv->remote.people   = NULL;

Modified: trunk/libgalago/libgalago/galago-object.c
===================================================================
--- trunk/libgalago/libgalago/galago-object.c	2006-04-03 07:56:38 UTC (rev 2662)
+++ trunk/libgalago/libgalago/galago-object.c	2006-04-03 08:20:17 UTC (rev 2663)
@@ -250,6 +250,17 @@
 	}
 }
 
+void
+galago_object_destroy(GalagoObject *object)
+{
+	g_return_if_fail(object != NULL);
+	g_return_if_fail(GALAGO_IS_OBJECT(object));
+
+	if (!GALAGO_OBJECT_HAS_FLAG(object, GALAGO_OBJECT_IN_DESTRUCTION))
+		g_object_run_dispose(G_OBJECT(object));
+
+}
+
 const gchar *
 galago_object_type_get_dbus_signature(GType type)
 {

Modified: trunk/libgalago/libgalago/galago-object.h
===================================================================
--- trunk/libgalago/libgalago/galago-object.h	2006-04-03 07:56:38 UTC (rev 2662)
+++ trunk/libgalago/libgalago/galago-object.h	2006-04-03 08:20:17 UTC (rev 2663)
@@ -177,6 +177,15 @@
 GType galago_object_get_type(void);
 
 /**
+ * Destroys an object.
+ *
+ * This will discard all references and emit the "destroy" signal.
+ *
+ * @param object The object to destroy.
+ */
+void galago_object_destroy(GalagoObject *object);
+
+/**
  * Returns the D-BUS signature of the object type.
  *
  * @param type The object GType.

Modified: trunk/libgalago/libgalago/galago-person.c
===================================================================
--- trunk/libgalago/libgalago/galago-person.c	2006-04-03 07:56:38 UTC (rev 2662)
+++ trunk/libgalago/libgalago/galago-person.c	2006-04-03 08:20:17 UTC (rev 2663)
@@ -210,7 +210,7 @@
 		if (person->priv->accounts != NULL)
 		{
 			g_list_foreach(person->priv->accounts,
-						   (GFunc)g_object_unref, NULL);
+						   (GFunc)galago_object_destroy, NULL);
 			g_list_free(person->priv->accounts);
 		}
 
@@ -523,11 +523,8 @@
 	if (person->priv->photo != NULL)
 	{
 		GalagoImage *old_photo = person->priv->photo;
-
 		person->priv->photo = NULL;
-
-		if (!GALAGO_OBJECT_HAS_FLAG(old_photo, GALAGO_OBJECT_IN_DESTRUCTION))
-			g_object_unref(old_photo);
+		galago_object_destroy(GALAGO_OBJECT(old_photo));
 	}
 
 	person->priv->photo = photo;

Modified: trunk/libgalago/libgalago/galago-presence.c
===================================================================
--- trunk/libgalago/libgalago/galago-presence.c	2006-04-03 07:56:38 UTC (rev 2662)
+++ trunk/libgalago/libgalago/galago-presence.c	2006-04-03 08:20:17 UTC (rev 2663)
@@ -190,7 +190,7 @@
 		if (presence->priv->statuses != NULL)
 		{
 			g_list_foreach(presence->priv->statuses,
-						   (GFunc)g_object_unref, NULL);
+						   (GFunc)galago_object_destroy, NULL);
 			g_list_free(presence->priv->statuses);
 		}
 
@@ -403,7 +403,7 @@
 
 			g_signal_emit(presence, signals[STATUS_REMOVED], 0, status);
 
-			g_object_unref(status);
+			galago_object_destroy(GALAGO_OBJECT(status));
 		}
 
 		g_list_free(presence->priv->statuses);
@@ -456,7 +456,7 @@
 				  "to the presence for account %s",
 				  status_id, galago_account_get_username(account));
 
-		g_object_unref(status);
+		galago_object_destroy(GALAGO_OBJECT(status));
 
 		return;
 	}
@@ -524,7 +524,7 @@
 	g_signal_emit(presence, signals[STATUS_REMOVED], 0, status);
 	g_signal_emit(presence, signals[CHANGED], 0);
 
-	g_object_unref(status);
+	galago_object_destroy(GALAGO_OBJECT(status));
 }
 
 void

Modified: trunk/libgalago/libgalago/galago-service.c
===================================================================
--- trunk/libgalago/libgalago/galago-service.c	2006-04-03 07:56:38 UTC (rev 2662)
+++ trunk/libgalago/libgalago/galago-service.c	2006-04-03 08:20:17 UTC (rev 2663)
@@ -159,7 +159,7 @@
 		if (service->priv->accounts != NULL)
 		{
 			g_list_foreach(service->priv->accounts,
-						   (GFunc)g_object_unref, NULL);
+						   (GFunc)galago_object_destroy, NULL);
 			g_list_free(service->priv->accounts);
 		}
 
@@ -227,7 +227,6 @@
 galago_service_dbus_push_full(GalagoObject *object)
 {
 	GalagoService *service = GALAGO_SERVICE(object);
-	GalagoAccount *account;
 	GList *l;
 
 	for (l = galago_service_get_accounts(service, FALSE);

Modified: trunk/libgalago/tests/Makefile.am
===================================================================
--- trunk/libgalago/tests/Makefile.am	2006-04-03 07:56:38 UTC (rev 2662)
+++ trunk/libgalago/tests/Makefile.am	2006-04-03 08:20:17 UTC (rev 2663)
@@ -16,6 +16,7 @@
 	presence-feed \
 	presence-feed-2 \
 	person-attr-test \
+	test-bug-36 \
 	$(unittests)
 
 common_ldflags = \
@@ -58,6 +59,9 @@
 check_libgalago_SOURCES = check-libgalago.c
 check_libgalago_LDADD   = $(common_ldflags) $(CHECK_LIBS)
 
+test_bug_36_SOURCES = test-bug-36.c
+test_bug_36_LDADD   = $(common_ldflags)
+
 CLEANFILES = check-libgalago.log
 
 INCLUDES = \

Added: trunk/libgalago/tests/test-bug-36.c
===================================================================
--- trunk/libgalago/tests/test-bug-36.c	2006-04-03 07:56:38 UTC (rev 2662)
+++ trunk/libgalago/tests/test-bug-36.c	2006-04-03 08:20:17 UTC (rev 2663)
@@ -0,0 +1,52 @@
+/**
+ * @file presence-feed.c Sample presence feed.
+ *
+ * @Copyright (C) 2004-2005 Christian Hammond
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the Free
+ * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA  02111-1307  USA
+ */
+#include <glib.h>
+#include <libgalago/galago.h>
+#include <sys/stat.h>
+#include <stdio.h>
+#include <string.h>
+
+int
+main(int argc, char **argv)
+{
+	if (!galago_init("test-death", TRUE))
+	{
+		fprintf(stderr, "Unable to initialize Galago and connect "
+				"to the server\n");
+		exit(1);
+	}
+
+	galago_create_service("test-death-1", "Test Death Service 1", 0);
+	galago_create_service("test-death-2", "Test Death Service 2", 0);
+
+	galago_uninit();
+
+	if (!galago_init("test-death", TRUE))
+	{
+		fprintf(stderr, "Unable to initialize Galago and connect "
+				"to the server\n");
+		exit(1);
+	}
+
+	galago_uninit();
+
+	return 0;
+}



More information about the galago-commits mailing list