25 #ifndef __CR_CLEANUP_H__
26 #define __CR_CLEANUP_H__
42 #define CR_DEFINE_CLEANUP_FUNCTION(Type, name, func) \
43 static inline void name (void *v) \
48 #define CR_DEFINE_CLEANUP_FUNCTION0(Type, name, func) \
49 static inline void name (void *v) \
55 #define CR_DEFINE_CLEANUP_FUNCTIONt(Type, name, func) \
56 static inline void name (void *v) \
59 func (*(Type*)v, TRUE); \
62 CR_DEFINE_CLEANUP_FUNCTION0(FILE*, cr_local_file_fclose, fclose)
63 CR_DEFINE_CLEANUP_FUNCTION0(GArray*, cr_local_array_unref, g_array_unref)
64 CR_DEFINE_CLEANUP_FUNCTION0(GChecksum*, cr_local_checksum_free, g_checksum_free)
65 CR_DEFINE_CLEANUP_FUNCTION0(GDir*, cr_local_dir_close, g_dir_close)
66 CR_DEFINE_CLEANUP_FUNCTION0(GError*, cr_local_free_error, g_error_free)
67 CR_DEFINE_CLEANUP_FUNCTION0(GHashTable*, cr_local_hashtable_unref, g_hash_table_unref)
68 CR_DEFINE_CLEANUP_FUNCTION0(GKeyFile*, cr_local_keyfile_free, g_key_file_free)
69 #if GLIB_CHECK_VERSION(2, 32, 0)
70 CR_DEFINE_CLEANUP_FUNCTION0(GKeyFile*, cr_local_keyfile_unref, g_key_file_unref)
72 CR_DEFINE_CLEANUP_FUNCTION0(GPtrArray*, cr_local_ptrarray_unref, g_ptr_array_unref)
73 CR_DEFINE_CLEANUP_FUNCTION0(GTimer*, cr_local_destroy_timer, g_timer_destroy)
75 CR_DEFINE_CLEANUP_FUNCTIONt(GString*, cr_local_free_string, g_string_free)
77 CR_DEFINE_CLEANUP_FUNCTION(
char**, cr_local_strfreev, g_strfreev)
78 CR_DEFINE_CLEANUP_FUNCTION(GList*, cr_local_free_list, g_list_free)
79 CR_DEFINE_CLEANUP_FUNCTION(
void*, cr_local_free, g_free)
80 CR_DEFINE_CLEANUP_FUNCTION(
int, cr_local_file_close, my_close)
82 #define _cleanup_array_unref_ __attribute__ ((cleanup(cr_local_array_unref)))
83 #define _cleanup_checksum_free_ __attribute__ ((cleanup(cr_local_checksum_free)))
84 #define _cleanup_dir_close_ __attribute__ ((cleanup(cr_local_dir_close)))
85 #define _cleanup_error_free_ __attribute__ ((cleanup(cr_local_free_error)))
86 #define _cleanup_file_close_ __attribute__ ((cleanup(cr_local_file_close)))
87 #define _cleanup_file_fclose_ __attribute__ ((cleanup(cr_local_file_fclose)))
88 #define _cleanup_free_ __attribute__ ((cleanup(cr_local_free)))
89 #define _cleanup_hashtable_unref_ __attribute__ ((cleanup(cr_local_hashtable_unref)))
90 #define _cleanup_keyfile_free_ __attribute__ ((cleanup(cr_local_keyfile_free)))
91 #define _cleanup_keyfile_unref_ __attribute__ ((cleanup(cr_local_keyfile_unref)))
92 #define _cleanup_list_free_ __attribute__ ((cleanup(cr_local_free_list)))
93 #define _cleanup_ptrarray_unref_ __attribute__ ((cleanup(cr_local_ptrarray_unref)))
94 #define _cleanup_string_free_ __attribute__ ((cleanup(cr_local_free_string)))
95 #define _cleanup_strv_free_ __attribute__ ((cleanup(cr_local_strfreev)))
96 #define _cleanup_timer_destroy_ __attribute__ ((cleanup(cr_local_destroy_timer)))