[gjs: 2/10] boxed: Clarify lifecycle log messages



commit cf71e3ba4bcaf3bdcb48ad76160e1939a88eb727
Author: Philip Chimento <philip chimento gmail com>
Date:   Sun Feb 24 11:05:10 2019 -0800

    boxed: Clarify lifecycle log messages
    
    To aid in debugging, we want to log a lifecycle message whenever the
    internal boxed pointer is created or allocated. This was only logged in
    some cases, and the message confusingly said "JSObject created".

 gi/boxed.cpp | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
---
diff --git a/gi/boxed.cpp b/gi/boxed.cpp
index 51ef8783..8b1118ea 100644
--- a/gi/boxed.cpp
+++ b/gi/boxed.cpp
@@ -116,7 +116,7 @@ void BoxedInstance::allocate_directly(void) {
     m_ptr = g_slice_alloc0(g_struct_info_get_size(info()));
     m_allocated_directly = true;
 
-    debug_lifecycle("JSObject created by direct allocation");
+    debug_lifecycle("Boxed pointer directly allocated");
 }
 
 /* When initializing a boxed object from a hash of properties, we don't want
@@ -255,6 +255,7 @@ static bool boxed_invoke_constructor(JSContext* context, JS::HandleObject obj,
  */
 void BoxedInstance::copy_boxed(void* boxed_ptr) {
     m_ptr = g_boxed_copy(gtype(), boxed_ptr);
+    debug_lifecycle("Boxed pointer created with g_boxed_copy()");
 }
 
 void BoxedInstance::copy_boxed(BoxedInstance* source) {
@@ -300,8 +301,12 @@ bool BoxedInstance::constructor_impl(JSContext* context, JS::HandleObject obj,
         /* Short-circuit construction for GVariants by calling into the JS packing
            function */
         const GjsAtoms& atoms = GjsContextPrivate::atoms(context);
-        return boxed_invoke_constructor(context, obj, atoms.new_internal(),
-                                        args);
+        if (!boxed_invoke_constructor(context, obj, atoms.new_internal(), args))
+            return false;
+
+        debug_lifecycle("Boxed construction delegated to GVariant constructor");
+
+        return true;
     }
 
     BoxedPrototype* proto = get_prototype();
@@ -329,7 +334,7 @@ bool BoxedInstance::constructor_impl(JSContext* context, JS::HandleObject obj,
 
         m_ptr = rval_arg.v_pointer;
 
-        debug_lifecycle("JSObject created with boxed instance");
+        debug_lifecycle("Boxed pointer created from zero-args constructor");
 
     } else if (proto->can_allocate_directly()) {
         allocate_directly();
@@ -349,6 +354,8 @@ bool BoxedInstance::constructor_impl(JSContext* context, JS::HandleObject obj,
                 return false;
         }
 
+        debug_lifecycle("Boxed construction delegated to JS constructor");
+
         return true;
     } else {
         gjs_throw(context,
@@ -459,6 +466,8 @@ bool BoxedInstance::get_nested_interface_object(
     /* A structure nested inside a parent object; doesn't have an independent allocation */
     priv->m_ptr = raw_ptr() + offset;
     priv->m_not_owning_ptr = true;
+    priv->debug_lifecycle(
+        "Boxed pointer created, pointing inside memory owned by parent");
 
     /* We never actually read the reserved slot, but we put the parent object
      * into it to hold onto the parent object.
@@ -991,6 +1000,7 @@ bool BoxedInstance::init_from_c_struct(JSContext* cx, void* gboxed, NoCopy) {
     // a copy of it. Used for G_SIGNAL_TYPE_STATIC_SCOPE.
     m_ptr = gboxed;
     m_not_owning_ptr = true;
+    debug_lifecycle("Boxed pointer acquired, memory not owned");
     return true;
 }
 
@@ -1000,6 +1010,7 @@ bool BoxedInstance::init_from_c_struct(JSContext* cx, void* gboxed) {
         return true;
     } else if (gtype() == G_TYPE_VARIANT) {
         m_ptr = g_variant_ref_sink(static_cast<GVariant*>(gboxed));
+        debug_lifecycle("Boxed pointer created by sinking GVariant ref");
         return true;
     } else if (get_prototype()->can_allocate_directly()) {
         copy_memory(gboxed);


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