]> granicus.if.org Git - postgresql/commitdiff
Clean up after recent pg_dump patches.
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 30 Nov 2011 01:41:06 +0000 (20:41 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 30 Nov 2011 01:41:54 +0000 (20:41 -0500)
Fix entirely broken handling of va_list printing routines, update some
out-of-date comments, fix some bogus inclusion orders, fix NLS declarations,
fix missed realloc calls.

src/bin/pg_dump/common.c
src/bin/pg_dump/dumpmem.c
src/bin/pg_dump/dumpmem.h
src/bin/pg_dump/dumputils.c
src/bin/pg_dump/dumputils.h
src/bin/pg_dump/nls.mk
src/bin/pg_dump/pg_backup_archiver.c
src/bin/pg_dump/pg_backup_archiver.h
src/bin/pg_dump/pg_dumpall.c
src/bin/pg_dump/pg_restore.c

index 6f921f7758c93dfa3a6b99b984cdd3794a2d9e88..d4e906ddd0c94581b54ac98cd779d06569aaf3ab 100644 (file)
@@ -1,7 +1,7 @@
 /*-------------------------------------------------------------------------
  *
  * common.c
- *     catalog routines used by pg_dump;  long ago these were shared
+ *     Catalog routines used by pg_dump; long ago these were shared
  *     by another dump tool, but not anymore.  
  *
  * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
  *
  *-------------------------------------------------------------------------
  */
-#include "postgres_fe.h"
+#include "pg_backup_archiver.h"
 
 #include <ctype.h>
 
 #include "catalog/pg_class.h"
-
-#include "pg_backup_archiver.h"
 #include "dumpmem.h"
+#include "dumputils.h"
 
 
 /*
index a71e217b702e6300fcd727c8a9889d9da11c5767..570b68021b6c27da5503fded29e358c266a3ec8e 100644 (file)
@@ -1,8 +1,7 @@
 /*-------------------------------------------------------------------------
  *
  * dumpmem.c
- *       memory routines used by pg_dump and pg_restore (but not pg_dumpall
- *       because there is no failure location to report).
+ *       Memory allocation routines used by pg_dump, pg_dumpall, and pg_restore
  *
  * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *-------------------------------------------------------------------------
  */
 #include "postgres_fe.h"
+
 #include "dumputils.h"
 #include "dumpmem.h"
 
-#include <ctype.h>
 
 /*
  * Safer versions of some standard C library functions. If an
- * out-of-memory condition occurs, these functions will bail out
- * safely; therefore, their return value is guaranteed to be non-NULL.
- * We also report the program name and close the database connection.
+ * out-of-memory condition occurs, these functions will bail out via exit();
+ *therefore, their return value is guaranteed to be non-NULL.
  */
 
 char *
@@ -57,7 +55,7 @@ pg_calloc(size_t nmemb, size_t size)
 
        tmp = calloc(nmemb, size);
        if (!tmp)
-               exit_horribly(NULL, _("out of memory\n"));
+               exit_horribly(NULL, "out of memory\n");
        return tmp;
 }
 
@@ -68,6 +66,6 @@ pg_realloc(void *ptr, size_t size)
 
        tmp = realloc(ptr, size);
        if (!tmp)
-               exit_horribly(NULL, _("out of memory\n"));
+               exit_horribly(NULL, "out of memory\n");
        return tmp;
 }
index f70b32065e6982d8d784fa955475eccf6326d1e4..2b4a1eb24d888ba7f2201da6e4e219b13349ef6d 100644 (file)
@@ -1,7 +1,7 @@
 /*-------------------------------------------------------------------------
  *
  * dumpmem.h
- *       Common header file for the pg_dump and pg_restore
+ *       Memory allocation routines used by pg_dump, pg_dumpall, and pg_restore
  *
  * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
@@ -14,8 +14,6 @@
 #ifndef DUMPMEM_H
 #define DUMPMEM_H
 
-#include "postgres_fe.h"
-
 extern char *pg_strdup(const char *string);
 extern void *pg_malloc(size_t size);
 extern void *pg_calloc(size_t nmemb, size_t size);
index 39601e6a5fc10297f72c45de5e8def0d39494445..5dab9675fc0bfe50fbceb49e69a379c45375a178 100644 (file)
 
 #include <ctype.h>
 
-#include "dumpmem.h"
 #include "dumputils.h"
 
 #include "parser/keywords.h"
 
 
+/* Globals exported by this file */
 int                    quote_all_identifiers = 0;
