]> Savannah Git Hosting - gnulib.git/commitdiff
scratch_buffer: Avoid conflict with prepr. macros owned by the system.
authorBruno Haible <bruno@clisp.org>
Sun, 6 Jun 2021 22:56:50 +0000 (00:56 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 6 Jun 2021 23:19:32 +0000 (01:19 +0200)
* lib/scratch_buffer.h: Don't include <libc-config.h>. 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
lib/scratch_buffer.h
modules/scratch_buffer

index b354ff0515c8fda2d9839c8dc9c77ad241fcc9ee..16132b1884635734432cf52dd6f844de3072aeca 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2021-06-06  Bruno Haible  <bruno@clisp.org>
+
+       scratch_buffer: Avoid conflict with prepr. macros owned by the system.
+       * lib/scratch_buffer.h: Don't include <libc-config.h>. 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  <bruno@clisp.org>
 
        dynarray: Avoid conflict with preprocessor macros owned by the system.
index 7bb6fe8aa32167d436a9bf576127f2a9845ee45a..88735771d2dfed89d206566d6a29217834c8c625 100644 (file)
@@ -110,14 +110,18 @@ extern void *scratch_buffer_dupfree (struct scratch_buffer *buffer,
 
 /* The implementation is imported from glibc.  */
 
-#include <libc-config.h>
-
 /* 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 <malloc/scratch_buffer.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
+
+#include <malloc/scratch_buffer.gl.h>
 
 #endif /* _GL_SCRATCH_BUFFER_H */
index cf83ab5b8853641b79c81f983c552f57489ef494..ede77a992419facbe73cdb67ece62b246858a035 100644 (file)
@@ -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 \