[gjs: 16/18] arg: Use GjsSmartPointer to get the right auto pointer on array
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 16/18] arg: Use GjsSmartPointer to get the right auto pointer on array
- Date: Fri, 20 Nov 2020 01:52:04 +0000 (UTC)
commit fc68688a3bead5f7f17157f979178017f11d26b4
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date: Wed Oct 14 14:19:01 2020 +0200
arg: Use GjsSmartPointer to get the right auto pointer on array
gi/arg.cpp | 11 +----------
gjs/jsapi-util.h | 10 ++++++++++
2 files changed, 11 insertions(+), 10 deletions(-)
---
diff --git a/gi/arg.cpp b/gi/arg.cpp
index 487c6352..d6bddf52 100644
--- a/gi/arg.cpp
+++ b/gi/arg.cpp
@@ -711,14 +711,6 @@ template <typename T>
return array;
}
-template <typename T>
-constexpr void array_free_func(T* array) {
- if constexpr (std::is_same_v<T, char*>)
- g_strfreev(array);
- else
- g_free(array);
-}
-
template <GITypeTag TAG, typename T>
GJS_JSAPI_RETURN_CONVENTION static bool js_value_to_c_strict(
JSContext* cx, const JS::HandleValue& value, T* out) {
@@ -740,8 +732,7 @@ GJS_JSAPI_RETURN_CONVENTION static bool gjs_array_to_auto_array(
JS::RootedValue elem(cx);
// Add one so we're always zero terminated
- GjsAutoPointer<T, T, array_free_func<T>> result =
- array_allocate<T>(length + 1);
+ GjsSmartPointer<T> result = array_allocate<T>(length + 1);
for (size_t i = 0; i < length; ++i) {
elem = JS::UndefinedValue();
diff --git a/gjs/jsapi-util.h b/gjs/jsapi-util.h
index 93bb29ab..ee004037 100644
--- a/gjs/jsapi-util.h
+++ b/gjs/jsapi-util.h
@@ -306,6 +306,16 @@ struct GjsSmartPointer : GjsAutoPointer<T> {
using GjsAutoPointer<T>::GjsAutoPointer;
};
+template <>
+struct GjsSmartPointer<char*> : GjsAutoStrv {
+ using GjsAutoStrv::GjsAutoPointer;
+};
+
+template <>
+struct GjsSmartPointer<GStrv> : GjsAutoStrv {
+ using GjsAutoStrv::GjsAutoPointer;
+};
+
template <>
struct GjsSmartPointer<GObject> : GjsAutoUnref<GObject> {
using GjsAutoUnref<GObject>::GjsAutoUnref;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]