bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
* time_r module does not work on MingW
@ 2019-11-11 18:56 Christian Biesinger
  2019-11-11 19:53 ` Paul Eggert
  2019-11-11 19:59 ` Bruno Haible
  0 siblings, 2 replies; 13+ messages in thread
From: Christian Biesinger @ 2019-11-11 18:56 UTC (permalink / raw)
  To: bug-gnulib

[-- Attachment #1: Type: text/plain, Size: 486 bytes --]

Hello!

I tried to use the time_r module with GDB (using Gnulib
revision 38237baf99386101934cd93278023aa4ae523ec0)

However, I found that it does not compile, see logs at:
https://gdb-buildbot.osci.io/#/builders/23/builds/934

Apparently, the MingW time.h has localtime_r and gmtime_r defined as
__forceinline functions outside of the extern "C" block, so they use C++
linkage, whereas gnulib expects C linkage.

I'm not sure what the best fix is but this seems unfortunate?

Christian

[-- Attachment #2: Type: text/html, Size: 725 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: time_r module does not work on MingW
  2019-11-11 18:56 time_r module does not work on MingW Christian Biesinger
@ 2019-11-11 19:53 ` Paul Eggert
  2019-11-11 19:59 ` Bruno Haible
  1 sibling, 0 replies; 13+ messages in thread
From: Paul Eggert @ 2019-11-11 19:53 UTC (permalink / raw)
  To: Christian Biesinger; +Cc: bug-gnulib

On 11/11/19 10:56 AM, Christian Biesinger wrote:

> I'm not sure what the best fix is but this seems unfortunate?

I don't use C++ so you'll have to help me out on this one. Would the followiung 
patch work, and if not why not?

diff --git a/lib/time.in.h b/lib/time.in.h
index 94e1da3a8..cb5fe3d84 100644
--- a/lib/time.in.h
+++ b/lib/time.in.h
@@ -157,7 +157,7 @@ _GL_CXXALIASWARN (mktime);
     <https://pubs.opengroup.org/onlinepubs/9699919799/functions/gmtime_r.html>.  */
  # if @GNULIB_TIME_R@
  #  if @REPLACE_LOCALTIME_R@
-#   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   if !(defined __cplusplus && defined GNULIB_NAMESPACE && !defined __MINGW32__)
  #    undef localtime_r
  #    define localtime_r rpl_localtime_r
  #   endif
@@ -179,7 +179,7 @@ _GL_CXXALIAS_SYS (localtime_r, struct tm *, (time_t const 
*restrict __timer,
  _GL_CXXALIASWARN (localtime_r);
  #  endif
  #  if @REPLACE_LOCALTIME_R@
-#   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   if !(defined __cplusplus && defined GNULIB_NAMESPACE && !defined __MINGW32__)
  #    undef gmtime_r
  #    define gmtime_r rpl_gmtime_r
  #   endif


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: time_r module does not work on MingW
  2019-11-11 18:56 time_r module does not work on MingW Christian Biesinger
  2019-11-11 19:53 ` Paul Eggert
@ 2019-11-11 19:59 ` Bruno Haible
  2019-11-11 20:47   ` Christian Biesinger
  1 sibling, 1 reply; 13+ messages in thread
From: Bruno Haible @ 2019-11-11 19:59 UTC (permalink / raw)
  To: bug-gnulib; +Cc: Christian Biesinger

Hi,

Christian Biesinger wrote:
> I tried to use the time_r module with GDB (using Gnulib
> revision 38237baf99386101934cd93278023aa4ae523ec0)
> 
> However, I found that it does not compile, see logs at:
> https://gdb-buildbot.osci.io/#/builders/23/builds/934

It is hard for me to do guesswork, based on a large set of sources such
as gdb and a log file that shows mixed output from two parallel processes
(the revenge of "make -j2").

Can you please provide a simple test case?

Or at least help the investigation by showing the values of
  GNULIB_TIME_R
  REPLACE_LOCALTIME_R
  HAVE_DECL_LOCALTIME_R
that you find in config.status? Also we would need to know whether
the gdb build defines GNULIB_NAMESPACE and whether the source file
(amd64.c) starts with '#include <config.h>'.

Bruno



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: time_r module does not work on MingW
  2019-11-11 19:59 ` Bruno Haible
@ 2019-11-11 20:47   ` Christian Biesinger
  2019-11-12  2:28     ` Bruno Haible
  0 siblings, 1 reply; 13+ messages in thread
From: Christian Biesinger @ 2019-11-11 20:47 UTC (permalink / raw)
  To: Bruno Haible; +Cc: bug-gnulib, Christian Biesinger

[-- Attachment #1: Type: text/plain, Size: 2403 bytes --]

(I accidentally sent this from the wrong email address. Please respond to
my google.com address, not gmail.com)

Thanks for your responses!

The patch above does not fix the issue because apparently
REPLACE_LOCALTIME_R is defined as GNULIB_PORTCHECK which is not defined.
Replacing that with #if 1 does fix it.

gdb does not define GNULIB_NAMESPACE.
 713 S["GNULIB_TIME_R"]="1"
 707 S["REPLACE_LOCALTIME_R"]="GNULIB_PORTCHECK"
 711 S["HAVE_DECL_LOCALTIME_R"]="0"

It includes gnulib's config.h as the second file after gdb's config.h.

Here is the testcase:
#include "build-gnulib-gdbserver/config.h"
#include "pathmax.h"
#include "time.h"

x86_64-w64-mingw32-g++ test.cc -I build-gnulib-gdbserver/import/ -I
~/binutils-gdb/gnulib/import/

It turns out that the pathmax.h include is required for this to fail.
Alternatively, including just unistd.h before time.h will fail. Error:
https://pastebin.com/Vp8LUqaQ

The enabled gnulib modules are:
IMPORTED_GNULIB_MODULES="\
    alloca \
    canonicalize-lgpl \
    dirent \
    dirfd \
    errno \
    fnmatch-gnu \
    frexpl \
    getcwd \
    glob \
    inet_ntop
    inttypes \
    lstat \
    limits-h \
    memchr \
    memmem \
    mkdir \
    mkdtemp \
    mkostemp \
    pathmax \
    rawmemchr \
    readlink \
    rename \
    setenv \
    signal-h \
    strchrnul \
    strerror_r-posix \
    strstr \
    strtok_r \
    sys_stat \
    time_r \
    unistd \
    unsetenv \
    update-copyright \
    wchar \
    wctype-h \
"

Christian

On Mon, Nov 11, 2019 at 11:59 AM Bruno Haible <bruno@clisp.org> wrote:

> Hi,
>
> Christian Biesinger wrote:
> > I tried to use the time_r module with GDB (using Gnulib
> > revision 38237baf99386101934cd93278023aa4ae523ec0)
> >
> > However, I found that it does not compile, see logs at:
> > https://gdb-buildbot.osci.io/#/builders/23/builds/934
>
> It is hard for me to do guesswork, based on a large set of sources such
> as gdb and a log file that shows mixed output from two parallel processes
> (the revenge of "make -j2").
>
> Can you please provide a simple test case?
>
> Or at least help the investigation by showing the values of
>   GNULIB_TIME_R
>   REPLACE_LOCALTIME_R
>   HAVE_DECL_LOCALTIME_R
> that you find in config.status? Also we would need to know whether
> the gdb build defines GNULIB_NAMESPACE and whether the source file
> (amd64.c) starts with '#include <config.h>'.
>
> Bruno
>
>

[-- Attachment #2: Type: text/html, Size: 3611 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: time_r module does not work on MingW
  2019-11-11 20:47   ` Christian Biesinger
@ 2019-11-12  2:28     ` Bruno Haible
  2019-11-16 12:15       ` Bruno Haible
  0 siblings, 1 reply; 13+ messages in thread
From: Bruno Haible @ 2019-11-12  2:28 UTC (permalink / raw)
  To: Christian Biesinger; +Cc: bug-gnulib, Christian Biesinger

> Here is the testcase:
> #include "build-gnulib-gdbserver/config.h"
> #include "pathmax.h"
> #include "time.h"
> 
> x86_64-w64-mingw32-g++ test.cc -I build-gnulib-gdbserver/import/ -I
> ~/binutils-gdb/gnulib/import/
> 
> It turns out that the pathmax.h include is required for this to fail.
> Alternatively, including just unistd.h before time.h will fail. Error:
> https://pastebin.com/Vp8LUqaQ
> 
> The enabled gnulib modules are:
> IMPORTED_GNULIB_MODULES="\ ...

Thanks. I reproduce it. Will investigate.

Bruno



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: time_r module does not work on MingW
  2019-11-12  2:28     ` Bruno Haible
@ 2019-11-16 12:15       ` Bruno Haible
  2019-11-16 22:41         ` wctype.h compile error on mingw with GNULIB_NAMESPACE Christian Biesinger
  2019-11-24 14:06         ` time_r module does not work on MingW Bruno Haible
  0 siblings, 2 replies; 13+ messages in thread
From: Bruno Haible @ 2019-11-16 12:15 UTC (permalink / raw)
  To: Christian Biesinger; +Cc: bug-gnulib, Christian Biesinger

This patch fixes the issue. The cause was that the contents of <time.h>
in mingw depends on whether <unistd.h> or <pthread.h> was included before.


2019-11-16  Bruno Haible  <bruno@clisp.org>

	time_r: Fix for mingw.
	Reported by Christian Biesinger <cbiesinger@google.com> in
	<https://lists.gnu.org/archive/html/bug-gnulib/2019-11/msg00014.html>.
	* lib/time.in.h: On mingw, include <unistd.h>.
	* m4/time_r.m4 (gl_TIME_R): On mingw, include <unistd.h> before
	<time.h>. Test for localtime_r in a way that works when it is defined
	as an inline function.

diff --git a/lib/time.in.h b/lib/time.in.h
index 94e1da3..dc00503 100644
--- a/lib/time.in.h
+++ b/lib/time.in.h
@@ -37,6 +37,12 @@
 
 # define _@GUARD_PREFIX@_TIME_H
 
+/* mingw's <time.h> provides the functions asctime_r, ctime_r, gmtime_r,
+   localtime_r only if <unistd.h> or <pthread.h> has been included before.  */
+# if defined __MINGW32__
+#  include <unistd.h>
+# endif
+
 # @INCLUDE_NEXT@ @NEXT_TIME_H@
 
 /* NetBSD 5.0 mis-defines NULL.  */
diff --git a/m4/time_r.m4 b/m4/time_r.m4
index 5caeca7..72cc975 100644
--- a/m4/time_r.m4
+++ b/m4/time_r.m4
@@ -17,19 +17,54 @@ AC_DEFUN([gl_TIME_R],
 
   dnl Some systems don't declare localtime_r() and gmtime_r() if _REENTRANT is
   dnl not defined.
-  AC_CHECK_DECLS([localtime_r], [], [], [[#include <time.h>]])
+  AC_CHECK_DECLS([localtime_r], [], [],
+    [[/* mingw's <time.h> provides the functions asctime_r, ctime_r,
+         gmtime_r, localtime_r only if <unistd.h> or <pthread.h> has
+         been included before.  */
+      #if defined __MINGW32__
+      # include <unistd.h>
+      #endif
+      #include <time.h>
+    ]])
   if test $ac_cv_have_decl_localtime_r = no; then
     HAVE_DECL_LOCALTIME_R=0
   fi
 
-  AC_CHECK_FUNCS_ONCE([localtime_r])
-  if test $ac_cv_func_localtime_r = yes; then
+  dnl We can't use AC_CHECK_FUNC here, because localtime_r() is defined as an
+  dnl inline function on mingw.
+  AC_CACHE_CHECK([for localtime_r], [gl_cv_func_localtime_r],
+    [AC_LINK_IFELSE(
+       [AC_LANG_PROGRAM(
+          [[/* mingw's <time.h> provides the functions asctime_r, ctime_r,
+               gmtime_r, localtime_r only if <unistd.h> or <pthread.h> has
+               been included before.  */
+            #if defined __MINGW32__
+            # include <unistd.h>
+            #endif
+            #include <time.h>
+          ]],
+          [[time_t a;
+            struct tm r;
+            localtime_r (&a, &r);
+          ]])
+       ],
+       [gl_cv_func_localtime_r=yes],
+       [gl_cv_func_localtime_r=no])
+    ])
+  if test $gl_cv_func_localtime_r = yes; then
     HAVE_LOCALTIME_R=1
     AC_CACHE_CHECK([whether localtime_r is compatible with its POSIX signature],
       [gl_cv_time_r_posix],
       [AC_COMPILE_IFELSE(
          [AC_LANG_PROGRAM(
-            [[#include <time.h>]],
+            [[/* mingw's <time.h> provides the functions asctime_r, ctime_r,
+                 gmtime_r, localtime_r only if <unistd.h> or <pthread.h> has
+                 been included before.  */
+              #if defined __MINGW32__
+              # include <unistd.h>
+              #endif
+              #include <time.h>
+            ]],
             [[/* We don't need to append 'restrict's to the argument types,
                  even though the POSIX signature has the 'restrict's,
                  since C99 says they can't affect type compatibility.  */



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* wctype.h compile error on mingw with GNULIB_NAMESPACE
  2019-11-16 12:15       ` Bruno Haible
@ 2019-11-16 22:41         ` Christian Biesinger
  2019-11-17  3:05           ` Bruno Haible
  2019-11-24 14:06         ` time_r module does not work on MingW Bruno Haible
  1 sibling, 1 reply; 13+ messages in thread
From: Christian Biesinger @ 2019-11-16 22:41 UTC (permalink / raw)
  To: Bruno Haible; +Cc: bug-gnulib

Hello Bruno,

On Sat, Nov 16, 2019 at 6:15 AM Bruno Haible <bruno@clisp.org> wrote:
>
> This patch fixes the issue. The cause was that the contents of <time.h>
> in mingw depends on whether <unistd.h> or <pthread.h> was included before.

thank you! That does seem to fix the issue (although it requires
deleting config.cache :( )

I tried to upgrade gnulib instead of patching it and found another
problem, introduced sometime between commits
38237baf99386101934cd93278023aa4ae523ec0 and
b7bf9f4361c8d78ccfda7a30ff31f7a406ea972e (hence my subject change).
Specifically, this testcase:

#define GNULIB_NAMESPACE gnulib
#include "gnulib/config.h"
#include "wctype.h"

x86_64-w64-mingw32-g++ -c test.cc -I build/gnulib/import/ -I
binutils-gdb/gnulib/import/

Fails with errors like:
gnulib/import/wctype.h: In member function
‘gnulib::_gl_iswalnum_wrapper::operator
gnulib::_gl_iswalnum_wrapper::type() const’:
gnulib/import/wctype.h:856:1: error: invalid conversion from ‘int
(*)(wint_t)’ {aka ‘int (*)(short unsigned int)’} to
‘gnulib::_gl_iswalnum_wrapper::type’ {aka ‘int (*)(unsigned int)’}
[-fpermissive]
 _GL_CXXALIAS_SYS (iswalnum, int, (wint_t wc));
 ^~~~~~~~~~~~~~~~

(and followed by many other is* functions)

This only fails with GNULIB_NAMESPACE defined (this is, I think, the
only file in gdb that does define it)

Any thoughts on this one? Let me know if you need any more data
(config.log, etc.)

Christian


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: wctype.h compile error on mingw with GNULIB_NAMESPACE
  2019-11-16 22:41         ` wctype.h compile error on mingw with GNULIB_NAMESPACE Christian Biesinger
@ 2019-11-17  3:05           ` Bruno Haible
  2019-11-17  4:40             ` Christian Biesinger
  0 siblings, 1 reply; 13+ messages in thread
From: Bruno Haible @ 2019-11-17  3:05 UTC (permalink / raw)
  To: Christian Biesinger; +Cc: bug-gnulib

Hello Christian,

> Specifically, this testcase:
> 
> #define GNULIB_NAMESPACE gnulib
> #include "gnulib/config.h"
> #include "wctype.h"
> 
> x86_64-w64-mingw32-g++ -c test.cc -I build/gnulib/import/ -I
> binutils-gdb/gnulib/import/
> 
> Fails with errors like:
> gnulib/import/wctype.h: In member function
> ‘gnulib::_gl_iswalnum_wrapper::operator
> gnulib::_gl_iswalnum_wrapper::type() const’:
> gnulib/import/wctype.h:856:1: error: invalid conversion from ‘int
> (*)(wint_t)’ {aka ‘int (*)(short unsigned int)’} to
> ‘gnulib::_gl_iswalnum_wrapper::type’ {aka ‘int (*)(unsigned int)’}
> [-fpermissive]
>  _GL_CXXALIAS_SYS (iswalnum, int, (wint_t wc));
>  ^~~~~~~~~~~~~~~~
> 
> (and followed by many other is* functions)

Fixed through the following patch.


2019-11-16  Bruno Haible  <bruno@clisp.org>

	wctype-h: When overriding wint_t, override also the related functions.
	Reported by Christian Biesinger <cbiesinger@google.com> in
	<https://lists.gnu.org/archive/html/bug-gnulib/2019-11/msg00027.html>.
	* m4/wctype_h.m4 (gl_WCTYPE_H): When GNULIB_OVERRIDES_WINT_T is 1, set
	REPLACE_ISWCNTRL to 1.
	* lib/wctype.in.h (rpl_iswalnum, rpl_iswalpha, rpl_iswblank,
	rpl_iswcntrl, rpl_iswdigit, rpl_iswgraph, rpl_iswlower, rpl_iswprint,
	rpl_iswpunct, rpl_iswspace, rpl_iswupper, rpl_iswxdigit, rpl_towlower,
	rpl_towupper): New definitions when GNULIB_OVERRIDES_WINT_T is 1.
	* doc/posix-headers/wchar.texi: Mention that wint_t is also overridden
	on mingw.
	* doc/posix-headers/wctype.texi: Likewise.

diff --git a/doc/posix-headers/wchar.texi b/doc/posix-headers/wchar.texi
index 5336d6b..6a94f13 100644
--- a/doc/posix-headers/wchar.texi
+++ b/doc/posix-headers/wchar.texi
@@ -12,7 +12,7 @@ This header file cannot be included on some platforms:
 Linux uClibc built without wide character support.
 @item
 The type @code{wint_t} is incorrect on some platforms:
-MSVC 14.
+mingw, MSVC 14.
 
 @item
 Some platforms provide a @code{NULL} macro that cannot be used in arbitrary
diff --git a/doc/posix-headers/wctype.texi b/doc/posix-headers/wctype.texi
index e288094..b97d491 100644
--- a/doc/posix-headers/wctype.texi
+++ b/doc/posix-headers/wctype.texi
@@ -12,7 +12,7 @@ This header file is missing on some platforms:
 HP-UX 11.00.
 @item
 The type @code{wint_t} is incorrect on some platforms:
-MSVC 14.
+mingw, MSVC 14.
 @item
 The functions @code{isw*} are missing on some platforms:
 FreeBSD 4.11.
diff --git a/lib/wctype.in.h b/lib/wctype.in.h
index 3cd568e..1a04742 100644
--- a/lib/wctype.in.h
+++ b/lib/wctype.in.h
@@ -133,33 +133,113 @@ typedef unsigned int rpl_wint_t;
 
 /* FreeBSD 4.4 to 4.11 has <wctype.h> but lacks the functions.
    Linux libc5 has <wctype.h> and the functions but they are broken.
+   mingw and MSVC have <wctype.h> and the functions but they take a wchar_t
+   as argument, not an rpl_wint_t.
    Assume all 11 functions (all isw* except iswblank) are implemented the
    same way, or not at all.  */
 # if ! @HAVE_ISWCNTRL@ || @REPLACE_ISWCNTRL@
 
-/* IRIX 5.3 has macros but no functions, its isw* macros refer to an
-   undefined variable _ctmp_ and to <ctype.h> macros like _P, and they
-   refer to system functions like _iswctype that are not in the
-   standard C library.  Rather than try to get ancient buggy
-   implementations like this to work, just disable them.  */
-#  undef iswalnum
-#  undef iswalpha
-#  undef iswblank
-#  undef iswcntrl
-#  undef iswdigit
-#  undef iswgraph
-#  undef iswlower
-#  undef iswprint
-#  undef iswpunct
-#  undef iswspace
-#  undef iswupper
-#  undef iswxdigit
-#  undef towlower
-#  undef towupper
+#  if @GNULIB_OVERRIDES_WINT_T@ /* implies @REPLACE_ISWCNTRL@ */
+
+_GL_WCTYPE_INLINE int
+rpl_iswalnum (wint_t wc)
+{
+  return ((wchar_t) wc == wc ? iswalnum ((wchar_t) wc) : 0);
+}
+
+_GL_WCTYPE_INLINE int
+rpl_iswalpha (wint_t wc)
+{
+  return ((wchar_t) wc == wc ? iswalpha ((wchar_t) wc) : 0);
+}
+
+_GL_WCTYPE_INLINE int
+rpl_iswblank (wint_t wc)
+{
+  return ((wchar_t) wc == wc ? iswblank ((wchar_t) wc) : 0);
+}
+
+_GL_WCTYPE_INLINE int
+rpl_iswcntrl (wint_t wc)
+{
+  return ((wchar_t) wc == wc ? iswcntrl ((wchar_t) wc) : 0);
+}
+
+_GL_WCTYPE_INLINE int
+rpl_iswdigit (wint_t wc)
+{
+  return ((wchar_t) wc == wc ? iswdigit ((wchar_t) wc) : 0);
+}
+
+_GL_WCTYPE_INLINE int
+rpl_iswgraph (wint_t wc)
+{
+  return ((wchar_t) wc == wc ? iswgraph ((wchar_t) wc) : 0);
+}
+
+_GL_WCTYPE_INLINE int
+rpl_iswlower (wint_t wc)
+{
+  return ((wchar_t) wc == wc ? iswlower ((wchar_t) wc) : 0);
+}
+
+_GL_WCTYPE_INLINE int
+rpl_iswprint (wint_t wc)
+{
+  return ((wchar_t) wc == wc ? iswprint ((wchar_t) wc) : 0);
+}
+
+_GL_WCTYPE_INLINE int
+rpl_iswpunct (wint_t wc)
+{
+  return ((wchar_t) wc == wc ? iswpunct ((wchar_t) wc) : 0);
+}
+
+_GL_WCTYPE_INLINE int
+rpl_iswspace (wint_t wc)
+{
+  return ((wchar_t) wc == wc ? iswspace ((wchar_t) wc) : 0);
+}
+
+_GL_WCTYPE_INLINE int
+rpl_iswupper (wint_t wc)
+{
+  return ((wchar_t) wc == wc ? iswupper ((wchar_t) wc) : 0);
+}
+
+_GL_WCTYPE_INLINE int
+rpl_iswxdigit (wint_t wc)
+{
+  return ((wchar_t) wc == wc ? iswxdigit ((wchar_t) wc) : 0);
+}
+
+_GL_WCTYPE_INLINE wint_t
+rpl_towlower (wint_t wc)
+{
+  return ((wchar_t) wc == wc ? (wchar_t) towlower ((wchar_t) wc) : wc);
+}
+
+_GL_WCTYPE_INLINE wint_t
+rpl_towupper (wint_t wc)
+{
+  return ((wchar_t) wc == wc ? (wchar_t) towupper ((wchar_t) wc) : wc);
+}
 
-/* Linux libc5 has <wctype.h> and the functions but they are broken.  */
-#  if @REPLACE_ISWCNTRL@
 #   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#    undef iswalnum
+#    undef iswalpha
+#    undef iswblank
+#    undef iswcntrl
+#    undef iswdigit
+#    undef iswgraph
+#    undef iswlower
+#    undef iswprint
+#    undef iswpunct
+#    undef iswspace
+#    undef iswupper
+#    undef iswxdigit
+#    undef towlower
+#    undef towupper
 #    define iswalnum rpl_iswalnum
 #    define iswalpha rpl_iswalpha
 #    define iswblank rpl_iswblank
@@ -172,21 +252,62 @@ typedef unsigned int rpl_wint_t;
 #    define iswspace rpl_iswspace
 #    define iswupper rpl_iswupper
 #    define iswxdigit rpl_iswxdigit
-#   endif
-#  endif
-#  if @REPLACE_TOWLOWER@
-#   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #    define towlower rpl_towlower
 #    define towupper rpl_towupper
 #   endif
-#  endif
+
+#  else
+
+/* IRIX 5.3 has macros but no functions, its isw* macros refer to an
+   undefined variable _ctmp_ and to <ctype.h> macros like _P, and they
+   refer to system functions like _iswctype that are not in the
+   standard C library.  Rather than try to get ancient buggy
+   implementations like this to work, just disable them.  */
+#   undef iswalnum
+#   undef iswalpha
+#   undef iswblank
+#   undef iswcntrl
+#   undef iswdigit
+#   undef iswgraph
+#   undef iswlower
+#   undef iswprint
+#   undef iswpunct
+#   undef iswspace
+#   undef iswupper
+#   undef iswxdigit
+#   undef towlower
+#   undef towupper
+
+/* Linux libc5 has <wctype.h> and the functions but they are broken.  */
+#   if @REPLACE_ISWCNTRL@
+#    if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#     define iswalnum rpl_iswalnum
+#     define iswalpha rpl_iswalpha
+#     define iswblank rpl_iswblank
+#     define iswcntrl rpl_iswcntrl
+#     define iswdigit rpl_iswdigit
+#     define iswgraph rpl_iswgraph
+#     define iswlower rpl_iswlower
+#     define iswprint rpl_iswprint
+#     define iswpunct rpl_iswpunct
+#     define iswspace rpl_iswspace
+#     define iswupper rpl_iswupper
+#     define iswxdigit rpl_iswxdigit
+#    endif
+#   endif
+#   if @REPLACE_TOWLOWER@
+#    if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#     define towlower rpl_towlower
+#     define towupper rpl_towupper
+#    endif
+#   endif
 
 _GL_WCTYPE_INLINE int
-#  if @REPLACE_ISWCNTRL@
+#   if @REPLACE_ISWCNTRL@
 rpl_iswalnum
-#  else
+#   else
 iswalnum
-#  endif
+#   endif
          (wint_t wc)
 {
   return ((wc >= '0' && wc <= '9')
@@ -194,88 +315,88 @@ iswalnum
 }
 
 _GL_WCTYPE_INLINE int
-#  if @REPLACE_ISWCNTRL@
+#   if @REPLACE_ISWCNTRL@
 rpl_iswalpha
-#  else
+#   else
 iswalpha
-#  endif
+#   endif
          (wint_t wc)
 {
   return (wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z';
 }
 
 _GL_WCTYPE_INLINE int
-#  if @REPLACE_ISWCNTRL@
+#   if @REPLACE_ISWCNTRL@
 rpl_iswblank
-#  else
+#   else
 iswblank
-#  endif
+#   endif
          (wint_t wc)
 {
   return wc == ' ' || wc == '\t';
 }
 
 _GL_WCTYPE_INLINE int
-#  if @REPLACE_ISWCNTRL@
+#   if @REPLACE_ISWCNTRL@
 rpl_iswcntrl
-#  else
+#   else
 iswcntrl
-#  endif
+#   endif
         (wint_t wc)
 {
   return (wc & ~0x1f) == 0 || wc == 0x7f;
 }
 
 _GL_WCTYPE_INLINE int
-#  if @REPLACE_ISWCNTRL@
+#   if @REPLACE_ISWCNTRL@
 rpl_iswdigit
-#  else
+#   else
 iswdigit
-#  endif
+#   endif
          (wint_t wc)
 {
   return wc >= '0' && wc <= '9';
 }
 
 _GL_WCTYPE_INLINE int
-#  if @REPLACE_ISWCNTRL@
+#   if @REPLACE_ISWCNTRL@
 rpl_iswgraph
-#  else
+#   else
 iswgraph
-#  endif
+#   endif
          (wint_t wc)
 {
   return wc >= '!' && wc <= '~';
 }
 
 _GL_WCTYPE_INLINE int
-#  if @REPLACE_ISWCNTRL@
+#   if @REPLACE_ISWCNTRL@
 rpl_iswlower
-#  else
+#   else
 iswlower
-#  endif
+#   endif
          (wint_t wc)
 {
   return wc >= 'a' && wc <= 'z';
 }
 
 _GL_WCTYPE_INLINE int
-#  if @REPLACE_ISWCNTRL@
+#   if @REPLACE_ISWCNTRL@
 rpl_iswprint
-#  else
+#   else
 iswprint
-#  endif
+#   endif
          (wint_t wc)
 {
   return wc >= ' ' && wc <= '~';
 }
 
 _GL_WCTYPE_INLINE int
-#  if @REPLACE_ISWCNTRL@
+#   if @REPLACE_ISWCNTRL@
 rpl_iswpunct
-#  else
+#   else
 iswpunct
-#  endif
+#   endif
          (wint_t wc)
 {
   return (wc >= '!' && wc <= '~'
@@ -284,11 +405,11 @@ iswpunct
 }
 
 _GL_WCTYPE_INLINE int
-#  if @REPLACE_ISWCNTRL@
+#   if @REPLACE_ISWCNTRL@
 rpl_iswspace
-#  else
+#   else
 iswspace
-#  endif
+#   endif
          (wint_t wc)
 {
   return (wc == ' ' || wc == '\t'
@@ -296,22 +417,22 @@ iswspace
 }
 
 _GL_WCTYPE_INLINE int
-#  if @REPLACE_ISWCNTRL@
+#   if @REPLACE_ISWCNTRL@
 rpl_iswupper
-#  else
+#   else
 iswupper
-#  endif
+#   endif
          (wint_t wc)
 {
   return wc >= 'A' && wc <= 'Z';
 }
 
 _GL_WCTYPE_INLINE int
-#  if @REPLACE_ISWCNTRL@
+#   if @REPLACE_ISWCNTRL@
 rpl_iswxdigit
-#  else
+#   else
 iswxdigit
-#  endif
+#   endif
           (wint_t wc)
 {
   return ((wc >= '0' && wc <= '9')
@@ -319,27 +440,29 @@ iswxdigit
 }
 
 _GL_WCTYPE_INLINE wint_t
-#  if @REPLACE_TOWLOWER@
+#   if @REPLACE_TOWLOWER@
 rpl_towlower
-#  else
+#   else
 towlower
-#  endif
+#   endif
          (wint_t wc)
 {
   return (wc >= 'A' && wc <= 'Z' ? wc - 'A' + 'a' : wc);
 }
 
 _GL_WCTYPE_INLINE wint_t
-#  if @REPLACE_TOWLOWER@
+#   if @REPLACE_TOWLOWER@
 rpl_towupper
-#  else
+#   else
 towupper
-#  endif
+#   endif
          (wint_t wc)
 {
   return (wc >= 'a' && wc <= 'z' ? wc - 'a' + 'A' : wc);
 }
 
+#  endif
+
 # elif @GNULIB_ISWBLANK@ && (! @HAVE_ISWBLANK@ || @REPLACE_ISWBLANK@)
 /* Only the iswblank function is missing.  */
 
@@ -354,7 +477,7 @@ _GL_FUNCDECL_SYS (iswblank, int, (wint_t wc));
 
 # endif
 
-# if defined __MINGW32__
+# if defined __MINGW32__ && !@GNULIB_OVERRIDES_WINT_T@
 
 /* On native Windows, wchar_t is uint16_t, and wint_t is uint32_t.
    The functions towlower and towupper are implemented in the MSVCRT library
@@ -387,7 +510,7 @@ rpl_towupper (wint_t wc)
 #   define towupper rpl_towupper
 #  endif
 
-# endif /* __MINGW32__ */
+# endif /* __MINGW32__ && !@GNULIB_OVERRIDES_WINT_T@ */
 
 # define GNULIB_defined_wctype_functions 1
 #endif
diff --git a/m4/wctype_h.m4 b/m4/wctype_h.m4
index 6903d75..d5acb72 100644
--- a/m4/wctype_h.m4
+++ b/m4/wctype_h.m4
@@ -1,4 +1,4 @@
-# wctype_h.m4 serial 21
+# wctype_h.m4 serial 22
 
 dnl A placeholder for ISO C99 <wctype.h>, for platforms that lack it.
 
@@ -69,10 +69,14 @@ AC_DEFUN([gl_WCTYPE_H],
   fi
   AC_SUBST([HAVE_WCTYPE_H])
 
-  case "$gl_cv_func_iswcntrl_works" in
-    *yes) REPLACE_ISWCNTRL=0 ;;
-    *)    REPLACE_ISWCNTRL=1 ;;
-  esac
+  if test $GNULIB_OVERRIDES_WINT_T = 1; then
+    REPLACE_ISWCNTRL=1
+  else
+    case "$gl_cv_func_iswcntrl_works" in
+      *yes) REPLACE_ISWCNTRL=0 ;;
+      *)    REPLACE_ISWCNTRL=1 ;;
+    esac
+  fi
   AC_SUBST([REPLACE_ISWCNTRL])
 
   if test $HAVE_ISWCNTRL = 0 || test $REPLACE_ISWCNTRL = 1; then



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: wctype.h compile error on mingw with GNULIB_NAMESPACE
  2019-11-17  3:05           ` Bruno Haible
@ 2019-11-17  4:40             ` Christian Biesinger
  2019-11-24 19:15               ` Bruno Haible
  0 siblings, 1 reply; 13+ messages in thread
From: Christian Biesinger @ 2019-11-17  4:40 UTC (permalink / raw)
  To: Bruno Haible; +Cc: bug-gnulib

On Sat, Nov 16, 2019 at 9:05 PM Bruno Haible <bruno@clisp.org> wrote:
>
> Hello Christian,
>
> > Specifically, this testcase:
> >
> > #define GNULIB_NAMESPACE gnulib
> > #include "gnulib/config.h"
> > #include "wctype.h"
> >
> > x86_64-w64-mingw32-g++ -c test.cc -I build/gnulib/import/ -I
> > binutils-gdb/gnulib/import/
> >
> > Fails with errors like:
> > gnulib/import/wctype.h: In member function
> > ‘gnulib::_gl_iswalnum_wrapper::operator
> > gnulib::_gl_iswalnum_wrapper::type() const’:
> > gnulib/import/wctype.h:856:1: error: invalid conversion from ‘int
> > (*)(wint_t)’ {aka ‘int (*)(short unsigned int)’} to
> > ‘gnulib::_gl_iswalnum_wrapper::type’ {aka ‘int (*)(unsigned int)’}
> > [-fpermissive]
> >  _GL_CXXALIAS_SYS (iswalnum, int, (wint_t wc));
> >  ^~~~~~~~~~~~~~~~
> >
> > (and followed by many other is* functions)
>
> Fixed through the following patch.

Thanks for your quick patches! This solves the problem for me.

Christian

> 2019-11-16  Bruno Haible  <bruno@clisp.org>
>
>         wctype-h: When overriding wint_t, override also the related functions.
>         Reported by Christian Biesinger <cbiesinger@google.com> in
>         <https://lists.gnu.org/archive/html/bug-gnulib/2019-11/msg00027.html>.
>         * m4/wctype_h.m4 (gl_WCTYPE_H): When GNULIB_OVERRIDES_WINT_T is 1, set
>         REPLACE_ISWCNTRL to 1.
>         * lib/wctype.in.h (rpl_iswalnum, rpl_iswalpha, rpl_iswblank,
>         rpl_iswcntrl, rpl_iswdigit, rpl_iswgraph, rpl_iswlower, rpl_iswprint,
>         rpl_iswpunct, rpl_iswspace, rpl_iswupper, rpl_iswxdigit, rpl_towlower,
>         rpl_towupper): New definitions when GNULIB_OVERRIDES_WINT_T is 1.
>         * doc/posix-headers/wchar.texi: Mention that wint_t is also overridden
>         on mingw.
>         * doc/posix-headers/wctype.texi: Likewise.
>
> diff --git a/doc/posix-headers/wchar.texi b/doc/posix-headers/wchar.texi
> index 5336d6b..6a94f13 100644
> --- a/doc/posix-headers/wchar.texi
> +++ b/doc/posix-headers/wchar.texi
> @@ -12,7 +12,7 @@ This header file cannot be included on some platforms:
>  Linux uClibc built without wide character support.
>  @item
>  The type @code{wint_t} is incorrect on some platforms:
> -MSVC 14.
> +mingw, MSVC 14.
>
>  @item
>  Some platforms provide a @code{NULL} macro that cannot be used in arbitrary
> diff --git a/doc/posix-headers/wctype.texi b/doc/posix-headers/wctype.texi
> index e288094..b97d491 100644
> --- a/doc/posix-headers/wctype.texi
> +++ b/doc/posix-headers/wctype.texi
> @@ -12,7 +12,7 @@ This header file is missing on some platforms:
>  HP-UX 11.00.
>  @item
>  The type @code{wint_t} is incorrect on some platforms:
> -MSVC 14.
> +mingw, MSVC 14.
>  @item
>  The functions @code{isw*} are missing on some platforms:
>  FreeBSD 4.11.
> diff --git a/lib/wctype.in.h b/lib/wctype.in.h
> index 3cd568e..1a04742 100644
> --- a/lib/wctype.in.h
> +++ b/lib/wctype.in.h
> @@ -133,33 +133,113 @@ typedef unsigned int rpl_wint_t;
>
>  /* FreeBSD 4.4 to 4.11 has <wctype.h> but lacks the functions.
>     Linux libc5 has <wctype.h> and the functions but they are broken.
> +   mingw and MSVC have <wctype.h> and the functions but they take a wchar_t
> +   as argument, not an rpl_wint_t.
>     Assume all 11 functions (all isw* except iswblank) are implemented the
>     same way, or not at all.  */
>  # if ! @HAVE_ISWCNTRL@ || @REPLACE_ISWCNTRL@
>
> -/* IRIX 5.3 has macros but no functions, its isw* macros refer to an
> -   undefined variable _ctmp_ and to <ctype.h> macros like _P, and they
> -   refer to system functions like _iswctype that are not in the
> -   standard C library.  Rather than try to get ancient buggy
> -   implementations like this to work, just disable them.  */
> -#  undef iswalnum
> -#  undef iswalpha
> -#  undef iswblank
> -#  undef iswcntrl
> -#  undef iswdigit
> -#  undef iswgraph
> -#  undef iswlower
> -#  undef iswprint
> -#  undef iswpunct
> -#  undef iswspace
> -#  undef iswupper
> -#  undef iswxdigit
> -#  undef towlower
> -#  undef towupper
> +#  if @GNULIB_OVERRIDES_WINT_T@ /* implies @REPLACE_ISWCNTRL@ */
> +
> +_GL_WCTYPE_INLINE int
> +rpl_iswalnum (wint_t wc)
> +{
> +  return ((wchar_t) wc == wc ? iswalnum ((wchar_t) wc) : 0);
> +}
> +
> +_GL_WCTYPE_INLINE int
> +rpl_iswalpha (wint_t wc)
> +{
> +  return ((wchar_t) wc == wc ? iswalpha ((wchar_t) wc) : 0);
> +}
> +
> +_GL_WCTYPE_INLINE int
> +rpl_iswblank (wint_t wc)
> +{
> +  return ((wchar_t) wc == wc ? iswblank ((wchar_t) wc) : 0);
> +}
> +
> +_GL_WCTYPE_INLINE int
> +rpl_iswcntrl (wint_t wc)
> +{
> +  return ((wchar_t) wc == wc ? iswcntrl ((wchar_t) wc) : 0);
> +}
> +
> +_GL_WCTYPE_INLINE int
> +rpl_iswdigit (wint_t wc)
> +{
> +  return ((wchar_t) wc == wc ? iswdigit ((wchar_t) wc) : 0);
> +}
> +
> +_GL_WCTYPE_INLINE int
> +rpl_iswgraph (wint_t wc)
> +{
> +  return ((wchar_t) wc == wc ? iswgraph ((wchar_t) wc) : 0);
> +}
> +
> +_GL_WCTYPE_INLINE int
> +rpl_iswlower (wint_t wc)
> +{
> +  return ((wchar_t) wc == wc ? iswlower ((wchar_t) wc) : 0);
> +}
> +
> +_GL_WCTYPE_INLINE int
> +rpl_iswprint (wint_t wc)
> +{
> +  return ((wchar_t) wc == wc ? iswprint ((wchar_t) wc) : 0);
> +}
> +
> +_GL_WCTYPE_INLINE int
> +rpl_iswpunct (wint_t wc)
> +{
> +  return ((wchar_t) wc == wc ? iswpunct ((wchar_t) wc) : 0);
> +}
> +
> +_GL_WCTYPE_INLINE int
> +rpl_iswspace (wint_t wc)
> +{
> +  return ((wchar_t) wc == wc ? iswspace ((wchar_t) wc) : 0);
> +}
> +
> +_GL_WCTYPE_INLINE int
> +rpl_iswupper (wint_t wc)
> +{
> +  return ((wchar_t) wc == wc ? iswupper ((wchar_t) wc) : 0);
> +}
> +
> +_GL_WCTYPE_INLINE int
> +rpl_iswxdigit (wint_t wc)
> +{
> +  return ((wchar_t) wc == wc ? iswxdigit ((wchar_t) wc) : 0);
> +}
> +
> +_GL_WCTYPE_INLINE wint_t
> +rpl_towlower (wint_t wc)
> +{
> +  return ((wchar_t) wc == wc ? (wchar_t) towlower ((wchar_t) wc) : wc);
> +}
> +
> +_GL_WCTYPE_INLINE wint_t
> +rpl_towupper (wint_t wc)
> +{
> +  return ((wchar_t) wc == wc ? (wchar_t) towupper ((wchar_t) wc) : wc);
> +}
>
> -/* Linux libc5 has <wctype.h> and the functions but they are broken.  */
> -#  if @REPLACE_ISWCNTRL@
>  #   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
> +#    undef iswalnum
> +#    undef iswalpha
> +#    undef iswblank
> +#    undef iswcntrl
> +#    undef iswdigit
> +#    undef iswgraph
> +#    undef iswlower
> +#    undef iswprint
> +#    undef iswpunct
> +#    undef iswspace
> +#    undef iswupper
> +#    undef iswxdigit
> +#    undef towlower
> +#    undef towupper
>  #    define iswalnum rpl_iswalnum
>  #    define iswalpha rpl_iswalpha
>  #    define iswblank rpl_iswblank
> @@ -172,21 +252,62 @@ typedef unsigned int rpl_wint_t;
>  #    define iswspace rpl_iswspace
>  #    define iswupper rpl_iswupper
>  #    define iswxdigit rpl_iswxdigit
> -#   endif
> -#  endif
> -#  if @REPLACE_TOWLOWER@
> -#   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
>  #    define towlower rpl_towlower
>  #    define towupper rpl_towupper
>  #   endif
> -#  endif
> +
> +#  else
> +
> +/* IRIX 5.3 has macros but no functions, its isw* macros refer to an
> +   undefined variable _ctmp_ and to <ctype.h> macros like _P, and they
> +   refer to system functions like _iswctype that are not in the
> +   standard C library.  Rather than try to get ancient buggy
> +   implementations like this to work, just disable them.  */
> +#   undef iswalnum
> +#   undef iswalpha
> +#   undef iswblank
> +#   undef iswcntrl
> +#   undef iswdigit
> +#   undef iswgraph
> +#   undef iswlower
> +#   undef iswprint
> +#   undef iswpunct
> +#   undef iswspace
> +#   undef iswupper
> +#   undef iswxdigit
> +#   undef towlower
> +#   undef towupper
> +
> +/* Linux libc5 has <wctype.h> and the functions but they are broken.  */
> +#   if @REPLACE_ISWCNTRL@
> +#    if !(defined __cplusplus && defined GNULIB_NAMESPACE)
> +#     define iswalnum rpl_iswalnum
> +#     define iswalpha rpl_iswalpha
> +#     define iswblank rpl_iswblank
> +#     define iswcntrl rpl_iswcntrl
> +#     define iswdigit rpl_iswdigit
> +#     define iswgraph rpl_iswgraph
> +#     define iswlower rpl_iswlower
> +#     define iswprint rpl_iswprint
> +#     define iswpunct rpl_iswpunct
> +#     define iswspace rpl_iswspace
> +#     define iswupper rpl_iswupper
> +#     define iswxdigit rpl_iswxdigit
> +#    endif
> +#   endif
> +#   if @REPLACE_TOWLOWER@
> +#    if !(defined __cplusplus && defined GNULIB_NAMESPACE)
> +#     define towlower rpl_towlower
> +#     define towupper rpl_towupper
> +#    endif
> +#   endif
>
>  _GL_WCTYPE_INLINE int
> -#  if @REPLACE_ISWCNTRL@
> +#   if @REPLACE_ISWCNTRL@
>  rpl_iswalnum
> -#  else
> +#   else
>  iswalnum
> -#  endif
> +#   endif
>           (wint_t wc)
>  {
>    return ((wc >= '0' && wc <= '9')
> @@ -194,88 +315,88 @@ iswalnum
>  }
>
>  _GL_WCTYPE_INLINE int
> -#  if @REPLACE_ISWCNTRL@
> +#   if @REPLACE_ISWCNTRL@
>  rpl_iswalpha
> -#  else
> +#   else
>  iswalpha
> -#  endif
> +#   endif
>           (wint_t wc)
>  {
>    return (wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z';
>  }
>
>  _GL_WCTYPE_INLINE int
> -#  if @REPLACE_ISWCNTRL@
> +#   if @REPLACE_ISWCNTRL@
>  rpl_iswblank
> -#  else
> +#   else
>  iswblank
> -#  endif
> +#   endif
>           (wint_t wc)
>  {
>    return wc == ' ' || wc == '\t';
>  }
>
>  _GL_WCTYPE_INLINE int
> -#  if @REPLACE_ISWCNTRL@
> +#   if @REPLACE_ISWCNTRL@
>  rpl_iswcntrl
> -#  else
> +#   else
>  iswcntrl
> -#  endif
> +#   endif
>          (wint_t wc)
>  {
>    return (wc & ~0x1f) == 0 || wc == 0x7f;
>  }
>
>  _GL_WCTYPE_INLINE int
> -#  if @REPLACE_ISWCNTRL@
> +#   if @REPLACE_ISWCNTRL@
>  rpl_iswdigit
> -#  else
> +#   else
>  iswdigit
> -#  endif
> +#   endif
>           (wint_t wc)
>  {
>    return wc >= '0' && wc <= '9';
>  }
>
>  _GL_WCTYPE_INLINE int
> -#  if @REPLACE_ISWCNTRL@
> +#   if @REPLACE_ISWCNTRL@
>  rpl_iswgraph
> -#  else
> +#   else
>  iswgraph
> -#  endif
> +#   endif
>           (wint_t wc)
>  {
>    return wc >= '!' && wc <= '~';
>  }
>
>  _GL_WCTYPE_INLINE int
> -#  if @REPLACE_ISWCNTRL@
> +#   if @REPLACE_ISWCNTRL@
>  rpl_iswlower
> -#  else
> +#   else
>  iswlower
> -#  endif
> +#   endif
>           (wint_t wc)
>  {
>    return wc >= 'a' && wc <= 'z';
>  }
>
>  _GL_WCTYPE_INLINE int
> -#  if @REPLACE_ISWCNTRL@
> +#   if @REPLACE_ISWCNTRL@
>  rpl_iswprint
> -#  else
> +#   else
>  iswprint
> -#  endif
> +#   endif
>           (wint_t wc)
>  {
>    return wc >= ' ' && wc <= '~';
>  }
>
>  _GL_WCTYPE_INLINE int
> -#  if @REPLACE_ISWCNTRL@
> +#   if @REPLACE_ISWCNTRL@
>  rpl_iswpunct
> -#  else
> +#   else
>  iswpunct
> -#  endif
> +#   endif
>           (wint_t wc)
>  {
>    return (wc >= '!' && wc <= '~'
> @@ -284,11 +405,11 @@ iswpunct
>  }
>
>  _GL_WCTYPE_INLINE int
> -#  if @REPLACE_ISWCNTRL@
> +#   if @REPLACE_ISWCNTRL@
>  rpl_iswspace
> -#  else
> +#   else
>  iswspace
> -#  endif
> +#   endif
>           (wint_t wc)
>  {
>    return (wc == ' ' || wc == '\t'
> @@ -296,22 +417,22 @@ iswspace
>  }
>
>  _GL_WCTYPE_INLINE int
> -#  if @REPLACE_ISWCNTRL@
> +#   if @REPLACE_ISWCNTRL@
>  rpl_iswupper
> -#  else
> +#   else
>  iswupper
> -#  endif
> +#   endif
>           (wint_t wc)
>  {
>    return wc >= 'A' && wc <= 'Z';
>  }
>
>  _GL_WCTYPE_INLINE int
> -#  if @REPLACE_ISWCNTRL@
> +#   if @REPLACE_ISWCNTRL@
>  rpl_iswxdigit
> -#  else
> +#   else
>  iswxdigit
> -#  endif
> +#   endif
>            (wint_t wc)
>  {
>    return ((wc >= '0' && wc <= '9')
> @@ -319,27 +440,29 @@ iswxdigit
>  }
>
>  _GL_WCTYPE_INLINE wint_t
> -#  if @REPLACE_TOWLOWER@
> +#   if @REPLACE_TOWLOWER@
>  rpl_towlower
> -#  else
> +#   else
>  towlower
> -#  endif
> +#   endif
>           (wint_t wc)
>  {
>    return (wc >= 'A' && wc <= 'Z' ? wc - 'A' + 'a' : wc);
>  }
>
>  _GL_WCTYPE_INLINE wint_t
> -#  if @REPLACE_TOWLOWER@
> +#   if @REPLACE_TOWLOWER@
>  rpl_towupper
> -#  else
> +#   else
>  towupper
> -#  endif
> +#   endif
>           (wint_t wc)
>  {
>    return (wc >= 'a' && wc <= 'z' ? wc - 'a' + 'A' : wc);
>  }
>
> +#  endif
> +
>  # elif @GNULIB_ISWBLANK@ && (! @HAVE_ISWBLANK@ || @REPLACE_ISWBLANK@)
>  /* Only the iswblank function is missing.  */
>
> @@ -354,7 +477,7 @@ _GL_FUNCDECL_SYS (iswblank, int, (wint_t wc));
>
>  # endif
>
> -# if defined __MINGW32__
> +# if defined __MINGW32__ && !@GNULIB_OVERRIDES_WINT_T@
>
>  /* On native Windows, wchar_t is uint16_t, and wint_t is uint32_t.
>     The functions towlower and towupper are implemented in the MSVCRT library
> @@ -387,7 +510,7 @@ rpl_towupper (wint_t wc)
>  #   define towupper rpl_towupper
>  #  endif
>
> -# endif /* __MINGW32__ */
> +# endif /* __MINGW32__ && !@GNULIB_OVERRIDES_WINT_T@ */
>
>  # define GNULIB_defined_wctype_functions 1
>  #endif
> diff --git a/m4/wctype_h.m4 b/m4/wctype_h.m4
> index 6903d75..d5acb72 100644
> --- a/m4/wctype_h.m4
> +++ b/m4/wctype_h.m4
> @@ -1,4 +1,4 @@
> -# wctype_h.m4 serial 21
> +# wctype_h.m4 serial 22
>
>  dnl A placeholder for ISO C99 <wctype.h>, for platforms that lack it.
>
> @@ -69,10 +69,14 @@ AC_DEFUN([gl_WCTYPE_H],
>    fi
>    AC_SUBST([HAVE_WCTYPE_H])
>
> -  case "$gl_cv_func_iswcntrl_works" in
> -    *yes) REPLACE_ISWCNTRL=0 ;;
> -    *)    REPLACE_ISWCNTRL=1 ;;
> -  esac
> +  if test $GNULIB_OVERRIDES_WINT_T = 1; then
> +    REPLACE_ISWCNTRL=1
> +  else
> +    case "$gl_cv_func_iswcntrl_works" in
> +      *yes) REPLACE_ISWCNTRL=0 ;;
> +      *)    REPLACE_ISWCNTRL=1 ;;
> +    esac
> +  fi
>    AC_SUBST([REPLACE_ISWCNTRL])
>
>    if test $HAVE_ISWCNTRL = 0 || test $REPLACE_ISWCNTRL = 1; then
>


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: time_r module does not work on MingW
  2019-11-16 12:15       ` Bruno Haible
  2019-11-16 22:41         ` wctype.h compile error on mingw with GNULIB_NAMESPACE Christian Biesinger
@ 2019-11-24 14:06         ` Bruno Haible
  1 sibling, 0 replies; 13+ messages in thread
From: Bruno Haible @ 2019-11-24 14:06 UTC (permalink / raw)
  To: Christian Biesinger; +Cc: bug-gnulib, Christian Biesinger

This patch introduced a regression:

> 2019-11-16  Bruno Haible  <bruno@clisp.org>
> 
> 	time_r: Fix for mingw.
> 	Reported by Christian Biesinger <cbiesinger@google.com> in
> 	<https://lists.gnu.org/archive/html/bug-gnulib/2019-11/msg00014.html>.
> 	* lib/time.in.h: On mingw, include <unistd.h>.
> 	* m4/time_r.m4 (gl_TIME_R): On mingw, include <unistd.h> before
> 	<time.h>. Test for localtime_r in a way that works when it is defined
> 	as an inline function.

Namely a link error in mktime:

../gllib/libgnu.a(mktime.o): In function `rpl_mktime':
/home/bruno/testdir3/build-mingw64/gllib/../../gllib/mktime.c:533: undefined reference to `localtime_r'


2019-11-24  Bruno Haible  <bruno@clisp.org>

	time_r: Fix for mingw (regression from 2019-11-16).
	* m4/time_r.m4 (gl_TIME_R): Revert to using AC_CHECK_FUNCS_ONCE. Use the
	AC_LINK_IFELSE test only if the function does not appear to exist.

diff --git a/m4/time_r.m4 b/m4/time_r.m4
index 72cc975..cc4b3e0 100644
--- a/m4/time_r.m4
+++ b/m4/time_r.m4
@@ -30,28 +30,8 @@ AC_DEFUN([gl_TIME_R],
     HAVE_DECL_LOCALTIME_R=0
   fi
 
-  dnl We can't use AC_CHECK_FUNC here, because localtime_r() is defined as an
-  dnl inline function on mingw.
-  AC_CACHE_CHECK([for localtime_r], [gl_cv_func_localtime_r],
-    [AC_LINK_IFELSE(
-       [AC_LANG_PROGRAM(
-          [[/* mingw's <time.h> provides the functions asctime_r, ctime_r,
-               gmtime_r, localtime_r only if <unistd.h> or <pthread.h> has
-               been included before.  */
-            #if defined __MINGW32__
-            # include <unistd.h>
-            #endif
-            #include <time.h>
-          ]],
-          [[time_t a;
-            struct tm r;
-            localtime_r (&a, &r);
-          ]])
-       ],
-       [gl_cv_func_localtime_r=yes],
-       [gl_cv_func_localtime_r=no])
-    ])
-  if test $gl_cv_func_localtime_r = yes; then
+  AC_CHECK_FUNCS_ONCE([localtime_r])
+  if test $ac_cv_func_localtime_r = yes; then
     HAVE_LOCALTIME_R=1
     AC_CACHE_CHECK([whether localtime_r is compatible with its POSIX signature],
       [gl_cv_time_r_posix],
@@ -84,6 +64,32 @@ AC_DEFUN([gl_TIME_R],
     fi
   else
     HAVE_LOCALTIME_R=0
+    dnl On mingw, localtime_r() is defined as an inline function; use through a
+    dnl direct function call works but the use as a function pointer leads to a
+    dnl link error.
+    AC_CACHE_CHECK([whether localtime_r exists as an inline function],
+      [gl_cv_func_localtime_r_inline],
+      [AC_LINK_IFELSE(
+         [AC_LANG_PROGRAM(
+            [[/* mingw's <time.h> provides the functions asctime_r, ctime_r,
+                 gmtime_r, localtime_r only if <unistd.h> or <pthread.h> has
+                 been included before.  */
+              #if defined __MINGW32__
+              # include <unistd.h>
+              #endif
+              #include <time.h>
+            ]],
+            [[time_t a;
+              struct tm r;
+              localtime_r (&a, &r);
+            ]])
+         ],
+         [gl_cv_func_localtime_r_inline=yes],
+         [gl_cv_func_localtime_r_inline=no])
+      ])
+    if test $gl_cv_func_localtime_r_inline = yes; then
+      REPLACE_LOCALTIME_R=1
+    fi
   fi
 ])
 



^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: wctype.h compile error on mingw with GNULIB_NAMESPACE
  2019-11-17  4:40             ` Christian Biesinger
@ 2019-11-24 19:15               ` Bruno Haible
  2019-11-25 23:28                 ` Christian Biesinger
  0 siblings, 1 reply; 13+ messages in thread
From: Bruno Haible @ 2019-11-24 19:15 UTC (permalink / raw)
  To: Christian Biesinger; +Cc: bug-gnulib

[-- Attachment #1: Type: text/plain, Size: 1476 bytes --]

Christian Biesinger wrote:
> Thanks for your quick patches! This solves the problem for me.

Thanks for the confirmation. Some other patches are needed for the same
thing to work on Cygwin and mingw. Will push them once Savannah is back online.


2019-11-24  Bruno Haible  <bruno@clisp.org>

	Fix errors in C++ mode on Cygwin.
	* lib/sys_wait.in.h (waitpid): Use _GL_CXXALIAS_SYS_CAST instead of
	_GL_CXXALIAS_SYS.

	windows-timedmutex: Fix errors in C++ mode on mingw.
	* lib/windows-timedmutex.h: Add closing brace.

	iswctype: Fix errors in C++ mode on mingw.
	* lib/wctype.in.h (rpl_iswctype): Override if GNULIB_OVERRIDES_WINT_T
	is 1.
	* lib/iswctype.c (iswctype): Add another implementation, for the
	GNULIB_defined_wint_t case.
	* modules/iswctype (configure.ac): Compile iswctype.c also if
	GNULIB_OVERRIDES_WINT_T is 1.

	sys_time: Fix errors in C++ mode on mingw.
	* lib/sys_time.in.h (timeval): Restore the redirection
	'#define timeval rpl_timeval', for when the symbol timeval is being used
	outside the 'gnulib' namespace.
	* lib/sys_select.in.h (select): In C++, write 'timeval', not
	'struct timeval'.

	Fix errors in C++ mode on mingw.
	* lib/arpa_inet.in.h (inet_ntop, inet_pton): Use _GL_CXXALIAS_SYS_CAST
	instead of _GL_CXXALIAS_SYS.
	* lib/signal.in.h (pthread_sigmask): Likewise.
	* lib/spawn.in.h (posix_spawn_file_actions_addopen,
	posix_spawn_file_actions_addclose, posix_spawn_file_actions_adddup2):
	Likewise.
	* lib/wchar.in.h (btowc): Likewise.

[-- Attachment #2: 0001-Fix-errors-in-C-mode-on-Cygwin.patch --]
[-- Type: text/x-patch, Size: 1603 bytes --]

From c67f26eb8394a4e3f63df1e84f777182f13f2f01 Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Sun, 24 Nov 2019 13:28:03 +0100
Subject: [PATCH 1/5] Fix errors in C++ mode on Cygwin.

* lib/sys_wait.in.h (waitpid): Use _GL_CXXALIAS_SYS_CAST instead of
_GL_CXXALIAS_SYS.
---
 ChangeLog         | 6 ++++++
 lib/sys_wait.in.h | 4 +++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 5c2f5c5..d70a898 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2019-11-24  Bruno Haible  <bruno@clisp.org>
 
+	Fix errors in C++ mode on Cygwin.
+	* lib/sys_wait.in.h (waitpid): Use _GL_CXXALIAS_SYS_CAST instead of
+	_GL_CXXALIAS_SYS.
+
+2019-11-24  Bruno Haible  <bruno@clisp.org>
+
 	time_r: Fix for mingw (regression from 2019-11-16).
 	* m4/time_r.m4 (gl_TIME_R): Revert to using AC_CHECK_FUNCS_ONCE. Use the
 	AC_LINK_IFELSE test only if the function does not appear to exist.
diff --git a/lib/sys_wait.in.h b/lib/sys_wait.in.h
index a4c52bb..52b13b3 100644
--- a/lib/sys_wait.in.h
+++ b/lib/sys_wait.in.h
@@ -114,7 +114,9 @@
 # if defined _WIN32 && ! defined __CYGWIN__
 _GL_FUNCDECL_SYS (waitpid, pid_t, (pid_t pid, int *statusp, int options));
 # endif
-_GL_CXXALIAS_SYS (waitpid, pid_t, (pid_t pid, int *statusp, int options));
+/* Need to cast, because on Cygwin, the second parameter is
+                                                __wait_status_ptr_t statusp.  */
+_GL_CXXALIAS_SYS_CAST (waitpid, pid_t, (pid_t pid, int *statusp, int options));
 _GL_CXXALIASWARN (waitpid);
 #elif defined GNULIB_POSIXCHECK
 # undef waitpid
-- 
2.7.4


[-- Attachment #3: 0002-windows-timedmutex-Fix-errors-in-C-mode-on-mingw.patch --]
[-- Type: text/x-patch, Size: 1296 bytes --]

From ae3efebeb1369a08b69d72d62795b67df840a727 Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Sun, 24 Nov 2019 20:10:02 +0100
Subject: [PATCH 2/5] windows-timedmutex: Fix errors in C++ mode on mingw.

* lib/windows-timedmutex.h: Add closing brace.
---
 ChangeLog                | 5 +++++
 lib/windows-timedmutex.h | 4 ++++
 2 files changed, 9 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index d70a898..6be838b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2019-11-24  Bruno Haible  <bruno@clisp.org>
 
+	windows-timedmutex: Fix errors in C++ mode on mingw.
+	* lib/windows-timedmutex.h: Add closing brace.
+
+2019-11-24  Bruno Haible  <bruno@clisp.org>
+
 	Fix errors in C++ mode on Cygwin.
 	* lib/sys_wait.in.h (waitpid): Use _GL_CXXALIAS_SYS_CAST instead of
 	_GL_CXXALIAS_SYS.
diff --git a/lib/windows-timedmutex.h b/lib/windows-timedmutex.h
index b952278..f10a774 100644
--- a/lib/windows-timedmutex.h
+++ b/lib/windows-timedmutex.h
@@ -49,4 +49,8 @@ extern int glwthread_timedmutex_timedlock (glwthread_timedmutex_t *mutex,
 extern int glwthread_timedmutex_unlock (glwthread_timedmutex_t *mutex);
 extern int glwthread_timedmutex_destroy (glwthread_timedmutex_t *mutex);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* _WINDOWS_TIMEDMUTEX_H */
-- 
2.7.4


[-- Attachment #4: 0003-iswctype-Fix-errors-in-C-mode-on-mingw.patch --]
[-- Type: text/x-patch, Size: 3016 bytes --]

From 48c29e1b8c556c8546ec5756563d9f90aafa93ce Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Sun, 24 Nov 2019 20:10:56 +0100
Subject: [PATCH 3/5] iswctype: Fix errors in C++ mode on mingw.

* lib/wctype.in.h (rpl_iswctype): Override if GNULIB_OVERRIDES_WINT_T
is 1.
* lib/iswctype.c (iswctype): Add another implementation, for the
GNULIB_defined_wint_t case.
* modules/iswctype (configure.ac): Compile iswctype.c also if
GNULIB_OVERRIDES_WINT_T is 1.
---
 ChangeLog        | 10 ++++++++++
 lib/iswctype.c   | 15 ++++++++++++++-
 lib/wctype.in.h  | 13 +++++++++++--
 modules/iswctype |  2 +-
 4 files changed, 36 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 6be838b..356edcb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2019-11-24  Bruno Haible  <bruno@clisp.org>
 
+	iswctype: Fix errors in C++ mode on mingw.
+	* lib/wctype.in.h (rpl_iswctype): Override if GNULIB_OVERRIDES_WINT_T
+	is 1.
+	* lib/iswctype.c (iswctype): Add another implementation, for the
+	GNULIB_defined_wint_t case.
+	* modules/iswctype (configure.ac): Compile iswctype.c also if
+	GNULIB_OVERRIDES_WINT_T is 1.
+
+2019-11-24  Bruno Haible  <bruno@clisp.org>
+
 	windows-timedmutex: Fix errors in C++ mode on mingw.
 	* lib/windows-timedmutex.h: Add closing brace.
 
diff --git a/lib/iswctype.c b/lib/iswctype.c
index 39d4316..75b69f0 100644
--- a/lib/iswctype.c
+++ b/lib/iswctype.c
@@ -20,4 +20,17 @@
 /* Specification.  */
 #include <wctype.h>
 
-#include "iswctype-impl.h"
+#if GNULIB_defined_wint_t
+
+int
+iswctype (wint_t wc, wctype_t desc)
+# undef iswctype
+{
+  return ((wchar_t) wc == wc ? iswctype ((wchar_t) wc, desc) : 0);
+}
+
+#else
+
+# include "iswctype-impl.h"
+
+#endif
diff --git a/lib/wctype.in.h b/lib/wctype.in.h
index 4e57961..b3edb0d 100644
--- a/lib/wctype.in.h
+++ b/lib/wctype.in.h
@@ -589,10 +589,19 @@ _GL_WARN_ON_USE (wctype, "wctype is unportable - "
    The argument WC must be either a wchar_t value or WEOF.
    The argument DESC must have been returned by the wctype() function.  */
 #if @GNULIB_ISWCTYPE@
-# if !@HAVE_WCTYPE_T@
+# if @GNULIB_OVERRIDES_WINT_T@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef iswctype
+#   define iswctype rpl_iswctype
+#  endif
+_GL_FUNCDECL_RPL (iswctype, int, (wint_t wc, wctype_t desc));
+_GL_CXXALIAS_RPL (iswctype, int, (wint_t wc, wctype_t desc));
+# else
+#  if !@HAVE_WCTYPE_T@
 _GL_FUNCDECL_SYS (iswctype, int, (wint_t wc, wctype_t desc));
-# endif
+#  endif
 _GL_CXXALIAS_SYS (iswctype, int, (wint_t wc, wctype_t desc));
+# endif
 _GL_CXXALIASWARN (iswctype);
 #elif defined GNULIB_POSIXCHECK
 # undef iswctype
diff --git a/modules/iswctype b/modules/iswctype
index 2f6c8a0..9fce684 100644
--- a/modules/iswctype
+++ b/modules/iswctype
@@ -17,7 +17,7 @@ wctype-h
 
 configure.ac:
 gl_FUNC_ISWCTYPE
-if test $HAVE_WCTYPE_T = 0; then
+if test $HAVE_WCTYPE_T = 0 || test $GNULIB_OVERRIDES_WINT_T = 1; then
   AC_LIBOBJ([iswctype])
 fi
 gl_WCTYPE_MODULE_INDICATOR([iswctype])
-- 
2.7.4


[-- Attachment #5: 0004-sys_time-Fix-errors-in-C-mode-on-mingw.patch --]
[-- Type: text/x-patch, Size: 2281 bytes --]

From df8452e776ee1e1374c4358d5df4c4f8e8440418 Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Sun, 24 Nov 2019 20:11:28 +0100
Subject: [PATCH 4/5] sys_time: Fix errors in C++ mode on mingw.

* lib/sys_time.in.h (timeval): Restore the redirection
'#define timeval rpl_timeval', for when the symbol timeval is being used
outside the 'gnulib' namespace.
* lib/sys_select.in.h (select): In C++, write 'timeval', not
'struct timeval'.
---
 ChangeLog           | 9 +++++++++
 lib/sys_select.in.h | 2 +-
 lib/sys_time.in.h   | 6 +++++-
 3 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 356edcb..573946e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2019-11-24  Bruno Haible  <bruno@clisp.org>
 
+	sys_time: Fix errors in C++ mode on mingw.
+	* lib/sys_time.in.h (timeval): Restore the redirection
+	'#define timeval rpl_timeval', for when the symbol timeval is being used
+	outside the 'gnulib' namespace.
+	* lib/sys_select.in.h (select): In C++, write 'timeval', not
+	'struct timeval'.
+
+2019-11-24  Bruno Haible  <bruno@clisp.org>
+
 	iswctype: Fix errors in C++ mode on mingw.
 	* lib/wctype.in.h (rpl_iswctype): Override if GNULIB_OVERRIDES_WINT_T
 	is 1.
diff --git a/lib/sys_select.in.h b/lib/sys_select.in.h
index e264257..19205cb 100644
--- a/lib/sys_select.in.h
+++ b/lib/sys_select.in.h
@@ -295,7 +295,7 @@ _GL_FUNCDECL_RPL (select, int,
                    struct timeval *restrict));
 _GL_CXXALIAS_RPL (select, int,
                   (int, fd_set *restrict, fd_set *restrict, fd_set *restrict,
-                   struct timeval *restrict));
+                   timeval *restrict));
 # else
 _GL_CXXALIAS_SYS (select, int,
                   (int, fd_set *restrict, fd_set *restrict, fd_set *restrict,
diff --git a/lib/sys_time.in.h b/lib/sys_time.in.h
index 2bc2bb3..6859af3 100644
--- a/lib/sys_time.in.h
+++ b/lib/sys_time.in.h
@@ -112,8 +112,12 @@ _GL_CXXALIASWARN (gettimeofday);
 # if defined __cplusplus && defined GNULIB_NAMESPACE
 namespace GNULIB_NAMESPACE {
   typedef ::timeval
-#undef timeval
+#  undef timeval
     timeval;
+#  if @REPLACE_STRUCT_TIMEVAL@
+#   define timeval rpl_timeval
+  typedef ::timeval timeval;
+#  endif
 }
 # endif
 #elif defined GNULIB_POSIXCHECK
-- 
2.7.4


[-- Attachment #6: 0005-Fix-errors-in-C-mode-on-mingw.patch --]
[-- Type: text/x-patch, Size: 4620 bytes --]

From ff66f981a9c19ee7644a55faf873f6ba4e89bdc0 Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Sun, 24 Nov 2019 20:12:02 +0100
Subject: [PATCH 5/5] Fix errors in C++ mode on mingw.

* lib/arpa_inet.in.h (inet_ntop, inet_pton): Use _GL_CXXALIAS_SYS_CAST
instead of _GL_CXXALIAS_SYS.
* lib/signal.in.h (pthread_sigmask): Likewise.
* lib/spawn.in.h (posix_spawn_file_actions_addopen,
posix_spawn_file_actions_addclose, posix_spawn_file_actions_adddup2):
Likewise.
* lib/wchar.in.h (btowc): Likewise.
---
 ChangeLog          | 11 +++++++++++
 lib/arpa_inet.in.h |  4 ++++
 lib/signal.in.h    |  2 ++
 lib/spawn.in.h     |  6 ++++++
 lib/wchar.in.h     |  3 ++-
 5 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 573946e..17907bd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 2019-11-24  Bruno Haible  <bruno@clisp.org>
 
+	Fix errors in C++ mode on mingw.
+	* lib/arpa_inet.in.h (inet_ntop, inet_pton): Use _GL_CXXALIAS_SYS_CAST
+	instead of _GL_CXXALIAS_SYS.
+	* lib/signal.in.h (pthread_sigmask): Likewise.
+	* lib/spawn.in.h (posix_spawn_file_actions_addopen,
+	posix_spawn_file_actions_addclose, posix_spawn_file_actions_adddup2):
+	Likewise.
+	* lib/wchar.in.h (btowc): Likewise.
+
+2019-11-24  Bruno Haible  <bruno@clisp.org>
+
 	sys_time: Fix errors in C++ mode on mingw.
 	* lib/sys_time.in.h (timeval): Restore the redirection
 	'#define timeval rpl_timeval', for when the symbol timeval is being used
diff --git a/lib/arpa_inet.in.h b/lib/arpa_inet.in.h
index 7a85eac..6722783 100644
--- a/lib/arpa_inet.in.h
+++ b/lib/arpa_inet.in.h
@@ -103,7 +103,9 @@ _GL_CXXALIAS_SYS_CAST (inet_ntop, const char *,
                        (int af, const void *restrict src,
                         char *restrict dst, socklen_t cnt));
 # endif
+# if __GLIBC__ >= 2
 _GL_CXXALIASWARN (inet_ntop);
+# endif
 #elif defined GNULIB_POSIXCHECK
 # undef inet_ntop
 # if HAVE_RAW_DECL_INET_NTOP
@@ -132,7 +134,9 @@ _GL_FUNCDECL_SYS (inet_pton, int,
 _GL_CXXALIAS_SYS (inet_pton, int,
                   (int af, const char *restrict src, void *restrict dst));
 # endif
+# if __GLIBC__ >= 2
 _GL_CXXALIASWARN (inet_pton);
+# endif
 #elif defined GNULIB_POSIXCHECK
 # undef inet_pton
 # if HAVE_RAW_DECL_INET_PTON
diff --git a/lib/signal.in.h b/lib/signal.in.h
index 0f6486d..b4e432d 100644
--- a/lib/signal.in.h
+++ b/lib/signal.in.h
@@ -144,7 +144,9 @@ _GL_FUNCDECL_SYS (pthread_sigmask, int,
 _GL_CXXALIAS_SYS (pthread_sigmask, int,
                   (int how, const sigset_t *new_mask, sigset_t *old_mask));
 # endif
+# if __GLIBC__ >= 2
 _GL_CXXALIASWARN (pthread_sigmask);
+# endif
 #elif defined GNULIB_POSIXCHECK
 # undef pthread_sigmask
 # if HAVE_RAW_DECL_PTHREAD_SIGMASK
diff --git a/lib/spawn.in.h b/lib/spawn.in.h
index 721d70f..09c66f5 100644
--- a/lib/spawn.in.h
+++ b/lib/spawn.in.h
@@ -802,7 +802,9 @@ _GL_CXXALIAS_SYS (posix_spawn_file_actions_addopen, int,
                    int __fd,
                    const char *_Restrict_ __path, int __oflag, mode_t __mode));
 # endif
+# if __GLIBC__ >= 2
 _GL_CXXALIASWARN (posix_spawn_file_actions_addopen);
+# endif
 #elif defined GNULIB_POSIXCHECK
 # undef posix_spawn_file_actions_addopen
 # if HAVE_RAW_DECL_POSIX_SPAWN_FILE_ACTIONS_ADDOPEN
@@ -833,7 +835,9 @@ _GL_FUNCDECL_SYS (posix_spawn_file_actions_addclose, int,
 _GL_CXXALIAS_SYS (posix_spawn_file_actions_addclose, int,
                   (posix_spawn_file_actions_t *__file_actions, int __fd));
 # endif
+# if __GLIBC__ >= 2
 _GL_CXXALIASWARN (posix_spawn_file_actions_addclose);
+# endif
 #elif defined GNULIB_POSIXCHECK
 # undef posix_spawn_file_actions_addclose
 # if HAVE_RAW_DECL_POSIX_SPAWN_FILE_ACTIONS_ADDCLOSE
@@ -868,7 +872,9 @@ _GL_CXXALIAS_SYS (posix_spawn_file_actions_adddup2, int,
                   (posix_spawn_file_actions_t *__file_actions,
                    int __fd, int __newfd));
 # endif
+# if __GLIBC__ >= 2
 _GL_CXXALIASWARN (posix_spawn_file_actions_adddup2);
+# endif
 #elif defined GNULIB_POSIXCHECK
 # undef posix_spawn_file_actions_adddup2
 # if HAVE_RAW_DECL_POSIX_SPAWN_FILE_ACTIONS_ADDDUP2
diff --git a/lib/wchar.in.h b/lib/wchar.in.h
index 9807f60..043a592 100644
--- a/lib/wchar.in.h
+++ b/lib/wchar.in.h
@@ -161,7 +161,8 @@ _GL_CXXALIAS_RPL (btowc, wint_t, (int c));
 #  if !@HAVE_BTOWC@
 _GL_FUNCDECL_SYS (btowc, wint_t, (int c) _GL_ATTRIBUTE_PURE);
 #  endif
-_GL_CXXALIAS_SYS (btowc, wint_t, (int c));
+/* Need to cast, because on mingw, the return type is 'unsigned short'.  */
+_GL_CXXALIAS_SYS_CAST (btowc, wint_t, (int c));
 # endif
 # if __GLIBC__ >= 2
 _GL_CXXALIASWARN (btowc);
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: wctype.h compile error on mingw with GNULIB_NAMESPACE
  2019-11-24 19:15               ` Bruno Haible
@ 2019-11-25 23:28                 ` Christian Biesinger
  2019-11-25 23:53                   ` Bruno Haible
  0 siblings, 1 reply; 13+ messages in thread
From: Christian Biesinger @ 2019-11-25 23:28 UTC (permalink / raw)
  To: Bruno Haible; +Cc: bug-gnulib

On Sun, Nov 24, 2019 at 1:16 PM Bruno Haible <bruno@clisp.org> wrote:
>
> Christian Biesinger wrote:
> > Thanks for your quick patches! This solves the problem for me.
>
> Thanks for the confirmation. Some other patches are needed for the same
> thing to work on Cygwin and mingw. Will push them once Savannah is back online.

Thanks Bruno -- have these been committed yet? It looks like they probably are?

Christian

> 2019-11-24  Bruno Haible  <bruno@clisp.org>
>
>         Fix errors in C++ mode on Cygwin.
>         * lib/sys_wait.in.h (waitpid): Use _GL_CXXALIAS_SYS_CAST instead of
>         _GL_CXXALIAS_SYS.
>
>         windows-timedmutex: Fix errors in C++ mode on mingw.
>         * lib/windows-timedmutex.h: Add closing brace.
>
>         iswctype: Fix errors in C++ mode on mingw.
>         * lib/wctype.in.h (rpl_iswctype): Override if GNULIB_OVERRIDES_WINT_T
>         is 1.
>         * lib/iswctype.c (iswctype): Add another implementation, for the
>         GNULIB_defined_wint_t case.
>         * modules/iswctype (configure.ac): Compile iswctype.c also if
>         GNULIB_OVERRIDES_WINT_T is 1.
>
>         sys_time: Fix errors in C++ mode on mingw.
>         * lib/sys_time.in.h (timeval): Restore the redirection
>         '#define timeval rpl_timeval', for when the symbol timeval is being used
>         outside the 'gnulib' namespace.
>         * lib/sys_select.in.h (select): In C++, write 'timeval', not
>         'struct timeval'.
>
>         Fix errors in C++ mode on mingw.
>         * lib/arpa_inet.in.h (inet_ntop, inet_pton): Use _GL_CXXALIAS_SYS_CAST
>         instead of _GL_CXXALIAS_SYS.
>         * lib/signal.in.h (pthread_sigmask): Likewise.
>         * lib/spawn.in.h (posix_spawn_file_actions_addopen,
>         posix_spawn_file_actions_addclose, posix_spawn_file_actions_adddup2):
>         Likewise.
>         * lib/wchar.in.h (btowc): Likewise.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: wctype.h compile error on mingw with GNULIB_NAMESPACE
  2019-11-25 23:28                 ` Christian Biesinger
@ 2019-11-25 23:53                   ` Bruno Haible
  0 siblings, 0 replies; 13+ messages in thread
From: Bruno Haible @ 2019-11-25 23:53 UTC (permalink / raw)
  To: Christian Biesinger; +Cc: bug-gnulib

Hi Christian,

> Thanks Bruno -- have these been committed yet? It looks like they probably are?

Yes. This should be obvious when you do a "git pull" or look at
https://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=shortlog

Bruno



^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2019-11-25 23:54 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-11 18:56 time_r module does not work on MingW Christian Biesinger
2019-11-11 19:53 ` Paul Eggert
2019-11-11 19:59 ` Bruno Haible
2019-11-11 20:47   ` Christian Biesinger
2019-11-12  2:28     ` Bruno Haible
2019-11-16 12:15       ` Bruno Haible
2019-11-16 22:41         ` wctype.h compile error on mingw with GNULIB_NAMESPACE Christian Biesinger
2019-11-17  3:05           ` Bruno Haible
2019-11-17  4:40             ` Christian Biesinger
2019-11-24 19:15               ` Bruno Haible
2019-11-25 23:28                 ` Christian Biesinger
2019-11-25 23:53                   ` Bruno Haible
2019-11-24 14:06         ` time_r module does not work on MingW Bruno Haible

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).