]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
array-omap: Use the counted_by attribute.
authorBruno Haible <bruno@clisp.org>
Sun, 3 May 2026 11:52:05 +0000 (13:52 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 3 May 2026 13:34:23 +0000 (15:34 +0200)
* lib/gl_array_omap.c (struct gl_omap_impl): Mark the pairs field as
counted_by count. Swap these fields (needed for clang).
(gl_array_nx_add_at): Increase map->count before writing into
map->pairs.

ChangeLog
lib/gl_array_omap.c

index 212bdd45145329f79f0969d1df16d0c3fe261cfd..36c0ec442b684d138c8ef976debf9d31edb8d407 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2026-05-03  Bruno Haible  <bruno@clisp.org>
+
+       array-omap: Use the counted_by attribute.
+       * lib/gl_array_omap.c (struct gl_omap_impl): Mark the pairs field as
+       counted_by count. Swap these fields (needed for clang).
+       (gl_array_nx_add_at): Increase map->count before writing into
+       map->pairs.
+
 2026-05-03  Bruno Haible  <bruno@clisp.org>
 
        array-map: Use the counted_by attribute.
index 600ac472c8f389185057fa4c378ec346318cea9e..be1b9151adcdb28561f27c6eeaa7c4c29e335bb6 100644 (file)
@@ -37,10 +37,11 @@ struct pair
 struct gl_omap_impl
 {
   struct gl_omap_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;
 };
 
@@ -205,11 +206,11 @@ gl_array_nx_add_at (gl_omap_t map, size_t position,
     if (grow (map) < 0)
       return -1;
   struct pair *pairs = map->pairs;
+  map->count = count + 1;
   for (size_t i = count; i > position; i--)
     pairs[i] = pairs[i - 1];
   pairs[position].key = key;
   pairs[position].value = value;
-  map->count = count + 1;
   return 1;
 }