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
3ad375a629, 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
This commit is contained in:
Philip Withnall
2019-09-21 10:45:36 +02:00
parent 3ad375a629
commit 55f9c6d2f4
8 changed files with 25 additions and 25 deletions

View File

@@ -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;