[glib] autocleanups: Add GString type
- From: Kalev Lember <klember src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] autocleanups: Add GString type
- Date: Thu, 10 Sep 2015 13:12:30 +0000 (UTC)
commit d19411a76f91d47930ea67d16b30fba55734b449
Author: Kalev Lember <klember redhat com>
Date: Thu Sep 10 14:08:35 2015 +0200
autocleanups: Add GString type
https://bugzilla.gnome.org/show_bug.cgi?id=754831
glib/glib-autocleanups.h | 10 +++++++++-
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 8b80b38..cab6408 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 676ee07..6f0eafb 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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]