summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog21
-rw-r--r--lib/fnmatch.c4
-rw-r--r--lib/gl_anytreehash_list1.h4
-rw-r--r--lib/glob.c4
-rw-r--r--lib/grantpt.c1
-rw-r--r--lib/memmem.c4
-rw-r--r--lib/regex_internal.h6
-rw-r--r--lib/scandir.c4
-rw-r--r--lib/strstr.c4
-rw-r--r--m4/builtin-expect.m434
-rw-r--r--modules/avltreehash-list1
-rw-r--r--modules/builtin-expect20
-rw-r--r--modules/fnmatch1
-rw-r--r--modules/glob1
-rw-r--r--modules/grantpt1
-rw-r--r--modules/memmem-simple1
-rw-r--r--modules/rbtreehash-list1
-rw-r--r--modules/scandir2
-rw-r--r--modules/strstr-simple1
19 files changed, 85 insertions, 30 deletions
diff --git a/ChangeLog b/ChangeLog
index f3522e7124..451e1d5bb8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,24 @@
+2016-12-16 Paul Eggert <eggert@cs.ucla.edu>
+
+ builtin-expect: new module
+ Fix fnmatch to use it.
+ Problem reported for z/OS by Daniel Richard G.
+ * lib/fnmatch.c (__builtin_expect):
+ * lib/glob.c (__builtin_expect):
+ * lib/grantpt.c (__builtin_expect) [!_LIBC]:
+ * lib/memmem.c (__builtin_expect) [!_LIBC]:
+ * lib/scandir.c (__builtin_expect):
+ * lib/strstr.c (__builtin_expect) [!_LIBC]:
+ Remove macro; config.h now does this.
+ * lib/gl_anytreehash_list1.h (add_to_bucket):
+ * lib/regex_internal.h (BE):
+ Assume __builtin_expect.
+ * m4/builtin-expect.m4, modules/builtin-expect: New files.
+ * modules/avltreehash-list, modules/fnmatch, modules/glob:
+ * modules/grantpt, modules/memmem-simple, modules/rbtreehash-list:
+ * modules/scandir, modules/strstr-simple:
+ Depend on builtin-expect.
+
2016-12-15 Bruno Haible <bruno@clisp.org>
init.sh: Add possibility to not delete temporary files.
diff --git a/lib/fnmatch.c b/lib/fnmatch.c
index 75b85c05db..cc690bba2d 100644
--- a/lib/fnmatch.c
+++ b/lib/fnmatch.c
@@ -22,10 +22,6 @@
# define _GNU_SOURCE 1
#endif
-#if ! defined __builtin_expect && (!defined __GNUC__ || __GNUC__ < 3)
-# define __builtin_expect(expr, expected) (expr)
-#endif
-
#include <fnmatch.h>
#include <alloca.h>
diff --git a/lib/gl_anytreehash_list1.h b/lib/gl_anytreehash_list1.h
index 11578ed6b1..cf44b59688 100644
--- a/lib/gl_anytreehash_list1.h
+++ b/lib/gl_anytreehash_list1.h
@@ -185,10 +185,8 @@ add_to_bucket (gl_list_t list, gl_list_node_t new_node)
return 0;
}
/* Tell GCC that the likely return value is 0. */
-#if __GNUC__ >= 3
-# define add_to_bucket(list,node) \
+#define add_to_bucket(list,node) \
__builtin_expect ((add_to_bucket) (list, node), 0)
-#endif
/* Remove a node from the hash table structure.
If duplicates are allowed, this function performs in average time
diff --git a/lib/glob.c b/lib/glob.c
index 5b2ff9d623..4a7dab2b42 100644
--- a/lib/glob.c
+++ b/lib/glob.c
@@ -222,10 +222,6 @@ convert_dirent64 (const struct dirent64 *source)
# endif
#endif
-#if ! defined __builtin_expect && __GNUC__ < 3
-# define __builtin_expect(expr, expected) (expr)
-#endif
-
#ifndef __glibc_unlikely
# define __glibc_unlikely(expr) __builtin_expect (expr, 0)
#endif
diff --git a/lib/grantpt.c b/lib/grantpt.c
index e4c1b9181e..2af879ab71 100644
--- a/lib/grantpt.c
+++ b/lib/grantpt.c
@@ -35,7 +35,6 @@
#include "pty-private.h"
#ifndef _LIBC
-# define __builtin_expect(expr,val) (expr)
# define __set_errno(e) errno = (e)
# define __dup2 dup2
# define __fork fork
diff --git a/lib/memmem.c b/lib/memmem.c
index 255490e675..a77c107583 100644
--- a/lib/memmem.c
+++ b/lib/memmem.c
@@ -24,10 +24,6 @@
/* Specification of memmem. */
#include <string.h>
-#ifndef _LIBC
-# define __builtin_expect(expr, val) (expr)
-#endif
-
#define RETURN_TYPE void *
#define AVAILABLE(h, h_l, j, n_l) ((j) <= (h_l) - (n_l))
#include "str-two-way.h"
diff --git a/lib/regex_internal.h b/lib/regex_internal.h
index 7ac5f92671..411410740f 100644
--- a/lib/regex_internal.h
+++ b/lib/regex_internal.h
@@ -115,11 +115,7 @@
# define RE_ENABLE_I18N
#endif
-#if __GNUC__ >= 3
-# define BE(expr, val) __builtin_expect (expr, val)
-#else
-# define BE(expr, val) (expr)
-#endif
+#define BE(expr, val) __builtin_expect (expr, val)
/* Number of ASCII characters. */
#define ASCII_CHARS 0x80
diff --git a/lib/scandir.c b/lib/scandir.c
index a41ef1ad3e..747bd8798b 100644
--- a/lib/scandir.c
+++ b/lib/scandir.c
@@ -26,10 +26,6 @@
# include <bits/libc-lock.h>
#endif
-#if ! defined __builtin_expect && __GNUC__ < 3
-# define __builtin_expect(expr, expected) (expr)
-#endif
-
#undef select
#ifndef _D_EXACT_NAMLEN
diff --git a/lib/strstr.c b/lib/strstr.c
index 7e1865f615..29da790c55 100644
--- a/lib/strstr.c
+++ b/lib/strstr.c
@@ -26,10 +26,6 @@
#include <stdbool.h>
-#ifndef _LIBC
-# define __builtin_expect(expr, val) (expr)
-#endif
-
#define RETURN_TYPE char *
#define AVAILABLE(h, h_l, j, n_l) \
(!memchr ((h) + (h_l), '\0', (j) + (n_l) - (h_l)) \
diff --git a/m4/builtin-expect.m4 b/m4/builtin-expect.m4
new file mode 100644
index 0000000000..5f7a323112
--- /dev/null
+++ b/m4/builtin-expect.m4
@@ -0,0 +1,34 @@
+dnl Check for __builtin_expect.
+
+dnl Copyright 2016 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl Written by Paul Eggert.
+
+AC_DEFUN([gl___BUILTIN_EXPECT],
+[
+ AC_CACHE_CHECK([for __builtin_expect],
+ [gl_cv___builtin_expect],
+ [AC_LINK_IFELSE(
+ [AC_LANG_SOURCE([[
+ int
+ main (int argc, char **argv)
+ {
+ argc = __builtin_expect (argc, 100);
+ return argv[argc != 100][0];
+ }]])],
+ [gl_cv___builtin_expect=yes],
+ [gl_cv___builtin_expect=no])])
+ if test "$gl_cv___builtin_expect" = yes; then
+ AC_DEFINE([HAVE___BUILTIN_EXPECT], [1])
+ fi
+ AH_VERBATIM([HAVE___BUILTIN_EXPECT],
+ [/* Define to 1 if the compiler understands __builtin_expect. */
+#undef HAVE___BUILTIN_EXPECT
+#ifndef HAVE___BUILTIN_EXPECT
+# define __builtin_expect(e, c) (e)
+#endif
+ ])
+])
diff --git a/modules/avltreehash-list b/modules/avltreehash-list
index f4d569917a..a7aa75ec45 100644
--- a/modules/avltreehash-list
+++ b/modules/avltreehash-list
@@ -14,6 +14,7 @@ lib/gl_anytreehash_list1.h
lib/gl_anytreehash_list2.h
Depends-on:
+builtin-expect
list
avltree-oset
stdint
diff --git a/modules/builtin-expect b/modules/builtin-expect
new file mode 100644
index 0000000000..c11d5d96c9
--- /dev/null
+++ b/modules/builtin-expect
@@ -0,0 +1,20 @@
+Description:
+Check for __builtin_expect.
+
+Files:
+m4/builtin-expect.m4
+
+Depends-on:
+
+configure.ac:
+gl___BUILTIN_EXPECT
+
+Makefile.am:
+
+Include:
+
+License:
+LGPLv2+
+
+Maintainer:
+all
diff --git a/modules/fnmatch b/modules/fnmatch
index ab302361ba..70563f9bda 100644
--- a/modules/fnmatch
+++ b/modules/fnmatch
@@ -12,6 +12,7 @@ Depends-on:
extensions
snippet/arg-nonnull
alloca [test -n "$FNMATCH_H"]
+builtin-expect [test -n "$FNMATCH_H"]
flexmember [test -n "$FNMATCH_H"]
stdbool [test -n "$FNMATCH_H"]
wchar [test -n "$FNMATCH_H"]
diff --git a/modules/glob b/modules/glob
index f32fe5f36f..29df7ab89b 100644
--- a/modules/glob
+++ b/modules/glob
@@ -15,6 +15,7 @@ snippet/arg-nonnull
snippet/c++defs
snippet/warn-on-use
alloca [test -n "$GLOB_H"]
+builtin-expect [test -n "$GLOB_H"]
closedir [test -n "$GLOB_H"]
d-type [test -n "$GLOB_H"]
dirfd [test -n "$GLOB_H"]
diff --git a/modules/grantpt b/modules/grantpt
index 38675b6fb5..486bb8550e 100644
--- a/modules/grantpt
+++ b/modules/grantpt
@@ -9,6 +9,7 @@ m4/grantpt.m4
Depends-on:
stdlib
extensions
+builtin-expect [test $HAVE_GRANTPT = 0]
pt_chown [test $HAVE_GRANTPT = 0]
waitpid [test $HAVE_GRANTPT = 0]
configmake [test $HAVE_GRANTPT = 0]
diff --git a/modules/memmem-simple b/modules/memmem-simple
index d4ae332a26..71de887c39 100644
--- a/modules/memmem-simple
+++ b/modules/memmem-simple
@@ -7,6 +7,7 @@ lib/memmem.c
m4/memmem.m4
Depends-on:
+builtin-expect
extensions
string
stdint
diff --git a/modules/rbtreehash-list b/modules/rbtreehash-list
index e7369cbfc0..2b4add5546 100644
--- a/modules/rbtreehash-list
+++ b/modules/rbtreehash-list
@@ -14,6 +14,7 @@ lib/gl_anytreehash_list1.h
lib/gl_anytreehash_list2.h
Depends-on:
+builtin-expect
list
rbtree-oset
stdint
diff --git a/modules/scandir b/modules/scandir
index 71ef4654c2..8d5e1058d8 100644
--- a/modules/scandir
+++ b/modules/scandir
@@ -6,6 +6,7 @@ lib/scandir.c
m4/scandir.m4
Depends-on:
+builtin-expect
closedir
dirent
extensions
@@ -31,4 +32,3 @@ LGPL
Maintainer:
all, glibc
-
diff --git a/modules/strstr-simple b/modules/strstr-simple
index c61afc45ad..bd52b17310 100644
--- a/modules/strstr-simple
+++ b/modules/strstr-simple
@@ -8,6 +8,7 @@ m4/strstr.m4
Depends-on:
string
+builtin-expect [test $REPLACE_STRSTR = 1]
stdbool [test $REPLACE_STRSTR = 1]
memchr [test $REPLACE_STRSTR = 1]
memcmp [test $REPLACE_STRSTR = 1]