[gimp/soc-2010-cage] app: move the instance debug facility to the new file app/gimp-debug.c
- From: Michael Muré <mmure src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/soc-2010-cage] app: move the instance debug facility to the new file app/gimp-debug.c
- Date: Wed, 30 Jun 2010 22:15:56 +0000 (UTC)
commit 9e76f9e35466d962cbc1eddc8b1e2d5003664e7c
Author: Michael Natterer <mitch gimp org>
Date: Thu Jun 24 19:11:56 2010 +0200
app: move the instance debug facility to the new file app/gimp-debug.c
Build it unconditionally but enable it via GIMP_DEBUG=instances
app/Makefile.am | 2 +
app/app.c | 5 +--
app/core/gimpobject.c | 81 ++----------------------------------------------
app/core/gimpobject.h | 6 ----
app/gimp-log.c | 7 ++++-
app/gimp-log.h | 4 ++-
6 files changed, 17 insertions(+), 88 deletions(-)
---
diff --git a/app/Makefile.am b/app/Makefile.am
index 75bc67f..c387d58 100644
--- a/app/Makefile.am
+++ b/app/Makefile.am
@@ -66,6 +66,8 @@ libapp_sources = \
units.h \
version.c \
version.h \
+ gimp-debug.c \
+ gimp-debug.h \
gimp-log.c \
gimp-log.h \
gimp-intl.h
diff --git a/app/app.c b/app/app.c
index 3c4334e..5db4879 100644
--- a/app/app.c
+++ b/app/app.c
@@ -59,6 +59,7 @@
#include "batch.h"
#include "errors.h"
#include "units.h"
+#include "gimp-debug.h"
#include "gimp-intl.h"
@@ -255,9 +256,7 @@ app_run (const gchar *full_prog_name,
g_object_unref (gimp);
-#ifdef DEBUG_INSTANCES
- gimp_object_debug_instances ();
-#endif
+ gimp_debug_instances ();
errors_exit ();
gegl_exit ();
diff --git a/app/core/gimpobject.c b/app/core/gimpobject.c
index 9bff063..253bf93 100644
--- a/app/core/gimpobject.c
+++ b/app/core/gimpobject.c
@@ -29,6 +29,8 @@
#include "gimpmarshal.h"
#include "gimpobject.h"
+#include "gimp-debug.h"
+
enum
{
@@ -75,10 +77,6 @@ static GObjectClass *parent_class = NULL;
static guint object_signals[LAST_SIGNAL] = { 0 };
-#ifdef DEBUG_INSTANCES
-static GHashTable *class_hash = NULL;
-#endif
-
GType
gimp_object_get_type (void)
@@ -150,13 +148,6 @@ gimp_object_class_init (GimpObjectClass *klass)
G_PARAM_CONSTRUCT));
g_type_class_add_private (klass,
sizeof (GimpObjectPrivate));
-
-#ifdef DEBUG_INSTANCES
- class_hash = g_hash_table_new_full (g_str_hash,
- g_str_equal,
- NULL,
- (GDestroyNotify )g_hash_table_unref);
-#endif
}
static void
@@ -169,25 +160,7 @@ gimp_object_init (GimpObject *object,
object->p->name = NULL;
object->p->normalized = NULL;
-#ifdef DEBUG_INSTANCES
- {
- GHashTable *instance_hash;
- const gchar *type_name;
-
- type_name = g_type_name (G_TYPE_FROM_CLASS (klass));
-
- instance_hash = g_hash_table_lookup (class_hash, type_name);
-
- if (! instance_hash)
- {
- instance_hash = g_hash_table_new (g_direct_hash,
- g_direct_equal);
- g_hash_table_insert (class_hash, (gchar *) type_name, instance_hash);
- }
-
- g_hash_table_insert (instance_hash, object, object);
- }
-#endif /* DEBUG_INSTANCES */
+ gimp_debug_add_instance (G_OBJECT (object), G_OBJECT_CLASS (klass));
}
static void
@@ -210,24 +183,7 @@ gimp_object_finalize (GObject *object)
{
gimp_object_name_free (GIMP_OBJECT (object));
-#ifdef DEBUG_INSTANCES
- {
- GHashTable *instance_hash;
- const gchar *type_name;
-
- type_name = g_type_name (G_OBJECT_TYPE (object));
-
- instance_hash = g_hash_table_lookup (class_hash, type_name);
-
- if (instance_hash)
- {
- g_hash_table_remove (instance_hash, object);
-
- if (g_hash_table_size (instance_hash) == 0)
- g_hash_table_remove (class_hash, type_name);
- }
- }
-#endif /* DEBUG_INSTANCES */
+ gimp_debug_remove_instance (object);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
@@ -568,32 +524,3 @@ gimp_object_real_get_memsize (GimpObject *object,
return memsize + gimp_g_object_get_memsize ((GObject *) object);
}
-
-#ifdef DEBUG_INSTANCES
-static void
-gimp_object_debug_instance_foreach (GimpObject *object)
-{
- g_printerr (" \'%s\': ref_count = %d\n",
- gimp_object_get_name (object), G_OBJECT (object)->ref_count);
-}
-
-static void
-gimp_object_debug_class_foreach (const gchar *type_name,
- GHashTable *instance_hash)
-{
- g_printerr ("Leaked %s instances: %d\n",
- type_name, g_hash_table_size (instance_hash));
-
- g_hash_table_foreach (instance_hash,
- (GHFunc) gimp_object_debug_instance_foreach,
- NULL);
-}
-
-void
-gimp_object_debug_instances (void)
-{
- g_hash_table_foreach (class_hash,
- (GHFunc) gimp_object_debug_class_foreach,
- NULL);
-}
-#endif /* DEBUG_INSTANCES */
diff --git a/app/core/gimpobject.h b/app/core/gimpobject.h
index 2b0ece7..40960a6 100644
--- a/app/core/gimpobject.h
+++ b/app/core/gimpobject.h
@@ -70,11 +70,5 @@ gint gimp_object_name_collate (GimpObject *object1,
gint64 gimp_object_get_memsize (GimpObject *object,
gint64 *gui_size);
-/* #define DEBUG_INSTANCES 1 */
-
-#ifdef DEBUG_INSTANCES
-void gimp_object_debug_instances (void);
-#endif
-
#endif /* __GIMP_OBJECT_H__ */
diff --git a/app/gimp-log.c b/app/gimp-log.c
index 3b0eb7a..24c59a5 100644
--- a/app/gimp-log.c
+++ b/app/gimp-log.c
@@ -19,6 +19,7 @@
#include "glib-object.h"
+#include "gimp-debug.h"
#include "gimp-log.h"
@@ -52,7 +53,8 @@ gimp_log_init (void)
{ "shm", GIMP_LOG_SHM },
{ "text-editing", GIMP_LOG_TEXT_EDITING },
{ "key-events", GIMP_LOG_KEY_EVENTS },
- { "auto-tab-style", GIMP_LOG_AUTO_TAB_STYLE }
+ { "auto-tab-style", GIMP_LOG_AUTO_TAB_STYLE },
+ { "instances", GIMP_LOG_INSTANCES }
};
/* g_parse_debug_string() has special treatment of the string 'help',
@@ -64,6 +66,9 @@ gimp_log_init (void)
gimp_log_flags = g_parse_debug_string (env_log_val,
log_keys,
G_N_ELEMENTS (log_keys));
+
+ if (gimp_log_flags & GIMP_LOG_INSTANCES)
+ gimp_debug_enable_instances ();
}
}
diff --git a/app/gimp-log.h b/app/gimp-log.h
index 8aa7444..49c667c 100644
--- a/app/gimp-log.h
+++ b/app/gimp-log.h
@@ -36,7 +36,8 @@ typedef enum
GIMP_LOG_SHM = 1 << 12,
GIMP_LOG_TEXT_EDITING = 1 << 13,
GIMP_LOG_KEY_EVENTS = 1 << 14,
- GIMP_LOG_AUTO_TAB_STYLE = 1 << 15
+ GIMP_LOG_AUTO_TAB_STYLE = 1 << 15,
+ GIMP_LOG_INSTANCES = 1 << 16
} GimpLogFlags;
@@ -93,6 +94,7 @@ void gimp_logv (const gchar *function,
#define TEXT_EDITING GIMP_LOG_TEXT_EDITING
#define KEY_EVENTS GIMP_LOG_KEY_EVENTS
#define AUTO_TAB_STYLE GIMP_LOG_AUTO_TAB_STYLE
+#define INSTANCES GIMP_LOG_INSTANCES
#if 0 /* last resort */
# define GIMP_LOG /* nothing => no varargs, no log */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]