[v9,19/22] string: Hook up the default implementation on test-strchr

Message ID 20230117200014.1299923-20-adhemerval.zanella@linaro.org
State Superseded
Headers
Series Improve generic string routines |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent

Commit Message

Adhemerval Zanella Jan. 17, 2023, 8 p.m. UTC
  Also remove the simple_STRCHR, which can be easily replaced.
---
 string/test-strchr.c | 47 ++++++++++++++++++++++++++++++--------------
 1 file changed, 32 insertions(+), 15 deletions(-)
  

Patch

diff --git a/string/test-strchr.c b/string/test-strchr.c
index 323c844d21..e6f3b3b243 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,35 @@ 
 
 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
+# define WCSCHR __wcschr_default
+# include "wcsmbs/wcschr.c"
+#  define STRCHR_DEFAULT WCSCHR
+#endif
+IMPL (STRCHR_DEFAULT, 1)
+
 static int
 check_result (impl_t *impl, const CHAR *s, int c, const CHAR *exp_res)
 {
@@ -219,7 +232,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);