gobject: Add a g_assert_finalize_object() macro

With modifications by Philip Withnall.

Fixes: #488
This commit is contained in:
Simon McVittie 2011-12-14 16:28:56 +00:00 committed by Philip Withnall
parent 3f1a79a4fa
commit b76bf3ca72
2 changed files with 35 additions and 0 deletions

View File

@ -322,6 +322,9 @@ g_weak_ref_clear
g_weak_ref_get
g_weak_ref_set
<SUBSECTION Testing>
g_assert_finalize_object
<SUBSECTION Standard>
G_INITIALLY_UNOWNED
G_INITIALLY_UNOWNED_CLASS

View File

@ -744,6 +744,38 @@ static inline gboolean
(g_set_object) ((GObject **) (object_ptr), (GObject *) (new_object)) \
)
/**
* g_assert_finalize_object: (skip)
* @object: (transfer full) (type GObject.Object): an object
*
* Assert that @object is non-%NULL, then release one reference to it with
* g_object_unref() and assert that it has been finalized (i.e. that there
* are no more references).
*
* If assertions are disabled via `G_DISABLE_ASSERT`,
* this macro just calls g_object_unref() without any further checks.
*
* This macro should only be used in regression tests.
*
* Since: 2.62
*/
static inline void
(g_assert_finalize_object) (GObject *object)
{
gpointer weak_pointer = object;
g_assert_true (G_IS_OBJECT (weak_pointer));
g_object_add_weak_pointer (object, &weak_pointer);
g_object_unref (weak_pointer);
g_assert_null (weak_pointer);
}
#ifdef G_DISABLE_ASSERT
#define g_assert_finalize_object(object) g_object_unref (object)
#else
#define g_assert_finalize_object(object) (g_assert_finalize_object ((GObject *) object))
#endif
/**
* g_clear_weak_pointer: (skip)
* @weak_pointer_location: The memory address of a pointer