[glib: 2/3] gdbus-codegen: emit GUnixFDLists if an arg has type 'h'
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 2/3] gdbus-codegen: emit GUnixFDLists if an arg has type 'h'
- Date: Tue, 8 Oct 2019 10:27:19 +0000 (UTC)
commit 4aba03562bc1526a1baf70ad068a9395ec64bf64
Author: Will Thompson <will willthompson co uk>
Date: Mon Sep 2 06:56:08 2019 +0100
gdbus-codegen: emit GUnixFDLists if an arg has type 'h'
Previously, if a method was not annotated with org.gtk.GDBus.C.UnixFD
then the generated code would never contain GUnixFDList parameters, even
if the method has 'h' (file descriptor) parameters. However, in this
case, the generated code is essentially useless: the method cannot be
called or handled except in degenerate cases where the file descriptors
are missing or ignored.
Check the argument types for 'h', and if present, generate code as if
org.gtk.GDBus.C.UnixFD annotation were specified.
This change will break any existing code which refers to the (useless)
wrappers for such methods. The workaround for such code is to add the
org.gtk.GDBus.C.UnixFD annotation, which will cause the same generated
code to be emitted before and after this change.
If this is found to cause widespread problems, we can explore a
different approach (perhaps emitting a warning from the code generator,
or annotating the symbols as deprecated).
https://gitlab.gnome.org/GNOME/glib/issues/1726
gio/gdbus-2.0/codegen/dbustypes.py | 4 ++++
gio/tests/gdbus-test-codegen.c | 34 ++++++++++++++++++++++++++++++++--
gio/tests/test-codegen.xml | 9 +++++++++
3 files changed, 45 insertions(+), 2 deletions(-)
---
diff --git a/gio/gdbus-2.0/codegen/dbustypes.py b/gio/gdbus-2.0/codegen/dbustypes.py
index 16364f9b7..498ea668b 100644
--- a/gio/gdbus-2.0/codegen/dbustypes.py
+++ b/gio/gdbus-2.0/codegen/dbustypes.py
@@ -284,10 +284,14 @@ class Method:
for a in self.in_args:
a.post_process(interface_prefix, cns, cns_upper, cns_lower, arg_count)
arg_count += 1
+ if 'h' in a.signature:
+ self.unix_fd = True
for a in self.out_args:
a.post_process(interface_prefix, cns, cns_upper, cns_lower, arg_count)
arg_count += 1
+ if 'h' in a.signature:
+ self.unix_fd = True
if utils.lookup_annotation(self.annotations, 'org.freedesktop.DBus.Deprecated') == 'true':
self.deprecated = True
diff --git a/gio/tests/gdbus-test-codegen.c b/gio/tests/gdbus-test-codegen.c
index 241cc529c..ba0f6ed61 100644
--- a/gio/tests/gdbus-test-codegen.c
+++ b/gio/tests/gdbus-test-codegen.c
@@ -2599,16 +2599,46 @@ handle_hello_fd (FooiGenFDPassing *object,
return TRUE;
}
-/* Test that generated code for methods includes GUnixFDList arguments if
- * the method is explicitly annotated as C.UnixFD.
+static gboolean
+handle_no_annotation (FooiGenFDPassing *object,
+ GDBusMethodInvocation *invocation,
+ GUnixFDList *fd_list,
+ GVariant *arg_greeting,
+ const gchar *arg_greeting_locale)
+{
+ foo_igen_fdpassing_complete_no_annotation (object, invocation, fd_list, arg_greeting, arg_greeting_locale);
+ return TRUE;
+}
+
+static gboolean
+handle_no_annotation_nested (FooiGenFDPassing *object,
+ GDBusMethodInvocation *invocation,
+ GUnixFDList *fd_list,
+ GVariant *arg_files)
+{
+ foo_igen_fdpassing_complete_no_annotation_nested (object, invocation, fd_list);
+ return TRUE;
+}
+
+/* Test that generated code for methods includes GUnixFDList arguments if:
+ * - the method is explicitly annotated as C.UnixFD; or
+ * - the method signature contains the type 'h'
*/
static void
test_unix_fd_list (void)
{
FooiGenFDPassingIface iface;
+ g_test_bug ("https://gitlab.gnome.org/GNOME/glib/issues/1726");
+
/* This method is explicitly annotated. */
iface.handle_hello_fd = handle_hello_fd;
+ /* This one is not, but it's got an in and out 'h' parameter so should
+ * automatically grow GUnixFDList arguments.
+ */
+ iface.handle_no_annotation = handle_no_annotation;
+ /* This method has an 'h' inside a complex type. */
+ iface.handle_no_annotation_nested = handle_no_annotation_nested;
(void) iface;
}
diff --git a/gio/tests/test-codegen.xml b/gio/tests/test-codegen.xml
index 39d8769c7..3090cad4a 100644
--- a/gio/tests/test-codegen.xml
+++ b/gio/tests/test-codegen.xml
@@ -481,6 +481,15 @@
<arg name="greeting" direction="in" type="s"/>
<arg name="response" direction="out" type="s"/>
</method>
+ <method name="NoAnnotation">
+ <arg name="greeting" direction="in" type="h"/>
+ <arg name="greeting_locale" direction="in" type="s"/>
+ <arg name="response" direction="out" type="h"/>
+ <arg name="response_locale" direction="out" type="s"/>
+ </method>
+ <method name="NoAnnotationNested">
+ <arg name="files" type="a{sh}" direction="in"/>
+ </method>
</interface>
<interface name="Naming">
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]