summaryrefslogtreecommitdiff
path: root/libappstream-glib/as-cleanup.h
blob: a635d03c8e05bbf08d8c4a8ef877e6a19b283a90 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
 *
 * Copyright (C) 2012 Colin Walters <walters@verbum.org>.
 * Copyright (C) 2014 Richard Hughes <richard@hughsie.com>
 *
 * Licensed under the GNU Lesser General Public License Version 2.1
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
 */

#ifndef __AS_CLEANUP_H__
#define __AS_CLEANUP_H__

#include <gio/gio.h>
#include <libsoup/soup.h>

#include "as-node.h"

G_BEGIN_DECLS

#define GS_DEFINE_CLEANUP_FUNCTION(Type, name, func) \
  static inline void name (void *v) \
  { \
    func (*(Type*)v); \
  }

#define GS_DEFINE_CLEANUP_FUNCTION0(Type, name, func) \
  static inline void name (void *v) \
  { \
    if (*(Type*)v) \
      func (*(Type*)v); \
  }

#define GS_DEFINE_CLEANUP_FUNCTIONt(Type, name, func) \
  static inline void name (void *v) \
  { \
    if (*(Type*)v) \
      func (*(Type*)v, TRUE); \
  }

GS_DEFINE_CLEANUP_FUNCTION0(GArray*, gs_local_array_unref, g_array_unref)
GS_DEFINE_CLEANUP_FUNCTION0(GBytes*, gs_local_bytes_unref, g_bytes_unref)
GS_DEFINE_CLEANUP_FUNCTION0(GChecksum*, gs_local_checksum_free, g_checksum_free)
GS_DEFINE_CLEANUP_FUNCTION0(GDir*, gs_local_dir_close, g_dir_close)
GS_DEFINE_CLEANUP_FUNCTION0(GError*, gs_local_free_error, g_error_free)
GS_DEFINE_CLEANUP_FUNCTION0(GHashTable*, gs_local_hashtable_unref, g_hash_table_unref)
GS_DEFINE_CLEANUP_FUNCTION0(GKeyFile*, gs_local_keyfile_unref, g_key_file_unref)
GS_DEFINE_CLEANUP_FUNCTION0(GMarkupParseContext*, gs_local_markup_parse_context_unref, g_markup_parse_context_unref)
GS_DEFINE_CLEANUP_FUNCTION0(GNode*, gs_local_node_unref, as_node_unref)
GS_DEFINE_CLEANUP_FUNCTION0(GObject*, gs_local_obj_unref, g_object_unref)
GS_DEFINE_CLEANUP_FUNCTION0(GPtrArray*, gs_local_ptrarray_unref, g_ptr_array_unref)
GS_DEFINE_CLEANUP_FUNCTION0(GTimer*, gs_local_destroy_timer, g_timer_destroy)
GS_DEFINE_CLEANUP_FUNCTION0(GVariantBuilder*, gs_local_variant_builder_unref, g_variant_builder_unref)
GS_DEFINE_CLEANUP_FUNCTION0(GVariant*, gs_local_variant_unref, g_variant_unref)
GS_DEFINE_CLEANUP_FUNCTION0(GVariantIter*, gs_local_variant_iter_free, g_variant_iter_free)
GS_DEFINE_CLEANUP_FUNCTION0(SoupURI*, gs_local_uri_unref, soup_uri_free)

GS_DEFINE_CLEANUP_FUNCTIONt(GString*, gs_local_free_string, g_string_free)

GS_DEFINE_CLEANUP_FUNCTION(char**, gs_local_strfreev, g_strfreev)
GS_DEFINE_CLEANUP_FUNCTION(GList*, gs_local_free_list, g_list_free)
GS_DEFINE_CLEANUP_FUNCTION(void*, gs_local_free, g_free)

#define _cleanup_close_dir __attribute__ ((cleanup(gs_local_dir_close)))
#define _cleanup_destroy_timer __attribute__ ((cleanup(gs_local_destroy_timer)))
#define _cleanup_free __attribute__ ((cleanup(gs_local_free)))
#define _cleanup_free_checksum __attribute__ ((cleanup(gs_local_checksum_free)))
#define _cleanup_free_error __attribute__ ((cleanup(gs_local_free_error)))
#define _cleanup_free_list __attribute__ ((cleanup(gs_local_free_list)))
#define _cleanup_free_string __attribute__ ((cleanup(gs_local_free_string)))
#define _cleanup_free_strv __attribute__ ((cleanup(gs_local_strfreev)))
#define _cleanup_unref_array __attribute__ ((cleanup(gs_local_array_unref)))
#define _cleanup_unref_bytes __attribute__ ((cleanup(gs_local_bytes_unref)))
#define _cleanup_unref_hashtable __attribute__ ((cleanup(gs_local_hashtable_unref)))
#define _cleanup_unref_keyfile __attribute__ ((cleanup(gs_local_keyfile_unref)))
#define _cleanup_unref_markup_parse_context __attribute__ ((cleanup(gs_local_markup_parse_context_unref)))
#define _cleanup_unref_node __attribute__ ((cleanup(gs_local_node_unref)))
#define _cleanup_unref_object __attribute__ ((cleanup(gs_local_obj_unref)))
#define _cleanup_unref_ptrarray __attribute__ ((cleanup(gs_local_ptrarray_unref)))
#define _cleanup_unref_uri __attribute__ ((cleanup(gs_local_uri_unref)))
#define _cleanup_unref_variant __attribute__ ((cleanup(gs_local_variant_unref)))

G_END_DECLS

#endif