[glib: 1/3] gobject: Add a g_assert_finalize_object() macro
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 1/3] gobject: Add a g_assert_finalize_object() macro
- Date: Thu, 25 Jul 2019 15:42:56 +0000 (UTC)
commit b76bf3ca72460a06ca2e5dd19eb3e5729487d270
Author: Simon McVittie <simon mcvittie collabora co uk>
Date: Wed Dec 14 16:28:56 2011 +0000
gobject: Add a g_assert_finalize_object() macro
With modifications by Philip Withnall.
Fixes: #488
docs/reference/gobject/gobject-sections.txt | 3 +++
gobject/gobject.h | 32 +++++++++++++++++++++++++++++
2 files changed, 35 insertions(+)
---
diff --git a/docs/reference/gobject/gobject-sections.txt b/docs/reference/gobject/gobject-sections.txt
index 2247888d1..bed38e4c5 100644
--- a/docs/reference/gobject/gobject-sections.txt
+++ b/docs/reference/gobject/gobject-sections.txt
@@ -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
diff --git a/gobject/gobject.h b/gobject/gobject.h
index 12e0882c6..91b9f6328 100644
--- a/gobject/gobject.h
+++ b/gobject/gobject.h
@@ -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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]