[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: swab wrapper fails mingw.org's MinGW compilation of GDB
From: |
Bruno Haible |
Subject: |
Re: swab wrapper fails mingw.org's MinGW compilation of GDB |
Date: |
Sun, 20 Jun 2021 17:22:47 +0200 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-210-generic; KDE/5.18.0; x86_64; ; ) |
Eli Zaretskii wrote in
<https://lists.gnu.org/archive/html/bug-gnulib/2021-03/msg00135.html>:
> The following snippet from Gnulib's unistd.h causes a compilation
> error when building the current development version of GDB 11:
>
> #if @GNULIB_MDA_SWAB@
> /* On native Windows, map 'swab' to '_swab', so that -loldnames is not
> required. In C++ with GNULIB_NAMESPACE, avoid differences between
> platforms by defining GNULIB_NAMESPACE::creat always. */
> # if defined _WIN32 && !defined __CYGWIN__
> # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
> # undef swab
> # define swab _swab
> # endif
> _GL_CXXALIAS_MDA (swab, void, (char *from, char *to, int n));
> # else
> _GL_CXXALIAS_SYS (swab, void, (const void *from, void *to, ssize_t n));
> # endif
> _GL_CXXALIASWARN (swab);
> #endif
>
> The problem is that mingw.org's MinGW uses a slightly different
> prototype of _swab:
>
> _CRTIMP __cdecl __MINGW_NOTHROW void _swab (const char *, char *, size_t);
>
> So the difference between the prototypes causes this compilation error
> in C++ programs:
>
> CXX unittests/string_view-selftests.o
> In file included from ./../gdbsupport/common-defs.h:86,
> from ./defs.h:28,
> from unittests/string_view-selftests.c:26:
> ./../gnulib/import/unistd.h: In member function
> 'gnulib::_gl_swab_wrapper::operator gnulib::_gl_swab_wrapper::type() const':
> ./../gnulib/import/unistd.h:2543:1: error: invalid conversion from 'void
> (__attribute__((cdecl)) *)(const char*, char*, size_t)' {aka 'void
> (__attribute__((cdecl)) *)(const char*, char*, unsigned int)'} to
> 'gnulib::_gl_swab_wrapper::type' {aka 'void (*)(char*, char*, int)'}
> [-fpermissive]
> 2543 | _GL_CXXALIAS_MDA (swab, void, (char *from, char *to, int n));
> | ^~~~~~~~~~~~~~~~
> | |
> | void (__attribute__((cdecl)) *)(const char*, char*, size_t) {aka
> void (__attribute__((cdecl)) *)(const char*, char*, unsigned int)}
Thanks for the report. A similar problem also exists on Solaris and HP-UX.
The patch below should fix it. Tested on Solaris with CC and g++.
> The suggested fix is as follows (__MINGW32_VERSION is defined by
> mingw.org's MinGW, but not by MinGW64):
It is good to know how to distinguish older mingw from mingw64; thanks
for this info. But here we don't need to make the distinction, since we
have a _GL_CXXALIAS_MDA_CAST macro for these situations.
2021-06-20 Bruno Haible <bruno@clisp.org>
unistd: Avoid compilation error in C++ mode on Solaris, HP-UX, mingw.
Reported by Eli Zaretskii <eliz@gnu.org> in
<https://lists.gnu.org/archive/html/bug-gnulib/2021-03/msg00135.html>.
* lib/unistd.in.h (swab): Consider different declarations on Solaris,
HP-UX, and old mingw.
diff --git a/lib/unistd.in.h b/lib/unistd.in.h
index d4d4ba7..73c882f 100644
--- a/lib/unistd.in.h
+++ b/lib/unistd.in.h
@@ -2034,9 +2034,17 @@ _GL_WARN_ON_USE (sleep, "sleep is unportable - "
# undef swab
# define swab _swab
# endif
-_GL_CXXALIAS_MDA (swab, void, (char *from, char *to, int n));
-# else
+/* Need to cast, because in old mingw the arguments are
+ (const char *from, char *to, size_t n). */
+_GL_CXXALIAS_MDA_CAST (swab, void, (char *from, char *to, int n));
+# else
+# if defined __hpux /* HP-UX */
+_GL_CXXALIAS_SYS (swab, void, (const char *from, char *to, int n));
+# elif defined __sun && !defined _XPG4 /* Solaris */
+_GL_CXXALIAS_SYS (swab, void, (const char *from, char *to, ssize_t n));
+# else
_GL_CXXALIAS_SYS (swab, void, (const void *from, void *to, ssize_t n));
+# endif
# endif
_GL_CXXALIASWARN (swab);
#endif
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: swab wrapper fails mingw.org's MinGW compilation of GDB,
Bruno Haible <=