-const char *progname;
+const char *progname = NULL;
 
 
 #define supports_grant_options(version) ((version) >= 70400)
@@ -1214,31 +1214,51 @@ emitShSecLabels(PGconn *conn, PGresult *res, PQExpBuffer buffer,
 }
 
 
+/*
+ * Write a printf-style message to stderr.
+ *
+ * The program name is prepended, if "progname" has been set.
+ * Also, if modulename isn't NULL, that's included too.
+ * Note that we'll try to translate the modulename and the fmt string.
+ */
 void
 write_msg(const char *modulename, const char *fmt,...)
 {
        va_list         ap;
 
        va_start(ap, fmt);
-       if (modulename)
-               fprintf(stderr, "%s: [%s] ", progname, _(modulename));
-       else
-               fprintf(stderr, "%s: ", progname);
-       vfprintf(stderr, _(fmt), ap);
+       vwrite_msg(modulename, fmt, ap);
        va_end(ap);
 }
 
+/*
+ * As write_msg, but pass a va_list not variable arguments.
+ */
+void
+vwrite_msg(const char *modulename, const char *fmt, va_list ap)
+{
+       if (progname)
+       {
+               if (modulename)
+                       fprintf(stderr, "%s: [%s] ", progname, _(modulename));
+               else
+                       fprintf(stderr, "%s: ", progname);
+       }
+       vfprintf(stderr, _(fmt), ap);
+}
+
 
+/*
+ * Fail and die, with a message to stderr.  Parameters as for write_msg.
+ */
 void
 exit_horribly(const char *modulename, const char *fmt,...)
 {
        va_list         ap;
 
        va_start(ap, fmt);
-       write_msg(modulename, fmt, ap);
+       vwrite_msg(modulename, fmt, ap);
        va_end(ap);
 
        exit(1);
 }
-
-
index 62d8080585d029c1b10bf68afc5eae6d7dbfb1b4..c857f3a0980a19758c265d73c078aa031a099e9a 100644 (file)
@@ -20,6 +20,7 @@
 #include "pqexpbuffer.h"
 
 extern int     quote_all_identifiers;
+extern const char *progname;
 
 extern void init_parallel_dump_utils(void);
 extern const char *fmtId(const char *identifier);
@@ -53,6 +54,8 @@ extern void emitShSecLabels(PGconn *conn, PGresult *res,
                                PQExpBuffer buffer, const char *target, const char *objname);
 extern void write_msg(const char *modulename, const char *fmt,...)
                                __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
+extern void vwrite_msg(const char *modulename, const char *fmt, va_list ap)
+                               __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 0)));
 extern void exit_horribly(const char *modulename, const char *fmt,...)
                                __attribute__((format(PG_PRINTF_ATTRIBUTE, 2, 3)));
 
index a4824af1b8caeca95337f6c7b43de3fea655ac66..b1b4a0e175255a71aa20e9ae4d9f035a63ebcda9 100644 (file)
@@ -5,10 +5,10 @@ GETTEXT_FILES    = pg_dump.c common.c pg_backup_archiver.c pg_backup_custom.c \
                    pg_backup_db.c pg_backup_files.c pg_backup_null.c \
                    pg_backup_tar.c pg_restore.c pg_dumpall.c \
                    ../../port/exec.c
-GETTEXT_TRIGGERS = write_msg:2 die_horribly:3 exit_horribly:3 simple_prompt \
+GETTEXT_TRIGGERS = write_msg:2 die_horribly:3 exit_horribly:2 simple_prompt \
                    ExecuteSqlCommand:3 ahlog:3
 GETTEXT_FLAGS  = \
     write_msg:2:c-format \
     die_horribly:3:c-format \
-    exit_horribly:3:c-format \
+    exit_horribly:2:c-format \
     ahlog:3:c-format
index 1eb2b8b40e8363b50cf0375ca243e45ae6c800aa..66123094fe8945b18c9665af487cc8380a30c637 100644 (file)
@@ -118,7 +118,9 @@ static int  _discoverArchiveFormat(ArchiveHandle *AH);
 
 static int     RestoringToDB(ArchiveHandle *AH);
 static void dump_lo_buf(ArchiveHandle *AH);
-static void _die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt, va_list ap) __attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 0)));
+static void vdie_horribly(ArchiveHandle *AH, const char *modulename,
+                                                 const char *fmt, va_list ap)
+       __attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 0)));
 
 static void dumpTimestamp(ArchiveHandle *AH, const char *msg, time_t tim);
 static void SetOutput(ArchiveHandle *AH, char *filename, int compression);
