diff options
author | Philip Withnall <withnall@endlessm.com> | 2019-09-21 10:45:36 +0200 |
---|---|---|
committer | Philip Withnall <withnall@endlessm.com> | 2019-09-21 10:48:23 +0200 |
commit | 55f9c6d2f422a12ecc84ada71dc3a596329b40e3 (patch) | |
tree | f9e7d672a48a27b1aed90076ca4e25929866bae7 /gio | |
parent | 3ad375a629c91a27d0165a31f0ed298fd553de0a (diff) | |
download | glib-55f9c6d2f422a12ecc84ada71dc3a596329b40e3.tar.gz |
gatomic: Add various casts to use of g_atomic_*()s to fix warnings
When compiling GLib with `-Wsign-conversion`, we get various warnings
about the atomic calls. A lot of these were fixed by
3ad375a629c91a27d0165a31f0ed298fd553de0a, but some remain. Fix them by
adding appropriate casts at the call sites.
Note that `g_atomic_int_{and,or,xor}()` actually all operate on `guint`s
rather than `gint`s (which is what the rest of the `g_atomic_int_*()`
functions operate on). I can’t find any written reasoning for this, but
assume that it’s because signedness is irrelevant when you’re using an
integer as a bit field. It’s unfortunate that they’re named a
`g_atomic_int_*()` rather than `g_atomic_uint_*()` functions.
Tested by compiling GLib as:
```
CFLAGS=-Wsign-conversion jhbuild make -ac |& grep atomic
```
I’m not going to add `-Wsign-conversion` to the set of default warnings
for building GLib, because it mostly produces false positives throughout
the rest of GLib.
Signed-off-by: Philip Withnall <withnall@endlessm.com>
Fixes: #1565
Diffstat (limited to 'gio')
-rw-r--r-- | gio/gdbusconnection.c | 8 | ||||
-rw-r--r-- | gio/gdbusnamewatching.c | 4 | ||||
-rw-r--r-- | gio/tests/gdbus-threading.c | 2 |
3 files changed, 7 insertions, 7 deletions
diff --git a/gio/gdbusconnection.c b/gio/gdbusconnection.c index f1f0921d4..3411033f3 100644 --- a/gio/gdbusconnection.c +++ b/gio/gdbusconnection.c @@ -3148,7 +3148,7 @@ g_dbus_connection_add_filter (GDBusConnection *connection, CONNECTION_LOCK (connection); data = g_new0 (FilterData, 1); - data->id = g_atomic_int_add (&_global_filter_id, 1); /* TODO: overflow etc. */ + data->id = (guint) g_atomic_int_add (&_global_filter_id, 1); /* TODO: overflow etc. */ data->ref_count = 1; data->filter_function = filter_function; data->user_data = user_data; @@ -3508,7 +3508,7 @@ g_dbus_connection_signal_subscribe (GDBusConnection *connection, subscriber.callback = callback; subscriber.user_data = user_data; subscriber.user_data_free_func = user_data_free_func; - subscriber.id = g_atomic_int_add (&_global_subscriber_id, 1); /* TODO: overflow etc. */ + subscriber.id = (guint) g_atomic_int_add (&_global_subscriber_id, 1); /* TODO: overflow etc. */ subscriber.context = g_main_context_ref_thread_default (); /* see if we've already have this rule */ @@ -5198,7 +5198,7 @@ g_dbus_connection_register_object (GDBusConnection *connection, } ei = g_new0 (ExportedInterface, 1); - ei->id = g_atomic_int_add (&_global_registration_id, 1); /* TODO: overflow etc. */ + ei->id = (guint) g_atomic_int_add (&_global_registration_id, 1); /* TODO: overflow etc. */ ei->eo = eo; ei->user_data = user_data; ei->user_data_free_func = user_data_free_func; @@ -6858,7 +6858,7 @@ g_dbus_connection_register_subtree (GDBusConnection *connection, es->vtable = _g_dbus_subtree_vtable_copy (vtable); es->flags = flags; - es->id = g_atomic_int_add (&_global_subtree_registration_id, 1); /* TODO: overflow etc. */ + es->id = (guint) g_atomic_int_add (&_global_subtree_registration_id, 1); /* TODO: overflow etc. */ es->user_data = user_data; es->user_data_free_func = user_data_free_func; es->context = g_main_context_ref_thread_default (); diff --git a/gio/gdbusnamewatching.c b/gio/gdbusnamewatching.c index 3a97c50ee..f74952a19 100644 --- a/gio/gdbusnamewatching.c +++ b/gio/gdbusnamewatching.c @@ -603,7 +603,7 @@ g_bus_watch_name (GBusType bus_type, client = g_new0 (Client, 1); client->ref_count = 1; - client->id = g_atomic_int_add (&next_global_id, 1); /* TODO: uh oh, handle overflow */ + client->id = (guint) g_atomic_int_add (&next_global_id, 1); /* TODO: uh oh, handle overflow */ client->name = g_strdup (name); client->flags = flags; client->name_appeared_handler = name_appeared_handler; @@ -665,7 +665,7 @@ guint g_bus_watch_name_on_connection (GDBusConnection *connection, client = g_new0 (Client, 1); client->ref_count = 1; - client->id = g_atomic_int_add (&next_global_id, 1); /* TODO: uh oh, handle overflow */ + client->id = (guint) g_atomic_int_add (&next_global_id, 1); /* TODO: uh oh, handle overflow */ client->name = g_strdup (name); client->flags = flags; client->name_appeared_handler = name_appeared_handler; diff --git a/gio/tests/gdbus-threading.c b/gio/tests/gdbus-threading.c index ffca6f317..dd20530ff 100644 --- a/gio/tests/gdbus-threading.c +++ b/gio/tests/gdbus-threading.c @@ -512,7 +512,7 @@ test_threaded_singleton (void) /* We want to be the last ref, so let it finish setting up */ for (j = 0; j < 100; j++) { - guint r = g_atomic_int_get (&G_OBJECT (c)->ref_count); + guint r = (guint) g_atomic_int_get (&G_OBJECT (c)->ref_count); if (r == 1) break; |