grel: Fix some -Wsign-conversion warnings in GRelation

The internals of this struct are private, so we have some freedom to fix
the types used to be wider (to allow addressing all of memory) and
correctly unsigned.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>

Helps: #3405
This commit is contained in:
Philip Withnall 2025-04-10 18:34:03 +01:00
parent 2dd6271a9a
commit 03c766879a
No known key found for this signature in database
GPG Key ID: C5C42CFB268637CA

View File

@ -97,13 +97,13 @@ typedef struct _GRealTuples GRealTuples;
struct _GRelation
{
gint fields;
gint current_field;
size_t fields;
size_t current_field;
GHashTable *all_tuples;
GHashTable **hashed_tuple_tables;
gint count;
size_t count;
};
/**
@ -195,10 +195,13 @@ GRelation*
g_relation_new (gint fields)
{
GRelation* rel = g_new0 (GRelation, 1);
size_t unsigned_fields;
rel->fields = fields;
rel->all_tuples = g_hash_table_new (tuple_hash (fields), tuple_equal (fields));
rel->hashed_tuple_tables = g_new0 (GHashTable*, fields);
unsigned_fields = (size_t) fields;
rel->fields = unsigned_fields;
rel->all_tuples = g_hash_table_new (tuple_hash (unsigned_fields), tuple_equal (unsigned_fields));
rel->hashed_tuple_tables = g_new0 (GHashTable*, unsigned_fields);
return rel;
}
@ -232,11 +235,9 @@ g_relation_free_array (gpointer key, gpointer value, gpointer user_data)
void
g_relation_destroy (GRelation *relation)
{
gint i;
if (relation)
{
for (i = 0; i < relation->fields; i += 1)
for (size_t i = 0; i < relation->fields; i += 1)
{
if (relation->hashed_tuple_tables[i])
{
@ -295,11 +296,10 @@ g_relation_insert (GRelation *relation,
{
gpointer* tuple = g_slice_alloc (relation->fields * sizeof (gpointer));
va_list args;
gint i;
va_start (args, relation);
for (i = 0; i < relation->fields; i += 1)
for (size_t i = 0; i < relation->fields; i += 1)
tuple[i] = va_arg (args, gpointer);
va_end (args);
@ -308,7 +308,7 @@ g_relation_insert (GRelation *relation,
relation->count += 1;
for (i = 0; i < relation->fields; i += 1)
for (size_t i = 0; i < relation->fields; i += 1)
{
GHashTable *table;
gpointer key;
@ -339,11 +339,10 @@ g_relation_delete_tuple (gpointer tuple_key,
{
gpointer *tuple = (gpointer*) tuple_value;
GRelation *relation = (GRelation *) user_data;
gint j;
g_assert (tuple_key == tuple_value);
for (j = 0; j < relation->fields; j += 1)
for (size_t j = 0; j < relation->fields; j += 1)
{
GHashTable *one_table = relation->hashed_tuple_tables[j];
gpointer one_key;
@ -389,7 +388,7 @@ g_relation_delete (GRelation *relation,
{
GHashTable *table;
GHashTable *key_table;
gint count;
size_t count;
g_return_val_if_fail (relation != NULL, 0);
@ -423,7 +422,7 @@ g_relation_select_tuple (gpointer tuple_key,
{
gpointer *tuple = (gpointer*) tuple_value;
GRealTuples *tuples = (GRealTuples*) user_data;
gint stride = sizeof (gpointer) * tuples->width;
size_t stride = sizeof (gpointer) * tuples->width;
g_assert (tuple_key == tuple_value);
@ -456,7 +455,7 @@ g_relation_select (GRelation *relation,
GHashTable *table;
GHashTable *key_table;
GRealTuples *tuples;
gint count;
size_t count;
g_return_val_if_fail (relation != NULL, NULL);
@ -477,7 +476,7 @@ g_relation_select (GRelation *relation,
g_hash_table_foreach (key_table, g_relation_select_tuple, tuples);
g_assert (count == tuples->len);
g_assert (count == (size_t) tuples->len);
return (GTuples*)tuples;
}
@ -536,12 +535,11 @@ g_relation_exists (GRelation *relation, ...)
{
gpointer *tuple = g_slice_alloc (relation->fields * sizeof (gpointer));
va_list args;
gint i;
gboolean result;
va_start(args, relation);
for (i = 0; i < relation->fields; i += 1)
for (size_t i = 0; i < relation->fields; i += 1)
tuple[i] = va_arg(args, gpointer);
va_end(args);
@ -611,14 +609,13 @@ g_relation_print_one (gpointer tuple_key,
gpointer tuple_value,
gpointer user_data)
{
gint i;
GString *gstring;
GRelation* rel = (GRelation*) user_data;
gpointer* tuples = (gpointer*) tuple_value;
gstring = g_string_new ("[");
for (i = 0; i < rel->fields; i += 1)
for (size_t i = 0; i < rel->fields; i += 1)
{
g_string_append_printf (gstring, "%p", tuples[i]);
@ -658,20 +655,18 @@ g_relation_print_index (gpointer tuple_key,
void
g_relation_print (GRelation *relation)
{
gint i;
g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "*** all tuples (%d)", relation->count);
g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "*** all tuples (%" G_GSIZE_FORMAT ")", relation->count);
g_hash_table_foreach (relation->all_tuples,
g_relation_print_one,
relation);
for (i = 0; i < relation->fields; i += 1)
for (size_t i = 0; i < relation->fields; i += 1)
{
if (relation->hashed_tuple_tables[i] == NULL)
continue;
g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "*** index %d", i);
g_log (G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "*** index %" G_GSIZE_FORMAT, i);
g_hash_table_foreach (relation->hashed_tuple_tables[i],
g_relation_print_index,