Commit cf71e3ba authored by Philip Chimento's avatar Philip Chimento

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".
parent 6d25dbeb
......@@ -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(),
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()) {
......@@ -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 {
......@@ -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;
"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()) {
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment