diff options
author | Marc-André Lureau <marcandre.lureau@redhat.com> | 2011-07-17 21:18:04 +0200 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2011-08-13 18:16:44 -0400 |
commit | d2ca14c270a8a0c01d8a897fad4ea2a9c2e31105 (patch) | |
tree | b0421380d3f30d40db3d24c6bec447c30e172961 /gobject | |
parent | a9ca74efb11bda0a90f482a44bb2ec214744ecc6 (diff) |
Add G_VALUE_INIT
The implementation of GValue is not public or documented. When
allocated on the stack, initializing a GValue is usually done as
documented with:
GValue value = { 0, };
There is lot code around (including WebKit) that added all the missing
fields, resulting in this ugly and non-obvious:
GValue value = { 0, { { 0 } } };
However, this doesn't play nice with -Wmissing-field-initializers for
example. Thus, G_VALUE_INIT.
http://bugzilla.gnome.org/show_bug.cgi?id=654793
http://bugzilla.gnome.org/show_bug.cgi?id=577231
Diffstat (limited to 'gobject')
-rw-r--r-- | gobject/gvalue.c | 6 | ||||
-rw-r--r-- | gobject/gvalue.h | 16 |
2 files changed, 19 insertions, 3 deletions
diff --git a/gobject/gvalue.c b/gobject/gvalue.c index 775747460..bca9aa5d1 100644 --- a/gobject/gvalue.c +++ b/gobject/gvalue.c @@ -73,9 +73,9 @@ * main (int argc, * char *argv[]) * { - * /* GValues must start zero-filled */ - * GValue a = {0}; - * GValue b = {0}; + * /* GValues must be initialized */ + * GValue a = G_VALUE_INIT; + * GValue b = G_VALUE_INIT; * const gchar *message; * * g_type_init (); diff --git a/gobject/gvalue.h b/gobject/gvalue.h index 60c19199d..e1f69806b 100644 --- a/gobject/gvalue.h +++ b/gobject/gvalue.h @@ -161,6 +161,22 @@ void g_value_register_transform_func (GType src_type, */ #define G_VALUE_NOCOPY_CONTENTS (1 << 27) +/** + * G_VALUE_INIT: + * + * A #GValue must be initialized before it can be used. + * This macro can be used as initializer instead of an explicit + * <literal>{ 0 }</literal> when declaring a variable, + * but it cannot be assigned to a variable. + * + * |[ + * GValue value = G_VALUE_INIT; + * ]| + * + * Since: 2.30 + */ +#define G_VALUE_INIT { 0, { { 0 } } } + G_END_DECLS |