Thread: compiler warnings on mingw

compiler warnings on mingw

From
Peter Eisentraut
Date:
I've tried to cross-compile PostgreSQL from Linux to Windows, following
the ideas of Andrew Dunstan [0].  This works quite well.  I see two
compiler warnings altogether, which might be worth getting rid of:

#1

mingwcompat.c:60:1: warning: ‘RegisterWaitForSingleObject’ redeclared without dllimport attribute: previous dllimport
ignored[-Wattributes]
 

This can apparently go away with this:

diff --git a/src/backend/port/win32/mingwcompat.c b/src/backend/port/win32/mingwcompat.c
index 0978e8c..b1a5ca5 100644
--- a/src/backend/port/win32/mingwcompat.c
+++ b/src/backend/port/win32/mingwcompat.c
@@ -56,6 +56,7 @@           (PHANDLE, HANDLE, WAITORTIMERCALLBACK, PVOID, ULONG, ULONG);static
__RegisterWaitForSingleObject_RegisterWaitForSingleObject = NULL;
 
+__attribute__((dllimport))BOOL       WINAPIRegisterWaitForSingleObject(PHANDLE phNewWaitObject,
  HANDLE hObject,
 

Oddly, the mingw buildfarm member[1] complains about

mingwcompat.c:66: warning: no previous prototype for 'RegisterWaitForSingleObject'

instead.  So there might be some divergent header files around.

Anyone know details about this?

#2

pg_stat_statements.c: In function ‘pgss_ProcessUtility’:
pg_stat_statements.c:840:4: warning: unknown conversion type character ‘l’ in format [-Wformat]
pg_stat_statements.c:840:4: warning: too many arguments for format [-Wformat-extra-args]

We use a replacement snprintf and set the int64 format to %lld and %llu
based on that.  But pg_stat_statements.c uses sscanf, for which we have
no replacement.  The configure check comments

# MinGW uses '%I64d', though gcc throws an warning with -Wall,
# while '%lld' doesn't generate a warning, but doesn't work.

So assuming that sscanf in the mingw C library works consistently with
snprintf, that might mean that pg_stat_statements is broken on that
platform.  (The claim that %lld doesn't generate a warning is also
questionable here.)


[0]: http://people.planetpostgresql.org/andrew/index.php?/archives/264-Cross-compiling-PostgreSQL-for-WIndows.html
[1]: http://buildfarm.postgresql.org/cgi-bin/show_stage_log.pl?nm=narwhal&dt=2012-06-22%2004%3A00%3A05&stg=make

PS: Instructions for Debian:

apt-get install gcc-mingw-w64

./configure --build=$(config/config.guess) --host=i686-w64-mingw32 --without-zlib --without-readline ZIC=/usr/sbin/zic
make world




Re: compiler warnings on mingw

From
Magnus Hagander
Date:
On Mon, Jun 25, 2012 at 11:42 AM, Peter Eisentraut <peter_e@gmx.net> wrote:
> I've tried to cross-compile PostgreSQL from Linux to Windows, following
> the ideas of Andrew Dunstan [0].  This works quite well.  I see two
> compiler warnings altogether, which might be worth getting rid of:
>
> #1
>
> mingwcompat.c:60:1: warning: ‘RegisterWaitForSingleObject’ redeclared without dllimport attribute: previous dllimport
ignored[-Wattributes] 
>
> This can apparently go away with this:
>
> diff --git a/src/backend/port/win32/mingwcompat.c b/src/backend/port/win32/mingwcompat.c
> index 0978e8c..b1a5ca5 100644
> --- a/src/backend/port/win32/mingwcompat.c
> +++ b/src/backend/port/win32/mingwcompat.c
> @@ -56,6 +56,7 @@
>            (PHANDLE, HANDLE, WAITORTIMERCALLBACK, PVOID, ULONG, ULONG);
>  static __RegisterWaitForSingleObject _RegisterWaitForSingleObject = NULL;
>
> +__attribute__((dllimport))
>  BOOL       WINAPI
>  RegisterWaitForSingleObject(PHANDLE phNewWaitObject,
>                            HANDLE hObject,

Seems like a proper fix to me - but could be verified by checking what
the actual mingw header looks like. Or maybe that's what you did
already..


> Oddly, the mingw buildfarm member[1] complains about
>
> mingwcompat.c:66: warning: no previous prototype for 'RegisterWaitForSingleObject'

I think that one is just laziness - in the case when we're injecting
that API function into mingw we should declare it in our own headers.
It was likely just left out because the proper API headers already
carry it, it was just missing in mingw.. So it hsould be added to the
port header, under an #ifdef.


> instead.  So there might be some divergent header files around.
>
> Anyone know details about this?

Perhaps mingw has added it to their api *properly* this time, and the
whole function should go away from mingwcompat.c? In that case it'd
obviously require a configure test, since it doesn't exist in previous
releases.


> #2
>
> pg_stat_statements.c: In function ‘pgss_ProcessUtility’:
> pg_stat_statements.c:840:4: warning: unknown conversion type character ‘l’ in format [-Wformat]
> pg_stat_statements.c:840:4: warning: too many arguments for format [-Wformat-extra-args]
>
> We use a replacement snprintf and set the int64 format to %lld and %llu
> based on that.  But pg_stat_statements.c uses sscanf, for which we have
> no replacement.  The configure check comments
>
> # MinGW uses '%I64d', though gcc throws an warning with -Wall,
> # while '%lld' doesn't generate a warning, but doesn't work.
>
> So assuming that sscanf in the mingw C library works consistently with
> snprintf, that might mean that pg_stat_statements is broken on that
> platform.  (The claim that %lld doesn't generate a warning is also
> questionable here.)

can't commend on that part without more investigation.

--
 Magnus Hagander
 Me: http://www.hagander.net/
 Work: http://www.redpill-linpro.com/