[glib/th/g-ptr-array-set-null-terminated] fixup! array: add support for g_ptr_array_null_terminated()
- From: Thomas Haller <thaller src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/th/g-ptr-array-set-null-terminated] fixup! array: add support for g_ptr_array_null_terminated()
- Date: Fri, 15 May 2020 15:55:03 +0000 (UTC)
commit c7252b356c65e635972a002eb2dfaa526bfae4a3
Author: Thomas Haller <thaller redhat com>
Date: Fri May 15 16:58:18 2020 +0200
fixup! array: add support for g_ptr_array_null_terminated()
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1485#note_800510
> I think we should guarantee that g_ptr_array_free() always returns a
> non-NULL array if it’s supposed to be NULL-terminated, but we shouldn’t
> worry about the pdata if the GPtrArray is still reffed. That can be
> cleared to NULL, as is already the case after constructing a new array.
th: I disagree. The documentation already makes it clear that an empty array
may either be represented as NULL or [ NULL ]. It doesn't seem useful
to artificially allocate an empty array during g_ptr_array_free(). If
the user cares, she can just do
return g_ptr_array_free (parray, FALSE) ?: g_new0 (char *, 1);
Anyway, here is a fixup implementing that.
glib/garray.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
---
diff --git a/glib/garray.c b/glib/garray.c
index 9cc53f17d..4f90407d1 100644
--- a/glib/garray.c
+++ b/glib/garray.c
@@ -1549,7 +1549,12 @@ ptr_array_free (GPtrArray *array,
segment = NULL;
}
else
- segment = rarray->pdata;
+ {
+ segment = rarray->pdata;
+ if ( !segment
+ && rarray->null_terminated)
+ segment = g_new0 (gpointer, 1);
+ }
if (flags & PRESERVE_WRAPPER)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]