mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 03:16:17 +01:00
gobject: add GOBJECT_IF_DEBUG macro for debugging gobjects and gsignals.
historically, DEBUG_CODE(gtype.c) and IF_DEBUG(gobject.c, gsignal.c) macros are used to support debugging messages about object bookkeeping and signal emission. DEBUG_CODE has never been used in gtype.c. IF_DEBUG, when used, must be accompanied by an extra #ifdef G_ENABLE_DEBUG. this is cumbersome. this patch add a new macro GOBJECT_IF_DEBUG based on DEBUG_CODE as a replacement for both DEBUG_CODE and IF_DEBUG. https://bugzilla.gnome.org/show_bug.cgi?id=729914
This commit is contained in:
parent
ec5397f9b0
commit
42dad59cc1
@ -316,7 +316,6 @@ g_object_notify_queue_add (GObject *object,
|
||||
}
|
||||
|
||||
#ifdef G_ENABLE_DEBUG
|
||||
#define IF_DEBUG(debug_type) if (_g_type_debug_flags & G_TYPE_DEBUG_ ## debug_type)
|
||||
G_LOCK_DEFINE_STATIC (debug_objects);
|
||||
static guint debug_objects_count = 0;
|
||||
static GHashTable *debug_objects_ht = NULL;
|
||||
@ -344,13 +343,13 @@ G_DEFINE_DESTRUCTOR(debug_objects_atexit)
|
||||
static void
|
||||
debug_objects_atexit (void)
|
||||
{
|
||||
IF_DEBUG (OBJECTS)
|
||||
GOBJECT_IF_DEBUG (OBJECTS,
|
||||
{
|
||||
G_LOCK (debug_objects);
|
||||
g_message ("stale GObjects: %u", debug_objects_count);
|
||||
g_hash_table_foreach (debug_objects_ht, debug_objects_foreach, NULL);
|
||||
G_UNLOCK (debug_objects);
|
||||
}
|
||||
});
|
||||
}
|
||||
#endif /* G_ENABLE_DEBUG */
|
||||
|
||||
@ -395,15 +394,13 @@ _g_object_type_init (void)
|
||||
g_assert (type == G_TYPE_OBJECT);
|
||||
g_value_register_transform_func (G_TYPE_OBJECT, G_TYPE_OBJECT, g_value_object_transform_value);
|
||||
|
||||
#ifdef G_ENABLE_DEBUG
|
||||
IF_DEBUG (OBJECTS)
|
||||
GOBJECT_IF_DEBUG (OBJECTS,
|
||||
{
|
||||
debug_objects_ht = g_hash_table_new (g_direct_hash, NULL);
|
||||
#ifndef G_HAS_CONSTRUCTORS
|
||||
g_atexit (debug_objects_atexit);
|
||||
#endif /* G_HAS_CONSTRUCTORS */
|
||||
}
|
||||
#endif /* G_ENABLE_DEBUG */
|
||||
});
|
||||
}
|
||||
|
||||
static void
|
||||
@ -981,15 +978,13 @@ g_object_init (GObject *object,
|
||||
g_datalist_id_set_data (&object->qdata, quark_in_construction, object);
|
||||
}
|
||||
|
||||
#ifdef G_ENABLE_DEBUG
|
||||
IF_DEBUG (OBJECTS)
|
||||
GOBJECT_IF_DEBUG (OBJECTS,
|
||||
{
|
||||
G_LOCK (debug_objects);
|
||||
debug_objects_count++;
|
||||
g_hash_table_insert (debug_objects_ht, object, object);
|
||||
G_UNLOCK (debug_objects);
|
||||
}
|
||||
#endif /* G_ENABLE_DEBUG */
|
||||
});
|
||||
}
|
||||
|
||||
static void
|
||||
@ -1039,16 +1034,14 @@ g_object_finalize (GObject *object)
|
||||
|
||||
g_datalist_clear (&object->qdata);
|
||||
|
||||
#ifdef G_ENABLE_DEBUG
|
||||
IF_DEBUG (OBJECTS)
|
||||
GOBJECT_IF_DEBUG (OBJECTS,
|
||||
{
|
||||
G_LOCK (debug_objects);
|
||||
g_assert (g_hash_table_lookup (debug_objects_ht, object) == object);
|
||||
g_hash_table_remove (debug_objects_ht, object);
|
||||
debug_objects_count--;
|
||||
G_UNLOCK (debug_objects);
|
||||
}
|
||||
#endif /* G_ENABLE_DEBUG */
|
||||
});
|
||||
}
|
||||
|
||||
static void
|
||||
@ -3184,15 +3177,13 @@ g_object_unref (gpointer _object)
|
||||
|
||||
TRACE (GOBJECT_OBJECT_FINALIZE_END(object,G_TYPE_FROM_INSTANCE(object)));
|
||||
|
||||
#ifdef G_ENABLE_DEBUG
|
||||
IF_DEBUG (OBJECTS)
|
||||
GOBJECT_IF_DEBUG (OBJECTS,
|
||||
{
|
||||
/* catch objects not chaining finalize handlers */
|
||||
G_LOCK (debug_objects);
|
||||
g_assert (g_hash_table_lookup (debug_objects_ht, object) == NULL);
|
||||
G_UNLOCK (debug_objects);
|
||||
}
|
||||
#endif /* G_ENABLE_DEBUG */
|
||||
});
|
||||
g_type_free_instance ((GTypeInstance*) object);
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,24 @@
|
||||
#include "gboxed.h"
|
||||
#include "gclosure.h"
|
||||
|
||||
/*< private >
|
||||
* GOBJECT_IF_DEBUG:
|
||||
* @debug_type: Currently only OBJECTS and SIGNALS are supported.
|
||||
* @code_block: Custom debug code.
|
||||
*
|
||||
* A convenience macro for debugging GObject.
|
||||
* This macro is only used internally.
|
||||
*/
|
||||
#ifdef G_ENABLE_DEBUG
|
||||
#define GOBJECT_IF_DEBUG(debug_type, code_block) \
|
||||
G_STMT_START { \
|
||||
if (_g_type_debug_flags & G_TYPE_DEBUG_ ## debug_type) \
|
||||
{ code_block; } \
|
||||
} G_STMT_END
|
||||
#else /* !G_ENABLE_DEBUG */
|
||||
#define GOBJECT_IF_DEBUG(debug_type, code_block)
|
||||
#endif /* G_ENABLE_DEBUG */
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
extern GTypeDebugFlags _g_type_debug_flags;
|
||||
|
@ -139,15 +139,6 @@
|
||||
#define g_assert_type_system_initialized() \
|
||||
g_assert (static_quark_type_flags)
|
||||
|
||||
#ifdef G_ENABLE_DEBUG
|
||||
#define DEBUG_CODE(debug_type, code_block) G_STMT_START { \
|
||||
if (_g_type_debug_flags & G_TYPE_DEBUG_ ## debug_type) \
|
||||
{ code_block; } \
|
||||
} G_STMT_END
|
||||
#else /* !G_ENABLE_DEBUG */
|
||||
#define DEBUG_CODE(debug_type, code_block) /* code_block */
|
||||
#endif /* G_ENABLE_DEBUG */
|
||||
|
||||
#define TYPE_FUNDAMENTAL_FLAG_MASK (G_TYPE_FLAG_CLASSED | \
|
||||
G_TYPE_FLAG_INSTANTIATABLE | \
|
||||
G_TYPE_FLAG_DERIVABLE | \
|
||||
|
Loading…
Reference in New Issue
Block a user