@@ -1299,7 +1301,7 @@ ahlog(ArchiveHandle *AH, int level, const char *fmt,...)
                return;
 
        va_start(ap, fmt);
-       write_msg(NULL, fmt, ap);
+       vwrite_msg(NULL, fmt, ap);
        va_end(ap);
 }
 
@@ -1418,10 +1420,12 @@ ahwrite(const void *ptr, size_t size, size_t nmemb, ArchiveHandle *AH)
 }
 
 
+/* Report a fatal error and exit(1) */
 static void
-_die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt, va_list ap)
+vdie_horribly(ArchiveHandle *AH, const char *modulename,
+                         const char *fmt, va_list ap)
 {
-       write_msg(modulename, fmt, ap);
+       vwrite_msg(modulename, fmt, ap);
 
        if (AH)
        {
@@ -1434,14 +1438,14 @@ _die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt, va_lis
        exit(1);
 }
 
-/* Archiver use (just different arg declaration) */
+/* As above, but with variable arg list */
 void
 die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt,...)
 {
        va_list         ap;
 
        va_start(ap, fmt);
-       _die_horribly(AH, modulename, fmt, ap);
+       vdie_horribly(AH, modulename, fmt, ap);
        va_end(ap);
 }
 
@@ -1486,10 +1490,10 @@ warn_or_die_horribly(ArchiveHandle *AH,
 
        va_start(ap, fmt);
        if (AH->public.exit_on_error)
-               _die_horribly(AH, modulename, fmt, ap);
+               vdie_horribly(AH, modulename, fmt, ap);
        else
        {
-               write_msg(modulename, fmt, ap);
+               vwrite_msg(modulename, fmt, ap);
                AH->public.n_errors++;
        }
        va_end(ap);
@@ -2218,7 +2222,7 @@ ReadToc(ArchiveHandle *AH)
                                if (depIdx >= depSize)
                                {
                                        depSize *= 2;
-                                       deps = (DumpId *) realloc(deps, sizeof(DumpId) * depSize);
+                                       deps = (DumpId *) pg_realloc(deps, sizeof(DumpId) * depSize);
                                }
                                sscanf(tmp, "%d", &deps[depIdx]);
                                free(tmp);
@@ -2227,7 +2231,7 @@ ReadToc(ArchiveHandle *AH)
 
                        if (depIdx > 0)         /* We have a non-null entry */
                        {
-                               deps = (DumpId *) realloc(deps, sizeof(DumpId) * depIdx);
+                               deps = (DumpId *) pg_realloc(deps, sizeof(DumpId) * depIdx);
                                te->dependencies = deps;
                                te->nDeps = depIdx;
                        }
@@ -4062,7 +4066,7 @@ identify_locking_dependencies(TocEntry *te)
                return;
        }
 
-       te->lockDeps = realloc(lockids, nlockids * sizeof(DumpId));
+       te->lockDeps = pg_realloc(lockids, nlockids * sizeof(DumpId));
        te->nLockDeps = nlockids;
 }
 
index d1e202f50f73fada05015e231f42d838ad8ebbd8..07a4b6e50a65ea26903ec7e1261674ace1a0613f 100644 (file)
@@ -298,8 +298,6 @@ typedef struct _tocEntry
        int                     nLockDeps;              /* number of such dependencies */
 } TocEntry;
 
-/* Used everywhere */
-extern const char *progname;
 
 extern void die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt,...) __attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4)));
 extern void warn_or_die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt,...) __attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4)));
index 4833b2269ca9e0cef349ce82ab82cbffdcd8314b..76927093ac345941eb8113c378efb88dc3cf78dd 100644 (file)
@@ -61,9 +61,6 @@ static PGconn *connectDatabase(const char *dbname, const char *pghost, const cha
 static PGresult *executeQuery(PGconn *conn, const char *query);
 static void executeCommand(PGconn *conn, const char *query);
 
-char *pg_strdup(const char *string);
-void *pg_malloc(size_t size);
-
 static char pg_dump_bin[MAXPGPATH];
 static PQExpBuffer pgdumpopts;
 static bool skip_acls = false;
index ea68f5175c161495ebcd5e872332244c4a989d5c..8d6edacd7d89ca01314f32048c59b84de1052fb4 100644 (file)
@@ -39,8 +39,9 @@
  *-------------------------------------------------------------------------
  */
 
-#include "dumpmem.h"
 #include "pg_backup_archiver.h"
+
+#include "dumpmem.h"
 #include "dumputils.h"
 
 #include <ctype.h>