Thread: libpq.dll on win32

libpq.dll on win32

From
"Magnus Hagander"
Date:
This patch aims to correct the issues with libpq.dll exporting too much
on win32. Contains the following changes:

* Exports PQgetssl() even if SSL support is not compiled in. In this
case, it always returns NULL. This is required so programs that expect
SSL version of the library does not crash if they don't get it.

* Create a global flag in Makefile.shlib named "DLL_DEFNAME" used to
specify a .def file when generating a DLL. If not specified, falls back
to the old behaviour of exporting everything in the file.

* Adds required functions to libpqdll.def and libpqddll.def. This
includes the functions not in the libpq API that are used by initdb and
imported from libpq.dll (per recent mail discussion)


//Magnus


Attachment

Re: libpq.dll on win32

From
Tom Lane
Date:
"Magnus Hagander" <mha@sollentuna.net> writes:

*** src/interfaces/libpq/fe-secure.c    28 Sep 2004 00:06:02 -0000    1.54
--- src/interfaces/libpq/fe-secure.c    11 Oct 2004 19:50:22 -0000
***************
*** 1201,1206 ****
--- 1201,1212 ----
          return NULL;
      return conn->ssl;
  }
+ #else
+ void *
+ PQgetssl(PGconn *conn)
+ {
+     return NULL;
+ }
  #endif   /* USE_SSL */


This seems like a good idea, but that particular approach to it will
draw an unprototyped-global-function warning on every non-SSL-enabled
compile ... please clean it up.

Also, I count 3 *.def files to be fixed, not two.  (We really oughta
figure a way to generate them all from a single list file... can we
rely on sed(1) being available in all Windows build environments?)

            regards, tom lane

Re: libpq.dll on win32

From
"Dave Page"
Date:

> -----Original Message-----
> From: pgsql-patches-owner@postgresql.org
> [mailto:pgsql-patches-owner@postgresql.org] On Behalf Of
> Magnus Hagander
> Sent: 11 October 2004 21:05
> To: pgsql-patches
> Subject: [PATCHES] libpq.dll on win32
>
> * Adds required functions to libpqdll.def and libpqddll.def.
> This includes the functions not in the libpq API that are
> used by initdb and imported from libpq.dll (per recent mail
> discussion)

They should be added to the Borland .def files as well.

Regards, Dave

Re: libpq.dll on win32

From
"Dave Page"
Date:

> -----Original Message-----
> From: pgsql-patches-owner@postgresql.org
> [mailto:pgsql-patches-owner@postgresql.org] On Behalf Of Tom Lane
> Sent: 12 October 2004 01:38
> To: Magnus Hagander
> Cc: pgsql-patches
> Subject: Re: [PATCHES] libpq.dll on win32
>
> Also, I count 3 *.def files to be fixed, not two.  (We really
> oughta figure a way to generate them all from a single list
> file... can we rely on sed(1) being available in all Windows
> build environments?)

I could have sworn there used to be 4 .def files - 2 for VC++ and 2 for
Borland. Oh well.

Anyway, no, sed will not be available in VC++, or (I guess) Borland
environments.

Regards, Dave

Re: libpq.dll on win32

From
Reini Urban
Date:
Tom Lane schrieb:
> Also, I count 3 *.def files to be fixed, not two.  (We really oughta
> figure a way to generate them all from a single list file... can we
> rely on sed(1) being available in all Windows build environments?)

for cygwin: yes.
the non-gcc builds would need the mingw or cygwin versions.

Re: libpq.dll on win32

From
Tom Lane
Date:
Reini Urban <rurban@x-ray.at> writes:
> Tom Lane schrieb:
>> Also, I count 3 *.def files to be fixed, not two.  (We really oughta
>> figure a way to generate them all from a single list file... can we
>> rely on sed(1) being available in all Windows build environments?)

> for cygwin: yes.
> the non-gcc builds would need the mingw or cygwin versions.

