The 'fnmatch' module currently tests for wmemcpy() differently than wmemcpy.m4
does. It also lacks the workarounds from the 'btowc' and 'iswctype' modules.

Therefore here is a proposed patch to let this module use more from gnulib.
Accordingly, the code becomes simpler.

Paul, is this OK from the perspective of a future merge with glibc?


2020-05-29  Bruno Haible  <br...@clisp.org>

        fnmatch: Rely on more gnulib modules.
        * modules/fnmatch (Depends-on): Add btowc, isblank, iswctype, wmemchr,
        wmempcpy, mempcpy.
        * lib/fnmatch.c: Assume that HAVE_WCTYPE_H, HAVE_BTOWC, HAVE_ISWCTYPE,
        HAVE_WMEMCHR, HAVE_WMEMPCPY, HAVE_ISBLANK, HAVE_DECL_ISBLANK,
        HAVE_MEMPCPY are all 1.
        * m4/fnmatch.m4 (gl_PREREQ_FNMATCH): Don't test for btowc, isblank,
        iswctype, mempcpy, wmemchr, wmemcpy, wmempcpy, <wctype.h>.

>From 1c61fb1eee1d63a110575258803637865a119762 Mon Sep 17 00:00:00 2001
From: Bruno Haible <br...@clisp.org>
Date: Fri, 29 May 2020 14:01:54 +0200
Subject: [PATCH] fnmatch: Rely on more gnulib modules.

* modules/fnmatch (Depends-on): Add btowc, isblank, iswctype, wmemchr,
wmempcpy, mempcpy.
* lib/fnmatch.c: Assume that HAVE_WCTYPE_H, HAVE_BTOWC, HAVE_ISWCTYPE,
HAVE_WMEMCHR, HAVE_WMEMPCPY, HAVE_ISBLANK, HAVE_DECL_ISBLANK,
HAVE_MEMPCPY are all 1.
* m4/fnmatch.m4 (gl_PREREQ_FNMATCH): Don't test for btowc, isblank,
iswctype, mempcpy, wmemchr, wmemcpy, wmempcpy, <wctype.h>.
---
 ChangeLog       | 11 ++++++++
 lib/fnmatch.c   | 80 +++++++++++++++++----------------------------------------
 m4/fnmatch.m4   |  6 ++---
 modules/fnmatch |  6 +++++
 4 files changed, 42 insertions(+), 61 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 566dfab..2d56a7b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 2020-05-29  Bruno Haible  <br...@clisp.org>
 
+	fnmatch: Rely on more gnulib modules.
+	* modules/fnmatch (Depends-on): Add btowc, isblank, iswctype, wmemchr,
+	wmempcpy, mempcpy.
+	* lib/fnmatch.c: Assume that HAVE_WCTYPE_H, HAVE_BTOWC, HAVE_ISWCTYPE,
+	HAVE_WMEMCHR, HAVE_WMEMPCPY, HAVE_ISBLANK, HAVE_DECL_ISBLANK,
+	HAVE_MEMPCPY are all 1.
+	* m4/fnmatch.m4 (gl_PREREQ_FNMATCH): Don't test for btowc, isblank,
+	iswctype, mempcpy, wmemchr, wmemcpy, wmempcpy, <wctype.h>.
+
+2020-05-29  Bruno Haible  <br...@clisp.org>
+
 	wmemchr, wmemcmp, wmemcpy, wmemmove, wmemset: Fix autoconf test.
 	* m4/wmemchr.m4 (gl_FUNC_WMEMCHR): Link, not only compile, the test
 	program.
diff --git a/lib/fnmatch.c b/lib/fnmatch.c
index 224512d..db4da5e 100644
--- a/lib/fnmatch.c
+++ b/lib/fnmatch.c
@@ -32,17 +32,8 @@
 #include <stdbool.h>
 #include <stdlib.h>
 #include <string.h>
-
-#define WIDE_CHAR_SUPPORT \
-  (HAVE_WCTYPE_H && HAVE_BTOWC && HAVE_ISWCTYPE \
-   && HAVE_WMEMCHR && (HAVE_WMEMCPY || HAVE_WMEMPCPY))
-
-/* For platform which support the ISO C amendment 1 functionality we
-   support user defined character classes.  */
-#if defined _LIBC || WIDE_CHAR_SUPPORT
-# include <wctype.h>
-# include <wchar.h>
-#endif
+#include <wchar.h>
+#include <wctype.h>
 
 /* We need some of the locale data (the collation sequence information)
    but there is no interface to get this information in general.  Therefore
@@ -82,50 +73,33 @@ extern int fnmatch (const char *pattern, const char *string, int flags);
 #if defined _LIBC || !defined __GNU_LIBRARY__ || !HAVE_FNMATCH_GNU
 
 
-# if ! (defined isblank || (HAVE_ISBLANK && HAVE_DECL_ISBLANK))
-#  define isblank(c) ((c) == ' ' || (c) == '\t')
-# endif
-
 # define STREQ(s1, s2) (strcmp (s1, s2) == 0)
 
-# if defined _LIBC || WIDE_CHAR_SUPPORT
-/* The GNU C library provides support for user-defined character classes
-   and the functions from ISO C amendment 1.  */
-#  ifdef CHARCLASS_NAME_MAX
-#   define CHAR_CLASS_MAX_LENGTH CHARCLASS_NAME_MAX
-#  else
+/* Provide support for user-defined character classes, based on the functions
+   from ISO C 90 amendment 1.  */
+# ifdef CHARCLASS_NAME_MAX
+#  define CHAR_CLASS_MAX_LENGTH CHARCLASS_NAME_MAX
+# else
 /* This shouldn't happen but some implementation might still have this
    problem.  Use a reasonable default value.  */
