mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-11 15:06:14 +01:00
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.
This commit is contained in:
parent
a8263add45
commit
ab25fa42cc
@ -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); } \
|
||||
|
@ -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 ();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user