[gjs: 13/22] object: Cancel queued toggles on dispose notify




commit eb28da76bd3995250d0b3ee729338d0c184871ea
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Mon Mar 29 04:05:47 2021 +0200

    object: Cancel queued toggles on dispose notify
    
    If when disposing an object we've toggle requests coming from another
    thread (as it happens with GSettings) we need to cancel the queue as
    the object won't be usable anymore and will be marked for being garbage
    collected. This was currently causing us to hit a g_error, that isn't
    actually problematic in this case because the object isn't going to be
    usable anyways.
    
    Add more test tools to simulate such case, and test it.

 gi/object.cpp                                      |  1 +
 installed-tests/js/testGObjectDestructionAccess.js | 16 ++++++++++++++++
 2 files changed, 17 insertions(+)
---
diff --git a/gi/object.cpp b/gi/object.cpp
index de63354c..e18620ec 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -1136,6 +1136,7 @@ ObjectInstance::gobj_dispose_notify(void)
     if (m_uses_toggle_ref) {
         g_object_ref(m_ptr.get());
         g_object_remove_toggle_ref(m_ptr, wrapped_gobj_toggle_notify, this);
+        ToggleQueue::get_default().cancel(m_ptr);
         wrapped_gobj_toggle_notify(this, m_ptr, TRUE);
         m_uses_toggle_ref = false;
     }
diff --git a/installed-tests/js/testGObjectDestructionAccess.js 
b/installed-tests/js/testGObjectDestructionAccess.js
index 05e79a32..6d592934 100644
--- a/installed-tests/js/testGObjectDestructionAccess.js
+++ b/installed-tests/js/testGObjectDestructionAccess.js
@@ -302,4 +302,20 @@ describe('Disposed or finalized GObject', function () {
         GLib.test_assert_expected_messages_internal('Gjs', 'testGObjectDestructionAccess.js', 0,
             'returned from function is marked as disposed and then as finalized');
     });
+
+    it('ignores toggling queued unref toggles', function () {
+        let file = Gio.File.new_for_path('/');
+        file.expandMeWithToggleRef = true;
+        file.ref();
+        GjsTestTools.unref_other_thread(file);
+        file.run_dispose();
+    });
+
+    it('ignores toggling queued toggles', function () {
+        let file = Gio.File.new_for_path('/');
+        file.expandMeWithToggleRef = true;
+        GjsTestTools.ref_other_thread(file);
+        GjsTestTools.unref_other_thread(file);
+        file.run_dispose();
+    });
 });


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