From 78f8543718af6cda30fadbe3f4aa409338a0274f Mon Sep 17 00:00:00 2001
From: Simon McVittie <smcv@collabora.com>
Date: Tue, 27 Jul 2021 17:34:42 +0100
Subject: [PATCH] pv-adverb: Factor out ptr_array_add_unique

Signed-off-by: Simon McVittie <smcv@collabora.com>
---
 pressure-vessel/adverb.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/pressure-vessel/adverb.c b/pressure-vessel/adverb.c
index 7a54755c4..147b30ff1 100644
--- a/pressure-vessel/adverb.c
+++ b/pressure-vessel/adverb.c
@@ -86,6 +86,22 @@ static PreloadModule opt_preload_modules[] =
   { "LD_PRELOAD", NULL },
 };
 
+static gpointer
+generic_strdup (gpointer p)
+{
+  return g_strdup (p);
+}
+
+static void
+ptr_array_add_unique (GPtrArray *arr,
+                      const void *item,
+                      GEqualFunc equal_func,
+                      GBoxedCopyFunc copy_func)
+{
+  if (!g_ptr_array_find_with_equal_func (arr, item, equal_func, NULL))
+    g_ptr_array_add (arr, copy_func ((gpointer) item));
+}
+
 static void
 lib_temp_dirs_free (LibTempDirs *lib_temp_dirs)
 {
@@ -1026,10 +1042,8 @@ main (int argc,
                   goto out;
                 }
               g_debug ("created symlink %s -> %s", link, preload);
-
-              if (!g_ptr_array_find_with_equal_func (search_path, platform_overlay_path,
-                                                     g_str_equal, NULL))
-                g_ptr_array_add (search_path, g_strdup (platform_overlay_path));
+              ptr_array_add_unique (search_path, platform_overlay_path,
+                                    g_str_equal, generic_strdup);
             }
           else
             {
-- 
GitLab