g_type_check_value, g_type_check_value_holds: accept const argument

Conceptually, these functions clearly ought to be fine for a const
structure. This avoids _G_TYPE_CVH (the implementation of
G_TYPE_CHECK_VALUE_TYPE, G_VALUE_HOLDS, G_VALUE_HOLDS_BOXED etc.)
needing to cast to a mutable GValue, which causes
G_VALUE_HOLDS (cv, type) to issue warnings under gcc -Wcast-qual if
cv is a const GValue *.

https://bugzilla.gnome.org/show_bug.cgi?id=734479
This commit is contained in:
Simon McVittie 2014-08-08 12:01:10 +01:00 committed by Philip Withnall
parent f5804275af
commit 0c0b1bdd0a
2 changed files with 7 additions and 7 deletions

View File

@ -4193,14 +4193,14 @@ g_type_check_is_value_type (GType type)
}
gboolean
g_type_check_value (GValue *value)
g_type_check_value (const GValue *value)
{
return value && type_check_is_value_type_U (value->g_type);
}
gboolean
g_type_check_value_holds (GValue *value,
GType type)
g_type_check_value_holds (const GValue *value,
GType type)
{
return value && type_check_is_value_type_U (value->g_type) && g_type_is_a (value->g_type, type);
}

View File

@ -2202,9 +2202,9 @@ gboolean g_type_check_class_is_a (GTypeClass *g_class,
GLIB_AVAILABLE_IN_ALL
gboolean g_type_check_is_value_type (GType type) G_GNUC_CONST;
GLIB_AVAILABLE_IN_ALL
gboolean g_type_check_value (GValue *value) G_GNUC_PURE;
gboolean g_type_check_value (const GValue *value) G_GNUC_PURE;
GLIB_AVAILABLE_IN_ALL
gboolean g_type_check_value_holds (GValue *value,
gboolean g_type_check_value_holds (const GValue *value,
GType type) G_GNUC_PURE;
GLIB_AVAILABLE_IN_ALL
gboolean g_type_test_flags (GType type,
@ -2255,7 +2255,7 @@ const gchar * g_type_name_from_class (GTypeClass *g_class);
__r; \
}))
# define _G_TYPE_CVH(vl, gt) (G_GNUC_EXTENSION ({ \
GValue *__val = (GValue*) vl; GType __t = gt; gboolean __r; \
const GValue *__val = (const GValue*) vl; GType __t = gt; gboolean __r; \
if (!__val) \
__r = FALSE; \
else if (__val->g_type == __t) \
@ -2267,7 +2267,7 @@ const gchar * g_type_name_from_class (GTypeClass *g_class);
#else /* !__GNUC__ */
# define _G_TYPE_CIT(ip, gt) (g_type_check_instance_is_a ((GTypeInstance*) ip, gt))
# define _G_TYPE_CCT(cp, gt) (g_type_check_class_is_a ((GTypeClass*) cp, gt))
# define _G_TYPE_CVH(vl, gt) (g_type_check_value_holds ((GValue*) vl, gt))
# define _G_TYPE_CVH(vl, gt) (g_type_check_value_holds ((const GValue*) vl, gt))
#endif /* !__GNUC__ */
/**
* G_TYPE_FLAG_RESERVED_ID_BIT: