Move GStrv typedef to glib.h instead of gobject.h

GStrv was historically only needed for the boxed G_TYPE_STRV,
but it is now useful for g_auto(GStrv) as well. This is not
an ABI change.

https://bugzilla.gnome.org/show_bug.cgi?id=755355
This commit is contained in:
Xavier Claessens 2015-09-21 10:41:00 -04:00
parent 32811598f3
commit b81f3ced71
9 changed files with 22 additions and 9 deletions

View File

@ -1453,6 +1453,9 @@ g_strfreev
g_strconcat
g_strjoin
g_strjoinv
<SUBSECTION>
GStrv
g_strv_length
g_strv_contains

View File

@ -398,7 +398,6 @@ G_TYPE_SOURCE
G_TYPE_POLLFD
G_TYPE_THREAD
G_TYPE_OPTION_GROUP
GStrv
<SUBSECTION Standard>
G_TYPE_IS_BOXED

View File

@ -2343,8 +2343,10 @@
* {
* g_auto(GQueue) queue = G_QUEUE_INIT;
* g_auto(GVariantBuilder) builder;
* g_auto(GStrv) strv;
*
* g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT);
* strv = g_strsplit("a:b:c", ":", -1);
*
* ...
*

View File

@ -86,3 +86,4 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(GVariantIter, g_variant_iter_free)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GVariantDict, g_variant_dict_unref)
G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(GVariantDict, g_variant_dict_clear)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GVariantType, g_variant_type_free)
G_DEFINE_AUTO_CLEANUP_FREE_FUNC(GStrv, g_strfreev, NULL)

View File

@ -2458,6 +2458,13 @@ g_strsplit_set (const gchar *string,
return result;
}
/**
* GStrv:
*
* A typedef alias for gchar**. This is mostly useful when used together with
* g_auto().
*/
/**
* g_strfreev:
* @str_array: a %NULL-terminated array of strings to free

View File

@ -265,6 +265,7 @@ gpointer g_memdup (gconstpointer mem,
* g_strdupv() copies a NULL-terminated array of strings
* g_strv_length() returns the length of a NULL-terminated array of strings
*/
typedef gchar** GStrv;
GLIB_AVAILABLE_IN_ALL
gchar** g_strsplit (const gchar *string,
const gchar *delimiter,

View File

@ -398,6 +398,13 @@ test_g_variant_type (void)
g_assert (val != NULL);
}
static void
test_strv (void)
{
g_auto(GStrv) val = g_strsplit("a:b:c", ":", -1);
g_assert (val != NULL);
}
int
main (int argc, gchar *argv[])
{
@ -449,6 +456,7 @@ main (int argc, gchar *argv[])
g_test_add_func ("/autoptr/g_variant_iter", test_g_variant_iter);
g_test_add_func ("/autoptr/g_variant_dict", test_g_variant_dict);
g_test_add_func ("/autoptr/g_variant_type", test_g_variant_type);
g_test_add_func ("/autoptr/strv", test_strv);
return g_test_run ();
}

View File

@ -357,13 +357,6 @@ GType g_option_group_get_type (void) G_GNUC_CONST;
GLIB_DEPRECATED_FOR('G_TYPE_VARIANT')
GType g_variant_get_gtype (void) G_GNUC_CONST;
/**
* GStrv:
*
* A C representable type name for #G_TYPE_STRV.
*/
typedef gchar** GStrv;
G_END_DECLS
#endif /* __GLIB_TYPES_H__ */

View File

@ -21,7 +21,6 @@
#error "Only <glib-object.h> can be included directly."
#endif
G_DEFINE_AUTO_CLEANUP_FREE_FUNC(GStrv, g_strfreev, NULL)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GObject, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GInitiallyUnowned, g_object_unref)
G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(GValue, g_value_unset)