Fix for Win32 pgport and pg_dumpall - Mailing list pgsql-patches
From | Bruce Momjian |
---|---|
Subject | Fix for Win32 pgport and pg_dumpall |
Date | |
Msg-id | 200408080643.i786h5x20312@candle.pha.pa.us Whole thread Raw |
List | pgsql-patches |
The applied patch fixes libpgport backend linking on Win32. The solution was to create palloc/pstrdup stubs in the backend and call them from dirmod.c. Seems the DLLIMPORT modifier on CurrentMemoryContext means it can't also be referenced in pgport. This also fixes a broken pg_dumpall implementation on Win32. All help via Claudio. -- 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/backend/utils/mmgr/mcxt.c =================================================================== RCS file: /cvsroot/pgsql-server/src/backend/utils/mmgr/mcxt.c,v retrieving revision 1.46 diff -c -c -r1.46 mcxt.c *** src/backend/utils/mmgr/mcxt.c 1 Jul 2004 00:51:29 -0000 1.46 --- src/backend/utils/mmgr/mcxt.c 8 Aug 2004 06:39:23 -0000 *************** *** 629,631 **** --- 629,666 ---- return nstr; } + + + #ifdef WIN32 + /* + * Memory support routines for libpgport on Win32 + * + * Win32 can't load a library that DLLIMPORTs a variable + * if the link object files also DLLIMPORT the same variable. + * For this reason, libpgport can't reference CurrentMemoryContext + * in the palloc macro calls. + * + * To fix this, we create several functions here that allow us to + * manage memory without doing the inline in libpgport. + */ + void * + pgport_palloc(Size sz) + { + return palloc(sz); + } + + char * + pgport_pstrdup(const char *str) + { + return pstrdup(str); + } + + + /* Doesn't reference a DLLIMPORT variable, but here for completeness. */ + void + pgport_pfree(void *pointer) + { + pfree(pointer); + return; + } + #endif Index: src/bin/pg_dump/pg_dumpall.c =================================================================== RCS file: /cvsroot/pgsql-server/src/bin/pg_dump/pg_dumpall.c,v retrieving revision 1.46 diff -c -c -r1.46 pg_dumpall.c *** src/bin/pg_dump/pg_dumpall.c 4 Aug 2004 21:34:12 -0000 1.46 --- src/bin/pg_dump/pg_dumpall.c 8 Aug 2004 06:39:26 -0000 *************** *** 840,860 **** const char *p; int ret; appendPQExpBuffer(cmd, "%s\"%s\" %s -Fp '", SYSTEMQUOTE, pg_dump_bin, pgdumpopts->data); /* Shell quoting is not quite like SQL quoting, so can't use fmtId */ for (p = dbname; *p; p++) { if (*p == '\'') appendPQExpBuffer(cmd, "'\"'\"'"); else appendPQExpBufferChar(cmd, *p); } appendPQExpBufferChar(cmd, '\''); ! appendStringLiteral(cmd, SYSTEMQUOTE, false); ! if (verbose) fprintf(stderr, _("%s: running \"%s\"\n"), progname, cmd->data); --- 840,878 ---- const char *p; int ret; + /* + * Win32 has to use double-quotes for args, rather than single quotes. + * Strangely enough, this is the only place we pass a database name + * on the command line, except template1 that doesn't need quoting. + */ + #ifndef WIN32 appendPQExpBuffer(cmd, "%s\"%s\" %s -Fp '", SYSTEMQUOTE, pg_dump_bin, + #else + appendPQExpBuffer(cmd, "%s\"%s\" %s -Fp \"", SYSTEMQUOTE, pg_dump_bin, + #endif pgdumpopts->data); /* Shell quoting is not quite like SQL quoting, so can't use fmtId */ for (p = dbname; *p; p++) { + #ifndef WIN32 if (*p == '\'') appendPQExpBuffer(cmd, "'\"'\"'"); else + #endif + /* not needed on Win32 */ appendPQExpBufferChar(cmd, *p); } + #ifndef WIN32 appendPQExpBufferChar(cmd, '\''); ! #else ! appendPQExpBufferChar(cmd, '"'); ! #endif ! ! if (strlen(SYSTEMQUOTE) > 0) ! appendPQExpBuffer(cmd, SYSTEMQUOTE); ! if (verbose) fprintf(stderr, _("%s: running \"%s\"\n"), progname, cmd->data); Index: src/include/port.h =================================================================== RCS file: /cvsroot/pgsql-server/src/include/port.h,v retrieving revision 1.49 diff -c -c -r1.49 port.h *** src/include/port.h 8 Aug 2004 01:43:33 -0000 1.49 --- src/include/port.h 8 Aug 2004 06:39:27 -0000 *************** *** 151,156 **** --- 151,157 ---- #define rename(from, to) pgrename(from, to) #define unlink(path) pgunlink(path) #define symlink(oldpath, newpath) pgsymlink(oldpath, newpath) + #endif extern bool rmtree(char *path, bool rmtopdir); Index: src/include/utils/palloc.h =================================================================== RCS file: /cvsroot/pgsql-server/src/include/utils/palloc.h,v retrieving revision 1.27 diff -c -c -r1.27 palloc.h *** src/include/utils/palloc.h 29 Nov 2003 22:41:15 -0000 1.27 --- src/include/utils/palloc.h 8 Aug 2004 06:39:29 -0000 *************** *** 80,83 **** --- 80,88 ---- #define pstrdup(str) MemoryContextStrdup(CurrentMemoryContext, (str)) + /* Used for Win32 */ + void *pgport_palloc(Size sz); + char *pgport_pstrdup(const char *str); + void pgport_pfree(void *pointer); + #endif /* PALLOC_H */ Index: src/port/dirmod.c =================================================================== RCS file: /cvsroot/pgsql-server/src/port/dirmod.c,v retrieving revision 1.17 diff -c -c -r1.17 dirmod.c *** src/port/dirmod.c 8 Aug 2004 05:04:41 -0000 1.17 --- src/port/dirmod.c 8 Aug 2004 06:39:31 -0000 *************** *** 38,43 **** --- 38,50 ---- #undef rename #undef unlink + #ifndef FRONTEND + #define palloc(sz) pgport_palloc(sz) + #define pstrdup(str) pgport_pstrdup(str) + #define pfree(pointer) pgport_pfree(pointer) + #endif + + /* * pgrename */
pgsql-patches by date: