[gjs: 9/18] jsapi-util: Add GjsSmartPointer template to create an auto-pointer dynamically
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 9/18] jsapi-util: Add GjsSmartPointer template to create an auto-pointer dynamically
- Date: Fri, 20 Nov 2020 01:52:03 +0000 (UTC)
commit 4800710ef355f3987e901642ad70968c23d22f60
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date: Thu Oct 1 05:39:40 2020 +0200
jsapi-util: Add GjsSmartPointer template to create an auto-pointer dynamically
gjs/jsapi-util.h | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
---
diff --git a/gjs/jsapi-util.h b/gjs/jsapi-util.h
index 34ffc987..cfe7ec76 100644
--- a/gjs/jsapi-util.h
+++ b/gjs/jsapi-util.h
@@ -187,11 +187,20 @@ struct GjsAutoCharFuncs {
using GjsAutoChar =
GjsAutoPointer<char, char, GjsAutoCharFuncs::free, GjsAutoCharFuncs::dup>;
+struct GjsAutoErrorFuncs {
+ static GError* error_copy(GError* error) { return g_error_copy(error); }
+};
+using GjsAutoError =
+ GjsAutoPointer<GError, GError, g_error_free, GjsAutoErrorFuncs::error_copy>;
+
using GjsAutoStrv = GjsAutoPointer<char*, char*, g_strfreev, g_strdupv>;
template <typename T>
using GjsAutoUnref = GjsAutoPointer<T, void, g_object_unref, g_object_ref>;
+using GjsAutoGVariant =
+ GjsAutoPointer<GVariant, GVariant, g_variant_unref, g_variant_ref>;
+
template <typename V, typename T>
constexpr void GjsAutoPointerDeleter(T v) {
if constexpr (std::is_array_v<V>)
@@ -291,6 +300,31 @@ struct GjsAutoCallableInfo : GjsAutoBaseInfo {
}
};
+template <typename T>
+struct GjsSmartPointer : GjsAutoPointer<T> {
+ using GjsAutoPointer<T>::GjsAutoPointer;
+};
+
+template <>
+struct GjsSmartPointer<GObject> : GjsAutoUnref<GObject> {
+ using GjsAutoUnref<GObject>::GjsAutoUnref;
+};
+
+template <>
+struct GjsSmartPointer<GIBaseInfo> : GjsAutoBaseInfo {
+ using GjsAutoBaseInfo::GjsAutoBaseInfo;
+};
+
+template <>
+struct GjsSmartPointer<GError> : GjsAutoError {
+ using GjsAutoError::GjsAutoError;
+};
+
+template <>
+struct GjsSmartPointer<GVariant> : GjsAutoGVariant {
+ using GjsAutoGVariant::GjsAutoPointer;
+};
+
/* For use of GjsAutoInfo<TAG> in GC hash maps */
namespace JS {
template <GIInfoType TAG>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]