[gjs: 11/21] util: Remove util/glib



commit 1f96eb4bd25451bf556b1f77a942209a3f981bb3
Author: Philip Chimento <philip chimento gmail com>
Date:   Fri May 31 23:42:38 2019 -0700

    util: Remove util/glib
    
    This file only had one function in it. It's not clear why this util file
    is "glib" and the other file with one function in it is "misc". Merge
    them both into "misc".

 gjs-srcs.mk                 |  2 --
 gjs/context.cpp             |  2 +-
 gjs/importer.cpp            |  2 +-
 gjs/jsapi-dynamic-class.cpp |  1 -
 gjs/jsapi-util.cpp          |  1 -
 test/gjs-tests.cpp          | 12 +++++----
 util/glib.cpp               | 62 ---------------------------------------------
 util/glib.h                 | 32 -----------------------
 util/misc.cpp               | 28 ++++++++++++++++++++
 util/misc.h                 |  2 ++
 10 files changed, 39 insertions(+), 105 deletions(-)
---
diff --git a/gjs-srcs.mk b/gjs-srcs.mk
index 2fcdfb8f..2a985330 100644
--- a/gjs-srcs.mk
+++ b/gjs-srcs.mk
@@ -91,8 +91,6 @@ gjs_srcs =                            \
        modules/modules.cpp             \
        modules/modules.h               \
        util/error.cpp                  \
-       util/glib.cpp                   \
-       util/glib.h                     \
        util/log.cpp                    \
        util/log.h                      \
        util/misc.cpp                   \
diff --git a/gjs/context.cpp b/gjs/context.cpp
index 6e2d54af..41a745dc 100644
--- a/gjs/context.cpp
+++ b/gjs/context.cpp
@@ -50,8 +50,8 @@
 #include <modules/modules.h>
 
 #include <util/log.h>
-#include <util/glib.h>
 #include <util/error.h>
+#include "util/misc.h"
 
 #ifdef G_OS_WIN32
 #define WIN32_LEAN_AND_MEAN
diff --git a/gjs/importer.cpp b/gjs/importer.cpp
index 313547f7..a7e888a1 100644
--- a/gjs/importer.cpp
+++ b/gjs/importer.cpp
@@ -34,8 +34,8 @@
 #include "jsapi-wrapper.h"
 #include "module.h"
 #include "native.h"
-#include "util/glib.h"
 #include "util/log.h"
+#include "util/misc.h"
 
 #ifdef G_OS_WIN32
 #define WIN32_LEAN_AND_MEAN
diff --git a/gjs/jsapi-dynamic-class.cpp b/gjs/jsapi-dynamic-class.cpp
index 9a0cfb19..fa20092f 100644
--- a/gjs/jsapi-dynamic-class.cpp
+++ b/gjs/jsapi-dynamic-class.cpp
@@ -25,7 +25,6 @@
 #include <config.h>
 
 #include <util/log.h>
-#include <util/glib.h>
 #include <util/misc.h>
 
 #include "gjs/context-private.h"
diff --git a/gjs/jsapi-util.cpp b/gjs/jsapi-util.cpp
index 05c64237..1740d2bb 100644
--- a/gjs/jsapi-util.cpp
+++ b/gjs/jsapi-util.cpp
@@ -43,7 +43,6 @@
 #include "gjs/jsapi-class.h"
 #include "gjs/jsapi-util.h"
 #include "util/error.h"
-#include "util/glib.h"
 #include "util/log.h"
 #include "util/misc.h"
 
diff --git a/test/gjs-tests.cpp b/test/gjs-tests.cpp
index 4ab3f8d6..522847a0 100644
--- a/test/gjs-tests.cpp
+++ b/test/gjs-tests.cpp
@@ -27,13 +27,13 @@
 
 #include <glib.h>
 #include <glib-object.h>
-#include <util/glib.h>
 
 #include <gjs/gjs.h>
 #include "gjs/jsapi-util.h"
 #include "gjs/jsapi-wrapper.h"
 #include "gjs-test-utils.h"
 #include "util/error.h"
+#include "util/misc.h"
 
 #define VALID_UTF8_STRING "\303\211\303\226 foobar \343\203\237"
 
@@ -286,7 +286,7 @@ static void test_jsapi_util_debug_string_object_with_complicated_to_string(
 }
 
 static void
-gjstest_test_func_util_glib_strv_concat_null(void)
+gjstest_test_func_util_misc_strv_concat_null(void)
 {
     char **ret;
 
@@ -298,7 +298,7 @@ gjstest_test_func_util_glib_strv_concat_null(void)
 }
 
 static void
-gjstest_test_func_util_glib_strv_concat_pointers(void)
+gjstest_test_func_util_misc_strv_concat_pointers(void)
 {
     char  *strv0[2] = {(char*)"foo", NULL};
     char  *strv1[1] = {NULL};
@@ -408,8 +408,10 @@ main(int    argc,
     g_test_add_func("/gjs/jsutil/strip_shebang/only_shebang",
                     gjstest_test_strip_shebang_advance_to_end_for_just_shebang);
     g_test_add_func("/gjs/profiler/start_stop", gjstest_test_profiler_start_stop);
-    g_test_add_func("/util/glib/strv/concat/null", gjstest_test_func_util_glib_strv_concat_null);
-    g_test_add_func("/util/glib/strv/concat/pointers", gjstest_test_func_util_glib_strv_concat_pointers);
+    g_test_add_func("/util/misc/strv/concat/null",
+                    gjstest_test_func_util_misc_strv_concat_null);
+    g_test_add_func("/util/misc/strv/concat/pointers",
+                    gjstest_test_func_util_misc_strv_concat_pointers);
 
 #define ADD_JSAPI_UTIL_TEST(path, func)                            \
     g_test_add("/gjs/jsapi/util/" path, GjsUnitTestFixture, NULL,  \
diff --git a/util/misc.cpp b/util/misc.cpp
index 464f23b6..6bc03c27 100644
--- a/util/misc.cpp
+++ b/util/misc.cpp
@@ -38,3 +38,31 @@ gjs_environment_variable_is_set(const char *env_variable_name)
 
     return true;
 }
+
+/** gjs_g_strv_concat:
+ *
+ * Concate an array of string arrays to one string array. The strings in each
+ * array is copied to the resulting array.
+ *
+ * @strv_array: array of 0-terminated arrays of strings. Null elements are
+ * allowed.
+ * @len: number of arrays in @strv_array
+ *
+ * Returns: (transfer full): a newly allocated 0-terminated array of strings.
+ */
+char** gjs_g_strv_concat(char*** strv_array, int len) {
+    GPtrArray* array = g_ptr_array_sized_new(16);
+
+    for (int i = 0; i < len; i++) {
+        char** strv = strv_array[i];
+        if (!strv)
+            continue;
+
+        for (int j = 0; strv[j]; ++j)
+            g_ptr_array_add(array, g_strdup(strv[j]));
+    }
+
+    g_ptr_array_add(array, nullptr);
+
+    return reinterpret_cast<char**>(g_ptr_array_free(array, false));
+}
diff --git a/util/misc.h b/util/misc.h
index 87c99cec..e0b42d8b 100644
--- a/util/misc.h
+++ b/util/misc.h
@@ -28,4 +28,6 @@
 
 bool    gjs_environment_variable_is_set   (const char *env_variable_name);
 
+char** gjs_g_strv_concat(char*** strv_array, int len);
+
 #endif  // UTIL_MISC_H_


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