all: merge branch 'th/nm-g-array-index'

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1776
This commit is contained in:
Thomas Haller 2023-10-30 18:07:32 +01:00
commit 67faab3f4d
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
5 changed files with 29 additions and 8 deletions

View file

@ -355,7 +355,7 @@ _nm_setting_class_commit(NMSettingClass *setting_class,
guint k;
nm_assert(!_nm_sett_info_property_find_in_array(
nm_g_array_index_p(properties_override, NMSettInfoProperty, 0),
nm_g_array_first_p(properties_override, NMSettInfoProperty),
i,
p->name));
for (k = 0; k < n_property_specs; k++) {
@ -374,7 +374,7 @@ _nm_setting_class_commit(NMSettingClass *setting_class,
NMSettInfoProperty *p;
if (_nm_sett_info_property_find_in_array(
nm_g_array_index_p(properties_override, NMSettInfoProperty, 0),
nm_g_array_first_p(properties_override, NMSettInfoProperty),
override_len,
name))
continue;

View file

@ -325,7 +325,7 @@ _nm_utils_enum_get_values(GType type, int from, int to)
GPtrArray *values = g_ptr_array_sized_new(values_full->len + 1);
for (i = 0; i < values_full->len; i++) {
NMUtilsEnumValueInfoFull *v = &g_array_index(values_full, NMUtilsEnumValueInfoFull, i);
NMUtilsEnumValueInfoFull *v = &nm_g_array_index(values_full, NMUtilsEnumValueInfoFull, i);
g_ptr_array_add(values, (gpointer) v->nick);
}
@ -418,8 +418,9 @@ _nm_utils_enum_get_values_full(GType type,
g_array_set_clear_func(array, (GDestroyNotify) _free_value_info_full);
for (i = 0; i < array->len; i++) {
NMUtilsEnumValueInfoFull *vi_full = &g_array_index(array, NMUtilsEnumValueInfoFull, i);
GPtrArray *aliases = g_ptr_array_new();
NMUtilsEnumValueInfoFull *vi_full =
&nm_g_array_index(array, NMUtilsEnumValueInfoFull, i);
GPtrArray *aliases = g_ptr_array_new();
const NMUtilsEnumValueInfo *vi;
for (vi = value_infos; vi && vi->nick; vi++) {

View file

@ -1941,7 +1941,27 @@ nm_g_array_unref(GArray *arr)
* When accessing index zero, then this returns NULL if-and-only-if
* "arr" is NULL or "arr->data" is NULL. In all other cases, this
* returns the pointer &((Type*) arr->data)[idx]. Note that the pointer
* may not be followed, if "idx" is equal to "arr->len". */
* may not be followed, if "idx" is equal to "arr->len".
*
* The reason to allow access one element past the length is the
* following usage:
*
* ptr = nm_g_array_index_p(arr, Type, 0);
* end = nm_g_array_index_p(arr, Type, length);
* for (; ptr < end; ptr++) { ... }
*
* Another usage is to get a buffer, if the length might be zero. If
* length is zero, you cannot dereference the pointer, but it can be convenient
* to not require special casing:
*
* // length might be zero.
* nm_memdup(nm_g_array_index_p(arr, Type, length), sizeof(Type) * length);
*
* Note that in C, it's valid point one past the end of an array. So getting
* a pointer at index "length" is valid, and what nm_g_array_index_p() allows.
* If you don't need that, nm_g_array_index() is usually preferable,
* because it asserts against access at index "length".
*/
#define nm_g_array_index_p(arr, Type, idx) \
({ \
const GArray *const _arr_55 = (arr); \

View file

@ -266,7 +266,7 @@ _append_enum_valid_values(GType g_type,
GArray *values = _nm_utils_enum_get_values_full(g_type, min, max, value_infos);
for (i = 0; i < values->len; i++) {
NMUtilsEnumValueInfoFull *val = &g_array_index(values, NMUtilsEnumValueInfoFull, i);
NMUtilsEnumValueInfoFull *val = &nm_g_array_index(values, NMUtilsEnumValueInfoFull, i);
g_string_assign(names, val->nick);

View file

@ -552,7 +552,7 @@ nmt_8021x_fields_constructed(GObject *object)
entry.id = (char *) eap_method_descs[i].id;
g_array_append_val(entries, entry);
}
priv->authentication = nmt_newt_popup_new(nm_g_array_index_p(entries, NmtNewtPopupEntry, 0));
priv->authentication = nmt_newt_popup_new(nm_g_array_first_p(entries, NmtNewtPopupEntry));
nmt_editor_grid_append(grid, "Authentication", NMT_NEWT_WIDGET(priv->authentication), NULL);
widget = nmt_newt_stack_new();