A workable plan B would be to keep a single list file in CVS and build
the *.def files as derived files that we include in the distribution
tarball (same principle as for bison/flex output files).

            regards, tom lane

Re: libpq.dll on win32

From
"Magnus Hagander"
Date:
>*** src/interfaces/libpq/fe-secure.c    28 Sep 2004 00:06:02
>-0000    1.54
>--- src/interfaces/libpq/fe-secure.c    11 Oct 2004 19:50:22 -0000
>***************
>*** 1201,1206 ****
>--- 1201,1212 ----
>          return NULL;
>      return conn->ssl;
>  }
>+ #else
>+ void *
>+ PQgetssl(PGconn *conn)
>+ {
>+     return NULL;
>+ }
>  #endif   /* USE_SSL */
>
>
>This seems like a good idea, but that particular approach to it will
>draw an unprototyped-global-function warning on every non-SSL-enabled
>compile ... please clean it up.

Oops. Updated patch attached.


>Also, I count 3 *.def files to be fixed, not two.

Right. The Borland one, forgot all about that one. Included in attached
patch. Borland version not actually tested, though, since I don't have
Borland C..

>  (We really oughta
>figure a way to generate them all from a single list file... can we
>rely on sed(1) being available in all Windows build environments?)

Unfortunatly, no, we can't.
There are sed implementations available for win32, but they're not
installed by default. MingW and Cygwin of course ship with sed, but we
build libpq with MSVC and Borland as well...

The avaiable options to do it are just horrible. There is edlin, but it
can't be used for anything serious. Or there is the wonderful concept of
writing something in vbscript. But putting vbscript in there doesn't
seem like a very good option.

I like the idea of having it built automatically for the snapshots in
some way, and if you want to build it manually, you have to install
'sed'. I think that's a reasonable requirement.

Anyway. Here is the patch for this one. Not sure we want to muck around
with those build issues during beta considering they actually *work* now
(if a bit of extra work).

//Magnus

Attachment

Re: libpq.dll on win32

From
Andrew Dunstan
Date:

Magnus Hagander wrote:

>> (We really oughta
>>figure a way to generate them all from a single list file... can we
>>rely on sed(1) being available in all Windows build environments?)
>>
>>
>
>Unfortunatly, no, we can't.
>There are sed implementations available for win32, but they're not
>installed by default. MingW and Cygwin of course ship with sed, but we
>build libpq with MSVC and Borland as well...
>
>The avaiable options to do it are just horrible. There is edlin, but it
>can't be used for anything serious. Or there is the wonderful concept of
>writing something in vbscript. But putting vbscript in there doesn't
>seem like a very good option.
>
>
>

ActiveState Perl? It's very widely used.

cheers

andrew

Re: libpq.dll on win32

From
"Magnus Hagander"
Date:
>>The avaiable options to do it are just horrible. There is
>edlin, but it
>>can't be used for anything serious. Or there is the wonderful
>concept of
>>writing something in vbscript. But putting vbscript in there doesn't
>>seem like a very good option.
>>
>>
>>
>
>ActiveState Perl? It's very widely used.
>

Yes, but it's not in there by default.
If we're going to require a third party tool to be installed, we'd
probably be better off requiring a simple sed.exe which is a single
binary instead of the whole perl package which is hundreds of files and
many megabytes...

//Magnus

Re: libpq.dll on win32

From
Andrew Dunstan
Date:

Magnus Hagander wrote:

>>>The avaiable options to do it are just horrible. There is
>>>
>>>
>>edlin, but it
>>
>>
>>>can't be used for anything serious. Or there is the wonderful
>>>
>>>
>>concept of
>>
>>
>>>writing something in vbscript. But putting vbscript in there doesn't
>>>seem like a very good option.
>>>
>>>
>>>
>>>
>>>
>>ActiveState Perl? It's very widely used.
>>
>>
>>
>
>Yes, but it's not in there by default.
>If we're going to require a third party tool to be installed, we'd
>probably be better off requiring a simple sed.exe which is a single
>binary instead of the whole perl package which is hundreds of files and
>many megabytes...
>
>

