From bc1dd5cf11dc920ff44d51051e1e695b0b8ea421 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Sun, 6 Sep 2009 13:54:50 -0400 Subject: [PATCH] Call element_free_func when shrinking array with g_ptr_array_set_size --- glib/garray.c | 8 ++------ glib/tests/array-test.c | 4 +++- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/glib/garray.c b/glib/garray.c index 8cb6e1d84..b43900013 100644 --- a/glib/garray.c +++ b/glib/garray.c @@ -618,12 +618,8 @@ g_ptr_array_set_size (GPtrArray *farray, for (i = array->len; i < length; i++) array->pdata[i] = NULL; } - if (G_UNLIKELY (g_mem_gc_friendly) && length < array->len) - { - int i; - for (i = length; i < array->len; i++) - array->pdata[i] = NULL; - } + else if (length < array->len) + g_ptr_array_remove_range (farray, length, array->len - length); array->len = length; } diff --git a/glib/tests/array-test.c b/glib/tests/array-test.c index 3572ba39a..86308e029 100644 --- a/glib/tests/array-test.c +++ b/glib/tests/array-test.c @@ -186,9 +186,11 @@ pointer_array_free_func (void) g_ptr_array_add (gparray, s); g_assert (g_ptr_array_remove (gparray, s)); g_assert_cmpint (num_free_func_invocations, ==, 2); + g_ptr_array_set_size (gparray, 1); + g_assert_cmpint (num_free_func_invocations, ==, 3); g_ptr_array_ref (gparray); g_ptr_array_unref (gparray); - g_assert_cmpint (num_free_func_invocations, ==, 2); + g_assert_cmpint (num_free_func_invocations, ==, 3); g_ptr_array_unref (gparray); g_assert_cmpint (num_free_func_invocations, ==, 4);