|
| 1 | +/* |
| 2 | + * Copyright © 2015 Canonical Limited |
| 3 | + * SPDX-License-Identifier: LGPL-2.0-or-later |
| 4 | + * |
| 5 | + * This library is free software; you can redistribute it and/or |
| 6 | + * modify it under the terms of the GNU Lesser General Public |
| 7 | + * License as published by the Free Software Foundation; either |
| 8 | + * version 2 of the licence, or (at your option) any later version. |
| 9 | + * |
| 10 | + * This library is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | + * Lesser General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU Lesser General Public |
| 16 | + * License along with this library; if not, see <http://www.gnu.org/licenses/>. |
| 17 | + * |
| 18 | + * Author: Ryan Lortie <[email protected]> |
| 19 | + */ |
| 20 | + |
| 21 | +#pragma once |
| 22 | + |
| 23 | +#include <glnx-backport-autoptr.h> |
| 24 | + |
| 25 | +#if !GLIB_CHECK_VERSION(2, 43, 4) |
| 26 | + |
| 27 | +static inline void |
| 28 | +g_autoptr_cleanup_generic_gfree (void *p) |
| 29 | +{ |
| 30 | + void **pp = (void**)p; |
| 31 | + if (*pp) |
| 32 | + g_free (*pp); |
| 33 | +} |
| 34 | + |
| 35 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GAsyncQueue, g_async_queue_unref) |
| 36 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GBookmarkFile, g_bookmark_file_free) |
| 37 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GBytes, g_bytes_unref) |
| 38 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GChecksum, g_checksum_free) |
| 39 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GDateTime, g_date_time_unref) |
| 40 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GDir, g_dir_close) |
| 41 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GError, g_error_free) |
| 42 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GHashTable, g_hash_table_unref) |
| 43 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GHmac, g_hmac_unref) |
| 44 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GIOChannel, g_io_channel_unref) |
| 45 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GKeyFile, g_key_file_unref) |
| 46 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GList, g_list_free) |
| 47 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GArray, g_array_unref) |
| 48 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GPtrArray, g_ptr_array_unref) |
| 49 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GMainContext, g_main_context_unref) |
| 50 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GMainLoop, g_main_loop_unref) |
| 51 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GSource, g_source_unref) |
| 52 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GMappedFile, g_mapped_file_unref) |
| 53 | +#if GLIB_CHECK_VERSION(2, 36, 0) |
| 54 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GMarkupParseContext, g_markup_parse_context_unref) |
| 55 | +#endif |
| 56 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(gchar, g_free) |
| 57 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GNode, g_node_destroy) |
| 58 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GOptionContext, g_option_context_free) |
| 59 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GOptionGroup, g_option_group_free) |
| 60 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GPatternSpec, g_pattern_spec_free) |
| 61 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GQueue, g_queue_free) |
| 62 | +G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(GQueue, g_queue_clear) |
| 63 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GRand, g_rand_free) |
| 64 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GRegex, g_regex_unref) |
| 65 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GMatchInfo, g_match_info_unref) |
| 66 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GScanner, g_scanner_destroy) |
| 67 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GSequence, g_sequence_free) |
| 68 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GSList, g_slist_free) |
| 69 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GStringChunk, g_string_chunk_free) |
| 70 | +G_DEFINE_AUTO_CLEANUP_FREE_FUNC(GStrv, g_strfreev, NULL) |
| 71 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GThread, g_thread_unref) |
| 72 | +G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(GMutex, g_mutex_clear) |
| 73 | +G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(GCond, g_cond_clear) |
| 74 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GTimer, g_timer_destroy) |
| 75 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GTimeZone, g_time_zone_unref) |
| 76 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GTree, g_tree_unref) |
| 77 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GVariant, g_variant_unref) |
| 78 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GVariantBuilder, g_variant_builder_unref) |
| 79 | +G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(GVariantBuilder, g_variant_builder_clear) |
| 80 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GVariantIter, g_variant_iter_free) |
| 81 | +#if GLIB_CHECK_VERSION(2, 40, 0) |
| 82 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GVariantDict, g_variant_dict_unref) |
| 83 | +G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(GVariantDict, g_variant_dict_clear) |
| 84 | +#endif |
| 85 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GVariantType, g_variant_type_free) |
| 86 | +#if GLIB_CHECK_VERSION(2, 40, 0) |
| 87 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GSubprocess, g_object_unref) |
| 88 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GSubprocessLauncher, g_object_unref) |
| 89 | +#endif |
| 90 | + |
| 91 | +/* Add GObject-based types as needed. */ |
| 92 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GAsyncResult, g_object_unref) |
| 93 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GCancellable, g_object_unref) |
| 94 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GConverter, g_object_unref) |
| 95 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GConverterOutputStream, g_object_unref) |
| 96 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GDataInputStream, g_object_unref) |
| 97 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GFile, g_object_unref) |
| 98 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GFileEnumerator, g_object_unref) |
| 99 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GFileIOStream, g_object_unref) |
| 100 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GFileInfo, g_object_unref) |
| 101 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GFileInputStream, g_object_unref) |
| 102 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GFileMonitor, g_object_unref) |
| 103 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GFileOutputStream, g_object_unref) |
| 104 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GInputStream, g_object_unref) |
| 105 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GMemoryInputStream, g_object_unref) |
| 106 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GMemoryOutputStream, g_object_unref) |
| 107 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GMount, g_object_unref) |
| 108 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GOutputStream, g_object_unref) |
| 109 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GSocket, g_object_unref) |
| 110 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GSocketAddress, g_object_unref) |
| 111 | +#if GLIB_CHECK_VERSION(2, 36, 0) |
| 112 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GTask, g_object_unref) |
| 113 | +#endif |
| 114 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GTlsCertificate, g_object_unref) |
| 115 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GTlsDatabase, g_object_unref) |
| 116 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GTlsInteraction, g_object_unref) |
| 117 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GDBusConnection, g_object_unref) |
| 118 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GDBusMessage, g_object_unref) |
| 119 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GVolumeMonitor, g_object_unref) |
| 120 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GZlibCompressor, g_object_unref) |
| 121 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GZlibDecompressor, g_object_unref) |
| 122 | + |
| 123 | +#endif |
| 124 | + |
| 125 | +#if !GLIB_CHECK_VERSION(2, 45, 8) |
| 126 | + |
| 127 | +static inline void |
| 128 | +g_autoptr_cleanup_gstring_free (GString *string) |
| 129 | +{ |
| 130 | + if (string) |
| 131 | + g_string_free (string, TRUE); |
| 132 | +} |
| 133 | + |
| 134 | +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GString, g_autoptr_cleanup_gstring_free) |
| 135 | + |
| 136 | +#endif |
0 commit comments