Try this then: http://gnuwin32.sourceforge.net/packages/sed.htm (almost
a single binary, anyway)


cheers

andrew

Re: libpq.dll on win32

From
Tom Lane
Date:
Andrew Dunstan <andrew@dunslane.net> writes:
>> Yes, but it's not in there by default.
>> If we're going to require a third party tool to be installed, we'd
>> probably be better off requiring a simple sed.exe which is a single
>> binary instead of the whole perl package which is hundreds of files and
>> many megabytes...

> Try this then: http://gnuwin32.sourceforge.net/packages/sed.htm (almost
> a single binary, anyway)

This is all pretty silly.  We should just build the .def files during
tarball construction, much as we handle bison/flex stuff.

            regards, tom lane

Re: libpq.dll on win32

From
Bruce Momjian
Date:
Patch applied.  Thanks.

I fixed a few merge conflicts.

---------------------------------------------------------------------------


Magnus Hagander wrote:
> >*** src/interfaces/libpq/fe-secure.c    28 Sep 2004 00:06:02
> >-0000    1.54
> >--- src/interfaces/libpq/fe-secure.c    11 Oct 2004 19:50:22 -0000
> >***************
> >*** 1201,1206 ****
> >--- 1201,1212 ----
> >          return NULL;
> >      return conn->ssl;
> >  }
> >+ #else
> >+ void *
> >+ PQgetssl(PGconn *conn)
> >+ {
> >+     return NULL;
> >+ }
> >  #endif   /* USE_SSL */
> >
> >
> >This seems like a good idea, but that particular approach to it will
> >draw an unprototyped-global-function warning on every non-SSL-enabled
> >compile ... please clean it up.
>
> Oops. Updated patch attached.
>
>
> >Also, I count 3 *.def files to be fixed, not two.
>
> Right. The Borland one, forgot all about that one. Included in attached
> patch. Borland version not actually tested, though, since I don't have
> Borland C..
>
> >  (We really oughta
> >figure a way to generate them all from a single list file... can we
> >rely on sed(1) being available in all Windows build environments?)
>
> Unfortunatly, no, we can't.
> There are sed implementations available for win32, but they're not
> installed by default. MingW and Cygwin of course ship with sed, but we
> build libpq with MSVC and Borland as well...
>
> The avaiable options to do it are just horrible. There is edlin, but it
> can't be used for anything serious. Or there is the wonderful concept of
> writing something in vbscript. But putting vbscript in there doesn't
> seem like a very good option.
>
> I like the idea of having it built automatically for the snapshots in
> some way, and if you want to build it manually, you have to install
> 'sed'. I think that's a reasonable requirement.
>
> Anyway. Here is the patch for this one. Not sure we want to muck around
> with those build issues during beta considering they actually *work* now
> (if a bit of extra work).
>
> //Magnus

Content-Description: libpq_def.patch

[ Attachment, skipping... ]

>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
>                http://www.postgresql.org/docs/faqs/FAQ.html

--
  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: src/Makefile.shlib
===================================================================
RCS file: /cvsroot/pgsql/src/Makefile.shlib,v
retrieving revision 1.85
diff -c -c -r1.85 Makefile.shlib
*** src/Makefile.shlib    15 Oct 2004 05:11:00 -0000    1.85
--- src/Makefile.shlib    16 Oct 2004 03:22:09 -0000
***************
*** 31,36 ****
--- 31,38 ----
  # DLLTOOL_DEFFLAGS      Additional flags when creating the dll .def file
  # DLLTOOL_LIBFLAGS      Additional flags when creating the lib<module>.a file
  # DLLWRAP_FLAGS         Additional flags to dllwrap
