[glib: 1/2] codegen: Change pointer casting to remove type-punning warnings



commit 64b76c7ca5cf5b4ede2f4b423114f46141890e1e
Author: Robert Ancell <robert ancell canonical com>
Date:   Fri Sep 7 10:19:05 2018 +1200

    codegen: Change pointer casting to remove type-punning warnings
    
    The existing code was generating code with undefined results that modern compilers warn about:
    
    accounts-generated.c:204:23: warning: dereferencing type-punned pointer will break strict-aliasing rules 
[-Wstrict-aliasing]
         (GDBusArgInfo **) &_accounts_accounts_method_info_list_cached_users_OUT_ARG_pointers,

 gio/gdbus-2.0/codegen/codegen.py | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)
---
diff --git a/gio/gdbus-2.0/codegen/codegen.py b/gio/gdbus-2.0/codegen/codegen.py
index e74131cdb..0d95cdcda 100644
--- a/gio/gdbus-2.0/codegen/codegen.py
+++ b/gio/gdbus-2.0/codegen/codegen.py
@@ -1129,10 +1129,10 @@ class CodeGenerator:
                                '\n')
 
         if len(args) > 0:
-            self.outfile.write('static const _ExtendedGDBusArgInfo * const %s_pointers[] =\n'
+            self.outfile.write('static const GDBusArgInfo * const %s_pointers[] =\n'
                              '{\n'%(prefix))
             for a in args:
-                self.outfile.write('  &%s_%s,\n'%(prefix, a.name))
+                self.outfile.write('  &%s_%s.parent_struct,\n'%(prefix, a.name))
             self.outfile.write('  NULL\n'
                                '};\n'
                                '\n')
@@ -1175,10 +1175,10 @@ class CodeGenerator:
                     self.outfile.write('};\n'
                                        '\n')
 
-                self.outfile.write('static const _ExtendedGDBusMethodInfo * const _%s_method_info_pointers[] 
=\n'
+                self.outfile.write('static const GDBusMethodInfo * const _%s_method_info_pointers[] =\n'
                                    '{\n'%(i.name_lower))
                 for m in i.methods:
-                    self.outfile.write('  &_%s_method_info_%s,\n'%(i.name_lower, m.name_lower))
+                    self.outfile.write('  &_%s_method_info_%s.parent_struct,\n'%(i.name_lower, m.name_lower))
                 self.outfile.write('  NULL\n'
                                    '};\n'
                                    '\n')
@@ -1209,10 +1209,10 @@ class CodeGenerator:
                     self.outfile.write('};\n'
                                        '\n')
 
-                self.outfile.write('static const _ExtendedGDBusSignalInfo * const _%s_signal_info_pointers[] 
=\n'
+                self.outfile.write('static const GDBusSignalInfo * const _%s_signal_info_pointers[] =\n'
                                    '{\n'%(i.name_lower))
                 for s in i.signals:
-                    self.outfile.write('  &_%s_signal_info_%s,\n'%(i.name_lower, s.name_lower))
+                    self.outfile.write('  &_%s_signal_info_%s.parent_struct,\n'%(i.name_lower, s.name_lower))
                 self.outfile.write('  NULL\n'
                                    '};\n'
                                    '\n')
@@ -1251,10 +1251,10 @@ class CodeGenerator:
                     self.outfile.write('};\n'
                                        '\n')
 
-                self.outfile.write('static const _ExtendedGDBusPropertyInfo * const 
_%s_property_info_pointers[] =\n'
+                self.outfile.write('static const GDBusPropertyInfo * const _%s_property_info_pointers[] =\n'
                                    '{\n'%(i.name_lower))
                 for p in i.properties:
-                    self.outfile.write('  &_%s_property_info_%s,\n'%(i.name_lower, p.name_lower))
+                    self.outfile.write('  &_%s_property_info_%s.parent_struct,\n'%(i.name_lower, 
p.name_lower))
                 self.outfile.write('  NULL\n'
                                    '};\n'
                                    '\n')
@@ -1948,7 +1948,7 @@ class CodeGenerator:
             self.outfile.write('  const _ExtendedGDBusPropertyInfo *info;\n'
                                '  GVariant *variant;\n'
                                '  g_assert (prop_id != 0 && prop_id - 1 < %d);\n'
-                               '  info = _%s_property_info_pointers[prop_id - 1];\n'
+                               '  info = (const _ExtendedGDBusPropertyInfo *) 
_%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'
                                '    {\n'
@@ -2001,7 +2001,7 @@ class CodeGenerator:
             self.outfile.write('  const _ExtendedGDBusPropertyInfo *info;\n'
                                '  GVariant *variant;\n'
                                '  g_assert (prop_id != 0 && prop_id - 1 < %d);\n'
-                               '  info = _%s_property_info_pointers[prop_id - 1];\n'
+                               '  info = (const _ExtendedGDBusPropertyInfo *) 
_%s_property_info_pointers[prop_id - 1];\n'
                                '  variant = g_dbus_gvalue_to_gvariant (value, G_VARIANT_TYPE 
(info->parent_struct.signature));\n'
                                '  g_dbus_proxy_call (G_DBUS_PROXY (object),\n'
                                '    "org.freedesktop.DBus.Properties.Set",\n'
@@ -2887,7 +2887,7 @@ class CodeGenerator:
                                '  if (!_g_value_equal (value, &skeleton->priv->properties[prop_id - 1]))\n'
                                '    {\n'
                                '      if (g_dbus_interface_skeleton_get_connection 
(G_DBUS_INTERFACE_SKELETON (skeleton)) != NULL)\n'
-                               '        _%s_schedule_emit_changed (skeleton, 
_%s_property_info_pointers[prop_id - 1], prop_id, &skeleton->priv->properties[prop_id - 1]);\n'
+                               '        _%s_schedule_emit_changed (skeleton, (const 
_ExtendedGDBusPropertyInfo *) _%s_property_info_pointers[prop_id - 1], prop_id, 
&skeleton->priv->properties[prop_id - 1]);\n'
                                '      g_value_copy (value, &skeleton->priv->properties[prop_id - 1]);\n'
                                '      g_object_notify_by_pspec (object, pspec);\n'
                                '    }\n'


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