[nautilus] Add custom foreach to eel_g_hash_table_new_free_at_exit
- From: Alexander Larsson <alexl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus] Add custom foreach to eel_g_hash_table_new_free_at_exit
- Date: Fri, 25 Mar 2011 15:43:29 +0000 (UTC)
commit 1d48f02ea1bf274d8fb0d70b61bed337bbda06c2
Author: Alexander Larsson <alexl redhat com>
Date: Fri Mar 25 14:35:43 2011 +0100
Add custom foreach to eel_g_hash_table_new_free_at_exit
This can be used to get some sort of printout for leaks in non-string
hashtables.
eel/eel-glib-extensions.c | 16 ++++++++++------
eel/eel-glib-extensions.h | 1 +
eel/eel-stock-dialogs.c | 2 +-
eel/eel-string.c | 2 +-
libnautilus-private/nautilus-directory-async.c | 4 ++--
libnautilus-private/nautilus-directory.c | 3 ++-
libnautilus-private/nautilus-file.c | 2 +-
src/nautilus-properties-window.c | 4 ++--
8 files changed, 20 insertions(+), 14 deletions(-)
---
diff --git a/eel/eel-glib-extensions.c b/eel/eel-glib-extensions.c
index beb9d71..3190dc1 100644
--- a/eel/eel-glib-extensions.c
+++ b/eel/eel-glib-extensions.c
@@ -48,7 +48,7 @@
typedef struct {
GHashTable *hash_table;
char *display_name;
- gboolean keys_known_to_be_strings;
+ GHFunc foreach_func;
} HashTableToFree;
static GList *hash_tables_to_free_at_exit;
@@ -533,16 +533,16 @@ free_hash_tables_at_exit (void)
size = g_hash_table_size (hash_table_to_free->hash_table);
if (size != 0) {
- if (hash_table_to_free->keys_known_to_be_strings) {
+ if (hash_table_to_free->foreach_func) {
g_print ("\n--- Hash table keys for warning below:\n");
g_hash_table_foreach (hash_table_to_free->hash_table,
- print_key_string,
+ hash_table_to_free->foreach_func,
NULL);
}
g_warning ("\"%s\" hash table still has %u element%s at quit time%s",
hash_table_to_free->display_name, size,
size == 1 ? "" : "s",
- hash_table_to_free->keys_known_to_be_strings
+ hash_table_to_free->foreach_func
? " (keys above)" : "");
}
@@ -557,6 +557,7 @@ free_hash_tables_at_exit (void)
GHashTable *
eel_g_hash_table_new_free_at_exit (GHashFunc hash_func,
GCompareFunc key_compare_func,
+ GHFunc foreach_func,
const char *display_name)
{
GHashTable *hash_table;
@@ -575,8 +576,11 @@ eel_g_hash_table_new_free_at_exit (GHashFunc hash_func,
hash_table_to_free = g_new (HashTableToFree, 1);
hash_table_to_free->hash_table = hash_table;
hash_table_to_free->display_name = g_strdup (display_name);
- hash_table_to_free->keys_known_to_be_strings =
- hash_func == g_str_hash;
+ hash_table_to_free->foreach_func = foreach_func;
+ if (hash_table_to_free->foreach_func == NULL &&
+ hash_func == g_str_hash) {
+ hash_table_to_free->foreach_func = print_key_string;
+ }
hash_tables_to_free_at_exit = g_list_prepend
(hash_tables_to_free_at_exit, hash_table_to_free);
diff --git a/eel/eel-glib-extensions.h b/eel/eel-glib-extensions.h
index 68b5204..6812f8d 100644
--- a/eel/eel-glib-extensions.h
+++ b/eel/eel-glib-extensions.h
@@ -69,6 +69,7 @@ GList * eel_g_object_list_copy (GList *
/* GHashTable functions */
GHashTable *eel_g_hash_table_new_free_at_exit (GHashFunc hash_function,
GCompareFunc key_compare_function,
+ GHFunc foreach_func,
const char *display_name);
void eel_g_hash_table_safe_for_each (GHashTable *hash_table,
GHFunc callback,
diff --git a/eel/eel-stock-dialogs.c b/eel/eel-stock-dialogs.c
index e7ae48a..fe29ef8 100644
--- a/eel/eel-stock-dialogs.c
+++ b/eel/eel-stock-dialogs.c
@@ -272,7 +272,7 @@ eel_timed_wait_start_with_duration (int duration,
/* Put in the hash table so we can find it later. */
if (timed_wait_hash_table == NULL) {
timed_wait_hash_table = eel_g_hash_table_new_free_at_exit
- (timed_wait_hash, timed_wait_hash_equal, __FILE__ ": timed wait");
+ (timed_wait_hash, timed_wait_hash_equal, NULL, __FILE__ ": timed wait");
}
g_assert (g_hash_table_lookup (timed_wait_hash_table, wait) == NULL);
g_hash_table_insert (timed_wait_hash_table, wait, wait);
diff --git a/eel/eel-string.c b/eel/eel-string.c
index c23eb93..d45c621 100644
--- a/eel/eel-string.c
+++ b/eel/eel-string.c
@@ -855,7 +855,7 @@ eel_ref_str_get_unique (const char *string)
if (unique_ref_strs == NULL) {
unique_ref_strs =
eel_g_hash_table_new_free_at_exit (g_str_hash, g_str_equal,
- "unique eel_ref_str");
+ NULL, "unique eel_ref_str");
}
res = g_hash_table_lookup (unique_ref_strs, string);
diff --git a/libnautilus-private/nautilus-directory-async.c b/libnautilus-private/nautilus-directory-async.c
index 43a51b2..214ef4f 100644
--- a/libnautilus-private/nautilus-directory-async.c
+++ b/libnautilus-private/nautilus-directory-async.c
@@ -365,7 +365,7 @@ async_job_start (NautilusDirectory *directory,
if (async_job_count >= MAX_ASYNC_JOBS) {
if (waiting_directories == NULL) {
waiting_directories = eel_g_hash_table_new_free_at_exit
- (NULL, NULL,
+ (NULL, NULL, NULL,
"nautilus-directory-async.c: waiting_directories");
}
@@ -381,7 +381,7 @@ async_job_start (NautilusDirectory *directory,
char *uri;
if (async_jobs == NULL) {
async_jobs = eel_g_hash_table_new_free_at_exit
- (g_str_hash, g_str_equal,
+ (g_str_hash, g_str_equal, NULL,
"nautilus-directory-async.c: async_jobs");
}
uri = nautilus_directory_get_uri (directory);
diff --git a/libnautilus-private/nautilus-directory.c b/libnautilus-private/nautilus-directory.c
index 34f92bf..9142a8c 100644
--- a/libnautilus-private/nautilus-directory.c
+++ b/libnautilus-private/nautilus-directory.c
@@ -348,7 +348,8 @@ nautilus_directory_get_internal (GFile *location, gboolean create)
/* Create the hash table first time through. */
if (directories == NULL) {
directories = eel_g_hash_table_new_free_at_exit
- (g_file_hash, (GCompareFunc)g_file_equal, "nautilus-directory.c: directories");
+ (g_file_hash, (GCompareFunc)g_file_equal, NULL,
+ "nautilus-directory.c: directories");
add_preferences_callbacks ();
}
diff --git a/libnautilus-private/nautilus-file.c b/libnautilus-private/nautilus-file.c
index a7a0e76..5ebc29e 100644
--- a/libnautilus-private/nautilus-file.c
+++ b/libnautilus-private/nautilus-file.c
@@ -550,7 +550,7 @@ modify_link_hash_table (NautilusFile *file,
/* Create the hash table first time through. */
if (symbolic_links == NULL) {
symbolic_links = eel_g_hash_table_new_free_at_exit
- (g_str_hash, g_str_equal, "nautilus-file.c: symbolic_links");
+ (g_str_hash, g_str_equal, NULL, "nautilus-file.c: symbolic_links");
}
target_uri = nautilus_file_get_symbolic_link_target_uri (file);
diff --git a/src/nautilus-properties-window.c b/src/nautilus-properties-window.c
index 4c23d7e..de3acd0 100644
--- a/src/nautilus-properties-window.c
+++ b/src/nautilus-properties-window.c
@@ -5087,12 +5087,12 @@ nautilus_properties_window_present (GList *original_files,
/* Create the hash tables first time through. */
if (windows == NULL) {
windows = eel_g_hash_table_new_free_at_exit
- (NULL, NULL, "property windows");
+ (NULL, NULL, NULL, "property windows");
}
if (pending_lists == NULL) {
pending_lists = eel_g_hash_table_new_free_at_exit
- (g_str_hash, g_str_equal, "pending property window files");
+ (g_str_hash, g_str_equal, NULL, "pending property window files");
}
/* Look to see if there's already a window for this file. */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]