Merge branch '1565-atomic-signs' into 'master'

Fix sign conversion warnings with g_atomic_int_*() calls in GLib

Closes #1565

See merge request GNOME/glib!1121
This commit is contained in:
Nirbheek Chauhan 2019-09-23 14:20:58 +00:00
commit 1f8d3451a4
8 changed files with 71 additions and 71 deletions

View File

@ -3148,7 +3148,7 @@ g_dbus_connection_add_filter (GDBusConnection *connection,
CONNECTION_LOCK (connection); CONNECTION_LOCK (connection);
data = g_new0 (FilterData, 1); 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->ref_count = 1;
data->filter_function = filter_function; data->filter_function = filter_function;
data->user_data = user_data; data->user_data = user_data;
@ -3508,7 +3508,7 @@ g_dbus_connection_signal_subscribe (GDBusConnection *connection,
subscriber.callback = callback; subscriber.callback = callback;
subscriber.user_data = user_data; subscriber.user_data = user_data;
subscriber.user_data_free_func = user_data_free_func; 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 (); subscriber.context = g_main_context_ref_thread_default ();
/* see if we've already have this rule */ /* 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 = 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->eo = eo;
ei->user_data = user_data; ei->user_data = user_data;
ei->user_data_free_func = user_data_free_func; 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->vtable = _g_dbus_subtree_vtable_copy (vtable);
es->flags = flags; 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 = user_data;
es->user_data_free_func = user_data_free_func; es->user_data_free_func = user_data_free_func;
es->context = g_main_context_ref_thread_default (); es->context = g_main_context_ref_thread_default ();

View File

@ -603,7 +603,7 @@ g_bus_watch_name (GBusType bus_type,
client = g_new0 (Client, 1); client = g_new0 (Client, 1);
client->ref_count = 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->name = g_strdup (name);
client->flags = flags; client->flags = flags;
client->name_appeared_handler = name_appeared_handler; 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 = g_new0 (Client, 1);
client->ref_count = 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->name = g_strdup (name);
client->flags = flags; client->flags = flags;
client->name_appeared_handler = name_appeared_handler; client->name_appeared_handler = name_appeared_handler;

View File

@ -512,7 +512,7 @@ test_threaded_singleton (void)
/* We want to be the last ref, so let it finish setting up */ /* We want to be the last ref, so let it finish setting up */
for (j = 0; j < 100; j++) 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) if (r == 1)
break; break;

View File

@ -224,7 +224,7 @@ g_bit_lock (volatile gint *address,
guint mask = 1u << lock_bit; guint mask = 1u << lock_bit;
guint v; guint v;
v = g_atomic_int_get (address); v = (guint) g_atomic_int_get (address);
if (v & mask) if (v & mask)
{ {
guint class = ((gsize) address) % G_N_ELEMENTS (g_bit_lock_contended); guint class = ((gsize) address) % G_N_ELEMENTS (g_bit_lock_contended);

View File

@ -273,7 +273,7 @@ g_quark_to_string (GQuark quark)
gchar **strings; gchar **strings;
guint seq_id; guint seq_id;
seq_id = g_atomic_int_get (&quark_seq_id); seq_id = (guint) g_atomic_int_get (&quark_seq_id);
strings = g_atomic_pointer_get (&quarks); strings = g_atomic_pointer_get (&quarks);
if (quark < seq_id) if (quark < seq_id)

View File

@ -1416,7 +1416,7 @@ void
g_cond_wait (GCond *cond, g_cond_wait (GCond *cond,
GMutex *mutex) GMutex *mutex)
{ {
guint sampled = g_atomic_int_get (&cond->i[0]); guint sampled = (guint) g_atomic_int_get (&cond->i[0]);
g_mutex_unlock (mutex); g_mutex_unlock (mutex);
syscall (__NR_futex, &cond->i[0], (gsize) FUTEX_WAIT_PRIVATE, (gsize) sampled, NULL); syscall (__NR_futex, &cond->i[0], (gsize) FUTEX_WAIT_PRIVATE, (gsize) sampled, NULL);

View File

@ -146,7 +146,7 @@ g_thread_pool_wait_for_new_pool (void)
gint last_wakeup_thread_serial; gint last_wakeup_thread_serial;
gboolean have_relayed_thread_marker = FALSE; gboolean have_relayed_thread_marker = FALSE;
local_max_unused_threads = g_atomic_int_get (&max_unused_threads); local_max_unused_threads = (guint) g_atomic_int_get (&max_unused_threads);
local_max_idle_time = g_atomic_int_get (&max_idle_time); local_max_idle_time = g_atomic_int_get (&max_idle_time);
last_wakeup_thread_serial = g_atomic_int_get (&wakeup_thread_serial); last_wakeup_thread_serial = g_atomic_int_get (&wakeup_thread_serial);
@ -210,7 +210,7 @@ g_thread_pool_wait_for_new_pool (void)
DEBUG_MSG (("thread %p updating to new limits.", DEBUG_MSG (("thread %p updating to new limits.",
g_thread_self ())); g_thread_self ()));
local_max_unused_threads = g_atomic_int_get (&max_unused_threads); local_max_unused_threads = (guint) g_atomic_int_get (&max_unused_threads);
local_max_idle_time = g_atomic_int_get (&max_idle_time); local_max_idle_time = g_atomic_int_get (&max_idle_time);
last_wakeup_thread_serial = local_wakeup_thread_serial; last_wakeup_thread_serial = local_wakeup_thread_serial;
@ -899,7 +899,7 @@ g_thread_pool_get_max_unused_threads (void)
guint guint
g_thread_pool_get_num_unused_threads (void) g_thread_pool_get_num_unused_threads (void)
{ {
return g_atomic_int_get (&unused_threads); return (guint) g_atomic_int_get (&unused_threads);
} }
/** /**
@ -1022,7 +1022,7 @@ g_thread_pool_set_max_idle_time (guint interval)
g_atomic_int_set (&max_idle_time, interval); g_atomic_int_set (&max_idle_time, interval);
i = g_atomic_int_get (&unused_threads); i = (guint) g_atomic_int_get (&unused_threads);
if (i > 0) if (i > 0)
{ {
g_atomic_int_inc (&wakeup_thread_serial); g_atomic_int_inc (&wakeup_thread_serial);
@ -1058,5 +1058,5 @@ g_thread_pool_set_max_idle_time (guint interval)
guint guint
g_thread_pool_get_max_idle_time (void) g_thread_pool_get_max_idle_time (void)
{ {
return g_atomic_int_get (&max_idle_time); return (guint) g_atomic_int_get (&max_idle_time);
} }

View File

@ -32,17 +32,17 @@ test_types (void)
cspp = &csp; cspp = &csp;
g_atomic_int_set (&u, 5); g_atomic_int_set (&u, 5);
u2 = g_atomic_int_get (&u); u2 = (guint) g_atomic_int_get (&u);
g_assert_cmpint (u2, ==, 5); g_assert_cmpint (u2, ==, 5);
res = g_atomic_int_compare_and_exchange (&u, 6, 7); res = g_atomic_int_compare_and_exchange (&u, 6, 7);
g_assert (!res); g_assert_false (res);
g_assert_cmpint (u, ==, 5); g_assert_cmpint (u, ==, 5);
g_atomic_int_add (&u, 1); g_atomic_int_add (&u, 1);
g_assert_cmpint (u, ==, 6); g_assert_cmpint (u, ==, 6);
g_atomic_int_inc (&u); g_atomic_int_inc (&u);
g_assert_cmpint (u, ==, 7); g_assert_cmpint (u, ==, 7);
res = g_atomic_int_dec_and_test (&u); res = g_atomic_int_dec_and_test (&u);
g_assert (!res); g_assert_false (res);
g_assert_cmpint (u, ==, 6); g_assert_cmpint (u, ==, 6);
u2 = g_atomic_int_and (&u, 5); u2 = g_atomic_int_and (&u, 5);
g_assert_cmpint (u2, ==, 6); g_assert_cmpint (u2, ==, 6);
@ -58,61 +58,61 @@ test_types (void)
s2 = g_atomic_int_get (&s); s2 = g_atomic_int_get (&s);
g_assert_cmpint (s2, ==, 5); g_assert_cmpint (s2, ==, 5);
res = g_atomic_int_compare_and_exchange (&s, 6, 7); res = g_atomic_int_compare_and_exchange (&s, 6, 7);
g_assert (!res); g_assert_false (res);
g_assert_cmpint (s, ==, 5); g_assert_cmpint (s, ==, 5);
g_atomic_int_add (&s, 1); g_atomic_int_add (&s, 1);
g_assert_cmpint (s, ==, 6); g_assert_cmpint (s, ==, 6);
g_atomic_int_inc (&s); g_atomic_int_inc (&s);
g_assert_cmpint (s, ==, 7); g_assert_cmpint (s, ==, 7);
res = g_atomic_int_dec_and_test (&s); res = g_atomic_int_dec_and_test (&s);
g_assert (!res); g_assert_false (res);
g_assert_cmpint (s, ==, 6); g_assert_cmpint (s, ==, 6);
s2 = g_atomic_int_and (&s, 5); s2 = (gint) g_atomic_int_and (&s, 5);
g_assert_cmpint (s2, ==, 6); g_assert_cmpint (s2, ==, 6);
g_assert_cmpint (s, ==, 4); g_assert_cmpint (s, ==, 4);
s2 = g_atomic_int_or (&s, 8); s2 = (gint) g_atomic_int_or (&s, 8);
g_assert_cmpint (s2, ==, 4); g_assert_cmpint (s2, ==, 4);
g_assert_cmpint (s, ==, 12); g_assert_cmpint (s, ==, 12);
s2 = g_atomic_int_xor (&s, 4); s2 = (gint) g_atomic_int_xor (&s, 4);
g_assert_cmpint (s2, ==, 12); g_assert_cmpint (s2, ==, 12);
g_assert_cmpint (s, ==, 8); g_assert_cmpint (s, ==, 8);
g_atomic_pointer_set (&vp, 0); g_atomic_pointer_set (&vp, 0);
vp2 = g_atomic_pointer_get (&vp); vp2 = g_atomic_pointer_get (&vp);
g_assert (vp2 == 0); g_assert_true (vp2 == 0);
res = g_atomic_pointer_compare_and_exchange (&vp, 0, 0); res = g_atomic_pointer_compare_and_exchange (&vp, 0, 0);
g_assert (res); g_assert_true (res);
g_assert (vp == 0); g_assert_true (vp == 0);
g_atomic_pointer_set (&ip, 0); g_atomic_pointer_set (&ip, 0);
ip2 = g_atomic_pointer_get (&ip); ip2 = g_atomic_pointer_get (&ip);
g_assert (ip2 == 0); g_assert_true (ip2 == 0);
res = g_atomic_pointer_compare_and_exchange (&ip, 0, 0); res = g_atomic_pointer_compare_and_exchange (&ip, 0, 0);
g_assert (res); g_assert_true (res);
g_assert (ip == 0); g_assert_true (ip == 0);
g_atomic_pointer_set (&gs, 0); g_atomic_pointer_set (&gs, 0);
vp2 = g_atomic_pointer_get (&gs); vp2 = g_atomic_pointer_get (&gs);
gs2 = (gsize) vp2; gs2 = (gsize) vp2;
g_assert (gs2 == 0); g_assert_cmpuint (gs2, ==, 0);
res = g_atomic_pointer_compare_and_exchange (&gs, 0, 0); res = g_atomic_pointer_compare_and_exchange (&gs, 0, 0);
g_assert (res); g_assert_true (res);
g_assert (gs == 0); g_assert_cmpuint (gs, ==, 0);
gs2 = g_atomic_pointer_add (&gs, 5); gs2 = (gsize) g_atomic_pointer_add (&gs, 5);
g_assert (gs2 == 0); g_assert_cmpuint (gs2, ==, 0);
g_assert (gs == 5); g_assert_cmpuint (gs, ==, 5);
gs2 = g_atomic_pointer_and (&gs, 6); gs2 = g_atomic_pointer_and (&gs, 6);
g_assert (gs2 == 5); g_assert_cmpuint (gs2, ==, 5);
g_assert (gs == 4); g_assert_cmpuint (gs, ==, 4);
gs2 = g_atomic_pointer_or (&gs, 8); gs2 = g_atomic_pointer_or (&gs, 8);
g_assert (gs2 == 4); g_assert_cmpuint (gs2, ==, 4);
g_assert (gs == 12); g_assert_cmpuint (gs, ==, 12);
gs2 = g_atomic_pointer_xor (&gs, 4); gs2 = g_atomic_pointer_xor (&gs, 4);
g_assert (gs2 == 12); g_assert_cmpuint (gs2, ==, 12);
g_assert (gs == 8); g_assert_cmpuint (gs, ==, 8);
g_assert (g_atomic_int_get (csp) == s); g_assert_cmpint (g_atomic_int_get (csp), ==, s);
g_assert (g_atomic_pointer_get (cspp) == csp); g_assert_true (g_atomic_pointer_get (cspp) == csp);
/* repeat, without the macros */ /* repeat, without the macros */
#undef g_atomic_int_set #undef g_atomic_int_set
@ -133,17 +133,17 @@ test_types (void)
#undef g_atomic_pointer_xor #undef g_atomic_pointer_xor
g_atomic_int_set ((gint*)&u, 5); g_atomic_int_set ((gint*)&u, 5);
u2 = g_atomic_int_get ((gint*)&u); u2 = (guint) g_atomic_int_get ((gint*)&u);
g_assert_cmpint (u2, ==, 5); g_assert_cmpint (u2, ==, 5);
res = g_atomic_int_compare_and_exchange ((gint*)&u, 6, 7); res = g_atomic_int_compare_and_exchange ((gint*)&u, 6, 7);
g_assert (!res); g_assert_false (res);
g_assert_cmpint (u, ==, 5); g_assert_cmpint (u, ==, 5);
g_atomic_int_add ((gint*)&u, 1); g_atomic_int_add ((gint*)&u, 1);
g_assert_cmpint (u, ==, 6); g_assert_cmpint (u, ==, 6);
g_atomic_int_inc ((gint*)&u); g_atomic_int_inc ((gint*)&u);
g_assert_cmpint (u, ==, 7); g_assert_cmpint (u, ==, 7);
res = g_atomic_int_dec_and_test ((gint*)&u); res = g_atomic_int_dec_and_test ((gint*)&u);
g_assert (!res); g_assert_false (res);
g_assert_cmpint (u, ==, 6); g_assert_cmpint (u, ==, 6);
u2 = g_atomic_int_and (&u, 5); u2 = g_atomic_int_and (&u, 5);
g_assert_cmpint (u2, ==, 6); g_assert_cmpint (u2, ==, 6);
@ -158,22 +158,22 @@ test_types (void)
s2 = g_atomic_int_get (&s); s2 = g_atomic_int_get (&s);
g_assert_cmpint (s2, ==, 5); g_assert_cmpint (s2, ==, 5);
res = g_atomic_int_compare_and_exchange (&s, 6, 7); res = g_atomic_int_compare_and_exchange (&s, 6, 7);
g_assert (!res); g_assert_false (res);
g_assert_cmpint (s, ==, 5); g_assert_cmpint (s, ==, 5);
g_atomic_int_add (&s, 1); g_atomic_int_add (&s, 1);
g_assert_cmpint (s, ==, 6); g_assert_cmpint (s, ==, 6);
g_atomic_int_inc (&s); g_atomic_int_inc (&s);
g_assert_cmpint (s, ==, 7); g_assert_cmpint (s, ==, 7);
res = g_atomic_int_dec_and_test (&s); res = g_atomic_int_dec_and_test (&s);
g_assert (!res); g_assert_false (res);
g_assert_cmpint (s, ==, 6); g_assert_cmpint (s, ==, 6);
s2 = g_atomic_int_and ((guint*)&s, 5); s2 = (gint) g_atomic_int_and ((guint*)&s, 5);
g_assert_cmpint (s2, ==, 6); g_assert_cmpint (s2, ==, 6);
g_assert_cmpint (s, ==, 4); g_assert_cmpint (s, ==, 4);
s2 = g_atomic_int_or ((guint*)&s, 8); s2 = (gint) g_atomic_int_or ((guint*)&s, 8);
g_assert_cmpint (s2, ==, 4); g_assert_cmpint (s2, ==, 4);
g_assert_cmpint (s, ==, 12); g_assert_cmpint (s, ==, 12);
s2 = g_atomic_int_xor ((guint*)&s, 4); s2 = (gint) g_atomic_int_xor ((guint*)&s, 4);
g_assert_cmpint (s2, ==, 12); g_assert_cmpint (s2, ==, 12);
g_assert_cmpint (s, ==, 8); g_assert_cmpint (s, ==, 8);
G_GNUC_BEGIN_IGNORE_DEPRECATIONS G_GNUC_BEGIN_IGNORE_DEPRECATIONS
@ -184,40 +184,40 @@ G_GNUC_END_IGNORE_DEPRECATIONS
g_atomic_pointer_set (&vp, 0); g_atomic_pointer_set (&vp, 0);
vp2 = g_atomic_pointer_get (&vp); vp2 = g_atomic_pointer_get (&vp);
g_assert (vp2 == 0); g_assert_true (vp2 == 0);
res = g_atomic_pointer_compare_and_exchange (&vp, 0, 0); res = g_atomic_pointer_compare_and_exchange (&vp, 0, 0);
g_assert (res); g_assert_true (res);
g_assert (vp == 0); g_assert_true (vp == 0);
g_atomic_pointer_set (&ip, 0); g_atomic_pointer_set (&ip, 0);
ip2 = g_atomic_pointer_get (&ip); ip2 = g_atomic_pointer_get (&ip);
g_assert (ip2 == 0); g_assert_true (ip2 == 0);
res = g_atomic_pointer_compare_and_exchange (&ip, 0, 0); res = g_atomic_pointer_compare_and_exchange (&ip, 0, 0);
g_assert (res); g_assert_true (res);
g_assert (ip == 0); g_assert_true (ip == 0);
g_atomic_pointer_set (&gs, 0); g_atomic_pointer_set (&gs, 0);
vp = g_atomic_pointer_get (&gs); vp = g_atomic_pointer_get (&gs);
gs2 = (gsize) vp; gs2 = (gsize) vp;
g_assert (gs2 == 0); g_assert_cmpuint (gs2, ==, 0);
res = g_atomic_pointer_compare_and_exchange (&gs, 0, 0); res = g_atomic_pointer_compare_and_exchange (&gs, 0, 0);
g_assert (res); g_assert_true (res);
g_assert (gs == 0); g_assert_cmpuint (gs, ==, 0);
gs2 = g_atomic_pointer_add (&gs, 5); gs2 = (gsize) g_atomic_pointer_add (&gs, 5);
g_assert (gs2 == 0); g_assert_cmpuint (gs2, ==, 0);
g_assert (gs == 5); g_assert_cmpuint (gs, ==, 5);
gs2 = g_atomic_pointer_and (&gs, 6); gs2 = g_atomic_pointer_and (&gs, 6);
g_assert (gs2 == 5); g_assert_cmpuint (gs2, ==, 5);
g_assert (gs == 4); g_assert_cmpuint (gs, ==, 4);
gs2 = g_atomic_pointer_or (&gs, 8); gs2 = g_atomic_pointer_or (&gs, 8);
g_assert (gs2 == 4); g_assert_cmpuint (gs2, ==, 4);
g_assert (gs == 12); g_assert_cmpuint (gs, ==, 12);
gs2 = g_atomic_pointer_xor (&gs, 4); gs2 = g_atomic_pointer_xor (&gs, 4);
g_assert (gs2 == 12); g_assert_cmpuint (gs2, ==, 12);
g_assert (gs == 8); g_assert_cmpuint (gs, ==, 8);
g_assert (g_atomic_int_get (csp) == s); g_assert_cmpint (g_atomic_int_get (csp), ==, s);
g_assert (g_atomic_pointer_get (cspp) == csp); g_assert_true (g_atomic_pointer_get (cspp) == csp);
} }
#define THREADS 10 #define THREADS 10