>From 469f9f3685c4026e79ccc8f3fb35c3eb25fd3716 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Mon, 7 Jun 2021 00:56:50 +0200 Subject: [PATCH 2/3] scratch_buffer: Avoid conflict with prepr. macros owned by the system. * lib/scratch_buffer.h: Don't include . Define _GL_LIKELY, _GL_UNLIKELY. Include malloc/scratch_buffer.gl.h instead of malloc/scratch_buffer.h. * modules/scratch_buffer (Depends-on): Add builtin-expect. (Makefile.am): Arrange to create malloc/scratch_buffer.gl.h from malloc/scratch_buffer.h. --- ChangeLog | 10 ++++++++++ lib/scratch_buffer.h | 10 +++++++--- modules/scratch_buffer | 15 +++++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index b354ff0..16132b1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,15 @@ 2021-06-06 Bruno Haible + scratch_buffer: Avoid conflict with prepr. macros owned by the system. + * lib/scratch_buffer.h: Don't include . Define + _GL_LIKELY, _GL_UNLIKELY. Include malloc/scratch_buffer.gl.h instead of + malloc/scratch_buffer.h. + * modules/scratch_buffer (Depends-on): Add builtin-expect. + (Makefile.am): Arrange to create malloc/scratch_buffer.gl.h from + malloc/scratch_buffer.h. + +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. diff --git a/lib/scratch_buffer.h b/lib/scratch_buffer.h index 7bb6fe8..8873577 100644 --- a/lib/scratch_buffer.h +++ b/lib/scratch_buffer.h @@ -110,14 +110,18 @@ extern void *scratch_buffer_dupfree (struct scratch_buffer *buffer, /* The implementation is imported from glibc. */ -#include - /* Avoid possible conflicts with symbols exported by the GNU libc. */ #define __libc_scratch_buffer_dupfree gl_scratch_buffer_dupfree #define __libc_scratch_buffer_grow gl_scratch_buffer_grow #define __libc_scratch_buffer_grow_preserve gl_scratch_buffer_grow_preserve #define __libc_scratch_buffer_set_array_size gl_scratch_buffer_set_array_size -#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 + +#include #endif /* _GL_SCRATCH_BUFFER_H */ diff --git a/modules/scratch_buffer b/modules/scratch_buffer index cf83ab5..ede77a9 100644 --- a/modules/scratch_buffer +++ b/modules/scratch_buffer @@ -11,6 +11,7 @@ lib/malloc/scratch_buffer_set_array_size.c Depends-on: c99 +builtin-expect libc-config stdbool stddef @@ -21,6 +22,20 @@ free-posix configure.ac: Makefile.am: +BUILT_SOURCES += malloc/scratch_buffer.gl.h + +malloc/scratch_buffer.gl.h: malloc/scratch_buffer.h + $(AM_V_GEN)rm -f $@-t $@ && \ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ + sed -e 's|__always_inline|inline _GL_ATTRIBUTE_ALWAYS_INLINE|g' \ + -e 's|__glibc_likely|_GL_LIKELY|g' \ + -e 's|__glibc_unlikely|_GL_UNLIKELY|g' \ + -e '/libc_hidden_proto/d' \ + < $(srcdir)/malloc/scratch_buffer.h; \ + } > $@-t && \ + mv $@-t $@ +MOSTLYCLEANFILES += malloc/scratch_buffer.gl.h malloc/scratch_buffer.gl.h-t + lib_SOURCES += malloc/scratch_buffer_dupfree.c \ malloc/scratch_buffer_grow.c \ malloc/scratch_buffer_grow_preserve.c \ -- 2.7.4