After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 741167 - gdbus-codegen fix for boxed out parameters
gdbus-codegen fix for boxed out parameters
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gdbus
2.42.x
Other Linux
: Normal normal
: ---
Assigned To: David Zeuthen (not reading bugmail)
gtkdev
Depends on:
Blocks:
 
 
Reported: 2014-12-05 15:28 UTC by Tim Waugh
Modified: 2017-12-03 20:02 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Git-format patch against glib-2-42 (3.67 KB, patch)
2014-12-05 15:28 UTC, Tim Waugh
none Details | Review
codegen: fix array out-param annotations (9.33 KB, patch)
2017-11-15 12:29 UTC, Philip Withnall
committed Details | Review
gdbusutils: Fix a memory leak in g_dbus_gvalue_to_gvariant() (1.21 KB, patch)
2017-11-15 12:30 UTC, Philip Withnall
committed Details | Review
tests: Fix some minor memory leaks in gdbus-test-codegen (1.21 KB, patch)
2017-11-15 12:30 UTC, Philip Withnall
committed Details | Review
gvariant: Clarify return docs for g_variant_get_normal_form() (946 bytes, patch)
2017-11-15 12:30 UTC, Philip Withnall
none Details | Review
gobject: Add missing annotations to GValue variant methods (1.48 KB, patch)
2017-11-15 12:30 UTC, Philip Withnall
committed Details | Review
gvariant: Clarify return docs for g_variant_get_normal_form() (1.29 KB, patch)
2017-11-28 14:37 UTC, Philip Withnall
committed Details | Review

Description Tim Waugh 2014-12-05 15:28:22 UTC
Created attachment 292195 [details] [review]
Git-format patch against glib-2-42

When using gdbus-codegen to produce generated code for a method like this:

    <method name="GetPrinters">
      <arg name="printers" direction="out" type="ao"/>
    </method>

it produces output like this:

/**
 * pd_manager_call_get_printers_sync:
 * @proxy: A #PdManagerProxy.
 * @out_printers: (out): Return location for return parameter or %NULL to ignore.
 * @cancellable: (allow-none): A #GCancellable or %NULL.
 * @error: Return location for error or %NULL.

Because out_printers is not annotated as being an array, the g-ir-scanner produces this GIR output:

          <parameter name="out_printers"
                     direction="out"
                     caller-allocates="0"
                     transfer-ownership="full">
            <type name="utf8" c:type="gchar***"/>
          </parameter>

...which is nonsense.

The fix is to include an "(array zero-terminated=1)" annotation. Patch attached.

Original discovery:
  https://github.com/hughsie/printerd/issues/40

Patch against glib-2-42 attached.
Comment 1 Philip Withnall 2017-11-15 12:29:57 UTC
Created attachment 363674 [details] [review]
codegen: fix array out-param annotations

When using gdbus-codegen to produce generated code for a method with
an out parameter with a signature like 'as', make sure to include
an "(array)" annotation for that parameter.

(Reworked by Philip Withnall to improve code formatting.)
Comment 2 Philip Withnall 2017-11-15 12:30:04 UTC
Created attachment 363675 [details] [review]
gdbusutils: Fix a memory leak in g_dbus_gvalue_to_gvariant()

g_variant_get_normal_form() doesn’t necessarily return a floating
GVariant, so we have to take, rather than sink, the ref.

This fixes a lot of leaks with gdbus-codegen-generated code.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Comment 3 Philip Withnall 2017-11-15 12:30:11 UTC
Created attachment 363676 [details] [review]
tests: Fix some minor memory leaks in gdbus-test-codegen

It’s not entirely leak-free, but it’s better than before.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Comment 4 Philip Withnall 2017-11-15 12:30:18 UTC
Created attachment 363677 [details] [review]
gvariant: Clarify return docs for g_variant_get_normal_form()

Clarify that the return value may be floating, or may not be (depends
on whether the input @value was in normal form).

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Comment 5 Philip Withnall 2017-11-15 12:30:23 UTC
Created attachment 363678 [details] [review]
gobject: Add missing annotations to GValue variant methods

They were missing some (nullable) and (transfer) annotations.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Comment 6 Emmanuele Bassi (:ebassi) 2017-11-28 12:28:14 UTC
Review of attachment 363674 [details] [review]:

:+1:
Comment 7 Emmanuele Bassi (:ebassi) 2017-11-28 12:28:45 UTC
Review of attachment 363675 [details] [review]:

Nice catch
Comment 8 Emmanuele Bassi (:ebassi) 2017-11-28 12:29:08 UTC
Review of attachment 363676 [details] [review]:

Okay
Comment 9 Emmanuele Bassi (:ebassi) 2017-11-28 12:35:03 UTC
Review of attachment 363677 [details] [review]:

::: glib/gvariant.c
@@ +5856,3 @@
  * output is definitely in normal form.
  *
+ * The return value may be floating.

This is kind of unhelpful; does it depend on the phase of the Moon or the alignment between planets?

If the GVariant is already a normal form, it'll return a reference to that GVariant, otherwise it'll ref_sink it. I think this should be the documented behaviour of the function, given that we cannot change it in a way that doesn't break existing code.

To be fair, I find this function vaguely confusing.
Comment 10 Emmanuele Bassi (:ebassi) 2017-11-28 12:35:25 UTC
Review of attachment 363678 [details] [review]:

Okay
Comment 11 Philip Withnall 2017-11-28 14:30:49 UTC
Attachment 363674 [details] pushed as d35d9b7 - codegen: fix array out-param annotations
Attachment 363675 [details] pushed as 37d9b0c - gdbusutils: Fix a memory leak in g_dbus_gvalue_to_gvariant()
Attachment 363676 [details] pushed as a2a4a10 - tests: Fix some minor memory leaks in gdbus-test-codegen
Attachment 363678 [details] pushed as aca410c - gobject: Add missing annotations to GValue variant methods
Comment 12 Philip Withnall 2017-11-28 14:37:30 UTC
Created attachment 364566 [details] [review]
gvariant: Clarify return docs for g_variant_get_normal_form()

Clarify that the return value may be floating, or may not be (depends
on whether the input @value was in normal form).

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Comment 13 Emmanuele Bassi (:ebassi) 2017-12-01 17:29:58 UTC
Review of attachment 364566 [details] [review]:

ACK-by: me
Comment 14 Philip Withnall 2017-12-03 20:02:07 UTC
Ta.

Attachment 364566 [details] pushed as e45f99e - gvariant: Clarify return docs for g_variant_get_normal_form()