about summary refs log tree commit diff
path: root/string
diff options
context:
space:
mode:
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>2023-01-17 10:12:40 -0300
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2023-02-06 16:19:35 -0300
commitc19e3394a2a85cabc9a1a02551ec1c2d8085b148 (patch)
tree1bc71caf840ed1e2c4af6b68a3bb5a6f782766d9 /string
parentb79cffb39185301d50dc42db2dfaf1d971be12c3 (diff)
downloadglibc-c19e3394a2a85cabc9a1a02551ec1c2d8085b148.tar.gz
glibc-c19e3394a2a85cabc9a1a02551ec1c2d8085b148.tar.xz
glibc-c19e3394a2a85cabc9a1a02551ec1c2d8085b148.zip
string: Hook up the default implementation on test-strchr
Also remove the simple_STRCHR, which can be easily replaced.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Diffstat (limited to 'string')
-rw-r--r--string/test-strchr.c53
1 files changed, 38 insertions, 15 deletions
diff --git a/string/test-strchr.c b/string/test-strchr.c
index 323c844d21..933fc0bbba 100644
--- a/string/test-strchr.c
+++ b/string/test-strchr.c
@@ -35,7 +35,6 @@
 #ifndef WIDE
 # ifdef USE_FOR_STRCHRNUL
 #  define STRCHR strchrnul
-#  define simple_STRCHR simple_STRCHRNUL
 # else
 #  define STRCHR strchr
 # endif /* !USE_FOR_STRCHRNUL */
@@ -50,7 +49,6 @@
 # include <wchar.h>
 # ifdef USE_FOR_STRCHRNUL
 #  define STRCHR wcschrnul
-#  define simple_STRCHR simple_WCSCHRNUL
 # else
 #  define STRCHR wcschr
 # endif /* !USE_FOR_STRCHRNUL */
@@ -72,20 +70,41 @@
 
 typedef CHAR *(*proto_t) (const CHAR *, int);
 
-/* Naive implementation to verify results.  */
-CHAR *
-simple_STRCHR (const CHAR *s, int c)
-{
-  size_t n = STRLEN (s) + 1;
-
-  while (n--)
-    if (*s++ == (CHAR) c)
-      return (CHAR *) s - 1;
-  return NULLRET ((CHAR *) s - 1);
-}
-
 IMPL (STRCHR, 1)
 
+/* Also check the generic implementation.  */
+#undef STRCHR
+#undef weak_alias
+#define weak_alias(a, b)
+#undef libc_hidden_builtin_def
+#define libc_hidden_builtin_def(a)
+#undef libc_hidden_def
+#define libc_hidden_def(a)
+#undef libc_hidden_weak
+#define libc_hidden_weak(a)
+#ifndef WIDE
+# define STRCHRNUL __strchrnul_default
+# include "string/strchrnul.c"
+# ifndef USE_FOR_STRCHRNUL
+#  define STRCHR __strchr_default
+#  include "string/strchr.c"
+#  define STRCHR_DEFAULT STRCHR
+# else
+#  define STRCHR_DEFAULT STRCHRNUL
+# endif
+#else
+# ifndef USE_FOR_STRCHRNUL
+#  define WCSCHR __wcschr_default
+#  include "wcsmbs/wcschr.c"
+#  define STRCHR_DEFAULT WCSCHR
+# else
+#  define WCSCHRNUL __wcschrnul_default
+#  include "wcsmbs/wcschrnul.c"
+#  define STRCHR_DEFAULT WCSCHRNUL
+# endif
+#endif
+IMPL (STRCHR_DEFAULT, 1)
+
 static int
 check_result (impl_t *impl, const CHAR *s, int c, const CHAR *exp_res)
 {
@@ -219,7 +238,11 @@ check1 (void)
 {
   CHAR s[] __attribute__((aligned(16))) = L ("\xff");
   CHAR c = L ('\xfe');
-  CHAR *exp_result = simple_STRCHR (s, c);
+#ifndef USE_FOR_STRCHRNUL
+  CHAR *exp_result = NULL;
+#else
+  CHAR *exp_result = s + STRLEN (s);
+#endif
 
   FOR_EACH_IMPL (impl, 0)
     check_result (impl, s, c, exp_result);