[glib] Call element_free_func when shrinking array with g_ptr_array_set_size



commit bc1dd5cf11dc920ff44d51051e1e695b0b8ea421
Author: Dan Winship <danw gnome org>
Date:   Sun Sep 6 13:54:50 2009 -0400

    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 8cb6e1d..b439000 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 3572ba3..86308e0 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);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]