+ # DLL_DEFFILE           Use pre-existing .def file instead of auto-generating
+ #                       one with all exports in it (win32 only).
  #
  # The module Makefile must also include
  # $(top_builddir)/src/Makefile.global before including this file.
***************
*** 306,314 ****
--- 308,321 ----

  # Cygwin case
  $(shlib) lib$(NAME).a: $(OBJS)
+ ifndef DLL_DEFFILE
      $(DLLTOOL) --export-all $(DLLTOOL_DEFFLAGS) --output-def $(NAME).def $(OBJS)
      $(DLLWRAP) $(LDFLAGS_SL) -o $(shlib) --dllname $(shlib) $(DLLWRAP_FLAGS) --def $(NAME).def $(OBJS) $(SHLIB_LINK)
      $(DLLTOOL) --dllname $(shlib) $(DLLTOOL_LIBFLAGS) --def $(NAME).def --output-lib lib$(NAME).a
+ else
+     $(DLLWRAP) $(LDFLAGS_SL) -o $(shlib) --dllname $(shlib) $(DLLWRAP_FLAGS) --def $(DLL_DEFFILE) $(OBJS)
$(SHLIB_LINK)
+     $(DLLTOOL) --dllname $(shlib) $(DLLTOOL_LIBFLAGS) --def $(DLL_DEFFILE) --output-lib lib$(NAME).a
+ endif

  endif # PORTNAME == cygwin

***************
*** 316,324 ****
--- 323,336 ----

  # win32 case
  $(shlib) lib$(NAME).a: $(OBJS)
+ ifndef DLL_DEFFILE
      $(DLLTOOL) --export-all $(DLLTOOL_DEFFLAGS) --output-def $(NAME).def $(OBJS)
      $(DLLWRAP) $(LDFLAGS_SL) -o $(shlib) --dllname $(shlib) $(DLLWRAP_FLAGS) --def $(NAME).def $(OBJS) $(SHLIB_LINK)
      $(DLLTOOL) --dllname $(shlib) $(DLLTOOL_LIBFLAGS) --def $(NAME).def --output-lib lib$(NAME).a
+ else
+     $(DLLWRAP) $(LDFLAGS_SL) -o $(shlib) --dllname $(shlib) $(DLLWRAP_FLAGS) --def $(DLL_DEFFILE) $(OBJS)
$(SHLIB_LINK)
+     $(DLLTOOL) --dllname $(shlib) $(DLLTOOL_LIBFLAGS) --def $(DLL_DEFFILE) --output-lib lib$(NAME).a
+ endif

  endif # PORTNAME == win32

Index: src/interfaces/libpq/Makefile
===================================================================
RCS file: /cvsroot/pgsql/src/interfaces/libpq/Makefile,v
retrieving revision 1.117
diff -c -c -r1.117 Makefile
*** src/interfaces/libpq/Makefile    12 Oct 2004 04:48:36 -0000    1.117
--- src/interfaces/libpq/Makefile    16 Oct 2004 03:22:22 -0000
***************
*** 34,39 ****
--- 34,40 ----
  OBJS += win32.o libpqrc.o
  libpqrc.o : libpq.rc
      windres -i libpq.rc -o libpqrc.o
+ DLL_DEFFILE=libpqdll.def
  ifeq ($(enable_thread_safety), yes)
  # This doesn't work yet because configure test fails.  2004-06-19
  OBJS += pthread-win32.o
Index: src/interfaces/libpq/blibpqdll.def
===================================================================
RCS file: /cvsroot/pgsql/src/interfaces/libpq/blibpqdll.def,v
retrieving revision 1.10
diff -c -c -r1.10 blibpqdll.def
*** src/interfaces/libpq/blibpqdll.def    11 Aug 2004 18:06:01 -0000    1.10
--- src/interfaces/libpq/blibpqdll.def    16 Oct 2004 03:22:23 -0000
***************
*** 115,120 ****
--- 115,124 ----
      _PQsendQueryPrepared     @ 111
      _PQdsplen                @ 112
      _PQserverVersion         @ 113
