From b6937c9b326d4159fa3d47f9caec7bea3ae1cdb7 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Fri, 11 Apr 2025 14:44:21 +0100 Subject: [PATCH 01/16] tests: Remove unnecessary prefix from GString test names Signed-off-by: Philip Withnall --- glib/tests/string.c | 46 ++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/glib/tests/string.c b/glib/tests/string.c index 6023bc43d..ed7179eb3 100644 --- a/glib/tests/string.c +++ b/glib/tests/string.c @@ -773,29 +773,29 @@ main (int argc, { g_test_init (&argc, &argv, NULL); - g_test_add_func ("/string/test-string-chunks", test_string_chunks); - g_test_add_func ("/string/test-string-chunk-insert", test_string_chunk_insert); - g_test_add_func ("/string/test-string-new", test_string_new); - g_test_add_func ("/string/test-string-printf", test_string_printf); - g_test_add_func ("/string/test-string-assign", test_string_assign); - g_test_add_func ("/string/test-string-append-c", test_string_append_c); - g_test_add_func ("/string/test-string-append", test_string_append); - g_test_add_func ("/string/test-string-append-vprintf", test_string_append_vprintf); - g_test_add_func ("/string/test-string-prepend-c", test_string_prepend_c); - g_test_add_func ("/string/test-string-prepend", test_string_prepend); - g_test_add_func ("/string/test-string-insert", test_string_insert); - g_test_add_func ("/string/test-string-insert-unichar", test_string_insert_unichar); - g_test_add_func ("/string/test-string-equal", test_string_equal); - g_test_add_func ("/string/test-string-truncate", test_string_truncate); - g_test_add_func ("/string/test-string-overwrite", test_string_overwrite); - g_test_add_func ("/string/test-string-nul-handling", test_string_nul_handling); - g_test_add_func ("/string/test-string-up-down", test_string_up_down); - g_test_add_func ("/string/test-string-set-size", test_string_set_size); - g_test_add_func ("/string/test-string-to-bytes", test_string_to_bytes); - g_test_add_func ("/string/test-string-replace", test_string_replace); - g_test_add_func ("/string/test-string-steal", test_string_steal); - g_test_add_func ("/string/test-string-new-take", test_string_new_take); - g_test_add_func ("/string/test-string-new-take/null", test_string_new_take_null); + g_test_add_func ("/string/chunks", test_string_chunks); + g_test_add_func ("/string/chunk-insert", test_string_chunk_insert); + g_test_add_func ("/string/new", test_string_new); + g_test_add_func ("/string/printf", test_string_printf); + g_test_add_func ("/string/assign", test_string_assign); + g_test_add_func ("/string/append-c", test_string_append_c); + g_test_add_func ("/string/append", test_string_append); + g_test_add_func ("/string/append-vprintf", test_string_append_vprintf); + g_test_add_func ("/string/prepend-c", test_string_prepend_c); + g_test_add_func ("/string/prepend", test_string_prepend); + g_test_add_func ("/string/insert", test_string_insert); + g_test_add_func ("/string/insert-unichar", test_string_insert_unichar); + g_test_add_func ("/string/equal", test_string_equal); + g_test_add_func ("/string/truncate", test_string_truncate); + g_test_add_func ("/string/overwrite", test_string_overwrite); + g_test_add_func ("/string/nul-handling", test_string_nul_handling); + g_test_add_func ("/string/up-down", test_string_up_down); + g_test_add_func ("/string/set-size", test_string_set_size); + g_test_add_func ("/string/to-bytes", test_string_to_bytes); + g_test_add_func ("/string/replace", test_string_replace); + g_test_add_func ("/string/steal", test_string_steal); + g_test_add_func ("/string/new-take", test_string_new_take); + g_test_add_func ("/string/new-take/null", test_string_new_take_null); return g_test_run(); } From 3048266aa30a5bef8e2e89a312f441c189f47b4c Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Fri, 11 Apr 2025 14:55:59 +0100 Subject: [PATCH 02/16] gstring: Add a new g_string_copy() method This does a deep copy on the `GString`. It means we can eliminate the less-efficient version currently used for `GBoxed`, which also has `-Wsign-conversion` problems. See the following commit. Signed-off-by: Philip Withnall Helps: #3405 --- glib/gstring.c | 32 ++++++++++++++++++++++++++++++++ glib/gstring.h | 2 ++ glib/tests/string.c | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+) diff --git a/glib/gstring.c b/glib/gstring.c index 2a399ee21..645746c9a 100644 --- a/glib/gstring.c +++ b/glib/gstring.c @@ -214,6 +214,38 @@ g_string_new_len (const gchar *init, } } +/** + * g_string_copy: + * @string: a string + * + * Copies the [struct@GLib.String] instance and its contents. + * + * This will preserve the allocation length of the [struct@GLib.String] in the + * copy. + * + * Returns: (transfer full): a copy of @string + * Since: 2.86 + */ +GString * +g_string_copy (GString *string) +{ + GString *copy = NULL; + + g_return_val_if_fail (string != NULL, NULL); + + copy = g_slice_new (GString); + copy->allocated_len = string->allocated_len; + copy->len = string->len; + + /* We can’t just strdup(string->str) here because it may contain embedded nuls. */ + copy->str = g_malloc (string->allocated_len); + if (string->str != NULL && string->len > 0) + memcpy (copy->str, string->str, string->len); + copy->str[copy->len] = '\0'; + + return g_steal_pointer (©); +} + /** * g_string_free: * @string: (transfer full): a #GString diff --git a/glib/gstring.h b/glib/gstring.h index 3e66367a0..e817176c9 100644 --- a/glib/gstring.h +++ b/glib/gstring.h @@ -58,6 +58,8 @@ GString* g_string_new_len (const gchar *init, gssize len); GLIB_AVAILABLE_IN_ALL GString* g_string_sized_new (gsize dfl_size); +GLIB_AVAILABLE_IN_2_86 +GString *g_string_copy (GString *string); GLIB_AVAILABLE_IN_ALL gchar* (g_string_free) (GString *string, gboolean free_segment); diff --git a/glib/tests/string.c b/glib/tests/string.c index ed7179eb3..fc9d8458a 100644 --- a/glib/tests/string.c +++ b/glib/tests/string.c @@ -767,6 +767,40 @@ test_string_new_take_null (void) g_string_free (g_steal_pointer (&string), TRUE); } +static void +test_string_copy (void) +{ + GString *string1 = NULL, *string2 = NULL; + + string1 = g_string_new ("hello"); + string2 = g_string_copy (string1); + g_assert_cmpstr (string1->str, ==, string2->str); + g_assert_true (string1->str != string2->str); + g_assert_cmpuint (string1->len, ==, string2->len); + g_assert_cmpuint (string2->allocated_len, ==, string2->allocated_len); + g_string_free (string1, TRUE); + g_string_free (string2, TRUE); + + string1 = g_string_sized_new (100); + string2 = g_string_copy (string1); + g_assert_cmpstr (string1->str, ==, string2->str); + g_assert_true (string1->str != string2->str); + g_assert_cmpuint (string1->len, ==, string2->len); + g_assert_cmpuint (string2->allocated_len, ==, string2->allocated_len); + g_string_free (string1, TRUE); + g_string_free (string2, TRUE); + + string1 = g_string_sized_new (200); + g_string_append_len (string1, "test with embedded\0nuls", 25); + string2 = g_string_copy (string1); + g_assert_cmpmem (string1->str, string1->len, string2->str, string2->len); + g_assert_true (string1->str != string2->str); + g_assert_cmpuint (string1->len, ==, string2->len); + g_assert_cmpuint (string2->allocated_len, ==, string2->allocated_len); + g_string_free (string1, TRUE); + g_string_free (string2, TRUE); +} + int main (int argc, char *argv[]) @@ -796,6 +830,7 @@ main (int argc, g_test_add_func ("/string/steal", test_string_steal); g_test_add_func ("/string/new-take", test_string_new_take); g_test_add_func ("/string/new-take/null", test_string_new_take_null); + g_test_add_func ("/string/copy", test_string_copy); return g_test_run(); } From b9d27192229fc9be3299a47f5ebd4a3163073a0c Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Fri, 11 Apr 2025 14:57:29 +0100 Subject: [PATCH 03/16] gboxed: Use new g_string_copy() as boxed copy for GString Rather than reinventing it ourselves. The old version in `gboxed.c` could lose the second half of very long strings, as it truncated the `size_t` string length to the `ssize_t` accepted by `g_string_new_len()`. Signed-off-by: Philip Withnall Helps: #3405 --- gobject/gboxed.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/gobject/gboxed.c b/gobject/gboxed.c index 04cededa0..fce661df2 100644 --- a/gobject/gboxed.c +++ b/gobject/gboxed.c @@ -96,12 +96,6 @@ _g_boxed_type_init (void) g_assert (type == G_TYPE_BOXED); } -static GString * -gstring_copy (GString *src_gstring) -{ - return g_string_new_len (src_gstring->str, src_gstring->len); -} - static void gstring_free (GString *gstring) { @@ -113,7 +107,7 @@ G_DEFINE_BOXED_TYPE (GValue, g_value, value_copy, value_free) G_DEFINE_BOXED_TYPE (GValueArray, g_value_array, g_value_array_copy, g_value_array_free) G_DEFINE_BOXED_TYPE (GDate, g_date, g_date_copy, g_date_free) /* the naming is a bit odd, but GString is obviously not G_TYPE_STRING */ -G_DEFINE_BOXED_TYPE (GString, g_gstring, gstring_copy, gstring_free) +G_DEFINE_BOXED_TYPE (GString, g_gstring, g_string_copy, gstring_free) G_DEFINE_BOXED_TYPE (GHashTable, g_hash_table, g_hash_table_ref, g_hash_table_unref) G_DEFINE_BOXED_TYPE (GArray, g_array, g_array_ref, g_array_unref) G_DEFINE_BOXED_TYPE (GPtrArray, g_ptr_array,g_ptr_array_ref, g_ptr_array_unref) From efed9028faf404b5c7752cfa1e9d4691a9f2b282 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Fri, 11 Apr 2025 15:01:27 +0100 Subject: [PATCH 04/16] gobject: Fix various straightforward -Wsign-conversion warnings None of these should have caused user-visible bugs. Signed-off-by: Philip Withnall Helps: #3405 --- gobject/gclosure.c | 31 ++++++++++++++++++------------- gobject/gparam.c | 12 ++++++------ gobject/gsourceclosure.c | 3 ++- gobject/gtype.c | 21 ++++++++++----------- gobject/gvaluearray.c | 3 ++- 5 files changed, 38 insertions(+), 32 deletions(-) diff --git a/gobject/gclosure.c b/gobject/gclosure.c index 9afcb76a5..1a1ce5e06 100644 --- a/gobject/gclosure.c +++ b/gobject/gclosure.c @@ -95,11 +95,11 @@ #define CLOSURE_MAX_N_GUARDS ((1 << 1) - 1) #define CLOSURE_MAX_N_FNOTIFIERS ((1 << 2) - 1) #define CLOSURE_MAX_N_INOTIFIERS ((1 << 8) - 1) -#define CLOSURE_N_MFUNCS(cl) (((cl)->n_guards << 1L)) +#define CLOSURE_N_MFUNCS(cl) ((size_t) ((cl)->n_guards << 1L)) /* same as G_CLOSURE_N_NOTIFIERS() (keep in sync) */ -#define CLOSURE_N_NOTIFIERS(cl) (CLOSURE_N_MFUNCS (cl) + \ +#define CLOSURE_N_NOTIFIERS(cl) ((size_t) (CLOSURE_N_MFUNCS (cl) + \ (cl)->n_fnotifiers + \ - (cl)->n_inotifiers) + (cl)->n_inotifiers)) /* A copy of the flags bitfield from the beginning of `struct _GClosure`, which * is in union with an int for atomic access to all fields at the same time. @@ -223,7 +223,7 @@ g_closure_new_simple (guint sizeof_closure, gpointer data) { GClosure *closure; - gint private_size; + size_t private_size; gchar *allocated; g_return_val_if_fail (sizeof_closure >= sizeof (GClosure), NULL); @@ -1316,7 +1316,7 @@ value_to_ffi_type (const GValue *gvalue, case G_TYPE_FLAGS: g_assert (enum_tmpval != NULL); rettype = &ffi_type_uint; - *enum_tmpval = g_value_get_flags (gvalue); + *enum_tmpval = (int) g_value_get_flags (gvalue); *value = enum_tmpval; *tmpval_used = TRUE; break; @@ -1560,10 +1560,10 @@ g_cclosure_marshal_generic (GClosure *closure, { ffi_type *rtype; void *rvalue; - int n_args; + size_t n_args; ffi_type **atypes; void **args; - int i; + size_t i; ffi_cif cif; GCClosure *cc = (GCClosure*) closure; gint *enum_tmpval; @@ -1659,17 +1659,22 @@ g_cclosure_marshal_generic_va (GClosure *closure, { ffi_type *rtype; void *rvalue; - int n_args; + size_t n_args; + size_t unsigned_n_params; ffi_type **atypes; void **args; va_arg_storage *storage; - int i; + size_t i; ffi_cif cif; GCClosure *cc = (GCClosure*) closure; gint *enum_tmpval; gboolean tmpval_used = FALSE; va_list args_copy; + g_return_if_fail (n_params >= 0); + + unsigned_n_params = (size_t) n_params; + enum_tmpval = g_alloca (sizeof (gint)); if (return_value && G_VALUE_TYPE (return_value)) { @@ -1682,10 +1687,10 @@ g_cclosure_marshal_generic_va (GClosure *closure, rvalue = g_alloca (MAX (rtype->size, sizeof (ffi_arg))); - n_args = n_params + 2; + n_args = unsigned_n_params + 2; atypes = g_alloca (sizeof (ffi_type *) * n_args); args = g_alloca (sizeof (gpointer) * n_args); - storage = g_alloca (sizeof (va_arg_storage) * n_params); + storage = g_alloca (sizeof (va_arg_storage) * unsigned_n_params); if (G_CCLOSURE_SWAP_DATA (closure)) { @@ -1705,7 +1710,7 @@ g_cclosure_marshal_generic_va (GClosure *closure, va_copy (args_copy, args_list); /* Box non-primitive arguments */ - for (i = 0; i < n_params; i++) + for (i = 0; i < unsigned_n_params; i++) { GType type = param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE; GType fundamental = G_TYPE_FUNDAMENTAL (type); @@ -1738,7 +1743,7 @@ g_cclosure_marshal_generic_va (GClosure *closure, ffi_call (&cif, marshal_data ? marshal_data : cc->callback, rvalue, args); /* Unbox non-primitive arguments */ - for (i = 0; i < n_params; i++) + for (i = 0; i < unsigned_n_params; i++) { GType type = param_types[i] & ~G_SIGNAL_TYPE_STATIC_SCOPE; GType fundamental = G_TYPE_FUNDAMENTAL (type); diff --git a/gobject/gparam.c b/gobject/gparam.c index 7ad8e76ae..71547f3a3 100644 --- a/gobject/gparam.c +++ b/gobject/gparam.c @@ -956,7 +956,7 @@ param_spec_pool_hash (gconstpointer key_spec) guint h = (guint) key->owner_type; for (p = key->name; *p; p++) - h = (h << 5) - h + *p; + h = (guint) (h << 5) - h + (guint) *p; return h; } @@ -1182,11 +1182,11 @@ g_param_spec_pool_lookup (GParamSpecPool *pool, /* strip type prefix */ if (delim && delim[1] == ':') { - guint l = delim - param_name; + size_t l = (size_t) (delim - param_name); gchar stack_buffer[32], *buffer = l < 32 ? stack_buffer : g_new (gchar, l + 1); GType type; - strncpy (buffer, param_name, delim - param_name); + strncpy (buffer, param_name, l); buffer[l] = 0; type = g_type_from_name (buffer); if (l >= 32) @@ -1311,7 +1311,7 @@ pool_depth_list (gpointer key, GSList **slists = data[0]; GType owner_type = (GType) data[1]; GHashTable *ht = data[2]; - int *count = data[3]; + unsigned int *count = data[3]; if (g_type_is_a (owner_type, pspec->owner_type) && should_list_pspec (pspec, owner_type, ht)) @@ -1350,7 +1350,7 @@ pool_depth_list_for_interface (gpointer key, GSList **slists = data[0]; GType owner_type = (GType) data[1]; GHashTable *ht = data[2]; - int *count = data[3]; + unsigned int *count = data[3]; if (pspec->owner_type == owner_type && should_list_pspec (pspec, owner_type, ht)) @@ -1382,7 +1382,7 @@ g_param_spec_pool_list (GParamSpecPool *pool, GSList **slists, *node; gpointer data[4]; guint d, i; - int n_pspecs = 0; + unsigned int n_pspecs = 0; g_return_val_if_fail (pool != NULL, NULL); g_return_val_if_fail (owner_type > 0, NULL); diff --git a/gobject/gsourceclosure.c b/gobject/gsourceclosure.c index 3ca5e45f9..13da5cf99 100644 --- a/gobject/gsourceclosure.c +++ b/gobject/gsourceclosure.c @@ -121,7 +121,8 @@ g_child_watch_closure_callback (GPid pid, #ifdef G_OS_UNIX g_value_init (¶ms[0], G_TYPE_ULONG); - g_value_set_ulong (¶ms[0], pid); + G_STATIC_ASSERT (sizeof (pid) <= sizeof (unsigned long)); + g_value_set_ulong (¶ms[0], (gulong) pid); #endif #ifdef G_OS_WIN32 g_value_init (¶ms[0], G_TYPE_POINTER); diff --git a/gobject/gtype.c b/gobject/gtype.c index fc5e4c45a..4a8a48724 100644 --- a/gobject/gtype.c +++ b/gobject/gtype.c @@ -125,9 +125,9 @@ * larger alignment than this, but we don't need to * do better than malloc. */ -#define STRUCT_ALIGNMENT (2 * sizeof (gsize)) +#define STRUCT_ALIGNMENT (2u * sizeof (gsize)) #define ALIGN_STRUCT(offset) \ - ((offset + (STRUCT_ALIGNMENT - 1)) & -STRUCT_ALIGNMENT) + (((size_t) (offset) + (STRUCT_ALIGNMENT - 1u)) & -STRUCT_ALIGNMENT) /* --- typedefs --- */ @@ -442,7 +442,7 @@ type_node_any_new_W (TypeNode *pnode, else { node->supers[0] = type; - memcpy (node->supers + 1, pnode->supers, sizeof (GType) * (1 + pnode->n_supers + 1)); + memcpy (node->supers + 1, pnode->supers, sizeof (GType) * (1u + pnode->n_supers + 1u)); node->is_abstract = (type_flags & G_TYPE_FLAG_ABSTRACT) != 0; node->is_classed = pnode->is_classed; @@ -1239,7 +1239,7 @@ type_data_ref_Wm (TypeNode *node) static gboolean iface_node_has_available_offset_L (TypeNode *iface_node, gsize offset, - int for_index) + size_t for_index) { guint8 *offsets; @@ -1263,8 +1263,7 @@ find_free_iface_offset_L (IFaceEntries *entries) IFaceEntry *entry; TypeNode *iface_node; gsize offset; - int i; - int n_entries; + size_t i, n_entries; n_entries = IFACE_ENTRIES_N_ENTRIES (entries); offset = 0; @@ -1290,7 +1289,7 @@ find_free_iface_offset_L (IFaceEntries *entries) static void iface_node_set_offset_L (TypeNode *iface_node, gsize offset, - int index) + size_t index) { guint8 *offsets, *old_offsets; gsize new_size, old_size; @@ -1821,8 +1820,8 @@ g_type_create_instance (GType type) GTypeInstance *instance; GTypeClass *class; gchar *allocated; - gint private_size; - gint ivar_size; + size_t private_size; + size_t ivar_size; guint i; node = lookup_type_node_I (type); @@ -1928,8 +1927,8 @@ g_type_free_instance (GTypeInstance *instance) TypeNode *node; GTypeClass *class; gchar *allocated; - gint private_size; - gint ivar_size; + size_t private_size; + size_t ivar_size; g_return_if_fail (instance != NULL && instance->g_class != NULL); diff --git a/gobject/gvaluearray.c b/gobject/gvaluearray.c index 8c6b81d2b..45870fc4b 100644 --- a/gobject/gvaluearray.c +++ b/gobject/gvaluearray.c @@ -62,7 +62,7 @@ * as described above. */ -#define GROUP_N_VALUES (8) /* power of 2 !! */ +#define GROUP_N_VALUES (8u) /* power of 2 !! */ /* --- functions --- */ @@ -99,6 +99,7 @@ value_array_grow (GValueArray *value_array, { guint i = value_array->n_prealloced; + /* round up to the next multiple of GROUP_N_VALUES */ value_array->n_prealloced = (value_array->n_values + GROUP_N_VALUES - 1) & ~(GROUP_N_VALUES - 1); value_array->values = g_renew (GValue, value_array->values, value_array->n_prealloced); if (!zero_init) From 636bbd1d63b1603ce499b85b83b9ec7f0f59661b Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Fri, 11 Apr 2025 15:02:34 +0100 Subject: [PATCH 05/16] gobject: Fix several int/unsigned conversions with atomics MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Unfortunately the signatures of our atomic functions alternate between using signed and unsigned integers across different functions, so we can’t just use one type as input. Add some explicit casts to fix harmless `-Wsign-conversion` warnings. Signed-off-by: Philip Withnall Helps: #3405 --- gobject/gobject.c | 6 +++--- gobject/gsignal.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/gobject/gobject.c b/gobject/gobject.c index cd4769ec0..f14c5112e 100644 --- a/gobject/gobject.c +++ b/gobject/gobject.c @@ -1657,21 +1657,21 @@ g_object_interface_list_properties (gpointer g_iface, static inline guint object_get_optional_flags (GObject *object) { - return g_atomic_int_get (object_get_optional_flags_p (object)); + return (guint) g_atomic_int_get ((gint *) object_get_optional_flags_p (object)); } static inline void object_set_optional_flags (GObject *object, guint flags) { - g_atomic_int_or (object_get_optional_flags_p (object), flags); + g_atomic_int_or ((gint *) object_get_optional_flags_p (object), (int) flags); } static inline void object_unset_optional_flags (GObject *object, guint flags) { - g_atomic_int_and (object_get_optional_flags_p (object), ~flags); + g_atomic_int_and ((gint *) object_get_optional_flags_p (object), (int) ~flags); } gboolean diff --git a/gobject/gsignal.c b/gobject/gsignal.c index 27484b3a0..914038963 100644 --- a/gobject/gsignal.c +++ b/gobject/gsignal.c @@ -3853,9 +3853,9 @@ signal_emit_unlocked_R (SignalNode *node, if (!(old_flags & G_HOOK_FLAG_IN_CALL)) { - g_atomic_int_compare_and_exchange (&hook->flags, - old_flags | G_HOOK_FLAG_IN_CALL, - old_flags); + g_atomic_int_compare_and_exchange ((gint *) &hook->flags, + (gint) old_flags | G_HOOK_FLAG_IN_CALL, + (gint) old_flags); } hook_returns[i] = !!need_destroy; From 615cd4c10cf0b0a9c198be4dbaf40c8687a2093c Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Fri, 11 Apr 2025 15:04:40 +0100 Subject: [PATCH 06/16] gobject: Fix a guint to gboolean conversion warning Make the conversion explicit. Fixes some `-Wsign-conversion` warnings. Signed-off-by: Philip Withnall Helps: #3405 --- gobject/gobject.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gobject/gobject.c b/gobject/gobject.c index f14c5112e..750959d55 100644 --- a/gobject/gobject.c +++ b/gobject/gobject.c @@ -3891,7 +3891,7 @@ g_object_is_floating (gpointer _object) { GObject *object = _object; g_return_val_if_fail (G_IS_OBJECT (object), FALSE); - return floating_flag_handler (object, 0); + return (floating_flag_handler (object, 0) != 0); } /** @@ -3922,7 +3922,7 @@ gpointer g_return_val_if_fail (G_IS_OBJECT (object), object); g_return_val_if_fail (g_atomic_int_get (&object->ref_count) >= 1, object); g_object_ref (object); - was_floating = floating_flag_handler (object, -1); + was_floating = (floating_flag_handler (object, -1) != 0); if (was_floating) g_object_unref (object); return object; From 70ddc35340acfbc3674c752e48cfd7f10d3cf308 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Fri, 11 Apr 2025 15:06:11 +0100 Subject: [PATCH 07/16] gparamspecs: Fix some guint to gboolean conversion warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit While we’re at it, rename the variables to make the intent a bit clearer: these functions return a boolean indicating whether any of the values were modified to make them valid. `n_changed` is a counter of the number of modified values. Signed-off-by: Philip Withnall Helps: #3405 --- gobject/gparamspecs.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/gobject/gparamspecs.c b/gobject/gparamspecs.c index 99bcf6085..111a035da 100644 --- a/gobject/gparamspecs.c +++ b/gobject/gparamspecs.c @@ -763,7 +763,7 @@ param_string_validate (GParamSpec *pspec, { GParamSpecString *sspec = G_PARAM_SPEC_STRING (pspec); gchar *string = value->data[0].v_pointer; - guint changed = 0; + guint n_changed = 0; if (string && string[0]) { @@ -778,7 +778,7 @@ param_string_validate (GParamSpec *pspec, value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS; } string[0] = sspec->substitutor; - changed++; + n_changed++; } if (sspec->cset_nth) for (s = string + 1; *s; s++) @@ -792,7 +792,7 @@ param_string_validate (GParamSpec *pspec, value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS; } *s = sspec->substitutor; - changed++; + n_changed++; } } if (sspec->null_fold_if_empty && string && string[0] == 0) @@ -802,18 +802,18 @@ param_string_validate (GParamSpec *pspec, else value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS; value->data[0].v_pointer = NULL; - changed++; + n_changed++; string = value->data[0].v_pointer; } if (sspec->ensure_non_null && !string) { value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS; value->data[0].v_pointer = g_strdup (""); - changed++; + n_changed++; string = value->data[0].v_pointer; } - return changed; + return (n_changed > 0); } static gboolean @@ -883,16 +883,16 @@ param_param_validate (GParamSpec *pspec, { /* GParamSpecParam *spec = G_PARAM_SPEC_PARAM (pspec); */ GParamSpec *param = value->data[0].v_pointer; - guint changed = 0; + guint n_changed = 0; if (param && !g_value_type_compatible (G_PARAM_SPEC_TYPE (param), G_PARAM_SPEC_VALUE_TYPE (pspec))) { g_param_spec_unref (param); value->data[0].v_pointer = NULL; - changed++; + n_changed++; } - return changed; + return (n_changed > 0); } static void @@ -1015,7 +1015,7 @@ param_value_array_validate (GParamSpec *pspec, { GParamSpecValueArray *aspec = G_PARAM_SPEC_VALUE_ARRAY (pspec); GValueArray *value_array = value->data[0].v_pointer; - guint changed = 0; + guint n_changed = 0; if (!value->data[0].v_pointer && aspec->fixed_n_elements) value_array = value->data[0].v_pointer = g_value_array_new (aspec->fixed_n_elements); @@ -1023,7 +1023,7 @@ param_value_array_validate (GParamSpec *pspec, if (value->data[0].v_pointer) { /* ensure array size validity */ - changed += value_array_ensure_size (value_array, aspec->fixed_n_elements); + n_changed += value_array_ensure_size (value_array, aspec->fixed_n_elements); /* ensure array values validity against a present element spec */ if (aspec->element_spec) @@ -1042,18 +1042,18 @@ param_value_array_validate (GParamSpec *pspec, g_value_unset (element); g_value_init (element, G_PARAM_SPEC_VALUE_TYPE (element_spec)); g_param_value_set_default (element_spec, element); - changed++; + n_changed++; } else { /* validate array value against element_spec */ - changed += g_param_value_validate (element_spec, element); + n_changed += g_param_value_validate (element_spec, element) ? 1 : 0; } } } } - return changed; + return (n_changed > 0); } static gint @@ -1128,16 +1128,16 @@ param_object_validate (GParamSpec *pspec, { GParamSpecObject *ospec = G_PARAM_SPEC_OBJECT (pspec); GObject *object = value->data[0].v_pointer; - guint changed = 0; + guint n_changed = 0; if (object && !g_value_type_compatible (G_OBJECT_TYPE (object), G_PARAM_SPEC_VALUE_TYPE (ospec))) { g_object_unref (object); value->data[0].v_pointer = NULL; - changed++; + n_changed++; } - return changed; + return (n_changed > 0); } static gint @@ -1242,15 +1242,15 @@ param_gtype_validate (GParamSpec *pspec, { GParamSpecGType *tspec = G_PARAM_SPEC_GTYPE (pspec); GType gtype = GPOINTER_TO_TYPE (value->data[0].v_pointer); - guint changed = 0; + guint n_changed = 0; if (tspec->is_a_type != G_TYPE_NONE && !g_type_is_a (gtype, tspec->is_a_type)) { value->data[0].v_pointer = GTYPE_TO_POINTER (tspec->is_a_type); - changed++; + n_changed++; } - return changed; + return (n_changed > 0); } static gint From 633e49c8d130a0e7f2f2bc2a233d94aa6c264aff Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Fri, 11 Apr 2025 15:08:16 +0100 Subject: [PATCH 08/16] gobject: Cast various inverted bitfield constants to unsigned MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes `-Wsign-conversion` warnings, though I’m not sure why the compiler is emitting them. The signed/unsigned status of flag enum members is not particularly well defined in the C standard (and even less well understood by me), so just do what seems necessary to shut the compiler up. The benefits of enabling `-Wsign-conversion` across the codebase hopefully outweighs this noise. Signed-off-by: Philip Withnall Helps: #3405 --- gobject/gbinding.c | 2 +- gobject/gobject.c | 2 +- gobject/gparam.c | 2 +- gobject/gparamspecs.c | 8 ++++---- gobject/gsignal.c | 14 +++++++------- gobject/gtype.c | 4 ++-- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/gobject/gbinding.c b/gobject/gbinding.c index 8c242e3af..193bd5c28 100644 --- a/gobject/gbinding.c +++ b/gobject/gbinding.c @@ -1250,7 +1250,7 @@ g_object_bind_property_full (gpointer source, if ((flags & G_BINDING_INVERT_BOOLEAN) && (transform_to != NULL || transform_from != NULL)) { - flags &= ~G_BINDING_INVERT_BOOLEAN; + flags &= (unsigned) ~G_BINDING_INVERT_BOOLEAN; } pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (source), source_property); diff --git a/gobject/gobject.c b/gobject/gobject.c index 750959d55..7ec7036a1 100644 --- a/gobject/gobject.c +++ b/gobject/gobject.c @@ -948,7 +948,7 @@ g_object_base_class_init (GObjectClass *class) GObjectClass *pclass = g_type_class_peek_parent (class); /* Don't inherit HAS_DERIVED_CLASS flag from parent class */ - class->flags &= ~CLASS_HAS_DERIVED_CLASS_FLAG; + class->flags &= (unsigned) ~CLASS_HAS_DERIVED_CLASS_FLAG; if (pclass) pclass->flags |= CLASS_HAS_DERIVED_CLASS_FLAG; diff --git a/gobject/gparam.c b/gobject/gparam.c index 71547f3a3..939aeb5c6 100644 --- a/gobject/gparam.c +++ b/gobject/gparam.c @@ -54,7 +54,7 @@ /* --- defines --- */ #define PARAM_FLOATING_FLAG 0x2 -#define G_PARAM_USER_MASK (~0U << G_PARAM_USER_SHIFT) +#define G_PARAM_USER_MASK ((GParamFlags) (~0U << G_PARAM_USER_SHIFT)) #define PSPEC_APPLIES_TO_VALUE(pspec, value) (G_TYPE_CHECK_VALUE_TYPE ((value), G_PARAM_SPEC_VALUE_TYPE (pspec))) /* --- prototypes --- */ diff --git a/gobject/gparamspecs.c b/gobject/gparamspecs.c index 111a035da..bc5cc1c8d 100644 --- a/gobject/gparamspecs.c +++ b/gobject/gparamspecs.c @@ -775,7 +775,7 @@ param_string_validate (GParamSpec *pspec, { value->data[0].v_pointer = g_strdup (string); string = value->data[0].v_pointer; - value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS; + value->data[1].v_uint &= (unsigned) ~G_VALUE_NOCOPY_CONTENTS; } string[0] = sspec->substitutor; n_changed++; @@ -789,7 +789,7 @@ param_string_validate (GParamSpec *pspec, value->data[0].v_pointer = g_strdup (string); s = (gchar*) value->data[0].v_pointer + (s - string); string = value->data[0].v_pointer; - value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS; + value->data[1].v_uint &= (unsigned) ~G_VALUE_NOCOPY_CONTENTS; } *s = sspec->substitutor; n_changed++; @@ -800,14 +800,14 @@ param_string_validate (GParamSpec *pspec, if (!(value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS)) g_free (value->data[0].v_pointer); else - value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS; + value->data[1].v_uint &= (unsigned) ~G_VALUE_NOCOPY_CONTENTS; value->data[0].v_pointer = NULL; n_changed++; string = value->data[0].v_pointer; } if (sspec->ensure_non_null && !string) { - value->data[1].v_uint &= ~G_VALUE_NOCOPY_CONTENTS; + value->data[1].v_uint &= (unsigned) ~G_VALUE_NOCOPY_CONTENTS; value->data[0].v_pointer = g_strdup (""); n_changed++; string = value->data[0].v_pointer; diff --git a/gobject/gsignal.c b/gobject/gsignal.c index 914038963..b70f15e46 100644 --- a/gobject/gsignal.c +++ b/gobject/gsignal.c @@ -2808,7 +2808,7 @@ g_signal_handler_find (gpointer instance, gulong handler_seq_no = 0; g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0); - g_return_val_if_fail ((mask & ~G_SIGNAL_MATCH_MASK) == 0, 0); + g_return_val_if_fail ((mask & (unsigned) ~G_SIGNAL_MATCH_MASK) == 0, 0); if (mask & G_SIGNAL_MATCH_MASK) { @@ -2894,7 +2894,7 @@ g_signal_handlers_block_matched (gpointer instance, guint n_handlers = 0; g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0); - g_return_val_if_fail ((mask & ~G_SIGNAL_MATCH_MASK) == 0, 0); + g_return_val_if_fail ((mask & (unsigned) ~G_SIGNAL_MATCH_MASK) == 0, 0); if (mask & (G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_CLOSURE | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA)) { @@ -2950,7 +2950,7 @@ g_signal_handlers_unblock_matched (gpointer instance, guint n_handlers = 0; g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0); - g_return_val_if_fail ((mask & ~G_SIGNAL_MATCH_MASK) == 0, 0); + g_return_val_if_fail ((mask & (unsigned) ~G_SIGNAL_MATCH_MASK) == 0, 0); if (mask & (G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_CLOSURE | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA)) { @@ -3005,7 +3005,7 @@ g_signal_handlers_disconnect_matched (gpointer instance, guint n_handlers = 0; g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0); - g_return_val_if_fail ((mask & ~G_SIGNAL_MATCH_MASK) == 0, 0); + g_return_val_if_fail ((mask & (unsigned) ~G_SIGNAL_MATCH_MASK) == 0, 0); if (mask & (G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_CLOSURE | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA)) { @@ -3240,7 +3240,7 @@ accumulate (GSignalInvocationHint *ihint, continue_emission = accumulator->func (ihint, return_accu, handler_return, accumulator->data); g_value_reset (handler_return); - ihint->run_type &= ~G_SIGNAL_ACCUMULATOR_FIRST_RUN; + ihint->run_type &= (unsigned) ~G_SIGNAL_ACCUMULATOR_FIRST_RUN; return continue_emission; } @@ -3929,7 +3929,7 @@ signal_emit_unlocked_R (SignalNode *node, goto EMIT_RESTART; } - emission.ihint.run_type &= ~G_SIGNAL_RUN_FIRST; + emission.ihint.run_type &= (unsigned) ~G_SIGNAL_RUN_FIRST; emission.ihint.run_type |= G_SIGNAL_RUN_LAST; if ((node->flags & G_SIGNAL_RUN_LAST) && class_closure) @@ -4003,7 +4003,7 @@ signal_emit_unlocked_R (SignalNode *node, EMIT_CLEANUP: - emission.ihint.run_type &= ~G_SIGNAL_RUN_LAST; + emission.ihint.run_type &= (unsigned) ~G_SIGNAL_RUN_LAST; emission.ihint.run_type |= G_SIGNAL_RUN_CLEANUP; if ((node->flags & G_SIGNAL_RUN_CLEANUP) && class_closure) diff --git a/gobject/gtype.c b/gobject/gtype.c index 4a8a48724..6b59ffb80 100644 --- a/gobject/gtype.c +++ b/gobject/gtype.c @@ -3628,7 +3628,7 @@ type_add_flags_W (TypeNode *node, { guint dflags; - g_return_if_fail ((flags & ~TYPE_FLAG_MASK) == 0); + g_return_if_fail ((flags & (unsigned) ~TYPE_FLAG_MASK) == 0); g_return_if_fail (node != NULL); if ((flags & TYPE_FLAG_MASK) && node->is_classed && node->data && node->data->class.class) @@ -3725,7 +3725,7 @@ _g_type_test_flags (GType type, node = lookup_type_node_I (type); if (node) { - if ((flags & ~NODE_FLAG_MASK) == 0) + if ((flags & (unsigned) ~NODE_FLAG_MASK) == 0) { if ((flags & G_TYPE_FLAG_CLASSED) && !node->is_classed) return FALSE; From 752c0787d6176a339f6e1a9cdc0c17ce86dbb3f9 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Fri, 11 Apr 2025 15:10:13 +0100 Subject: [PATCH 09/16] gparamspecs: Fix -Wsign-conversion warnings for large constants MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Not sure why these constants were chosen the way they were, but that’s not a problem I’m going to investigate right now. This just makes the implicit cast explicit to shut the compiler warning up. Signed-off-by: Philip Withnall Helps: #3405 --- gobject/gparamspecs.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/gobject/gparamspecs.c b/gobject/gparamspecs.c index bc5cc1c8d..22986781c 100644 --- a/gobject/gparamspecs.c +++ b/gobject/gparamspecs.c @@ -152,8 +152,8 @@ param_int_init (GParamSpec *pspec) { GParamSpecInt *ispec = G_PARAM_SPEC_INT (pspec); - ispec->minimum = 0x7fffffff; - ispec->maximum = 0x80000000; + ispec->minimum = (int) 0x7fffffff; + ispec->maximum = (int) 0x80000000; ispec->default_value = 0; } @@ -253,11 +253,11 @@ param_long_init (GParamSpec *pspec) GParamSpecLong *lspec = G_PARAM_SPEC_LONG (pspec); #if SIZEOF_LONG == 4 - lspec->minimum = 0x7fffffff; - lspec->maximum = 0x80000000; + lspec->minimum = (glong) 0x7fffffff; + lspec->maximum = (glong) 0x80000000; #else /* SIZEOF_LONG != 4 (8) */ - lspec->minimum = 0x7fffffffffffffff; - lspec->maximum = 0x8000000000000000; + lspec->minimum = (glong) 0x7fffffffffffffff; + lspec->maximum = (glong) 0x8000000000000000; #endif lspec->default_value = 0; } From b3ebef609f01149a9d3bc7a4b151513bfb70367b Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Fri, 11 Apr 2025 15:13:36 +0100 Subject: [PATCH 10/16] tests: Fix various unsigned/signed comparisons in gobject tests Fix all the instances where `-Wsign-conversion` was pointing out that `g_assert_cmpint()` had been used on unsigned inputs, or vice-versa. Signed-off-by: Philip Withnall Helps: #3405 --- gobject/tests/basics-gobject.c | 2 +- gobject/tests/flags.c | 2 +- gobject/tests/param.c | 14 +++++++------- gobject/tests/reference.c | 6 +++--- gobject/tests/signalgroup.c | 2 +- gobject/tests/signals.c | 6 +++--- gobject/tests/type.c | 6 +++--- gobject/tests/value.c | 4 ++-- 8 files changed, 21 insertions(+), 21 deletions(-) diff --git a/gobject/tests/basics-gobject.c b/gobject/tests/basics-gobject.c index 60ab00319..ec1b34c81 100644 --- a/gobject/tests/basics-gobject.c +++ b/gobject/tests/basics-gobject.c @@ -100,7 +100,7 @@ test_object_test_iface_init (gpointer giface, TestIfaceClass *iface = giface; g_assert (iface_data == GUINT_TO_POINTER (42)); - g_assert_cmpint (G_TYPE_FROM_INTERFACE (iface), ==, TEST_TYPE_IFACE); + g_assert_cmpuint (G_TYPE_FROM_INTERFACE (iface), ==, TEST_TYPE_IFACE); /* assert iface_base_init() was already called */ g_assert_cmpuint (iface_base_init_count, >, 0); diff --git a/gobject/tests/flags.c b/gobject/tests/flags.c index 4483c1858..bd3733c3b 100644 --- a/gobject/tests/flags.c +++ b/gobject/tests/flags.c @@ -166,7 +166,7 @@ check_flags_validation (void) /* This check will fail in case of gint -> glong conversion * in value_flags_enum_collect_value() */ - g_assert_cmpint (flag_read, ==, flag_set); + g_assert_cmpuint (flag_read, ==, flag_set); g_object_unref (test); } diff --git a/gobject/tests/param.c b/gobject/tests/param.c index 2aee68dc8..9d49c3648 100644 --- a/gobject/tests/param.c +++ b/gobject/tests/param.c @@ -195,13 +195,13 @@ test_param_spec_ulong (void) g_param_value_set_default (pspec, &value); g_assert_true (G_VALUE_TYPE (&value) == G_TYPE_ULONG); - g_assert_cmpint (g_value_get_ulong (&value), ==, 30); + g_assert_cmpuint (g_value_get_ulong (&value), ==, 30); g_assert_true (g_param_value_defaults (pspec, &value)); g_value_set_ulong (&value, 0); g_assert_false (g_param_value_is_valid (pspec, &value)); g_assert_true (g_param_value_validate (pspec, &value)); - g_assert_cmpint (g_value_get_ulong (&value), ==, 20); + g_assert_cmpuint (g_value_get_ulong (&value), ==, 20); g_param_spec_unref (pspec); } @@ -239,13 +239,13 @@ test_param_spec_uint64 (void) g_param_value_set_default (pspec, &value); g_assert_true (G_VALUE_TYPE (&value) == G_TYPE_UINT64); - g_assert_cmpint (g_value_get_uint64 (&value), ==, 30); + g_assert_cmpuint (g_value_get_uint64 (&value), ==, 30); g_assert_true (g_param_value_defaults (pspec, &value)); g_value_set_uint64 (&value, 0); g_assert_false (g_param_value_is_valid (pspec, &value)); g_assert_true (g_param_value_validate (pspec, &value)); - g_assert_cmpint (g_value_get_uint64 (&value), ==, 20); + g_assert_cmpuint (g_value_get_uint64 (&value), ==, 20); g_param_spec_unref (pspec); } @@ -522,12 +522,12 @@ test_param_spec_gtype (void) g_value_set_gtype (&value, G_TYPE_INT); g_assert_false (g_param_value_is_valid (pspec, &value)); g_assert_true (g_param_value_validate (pspec, &value)); - g_assert_cmpint (g_value_get_gtype (&value), ==, G_TYPE_PARAM); + g_assert_cmpuint (g_value_get_gtype (&value), ==, G_TYPE_PARAM); g_value_set_gtype (&value, G_TYPE_PARAM_INT); g_assert_true (g_param_value_is_valid (pspec, &value)); g_assert_false (g_param_value_validate (pspec, &value)); - g_assert_cmpint (g_value_get_gtype (&value), ==, G_TYPE_PARAM_INT); + g_assert_cmpuint (g_value_get_gtype (&value), ==, G_TYPE_PARAM_INT); g_param_spec_unref (pspec); } @@ -834,7 +834,7 @@ test_value_transform (void) * https://bugzilla.gnome.org/show_bug.cgi?id=659870 * for why it is broken. */ - CHECK_INT_CONVERSION(G_TYPE_CHAR, g_assert_cmpuint, char, 124) + CHECK_INT_CONVERSION(G_TYPE_CHAR, g_assert_cmpint, char, 124) CHECK_INT_CONVERSION(G_TYPE_CHAR, g_assert_cmpint, schar, -124) CHECK_INT_CONVERSION(G_TYPE_CHAR, g_assert_cmpint, schar, 124) diff --git a/gobject/tests/reference.c b/gobject/tests/reference.c index 0408a8edf..0ad330794 100644 --- a/gobject/tests/reference.c +++ b/gobject/tests/reference.c @@ -48,10 +48,10 @@ test_type_query (void) GTypeQuery query; g_type_query (G_TYPE_ENUM, &query); - g_assert_cmpint (query.type, ==, G_TYPE_ENUM); + g_assert_cmpuint (query.type, ==, G_TYPE_ENUM); g_assert_cmpstr (query.type_name, ==, "GEnum"); - g_assert_cmpint (query.class_size, ==, sizeof (GEnumClass)); - g_assert_cmpint (query.instance_size, ==, 0); + g_assert_cmpuint (query.class_size, ==, sizeof (GEnumClass)); + g_assert_cmpuint (query.instance_size, ==, 0); } typedef struct _MyObject MyObject; diff --git a/gobject/tests/signalgroup.c b/gobject/tests/signalgroup.c index 198c16ca4..c4d98062f 100644 --- a/gobject/tests/signalgroup.c +++ b/gobject/tests/signalgroup.c @@ -590,7 +590,7 @@ test_signal_group_properties (void) "target", &target, "target-type", >ype, NULL); - g_assert_cmpint (gtype, ==, signal_target_get_type ()); + g_assert_cmpuint (gtype, ==, signal_target_get_type ()); g_assert_null (target); target = g_object_new (signal_target_get_type (), NULL); diff --git a/gobject/tests/signals.c b/gobject/tests/signals.c index 834fdd68e..b91046eea 100644 --- a/gobject/tests/signals.c +++ b/gobject/tests/signals.c @@ -1509,7 +1509,7 @@ test_introspection (void) g_assert_cmpstr (query.signal_name, ==, "simple"); g_assert_true (query.itype == test_get_type ()); g_assert_cmpint (query.signal_flags, ==, G_SIGNAL_RUN_LAST); - g_assert_cmpint (query.return_type, ==, G_TYPE_NONE); + g_assert_cmpuint (query.return_type, ==, G_TYPE_NONE); g_assert_cmpuint (query.n_params, ==, 0); g_free (ids); @@ -2074,11 +2074,11 @@ test_weak_ref_disconnect (void) &state, (GClosureNotify) weak_ref_disconnect_notify, 0); - g_assert_cmpint (state.handler, >, 0); + g_assert_cmpuint (state.handler, >, 0); g_object_unref (test); - g_assert_cmpint (state.handler, ==, 0); + g_assert_cmpuint (state.handler, ==, 0); g_assert_null (g_weak_ref_get (&state.wr)); g_weak_ref_clear (&state.wr); } diff --git a/gobject/tests/type.c b/gobject/tests/type.c index ea0dd46f3..9cecf3bf2 100644 --- a/gobject/tests/type.c +++ b/gobject/tests/type.c @@ -118,10 +118,10 @@ test_interface_prerequisite (void) g_free (prereqs); - g_assert_cmpint (g_type_interface_instantiatable_prerequisite (baa_get_type ()), ==, G_TYPE_INVALID); - g_assert_cmpint (g_type_interface_instantiatable_prerequisite (boo_get_type ()), ==, G_TYPE_INVALID); + g_assert_cmpuint (g_type_interface_instantiatable_prerequisite (baa_get_type ()), ==, G_TYPE_INVALID); + g_assert_cmpuint (g_type_interface_instantiatable_prerequisite (boo_get_type ()), ==, G_TYPE_INVALID); - g_assert_cmpint (g_type_interface_instantiatable_prerequisite (bozo_get_type ()), ==, G_TYPE_INITIALLY_UNOWNED); + g_assert_cmpuint (g_type_interface_instantiatable_prerequisite (bozo_get_type ()), ==, G_TYPE_INITIALLY_UNOWNED); } typedef struct { diff --git a/gobject/tests/value.c b/gobject/tests/value.c index 4d5637880..105a20d84 100644 --- a/gobject/tests/value.c +++ b/gobject/tests/value.c @@ -72,7 +72,7 @@ test_enum_transformation (void) memset (&xform, 0, sizeof (GValue)); g_value_init (&xform, G_TYPE_ULONG); g_value_transform (&orig, &xform); - g_assert_cmpint (g_value_get_ulong (&xform), ==, 1); + g_assert_cmpuint (g_value_get_ulong (&xform), ==, 1); memset (&xform, 0, sizeof (GValue)); g_value_init (&xform, G_TYPE_INT64); @@ -82,7 +82,7 @@ test_enum_transformation (void) memset (&xform, 0, sizeof (GValue)); g_value_init (&xform, G_TYPE_UINT64); g_value_transform (&orig, &xform); - g_assert_cmpint (g_value_get_uint64 (&xform), ==, 1); + g_assert_cmpuint (g_value_get_uint64 (&xform), ==, 1); } From ee2d25b57a745a2cb3439070cd98d37d4f47ae96 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Fri, 11 Apr 2025 16:59:00 +0100 Subject: [PATCH 11/16] tests: Fix various straightforward -Wsign-conversion warnings In the gobject tests. Signed-off-by: Philip Withnall Helps: #3405 --- gobject/tests/ifaceproperties.c | 4 ++-- gobject/tests/param.c | 16 ++++++++-------- gobject/tests/properties-refcount1.c | 2 +- gobject/tests/properties-refcount3.c | 2 +- gobject/tests/signals.c | 2 +- gobject/tests/threadtests.c | 10 +++++----- gobject/tests/type.c | 2 +- gobject/tests/value.c | 10 +++++----- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/gobject/tests/ifaceproperties.c b/gobject/tests/ifaceproperties.c index 3356da0b3..9ee09cbfa 100644 --- a/gobject/tests/ifaceproperties.c +++ b/gobject/tests/ifaceproperties.c @@ -396,9 +396,9 @@ static DEFINE_TYPE (DerivedObject, derived_object, static void assert_in_properties (GParamSpec *param_spec, GParamSpec **properties, - gint n_properties) + size_t n_properties) { - gint i; + size_t i; gboolean found = FALSE; for (i = 0; i < n_properties; i++) diff --git a/gobject/tests/param.c b/gobject/tests/param.c index 9d49c3648..22375f4d5 100644 --- a/gobject/tests/param.c +++ b/gobject/tests/param.c @@ -1376,10 +1376,10 @@ static void test_implementation_class_init (TestImplementationClass *class) } typedef struct { - gint change_this_flag; - gint change_this_type; - gint use_this_flag; - gint use_this_type; + guint change_this_flag; + guint change_this_type; + guint use_this_flag; + guint use_this_type; } TestParamImplementData; static void @@ -1433,7 +1433,7 @@ test_param_implement (void) continue; } - test_path = g_strdup_printf ("/param/implement/subprocess/%d-%d-%d-%d", + test_path = g_strdup_printf ("/param/implement/subprocess/%u-%u-%u-%u", change_this_flag, change_this_type, use_this_flag, use_this_type); g_test_trap_subprocess (test_path, G_TIME_SPAN_SECOND, @@ -1545,8 +1545,8 @@ param_int_init (GParamSpec *pspec) { GParamSpecInt *ispec = (GParamSpecInt *)pspec; - ispec->minimum = 0x7fffffff; - ispec->maximum = 0x80000000; + ispec->minimum = (int) 0x7fffffff; + ispec->maximum = (int) 0x80000000; ispec->default_value = 0; } @@ -1686,7 +1686,7 @@ main (int argc, char *argv[]) for (data.use_this_flag = 0; data.use_this_flag < 16; data.use_this_flag++) for (data.use_this_type = 0; data.use_this_type < 4; data.use_this_type++) { - test_path = g_strdup_printf ("/param/implement/subprocess/%d-%d-%d-%d", + test_path = g_strdup_printf ("/param/implement/subprocess/%u-%u-%u-%u", data.change_this_flag, data.change_this_type, data.use_this_flag, data.use_this_type); test_data = g_memdup2 (&data, sizeof (TestParamImplementData)); diff --git a/gobject/tests/properties-refcount1.c b/gobject/tests/properties-refcount1.c index 5a96518dc..532e15048 100644 --- a/gobject/tests/properties-refcount1.c +++ b/gobject/tests/properties-refcount1.c @@ -23,7 +23,7 @@ typedef struct _GTestClass GTestClass; struct _GTest { GObject object; - gint id; + unsigned int id; gint dummy; gint count; diff --git a/gobject/tests/properties-refcount3.c b/gobject/tests/properties-refcount3.c index 802689283..fd55f0c0d 100644 --- a/gobject/tests/properties-refcount3.c +++ b/gobject/tests/properties-refcount3.c @@ -19,7 +19,7 @@ typedef struct _GTestClass GTestClass; struct _GTest { GObject object; - gint id; + unsigned int id; gint dummy; gint count; diff --git a/gobject/tests/signals.c b/gobject/tests/signals.c index b91046eea..a11e92038 100644 --- a/gobject/tests/signals.c +++ b/gobject/tests/signals.c @@ -1705,7 +1705,7 @@ test_clear_signal_handler (void) if (g_test_undefined ()) { - handler = g_random_int_range (0x01, 0xFF); + handler = (gulong) g_random_int_range (0x01, 0xFF); g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, "*instance '* has no handler with id *'"); g_clear_signal_handler (&handler, test_obj); diff --git a/gobject/tests/threadtests.c b/gobject/tests/threadtests.c index 9b923f3fd..2ae257859 100644 --- a/gobject/tests/threadtests.c +++ b/gobject/tests/threadtests.c @@ -220,8 +220,8 @@ test_threaded_object_init (void) } typedef struct { - MyTester0 *strong; - guint unref_delay; + MyTester0 *strong; + gulong unref_delay; } UnrefInThreadData; static gpointer @@ -269,7 +269,7 @@ test_threaded_weak_ref (void) gpointer weak; #endif MyTester0 *strengthened; - guint get_delay; + gulong get_delay; GThread *thread; GError *error = NULL; @@ -290,8 +290,8 @@ test_threaded_weak_ref (void) * timing. Ideally, we want each side to win half the races; on * smcv's laptop, these timings are about right. */ - data.unref_delay = g_random_int_range (SLEEP_MIN_USEC / 2, SLEEP_MAX_USEC / 2); - get_delay = g_random_int_range (SLEEP_MIN_USEC, SLEEP_MAX_USEC); + data.unref_delay = (gulong) g_random_int_range (SLEEP_MIN_USEC / 2, SLEEP_MAX_USEC / 2); + get_delay = (gulong) g_random_int_range (SLEEP_MIN_USEC, SLEEP_MAX_USEC); /* One half of the race is to unref the shared object */ thread = g_thread_create (unref_in_thread, &data, TRUE, &error); diff --git a/gobject/tests/type.c b/gobject/tests/type.c index 9cecf3bf2..372596e39 100644 --- a/gobject/tests/type.c +++ b/gobject/tests/type.c @@ -3,7 +3,7 @@ static void test_registration_serial (void) { - gint serial1, serial2, serial3; + guint serial1, serial2, serial3; serial1 = g_type_get_type_registration_serial (); g_pointer_type_register_static ("my+pointer"); diff --git a/gobject/tests/value.c b/gobject/tests/value.c index 105a20d84..e1c647d71 100644 --- a/gobject/tests/value.c +++ b/gobject/tests/value.c @@ -633,9 +633,9 @@ test_valuearray_basic (void) a = g_value_array_new (20); g_value_init (&v, G_TYPE_INT); - for (i = 0; i < 100; i++) + for (int j = 0; j < 100; j++) { - g_value_set_int (&v, i); + g_value_set_int (&v, j); g_value_array_append (a, &v); } @@ -646,9 +646,9 @@ test_valuearray_basic (void) for (i = 20; i < 100; i+= 5) g_value_array_remove (a, 100 - i); - for (i = 100; i < 150; i++) + for (int j = 100; j < 150; j++) { - g_value_set_int (&v, i); + g_value_set_int (&v, j); g_value_array_prepend (a, &v); } @@ -692,7 +692,7 @@ test_value_array_sort_with_data (void) /* Add some values and try sorting them. */ g_value_init (&v, G_TYPE_INT); - for (unsigned int i = 0; i < 100; i++) + for (int i = 0; i < 100; i++) { g_value_set_int (&v, 100 - i); g_value_array_append (a, &v); From bad7a325044f70ea939991d137b38fc9ec39ba17 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Fri, 11 Apr 2025 17:00:30 +0100 Subject: [PATCH 12/16] tests: Fix various -Wsign-conversion warnings with flags in gobject tests Signed-off-by: Philip Withnall Helps: #3405 --- gobject/tests/flags.c | 6 +++--- gobject/tests/signals.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/gobject/tests/flags.c b/gobject/tests/flags.c index bd3733c3b..89ea06b10 100644 --- a/gobject/tests/flags.c +++ b/gobject/tests/flags.c @@ -75,8 +75,8 @@ my_test_flags_get_type (void) if (G_UNLIKELY(flags_type == 0)) { static const GFlagsValue values[] = { - { LOWEST_FLAG, "LOWEST_FLAG", "lowest" }, - { HIGHEST_FLAG, "HIGHEST_FLAG", "highest" }, + { (unsigned) LOWEST_FLAG, "LOWEST_FLAG", "lowest" }, + { (unsigned) HIGHEST_FLAG, "HIGHEST_FLAG", "highest" }, { 0, NULL, NULL } }; @@ -146,7 +146,7 @@ my_test_set_property (GObject *object, static void check_flags_validation (void) { - guint test_flags[] = { + MyFlagsEnum test_flags[] = { NO_FLAG, LOWEST_FLAG, HIGHEST_FLAG, diff --git a/gobject/tests/signals.c b/gobject/tests/signals.c index a11e92038..2647d3b93 100644 --- a/gobject/tests/signals.c +++ b/gobject/tests/signals.c @@ -118,7 +118,7 @@ static const GEnumValue my_enum_values[] = typedef enum { MY_FLAGS_FIRST_BIT = (1 << 0), MY_FLAGS_THIRD_BIT = (1 << 2), - MY_FLAGS_LAST_BIT = (1 << 31) + MY_FLAGS_LAST_BIT = (1u << 31) } MyFlags; static const GFlagsValue my_flag_values[] = From ba4f5ca44e64cc52fca8b81fa7285446105346c6 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Fri, 11 Apr 2025 17:01:06 +0100 Subject: [PATCH 13/16] tests: Explicitly cast src value in param conversion tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes a load of -Wsign-conversion warnings. The dest type setter function is being used (presumably by design?) so there’s sometimes a type mismatch (signed/unsigned, or size) with the constant value being used by the test. This just makes the existing implicit casts explicit. Signed-off-by: Philip Withnall Helps: #3405 --- gobject/tests/param.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/gobject/tests/param.c b/gobject/tests/param.c index 22375f4d5..29a14f282 100644 --- a/gobject/tests/param.c +++ b/gobject/tests/param.c @@ -823,7 +823,7 @@ test_value_transform (void) g_assert_true (g_value_type_transformable (G_TYPE_INT, type)); \ g_value_init (&src, G_TYPE_INT); \ g_value_init (&dest, type); \ - g_value_set_int (&src, value); \ + g_value_set_int (&src, (int) value); \ g_assert_true (g_value_transform (&src, &dest)); \ cmpfunc (g_value_get_##getter (&dest), ==, value); \ g_value_unset (&src); \ @@ -855,7 +855,7 @@ test_value_transform (void) g_assert_true (g_value_type_transformable (G_TYPE_UINT, type)); \ g_value_init (&src, G_TYPE_UINT); \ g_value_init (&dest, type); \ - g_value_set_uint (&src, value); \ + g_value_set_uint (&src, (unsigned int) value); \ g_assert_true (g_value_transform (&src, &dest)); \ cmpfunc (g_value_get_##getter (&dest), ==, value); \ g_value_unset (&src); \ @@ -880,7 +880,7 @@ test_value_transform (void) g_assert_true (g_value_type_transformable (G_TYPE_LONG, type)); \ g_value_init (&src, G_TYPE_LONG); \ g_value_init (&dest, type); \ - g_value_set_long (&src, value); \ + g_value_set_long (&src, (long) value); \ g_assert_true (g_value_transform (&src, &dest)); \ cmpfunc (g_value_get_##getter (&dest), ==, value); \ g_value_unset (&src); \ @@ -905,7 +905,7 @@ test_value_transform (void) g_assert_true (g_value_type_transformable (G_TYPE_ULONG, type)); \ g_value_init (&src, G_TYPE_ULONG); \ g_value_init (&dest, type); \ - g_value_set_ulong (&src, value); \ + g_value_set_ulong (&src, (gulong) value); \ g_assert_true (g_value_transform (&src, &dest)); \ cmpfunc (g_value_get_##getter (&dest), ==, value); \ g_value_unset (&src); \ @@ -930,7 +930,7 @@ test_value_transform (void) g_assert_true (g_value_type_transformable (G_TYPE_INT64, type)); \ g_value_init (&src, G_TYPE_INT64); \ g_value_init (&dest, type); \ - g_value_set_int64 (&src, value); \ + g_value_set_int64 (&src, (gint64) value); \ g_assert_true (g_value_transform (&src, &dest)); \ cmpfunc (g_value_get_##getter (&dest), ==, value); \ g_value_unset (&src); \ @@ -955,7 +955,7 @@ test_value_transform (void) g_assert_true (g_value_type_transformable (G_TYPE_UINT64, type)); \ g_value_init (&src, G_TYPE_UINT64); \ g_value_init (&dest, type); \ - g_value_set_uint64 (&src, value); \ + g_value_set_uint64 (&src, (guint64) value); \ g_assert_true (g_value_transform (&src, &dest)); \ cmpfunc (g_value_get_##getter (&dest), ==, value); \ g_value_unset (&src); \ @@ -980,7 +980,7 @@ test_value_transform (void) g_assert_true (g_value_type_transformable (G_TYPE_FLOAT, type)); \ g_value_init (&src, G_TYPE_FLOAT); \ g_value_init (&dest, type); \ - g_value_set_float (&src, value); \ + g_value_set_float (&src, (float) value); \ g_assert_true (g_value_transform (&src, &dest)); \ cmpfunc (g_value_get_##getter (&dest), ==, value); \ g_value_unset (&src); \ @@ -1005,7 +1005,7 @@ test_value_transform (void) g_assert_true (g_value_type_transformable (G_TYPE_DOUBLE, type)); \ g_value_init (&src, G_TYPE_DOUBLE); \ g_value_init (&dest, type); \ - g_value_set_double (&src, value); \ + g_value_set_double (&src, (double) value); \ g_assert_true (g_value_transform (&src, &dest)); \ cmpfunc (g_value_get_##getter (&dest), ==, value); \ g_value_unset (&src); \ From e27d64e651433b4c057fd2b81fd302e04016d90b Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Fri, 11 Apr 2025 17:03:23 +0100 Subject: [PATCH 14/16] tests: Fix -Wsign-conversion warnings for random ints in gobject tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There’s a painful inconsistency in the types of the `g_{test_rand,random,rand}_int{,_range}()` functions, which vary arbitrarily between `gint32` and `guint32`. Unfortunately since those functions mention `int` explicitly in the name (and then some of them return an `unsigned` integer), I don’t see a way to make the APIs consistent without significant deprecations or additions. So, for the moment, to fix various `-Wsign-conversion` warnings, plaster the tests with casts. Signed-off-by: Philip Withnall Helps: #3405 --- gobject/tests/reference.c | 10 +++++----- gobject/tests/signal-handler.c | 8 ++++---- gobject/tests/signals-refcount.c | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/gobject/tests/reference.c b/gobject/tests/reference.c index 0ad330794..0aaf9f3cf 100644 --- a/gobject/tests/reference.c +++ b/gobject/tests/reference.c @@ -790,7 +790,7 @@ test_weak_ref_many (void) /* We register them in a somewhat juggled order. That's because below, we will clear them * again, and we don't want to always clear them in the same order as they were registered. * For that, we calculate the actual index by jumping around by adding a prime number. */ - j = (g_test_rand_int () % (N + 1)); + j = ((guint) g_test_rand_int () % (N + 1)); for (i = 0; i < N; i++) { j = (j + PRIME) % N; @@ -805,7 +805,7 @@ test_weak_ref_many (void) g_assert_null (g_weak_ref_get (&weak_ref1)); } - n = g_test_rand_int () % (N + 1u); + n = (guint) g_test_rand_int () % (N + 1u); for (i = 0; i < N; i++) g_weak_ref_set (&weak_refs[i], i < n ? NULL : obj); @@ -972,9 +972,9 @@ test_weak_ref_concurrent (gconstpointer testdata) for (i = 0; i < CONCURRENT_N_THREADS; i++) { const guint32 rnd_seed[] = { - g_test_rand_int (), - g_test_rand_int (), - g_test_rand_int (), + (guint32) g_test_rand_int (), + (guint32) g_test_rand_int (), + (guint32) g_test_rand_int (), }; thread_data[i] = (ConcurrentThreadData){ diff --git a/gobject/tests/signal-handler.c b/gobject/tests/signal-handler.c index 81db9ccf9..6dee17e18 100644 --- a/gobject/tests/signal-handler.c +++ b/gobject/tests/signal-handler.c @@ -147,7 +147,7 @@ test_disconnect_many_random (void) for (i = 0; i < n_handlers; i++) { - j = g_test_rand_int_range (0, n_handlers); + j = (guint) g_test_rand_int_range (0, (int) n_handlers); id = handlers[i]; handlers[i] = handlers[j]; handlers[j] = id; @@ -189,7 +189,7 @@ test_disconnect_2_signals (void) for (i = 0; i < n_handlers; i++) { - j = g_test_rand_int_range (0, n_handlers); + j = (guint) g_test_rand_int_range (0, (int) n_handlers); id = handlers[i]; handlers[i] = handlers[j]; handlers[j] = id; @@ -240,7 +240,7 @@ test_disconnect_2_objects (void) for (i = 0; i < n_handlers; i++) { - j = g_test_rand_int_range (0, n_handlers); + j = (guint) g_test_rand_int_range (0, (int) n_handlers); id = handlers[i]; handlers[i] = handlers[j]; handlers[j] = id; @@ -282,7 +282,7 @@ test_block_many (void) for (i = 0; i < n_handlers; i++) { - j = g_test_rand_int_range (0, n_handlers); + j = (guint) g_test_rand_int_range (0, (int) n_handlers); id = handlers[i]; handlers[i] = handlers[j]; handlers[j] = id; diff --git a/gobject/tests/signals-refcount.c b/gobject/tests/signals-refcount.c index 76c9a14ec..46ddbf25b 100644 --- a/gobject/tests/signals-refcount.c +++ b/gobject/tests/signals-refcount.c @@ -217,7 +217,7 @@ my_test_do_signal3 (GTest * test) static void my_test_do_prop (GTest * test) { - test->value = g_random_int (); + test->value = (int) g_random_int (); g_object_notify (G_OBJECT (test), "test-prop"); } From 4ddea1f6c05a8127d889f38558477e6e83a08e09 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Fri, 11 Apr 2025 17:05:46 +0100 Subject: [PATCH 15/16] gobject: Enable -Wsign-conversion for gobject subdirectory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixing #3405 is going to take a lot of work, so let’s split it up into pieces and work on them separately. The `gobject/` and `gobject/tests/` directories now compile cleanly with `-Wsign-conversion` (see the previous commits), so let’s enable the warning for those directories to prevent regressions while we continue to work on the other directories. Signed-off-by: Philip Withnall Helps: #3405 --- gobject/meson.build | 2 +- gobject/tests/meson.build | 2 +- meson.build | 7 +++++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/gobject/meson.build b/gobject/meson.build index 4bba94c96..91823af79 100644 --- a/gobject/meson.build +++ b/gobject/meson.build @@ -147,7 +147,7 @@ libgobject = library('gobject-2.0', install : true, include_directories : [configinc], dependencies : [libffi_dep, libglib_dep], - c_args : ['-DG_LOG_DOMAIN="GLib-GObject"', '-DGOBJECT_COMPILATION'], + c_args : ['-DG_LOG_DOMAIN="GLib-GObject"', '-DGOBJECT_COMPILATION', warning_sign_conversion_args], gnu_symbol_visibility : 'hidden', link_args : glib_link_flags, ) diff --git a/gobject/tests/meson.build b/gobject/tests/meson.build index 268dd5dd9..0ae4e86ed 100644 --- a/gobject/tests/meson.build +++ b/gobject/tests/meson.build @@ -179,7 +179,7 @@ test_env.set('G_TEST_SRCDIR', meson.current_source_dir()) test_env.set('G_TEST_BUILDDIR', meson.current_build_dir()) test_deps = [libm, thread_dep, libglib_dep, libgobject_dep] -test_cargs = ['-DG_LOG_DOMAIN="GLib-GObject"', '-UG_DISABLE_ASSERT'] +test_cargs = ['-DG_LOG_DOMAIN="GLib-GObject"', '-UG_DISABLE_ASSERT', warning_sign_conversion_args] test_cpp_args = test_cargs foreach test_name, extra_args : gobject_tests diff --git a/meson.build b/meson.build index b11151d28..48cb6cd3c 100644 --- a/meson.build +++ b/meson.build @@ -660,6 +660,13 @@ if have_cxx add_project_arguments(cxx.get_supported_arguments(warning_cxx_args), language: 'cpp') endif +# FIXME: This is checked and implemented separately from warning_common_args for +# now because it causes so many warnings. Adding it as a variable in various +# directories allows us to gradually tighten up support for it. Eventually, the +# warning can be enabled unconditionally in warning_c_args, and this variable +# removed. See https://gitlab.gnome.org/GNOME/glib/-/issues/3405 +warning_sign_conversion_args = cc.get_supported_arguments(['-Wsign-conversion']) + # FIXME: We cannot build some of the GResource tests with -z nodelete, which # means we cannot use that flag in add_project_link_arguments(), and must add # it to the relevant targets manually. We do the same with -Bsymbolic-functions From 96178eb9c01388cf0e5aca1a3b559eda31fbf599 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Fri, 11 Apr 2025 23:46:05 +0100 Subject: [PATCH 16/16] gobject: Fix a few more -Wsign-conversion warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These are all fairly straightforward, but I didn’t get them locally; they only showed up on CI. Signed-off-by: Philip Withnall Helps: #3405 --- glib/gbsearcharray.h | 2 +- gobject/gsignal.c | 2 +- gobject/gtype.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/glib/gbsearcharray.h b/glib/gbsearcharray.h index 39afa3f79..dc7a25a71 100644 --- a/glib/gbsearcharray.h +++ b/glib/gbsearcharray.h @@ -182,7 +182,7 @@ g_bsearch_array_get_index (GBSearchArray *barray, const GBSearchConfig *bconfig, gconstpointer node_in_array) { - guint distance = ((guint8*) node_in_array) - G_BSEARCH_ARRAY_NODES (barray); + size_t distance = (size_t) (((guint8*) node_in_array) - G_BSEARCH_ARRAY_NODES (barray)); g_return_val_if_fail (node_in_array != NULL, barray->n_nodes); diff --git a/gobject/gsignal.c b/gobject/gsignal.c index b70f15e46..137bc003f 100644 --- a/gobject/gsignal.c +++ b/gobject/gsignal.c @@ -1056,7 +1056,7 @@ signal_parse_name (const gchar *name, else if (colon[1] == ':') { gchar buffer[32]; - guint l = colon - name; + size_t l = (size_t) (colon - name); if (colon[2] == '\0') return 0; diff --git a/gobject/gtype.c b/gobject/gtype.c index 6b59ffb80..7d03d322a 100644 --- a/gobject/gtype.c +++ b/gobject/gtype.c @@ -4600,7 +4600,7 @@ g_type_add_instance_private (GType class_gtype, * should make the migration fully transparent even if we're effectively * copying this macro into everybody's code. */ - return private_size; + return (gint) private_size; } /* semi-private function, should only be used by G_DEFINE_TYPE_EXTENDED */ @@ -4610,7 +4610,7 @@ g_type_class_adjust_private_offset (gpointer g_class, { GType class_gtype = ((GTypeClass *) g_class)->g_type; TypeNode *node = lookup_type_node_I (class_gtype); - gssize private_size; + size_t private_size; g_return_if_fail (private_size_or_offset != NULL);