The attached patch is intended to clean up a bunch of compiler warnings seen on Windows due to mismatches of signedness or constness, unused variables, redefined macros and a missing prototype.

It doesn't clean up all the warnings by any means, but it fixes quite a few.

One thing I'm a bit confused about is this type of warning:

      src\backend\utils\misc\guc-file.c(977): warning C4003: not enough actual 
parameters for macro 'GUC_yywrap'


If someone can suggest a good fix That would be nice.

cheers

andrew

*** a/src/backend/main/main.c
--- b/src/backend/main/main.c
***************
*** 393,399 **** get_current_username(const char *progname)
  	return strdup(pw->pw_name);
  #else
  	long		namesize = 256 /* UNLEN */ + 1;
! 	char	   *name;
  
  	name = malloc(namesize);
  	if (!GetUserName(name, &namesize))
--- 393,399 ----
  	return strdup(pw->pw_name);
  #else
  	long		namesize = 256 /* UNLEN */ + 1;
! 	unsigned char   *name;
  
  	name = malloc(namesize);
  	if (!GetUserName(name, &namesize))
*** a/src/backend/port/win32/socket.c
--- b/src/backend/port/win32/socket.c
***************
*** 370,376 **** pgwin32_recv(SOCKET s, char *buf, int len, int f)
  }
  
  int
! pgwin32_send(SOCKET s, char *buf, int len, int flags)
  {
  	WSABUF		wbuf;
  	int			r;
--- 370,376 ----
  }
  
  int
