Fix regress_test_closure_variant return value
authorMartin Pitt <martinpitt@gnome.org>
Sat, 5 May 2012 19:14:52 +0000 (12:14 -0700)
committerMartin Pitt <martinpitt@gnome.org>
Sat, 5 May 2012 21:10:42 +0000 (14:10 -0700)
We need to g_variant_ref() the return type: the closure delivers it wrapped
in a GValue, and the subsequent g_value_unset() unrefs it to zero otherwise.

This was uncovered by the now working TestClosures.test_variant() test case in
PyGObject.

Also allow passing NULL as argument, to be able to test these code paths as
well.

tests/scanner/Regress-1.0-expected.gir
tests/scanner/regress.c

index 4a1b49a..81c0a6b 100644 (file)
@@ -2129,7 +2129,7 @@ call and can be released on return.</doc>
           <doc xml:whitespace="preserve">GClosure which takes one GVariant and returns a GVariant</doc>
           <type name="GObject.Closure" c:type="GClosure*"/>
         </parameter>
-        <parameter name="arg" transfer-ownership="none">
+        <parameter name="arg" transfer-ownership="none" allow-none="1">
           <doc xml:whitespace="preserve">a GVariant passed as argument to @closure</doc>
           <type name="GLib.Variant" c:type="GVariant*"/>
         </parameter>
index 2736313..032d07b 100644 (file)
@@ -216,7 +216,7 @@ regress_test_closure_one_arg (GClosure *closure, int arg)
 /**
  * regress_test_closure_variant:
  * @closure: GClosure which takes one GVariant and returns a GVariant
- * @arg: (transfer none): a GVariant passed as argument to @closure
+ * @arg: (allow-none) (transfer none): a GVariant passed as argument to @closure
  *
  * Return value: (transfer full): the return value of @closure
  */
@@ -238,6 +238,8 @@ regress_test_closure_variant (GClosure *closure, GVariant* arg)
                     NULL);
 
   ret = g_value_get_variant (&return_value);
+  if (ret != NULL)
+    g_variant_ref (ret);
 
   g_value_unset (&return_value);
   g_value_unset (&arguments[0]);