]> Savannah Git Hosting - gnulib.git/commitdiff
dynarray: Avoid conflict with preprocessor macros owned by the system.
authorBruno Haible <bruno@clisp.org>
Sun, 6 Jun 2021 22:54:25 +0000 (00:54 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 6 Jun 2021 23:19:32 +0000 (01:19 +0200)
* lib/dynarray.h: Don't include <libc-config.h>. Define _GL_LIKELY,
_GL_UNLIKELY. Include malloc/dynarray.gl.h instead of malloc/dynarray.h.
Include malloc/dynarray-skeleton.gl.h instead of
malloc/dynarray-skeleton.c.
* modules/dynarray (Depends-on): Add builtin-expect.
(Makefile.am): Arrange to create malloc/dynarray.gl.h from
malloc/dynarray.h and malloc/dynarray-skeleton.gl.h from
malloc/dynarray-skeleton.c.

ChangeLog
lib/dynarray.h
modules/dynarray

index 79fc6ff0ddcca511ab6f0fdfafa96552fdc1d244..b354ff0515c8fda2d9839c8dc9c77ad241fcc9ee 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2021-06-06  Bruno Haible  <bruno@clisp.org>
+
+       dynarray: Avoid conflict with preprocessor macros owned by the system.
+       * lib/dynarray.h: Don't include <libc-config.h>. Define _GL_LIKELY,
+       _GL_UNLIKELY. Include malloc/dynarray.gl.h instead of malloc/dynarray.h.
+       Include malloc/dynarray-skeleton.gl.h instead of
+       malloc/dynarray-skeleton.c.
+       * modules/dynarray (Depends-on): Add builtin-expect.
+       (Makefile.am): Arrange to create malloc/dynarray.gl.h from
+       malloc/dynarray.h and malloc/dynarray-skeleton.gl.h from
+       malloc/dynarray-skeleton.c.
+
 2021-06-06  Bruno Haible  <bruno@clisp.org>
 
        glob-h: Avoid conflict with preprocessor macros owned by the system.
index 375d3da28437d6ccaac91a8187af3b8d436028d8..ec64273b3a1eb61a1da36aa3e52796c4f2ece360 100644 (file)
@@ -257,18 +257,22 @@ static DYNARRAY_ELEMENT *
 
 #if defined DYNARRAY_STRUCT || defined DYNARRAY_ELEMENT || defined DYNARRAY_PREFIX
 
-# include <libc-config.h>
+# ifndef _GL_LIKELY
+/* Rely on __builtin_expect, as provided by the module 'builtin-expect'.  */
+#  define _GL_LIKELY(cond) __builtin_expect ((cond), 1)
+#  define _GL_UNLIKELY(cond) __builtin_expect ((cond), 0)
+# endif
 
 /* Define auxiliary structs and declare auxiliary functions, common to all
    instantiations of dynarray.  */
-# include <malloc/dynarray.h>
+# include <malloc/dynarray.gl.h>
 
 /* Define the instantiation, specified through
      DYNARRAY_STRUCT
      DYNARRAY_ELEMENT
      DYNARRAY_PREFIX
    etc.  */
-# include <malloc/dynarray-skeleton.c>
+# include <malloc/dynarray-skeleton.gl.h>
 
 #else
 
index dcdcba4ef5548264744dcdae2974acc65c0460ca..7fd444f5225f3fb35b5bb5f99a7161253a763f7f 100644 (file)
@@ -13,6 +13,7 @@ lib/malloc/dynarray_resize_clear.c
 
 Depends-on:
 c99
+builtin-expect
 libc-config
 stdbool
 stddef
@@ -21,6 +22,30 @@ intprops
 configure.ac:
 
 Makefile.am:
+BUILT_SOURCES += malloc/dynarray.gl.h malloc/dynarray-skeleton.gl.h
+
+malloc/dynarray.gl.h: malloc/dynarray.h
+       $(AM_V_GEN)rm -f $@-t $@ && \
+       { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
+         sed -e '/libc_hidden_proto/d' < $(srcdir)/malloc/dynarray.h; \
+       } > $@-t && \
+       mv $@-t $@
+MOSTLYCLEANFILES += malloc/dynarray.gl.h malloc/dynarray.gl.h-t
+
+malloc/dynarray-skeleton.gl.h: malloc/dynarray-skeleton.c
+       $(AM_V_GEN)rm -f $@-t $@ && \
+       { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
+         sed -e 's|<malloc/dynarray\.h>|<malloc/dynarray.gl.h>|g' \
+             -e 's|__attribute_maybe_unused__|_GL_ATTRIBUTE_MAYBE_UNUSED|g' \
+             -e 's|__attribute_nonnull__|_GL_ATTRIBUTE_NONNULL|g' \
+             -e 's|__attribute_warn_unused_result__|_GL_ATTRIBUTE_NODISCARD|g' \
+             -e 's|__glibc_likely|_GL_LIKELY|g' \
+             -e 's|__glibc_unlikely|_GL_UNLIKELY|g' \
+             < $(srcdir)/malloc/dynarray-skeleton.c; \
+       } > $@-t && \
+       mv $@-t $@
+MOSTLYCLEANFILES += malloc/dynarray-skeleton.gl.h malloc/dynarray-skeleton.gl.h-t
+
 lib_SOURCES += malloc/dynarray_at_failure.c \
                malloc/dynarray_emplace_enlarge.c \
                malloc/dynarray_finalize.c \