pyPgSQL works with MSVC6 compiled libpq now -- was Re: [Pypgsql-users] Re: Can't connect using Win95 client

Gerhard Häring <[email protected]> Mon, 16 Jun 2003 14:46:30 +0200
Newsgroups gmane.comp.python.db.pypgsql.user
Message-ID <[email protected]>
Gerhard Häring wrote:
> Pinchart, Laurent wrote:
> 
>> Yes I did (to fix a problem for which I submitted a patch). That's 
>> probably
>> the cause of the problem, as I don't remember having encountered it 
>> before.
>>
>> I compiled libpq using Visual Studio 6 (nmake -f win32.mak), and then
>> compiled pyPgSQL using the same compiler (python setup.py build).
> 
> I'll try to look into this on the weekend. [...]

The problem Problem solved and fixed in CSV. It was indeed a pretty 
strange one as well:

In fact, the problem was with my mingw patch for libpq, not with 
pyPgSQL. pyPgSQL shouldn't have worked in the first place. Ok, it was 
pretty clear that a call to WSAStartup was missing, but why the hell did 
the mingw build work ok, then? The reason was that my mingw patch for 
libpq included the libpdll.c file in both the DLL version *and* the 
static version. This file contains a function DllMain. Now if you 
compiled pyPgSQL statically against libpq, this DllMain function was 
linked in into pyPgSQL/libpq/libpq.pyd. Of course this DllMain does the 
necessary WSAStartup/WSACleanup calls. The MSVC build was missing this 
DLLMain and thus the WSAStartup call.

Now of course the proper solution was for me to fix my mingw/libpq 
patch, which I did and uploaded to http://pypgsql.sf.net/misc/

Of course the WSAStartup/Cleanup call needed to go into pyPgSQL and this 
I did. I just put the PostgreSQL code into the pyPgSQL C layer and 
everything is fine now. I tested all combinations and all work:

MSVC6:	statically + dynamically linked against libpq
mingw:  statically + dynamically linked against libpq

I have no idea about the original Windows 95 problem this thread started 
with. All I can recommend is that SP1 for Win95 is installed. It 
includes some Winsock fixes.

-- Gerhard


-------------------------------------------------------
This SF.NET email is sponsored by: eBay
Great deals on office technology -- on eBay now! Click here:
http://adfarm.mediaplex.com/ad/ck/711-11697-6916-5