Thread: MinGW patch

MinGW patch

From
Bruce Momjian
Date:
I have applied the following patch to allow MinGW to again work on CVS.

THe patch makes the following changes:

    o allow configure to see include/port/win32 include files
    o add matching Win32 accept() prototype
    o allow pg_id to compile with native Win32 API
    o fix invalide mbvalidate() function calls (existing bug)
    o allow /scripts to compile with native Win32 API
    o add win32.c to Win32 compiles (already in *.mak files)

Other Win32 compile platforms were going to need some of these fixes
anyway.

These changes allow the first client-level compiles on Win32 using our
existing Makefile system (no *.mak), and not using Cygwin.  All
interfaces and client apps work except for pg_resetxlog (no fsync).

With these patches, psql works using CMD.EXE:

    U:\>psql -h 172.20.0.1 -U postgres test
    Welcome to psql 7.4beta2, the PostgreSQL interactive terminal.

    Type:  \copyright for distribution terms
           \h for help with SQL commands
           \? for help on internal slash commands
           \g or terminate with semicolon to execute query
           \q to quit

    test=# select * from pg_language;
     lanname  | lanispl | lanpltrusted | lanplcallfoid | lanvalidator |    lanacl

    ----------+---------+--------------+---------------+--------------+---------------
     internal | f       | f            |             0 |         2246 |
     c        | f       | f            |             0 |         2247 |
     sql      | f       | t            |             0 |         2248 | {=U/postgres}
    (3 rows)

    test=#

The backend still does not link.

The MinGW command console seems to have some problems with flushing
output to the screen (no prompt, no errors display), but the same binary
runs fine in CMD.EXE.  We can look at that later.

I will update the WIN32 branch to match current CVS so all the Win32
fixes will be in that branch.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
Index: configure
===================================================================
RCS file: /cvsroot/pgsql-server/configure,v
retrieving revision 1.292
diff -c -c -r1.292 configure
*** configure    1 Sep 2003 23:01:49 -0000    1.292
--- configure    7 Sep 2003 01:53:57 -0000
***************
*** 2370,2375 ****
--- 2370,2381 ----
  { echo "$as_me:$LINENO: using CFLAGS=$CFLAGS" >&5
  echo "$as_me: using CFLAGS=$CFLAGS" >&6;}

+ # We already have this in Makefile.win32, but configure needs it too
+ if test "$PORTNAME" = "win32"
+ then
+     CPPFLAGS="$CPPFLAGS -Isrc/include/port/win32"
+ fi
+
  # Check if the compiler still works with the template settings
  echo "$as_me:$LINENO: checking whether the C compiler still works" >&5
  echo $ECHO_N "checking whether the C compiler still works... $ECHO_C" >&6
***************
*** 10810,10828 ****
  fi
  echo "$as_me:$LINENO: checking types of arguments for accept()" >&5
  echo $ECHO_N "checking types of arguments for accept()... $ECHO_C" >&6
!  if test "${ac_cv_func_accept_arg1+set}" = set; then
    echo $ECHO_N "(cached) $ECHO_C" >&6
  else
!    if test "${ac_cv_func_accept_arg2+set}" = set; then
    echo $ECHO_N "(cached) $ECHO_C" >&6
  else
!     if test "${ac_cv_func_accept_arg3+set}" = set; then
    echo $ECHO_N "(cached) $ECHO_C" >&6
  else
!      for ac_cv_func_accept_arg1 in 'int' 'unsigned int'; do
!      for ac_cv_func_accept_arg2 in 'struct sockaddr *' 'const struct sockaddr *' 'void *'; do
!       for ac_cv_func_accept_arg3 in 'int' 'size_t' 'socklen_t' 'unsigned int' 'void'; do
!        cat >conftest.$ac_ext <<_ACEOF
  #line $LINENO "configure"
  #include "confdefs.h"
  #ifdef HAVE_SYS_TYPES_H
--- 10816,10838 ----
  fi
  echo "$as_me:$LINENO: checking types of arguments for accept()" >&5
  echo $ECHO_N "checking types of arguments for accept()... $ECHO_C" >&6
!  if test "${ac_cv_func_accept_return+set}" = set; then
!   echo $ECHO_N "(cached) $ECHO_C" >&6
! else
!    if test "${ac_cv_func_accept_arg1+set}" = set; then
    echo $ECHO_N "(cached) $ECHO_C" >&6
  else
!     if test "${ac_cv_func_accept_arg2+set}" = set; then
    echo $ECHO_N "(cached) $ECHO_C" >&6
  else
!      if test "${ac_cv_func_accept_arg3+set}" = set; then
    echo $ECHO_N "(cached) $ECHO_C" >&6
  else
!       for ac_cv_func_accept_return in 'int' 'unsigned int PASCAL'; do
!       for ac_cv_func_accept_arg1 in 'int' 'unsigned int'; do
!        for ac_cv_func_accept_arg2 in 'struct sockaddr *' 'const struct sockaddr *' 'void *'; do
!         for ac_cv_func_accept_arg3 in 'int' 'size_t' 'socklen_t' 'unsigned int' 'void'; do
!          cat >conftest.$ac_ext <<_ACEOF
  #line $LINENO "configure"
  #include "confdefs.h"
  #ifdef HAVE_SYS_TYPES_H
