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

Commit8b08deb

Browse files
committed
Simplify the pg_dump/pg_restore error reporting macros, and allow
pg_dumpall to use the same memory allocation functions as the others.
1 parentb60f37b commit8b08deb

File tree

12 files changed

+54
-92
lines changed

12 files changed

+54
-92
lines changed

‎src/bin/pg_dump/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ pg_dump: pg_dump.o common.o pg_dump_sort.o $(OBJS) $(KEYWRDOBJS) | submake-libpq
3535
pg_restore: pg_restore.o$(OBJS)$(KEYWRDOBJS) | submake-libpq submake-libpgport
3636
$(CC)$(CFLAGS) pg_restore.o$(KEYWRDOBJS)$(OBJS)$(libpq_pgport)$(LDFLAGS)$(LDFLAGS_EX)$(LIBS) -o$@$(X)
3737

38-
pg_dumpall: pg_dumpall.o dumputils.o$(KEYWRDOBJS) | submake-libpq submake-libpgport
39-
$(CC)$(CFLAGS) pg_dumpall.o dumputils.o$(KEYWRDOBJS)$(WIN32RES)$(libpq_pgport)$(LDFLAGS)$(LDFLAGS_EX)$(LIBS) -o$@$(X)
38+
pg_dumpall: pg_dumpall.o dumputils.odumpmem.o$(KEYWRDOBJS) | submake-libpq submake-libpgport
39+
$(CC)$(CFLAGS) pg_dumpall.o dumputils.odumpmem.o$(KEYWRDOBJS)$(WIN32RES)$(libpq_pgport)$(LDFLAGS)$(LDFLAGS_EX)$(LIBS) -o$@$(X)
4040

4141
install: all installdirs
4242
$(INSTALL_PROGRAM) pg_dump$(X)'$(DESTDIR)$(bindir)'/pg_dump$(X)

‎src/bin/pg_dump/dumpmem.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*-------------------------------------------------------------------------
1515
*/
1616
#include"postgres_fe.h"
17-
#include"pg_backup.h"
17+
#include"dumputils.h"
1818
#include"dumpmem.h"
1919

2020
#include<ctype.h>
@@ -32,10 +32,10 @@ pg_strdup(const char *string)
3232
char*tmp;
3333

3434
if (!string)
35-
exit_horribly(NULL,NULL,"cannot duplicate null pointer\n");
35+
exit_horribly(NULL,"cannot duplicate null pointer\n");
3636
tmp=strdup(string);
3737
if (!tmp)
38-
exit_horribly(NULL,NULL,"out of memory\n");
38+
exit_horribly(NULL,"out of memory\n");
3939
returntmp;
4040
}
4141

@@ -46,7 +46,7 @@ pg_malloc(size_t size)
4646

4747
tmp=malloc(size);
4848
if (!tmp)
49-
exit_horribly(NULL,NULL,"out of memory\n");
49+
exit_horribly(NULL,"out of memory\n");
5050
returntmp;
5151
}
5252

@@ -57,7 +57,7 @@ pg_calloc(size_t nmemb, size_t size)
5757

5858
tmp=calloc(nmemb,size);
5959
if (!tmp)
60-
exit_horribly(NULL,NULL,_("out of memory\n"));
60+
exit_horribly(NULL,_("out of memory\n"));
6161
returntmp;
6262
}
6363

@@ -68,6 +68,6 @@ pg_realloc(void *ptr, size_t size)
6868

6969
tmp=realloc(ptr,size);
7070
if (!tmp)
71-
exit_horribly(NULL,NULL,_("out of memory\n"));
71+
exit_horribly(NULL,_("out of memory\n"));
7272
returntmp;
7373
}

‎src/bin/pg_dump/dumputils.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424

2525
intquote_all_identifiers=0;
26+
constchar*progname;
2627

2728

2829
#definesupports_grant_options(version) ((version) >= 70400)
@@ -1211,3 +1212,33 @@ emitShSecLabels(PGconn *conn, PGresult *res, PQExpBuffer buffer,
12111212
appendPQExpBuffer(buffer,";\n");
12121213
}
12131214
}
1215+
1216+
1217+
void
1218+
write_msg(constchar*modulename,constchar*fmt,...)
1219+
{
1220+
va_listap;
1221+
1222+
va_start(ap,fmt);
1223+
if (modulename)
1224+
fprintf(stderr,"%s: [%s] ",progname,_(modulename));
1225+
else
1226+
fprintf(stderr,"%s: ",progname);
1227+
vfprintf(stderr,_(fmt),ap);
1228+
va_end(ap);
1229+
}
1230+
1231+
1232+
void
1233+
exit_horribly(constchar*modulename,constchar*fmt,...)
1234+
{
1235+
va_listap;
1236+
1237+
va_start(ap,fmt);
1238+
write_msg(modulename,fmt,ap);
1239+
va_end(ap);
1240+
1241+
exit(1);
1242+
}
1243+
1244+

