Call element_free_func when shrinking array with g_ptr_array_set_size

This commit is contained in:
Dan Winship 2009-09-06 13:54:50 -04:00
parent 9a29f087e7
commit bc1dd5cf11
2 changed files with 5 additions and 7 deletions

View File

@ -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;
}

View File

@ -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);