***************
*** 10831,10837 ****
  #ifdef HAVE_SYS_SOCKET_H
  #include <sys/socket.h>
  #endif
! extern int accept ($ac_cv_func_accept_arg1, $ac_cv_func_accept_arg2, $ac_cv_func_accept_arg3 *);
  #ifdef F77_DUMMY_MAIN
  #  ifdef __cplusplus
       extern "C"
--- 10841,10847 ----
  #ifdef HAVE_SYS_SOCKET_H
  #include <sys/socket.h>
  #endif
! extern $ac_cv_func_accept_return accept ($ac_cv_func_accept_arg1, $ac_cv_func_accept_arg2, $ac_cv_func_accept_arg3
*);
  #ifdef F77_DUMMY_MAIN
  #  ifdef __cplusplus
       extern "C"
***************
*** 10858,10870 ****
    ac_status=$?
    echo "$as_me:$LINENO: \$? = $ac_status" >&5
    (exit $ac_status); }; }; then
!   ac_not_found=no; break 3
  else
    echo "$as_me: failed program was:" >&5
  cat conftest.$ac_ext >&5
  ac_not_found=yes
  fi
  rm -f conftest.$ac_objext conftest.$ac_ext
        done
       done
      done
--- 10868,10881 ----
    ac_status=$?
    echo "$as_me:$LINENO: \$? = $ac_status" >&5
    (exit $ac_status); }; }; then
!   ac_not_found=no; break 4
  else
    echo "$as_me: failed program was:" >&5
  cat conftest.$ac_ext >&5
  ac_not_found=yes
  fi
  rm -f conftest.$ac_objext conftest.$ac_ext
+        done
        done
       done
      done
***************
*** 10882,10889 ****
  fi

  fi
!  echo "$as_me:$LINENO: result: $ac_cv_func_accept_arg1, $ac_cv_func_accept_arg2, $ac_cv_func_accept_arg3 *" >&5
! echo "${ECHO_T}$ac_cv_func_accept_arg1, $ac_cv_func_accept_arg2, $ac_cv_func_accept_arg3 *" >&6

  cat >>confdefs.h <<_ACEOF
  #define ACCEPT_TYPE_ARG1 $ac_cv_func_accept_arg1
--- 10893,10907 ----
  fi

  fi
!
! fi
!  echo "$as_me:$LINENO: result: $ac_cv_func_accept_return, $ac_cv_func_accept_arg1, $ac_cv_func_accept_arg2,
$ac_cv_func_accept_arg3*" >&5 
! echo "${ECHO_T}$ac_cv_func_accept_return, $ac_cv_func_accept_arg1, $ac_cv_func_accept_arg2, $ac_cv_func_accept_arg3
*">&6 
!
! cat >>confdefs.h <<_ACEOF
! #define ACCEPT_TYPE_RETURN $ac_cv_func_accept_return
! _ACEOF
!

  cat >>confdefs.h <<_ACEOF
  #define ACCEPT_TYPE_ARG1 $ac_cv_func_accept_arg1
Index: configure.in
===================================================================
RCS file: /cvsroot/pgsql-server/configure.in,v
retrieving revision 1.283
diff -c -c -r1.283 configure.in
*** configure.in    1 Sep 2003 23:01:49 -0000    1.283
--- configure.in    7 Sep 2003 01:53:58 -0000
***************
*** 238,243 ****
--- 238,249 ----
  fi
  AC_MSG_NOTICE([using CFLAGS=$CFLAGS])

