diff options
author | Carlos Soriano <csoriano@gnome.org> | 2015-12-08 14:28:35 +0100 |
---|---|---|
committer | Carlos Soriano <csoriano@gnome.org> | 2015-12-11 22:42:04 +0100 |
commit | 864c815479a25a2b99ca354ff20edf5804d46070 (patch) | |
tree | 6834bbc1cd2ec026919f563fe2ea1461bd77d7de /eel | |
parent | 81c58a9c7ae2688ed7fff7f3400a698bbc4d1a00 (diff) | |
download | nautilus-864c815479a25a2b99ca354ff20edf5804d46070.tar.gz |
file: refactor eel-partition for better ownership management
Instead of a generic function to filter GLists, implement a simpler
and clearer filter function for file lists, since it was the only
use of that function.
In this way the ownership of files and directories are clearer
since it always returns a new allocated nautilus file list, and also
it always uses nautilus_file_ref instead of the generic g_object_ref
to match what we do everywhere else in nautilus, so it's not confusing
when breaking at nautilus_file_ref/unref for ref counting debugging.
This change fixes multiple leaks on nautilus files catched by valgrind.
Diffstat (limited to 'eel')
-rw-r--r-- | eel/eel-glib-extensions.c | 124 | ||||
-rw-r--r-- | eel/eel-glib-extensions.h | 5 | ||||
-rw-r--r-- | eel/eel-lib-self-check-functions.h | 1 |
3 files changed, 0 insertions, 130 deletions
diff --git a/eel/eel-glib-extensions.c b/eel/eel-glib-extensions.c index 1f1dc5f49..709c37a79 100644 --- a/eel/eel-glib-extensions.c +++ b/eel/eel-glib-extensions.c @@ -92,67 +92,6 @@ eel_g_lists_sort_and_check_for_intersection (GList **list_1, return FALSE; } - -/** - * eel_g_list_partition - * - * Parition a list into two parts depending on whether the data - * elements satisfy a provided predicate. Order is preserved in both - * of the resulting lists, and the original list is consumed. A list - * of the items that satisfy the predicate is returned, and the list - * of items not satisfying the predicate is returned via the failed - * out argument. - * - * @list: List to partition. - * @predicate: Function to call on each element. - * @user_data: Data to pass to function. - * @failed: The GList * variable pointed to by this argument will be - * set to the list of elements for which the predicate returned - * false. */ - -GList * -eel_g_list_partition (GList *list, - EelPredicateFunction predicate, - gpointer user_data, - GList **failed) -{ - GList *predicate_true; - GList *predicate_false; - GList *reverse; - GList *p; - GList *next; - - predicate_true = NULL; - predicate_false = NULL; - - reverse = g_list_reverse (list); - - for (p = reverse; p != NULL; p = next) { - next = p->next; - - if (next != NULL) { - next->prev = NULL; - } - - if (predicate (p->data, user_data)) { - p->next = predicate_true; - if (predicate_true != NULL) { - predicate_true->prev = p; - } - predicate_true = p; - } else { - p->next = predicate_false; - if (predicate_false != NULL) { - predicate_false->prev = p; - } - predicate_false = p; - } - } - - *failed = predicate_false; - return predicate_true; -} - typedef struct { GList *keys; GList *values; @@ -197,67 +136,4 @@ eel_g_hash_table_safe_for_each (GHashTable *hash_table, #if !defined (EEL_OMIT_SELF_CHECK) -static gboolean -eel_test_str_list_equal (GList *list_a, GList *list_b) -{ - GList *p, *q; - - for (p = list_a, q = list_b; p != NULL && q != NULL; p = p->next, q = q->next) { - if (g_strcmp0 (p->data, q->data) != 0) { - return FALSE; - } - } - return p == NULL && q == NULL; -} - -static gboolean -eel_test_predicate (gpointer data, - gpointer callback_data) -{ - return g_ascii_strcasecmp (data, callback_data) <= 0; -} - -void -eel_self_check_glib_extensions (void) -{ - GList *list_to_partition; - GList *expected_passed; - GList *expected_failed; - GList *actual_passed; - GList *actual_failed; - - /* eel_g_list_partition */ - - list_to_partition = NULL; - list_to_partition = g_list_append (list_to_partition, "Cadillac"); - list_to_partition = g_list_append (list_to_partition, "Pontiac"); - list_to_partition = g_list_append (list_to_partition, "Ford"); - list_to_partition = g_list_append (list_to_partition, "Range Rover"); - - expected_passed = NULL; - expected_passed = g_list_append (expected_passed, "Cadillac"); - expected_passed = g_list_append (expected_passed, "Ford"); - - expected_failed = NULL; - expected_failed = g_list_append (expected_failed, "Pontiac"); - expected_failed = g_list_append (expected_failed, "Range Rover"); - - actual_passed = eel_g_list_partition (list_to_partition, - eel_test_predicate, - "m", - &actual_failed); - - EEL_CHECK_BOOLEAN_RESULT (eel_test_str_list_equal (expected_passed, actual_passed), TRUE); - EEL_CHECK_BOOLEAN_RESULT (eel_test_str_list_equal (expected_failed, actual_failed), TRUE); - - /* Don't free "list_to_partition", since it is consumed - * by eel_g_list_partition. - */ - - g_list_free (expected_passed); - g_list_free (actual_passed); - g_list_free (expected_failed); - g_list_free (actual_failed); -} - #endif /* !EEL_OMIT_SELF_CHECK */ diff --git a/eel/eel-glib-extensions.h b/eel/eel-glib-extensions.h index 2ccb86200..f23302433 100644 --- a/eel/eel-glib-extensions.h +++ b/eel/eel-glib-extensions.h @@ -39,11 +39,6 @@ typedef gboolean (* EelPredicateFunction) (gpointer data, /* GList functions. */ gboolean eel_g_lists_sort_and_check_for_intersection (GList **list_a, GList **list_b); -GList * eel_g_list_partition (GList *list, - EelPredicateFunction predicate, - gpointer user_data, - GList **removed); - /* GHashTable functions */ void eel_g_hash_table_safe_for_each (GHashTable *hash_table, GHFunc callback, diff --git a/eel/eel-lib-self-check-functions.h b/eel/eel-lib-self-check-functions.h index ed9de8f4f..11386e8e6 100644 --- a/eel/eel-lib-self-check-functions.h +++ b/eel/eel-lib-self-check-functions.h @@ -37,7 +37,6 @@ void eel_run_lib_self_checks (void); */ #define EEL_LIB_FOR_EACH_SELF_CHECK_FUNCTION(macro) \ - macro (eel_self_check_glib_extensions) \ macro (eel_self_check_string) \ /* Add new self-check functions to the list above this line. */ |