[gjs/gnome-3-28] object: Warn about finalized GObject in fewer cases



commit 4e60cccfb506975e7ec6983e8e6933c5f5ab0cbf
Author: Philip Chimento <philip chimento gmail com>
Date:   Sat Jun 2 15:15:14 2018 -0700

    object: Warn about finalized GObject in fewer cases
    
    We want to remove this warning in cases where the subsequent code isn't
    actually trying to access the underlying GObject and therefore isn't
    going to crash. On resolve() we don't want the warning, as that only
    applies to prototype objects. On trace() we don't want it either, as that
    may legitimately be called during the GC mark phase on a JS wrapper with
    a disposed GObject.
    
    In the typecheck function, we only use the GObject for a debug assertion.
    All the other checks use the GType. We relax the assertion and only do
    the debug sanity check if the GObject is still alive. Instead of logging
    the warning here, we log the warning in gjs_g_object_from_object() which
    happens later when the GObject is actually used.
    
    We keep the warnings in property getters and setters, since those would
    access the underlying GObject, and they are now only called for names
    that really do resolve to GObject properties and fields.
    
    Closes: #24

 gi/object.cpp | 48 ++++++++++++++----------------------------------
 1 file changed, 14 insertions(+), 34 deletions(-)
---
diff --git a/gi/object.cpp b/gi/object.cpp
index 0c1f75ca..e7d63b0a 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -816,18 +816,6 @@ object_instance_resolve(JSContext       *context,
         return true;
     }
 
-    if (priv->g_object_finalized) {
-        g_critical("Object %s.%s (%p), has been already finalized. "
-                   "Impossible to resolve it.",
-                   priv->info ? g_base_info_get_namespace( (GIBaseInfo*) priv->info) : "",
-                   priv->info ? g_base_info_get_name( (GIBaseInfo*) priv->info) : g_type_name(priv->gtype),
-                   priv->gobj);
-        gjs_dumpstack();
-
-        *resolved = false;
-        return true;
-    }
-
     /* If we have no GIRepository information (we're a JS GObject subclass),
      * we need to look at exposing interfaces. Look up our interfaces through
      * GType data, and then hope that *those* are introspectable. */
@@ -1550,15 +1538,6 @@ object_instance_trace(JSTracer *tracer,
     if (priv == NULL)
         return;
 
-    if (priv->g_object_finalized) {
-        g_debug("Object %s.%s (%p), has been already finalized. "
-                "Impossible to trace it.",
-                 priv->info ? g_base_info_get_namespace( (GIBaseInfo*) priv->info) : "",
-                 priv->info ? g_base_info_get_name( (GIBaseInfo*) priv->info) : g_type_name(priv->gtype),
-                 priv->gobj);
-        return;
-    }
-
     for (GClosure *closure : priv->closures)
         gjs_closure_trace(closure, tracer);
 }
@@ -2229,6 +2208,19 @@ gjs_g_object_from_object(JSContext       *context,
         return NULL;
 
     priv = priv_from_js(context, obj);
+
+    if (priv->g_object_finalized) {
+        g_critical("Object %s.%s (%p), has been already deallocated - "
+                   "impossible to access it. This might be caused by the "
+                   "object having been destroyed from C code using something "
+                   "such as destroy(), dispose(), or remove() vfuncs",
+                   priv->info ? g_base_info_get_namespace(priv->info) : "",
+                   priv->info ? g_base_info_get_name(priv->info) : g_type_name(priv->gtype),
+                   priv->gobj);
+        gjs_dumpstack();
+        return nullptr;
+    }
+
     return priv->gobj;
 }
 
@@ -2275,19 +2267,7 @@ gjs_typecheck_object(JSContext       *context,
         return false;
     }
 
-    if (priv->g_object_finalized) {
-        g_critical("Object %s.%s (%p), has been already deallocated - impossible to access to it. "
-                   "This might be caused by the fact that the object has been destroyed from C "
-                   "code using something such as destroy(), dispose(), or remove() vfuncs",
-                   priv->info ? g_base_info_get_namespace( (GIBaseInfo*) priv->info) : "",
-                   priv->info ? g_base_info_get_name( (GIBaseInfo*) priv->info) : g_type_name(priv->gtype),
-                   priv->gobj);
-        gjs_dumpstack();
-
-        return true;
-    }
-
-    g_assert(priv->gtype == G_OBJECT_TYPE(priv->gobj));
+    g_assert(priv->g_object_finalized || priv->gtype == G_OBJECT_TYPE(priv->gobj));
 
     if (expected_type != G_TYPE_NONE)
         result = g_type_is_a (priv->gtype, expected_type);


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