]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
array-map: Use the counted_by attribute.
authorBruno Haible <bruno@clisp.org>
Sun, 3 May 2026 11:50:43 +0000 (13:50 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 3 May 2026 13:34:22 +0000 (15:34 +0200)
* 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.

ChangeLog
lib/gl_array_map.c

index 7bb7e0b36d9ae062aac548c9f3e5104554dfda43..212bdd45145329f79f0969d1df16d0c3fe261cfd 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2026-05-03  Bruno Haible  <bruno@clisp.org>
+
+       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  <bruno@clisp.org>
 
        array-list: Use the counted_by attribute.
index efcff8617742c243a797e5e15f6f1a265c0b7607..e4c897fffda94f338f9eecc05969efb8a273e7fc 100644 (file)
@@ -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;
     }
 }