-#   define CHAR_CLASS_MAX_LENGTH 256
-#  endif
+#  define CHAR_CLASS_MAX_LENGTH 256
+# endif
 
-#  ifdef _LIBC
-#   define IS_CHAR_CLASS(string) __wctype (string)
-#  else
-#   define IS_CHAR_CLASS(string) wctype (string)
-#  endif
+# ifdef _LIBC
+#  define IS_CHAR_CLASS(string) __wctype (string)
+# else
+#  define IS_CHAR_CLASS(string) wctype (string)
+# endif
 
-#  ifdef _LIBC
-#   define ISWCTYPE(WC, WT)     __iswctype (WC, WT)
-#  else
-#   define ISWCTYPE(WC, WT)     iswctype (WC, WT)
-#  endif
+# ifdef _LIBC
+#  define ISWCTYPE(WC, WT)     __iswctype (WC, WT)
+# else
+#  define ISWCTYPE(WC, WT)     iswctype (WC, WT)
+# endif
 
-#  if (HAVE_MBSTATE_T && HAVE_MBSRTOWCS) || _LIBC
+# if (HAVE_MBSTATE_T && HAVE_MBSRTOWCS) || _LIBC
 /* In this case we are implementing the multibyte character handling.  */
-#   define HANDLE_MULTIBYTE     1
-#  endif
-
-# else
-#  define CHAR_CLASS_MAX_LENGTH  6 /* Namely, 'xdigit'.  */
-
-#  define IS_CHAR_CLASS(string)                                               \
-   (STREQ (string, "alpha") || STREQ (string, "upper")                        \
-    || STREQ (string, "lower") || STREQ (string, "digit")                     \
-    || STREQ (string, "alnum") || STREQ (string, "xdigit")                    \
-    || STREQ (string, "space") || STREQ (string, "print")                     \
-    || STREQ (string, "punct") || STREQ (string, "graph")                     \
-    || STREQ (string, "cntrl") || STREQ (string, "blank"))
+#  define HANDLE_MULTIBYTE     1
 # endif
 
 /* Avoid depending on library functions or files
@@ -159,11 +133,7 @@ static int posixly_correct;
 # ifdef _LIBC
 #  define MEMPCPY(D, S, N) __mempcpy (D, S, N)
 # else
-#  if HAVE_MEMPCPY
-#   define MEMPCPY(D, S, N) mempcpy (D, S, N)
-#  else
-#   define MEMPCPY(D, S, N) ((void *) ((char *) memcpy (D, S, N) + (N)))
-#  endif
+#  define MEMPCPY(D, S, N) mempcpy (D, S, N)
 # endif
 # define MEMCHR(S, C, N) memchr (S, C, N)
 # include "fnmatch_loop.c"
@@ -186,11 +156,7 @@ static int posixly_correct;
 #  else
 #   define STRLEN(S) wcslen (S)
 #   define STRCAT(D, S) wcscat (D, S)
-#   if HAVE_WMEMPCPY
-#    define MEMPCPY(D, S, N) wmempcpy (D, S, N)
-#   else
-#    define MEMPCPY(D, S, N) (wmemcpy (D, S, N) + (N))
-#   endif
+#   define MEMPCPY(D, S, N) wmempcpy (D, S, N)
 #  endif
 #  define MEMCHR(S, C, N) wmemchr (S, C, N)
 #  define WIDE_CHAR_VERSION 1
diff --git a/m4/fnmatch.m4 b/m4/fnmatch.m4
index 0f41f8c..2f8e4a8 100644
--- a/m4/fnmatch.m4
+++ b/m4/fnmatch.m4
@@ -1,4 +1,4 @@
-# Check for fnmatch - serial 14.  -*- coding: utf-8 -*-
+# Check for fnmatch - serial 15.  -*- coding: utf-8 -*-
 
 # Copyright (C) 2000-2007, 2009-2020 Free Software Foundation, Inc.
 # This file is free software; the Free Software Foundation
@@ -149,7 +149,5 @@ AC_DEFUN([gl_PREREQ_FNMATCH],
 [
   dnl Prerequisites of lib/fnmatch.c.
   AC_REQUIRE([AC_TYPE_MBSTATE_T])
-  AC_CHECK_DECLS([isblank], [], [], [[#include <ctype.h>]])
-  AC_CHECK_FUNCS_ONCE([btowc isblank iswctype mbsrtowcs mempcpy wmemchr wmemcpy wmempcpy])
-  AC_CHECK_HEADERS_ONCE([wctype.h])
+  AC_CHECK_FUNCS_ONCE([mbsrtowcs])
 ])
diff --git a/modules/fnmatch b/modules/fnmatch
index c7977b4..4fc5a3b 100644
--- a/modules/fnmatch
+++ b/modules/fnmatch
@@ -11,13 +11,19 @@ Depends-on:
 fnmatch-h
 alloca          [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1]
 attribute       [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1]
+btowc           [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1]
 builtin-expect  [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1]
 flexmember      [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1]
+isblank         [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1]
+iswctype        [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1]
 stdbool         [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1]
 wchar           [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1]
 wctype-h        [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1]
+wmemchr         [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1]
+wmempcpy        [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1]
 memchr          [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1]
 memcmp          [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1]
+mempcpy         [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1]
 mbsrtowcs       [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1]
 mbsinit         [test $HAVE_FNMATCH = 0 || test $REPLACE_FNMATCH = 1]
 
-- 
2.7.4

Reply via email to