mirror of
https://github.com/brl/mutter.git
synced 2024-11-23 00:20:42 -05:00
interval: Transform values on set, if needed
It's possible that GValues passed to a ClutterInterval setter are not of the same type as the interval - for instance, if they come from language bindings, or from untrusted sources; we can use the same transformation functions we already use inside ClutterTransition to ensure that the ClutterInterval always stores values of the same type used to create the interval itself.
This commit is contained in:
parent
b525253c88
commit
a0c620b157
@ -463,6 +463,7 @@ clutter_interval_set_value_internal (ClutterInterval *interval,
|
|||||||
const GValue *value)
|
const GValue *value)
|
||||||
{
|
{
|
||||||
ClutterIntervalPrivate *priv = interval->priv;
|
ClutterIntervalPrivate *priv = interval->priv;
|
||||||
|
GType value_type;
|
||||||
|
|
||||||
g_assert (index_ >= INITIAL && index_ <= RESULT);
|
g_assert (index_ >= INITIAL && index_ <= RESULT);
|
||||||
|
|
||||||
@ -470,7 +471,39 @@ clutter_interval_set_value_internal (ClutterInterval *interval,
|
|||||||
g_value_unset (&priv->values[index_]);
|
g_value_unset (&priv->values[index_]);
|
||||||
|
|
||||||
g_value_init (&priv->values[index_], priv->value_type);
|
g_value_init (&priv->values[index_], priv->value_type);
|
||||||
g_value_copy (value, &priv->values[index_]);
|
|
||||||
|
value_type = G_VALUE_TYPE (value);
|
||||||
|
if (value_type != priv->value_type ||
|
||||||
|
!g_type_is_a (value_type, priv->value_type))
|
||||||
|
{
|
||||||
|
if (g_value_type_compatible (value_type, priv->value_type))
|
||||||
|
{
|
||||||
|
g_value_copy (value, &priv->values[index_]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g_value_type_transformable (value_type, priv->value_type))
|
||||||
|
{
|
||||||
|
GValue transform = G_VALUE_INIT;
|
||||||
|
|
||||||
|
g_value_init (&transform, priv->value_type);
|
||||||
|
|
||||||
|
if (g_value_transform (value, &transform))
|
||||||
|
g_value_copy (&transform, &priv->values[index_]);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
g_warning ("%s: Unable to convert a value of type '%s' into "
|
||||||
|
"the value type '%s' of the interval.",
|
||||||
|
G_STRLOC,
|
||||||
|
g_type_name (value_type),
|
||||||
|
g_type_name (priv->value_type));
|
||||||
|
}
|
||||||
|
|
||||||
|
g_value_unset (&transform);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
g_value_copy (value, &priv->values[index_]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
|
Loading…
Reference in New Issue
Block a user