* all:
authorDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Thu, 15 Feb 2007 10:06:06 +0000 (10:06 +0000)
committerDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Thu, 15 Feb 2007 10:06:06 +0000 (10:06 +0000)
- added modest_runtime_verify_object_death macro,
which checks that all refs are cleared up if the
MODEST_DEBUG contains "debug-objects"

pmo-trunk-r833

src/modest-defs.h
src/modest-runtime.h
src/modest-singletons.c
src/modest-tny-account-store.c
src/widgets/modest-header-view.c

index 8754c4a..a0ffd7a 100644 (file)
@@ -90,5 +90,4 @@
 #define MODEST_ACCOUNT_PREFERRED_CNX     "preferred_cnx"     /* string */
 #define MODEST_ACCOUNT_OPTIONS          "options"           /* list */
 
-
 #endif /*__MODEST_DEFS_H__*/
index e4f91e8..2509e4c 100644 (file)
@@ -194,6 +194,26 @@ ModestMailOperationQueue* modest_runtime_get_mail_operation_queue (void);
 ModestTnySendQueue* modest_runtime_get_send_queue        (TnyTransportAccount *account);
 
 
+
+/**
+ * modest_runtime_verify_object_death
+ * @obj: some (GObject) ptr
+ *
+ * macro to check whether @obj is 'dead', ie, it is no longer a valid GObject. If
+ * not, a g_warning will be issued on stderr. NOTE: this is only active
+ * when MODEST_DEBUG contains "debug-objects".
+ *
+ ***/
+#define modest_runtime_verify_object_death(OBJ,name)                   \
+       do {                                                            \
+               if (modest_runtime_get_debug_flags() & MODEST_RUNTIME_DEBUG_DEBUG_OBJECTS) \
+                       if (G_IS_OBJECT(OBJ))                           \
+                               g_warning ("%s:%d: %s ("        \
+                                          #OBJ ") still holds a ref count of %d", \
+                                          __FILE__,__LINE__,name, G_OBJECT(OBJ)->ref_count); \
+       } while (0)
+
+
 G_END_DECLS
 
 #endif /*__MODEST_RUNTIME_H__*/
index 61d0b08..396a4b3 100644 (file)
@@ -144,67 +144,46 @@ modest_singletons_init (ModestSingletons *obj)
        }       
 }
 
-
-static void
-check_object_is_dead (GObject *obj, gchar *name)
-{
-       if (G_IS_OBJECT(obj))
-               g_warning ("BUG: %s still has %d ref(s)\n", name, obj->ref_count);
-}
-
 static void
 modest_singletons_finalize (GObject *obj)
 {
        ModestSingletonsPrivate *priv;
-       gboolean debug = modest_runtime_get_debug_flags() & MODEST_RUNTIME_DEBUG_DEBUG_OBJECTS;
                
        priv = MODEST_SINGLETONS_GET_PRIVATE(obj);
 
        if (priv->account_store) {
                g_object_unref (G_OBJECT(priv->account_store));
-               if (debug)
-                       check_object_is_dead ((GObject*)priv->account_store,
-                                             "priv->account_store");
+               modest_runtime_verify_object_death(priv->account_store,"");
                priv->account_store = NULL;
        }
 
        if (priv->account_mgr) {
                g_object_unref (G_OBJECT(priv->account_mgr));
-               if (debug)
-                       check_object_is_dead ((GObject*)priv->account_mgr,
-                                             "priv->account_mgr");
+               modest_runtime_verify_object_death(priv->account_mgr,"");
                priv->account_mgr = NULL;
        }
 
        if (priv->conf) {
                g_object_unref (G_OBJECT(priv->conf));
-               if (debug)
-                       check_object_is_dead ((GObject*)priv->conf,
-                                             "priv->conf");
+               modest_runtime_verify_object_death(priv->conf,"");
                priv->conf = NULL;
        }
 
        if (priv->cache_mgr) {
                g_object_unref (G_OBJECT(priv->cache_mgr));
-               if (debug)
-                       check_object_is_dead ((GObject*)priv->cache_mgr,
-                                             "priv->cache_mgr");
+               modest_runtime_verify_object_death(priv->cache_mgr,"");
                priv->cache_mgr = NULL;
        }
 
        if (priv->device) {
                g_object_unref (G_OBJECT(priv->device));
-               if (debug)
-                       check_object_is_dead ((GObject*)priv->cache_mgr,
-                                             "priv->device");
+               modest_runtime_verify_object_death(priv->device,"");
                priv->device = NULL;
        }
 
        if (priv->platform_fact) {
                g_object_unref (G_OBJECT(priv->platform_fact));
-               if (debug)
-                       check_object_is_dead ((GObject*)priv->cache_mgr,
-                                             "priv->platform_fact");
+               modest_runtime_verify_object_death(priv->platform_fact,"");
                priv->platform_fact = NULL;
        }
 
index 9868a51..bfe6814 100644 (file)
@@ -177,14 +177,13 @@ static void
 account_list_free (GSList *accounts)
 {
        GSList *cursor = accounts;
-       gboolean debug = modest_runtime_get_debug_flags() & MODEST_RUNTIME_DEBUG_DEBUG_OBJECTS;
 
        while (cursor) {
                g_object_unref (G_OBJECT(cursor->data));
-               if (debug && G_IS_OBJECT(cursor->data))
-                       g_warning ("BUG: account %s still holds %d ref(s)",
-                                  tny_account_get_id (TNY_ACCOUNT(cursor->data)),
-                                  G_OBJECT(cursor->data)->ref_count);
+               if (G_IS_OBJECT(cursor->data)) { /* check twice... */
+                       const gchar *id = tny_account_get_id(TNY_ACCOUNT(cursor->data));
+                       modest_runtime_verify_object_death(cursor->data,id);
+               }                       
                cursor = cursor->next;
        }
        g_slist_free (accounts);
@@ -369,8 +368,8 @@ modest_tny_account_store_finalize (GObject *obj)
        if (priv->session) {
                camel_object_unref (CAMEL_OBJECT(priv->session));
                if (debug && CAMEL_IS_OBJECT(priv->session))
-                               g_warning ("BUG: TnyCamelSession still holds %d ref(s)",
-                                  CAMEL_OBJECT(priv->session)->ref_count);     
+                       g_warning ("%s:%d: TnyCamelSession still holds a refcount of %d",
+                                  __FILE__,__LINE__,CAMEL_OBJECT(priv->session)->ref_count);   
                priv->session = NULL;
        }
        
index de54a58..54de306 100644 (file)
@@ -38,6 +38,7 @@
 #include <modest-marshal.h>
 #include <modest-text-utils.h>
 #include <modest-icon-names.h>
+#include <modest-runtime.h>
 
 static void modest_header_view_class_init  (ModestHeaderViewClass *klass);
 static void modest_header_view_init        (ModestHeaderView *obj);
@@ -620,9 +621,10 @@ on_refresh_folder (TnyFolder *folder, gboolean cancelled, GError **err,
        if (folder) { /* it's a new one or a refresh */
                GList *cols, *cursor;
                
-               if (priv->headers)
+               if (priv->headers) {
                        g_object_unref (priv->headers);
-
+                       modest_runtime_verify_object_death(priv->headers,"");
+               }
                priv->headers = TNY_LIST(tny_gtk_header_list_model_new ());
                tny_folder_get_headers (folder, priv->headers, FALSE, &error); /* FIXME */
                if (error) {