‎src/bin/pg_dump/dumputils.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,9 @@ extern void buildShSecLabelQuery(PGconn *conn, const char *catalog_name,
5151
uint32objectId,PQExpBuffersql);
5252
externvoidemitShSecLabels(PGconn*conn,PGresult*res,
5353
PQExpBufferbuffer,constchar*target,constchar*objname);
54+
externvoidwrite_msg(constchar*modulename,constchar*fmt,...)
55+
__attribute__((format(PG_PRINTF_ATTRIBUTE,2,3)));
56+
externvoidexit_horribly(constchar*modulename,constchar*fmt,...)
57+
__attribute__((format(PG_PRINTF_ATTRIBUTE,2,3)));
5458

5559
#endif/* DUMPUTILS_H */

‎src/bin/pg_dump/pg_backup.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,6 @@ typedef struct _restoreOptions
150150
* Main archiver interface.
151151
*/
152152

153-
externvoid
154-
exit_horribly(Archive*AH,constchar*modulename,constchar*fmt,...)
155-
__attribute__((format(PG_PRINTF_ATTRIBUTE,3,4)));
156-
157153

158154
/* Lets the archive know we have a DB connection to shutdown if it dies */
159155

‎src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ typedef struct _outputContext
8484
intgzOut;
8585
}OutputContext;
8686

87-
constchar*progname;
88-
8987
staticconstchar*modulename=gettext_noop("archiver");
9088

9189
/* index array created by fix_dependencies -- only used in parallel restore */
@@ -120,7 +118,6 @@ static int_discoverArchiveFormat(ArchiveHandle *AH);
120118

121119
staticintRestoringToDB(ArchiveHandle*AH);
122120
staticvoiddump_lo_buf(ArchiveHandle*AH);
123-
staticvoid_write_msg(constchar*modulename,constchar*fmt,va_listap) __attribute__((format(PG_PRINTF_ATTRIBUTE,2,0)));
124121
staticvoid_die_horribly(ArchiveHandle*AH,constchar*modulename,constchar*fmt,va_listap) __attribute__((format(PG_PRINTF_ATTRIBUTE,3,0)));
125122

126123
staticvoiddumpTimestamp(ArchiveHandle*AH,constchar*msg,time_ttim);
@@ -1302,7 +1299,7 @@ ahlog(ArchiveHandle *AH, int level, const char *fmt,...)
13021299
return;
13031300

13041301
va_start(ap,fmt);
1305-
_write_msg(NULL,fmt,ap);
1302+
write_msg(NULL,fmt,ap);
13061303
va_end(ap);
13071304
}
13081305

@@ -1420,32 +1417,11 @@ ahwrite(const void *ptr, size_t size, size_t nmemb, ArchiveHandle *AH)
14201417
}
14211418
}
14221419

1423-
/* Common exit code */
1424-
staticvoid
1425-
_write_msg(constchar*modulename,constchar*fmt,va_listap)
1426-
{
1427-
if (modulename)
1428-
fprintf(stderr,"%s: [%s] ",progname,_(modulename));
1429-
else
1430-
fprintf(stderr,"%s: ",progname);
1431-
vfprintf(stderr,_(fmt),ap);
1432-
}
1433-
1434-
void
1435-
write_msg(constchar*modulename,constchar*fmt,...)
1436-
{
1437-
va_listap;
1438-
1439-
va_start(ap,fmt);
1440-
_write_msg(modulename,fmt,ap);
1441-
va_end(ap);
1442-
}
1443-
14441420