+ # We already have this in Makefile.win32, but configure needs it too
+ if test "$PORTNAME" = "win32"
+ then
+     CPPFLAGS="$CPPFLAGS -Isrc/include/port/win32"
+ fi
+
  # Check if the compiler still works with the template settings
  AC_MSG_CHECKING([whether the C compiler still works])
  AC_TRY_LINK([], [return 0;],
Index: config/ac_func_accept_argtypes.m4
===================================================================
RCS file: /cvsroot/pgsql-server/config/ac_func_accept_argtypes.m4,v
retrieving revision 1.4
diff -c -c -r1.4 ac_func_accept_argtypes.m4
*** config/ac_func_accept_argtypes.m4    29 Mar 2002 17:32:53 -0000    1.4
--- config/ac_func_accept_argtypes.m4    7 Sep 2003 01:53:58 -0000
***************
*** 7,15 ****
  dnl @synopsis AC_FUNC_ACCEPT_ARGTYPES
  dnl
  dnl Checks the data types of the three arguments to accept(). Results are
! dnl placed into the symbols ACCEPT_TYPE_ARG[123], consistent with the
! dnl following example:
  dnl
  dnl       #define ACCEPT_TYPE_ARG1 int
  dnl       #define ACCEPT_TYPE_ARG2 struct sockaddr *
  dnl       #define ACCEPT_TYPE_ARG3 socklen_t
--- 7,16 ----
  dnl @synopsis AC_FUNC_ACCEPT_ARGTYPES
  dnl
  dnl Checks the data types of the three arguments to accept(). Results are
! dnl placed into the symbols ACCEPT_TYPE_RETURN and ACCEPT_TYPE_ARG[123],
! dnl consistent with the following example:
  dnl
+ dnl       #define ACCEPT_TYPE_RETURN int
  dnl       #define ACCEPT_TYPE_ARG1 int
  dnl       #define ACCEPT_TYPE_ARG2 struct sockaddr *
  dnl       #define ACCEPT_TYPE_ARG3 socklen_t
***************
*** 36,59 ****
  # Solaris 7 and 8 have arg3 as 'void *' (disguised as 'Psocklen_t'
  # which is *not* 'socklen_t *').  If we detect that, then we assume
  # 'int' as the result, because that ought to work best.

  AC_DEFUN([AC_FUNC_ACCEPT_ARGTYPES],
  [AC_MSG_CHECKING([types of arguments for accept()])
!  AC_CACHE_VAL(ac_cv_func_accept_arg1,dnl
!  [AC_CACHE_VAL(ac_cv_func_accept_arg2,dnl
!   [AC_CACHE_VAL(ac_cv_func_accept_arg3,dnl
!    [for ac_cv_func_accept_arg1 in 'int' 'unsigned int'; do
!      for ac_cv_func_accept_arg2 in 'struct sockaddr *' 'const struct sockaddr *' 'void *'; do
!       for ac_cv_func_accept_arg3 in 'int' 'size_t' 'socklen_t' 'unsigned int' 'void'; do
!        AC_TRY_COMPILE(
  [#ifdef HAVE_SYS_TYPES_H
  #include <sys/types.h>
  #endif
  #ifdef HAVE_SYS_SOCKET_H
  #include <sys/socket.h>
  #endif
! extern int accept ($ac_cv_func_accept_arg1, $ac_cv_func_accept_arg2, $ac_cv_func_accept_arg3 *);],
!         [], [ac_not_found=no; break 3], [ac_not_found=yes])
        done
       done
      done
--- 37,65 ----
  # Solaris 7 and 8 have arg3 as 'void *' (disguised as 'Psocklen_t'
  # which is *not* 'socklen_t *').  If we detect that, then we assume
  # 'int' as the result, because that ought to work best.
+ #
+ # On Win32, accept() returns 'unsigned int PASCAL'

  AC_DEFUN([AC_FUNC_ACCEPT_ARGTYPES],
  [AC_MSG_CHECKING([types of arguments for accept()])
!  AC_CACHE_VAL(ac_cv_func_accept_return,dnl
!  [AC_CACHE_VAL(ac_cv_func_accept_arg1,dnl
!   [AC_CACHE_VAL(ac_cv_func_accept_arg2,dnl
!    [AC_CACHE_VAL(ac_cv_func_accept_arg3,dnl
!     [for ac_cv_func_accept_return in 'int' 'unsigned int PASCAL'; do
!       for ac_cv_func_accept_arg1 in 'int' 'unsigned int'; do
!        for ac_cv_func_accept_arg2 in 'struct sockaddr *' 'const struct sockaddr *' 'void *'; do
!         for ac_cv_func_accept_arg3 in 'int' 'size_t' 'socklen_t' 'unsigned int' 'void'; do
!          AC_TRY_COMPILE(
  [#ifdef HAVE_SYS_TYPES_H
  #include <sys/types.h>
  #endif
  #ifdef HAVE_SYS_SOCKET_H
  #include <sys/socket.h>
  #endif
! extern $ac_cv_func_accept_return accept ($ac_cv_func_accept_arg1, $ac_cv_func_accept_arg2, $ac_cv_func_accept_arg3
*);],
!          [], [ac_not_found=no; break 4], [ac_not_found=yes])
!        done
        done
       done
      done
***************
*** 63,72 ****
      if test "$ac_cv_func_accept_arg3" = "void"; then
        ac_cv_func_accept_arg3=int
      fi
     ])dnl AC_CACHE_VAL
    ])dnl AC_CACHE_VAL
   ])dnl AC_CACHE_VAL
!  AC_MSG_RESULT([$ac_cv_func_accept_arg1, $ac_cv_func_accept_arg2, $ac_cv_func_accept_arg3 *])
   AC_DEFINE_UNQUOTED(ACCEPT_TYPE_ARG1, $ac_cv_func_accept_arg1,
                      [Define to the type of arg 1 of 'accept'])
   AC_DEFINE_UNQUOTED(ACCEPT_TYPE_ARG2, $ac_cv_func_accept_arg2,
--- 69,81 ----
      if test "$ac_cv_func_accept_arg3" = "void"; then
        ac_cv_func_accept_arg3=int
      fi
+     ])dnl AC_CACHE_VAL
     ])dnl AC_CACHE_VAL
    ])dnl AC_CACHE_VAL
   ])dnl AC_CACHE_VAL
!  AC_MSG_RESULT([$ac_cv_func_accept_return, $ac_cv_func_accept_arg1, $ac_cv_func_accept_arg2, $ac_cv_func_accept_arg3
*])
!  AC_DEFINE_UNQUOTED(ACCEPT_TYPE_RETURN, $ac_cv_func_accept_return,
!                     [Define to the return type of 'accept'])
   AC_DEFINE_UNQUOTED(ACCEPT_TYPE_ARG1, $ac_cv_func_accept_arg1,
                      [Define to the type of arg 1 of 'accept'])
   AC_DEFINE_UNQUOTED(ACCEPT_TYPE_ARG2, $ac_cv_func_accept_arg2,
Index: src/bin/pg_id/pg_id.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/bin/pg_id/pg_id.c,v
retrieving revision 1.23
diff -c -c -r1.23 pg_id.c
*** src/bin/pg_id/pg_id.c    6 Sep 2003 01:41:56 -0000    1.23
--- src/bin/pg_id/pg_id.c    7 Sep 2003 01:54:04 -0000
***************
*** 28,37 ****
                  use_real_uid_flag = 0,
                  limit_user_info = 0;
      const char *username = NULL;
!
      struct passwd *pw;

!     extern int    optind;

      while ((c = getopt(argc, argv, "nru")) != -1)
      {
--- 28,46 ----
                  use_real_uid_flag = 0,
                  limit_user_info = 0;
      const char *username = NULL;
!     extern int    optind;
! #ifndef WIN32
      struct passwd *pw;
+ #else
+     struct passwd_win32
+     {
+         int pw_uid;
+         char pw_name[128];
+     } pass_win32;
+     struct passwd_win32 *pw = &pass_win32;

!     pw->pw_uid = 1;
! #endif

      while ((c = getopt(argc, argv, "nru")) != -1)
      {
***************
*** 47,59 ****
--- 56,79 ----
                  limit_user_info = 1;
                  break;
              default:
+ #ifndef WIN32
                  fprintf(stderr, "Usage: %s [-n] [-r] [-u] [username]\n", argv[0]);
+ #else
+                 fprintf(stderr, "Usage: %s [-n] [-r] [-u]\n", argv[0]);
+ #endif
                  exit(1);
          }
      }

      if (argc - optind >= 1)
+ #ifndef WIN32
          username = argv[optind];
+ #else
+     {
+         fprintf(stderr, "%s: specifying a username is not supported on this platform\n", argv[0]);
+         exit(1);
+     }
+ #endif

      if (name_only_flag && !limit_user_info)
      {
***************
*** 66,72 ****
          exit(1);
      }

!
      if (username)
      {
          pw = getpwnam(username);
--- 86,92 ----
          exit(1);
      }

! #ifndef WIN32
      if (username)
      {
          pw = getpwnam(username);
***************
*** 86,91 ****
--- 106,120 ----
          perror(argv[0]);
          exit(1);
      }
+ #else
+     if (!use_real_uid_flag)
+     {
+         fprintf(stderr, "%s: -r must be used on this platform\n", argv[0]);
+         exit(1);
+     }
+
+     GetUserName(pw->pw_name, sizeof(pw->pw_name)-1);
+ #endif

      if (!limit_user_info)
          printf("uid=%d(%s)\n", (int) pw->pw_uid, pw->pw_name);
Index: src/bin/pg_resetxlog/pg_resetxlog.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/bin/pg_resetxlog/pg_resetxlog.c,v
retrieving revision 1.12
diff -c -c -r1.12 pg_resetxlog.c
*** src/bin/pg_resetxlog/pg_resetxlog.c    4 Aug 2003 02:40:09 -0000    1.12
--- src/bin/pg_resetxlog/pg_resetxlog.c    7 Sep 2003 01:54:04 -0000
***************
*** 41,47 ****
  #include "catalog/catversion.h"
  #include "catalog/pg_control.h"

-
  /******************** stuff copied from xlog.c ********************/

  /* Increment an xlogid/segment pair */
--- 41,46 ----
***************
*** 80,85 ****
--- 79,86 ----
  static void KillExistingXLOG(void);
  static void WriteEmptyXLOG(void);
  static void usage(void);
+
+ extern char *optarg;



Index: src/bin/psql/describe.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/bin/psql/describe.c,v
retrieving revision 1.84
diff -c -c -r1.84 describe.c
*** src/bin/psql/describe.c    9 Aug 2003 01:21:54 -0000    1.84
--- src/bin/psql/describe.c    7 Sep 2003 01:54:05 -0000
***************
*** 765,771 ****
      {
          /* Name */
  #ifdef WIN32
!         cells[i * cols + 0] = mbvalidate(PQgetvalue(res, i, 0));
  #else
          cells[i * cols + 0] = PQgetvalue(res, i, 0);    /* don't free this
                                                           * afterwards */
--- 765,771 ----
      {
          /* Name */
  #ifdef WIN32
!         cells[i * cols + 0] = mbvalidate(PQgetvalue(res, i, 0), myopt.encoding);
  #else
          cells[i * cols + 0] = PQgetvalue(res, i, 0);    /* don't free this
                                                           * afterwards */
***************
*** 773,779 ****

          /* Type */
  #ifdef WIN32
!         cells[i * cols + 1] = mbvalidate(PQgetvalue(res, i, 1));
  #else
          cells[i * cols + 1] = PQgetvalue(res, i, 1);    /* don't free this
                                                           * either */
--- 773,779 ----

          /* Type */
  #ifdef WIN32
!         cells[i * cols + 1] = mbvalidate(PQgetvalue(res, i, 1), myopt.encoding);
  #else
          cells[i * cols + 1] = PQgetvalue(res, i, 1);    /* don't free this
                                                           * either */
***************
*** 797,803 ****
              }

  #ifdef WIN32
!             cells[i * cols + 2] = xstrdup(mbvalidate(tmpbuf.data));
  #else
              cells[i * cols + 2] = xstrdup(tmpbuf.data);
  #endif
--- 797,803 ----
              }

  #ifdef WIN32
!             cells[i * cols + 2] = xstrdup(mbvalidate(tmpbuf.data, myopt.encoding));
  #else
              cells[i * cols + 2] = xstrdup(tmpbuf.data);
  #endif
***************
*** 806,812 ****
          /* Description */
          if (verbose)
  #ifdef WIN32
!             cells[i * cols + cols - 1] = mbvalidate(PQgetvalue(res, i, 5));
  #else
              cells[i * cols + cols - 1] = PQgetvalue(res, i, 5);
  #endif
--- 806,812 ----
          /* Description */
          if (verbose)
  #ifdef WIN32
!             cells[i * cols + cols - 1] = mbvalidate(PQgetvalue(res, i, 5), myopt.encoding);
  #else
              cells[i * cols + cols - 1] = PQgetvalue(res, i, 5);
  #endif
Index: src/bin/psql/mbprint.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/bin/psql/mbprint.c,v
retrieving revision 1.10
diff -c -c -r1.10 mbprint.c
*** src/bin/psql/mbprint.c    5 Sep 2003 02:31:10 -0000    1.10
--- src/bin/psql/mbprint.c    7 Sep 2003 01:54:07 -0000
***************
*** 7,12 ****
--- 7,15 ----
   */

  #include "postgres_fe.h"
+ #ifndef PGSCRIPTS
+ #include "settings.h"
+ #endif
  #include "mbprint.h"

  #include "mb/pg_wchar.h"
***************
*** 334,340 ****
          return mb_utf_validate(pwcs);
      else
      {
! #ifdef WIN32
          /*
           * translate characters to DOS console encoding, e.g. needed for
           * German umlauts
--- 337,343 ----
          return mb_utf_validate(pwcs);
      else
      {
! #if defined(WIN32) && !defined(PGSCRIPTS)
          /*
           * translate characters to DOS console encoding, e.g. needed for
           * German umlauts
Index: src/bin/scripts/Makefile
===================================================================
RCS file: /cvsroot/pgsql-server/src/bin/scripts/Makefile,v
retrieving revision 1.22
diff -c -c -r1.22 Makefile
*** src/bin/scripts/Makefile    8 Aug 2003 04:52:21 -0000    1.22
--- src/bin/scripts/Makefile    7 Sep 2003 01:54:08 -0000
***************
*** 15,21 ****

  PROGRAMS = createdb createlang createuser dropdb droplang dropuser clusterdb vacuumdb

! override CPPFLAGS := -I$(top_srcdir)/src/bin/pg_dump -I$(top_srcdir)/src/bin/psql -I$(libpq_srcdir) $(CPPFLAGS)

  all: submake-libpq submake-backend $(PROGRAMS)

--- 15,21 ----

  PROGRAMS = createdb createlang createuser dropdb droplang dropuser clusterdb vacuumdb

! override CPPFLAGS := -DPGSCRIPTS -I$(top_srcdir)/src/bin/pg_dump -I$(top_srcdir)/src/bin/psql -I$(libpq_srcdir)
$(CPPFLAGS)

  all: submake-libpq submake-backend $(PROGRAMS)

Index: src/bin/scripts/common.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/bin/scripts/common.c,v
retrieving revision 1.4
diff -c -c -r1.4 common.c
*** src/bin/scripts/common.c    4 Aug 2003 00:43:29 -0000    1.4
--- src/bin/scripts/common.c    7 Sep 2003 01:54:08 -0000
***************
*** 23,28 ****
--- 23,29 ----
  const char *
  get_user_name(const char *progname)
  {
+ #ifndef WIN32
      struct passwd *pw;

      pw = getpwuid(getuid());
***************
*** 32,37 ****
--- 33,44 ----
          exit(1);
      }
      return pw->pw_name;
+ #else
+     static char username[128];    /* remains after function exit */
+
+     GetUserName(username, sizeof(username)-1);
+     return username;
+ #endif
  }


Index: src/include/pg_config.h.in
===================================================================
RCS file: /cvsroot/pgsql-server/src/include/pg_config.h.in,v
retrieving revision 1.61
diff -c -c -r1.61 pg_config.h.in
*** src/include/pg_config.h.in    16 Aug 2003 15:35:51 -0000    1.61
--- src/include/pg_config.h.in    7 Sep 2003 01:54:08 -0000
***************
*** 9,14 ****
--- 9,17 ----
  /* Define to the type of arg 3 of 'accept' */
  #undef ACCEPT_TYPE_ARG3

+ /* Define to the return type of 'accept' */
+ #undef ACCEPT_TYPE_RETURN
+
  /* The alignment requirement of a `double'. */
  #undef ALIGNOF_DOUBLE

Index: src/interfaces/libpq/Makefile
===================================================================
RCS file: /cvsroot/pgsql-server/src/interfaces/libpq/Makefile,v
retrieving revision 1.92
diff -c -c -r1.92 Makefile
*** src/interfaces/libpq/Makefile    23 Aug 2003 04:21:59 -0000    1.92
--- src/interfaces/libpq/Makefile    7 Sep 2003 01:54:09 -0000
***************
*** 24,29 ****
--- 24,32 ----
        fe-protocol2.o fe-protocol3.o pqexpbuffer.o pqsignal.o fe-secure.o \
        dllist.o md5.o ip.o wchar.o encnames.o \
        $(filter crypt.o getaddrinfo.o inet_aton.o snprintf.o strerror.o path.o thread.o, $(LIBOBJS))
+ ifeq ($(PORTNAME), win32)
+ OBJS+=win32.o
+ endif


  # Add libraries that libpq depends (or might depend) on into the

Re: MinGW patch

From
Tom Lane
Date:
Bruce Momjian <pgman@candle.pha.pa.us> writes:

> + # We already have this in Makefile.win32, but configure needs it too
> + if test "$PORTNAME" = "win32"
> + then
> +     CPPFLAGS="$CPPFLAGS -Isrc/include/port/win32"
> + fi

This seems unlikely to work when building outside the source tree.

            regards, tom lane

Re: MinGW patch

From
Bruce Momjian
Date:
Tom Lane wrote:
> Bruce Momjian <pgman@candle.pha.pa.us> writes:
>
> > + # We already have this in Makefile.win32, but configure needs it too
> > + if test "$PORTNAME" = "win32"
> > + then
> > +     CPPFLAGS="$CPPFLAGS -Isrc/include/port/win32"
> > + fi
>
> This seems unlikely to work when building outside the source tree.

Oh.  Any ideas on how to handle that?  The other reference uses:

    override CPPFLAGS+="-I$(top_srcdir)/src/include/port/win32"

but top_srcdir isn't defined at this point.  This is there only so
'configure' sees those include files.  Does that relate to building
outside the tree?

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

Re: MinGW patch

From
Tom Lane
Date:
Bruce Momjian <pgman@candle.pha.pa.us> writes:
> but top_srcdir isn't defined at this point.

Perhaps $srcdir?  Peter would probably know what to use.

            regards, tom lane

Re: MinGW patch

From
Peter Eisentraut
Date:
Bruce Momjian writes:

> Oh.  Any ideas on how to handle that?  The other reference uses:
>
>     override CPPFLAGS+="-I$(top_srcdir)/src/include/port/win32"
>
> but top_srcdir isn't defined at this point.

If you put this in the port makefile, then it should work.

> This is there only so 'configure' sees those include files.  Does that
> relate to building outside the tree?

Why does configure need to see those files?  Surely you don't need
configure to test the capabilities of our own source tree?

--
Peter Eisentraut   peter_e@gmx.net


Re: MinGW patch

From
Peter Eisentraut
Date:
Bruce Momjian writes:

In mbprint.c:

+ #ifndef PGSCRIPTS
+ #include "settings.h"
+ #endif

Why is this needed, considering that the rest of the code was not changed
to make use of any setting?  The print modules in psql should not make use
of psql-specific settings.  That's why there are extensive separate
structures to pass this information.

Also, I'm beginning to feel that there are too many places where the lack
of getpwuid() is being worked around.  That needs to be centralized.

Lastly, since there is not going to be a Windows port in 7.4, why was this
committed to the head branch?

--
Peter Eisentraut   peter_e@gmx.net


Re: MinGW patch

From
Tom Lane
Date:
Peter Eisentraut <peter_e@gmx.net> writes:
> Why does configure need to see those files?  Surely you don't need
> configure to test the capabilities of our own source tree?

Looking at the contents of src/include/port/win32, I would imagine the
problem is configure will decide we don't HAVE_SYS_SOCKET_H, etc.

            regards, tom lane

Re: MinGW patch

From
Bruce Momjian
Date:
Peter Eisentraut wrote:
> Bruce Momjian writes:
>
> > Oh.  Any ideas on how to handle that?  The other reference uses:
> >
> >     override CPPFLAGS+="-I$(top_srcdir)/src/include/port/win32"
> >
> > but top_srcdir isn't defined at this point.
>
> If you put this in the port makefile, then it should work.

The problem is that the 'configure' doesn't find the include files
during its tests.

> > This is there only so 'configure' sees those include files.  Does that
> > relate to building outside the tree?
>
> Why does configure need to see those files?  Surely you don't need
> configure to test the capabilities of our own source tree?

As Tom mentioned, it doesn't find things like sys/socket.h, which we
have added to src/include/port/win32/.  This was done to elimintate
#ifdef of the include files that are Win32-specific.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

Re: MinGW patch

From
Bruce Momjian
Date:
Peter Eisentraut wrote:
> Bruce Momjian writes:
>
> In mbprint.c:
>
> + #ifndef PGSCRIPTS
> + #include "settings.h"
> + #endif
>
> Why is this needed, considering that the rest of the code was not changed
> to make use of any setting?  The print modules in psql should not make use
> of psql-specific settings.  That's why there are extensive separate
> structures to pass this information.

The problem is that mbvalidate() has this code:

        if (GetVariableBool(pset.vars, "WIN32_CONSOLE"))
            CharToOem(pwcs, pwcs);

That's why I needed the #ifdef so it only tests from psql.  This code
was just broken without that test, and because no one else has done
Win32 compiles since it was added, no one saw it.

> Also, I'm beginning to feel that there are too many places where the lack
> of getpwuid() is being worked around.  That needs to be centralized.

Yep.  Let me add that to my list for 7.5.

> Lastly, since there is not going to be a Windows port in 7.4, why was this
> committed to the head branch?

Yes, I knew someone would ask, and debated it myself.  Having these
patches in 7.4 allows us to have full-functional interfaces and client
binaries for MinGW.  This allows us to show progress on the Win32 port,
and for folks to start using MinGW in client applications.  Also, many
of these fixes will be needed for Cygwin and other Win32 platforms, so
it seemed best to fix them in head and just patch them back to the WIN32
branch.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

Re: MinGW patch

From
Bruce Momjian
Date:
Tom Lane wrote:
> Peter Eisentraut <peter_e@gmx.net> writes:
> > Why does configure need to see those files?  Surely you don't need
> > configure to test the capabilities of our own source tree?
>
> Looking at the contents of src/include/port/win32, I would imagine the
> problem is configure will decide we don't HAVE_SYS_SOCKET_H, etc.

Yep.  Can anyone suggest a better solution?

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

Re: MinGW patch

From
Peter Eisentraut
Date:
Bruce Momjian writes:

> The problem is that mbvalidate() has this code:
>
>         if (GetVariableBool(pset.vars, "WIN32_CONSOLE"))
>             CharToOem(pwcs, pwcs);
>
> That's why I needed the #ifdef so it only tests from psql.  This code
> was just broken without that test, and because no one else has done
> Win32 compiles since it was added, no one saw it.

Interesting, considering that WIN32_CONSOLE isn't being set anywhere.

Anyway, that code needs to be removed/fixed, for the mentioned reasons.

--
Peter Eisentraut   peter_e@gmx.net


WIN32_CONSOLE usage

From
Bruce Momjian
Date:
Peter Eisentraut wrote:
> Bruce Momjian writes:
>
> > The problem is that mbvalidate() has this code:
> >
> >         if (GetVariableBool(pset.vars, "WIN32_CONSOLE"))
> >             CharToOem(pwcs, pwcs);
> >
> > That's why I needed the #ifdef so it only tests from psql.  This code
> > was just broken without that test, and because no one else has done
> > Win32 compiles since it was added, no one saw it.
>
> Interesting, considering that WIN32_CONSOLE isn't being set anywhere.
>
> Anyway, that code needs to be removed/fixed, for the mentioned reasons.

Yikes, I see no doc mention of it.

Here is the submission email:

>   c) Problem:  8bit characters were displayed/interpreted wrong in psql
>                This is due to the fact that the Win32 "console" uses a
>                different encoding than the rest of the Windows system
>      Solution: Introduced a new psql variable WIN32_CONSOLE
>                When set with "\set WIN32_console", the function OemToChar()

I have CC'ed the author.

Is this a valid feature?  Should I document it?

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

Re: WIN32_CONSOLE usage

From
Peter Eisentraut
Date:
Bruce Momjian writes:

> Is this a valid feature?  Should I document it?

Maybe it's a valid feature, but the implementation is not valid.
Other applications also make use of the print routines (e.g., createlang),
and they cannot interactively set variables.  So I repeat: the print
routines may not access the psql settings.

I think we ought to detect the console type automatically anyway.
Certainly we don't want people to have to set this variables all the time.

--
Peter Eisentraut   peter_e@gmx.net


Re: MinGW patch

From
Peter Eisentraut
Date:
Bruce Momjian writes:

> As Tom mentioned, it doesn't find things like sys/socket.h, which we
> have added to src/include/port/win32/.  This was done to elimintate
> #ifdef of the include files that are Win32-specific.

OK, then you can reference the top source directory as $srcdir in
configure.

--
Peter Eisentraut   peter_e@gmx.net


Re: WIN32_CONSOLE usage

From
Bruce Momjian
Date:
Peter Eisentraut wrote:

>   c) Problem:  8bit characters were displayed/interpreted wrong in psql
>                This is due to the fact that the Win32 "console" uses a
>                different encoding than the rest of the Windows system
>      Solution: Introduced a new psql variable WIN32_CONSOLE
>                When set with "\set WIN32_console", the function OemToChar()

> Bruce Momjian writes:
>
> > Is this a valid feature?  Should I document it?
>
> Maybe it's a valid feature, but the implementation is not valid.
> Other applications also make use of the print routines (e.g., createlang),
> and they cannot interactively set variables.  So I repeat: the print
> routines may not access the psql settings.
>
> I think we ought to detect the console type automatically anyway.
> Certainly we don't want people to have to set this variables all the time.

Agreed.  Automatic is ideal.  Any ideas out there?

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

Re: MinGW patch

From
Bruce Momjian
Date:
Peter Eisentraut wrote:
> Bruce Momjian writes:
>
> > As Tom mentioned, it doesn't find things like sys/socket.h, which we
> > have added to src/include/port/win32/.  This was done to elimintate
> > #ifdef of the include files that are Win32-specific.
>
> OK, then you can reference the top source directory as $srcdir in
> configure.

OK, new code is:

    if test "$PORTNAME" = "win32"
    then
            CPPFLAGS="$CPPFLAGS -I$srcdir/src/include/port/win32"
    fi

Thanks.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

Re: WIN32_CONSOLE usage

From
Manfred Spraul
Date:
Bruce Momjian wrote:

>>I think we ought to detect the console type automatically anyway.
>>Certainly we don't want people to have to set this variables all the time.
>>
>>
>
>Agreed.  Automatic is ideal.  Any ideas out there?
>
>
>
Does input from the console work correctly right now?

What about setting the code page of the console to the ansi code page?
Or to the code page that postgresql uses internally.

    SetConsoleCP(GetACP());
    SetConsoleOutputCP(GetACP());

might be sufficient.

--
    Manfred


Re: WIN32_CONSOLE usage

From
Christoph Dalitz
Date:
On Sun, 07 Sep 2003 20:37:08 +0200
Manfred Spraul <manfred@colorfullife.com> wrote:
>
> >>I think we ought to detect the console type automatically anyway.
> >>Certainly we don't want people to have to set this variables all the time.
> >>
> Does input from the console work correctly right now?
>
> What about setting the code page of the console to the ansi code page?
> Or to the code page that postgresql uses internally.
>
>     SetConsoleCP(GetACP());
>     SetConsoleOutputCP(GetACP());
>
> might be sufficient.
>
Shame on me!

Manfred's suggestion works perfectly. I did not realize this because the default
"rasterfont" for the win32 console cannot be used with codepage 1252 (windows
codepage on my system). When I switch to the font "Lucida Console" however, all
is fine with codepage 1252.

I have found this soultion here:
http://www.bei-priess.de/Perliges/perl-sonder.htm

Actually no psql tweaks are necessary at all, because the codepage for a console window
can be set with "cmd.exe /c chcp 1252". When I put this in my .bashrc, I actuallay
can use umlauts.

Sorry for producing some inconviniences in the psql devellopment.

The easiest would be to withdraw the WIN32_CONSOLE stuff from psql, replace it with
Manfred's solution and add to the documentation a tutorial how to make 8-bit characters
work in the Win32 console (with Manfred's solution, it actually only requires to set
the console font to "Lucida Console"). Alternatively no tweaks to psql could be done,
and the documentation should describe how the console can be forced to use the proper
encoding (this is certainly of interest to all win32 users of other applictaions as
well).

Christoph Dalitz


Re: WIN32_CONSOLE usage

From
Peter Eisentraut
Date:
Christoph Dalitz writes:

> The easiest would be to withdraw the WIN32_CONSOLE stuff from psql, replace it with
> Manfred's solution and add to the documentation a tutorial how to make 8-bit characters
> work in the Win32 console (with Manfred's solution, it actually only requires to set
> the console font to "Lucida Console"). Alternatively no tweaks to psql could be done,
> and the documentation should describe how the console can be forced to use the proper
> encoding (this is certainly of interest to all win32 users of other applictaions as
> well).

Please send in a patch.  Else, someone else is going to try to fix it with
less guarantees that it will work afterwards.

--
Peter Eisentraut   peter_e@gmx.net


Re: WIN32_CONSOLE usage

From
Christoph Dalitz
Date:
On Wed, 10 Sep 2003 19:18:24 +0200 (CEST)
Peter Eisentraut <peter_e@gmx.net> wrote:
>
> > The easiest would be to withdraw the WIN32_CONSOLE stuff from psql, replace it with
> > Manfred's solution and add to the documentation a tutorial how to make 8-bit characters
> > work in the Win32 console (with Manfred's solution, it actually only requires to set
> > the console font to "Lucida Console"). Alternatively no tweaks to psql could be done,
> > and the documentation should describe how the console can be forced to use the proper
> > encoding (this is certainly of interest to all win32 users of other applictaions as
> > well).
>
> Please send in a patch.  Else, someone else is going to try to fix it with
> less guarantees that it will work afterwards.
>
Ok. I can do the following:

 a) Write documentation how the win32 console needs to be set up so that
    psql can handle 8-bit characters.
    Where should it be added? The Section "Installation on Windows" in the
    Administrator's Guide seems natural to me.

 b) Add code to psql that prints a warning on startup of psql when the
    console codepage differs from the windows codepage, something like

    Warning: Console codepage (850) differs from windows codepage (1252)
             8-bit characters will not work correctly. See PostgreSQL
             documentation "Installation on Windows" for details.

Unfortunately there seems to be no automatic solution to the "console codepage problem",
because the windows codepage does not work with the default console font.
Thus the user must tweak his console settings in any case and I think a warning
is the best to remind the user of this issue.

Please let me know whether this "solution" would be ok. Then I can do it on Monday.

@Bruce:
-------

Could you please already remove the WIN32_CONSOLE and OemToChar/CharToOem stuff
from psql? Sorry for the inconvenience generated by my ignorance.

Christoph Dalitz