+     _PQgetssl                @ 114
+     _pg_char_to_encoding     @ 115
+     _pg_valid_server_encoding @ 116
+     _pqsignal                @ 117

  ; Aliases for MS compatible names
      PQconnectdb             = _PQconnectdb
***************
*** 230,232 ****
--- 234,240 ----
      PQsendQueryPrepared     = _PQsendQueryPrepared
      PQdsplen                = _PQdsplen
      PQserverVersion         = _PQserverVersion
+     PQgetssl                = _PQgetssl
+     pg_char_to_encoding     = _pg_char_to_encoding
+     pg_valid_server_encoding = _pg_valid_server_encoding
+     pqsignal                = _pqsignal
Index: src/interfaces/libpq/fe-secure.c
===================================================================
RCS file: /cvsroot/pgsql/src/interfaces/libpq/fe-secure.c,v
retrieving revision 1.54
diff -c -c -r1.54 fe-secure.c
*** src/interfaces/libpq/fe-secure.c    28 Sep 2004 00:06:02 -0000    1.54
--- src/interfaces/libpq/fe-secure.c    16 Oct 2004 03:22:26 -0000
***************
*** 1201,1206 ****
--- 1201,1212 ----
          return NULL;
      return conn->ssl;
  }
+ #else
+ void *
+ PQgetssl(PGconn *conn)
+ {
+     return NULL;
+ }
  #endif   /* USE_SSL */


Index: src/interfaces/libpq/libpq-fe.h
===================================================================
RCS file: /cvsroot/pgsql/src/interfaces/libpq/libpq-fe.h,v
retrieving revision 1.109
diff -c -c -r1.109 libpq-fe.h
*** src/interfaces/libpq/libpq-fe.h    16 Oct 2004 03:10:17 -0000    1.109
--- src/interfaces/libpq/libpq-fe.h    16 Oct 2004 03:22:28 -0000
***************
*** 258,263 ****
--- 258,265 ----
  #ifdef USE_SSL
  /* Get the SSL structure associated with a connection */
  extern SSL *PQgetssl(PGconn *conn);
+ #else
+ extern void *PQgetssl(PGconn *conn);
  #endif

  /* Set verbosity for PQerrorMessage and PQresultErrorMessage */
Index: src/interfaces/libpq/libpqddll.def
===================================================================
RCS file: /cvsroot/pgsql/src/interfaces/libpq/libpqddll.def,v
retrieving revision 1.2
diff -c -c -r1.2 libpqddll.def
*** src/interfaces/libpq/libpqddll.def    11 Aug 2004 18:06:01 -0000    1.2
--- src/interfaces/libpq/libpqddll.def    16 Oct 2004 03:22:29 -0000
***************
*** 115,117 ****
--- 115,121 ----
      PQsendQueryPrepared     @ 111
      PQdsplen                @ 112
      PQserverVersion         @ 113
+     PQgetssl                @ 114
+     pg_char_to_encoding     @ 115
+     pg_valid_server_encoding @ 116
+     pqsignal                @ 117
Index: src/interfaces/libpq/libpqdll.def
===================================================================
RCS file: /cvsroot/pgsql/src/interfaces/libpq/libpqdll.def,v
retrieving revision 1.26
diff -c -c -r1.26 libpqdll.def
*** src/interfaces/libpq/libpqdll.def    11 Aug 2004 18:06:01 -0000    1.26
--- src/interfaces/libpq/libpqdll.def    16 Oct 2004 03:22:29 -0000
***************
*** 115,117 ****
--- 115,121 ----
      PQsendQueryPrepared     @ 111
      PQdsplen                @ 112
      PQserverVersion         @ 113
+     PQgetssl                @ 114
+     pg_char_to_encoding     @ 115
+     pg_valid_server_encoding @ 116
+     pqsignal                @ 117