gparamspecs: Fix some guint to gboolean conversion warnings

While we’re at it, rename the variables to make the intent a bit
clearer: these functions return a boolean indicating whether any of the
values were modified to make them valid. `n_changed` is a counter of the
number of modified values.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3405
This commit is contained in:
Philip Withnall 2025-04-11 15:06:11 +01:00
parent 615cd4c10c
commit 70ddc35340
No known key found for this signature in database
GPG Key ID: C5C42CFB268637CA

View File

@ -763,7 +763,7 @@ param_string_validate (GParamSpec *pspec,
{
GParamSpecString *sspec = G_PARAM_SPEC_STRING (pspec);
gchar *string = value->data[0].v_pointer;
guint changed = 0;
guint n_changed = 0;
if (string && string[0])
{
@ -778,7 +778,7 @@ param_string_validate (GParamSpec *pspec,
value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS;
}
string[0] = sspec->substitutor;
changed++;
n_changed++;
}
if (sspec->cset_nth)
for (s = string + 1; *s; s++)
@ -792,7 +792,7 @@ param_string_validate (GParamSpec *pspec,
value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS;
}
*s = sspec->substitutor;
changed++;
n_changed++;
}
}
if (sspec->null_fold_if_empty && string && string[0] == 0)
@ -802,18 +802,18 @@ param_string_validate (GParamSpec *pspec,
else
value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS;
value->data[0].v_pointer = NULL;
changed++;
n_changed++;
string = value->data[0].v_pointer;
}
if (sspec->ensure_non_null && !string)
{
value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS;
value->data[0].v_pointer = g_strdup ("");
changed++;
n_changed++;
string = value->data[0].v_pointer;
}
return changed;
return (n_changed > 0);
}
static gboolean
@ -883,16 +883,16 @@ param_param_validate (GParamSpec *pspec,
{
/* GParamSpecParam *spec = G_PARAM_SPEC_PARAM (pspec); */
GParamSpec *param = value->data[0].v_pointer;
guint changed = 0;
guint n_changed = 0;
if (param && !g_value_type_compatible (G_PARAM_SPEC_TYPE (param), G_PARAM_SPEC_VALUE_TYPE (pspec)))
{
g_param_spec_unref (param);
value->data[0].v_pointer = NULL;
changed++;
n_changed++;
}
return changed;
return (n_changed > 0);
}
static void
@ -1015,7 +1015,7 @@ param_value_array_validate (GParamSpec *pspec,
{
GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec);
GValueArray *value_array = value->data[0].v_pointer;
guint changed = 0;
guint n_changed = 0;
if (!value->data[0].v_pointer && aspec->fixed_n_elements)
value_array = value->data[0].v_pointer = g_value_array_new (aspec->fixed_n_elements);
@ -1023,7 +1023,7 @@ param_value_array_validate (GParamSpec *pspec,
if (value->data[0].v_pointer)
{
/* ensure array size validity */
changed += value_array_ensure_size (value_array, aspec->fixed_n_elements);
n_changed += value_array_ensure_size (value_array, aspec->fixed_n_elements);
/* ensure array values validity against a present element spec */
if (aspec->element_spec)
@ -1042,18 +1042,18 @@ param_value_array_validate (GParamSpec *pspec,
g_value_unset (element);
g_value_init (element, G_PARAM_SPEC_VALUE_TYPE (element_spec));
g_param_value_set_default (element_spec, element);
changed++;
n_changed++;
}
else
{
/* validate array value against element_spec */
changed += g_param_value_validate (element_spec, element);
n_changed += g_param_value_validate (element_spec, element) ? 1 : 0;
}
}
}
}
return changed;
return (n_changed > 0);
}
static gint
@ -1128,16 +1128,16 @@ param_object_validate (GParamSpec *pspec,
{
GParamSpecObject *ospec = G_PARAM_SPEC_OBJECT (pspec);
GObject *object = value->data[0].v_pointer;
guint changed = 0;
guint n_changed = 0;
if (object && !g_value_type_compatible (G_OBJECT_TYPE (object), G_PARAM_SPEC_VALUE_TYPE (ospec)))
{
g_object_unref (object);
value->data[0].v_pointer = NULL;
changed++;
n_changed++;
}
return changed;
return (n_changed > 0);
}
static gint
@ -1242,15 +1242,15 @@ param_gtype_validate (GParamSpec *pspec,
{
GParamSpecGType *tspec = G_PARAM_SPEC_GTYPE (pspec);
GType gtype = GPOINTER_TO_TYPE (value->data[0].v_pointer);
guint changed = 0;
guint n_changed = 0;
if (tspec->is_a_type != G_TYPE_NONE && !g_type_is_a (gtype, tspec->is_a_type))
{
value->data[0].v_pointer = GTYPE_TO_POINTER (tspec->is_a_type);
changed++;
n_changed++;
}
return changed;
return (n_changed > 0);
}
static gint