summaryrefslogtreecommitdiff
path: root/gi/object.h
diff options
context:
space:
mode:
authorMarco Trevisan (Treviño) <mail@3v1n0.net>2021-03-24 07:40:47 +0100
committerMarco Trevisan (Treviño) <mail@3v1n0.net>2021-04-22 19:53:46 +0200
commit3303948fd850963831925b5e213d1ada17e07eab (patch)
tree83d5a370d137f84c653dd0ef065f5876c0e66f08 /gi/object.h
parentb22497a768bdc71ecc7d4fb8971453a65df522d1 (diff)
downloadgjs-3303948fd850963831925b5e213d1ada17e07eab.tar.gz
object: Catch finalized objects that are still under gjs scope
When an object is finalized its qdata is finally removed, so if while we track the object in the wrapper the qdata is removed (after a disposal) then we can be sure that the object is finalized. We can so track this state by using a GDestroyNotify function as it will be called with the wrapper pointer and so we can easily mark the object as finalized in such case. While the object is in the disposed state, waiting for finalization we have to temporary give the role of monitoring the qdata to the disposed quark so that during this phase the object has still the private qdata unset, but still monitored for finalization, until we stop caring about it. If instead the object is created as a wrapper for a disposed object, the private qdata still serves us to monitor its finalization without having to override the disposed one, that may still be used by another wrapper that is still living waiting for being garbage collected. If this happens we can finally write proper critical messages and avoid accessing to the object again. Added a test to cover this case
Diffstat (limited to 'gi/object.h')
-rw-r--r--gi/object.h4
1 files changed, 4 insertions, 0 deletions
diff --git a/gi/object.h b/gi/object.h
index bdc50de6..e6d5a365 100644
--- a/gi/object.h
+++ b/gi/object.h
@@ -177,6 +177,7 @@ class ObjectBase
[[nodiscard]] static GQuark custom_type_quark();
[[nodiscard]] static GQuark custom_property_quark();
+ [[nodiscard]] static GQuark disposed_quark();
};
// See https://bugzilla.mozilla.org/show_bug.cgi?id=1614220
@@ -304,6 +305,7 @@ class ObjectInstance : public GIWrapperInstance<ObjectBase, ObjectPrototype,
bool m_wrapper_finalized : 1;
bool m_gobj_disposed : 1;
+ bool m_gobj_finalized : 1;
/* True if this object has visible JS state, and thus its lifecycle is
* managed using toggle references. False if this object just keeps a
@@ -373,6 +375,8 @@ class ObjectInstance : public GIWrapperInstance<ObjectBase, ObjectPrototype,
private:
void set_object_qdata(void);
void unset_object_qdata(void);
+ void track_gobject_finalization();
+ void ignore_gobject_finalization();
void check_js_object_finalized(void);
void ensure_uses_toggle_ref(JSContext* cx);
[[nodiscard]] bool check_gobject_disposed(const char* for_what) const;