Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbd0a767

Browse files
committed
Here is a patch to make the current snapshot compile on Win32 (native, libpq
and psql) again. Changes are:1) psql requires the includes of "io.h" and "fcntl.h" in command.c in orderto make a call to open() work (io.h for _open(), fcntl.h for the O_xxx)2) PG_VERSION is no longer defined in version.h[.in], but in configure.in.Since we don't do configure on native win32, we need to put it inconfig.h.win32 :-(3) Added define of SYSCONFDIR to config.h.win32 - libpq won't compilewithout it. This functionality is *NOT* tested - it's just defined as "" fornow. May work, may not.4) DEF_PGPORT renamed to DEF_PGPORT_STRI have done the "basic tests" on it - it connects to a database, and I canrun queries. Haven't tested any of the fancier functions (yet).However, I stepped on a much bigger problem when fixing psql to work. It nolonger works when linked against the .DLL version of libpq (which theMakefile does for it). I have left it linked against this version anyway,pending the comments I get on this mail :-)The problem is that there are strings being allocated from libpq.dll usingPQExpBuffers (for example, initPQExpBuffer() on line 92 of input.c). Theseare being allocated using the malloc function used by libpq.dll. Thisfunction *may* be different from the malloc function used by psql.exe - onlythe resulting pointer must be valid. And with the default linking methods,it *WILL* be different. Later, psql.exe tries to free() this string, atwhich point it crashes because the free() function can't find the allocatedblock (it's on the allocated blocks list used by the runtime lib oflibpq.dll).Shouldn't the right thing to do be to have psql call termPQExpBuffer() onthe data instead? As it is now, gets_fromFile() will just return the pointerreceived from the PQExpBuffer.data (this may well be present at severalplaces - this is the one I was bitten by so far). Isn't that kind of"accessing the internals of the PQExpBuffer structure" wrong? Instead,perhaps it shuold make a copy of the string, adn then termPQExpBuffer() it?In that case, the string will have been allocated from within the samelibrary as the free() is called.I can get it to work just fine by doing this - changing from (around line100 of input.c):and the same a bit further down in the same function.But, as I said above, this may be at more places in the code? Perhapssomeone more familiar to it could comment on that?What do you think shuld be done about this? Personally, I go by the "If youallocate a piece of memory using an interface, use the same interface tofree it", but the question is how to make it work :-)Also, AFAIK this only affects psql.exe, so the changes made to the libpqthis patch are required no matter how the other issue is handled.Regards, Magnus
1 parenta939e97 commitbd0a767

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

‎src/bin/psql/command.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.43 2000/12/30 14:47:06 petere Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.44 2001/01/24 03:42:37 momjian Exp $
77
*/
88
#include"postgres.h"
99
#include"command.h"
@@ -18,6 +18,8 @@
1818
#include<unistd.h>/* for geteuid(), getpid(), stat() */
1919
#else
2020
#include<win32.h>
21+
#include<io.h>
22+
#include<fnctl.h>
2123
#endif
2224

2325
#include"libpq-fe.h"

‎src/include/config.h.win32

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
*/
44

55

6-
/* Since we don't do autoconf, we need to read the .in file. Ugly */
7-
#include "version.h.in"
6+
#define PG_VERSION 7.1
7+
#define PG_VERSION_STR "7.1 (win32)"
88

9-
#define DEF_PGPORT "5432"
9+
#define SYSCONFDIR ""
10+
11+
#define DEF_PGPORT_STR "5432"
1012
#define MAXIMUM_ALIGNOF 4
1113
#define MAXPGPATH 1024
1214

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp