gobject: Always ref-sink variants in g_object_set

When collecting varargs, ignore the NOCOPY_CONTENTS
flag for variants. That is what our docs advice for
refcounted types, and it fixes a regression that
was inadvertendly introduced when we stopped doing
some extra GValue copies.

Includes a test case by Philip Withnall.

Fixes: #2774
This commit is contained in:
Matthias Clasen
2022-10-05 07:16:20 -04:00
committed by Philip Withnall
parent 662661a8d0
commit e79af74d1b
2 changed files with 68 additions and 6 deletions

View File

@@ -388,12 +388,8 @@ value_collect_variant (GValue *value,
{
if (!collect_values[0].v_pointer)
value->data[0].v_pointer = NULL;
else if (collect_flags & G_VALUE_NOCOPY_CONTENTS)
{
value->data[0].v_pointer = collect_values[0].v_pointer;
value->data[1].v_uint = G_VALUE_NOCOPY_CONTENTS;
}
else
/* never honour G_VALUE_NOCOPY_CONTENTS for ref-counted types */
value->data[0].v_pointer = g_variant_ref_sink (collect_values[0].v_pointer);
return NULL;