From 0c907f7da13232908f05c415b8cec56024071906 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 7 Jun 2021 00:54:25 +0200 Subject: [PATCH 1/3] dynarray: Avoid conflict with preprocessor macros owned by the system. * lib/dynarray.h: Don't include . 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 | 12 ++++++++++++ lib/dynarray.h | 10 +++++++--- modules/dynarray | 25 +++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 79fc6ff..b354ff0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,17 @@ 2021-06-06 Bruno Haible + dynarray: Avoid conflict with preprocessor macros owned by the system. + * lib/dynarray.h: Don't include . 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 + glob-h: Avoid conflict with preprocessor macros owned by the system. This fixes a compilation error on DragonFly BSD 6.0. * lib/glob.in.h: Don't include . Don't define __USE_GNU. diff --git a/lib/dynarray.h b/lib/dynarray.h index 375d3da..ec64273 100644 --- a/lib/dynarray.h +++ b/lib/dynarray.h @@ -257,18 +257,22 @@ static DYNARRAY_ELEMENT * #if defined DYNARRAY_STRUCT || defined DYNARRAY_ELEMENT || defined DYNARRAY_PREFIX -# include +# 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 +# include /* Define the instantiation, specified through DYNARRAY_STRUCT DYNARRAY_ELEMENT DYNARRAY_PREFIX etc. */ -# include +# include #else diff --git a/modules/dynarray b/modules/dynarray index dcdcba4..7fd444f 100644 --- a/modules/dynarray +++ b/modules/dynarray @@ -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|||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 \ -- 2.7.4