Re: Gnulib's use of _Atomic, and hamt

Bruno Haible via Gnulib discussion list <[email protected]>
Newsgroups gmane.comp.lib.gnulib.bugs
Message-ID <11404941.nnTZe4vzsl@cagnes>
Paul Eggert wrote:
> I attempted to fix these problems by installing the attached patches.

This produced a compilation error on many platforms:

gcc -std=gnu23 -DHAVE_CONFIG_H -DEXEEXT=\"\" -DEXEEXT=\"\" -DNO_XMALLOC -DEXEEXT=\"\" -I. -I../../gllib -I..  -DGNULIB_STRICT_CHECKING=1 -Wall -DCONTINUE_AFTER_ASSERT -fvisibility=hidden -g -O2 -MT hamt.o -MD -MP -MF $depbase.Tpo -c -o hamt.o ../../gllib/hamt.c &&\
mv -f $depbase.Tpo $depbase.Po
../../gllib/hamt.c: In function 'free_element':
../../gllib/hamt.c:195:24: error: passing argument 1 of 'dec_ref_counter' from incompatible pointer type [-Wincompatible-pointer-types]
  195 |   if (dec_ref_counter (&elt->ref_count))
      |                        ^~~~~~~~~~~~~~~
      |                        |
      |                        _Atomic size_t * {aka _Atomic long unsigned int *}
../../gllib/hamt.c:87:31: note: expected 'ref_counter *' {aka 'long unsigned int *'} but argument is of type '_Atomic size_t *' {aka '_Atomic long unsigned int *'}
   87 | dec_ref_counter (ref_counter *counter)
      |                  ~~~~~~~~~~~~~^~~~~~~

Fixed as follows:


2026-08-12  Bruno Haible  <[email protected]>

	hamt: Fix compilation error (regression 2026-08-10).
	* lib/hamt.c (ref_counter): Use GL_HAMT_ATOMIC instead of
	GL_HAMT_THREAD_SAFE.

diff --git a/lib/hamt.c b/lib/hamt.c
index fa4bed98d1..095a47665b 100644
--- a/lib/hamt.c
+++ b/lib/hamt.c
@@ -35,11 +35,7 @@
    A thread must not modify an entry or its children (!) if its
    reference count implies that the entry is shared by at least two
    hamts.  */
-typedef
-#if GL_HAMT_THREAD_SAFE
-_Atomic
-#endif
-size_t ref_counter;
+typedef GL_HAMT_ATOMIC (size_t) ref_counter;
 
 /***************/
 /* Entry Types */
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.