From 7ee3c351522694dc6f8f0d6578394bdf5dec0b59 Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Sun, 8 Aug 2004 06:44:36 +0000 Subject: [PATCH] Allow libpgport to call memory allocation routines even though CurrentMemoryContext is DLLIMPORT on Win32. Work around that by creating stubs in the backend for palloc/pstrdup. Also fix pg_dumpall to do proper quoting on Win32. --- src/backend/utils/mmgr/mcxt.c | 37 ++++++++++++++++++++++++++++++++++++- src/bin/pg_dump/pg_dumpall.c | 22 ++++++++++++++++++++-- src/include/port.h | 3 ++- src/include/utils/palloc.h | 7 ++++++- src/port/dirmod.c | 9 ++++++++- 5 files changed, 72 insertions(+), 6 deletions(-) diff --git a/src/backend/utils/mmgr/mcxt.c b/src/backend/utils/mmgr/mcxt.c index 96ffb1a8e1..28e9d26a2f 100644 --- a/src/backend/utils/mmgr/mcxt.c +++ b/src/backend/utils/mmgr/mcxt.c @@ -14,7 +14,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/mmgr/mcxt.c,v 1.46 2004/07/01 00:51:29 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/mmgr/mcxt.c,v 1.47 2004/08/08 06:44:32 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -629,3 +629,38 @@ MemoryContextStrdup(MemoryContext context, const char *string) 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 diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index d260f2c0b2..a79cf836b2 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -6,7 +6,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * - * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.46 2004/08/04 21:34:12 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.47 2004/08/08 06:44:33 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -840,21 +840,39 @@ runPgDump(const char *dbname) 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, '\''); - appendStringLiteral(cmd, SYSTEMQUOTE, false); +#else + appendPQExpBufferChar(cmd, '"'); +#endif + if (strlen(SYSTEMQUOTE) > 0) + appendPQExpBuffer(cmd, SYSTEMQUOTE); + if (verbose) fprintf(stderr, _("%s: running \"%s\"\n"), progname, cmd->data); diff --git a/src/include/port.h b/src/include/port.h index c2bcea78bf..e7ffdce362 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -6,7 +6,7 @@ * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/port.h,v 1.49 2004/08/08 01:43:33 momjian Exp $ + * $PostgreSQL: pgsql/src/include/port.h,v 1.50 2004/08/08 06:44:33 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -151,6 +151,7 @@ extern int pgsymlink(const char *oldpath, const char *newpath); #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); diff --git a/src/include/utils/palloc.h b/src/include/utils/palloc.h index b0a6760f5e..8dfa98bf97 100644 --- a/src/include/utils/palloc.h +++ b/src/include/utils/palloc.h @@ -21,7 +21,7 @@ * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/utils/palloc.h,v 1.27 2003/11/29 22:41:15 pgsql Exp $ + * $PostgreSQL: pgsql/src/include/utils/palloc.h,v 1.28 2004/08/08 06:44:35 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -80,4 +80,9 @@ extern char *MemoryContextStrdup(MemoryContext context, const char *string); #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 */ diff --git a/src/port/dirmod.c b/src/port/dirmod.c index 5413253efd..7c87c0fff0 100644 --- a/src/port/dirmod.c +++ b/src/port/dirmod.c @@ -10,7 +10,7 @@ * Win32 (NT, Win2k, XP). replace() doesn't work on Win95/98/Me. * * IDENTIFICATION - * $PostgreSQL: pgsql/src/port/dirmod.c,v 1.17 2004/08/08 05:04:41 momjian Exp $ + * $PostgreSQL: pgsql/src/port/dirmod.c,v 1.18 2004/08/08 06:44:36 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -38,6 +38,13 @@ #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 */ -- 2.11.0