! pgwin32_send(SOCKET s, const char *buf, int len, int flags)
  {
  	WSABUF		wbuf;
  	int			r;
***************
*** 380,386 **** pgwin32_send(SOCKET s, char *buf, int len, int flags)
  		return -1;
  
  	wbuf.len = len;
! 	wbuf.buf = buf;
  
  	/*
  	 * Readiness of socket to send data to UDP socket may be not true: socket
--- 380,386 ----
  		return -1;
  
  	wbuf.len = len;
! 	wbuf.buf = (char *) buf;
  
  	/*
  	 * Readiness of socket to send data to UDP socket may be not true: socket
*** a/src/backend/utils/adt/pg_locale.c
--- b/src/backend/utils/adt/pg_locale.c
***************
*** 63,69 ****
--- 63,78 ----
  #include "utils/syscache.h"
  
  #ifdef WIN32
+ /*
+  * This Windows file defines StrNCpy. We don't need it here, so we undefine
+  * it to keep the compiler quiet, and undefine it again after the file is
+  * included, so we don't accidentally use theirs.
+  */
+ #undef StrNCpy
  #include <shlwapi.h>
+ #ifdef StrNCpy
+ #undef STrNCpy
+ #endif
  #endif
  
  #define		MAX_L10N_DATA		80
***************
*** 555,561 **** strftime_win32(char *dst, size_t dstlen, const wchar_t *format, const struct tm
  	dst[len] = '\0';
  	if (encoding != PG_UTF8)
  	{
! 		char	   *convstr = pg_do_encoding_conversion(dst, len, PG_UTF8, encoding);
  
  		if (dst != convstr)
  		{
--- 564,571 ----
  	dst[len] = '\0';
  	if (encoding != PG_UTF8)
  	{
! 		char	   *convstr = pg_do_encoding_conversion((unsigned char *) dst, 
! 														len, PG_UTF8, encoding);
  
  		if (dst != convstr)
  		{
*** a/src/bin/initdb/initdb.c
--- b/src/bin/initdb/initdb.c
***************
*** 1561,1567 **** normalize_locale_name(char *new, const char *old)
  static void
  setup_collation(void)
  {
! #ifdef HAVE_LOCALE_T
  	int			i;
  	FILE	   *locale_a_handle;
  	char		localebuf[NAMEDATALEN];
--- 1561,1567 ----
  static void
  setup_collation(void)
  {
! #if defined(HAVE_LOCALE_T) && !defined(WIN32)
  	int			i;
  	FILE	   *locale_a_handle;
  	char		localebuf[NAMEDATALEN];
***************
*** 1687,1696 **** setup_collation(void)
  		printf(_("No usable system locales were found.\n"));
  		printf(_("Use the option \"--debug\" to see details.\n"));
  	}
! #else							/* not HAVE_LOCALE_T */
  	printf(_("not supported on this platform\n"));
  	fflush(stdout);
! #endif   /* not HAVE_LOCALE_T */
  }
  
  /*
--- 1687,1696 ----
  		printf(_("No usable system locales were found.\n"));
  		printf(_("Use the option \"--debug\" to see details.\n"));
  	}
! #else							/* not HAVE_LOCALE_T && not WIN32 */
  	printf(_("not supported on this platform\n"));
  	fflush(stdout);
! #endif   /* not HAVE_LOCALE_T  && not WIN32*/
  }
  
  /*
***************
*** 2387,2393 **** setlocales(void)
--- 2387,2396 ----
  #ifdef WIN32
  typedef BOOL (WINAPI * __CreateRestrictedToken) (HANDLE, DWORD, DWORD, PSID_AND_ATTRIBUTES, DWORD, PLUID_AND_ATTRIBUTES, DWORD, PSID_AND_ATTRIBUTES, PHANDLE);
  
+ /* Windows API define missing from some versions of MingW headers */
+ #ifndef  DISABLE_MAX_PRIVILEGE
  #define DISABLE_MAX_PRIVILEGE	0x1
+ #endif
  
  /*
   * Create a restricted token and execute the specified process with it.
*** a/src/bin/pg_ctl/pg_ctl.c
--- b/src/bin/pg_ctl/pg_ctl.c
***************
*** 1461,1468 **** typedef BOOL (WINAPI * __SetInformationJobObject) (HANDLE, JOBOBJECTINFOCLASS, L
  typedef BOOL (WINAPI * __AssignProcessToJobObject) (HANDLE, HANDLE);
  typedef BOOL (WINAPI * __QueryInformationJobObject) (HANDLE, JOBOBJECTINFOCLASS, LPVOID, DWORD, LPDWORD);
  
! /* Windows API define missing from MingW headers */
  #define DISABLE_MAX_PRIVILEGE	0x1
  
  /*
   * Create a restricted token, a job object sandbox, and execute the specified
--- 1461,1470 ----
  typedef BOOL (WINAPI * __AssignProcessToJobObject) (HANDLE, HANDLE);
  typedef BOOL (WINAPI * __QueryInformationJobObject) (HANDLE, JOBOBJECTINFOCLASS, LPVOID, DWORD, LPDWORD);
  
! /* Windows API define missing from some versions of MingW headers */
! #ifndef  DISABLE_MAX_PRIVILEGE
  #define DISABLE_MAX_PRIVILEGE	0x1
+ #endif
  
  /*
   * Create a restricted token, a job object sandbox, and execute the specified
*** a/src/include/port/win32.h
--- b/src/include/port/win32.h
***************
*** 336,342 **** SOCKET		pgwin32_accept(SOCKET s, struct sockaddr * addr, int *addrlen);
  int			pgwin32_connect(SOCKET s, const struct sockaddr * name, int namelen);
  int			pgwin32_select(int nfds, fd_set *readfs, fd_set *writefds, fd_set *exceptfds, const struct timeval * timeout);
  int			pgwin32_recv(SOCKET s, char *buf, int len, int flags);
! int			pgwin32_send(SOCKET s, char *buf, int len, int flags);
  
  const char *pgwin32_socket_strerror(int err);
  int			pgwin32_waitforsinglesocket(SOCKET s, int what, int timeout);
--- 336,342 ----
  int			pgwin32_connect(SOCKET s, const struct sockaddr * name, int namelen);
  int			pgwin32_select(int nfds, fd_set *readfs, fd_set *writefds, fd_set *exceptfds, const struct timeval * timeout);
  int			pgwin32_recv(SOCKET s, char *buf, int len, int flags);
! int			pgwin32_send(SOCKET s, const char *buf, int len, int flags);
  
  const char *pgwin32_socket_strerror(int err);
  int			pgwin32_waitforsinglesocket(SOCKET s, int what, int timeout);
*** a/src/pl/plperl/plperl.c
--- b/src/pl/plperl/plperl.c
***************
*** 3551,3557 **** hv_store_string(HV *hv, const char *key, SV *val)
  	 * does not appear that hashes track UTF-8-ness of keys at all in Perl
  	 * 5.6.
  	 */
! 	hlen = -strlen(hkey);
  	ret = hv_store(hv, hkey, hlen, val, 0);
  
  	if (hkey != key)
--- 3551,3557 ----
  	 * does not appear that hashes track UTF-8-ness of keys at all in Perl
  	 * 5.6.
  	 */
! 	hlen = - (int) strlen(hkey);
  	ret = hv_store(hv, hkey, hlen, val, 0);
  
  	if (hkey != key)
***************
*** 3576,3582 **** hv_fetch_string(HV *hv, const char *key)
  								  GetDatabaseEncoding(), PG_UTF8);
  
  	/* See notes in hv_store_string */
! 	hlen = -strlen(hkey);
  	ret = hv_fetch(hv, hkey, hlen, 0);
  
  	if (hkey != key)
--- 3576,3582 ----
  								  GetDatabaseEncoding(), PG_UTF8);
  
  	/* See notes in hv_store_string */
! 	hlen = - (int) strlen(hkey);
  	ret = hv_fetch(hv, hkey, hlen, 0);
  
  	if (hkey != key)
*** a/src/pl/plperl/plperl.h
--- b/src/pl/plperl/plperl.h
***************
*** 26,36 ****
--- 26,72 ----
  #endif
  #endif
  
+ /*
+  * Supply a value of PERL_UNUSED_DECL that will satisfy gcc - the one
+  * perl itself supplies doesn't seem to.
+  */
+ #if defined(__GNUC__)
+ #define PERL_UNUSED_DECL __attribute__ ((unused))
+ #endif
+ 
+ /*
+  * Sometimes perl carefully scribbles on our *printf macros.
+  * So we undefine them ehere and redefine them after it's done its dirty deed.
+  */
+ 
+ #ifdef USE_REPL_SNPRINTF
+ #undef snprintf
+ #undef vsnprintf
+ #endif
+ 
+ 
  /* required for perl API */
  #include "EXTERN.h"
  #include "perl.h"
  #include "XSUB.h"
  
+ /* put back our snprintf and vsnprintf */
+ #ifdef USE_REPL_SNPRINTF
+ #ifdef snprintf
+ #undef snprintf
+ #endif
+ #ifdef vnsprintf
+ #undef vsnprintf
+ #endif
+ #ifdef __GNUC__
+ #define vsnprintf(...)  pg_vsnprintf(__VA_ARGS__)
+ #define snprintf(...)   pg_snprintf(__VA_ARGS__)
+ #else
+ #define vsnprintf       pg_vsnprintf
+ #define snprintf        pg_snprintf
+ #endif /* __GNUC__ */
+ #endif /*  USE_REPL_SNPRINTF */
+ 
  /* perl version and platform portability */
  #define NEED_eval_pv
  #define NEED_newRV_noinc
*** a/src/pl/plpython/plpython.c
--- b/src/pl/plpython/plpython.c
***************
*** 84,89 **** typedef int Py_ssize_t;
--- 84,101 ----
  		PyObject_HEAD_INIT(type) size,
  #endif
  
+ /*
+  * Some Python headers define these two symbols (e.g. on Windows) which is
+  * possibly a bit unfriendly. Use the Postgres definitions (or lack thereof).
+  */ 
+ #ifdef HAVE_STRERROR
+ #undef HAVE_STRERROR
+ #endif
+ 
+ #ifdef HAVE_TZNAME
+ #undef HAVE_TZNAME
+ #endif
+ 
  #include "postgres.h"
  
  /* system stuff */
*** a/src/port/getopt.c
--- b/src/port/getopt.c
***************
*** 61,66 **** extern char *optarg;
--- 61,68 ----
  #define BADARG	(int)':'
  #define EMSG	""
  
+ int getopt(int nargc, char *const * nargv, const char * ostr);
+ 
  /*
   * getopt
   *	Parse argc/argv argument vector.
***************
*** 72,81 **** extern char *optarg;
   * returning -1.)
   */
  int
! getopt(nargc, nargv, ostr)
! int			nargc;
! char	   *const * nargv;
! const char *ostr;
  {
  	static char *place = EMSG;	/* option letter processing */
  	char	   *oli;			/* option letter list index */
--- 74,80 ----
   * returning -1.)
   */
  int
! getopt(int nargc, char *const * nargv, const char * ostr)
  {
  	static char *place = EMSG;	/* option letter processing */
  	char	   *oli;			/* option letter list index */
*** a/src/port/noblock.c
--- b/src/port/noblock.c
***************
*** 23,29 **** pg_set_noblock(pgsocket sock)
  #if !defined(WIN32)
  	return (fcntl(sock, F_SETFL, O_NONBLOCK) != -1);
  #else
! 	long		ioctlsocket_ret = 1;
  
  	/* Returns non-0 on failure, while fcntl() returns -1 on failure */
  	return (ioctlsocket(sock, FIONBIO, &ioctlsocket_ret) == 0);
--- 23,29 ----
  #if !defined(WIN32)
  	return (fcntl(sock, F_SETFL, O_NONBLOCK) != -1);
  #else
! 	unsigned long		ioctlsocket_ret = 1;
  
  	/* Returns non-0 on failure, while fcntl() returns -1 on failure */
  	return (ioctlsocket(sock, FIONBIO, &ioctlsocket_ret) == 0);
***************
*** 42,48 **** pg_set_block(pgsocket sock)
  		return false;
  	return true;
  #else
! 	long		ioctlsocket_ret = 0;
  
  	/* Returns non-0 on failure, while fcntl() returns -1 on failure */
  	return (ioctlsocket(sock, FIONBIO, &ioctlsocket_ret) == 0);
--- 42,48 ----
  		return false;
  	return true;
  #else
! 	unsigned long		ioctlsocket_ret = 0;
  
  	/* Returns non-0 on failure, while fcntl() returns -1 on failure */
  	return (ioctlsocket(sock, FIONBIO, &ioctlsocket_ret) == 0);
*** a/src/test/regress/pg_regress.c
--- b/src/test/regress/pg_regress.c
***************
*** 140,148 **** __attribute__((format(printf, 2, 3)));
  #ifdef WIN32
  typedef BOOL (WINAPI * __CreateRestrictedToken) (HANDLE, DWORD, DWORD, PSID_AND_ATTRIBUTES, DWORD, PLUID_AND_ATTRIBUTES, DWORD, PSID_AND_ATTRIBUTES, PHANDLE);
  
! /* Windows API define missing from MingW headers */
  #define DISABLE_MAX_PRIVILEGE	0x1
  #endif
  
  /*
   * allow core files if possible.
--- 140,150 ----
  #ifdef WIN32
  typedef BOOL (WINAPI * __CreateRestrictedToken) (HANDLE, DWORD, DWORD, PSID_AND_ATTRIBUTES, DWORD, PLUID_AND_ATTRIBUTES, DWORD, PSID_AND_ATTRIBUTES, PHANDLE);
  
! /* Windows API define missing from some versions of MingW headers */
! #ifndef  DISABLE_MAX_PRIVILEGE
  #define DISABLE_MAX_PRIVILEGE	0x1
  #endif
+ #endif
  
  /*
   * allow core files if possible.
*** a/src/timezone/pgtz.c
--- b/src/timezone/pgtz.c
***************
*** 1125,1131 **** identify_system_timezone(void)
  	for (idx = 0;; idx++)
  	{
  		char		keyname[256];
! 		char		zonename[256];
  		DWORD		namesize;
  		FILETIME	lastwrite;
  		HKEY		key;
--- 1125,1131 ----
  	for (idx = 0;; idx++)
  	{
  		char		keyname[256];
! 		unsigned char	zonename[256];
  		DWORD		namesize;
  		FILETIME	lastwrite;
  		HKEY		key;
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to