[gjs] Fix strict aliasing errors. (Type-punned pointer warnings.)
- From: C. Scott Ananian <cananian src gnome org>
- To: svn-commits-list gnome org
- Subject: [gjs] Fix strict aliasing errors. (Type-punned pointer warnings.)
- Date: Thu, 4 Jun 2009 14:01:07 -0400 (EDT)
commit 64cb8f2dfe00004433b210e5ba0d8c9e0e95775a
Author: C. Scott Ananian <cscott litl com>
Date: Wed Jun 3 18:29:29 2009 -0400
Fix strict aliasing errors. (Type-punned pointer warnings.)
http://bugzilla.gnome.org/show_bug.cgi?id=584849
---
gjsdbus/dbus-signals.c | 19 ++++++++++++++-----
gjsdbus/dbus.c | 9 ++++++---
2 files changed, 20 insertions(+), 8 deletions(-)
diff --git a/gjsdbus/dbus-signals.c b/gjsdbus/dbus-signals.c
index cbe2e15..bdb58bc 100644
--- a/gjsdbus/dbus-signals.c
+++ b/gjsdbus/dbus-signals.c
@@ -162,10 +162,15 @@ signal_watcher_table_add(GHashTable **table_p,
g_free,
signal_watcher_list_free);
} else {
- if (!g_hash_table_lookup_extended(*table_p,
+ gpointer k, v;
+ if (g_hash_table_lookup_extended(*table_p,
key,
- (gpointer*)&original_key,
- (gpointer*)&list)) {
+ &k, &v)) {
+ // do this assignment as separate step so as to avoid
+ // passing a type-punned pointer into g_hash_table_lookup_extended
+ original_key = (char *) k;
+ list = (GSList *) v;
+ } else {
original_key = g_strdup(key);
list = NULL;
}
@@ -186,16 +191,20 @@ signal_watcher_table_remove(GHashTable *table,
GSList *list;
GSList *l;
char *original_key;
+ gpointer k, v;
if (table == NULL)
return; /* Never lazily-created the table, nothing ever added */
if (!g_hash_table_lookup_extended(table,
key,
- (gpointer*)&original_key,
- (gpointer*)&list)) {
+ &k, &v)) {
return;
}
+ // do this assignment as separate step so as to avoid
+ // passing a type-punned pointer into g_hash_table_lookup_extended
+ original_key = (char *) k;
+ list = (GSList *) v;
l = g_slist_find(list, watcher);
if (!l)
diff --git a/gjsdbus/dbus.c b/gjsdbus/dbus.c
index 0651f22..43bf0ad 100644
--- a/gjsdbus/dbus.c
+++ b/gjsdbus/dbus.c
@@ -1608,7 +1608,10 @@ gjs_dbus_unregister_json(DBusConnection *connection,
typedef struct {
DBusConnection *connection;
- GObject *gobj;
+ /* strict aliasing rules require us to relate the 'gobj' field to a
+ * void * type here, in order to be able to pass it to
+ * g_object_*_weak_pointer (which takes a void **) */
+ union { GObject *gobj; void *weak_ptr; };
char *iface_name;
} GjsDBusGObject;
@@ -1621,7 +1624,7 @@ gobj_path_unregistered(DBusConnection *connection,
g = user_data;
if (g->gobj) {
- g_object_remove_weak_pointer(g->gobj, (void**) &g->gobj);
+ g_object_remove_weak_pointer(g->gobj, &g->weak_ptr /* aka, gobj */);
g->gobj = NULL;
}
@@ -1802,7 +1805,7 @@ gjs_dbus_register_g_object(DBusConnection *connection,
g_warning("Failed to register object path %s", path);
}
- g_object_add_weak_pointer(g->gobj, (void**) &g->gobj);
+ g_object_add_weak_pointer(g->gobj, &g->weak_ptr /* aka, gobj */);
}
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]