1/*
2 * Copyright © 2015 Canonical Limited
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
16 *
17 * Author: Ryan Lortie <desrt@desrt.ca>
18 */
19
20#if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
21#error "Only <glib.h> can be included directly."
22#endif
23
24static inline void
25g_autoptr_cleanup_generic_gfree (void *p)
26{
27 void **pp = (void**)p;
28 g_free (mem: *pp);
29}
30
31static inline void
32g_autoptr_cleanup_gstring_free (GString *string)
33{
34 if (string)
35 g_string_free (string, TRUE);
36}
37
38/* Ignore deprecations in case we refer to a type which was added in a more
39 * recent GLib version than the user’s #GLIB_VERSION_MAX_ALLOWED definition. */
40G_GNUC_BEGIN_IGNORE_DEPRECATIONS
41
42/* If adding a cleanup here, please also add a test case to
43 * glib/tests/autoptr.c
44 */
45G_DEFINE_AUTOPTR_CLEANUP_FUNC(GAsyncQueue, g_async_queue_unref)
46G_DEFINE_AUTOPTR_CLEANUP_FUNC(GBookmarkFile, g_bookmark_file_free)
47G_DEFINE_AUTOPTR_CLEANUP_FUNC(GBytes, g_bytes_unref)
48G_DEFINE_AUTOPTR_CLEANUP_FUNC(GChecksum, g_checksum_free)
49G_DEFINE_AUTOPTR_CLEANUP_FUNC(GDateTime, g_date_time_unref)
50G_DEFINE_AUTOPTR_CLEANUP_FUNC(GDate, g_date_free)
51G_DEFINE_AUTOPTR_CLEANUP_FUNC(GDir, g_dir_close)
52G_DEFINE_AUTOPTR_CLEANUP_FUNC(GError, g_error_free)
53G_DEFINE_AUTOPTR_CLEANUP_FUNC(GHashTable, g_hash_table_unref)
54G_DEFINE_AUTOPTR_CLEANUP_FUNC(GHmac, g_hmac_unref)
55G_DEFINE_AUTOPTR_CLEANUP_FUNC(GIOChannel, g_io_channel_unref)
56G_DEFINE_AUTOPTR_CLEANUP_FUNC(GKeyFile, g_key_file_unref)
57G_DEFINE_AUTOPTR_CLEANUP_FUNC(GList, g_list_free)
58G_DEFINE_AUTOPTR_CLEANUP_FUNC(GArray, g_array_unref)
59G_DEFINE_AUTOPTR_CLEANUP_FUNC(GPtrArray, g_ptr_array_unref)
60G_DEFINE_AUTOPTR_CLEANUP_FUNC(GByteArray, g_byte_array_unref)
61G_DEFINE_AUTOPTR_CLEANUP_FUNC(GMainContext, g_main_context_unref)
62G_DEFINE_AUTOPTR_CLEANUP_FUNC(GMainContextPusher, g_main_context_pusher_free)
63G_DEFINE_AUTOPTR_CLEANUP_FUNC(GMainLoop, g_main_loop_unref)
64G_DEFINE_AUTOPTR_CLEANUP_FUNC(GSource, g_source_unref)
65G_DEFINE_AUTOPTR_CLEANUP_FUNC(GMappedFile, g_mapped_file_unref)
66G_DEFINE_AUTOPTR_CLEANUP_FUNC(GMarkupParseContext, g_markup_parse_context_unref)
67G_DEFINE_AUTOPTR_CLEANUP_FUNC(GNode, g_node_destroy)
68G_DEFINE_AUTOPTR_CLEANUP_FUNC(GOptionContext, g_option_context_free)
69G_DEFINE_AUTOPTR_CLEANUP_FUNC(GOptionGroup, g_option_group_unref)
70G_DEFINE_AUTOPTR_CLEANUP_FUNC(GPatternSpec, g_pattern_spec_free)
71G_DEFINE_AUTOPTR_CLEANUP_FUNC(GQueue, g_queue_free)
72G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(GQueue, g_queue_clear)
73G_DEFINE_AUTOPTR_CLEANUP_FUNC(GRand, g_rand_free)
74G_DEFINE_AUTOPTR_CLEANUP_FUNC(GRegex, g_regex_unref)
75G_DEFINE_AUTOPTR_CLEANUP_FUNC(GMatchInfo, g_match_info_unref)
76G_DEFINE_AUTOPTR_CLEANUP_FUNC(GScanner, g_scanner_destroy)
77G_DEFINE_AUTOPTR_CLEANUP_FUNC(GSequence, g_sequence_free)
78G_DEFINE_AUTOPTR_CLEANUP_FUNC(GSList, g_slist_free)
79G_DEFINE_AUTOPTR_CLEANUP_FUNC(GString, g_autoptr_cleanup_gstring_free)
80G_DEFINE_AUTOPTR_CLEANUP_FUNC(GStringChunk, g_string_chunk_free)
81G_DEFINE_AUTOPTR_CLEANUP_FUNC(GStrvBuilder, g_strv_builder_unref)
82G_DEFINE_AUTOPTR_CLEANUP_FUNC(GThread, g_thread_unref)
83G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(GMutex, g_mutex_clear)
84G_DEFINE_AUTOPTR_CLEANUP_FUNC(GMutexLocker, g_mutex_locker_free)
85G_DEFINE_AUTOPTR_CLEANUP_FUNC(GRecMutexLocker, g_rec_mutex_locker_free)
86G_DEFINE_AUTOPTR_CLEANUP_FUNC(GRWLockWriterLocker, g_rw_lock_writer_locker_free)
87G_DEFINE_AUTOPTR_CLEANUP_FUNC(GRWLockReaderLocker, g_rw_lock_reader_locker_free)
88G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(GCond, g_cond_clear)
89G_DEFINE_AUTOPTR_CLEANUP_FUNC(GTimer, g_timer_destroy)
90G_DEFINE_AUTOPTR_CLEANUP_FUNC(GTimeZone, g_time_zone_unref)
91G_DEFINE_AUTOPTR_CLEANUP_FUNC(GTree, g_tree_unref)
92G_DEFINE_AUTOPTR_CLEANUP_FUNC(GVariant, g_variant_unref)
93G_DEFINE_AUTOPTR_CLEANUP_FUNC(GVariantBuilder, g_variant_builder_unref)
94G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(GVariantBuilder, g_variant_builder_clear)
95G_DEFINE_AUTOPTR_CLEANUP_FUNC(GVariantIter, g_variant_iter_free)
96G_DEFINE_AUTOPTR_CLEANUP_FUNC(GVariantDict, g_variant_dict_unref)
97G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(GVariantDict, g_variant_dict_clear)
98G_DEFINE_AUTOPTR_CLEANUP_FUNC(GVariantType, g_variant_type_free)
99G_DEFINE_AUTO_CLEANUP_FREE_FUNC(GStrv, g_strfreev, NULL)
100G_DEFINE_AUTOPTR_CLEANUP_FUNC(GRefString, g_ref_string_release)
101G_DEFINE_AUTOPTR_CLEANUP_FUNC(GUri, g_uri_unref)
102
103G_GNUC_END_IGNORE_DEPRECATIONS
104

source code of include/glib-2.0/glib/glib-autocleanups.h