Constify collect and lcopy strings in GTypeValueTable
authorEmmanuele Bassi <ebassi@linux.intel.com>
Wed, 7 Mar 2012 12:54:04 +0000 (12:54 +0000)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 6 Jul 2012 03:27:35 +0000 (23:27 -0400)
This avoids warnings when creating idiomatic value tables, like:

  static const GTypeValueTable _clutter_shader_float_value_table = {
    clutter_value_init_shader_float,
    clutter_value_free_shader_float,
    clutter_value_copy_shader_float,
    clutter_value_peek_pointer,
    "ip",
    clutter_value_collect_shader_float,
    "pp",
    clutter_value_lcopy_shader_float
  };

Because the strings are literals. And, really: nobody should be using
allocated values for the collection and lcopy strings.

https://bugzilla.gnome.org/show_bug.cgi?id=671545

gobject/gtype.h
gobject/gvaluecollector.h

index 768ad00..14206ed 100644 (file)
@@ -1206,12 +1206,12 @@ struct _GTypeValueTable
                                  GValue       *dest_value);
   /* varargs functionality (optional) */
   gpointer (*value_peek_pointer) (const GValue *value);
-  gchar            *collect_format;
+  const gchar *collect_format;
   gchar*   (*collect_value)      (GValue       *value,
                                  guint         n_collect_values,
                                  GTypeCValue  *collect_values,
                                  guint         collect_flags);
-  gchar            *lcopy_format;
+  const gchar *lcopy_format;
   gchar*   (*lcopy_value)        (const GValue *value,
                                  guint         n_collect_values,
                                  GTypeCValue  *collect_values,
index 6d5190e..05a436a 100644 (file)
@@ -92,7 +92,7 @@ G_STMT_START {                                                                                \
   GValue *_val = (value);                                                              \
   guint _flags = (flags);                                                              \
   GTypeValueTable *_vtab = g_type_value_table_peek (_value_type);                      \
-  gchar *_collect_format = _vtab->collect_format;                                      \
+  const gchar *_collect_format = _vtab->collect_format;                                        \
   GTypeCValue _cvalues[G_VALUE_COLLECT_FORMAT_MAX_LENGTH] = { { 0, }, };               \
   guint _n_values = 0;                                                                 \
                                                                                         \
@@ -161,7 +161,7 @@ G_STMT_START {                                                                              \
 #define G_VALUE_COLLECT_SKIP(_value_type, var_args)                                    \
 G_STMT_START {                                                                         \
   GTypeValueTable *_vtable = g_type_value_table_peek (_value_type);                    \
-  gchar *_collect_format = _vtable->collect_format;                                    \
+  const gchar *_collect_format = _vtable->collect_format;                              \
                                                                                         \
   while (*_collect_format)                                                             \
     {                                                                                  \
@@ -207,7 +207,7 @@ G_STMT_START {                                                                              \
   guint _flags = (flags);                                                              \
   GType _value_type = G_VALUE_TYPE (_value);                                           \
   GTypeValueTable *_vtable = g_type_value_table_peek (_value_type);                    \
-  gchar *_lcopy_format = _vtable->lcopy_format;                                                \
+  const gchar *_lcopy_format = _vtable->lcopy_format;                                  \
   GTypeCValue _cvalues[G_VALUE_COLLECT_FORMAT_MAX_LENGTH] = { { 0, }, };               \
   guint _n_values = 0;                                                                 \
                                                                                         \