On Fri, Jun 3, 2022 at 12:28 AM sisyphus <[email protected]> wrote:

> On Thu, Jun 2, 2022 at 10:47 PM LIU Hao <[email protected]> wrote:
>
>> 在 2022/6/2 20:37, sisyphus 写道:
>> > On Thu, Jun 2, 2022 at 12:28 PM sisyphus <[email protected]> wrote:
>> ....
>
>

> What's the error? Is it caused by re-declaration with a different calling
>> convention i.e.
>> `__stdcall` vs. `__cdecl`?
>>
>> Socket.xs:101:12: error: static declaration of 'inet_pton' follows
> non-static declaration
>  .... <some details specified>
>
> Socket.xs:123:20: error: conflicting types for 'inet_ntop' ... <some
> details specified>
>
>>
>> This issue is not specific to mingw-w64. If MSVC was used to build Perl,
>> there would be the same
>> error, because we do the same.
>>
>>
> Yes - but the Perl source can direct MSVC and mingw-w64 down different
> paths.
> I don't exactly know why my VS 2019 builds don't need the patch .... but I
> ought to work out why :-(
>
>

On further investigation, MSVC and mingw-w64 are *not* taking a different
path through the perl source.
There seems to be a difference in behaviour between mingw-w64 and Visual
Studio 2019.

Here is a C demo.
```
/* try.c */

#include <stdio.h>
#include <ws2tcpip.h>

static int inet_pton(int af, const char *src, void *dst);
static const char *inet_ntop(int af, const void *src, char *dst, socklen_t
size);

int main(void) {
#if defined(__MINGW64_VERSION_MAJOR)
 printf("mingw runtime version: %d\n", __MINGW64_VERSION_MAJOR);
#endif

#if defined(_MSC_VER)
  printf ("MSVC version: %d\n", _MSC_VER);
#endif

#if defined(InetNtopA)
  printf("InetNtopA defined\n");
#endif

  return 0;
}

```
It contains the very same (troublesome) inet_pton and inet_ntop prototypes
contained in cpan/Socket/Socket.xs (in the perl source).
The executable builds fine on my VS2019 compiler. When executed it outputs:

MSVC version: 1924
InetNtopA defined

It does, however, issue a compile-time warning in relation to the second
(inet_ntop) of the two declarations:

try.c(7): warning C4028: formal parameter 4 different from declaration

But, with my mingw-w64 port of gcc-11.3.0, runtime 10, (obtained from
https://winlibs.com) the build blows up in exactly the same way as the Perl
build blows up:

```
C:\_32\C>gcc -o try.exe try.c
try.c:6:12: error: static declaration of 'inet_pton' follows non-static
declaration
    6 | static int inet_pton(int af, const char *src, void *dst);
      |            ^~~~~~~~~
In file included from try.c:4:
c:\_64\winlibs-gcc-1130\mingw64\x86_64-w64-mingw32\include\ws2tcpip.h:408:32:
note: previous declaration of 'inet_pton' with type 'INT(INT,  const CHAR
*, void *)' {aka 'int(int,  const char *, void *)'}
  408 | WINSOCK_API_LINKAGE INT WSAAPI InetPtonA(INT Family, LPCSTR
pStringBuf, PVOID pAddr);
      |                                ^~~~~~~~~
try.c:7:20: error: conflicting types for 'inet_ntop'; have 'const char
*(int,  const void *, char *, socklen_t)' {aka 'const char *(int,  const
void *, char *, int)'}
    7 | static const char *inet_ntop(int af, const void *src, char *dst,
socklen_t size);
      |                    ^~~~~~~~~
In file included from try.c:4:
c:\_64\winlibs-gcc-1130\mingw64\x86_64-w64-mingw32\include\ws2tcpip.h:401:35:
note: previous declaration of 'inet_ntop' with type 'const CHAR *(INT,
 const void
 *, CHAR *, size_t)' {aka 'const char *(int,  const void *, char *, long
long unsigned int)'}
  401 | WINSOCK_API_LINKAGE LPCSTR WSAAPI InetNtopA(INT Family, LPCVOID
pAddr, LPSTR pStringBuf, size_t StringBufSize);
      |                                   ^~~~~~~~~

```
The same problem arises with mingw runtime 9, but earlier runtimes are fine
because InetNtopA does not get defined.
If I comment out the 2 prototypes, then there's (pretty obviously) no issue
with either gcc or msvc.

Is this just a difference in what gcc and MSVC regard as fatal errors ?

AFAICT, this Perl patch I'm trying to get right does not need to be applied
when the compiler is Visual Studio 2019.
However, applying it to Visual Studio 2019 builds doesn't seem to break
anything.

Cheers,
Rob

_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to