[glib/th/g-ptr-array-set-null-terminated: 32/32] fixup! array: add support for %NULL termination in GPtrArray




commit a5089952aac4c3df47fa16154a6986ab75294c2e
Author: Thomas Haller <thaller redhat com>
Date:   Mon Jan 25 16:39:42 2021 +0100

    fixup! array: add support for %NULL termination in GPtrArray

 glib/garray.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
---
diff --git a/glib/garray.c b/glib/garray.c
index 8e2cd56a6..8cd9e2cac 100644
--- a/glib/garray.c
+++ b/glib/garray.c
@@ -1511,8 +1511,8 @@ g_ptr_array_unref (GPtrArray *array)
  * function has been set for @array.
  *
  * Note that if the array is %NULL terminated and @free_seg is %FALSE
- * and the pdata is %NULL (and the length is zero), the this function
- * will return %NULL too and not allocate an empty %NULL terminated buffer.
+ * then this will always return an allocated %NULL termianted buffer.
+ * If pdata is previously %NULL, a new buffer will be allocated.
  *
  * This function is not thread-safe. If using a #GPtrArray from multiple
  * threads, use only the atomic g_ptr_array_ref() and g_ptr_array_unref()
@@ -1569,7 +1569,11 @@ ptr_array_free (GPtrArray      *array,
       segment = NULL;
     }
   else
-    segment = rarray->pdata;
+    {
+      segment = rarray->pdata;
+      if (!segment && rarray->null_terminated)
+        segment = (gpointer *) g_new0 (char *, 1);
+    }
 
   if (flags & PRESERVE_WRAPPER)
     {


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