[gjs: 4/18] jsapi-util: Inherit constructors for GjsAutoBaseInfo and friends




commit 6f73ae9efb03d9f24d7ef8895d72c4580966e8d9
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Wed Sep 30 18:15:39 2020 +0200

    jsapi-util: Inherit constructors for GjsAutoBaseInfo and friends
    
    Use automatic c++ constructor inheritance, as it allows us to reuse all
    the constructors defined in the main base class, and so to support the
    GjsAutoTakeOwnership() "struct-flag", to add a ref.
    
    Take advantage of this in the real code.

 gi/function.cpp   | 2 +-
 gi/object.cpp     | 2 +-
 gi/wrapperutils.h | 4 +---
 gjs/jsapi-util.h  | 7 +++++--
 4 files changed, 8 insertions(+), 7 deletions(-)
---
diff --git a/gi/function.cpp b/gi/function.cpp
index 9e6c91a6..063dd652 100644
--- a/gi/function.cpp
+++ b/gi/function.cpp
@@ -531,7 +531,7 @@ GjsCallbackTrampoline* gjs_callback_trampoline_new(
 
 GjsCallbackTrampoline::GjsCallbackTrampoline(GICallableInfo* callable_info,
                                              GIScopeType scope, bool is_vfunc)
-    : m_info(g_base_info_ref(callable_info)),
+    : m_info(callable_info, GjsAutoTakeOwnership()),
       m_scope(scope),
       m_param_types(g_callable_info_get_n_args(callable_info), {}),
       m_is_vfunc(is_vfunc) {
diff --git a/gi/object.cpp b/gi/object.cpp
index 08e82081..1d7d6df6 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -565,7 +565,7 @@ bool ObjectPrototype::is_vfunc_unchanged(GIVFuncInfo* info) {
 
     /* ref the first info so that we don't destroy
      * it when unrefing parents later */
-    GjsAutoObjectInfo parent = g_base_info_ref(info);
+    GjsAutoObjectInfo parent(info, GjsAutoTakeOwnership());
 
     /* Since it isn't possible to override a vfunc on
      * an interface without reimplementing it, we don't need
diff --git a/gi/wrapperutils.h b/gi/wrapperutils.h
index 303db7be..544bae3b 100644
--- a/gi/wrapperutils.h
+++ b/gi/wrapperutils.h
@@ -716,9 +716,7 @@ class GIWrapperPrototype : public Base {
     GType m_gtype;
 
     explicit GIWrapperPrototype(Info* info, GType gtype)
-        : Base(),
-          m_info(info ? g_base_info_ref(info) : nullptr),
-          m_gtype(gtype) {
+        : Base(), m_info(info, GjsAutoTakeOwnership()), m_gtype(gtype) {
         Base::debug_lifecycle("Prototype constructor");
     }
 
diff --git a/gjs/jsapi-util.h b/gjs/jsapi-util.h
index eee80fcf..aa2f391e 100644
--- a/gjs/jsapi-util.h
+++ b/gjs/jsapi-util.h
@@ -181,8 +181,7 @@ struct GjsAutoTypeClass : GjsAutoPointer<T, void, &g_type_class_unref> {
 // returns GIFunctionInfo*,) use one of the derived classes below.
 struct GjsAutoBaseInfo : GjsAutoPointer<GIBaseInfo, GIBaseInfo,
                                         g_base_info_unref, g_base_info_ref> {
-    GjsAutoBaseInfo(GIBaseInfo* ptr = nullptr)  // NOLINT(runtime/explicit)
-        : GjsAutoPointer(ptr) {}
+    using GjsAutoPointer::GjsAutoPointer;
 
     [[nodiscard]] const char* name() const {
         return g_base_info_get_name(*this);
@@ -199,6 +198,8 @@ struct GjsAutoBaseInfo : GjsAutoPointer<GIBaseInfo, GIBaseInfo,
 // the info is either of a certain type or null.
 template <GIInfoType TAG>
 struct GjsAutoInfo : GjsAutoBaseInfo {
+    using GjsAutoBaseInfo::GjsAutoBaseInfo;
+
     // Normally one-argument constructors should be explicit, but we are trying
     // to conform to the interface of std::unique_ptr here.
     GjsAutoInfo(GIBaseInfo* ptr = nullptr)  // NOLINT(runtime/explicit)
@@ -235,6 +236,8 @@ using GjsAutoVFuncInfo = GjsAutoInfo<GI_INFO_TYPE_VFUNC>;
 // GICallableInfo can be one of several tags, so we have to have a separate
 // class, and use GI_IS_CALLABLE_INFO() to validate.
 struct GjsAutoCallableInfo : GjsAutoBaseInfo {
+    using GjsAutoBaseInfo::GjsAutoBaseInfo;
+
     GjsAutoCallableInfo(GIBaseInfo* ptr = nullptr)  // NOLINT(runtime/explicit)
         : GjsAutoBaseInfo(ptr) {
         validate();


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