glib-autocleanups.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 of the licence, 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. #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
  20. #error "Only <glib.h> can be included directly."
  21. #endif
  22. #ifndef __GI_SCANNER__
  23. static inline void
  24. g_autoptr_cleanup_generic_gfree (void *p)
  25. {
  26. void **pp = (void**)p;
  27. g_free (*pp);
  28. }
  29. static inline void
  30. g_autoptr_cleanup_gstring_free (GString *string)
  31. {
  32. if (string)
  33. g_string_free (string, TRUE);
  34. }
  35. /* If adding a cleanup here, please also add a test case to
  36. * glib/tests/autoptr.c
  37. */
  38. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GAsyncQueue, g_async_queue_unref)
  39. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GBookmarkFile, g_bookmark_file_free)
  40. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GBytes, g_bytes_unref)
  41. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GChecksum, g_checksum_free)
  42. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GDateTime, g_date_time_unref)
  43. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GDir, g_dir_close)
  44. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GError, g_error_free)
  45. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GHashTable, g_hash_table_unref)
  46. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GHmac, g_hmac_unref)
  47. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GIOChannel, g_io_channel_unref)
  48. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GKeyFile, g_key_file_unref)
  49. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GList, g_list_free)
  50. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GArray, g_array_unref)
  51. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GPtrArray, g_ptr_array_unref)
  52. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GByteArray, g_byte_array_unref)
  53. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GMainContext, g_main_context_unref)
  54. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GMainLoop, g_main_loop_unref)
  55. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GSource, g_source_unref)
  56. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GMappedFile, g_mapped_file_unref)
  57. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GMarkupParseContext, g_markup_parse_context_unref)
  58. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GNode, g_node_destroy)
  59. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GOptionContext, g_option_context_free)
  60. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GOptionGroup, g_option_group_unref)
  61. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GPatternSpec, g_pattern_spec_free)
  62. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GQueue, g_queue_free)
  63. G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(GQueue, g_queue_clear)
  64. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GRand, g_rand_free)
  65. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GRegex, g_regex_unref)
  66. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GMatchInfo, g_match_info_unref)
  67. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GScanner, g_scanner_destroy)
  68. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GSequence, g_sequence_free)
  69. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GSList, g_slist_free)
  70. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GString, g_autoptr_cleanup_gstring_free)
  71. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GStringChunk, g_string_chunk_free)
  72. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GThread, g_thread_unref)
  73. G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(GMutex, g_mutex_clear)
  74. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GMutexLocker, g_mutex_locker_free)
  75. G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(GCond, g_cond_clear)
  76. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GTimer, g_timer_destroy)
  77. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GTimeZone, g_time_zone_unref)
  78. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GTree, g_tree_unref)
  79. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GVariant, g_variant_unref)
  80. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GVariantBuilder, g_variant_builder_unref)
  81. G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(GVariantBuilder, g_variant_builder_clear)
  82. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GVariantIter, g_variant_iter_free)
  83. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GVariantDict, g_variant_dict_unref)
  84. G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(GVariantDict, g_variant_dict_clear)
  85. G_DEFINE_AUTOPTR_CLEANUP_FUNC(GVariantType, g_variant_type_free)
  86. G_DEFINE_AUTO_CLEANUP_FREE_FUNC(GStrv, g_strfreev, NULL)
  87. #endif