]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
array-set: Use the counted_by attribute.
authorBruno Haible <bruno@clisp.org>
Sun, 3 May 2026 11:54:51 +0000 (13:54 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 3 May 2026 13:34:23 +0000 (15:34 +0200)
* lib/gl_array_set.c (struct gl_set_impl): Mark the elements field as
counted_by count. Swap these fields (needed for clang).
(gl_array_nx_add): Increase set->count before writing into
set->elements.

ChangeLog
lib/gl_array_set.c

index 3d2089cc76590a6de8eacff959064321cad85112..453e2ac22bbacbc24f3a9349b32682b7d09d0dde 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2026-05-03  Bruno Haible  <bruno@clisp.org>
+
+       array-set: Use the counted_by attribute.
+       * lib/gl_array_set.c (struct gl_set_impl): Mark the elements field as
+       counted_by count. Swap these fields (needed for clang).
+       (gl_array_nx_add): Increase set->count before writing into
+       set->elements.
+
 2026-05-03  Bruno Haible  <bruno@clisp.org>
 
        array-oset: Use the counted_by attribute.
index e34d5962a192fdf692501f6f2cf6ff485a970c5e..0348627fb7938911651466980dabae10933a8a1b 100644 (file)
 struct gl_set_impl
 {
   struct gl_set_impl_base base;
+  size_t count;
   /* An array of ALLOCATED elements, of which the first COUNT are used.
      0 <= COUNT <= ALLOCATED.  */
-  const void **elements;
-  size_t count;
+  const void **elements
+    _GL_ATTRIBUTE_COUNTED_BY (count);
   size_t allocated;
 };
 
@@ -124,8 +125,8 @@ gl_array_nx_add (gl_set_t set, const void *elt)
       if (count == set->allocated)
         if (grow (set) < 0)
           return -1;
-      set->elements[count] = elt;
       set->count = count + 1;
+      set->elements[count] = elt;
       return 1;
     }
 }