14451421
staticvoid
14461422
_die_horribly(ArchiveHandle*AH,constchar*modulename,constchar*fmt,va_listap)
14471423
{
1448-
_write_msg(modulename,fmt,ap);
1424+
write_msg(modulename,fmt,ap);
14491425

14501426
if (AH)
14511427
{
@@ -1458,17 +1434,6 @@ _die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt, va_lis
14581434
exit(1);
14591435
}
14601436

1461-
/* External use */
1462-
void
1463-
exit_horribly(Archive*AH,constchar*modulename,constchar*fmt,...)
1464-
{
1465-
va_listap;
1466-
1467-
va_start(ap,fmt);
1468-
_die_horribly((ArchiveHandle*)AH,modulename,fmt,ap);
1469-
va_end(ap);
1470-
}
1471-
14721437
/* Archiver use (just different arg declaration) */
14731438
void
14741439
die_horribly(ArchiveHandle*AH,constchar*modulename,constchar*fmt,...)
@@ -1524,7 +1489,7 @@ warn_or_die_horribly(ArchiveHandle *AH,
15241489
_die_horribly(AH,modulename,fmt,ap);
15251490
else
15261491
{
1527-
_write_msg(modulename,fmt,ap);
1492+
write_msg(modulename,fmt,ap);
15281493
AH->public.n_errors++;
15291494
}
15301495
va_end(ap);

‎src/bin/pg_dump/pg_backup_archiver.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,6 @@ extern const char *progname;
303303

304304
externvoiddie_horribly(ArchiveHandle*AH,constchar*modulename,constchar*fmt,...) __attribute__((format(PG_PRINTF_ATTRIBUTE,3,4)));
305305
externvoidwarn_or_die_horribly(ArchiveHandle*AH,constchar*modulename,constchar*fmt,...) __attribute__((format(PG_PRINTF_ATTRIBUTE,3,4)));
306-
externvoidwrite_msg(constchar*modulename,constchar*fmt,...) __attribute__((format(PG_PRINTF_ATTRIBUTE,2,3)));
307306

308307
externvoidWriteTOC(ArchiveHandle*AH);
309308
externvoidReadTOC(ArchiveHandle*AH);

‎src/bin/pg_dump/pg_backup_custom.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
*/
2626

2727
#include"compress_io.h"
28+
#include"dumputils.h"
2829
#include"dumpmem.h"
2930

3031
/*--------

‎src/bin/pg_dump/pg_backup_files.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
*/
2727

2828
#include"pg_backup_archiver.h"
29+
#include"dumputils.h"
2930
#include"dumpmem.h"
3031

3132
staticvoid_ArchiveEntry(ArchiveHandle*AH,TocEntry*te);

‎src/bin/pg_dump/pg_dump_sort.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*-------------------------------------------------------------------------
1515
*/
1616
#include"pg_backup_archiver.h"
17+
#include"dumputils.h"
1718
#include"dumpmem.h"
1819

1920
staticconstchar*modulename=gettext_noop("sorter");
@@ -315,13 +316,13 @@ TopoSort(DumpableObject **objs,
315316
obj=objs[i];
316317
j=obj->dumpId;
317318
if (j <=0||j>maxDumpId)
318-
exit_horribly(NULL,modulename,"invalid dumpId %d\n",j);
319+
exit_horribly(modulename,"invalid dumpId %d\n",j);
319320
idMap[j]=i;
320321
for (j=0;j<obj->nDeps;j++)
321322
{
322323
k=obj->dependencies[j];
323324
if (k <=0||k>maxDumpId)
324-
exit_horribly(NULL,modulename,"invalid dependency %d\n",k);
325+
exit_horribly(modulename,"invalid dependency %d\n",k);
325326
beforeConstraints[k]++;
326327
}
327328
}
@@ -541,7 +542,7 @@ findDependencyLoops(DumpableObject **objs, int nObjs, int totObjs)
541542

542543
/* We'd better have fixed at least one loop */
543544
if (!fixedloop)
544-
exit_horribly(NULL,modulename,"could not identify dependency loop\n");
545+
exit_horribly(modulename,"could not identify dependency loop\n");
545546

546547
free(workspace);
547548
}

‎src/bin/pg_dump/pg_dumpall.c

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include"getopt_long.h"
2424

2525
#include"dumputils.h"
26+
#include"dumpmem.h"
2627
#include"pg_backup.h"
2728

2829
/* version string we expect back from pg_dump */
@@ -1908,41 +1909,3 @@ doShellQuoting(PQExpBuffer buf, const char *str)
19081909
appendPQExpBufferChar(buf,'"');
19091910
#endif/* WIN32 */
19101911
}
1911-
1912-
1913-
/*
1914-
*Simpler versions of common.c functions.
1915-
*/
1916-
1917-
char*
1918-
pg_strdup(constchar*string)
1919-
{
1920-
char*tmp;
1921-
1922-
if (!string)
1923-
{
1924-
fprintf(stderr,"cannot duplicate null pointer\n");
1925-
exit(1);
1926-
}
1927-
tmp=strdup(string);
1928-
if (!tmp)
1929-
{
1930-
fprintf(stderr,_("%s: out of memory\n"),progname);
1931-
exit(1);
1932-
}
1933-
returntmp;
1934-
}
1935-
1936-
void*
1937-
pg_malloc(size_tsize)
1938-
{
1939-
void*tmp;
1940-
1941-
tmp=malloc(size);
1942-
if (!tmp)
1943-
{
1944-
fprintf(stderr,_("%s: out of memory\n"),progname);
1945-
exit(1);
1946-
}
1947-
returntmp;
1948-
}

‎src/tools/msvc/Mkvcbuild.pm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ sub mkvcbuild
355355
$pgdumpall->AddIncludeDir('src\backend');
356356
$pgdumpall->AddFile('src\bin\pg_dump\pg_dumpall.c');
357357
$pgdumpall->AddFile('src\bin\pg_dump\dumputils.c');
358+
$pgdumpall->AddFile('src\bin\pg_dump\dumpmem.c');
358359
$pgdumpall->AddFile('src\bin\pg_dump\keywords.c');
359360
$pgdumpall->AddFile('src\backend\parser\kwlookup.c');
360361

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp