libmalcontent-ui: Add an explicit array length argument to a function

This aligns the copy of the API here with what’s being proposed in
appstream-glib (https://github.com/hughsie/appstream-glib/pull/364). In
a few commits’ time, this copy will be deprecated.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
This commit is contained in:
Philip Withnall 2020-05-21 16:03:46 +01:00
parent 150d303d39
commit 2a87b85fe1
3 changed files with 16 additions and 6 deletions

View File

@ -509,9 +509,16 @@ static guint content_rating_ages[GS_CONTENT_RATING_SYSTEM_LAST][7] = {
}; };
const guint * const guint *
gs_utils_content_rating_get_ages (GsContentRatingSystem system) gs_utils_content_rating_get_ages (GsContentRatingSystem system, gsize *length_out)
{ {
g_assert (system < GS_CONTENT_RATING_SYSTEM_LAST); g_return_val_if_fail ((int) system < GS_CONTENT_RATING_SYSTEM_LAST, NULL);
g_return_val_if_fail (length_out != NULL, NULL);
/* IARC is the fallback for everything */
if (system == GS_CONTENT_RATING_SYSTEM_UNKNOWN)
system = GS_CONTENT_RATING_SYSTEM_IARC;
*length_out = g_strv_length ((gchar **) content_rating_strings[system]);
return content_rating_ages[system]; return content_rating_ages[system];
} }

View File

@ -52,7 +52,7 @@ gchar *gs_utils_content_rating_age_to_str (GsContentRatingSystem system,
GsContentRatingSystem gs_utils_content_rating_system_from_locale (const gchar *locale); GsContentRatingSystem gs_utils_content_rating_system_from_locale (const gchar *locale);
const gchar *gs_content_rating_system_to_str (GsContentRatingSystem system); const gchar *gs_content_rating_system_to_str (GsContentRatingSystem system);
gchar **gs_utils_content_rating_get_values (GsContentRatingSystem system); gchar **gs_utils_content_rating_get_values (GsContentRatingSystem system);
const guint *gs_utils_content_rating_get_ages (GsContentRatingSystem system); const guint *gs_utils_content_rating_get_ages (GsContentRatingSystem system, gsize *length_out);
guint as_content_rating_id_value_to_csm_age (const gchar *id, MctAppFilterOarsValue value); guint as_content_rating_id_value_to_csm_age (const gchar *id, MctAppFilterOarsValue value);
MctAppFilterOarsValue as_content_rating_id_csm_age_to_value (const gchar *id, guint age); MctAppFilterOarsValue as_content_rating_id_csm_age_to_value (const gchar *id, guint age);

View File

@ -319,7 +319,7 @@ update_categories_from_language (MctUserControls *self)
g_auto(GStrv) entries = NULL; g_auto(GStrv) entries = NULL;
const gchar *rating_system_str; const gchar *rating_system_str;
const guint *ages; const guint *ages;
gsize i; gsize i, n_ages;
g_autofree gchar *disabled_action = NULL; g_autofree gchar *disabled_action = NULL;
rating_system = get_content_rating_system (self); rating_system = get_content_rating_system (self);
@ -328,7 +328,7 @@ update_categories_from_language (MctUserControls *self)
g_debug ("Using rating system %s", rating_system_str); g_debug ("Using rating system %s", rating_system_str);
entries = gs_utils_content_rating_get_values (rating_system); entries = gs_utils_content_rating_get_values (rating_system);
ages = gs_utils_content_rating_get_ages (rating_system); ages = gs_utils_content_rating_get_ages (rating_system, &n_ages);
/* Fill in the age menu */ /* Fill in the age menu */
g_menu_remove_all (self->age_menu); g_menu_remove_all (self->age_menu);
@ -346,6 +346,8 @@ update_categories_from_language (MctUserControls *self)
g_menu_append (self->age_menu, entries[i], action); g_menu_append (self->age_menu, entries[i], action);
} }
g_assert (i == n_ages);
} }
/* Returns a human-readable but untranslated string, not suitable /* Returns a human-readable but untranslated string, not suitable
@ -684,13 +686,14 @@ on_set_age_action_activated (GSimpleAction *action,
const guint *ages; const guint *ages;
guint age; guint age;
guint i; guint i;
gsize n_ages;
self = MCT_USER_CONTROLS (user_data); self = MCT_USER_CONTROLS (user_data);
age = g_variant_get_uint32 (param); age = g_variant_get_uint32 (param);
rating_system = get_content_rating_system (self); rating_system = get_content_rating_system (self);
entries = gs_utils_content_rating_get_values (rating_system); entries = gs_utils_content_rating_get_values (rating_system);
ages = gs_utils_content_rating_get_ages (rating_system); ages = gs_utils_content_rating_get_ages (rating_system, &n_ages);
/* Update the button */ /* Update the button */
if (age == oars_disabled_age) if (age == oars_disabled_age)