>From 5ac9de982d61df59a1afc3446000f50a4ca705b6 Mon Sep 17 00:00:00 2001 From: Bruno Haible
Date: Sun, 24 Nov 2019 13:11:12 +0100 Subject: [PATCH 1/2] wcstok: Work around wrong signature on native Windows. * lib/wchar.in.h (wcstok): Override when REPLACE_WCSTOK is 1. * m4/wcstok.m4 (gl_FUNC_WCSTOK): Check for signature of wcstok. Set REPLACE_WCSTOK. * m4/wchar_h.m4 (gl_WCHAR_H_DEFAULTS): Initialize REPLACE_WCSTOK. * modules/wchar (Makefile.am): Substitute REPLACE_WCSTOK. * modules/wcstok (Depends-on, configure.ac): Consider REPLACE_WCSTOK. * doc/posix-functions/wcstok.texi: Mention the problem. --- ChangeLog | 11 +++++++++++ doc/posix-functions/wcstok.texi | 3 +++ lib/wchar.in.h | 15 +++++++++++++-- m4/wchar_h.m4 | 3 ++- m4/wcstok.m4 | 29 +++++++++++++++++++++++++++-- modules/wchar | 1 + modules/wcstok | 6 +++--- 7 files changed, 60 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 47b079b..9e6725a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2019-11-24 Bruno Haible + + wcstok: Work around wrong signature on native Windows. + * lib/wchar.in.h (wcstok): Override when REPLACE_WCSTOK is 1. + * m4/wcstok.m4 (gl_FUNC_WCSTOK): Check for signature of wcstok. Set + REPLACE_WCSTOK. + * m4/wchar_h.m4 (gl_WCHAR_H_DEFAULTS): Initialize REPLACE_WCSTOK. + * modules/wchar (Makefile.am): Substitute REPLACE_WCSTOK. + * modules/wcstok (Depends-on, configure.ac): Consider REPLACE_WCSTOK. + * doc/posix-functions/wcstok.texi: Mention the problem. + 2019-11-22 Paul Eggert intprops: INT_MULTIPLY_WRAPV speedup for GCC 8.4+ diff --git a/doc/posix-functions/wcstok.texi b/doc/posix-functions/wcstok.texi index c93e236..6f971e1 100644 --- a/doc/posix-functions/wcstok.texi +++ b/doc/posix-functions/wcstok.texi @@ -11,6 +11,9 @@ Portability problems fixed by Gnulib: @item This function is missing on some platforms: Cygwin 1.5.x. +@item +This function takes only two arguments on some platforms: +mingw, MSVC 14. @end itemize Portability problems not fixed by Gnulib: diff --git a/lib/wchar.in.h b/lib/wchar.in.h index 3ebcdba..9807f60 100644 --- a/lib/wchar.in.h +++ b/lib/wchar.in.h @@ -1037,12 +1037,23 @@ _GL_WARN_ON_USE (wcsstr, "wcsstr is unportable - " /* Divide WCS into tokens separated by characters in DELIM. */ #if @GNULIB_WCSTOK@ -# if !@HAVE_WCSTOK@ +# if @REPLACE_WCSTOK@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef wcstok +# define wcstok rpl_wcstok +# endif +_GL_FUNCDECL_RPL (wcstok, wchar_t *, + (wchar_t *wcs, const wchar_t *delim, wchar_t **ptr)); +_GL_CXXALIAS_RPL (wcstok, wchar_t *, + (wchar_t *wcs, const wchar_t *delim, wchar_t **ptr)); +# else +# if !@HAVE_WCSTOK@ _GL_FUNCDECL_SYS (wcstok, wchar_t *, (wchar_t *wcs, const wchar_t *delim, wchar_t **ptr)); -# endif +# endif _GL_CXXALIAS_SYS (wcstok, wchar_t *, (wchar_t *wcs, const wchar_t *delim, wchar_t **ptr)); +# endif # if __GLIBC__ >= 2 _GL_CXXALIASWARN (wcstok); # endif diff --git a/m4/wchar_h.m4 b/m4/wchar_h.m4 index cd20e7a..8c6ebcc 100644 --- a/m4/wchar_h.m4 +++ b/m4/wchar_h.m4 @@ -7,7 +7,7 @@ dnl with or without modifications, as long as this notice is preserved. dnl Written by Eric Blake. -# wchar_h.m4 serial 43 +# wchar_h.m4 serial 44 AC_DEFUN([gl_WCHAR_H], [ @@ -237,4 +237,5 @@ AC_DEFUN([gl_WCHAR_H_DEFAULTS], REPLACE_WCWIDTH=0; AC_SUBST([REPLACE_WCWIDTH]) REPLACE_WCSWIDTH=0; AC_SUBST([REPLACE_WCSWIDTH]) REPLACE_WCSFTIME=0; AC_SUBST([REPLACE_WCSFTIME]) + REPLACE_WCSTOK=0; AC_SUBST([REPLACE_WCSTOK]) ]) diff --git a/m4/wcstok.m4 b/m4/wcstok.m4 index 8201ca3..8f0aeb0 100644 --- a/m4/wcstok.m4 +++ b/m4/wcstok.m4 @@ -1,4 +1,4 @@ -# wcstok.m4 serial 2 +# wcstok.m4 serial 3 dnl Copyright (C) 2011-2019 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -8,7 +8,32 @@ AC_DEFUN([gl_FUNC_WCSTOK], [ AC_REQUIRE([gl_WCHAR_H_DEFAULTS]) AC_CHECK_FUNCS_ONCE([wcstok]) - if test $ac_cv_func_wcstok = no; then + if test $ac_cv_func_wcstok = yes; then + dnl POSIX: wchar_t *wcstok (wchar_t *, const wchar_t *, wchar_t **); + dnl mingw, MSVC: wchar_t *wcstok (wchar_t *, const wchar_t *); + AC_CACHE_CHECK([for wcstok with POSIX signature], + [gl_cv_func_wcstok_posix_signature], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[ +/* Tru64 with Desktop Toolkit C has a bug: