bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
* swab wrapper fails mingw.org's MinGW compilation of GDB
@ 2021-03-29  8:23 Eli Zaretskii
  2021-06-20 15:22 ` Bruno Haible
  0 siblings, 1 reply; 2+ messages in thread
From: Eli Zaretskii @ 2021-03-29  8:23 UTC (permalink / raw)
  To: bug-gnulib

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)}

The suggested fix is as follows (__MINGW32_VERSION is defined by
mingw.org's MinGW, but not by MinGW64):

--- unistd.h~	2021-03-29 09:15:08.782625000 +0300
+++ unistd.h	2021-03-29 10:19:46.485750000 +0300
@@ -2540,7 +2540,11 @@ _GL_WARN_ON_USE (sleep, "sleep is unport
 #   undef swab
 #   define swab _swab
 #  endif
+#  if defined __MINGW32_VERSION
+_GL_CXXALIAS_MDA (swab, void, (const char *from, char *to, size_t n));
+#  else
 _GL_CXXALIAS_MDA (swab, void, (char *from, char *to, int n));
+#  endif
 # else
 _GL_CXXALIAS_SYS (swab, void, (const void *from, void *to, ssize_t n));
 # endif


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

end of thread, other threads:[~2021-06-20 15:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-29  8:23 swab wrapper fails mingw.org's MinGW compilation of GDB Eli Zaretskii
2021-06-20 15:22 ` 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).