bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: C++ aliases in <netdb.h>


From: Bruno Haible
Subject: Re: C++ aliases in <netdb.h>
Date: Sun, 18 Dec 2016 01:51:01 +0100
User-agent: KMail/4.8.5 (Linux/3.8.0-44-generic; KDE/4.8.5; x86_64; ; )

Gisle Vanem wrote:
> > Can't see how that can run fine?  The compiler will set up the call
> > assuming cdecl convention, while the called function has stdcall
> > convention.
> 
> I would expect the 'reinterpret_cast<type>(::getaddrinfo)' to fix that.

But this will cause undefined behaviour. reinterpret_cast is really the most
dangerous cast that exist.

MSVC gives an error from implicit type conversion from __cdecl to __stdcall:

/home/bruno/msvc/compile cl -nologo -DHAVE_CONFIG_H -DEXEEXT=\".exe\" -I. 
-I../../gltests -I..  -DGNULIB_STRICT_CHECKING=1 -DIN_GNULIB_TESTS=1 -I. 
-I../../gltests -I.. -I../../gltests/.. -I../gllib -I../../gltests/../gllib 
-D_WIN32_WINNT=_WIN32_WINNT_WINXP -I/usr/local/msvc32/include  -MD -c -o 
test-getaddrinfo.obj `cygpath -w '../../gltests/test-getaddrinfo.c'`
test-getaddrinfo.c
C:\cygwin64\home\bruno\testdir-posix\gltests\test-getaddrinfo.c(25): error 
C2440: 'initializing': cannot convert from 'void (__stdcall *)(PADDRINFOA)' to 
'void (__cdecl *)(addrinfo *)'
C:\cygwin64\home\bruno\testdir-posix\gltests\test-getaddrinfo.c(27): error 
C2440: 'initializing': cannot convert from 'INT (__stdcall *)(PCSTR,PCSTR,const 
ADDRINFOA *,PADDRINFOA *)' to 'int (__cdecl *)(const char *,const char *,const 
addrinfo *,addrinfo **)'
make[4]: *** [Makefile:8042: test-getaddrinfo.obj] Error 2

Therefore you cannot assume that these can be used interchangeably.
They wouldn't give an error if such a conversion was a harmless no-op.

Meanwhile, I'm fixing this compilation error by disabling the signature check
(like we do for functions that are actually defined as macros, e.g. in
test-strtol.c).


2016-12-17  Bruno Haible  <address@hidden>

        getaddrinfo tests: Avoid compilation error on MSVC.
        * tests/test-getaddrinfo.c: Don't check the prototypes of freeaddrinfo,
        getaddrinfo on native Windows.

diff --git a/tests/test-getaddrinfo.c b/tests/test-getaddrinfo.c
index 0251632..f7d4caa 100644
--- a/tests/test-getaddrinfo.c
+++ b/tests/test-getaddrinfo.c
@@ -22,11 +22,16 @@
 #include <netdb.h>
 
 #include "signature.h"
-SIGNATURE_CHECK (freeaddrinfo, void, (struct addrinfo *));
 SIGNATURE_CHECK (gai_strerror, char const *, (int));
+/* On native Windows, these two functions may have the __stdcall calling
+   convention.  But the SIGNATURE_CHECK works only for functions with __cdecl
+   calling convention.  */
+#if !((defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__)
+SIGNATURE_CHECK (freeaddrinfo, void, (struct addrinfo *));
 SIGNATURE_CHECK (getaddrinfo, int, (char const *, char const *,
                                     struct addrinfo const *,
                                     struct addrinfo **));
+#endif
 
 #include <arpa/inet.h>
 #include <errno.h>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]