1
0
mirror of https://github.com/postgres/postgres.git synced 2025-04-24 10:47:04 +03:00

Suppress possibly-uninitialized-variable warnings from gcc 4.5.

It appears that gcc 4.5 can issue such warnings for whole structs, not
just scalar variables as in the past.  Refactor some pg_dump code slightly
so that the OutputContext local variables are always initialized, even
if they won't be used.  It's cheap enough to not be worth worrying about.
This commit is contained in:
Tom Lane 2011-01-22 17:56:42 -05:00
parent 116ce2f4d0
commit e2627258c3
2 changed files with 29 additions and 21 deletions

View File

@ -75,6 +75,13 @@ typedef struct _parallel_slot
#define NO_SLOT (-1) #define NO_SLOT (-1)
/* state needed to save/restore an archive's output target */
typedef struct _outputContext
{
void *OF;
int gzOut;
} OutputContext;
const char *progname; const char *progname;
static const char *modulename = gettext_noop("archiver"); static const char *modulename = gettext_noop("archiver");
@ -114,8 +121,9 @@ static void _write_msg(const char *modulename, const char *fmt, va_list ap);
static void _die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt, va_list ap); static void _die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt, va_list ap);
static void dumpTimestamp(ArchiveHandle *AH, const char *msg, time_t tim); static void dumpTimestamp(ArchiveHandle *AH, const char *msg, time_t tim);
static OutputContext SetOutput(ArchiveHandle *AH, char *filename, int compression); static void SetOutput(ArchiveHandle *AH, char *filename, int compression);
static void ResetOutput(ArchiveHandle *AH, OutputContext savedContext); static OutputContext SaveOutput(ArchiveHandle *AH);
static void RestoreOutput(ArchiveHandle *AH, OutputContext savedContext);
static int restore_toc_entry(ArchiveHandle *AH, TocEntry *te, static int restore_toc_entry(ArchiveHandle *AH, TocEntry *te,
RestoreOptions *ropt, bool is_parallel); RestoreOptions *ropt, bool is_parallel);
@ -299,8 +307,9 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
/* /*
* Setup the output file if necessary. * Setup the output file if necessary.
*/ */
sav = SaveOutput(AH);
if (ropt->filename || ropt->compression) if (ropt->filename || ropt->compression)
sav = SetOutput(AH, ropt->filename, ropt->compression); SetOutput(AH, ropt->filename, ropt->compression);
ahprintf(AH, "--\n-- PostgreSQL database dump\n--\n\n"); ahprintf(AH, "--\n-- PostgreSQL database dump\n--\n\n");
@ -420,7 +429,7 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
AH->stage = STAGE_FINALIZING; AH->stage = STAGE_FINALIZING;
if (ropt->filename || ropt->compression) if (ropt->filename || ropt->compression)
ResetOutput(AH, sav); RestoreOutput(AH, sav);
if (ropt->useDB) if (ropt->useDB)
{ {
@ -782,8 +791,9 @@ PrintTOCSummary(Archive *AHX, RestoreOptions *ropt)
OutputContext sav; OutputContext sav;
char *fmtName; char *fmtName;
sav = SaveOutput(AH);
if (ropt->filename) if (ropt->filename)
sav = SetOutput(AH, ropt->filename, 0 /* no compression */ ); SetOutput(AH, ropt->filename, 0 /* no compression */ );
ahprintf(AH, ";\n; Archive created at %s", ctime(&AH->createDate)); ahprintf(AH, ";\n; Archive created at %s", ctime(&AH->createDate));
ahprintf(AH, "; dbname: %s\n; TOC Entries: %d\n; Compression: %d\n", ahprintf(AH, "; dbname: %s\n; TOC Entries: %d\n; Compression: %d\n",
@ -839,7 +849,7 @@ PrintTOCSummary(Archive *AHX, RestoreOptions *ropt)
} }
if (ropt->filename) if (ropt->filename)
ResetOutput(AH, sav); RestoreOutput(AH, sav);
} }
/*********** /***********
@ -1117,16 +1127,11 @@ archprintf(Archive *AH, const char *fmt,...)
* Stuff below here should be 'private' to the archiver routines * Stuff below here should be 'private' to the archiver routines
*******************************/ *******************************/
static OutputContext static void
SetOutput(ArchiveHandle *AH, char *filename, int compression) SetOutput(ArchiveHandle *AH, char *filename, int compression)
{ {
OutputContext sav;
int fn; int fn;
/* Replace the AH output file handle */
sav.OF = AH->OF;
sav.gzOut = AH->gzOut;
if (filename) if (filename)
fn = -1; fn = -1;
else if (AH->FH) else if (AH->FH)
@ -1182,12 +1187,21 @@ SetOutput(ArchiveHandle *AH, char *filename, int compression)
die_horribly(AH, modulename, "could not open output file: %s\n", die_horribly(AH, modulename, "could not open output file: %s\n",
strerror(errno)); strerror(errno));
} }
}
static OutputContext
SaveOutput(ArchiveHandle *AH)
{
OutputContext sav;
sav.OF = AH->OF;
sav.gzOut = AH->gzOut;
return sav; return sav;
} }
static void static void
ResetOutput(ArchiveHandle *AH, OutputContext sav) RestoreOutput(ArchiveHandle *AH, OutputContext savedContext)
{ {
int res; int res;
@ -1200,8 +1214,8 @@ ResetOutput(ArchiveHandle *AH, OutputContext sav)
die_horribly(AH, modulename, "could not close output file: %s\n", die_horribly(AH, modulename, "could not close output file: %s\n",
strerror(errno)); strerror(errno));
AH->gzOut = sav.gzOut; AH->gzOut = savedContext.gzOut;
AH->OF = sav.OF; AH->OF = savedContext.OF;
} }

View File

@ -132,12 +132,6 @@ typedef void (*DeClonePtr) (struct _archiveHandle * AH);
typedef size_t (*CustomOutPtr) (struct _archiveHandle * AH, const void *buf, size_t len); typedef size_t (*CustomOutPtr) (struct _archiveHandle * AH, const void *buf, size_t len);
typedef struct _outputContext
{
void *OF;
int gzOut;
} OutputContext;
typedef enum typedef enum
{ {
SQL_SCAN = 0, /* normal */ SQL_SCAN = 0, /* normal */