diff options
author | Kalev Lember <klember@redhat.com> | 2015-09-10 14:08:35 +0200 |
---|---|---|
committer | Kalev Lember <klember@redhat.com> | 2015-09-10 14:36:43 +0200 |
commit | d19411a76f91d47930ea67d16b30fba55734b449 (patch) | |
tree | 2b60c5e35a26d9292fcdd03cfc8db1178c5d1be5 | |
parent | 4025b5a54fcbe2f5bc4c71e3259bc1af60c99169 (diff) | |
download | glib-d19411a76f91d47930ea67d16b30fba55734b449.tar.gz |
autocleanups: Add GString type
https://bugzilla.gnome.org/show_bug.cgi?id=754831
-rw-r--r-- | glib/glib-autocleanups.h | 10 | ||||
-rw-r--r-- | glib/tests/autoptr.c | 8 |
2 files changed, 17 insertions, 1 deletions
diff --git a/glib/glib-autocleanups.h b/glib/glib-autocleanups.h index 8b80b3853..cab6408e8 100644 --- a/glib/glib-autocleanups.h +++ b/glib/glib-autocleanups.h @@ -29,8 +29,15 @@ g_autoptr_cleanup_generic_gfree (void *p) g_free (*pp); } +static inline void +g_autoptr_cleanup_gstring_free (GString *string) +{ + if (string) + g_string_free (string, TRUE); +} + /* If adding a cleanup here, please also add a test case to - * glib/glib/autoptr.c + * glib/tests/autoptr.c */ G_DEFINE_AUTOPTR_CLEANUP_FUNC(GAsyncQueue, g_async_queue_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC(GBookmarkFile, g_bookmark_file_free) @@ -64,6 +71,7 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(GMatchInfo, g_match_info_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC(GScanner, g_scanner_destroy) G_DEFINE_AUTOPTR_CLEANUP_FUNC(GSequence, g_sequence_free) G_DEFINE_AUTOPTR_CLEANUP_FUNC(GSList, g_slist_free) +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GString, g_autoptr_cleanup_gstring_free) G_DEFINE_AUTOPTR_CLEANUP_FUNC(GStringChunk, g_string_chunk_free) G_DEFINE_AUTOPTR_CLEANUP_FUNC(GThread, g_thread_unref) G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(GMutex, g_mutex_clear) diff --git a/glib/tests/autoptr.c b/glib/tests/autoptr.c index 676ee0733..6f0eafbf8 100644 --- a/glib/tests/autoptr.c +++ b/glib/tests/autoptr.c @@ -277,6 +277,13 @@ test_g_slist (void) } static void +test_g_string (void) +{ + g_autoptr(GString) val = g_string_new (""); + g_assert (val != NULL); +} + +static void test_g_string_chunk (void) { g_autoptr(GStringChunk) val = g_string_chunk_new (42); @@ -428,6 +435,7 @@ main (int argc, gchar *argv[]) g_test_add_func ("/autoptr/g_scanner", test_g_scanner); g_test_add_func ("/autoptr/g_sequence", test_g_sequence); g_test_add_func ("/autoptr/g_slist", test_g_slist); + g_test_add_func ("/autoptr/g_string", test_g_string); g_test_add_func ("/autoptr/g_string_chunk", test_g_string_chunk); g_test_add_func ("/autoptr/g_thread", test_g_thread); g_test_add_func ("/autoptr/g_mutex", test_g_mutex); |