[glib] gdbus-codegen: gracefully handle property get on proxy with no cached property



commit f773bd8b764232d6c691de1329a2defc66c0e51f
Author: David Zeuthen <davidz redhat com>
Date:   Fri May 6 10:32:42 2011 -0400

    gdbus-codegen: gracefully handle property get on proxy with no cached property
    
    This can easily happen if the owner of the remote object vanishes. Of
    course, when that happens, user code is already notified (by e.g. the
    notify::g-name-owner signal) so it can avoid using the proxy but
    requiring that is a bit harsh. IOW, before this patch this critical
    error was printed
    
     GLib-GIO-CRITICAL **: g_dbus_gvariant_to_gvalue: assertion `value != NULL' failed
    
    when that happened. With this patch, we just avoid setting the GValue
    so the user will get the default value for its type instead. So, for
    example, if the user code is getting a GVariant property on such a
    defunct proxy, then he gets a NULL back. So unless said user code
    checks the return value, criticals will still be printed if the NULL
    GVariant is used for anything interesting.
    
    Signed-off-by: David Zeuthen <davidz redhat com>

 gio/gdbus-codegen/codegen.py |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)
---
diff --git a/gio/gdbus-codegen/codegen.py b/gio/gdbus-codegen/codegen.py
index 256ff77..8eafaf6 100644
--- a/gio/gdbus-codegen/codegen.py
+++ b/gio/gdbus-codegen/codegen.py
@@ -1449,9 +1449,16 @@ class CodeGenerator:
                          '  info = _%s_property_info_pointers[prop_id - 1];\n'
                          '  variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (object), info->parent_struct.name);\n'
                          '  if (info->use_gvariant)\n'
-                         '    g_value_set_variant (value, variant);\n'
+                         '    {\n'
+                         '      g_value_set_variant (value, variant);\n'
+                         '    }\n'
                          '  else\n'
-                         '    g_dbus_gvariant_to_gvalue (variant, value);\n'
+                         '    {\n'
+                         # could be that we don't have the value in cache - in that case, we do
+                         # nothing and the user gets the default value for the GType
+                         '      if (variant != NULL)\n'
+                         '        g_dbus_gvariant_to_gvalue (variant, value);\n'
+                         '    }\n'
                          '  if (variant != NULL)\n'
                          '    g_variant_unref (variant);\n'
                          %(len(i.properties), i.name_lower))



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]