[gjs: 1/8] jsapi-util: add ability to ref added GjsAutoParam



commit 2c0089dc50736d4d514a08e3fceabee9114856f9
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Tue Oct 9 05:48:35 2018 +0200

    jsapi-util: add ability to ref added GjsAutoParam
    
    Add an overloaded method to initialize a GjsAutoParam with with a reffed pspec.
    This helps to ref param specs we're consuming.
    
    Fixes GNOME/gjs#213

 gjs/jsapi-util.h | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
---
diff --git a/gjs/jsapi-util.h b/gjs/jsapi-util.h
index 4bcaa577..c48b35df 100644
--- a/gjs/jsapi-util.h
+++ b/gjs/jsapi-util.h
@@ -86,10 +86,13 @@ struct GCPolicy<GjsAutoInfo<T>> : public IgnoreGCPolicy<GjsAutoInfo<T>> {};
 class GjsAutoParam
     : public std::unique_ptr<GParamSpec, decltype(&g_param_spec_unref)> {
     public:
+    struct TakeOwnership {};
+
     GjsAutoParam(GParamSpec* ptr = nullptr)
-        : unique_ptr(ptr, g_param_spec_unref)
-    {
-    }
+        : unique_ptr(ptr, g_param_spec_unref) {}
+
+    GjsAutoParam(GParamSpec* ptr, const TakeOwnership&)
+        : GjsAutoParam(ptr ? g_param_spec_ref(ptr) : nullptr) {}
 
     operator GParamSpec*() { return get(); }
 };


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