[glib: 1/2] gtype: Define auto-cleanup functions for Module class
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 1/2] gtype: Define auto-cleanup functions for Module class
- Date: Mon, 16 Dec 2019 12:13:38 +0000 (UTC)
commit ab25fa42cc6906df31352877154bb7b07f39552f
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date: Fri Dec 13 20:07:51 2019 +0100
gtype: Define auto-cleanup functions for Module class
While we automatically define cleanup functions for the module, we don't
do it for the module class.
This will allow to manage the ownership of the class when reffing it
without having to cast it to GTypeClass.
gobject/gtype.h | 2 ++
gobject/tests/autoptr.c | 26 ++++++++++++++++++++++++++
2 files changed, 28 insertions(+)
---
diff --git a/gobject/gtype.h b/gobject/gtype.h
index 797ab48ee..479b405e9 100644
--- a/gobject/gtype.h
+++ b/gobject/gtype.h
@@ -1406,6 +1406,7 @@ guint g_type_get_type_registration_serial (void);
typedef struct { ParentName##Class parent_class; } ModuleObjName##Class; \
\
_GLIB_DEFINE_AUTOPTR_CHAINUP (ModuleObjName, ParentName) \
+ G_DEFINE_AUTOPTR_CLEANUP_FUNC (ModuleObjName##Class, g_type_class_unref) \
\
G_GNUC_UNUSED static inline ModuleObjName * MODULE##_##OBJ_NAME (gpointer ptr) { \
return G_TYPE_CHECK_INSTANCE_CAST (ptr, module_obj_name##_get_type (), ModuleObjName); } \
@@ -1497,6 +1498,7 @@ guint g_type_get_type_registration_serial (void);
struct _##ModuleObjName { ParentName parent_instance; }; \
\
_GLIB_DEFINE_AUTOPTR_CHAINUP (ModuleObjName, ParentName) \
+ G_DEFINE_AUTOPTR_CLEANUP_FUNC (ModuleObjName##Class, g_type_class_unref) \
\
G_GNUC_UNUSED static inline ModuleObjName * MODULE##_##OBJ_NAME (gpointer ptr) { \
return G_TYPE_CHECK_INSTANCE_CAST (ptr, module_obj_name##_get_type (), ModuleObjName); } \
diff --git a/gobject/tests/autoptr.c b/gobject/tests/autoptr.c
index 1f68cb3f9..19421c220 100644
--- a/gobject/tests/autoptr.c
+++ b/gobject/tests/autoptr.c
@@ -29,6 +29,18 @@ struct _TestAutoCleanupBaseClass {
GObjectClass parent_class;
};
+G_DEFINE_TYPE (TestAutoCleanupBase, test_base_auto_cleanup, G_TYPE_OBJECT)
+
+static void
+test_base_auto_cleanup_class_init (TestAutoCleanupBaseClass *class)
+{
+}
+
+static void
+test_base_auto_cleanup_init (TestAutoCleanupBase *tac)
+{
+}
+
G_DECLARE_FINAL_TYPE (TestAutoCleanup, test_auto_cleanup, TEST, AUTO_CLEANUP, TestAutoCleanupBase)
struct _TestAutoCleanup
@@ -195,6 +207,19 @@ test_autoqueue (void)
g_assert_null (tac3);
}
+static void
+test_autoclass (void)
+{
+ g_autoptr (TestAutoCleanupBaseClass) base_class_ptr = NULL;
+ g_autoptr (TestAutoCleanupClass) class_ptr = NULL;
+
+ base_class_ptr = g_type_class_ref (test_base_auto_cleanup_get_type ());
+ class_ptr = g_type_class_ref (test_auto_cleanup_get_type ());
+
+ g_assert_nonnull (base_class_ptr);
+ g_assert_nonnull (class_ptr);
+}
+
int
main (int argc, gchar *argv[])
{
@@ -205,6 +230,7 @@ main (int argc, gchar *argv[])
g_test_add_func ("/autoptr/autolist", test_autolist);
g_test_add_func ("/autoptr/autoslist", test_autoslist);
g_test_add_func ("/autoptr/autoqueue", test_autoqueue);
+ g_test_add_func ("/autoptr/autoclass", test_autoclass);
return g_test_run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]