[gjs/ewlsh/fix-data-corruption] gi: Correctly hold references for gvariant transfer parameters




commit 9fee568d832acd4907225aeca40ed0c97ebdd96c
Author: Evan Welsh <contact evanwelsh com>
Date:   Tue Jun 29 01:11:29 2021 -0700

    gi: Correctly hold references for gvariant transfer parameters
    
    Fixes #269

 gi/boxed.cpp                            | 8 ++++++--
 installed-tests/js/testGIMarshalling.js | 4 ++--
 2 files changed, 8 insertions(+), 4 deletions(-)
---
diff --git a/gi/boxed.cpp b/gi/boxed.cpp
index 44c2063c..7327c317 100644
--- a/gi/boxed.cpp
+++ b/gi/boxed.cpp
@@ -1024,8 +1024,12 @@ bool BoxedInstance::init_from_c_struct(JSContext* cx, void* gboxed) {
         copy_boxed(gboxed);
         return true;
     } else if (gtype() == G_TYPE_VARIANT) {
-        own_ptr(g_variant_ref_sink(static_cast<GVariant*>(gboxed)));
-        debug_lifecycle("Boxed pointer created by sinking GVariant ref");
+        // Sink the reference if it is floating
+        GVariant* temp = g_variant_take_ref(static_cast<GVariant*>(gboxed));
+        // Add an additional reference which will be unref-ed
+        // in the marshaller
+        own_ptr(g_variant_ref(temp));
+        debug_lifecycle("Boxed pointer created by taking GVariant ref");
         return true;
     } else if (get_prototype()->can_allocate_directly()) {
         copy_memory(gboxed);
diff --git a/installed-tests/js/testGIMarshalling.js b/installed-tests/js/testGIMarshalling.js
index c0bce490..27e05c8a 100644
--- a/installed-tests/js/testGIMarshalling.js
+++ b/installed-tests/js/testGIMarshalling.js
@@ -515,11 +515,11 @@ describe('Zero-terminated C array', function () {
         });
 
         ['none', 'container', 'full'].forEach(transfer => {
-            xit(`marshals as a transfer-${transfer} in and out parameter`, function () {
+            it(`marshals as a transfer-${transfer} in and out parameter`, function () {
                 const returnedArray =
                     GIMarshallingTests[`array_gvariant_${transfer}_in`](variantArray);
                 expect(returnedArray.map(v => v.deepUnpack())).toEqual([27, 'Hello']);
-            }).pend('https://gitlab.gnome.org/GNOME/gjs/issues/269');
+            });
         });
     });
 });


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