From: Bruno Haible Date: Sun, 3 May 2026 11:50:43 +0000 (+0200) Subject: array-map: Use the counted_by attribute. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1479336e8a3147b05adcc6f6aaffbddd2da772a8;p=thirdparty%2Fgnulib.git array-map: Use the counted_by attribute. * lib/gl_array_map.c (struct gl_map_impl): Mark the pairs field as counted_by count. Swap these fields (needed for clang). (gl_array_nx_getput): Increase map->count before writing into map->pairs. --- diff --git a/ChangeLog b/ChangeLog index 7bb7e0b36d..212bdd4514 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2026-05-03 Bruno Haible + + array-map: Use the counted_by attribute. + * lib/gl_array_map.c (struct gl_map_impl): Mark the pairs field as + counted_by count. Swap these fields (needed for clang). + (gl_array_nx_getput): Increase map->count before writing into + map->pairs. + 2026-05-03 Bruno Haible array-list: Use the counted_by attribute. diff --git a/lib/gl_array_map.c b/lib/gl_array_map.c index efcff86177..e4c897fffd 100644 --- a/lib/gl_array_map.c +++ b/lib/gl_array_map.c @@ -38,10 +38,11 @@ struct pair struct gl_map_impl { struct gl_map_impl_base base; + size_t count; /* An array of ALLOCATED pairs, of which the first COUNT are used. 0 <= COUNT <= ALLOCATED. */ - struct pair *pairs; - size_t count; + struct pair *pairs + _GL_ATTRIBUTE_COUNTED_BY (count); size_t allocated; }; @@ -150,9 +151,9 @@ gl_array_nx_getput (gl_map_t map, const void *key, const void *value, if (grow (map) < 0) return -1; struct pair *pairs = map->pairs; + map->count = count + 1; pairs[count].key = key; pairs[count].value = value; - map->count = count + 1; return 1; } }