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

Commit0195e5c

Browse files
committed
Clean up after recent pg_dump patches.
Fix entirely broken handling of va_list printing routines, update someout-of-date comments, fix some bogus inclusion orders, fix NLS declarations,fix missed realloc calls.
1 parent2ff36ab commit0195e5c

File tree

10 files changed

+62
-44
lines changed

10 files changed

+62
-44
lines changed

‎src/bin/pg_dump/common.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*-------------------------------------------------------------------------
22
*
33
* common.c
4-
*catalog routines used by pg_dump; long ago these were shared
4+
*Catalog routines used by pg_dump; long ago these were shared
55
*by another dump tool, but not anymore.
66
*
77
* Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
@@ -13,14 +13,13 @@
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
16-
#include"postgres_fe.h"
16+
#include"pg_backup_archiver.h"
1717

1818
#include<ctype.h>
1919

2020
#include"catalog/pg_class.h"
21-
22-
#include"pg_backup_archiver.h"
2321
#include"dumpmem.h"
22+
#include"dumputils.h"
2423

2524

2625
/*

‎src/bin/pg_dump/dumpmem.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
/*-------------------------------------------------------------------------
22
*
33
* dumpmem.c
4-
* memory routines used by pg_dump and pg_restore (but not pg_dumpall
5-
* because there is no failure location to report).
4+
* Memory allocation routines used by pg_dump, pg_dumpall, and pg_restore
65
*
76
* Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
87
* Portions Copyright (c) 1994, Regents of the University of California
@@ -14,16 +13,15 @@
1413
*-------------------------------------------------------------------------
1514
*/
1615
#include"postgres_fe.h"
16+
1717
#include"dumputils.h"
1818
#include"dumpmem.h"
1919

20-
#include<ctype.h>
2120

2221
/*
2322
* Safer versions of some standard C library functions. If an
24-
* out-of-memory condition occurs, these functions will bail out
25-
* safely; therefore, their return value is guaranteed to be non-NULL.
26-
* We also report the program name and close the database connection.
23+
* out-of-memory condition occurs, these functions will bail out via exit();
24+
*therefore, their return value is guaranteed to be non-NULL.
2725
*/
2826

2927
char*
@@ -57,7 +55,7 @@ pg_calloc(size_t nmemb, size_t size)
5755

5856
tmp=calloc(nmemb,size);
5957
if (!tmp)
60-
exit_horribly(NULL,_("out of memory\n"));
58+
exit_horribly(NULL,"out of memory\n");
6159
returntmp;
6260
}
6361

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

6967
tmp=realloc(ptr,size);
7068
if (!tmp)
71-
exit_horribly(NULL,_("out of memory\n"));
69+
exit_horribly(NULL,"out of memory\n");
7270
returntmp;
7371
}

‎src/bin/pg_dump/dumpmem.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*-------------------------------------------------------------------------
22
*
33
* dumpmem.h
4-
*Common header file for the pg_dump and pg_restore
4+
*Memory allocation routines used by pg_dump, pg_dumpall, and pg_restore
55
*
66
* Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
@@ -14,8 +14,6 @@
1414
#ifndefDUMPMEM_H
1515
#defineDUMPMEM_H
1616

17-
#include"postgres_fe.h"
18-
1917
externchar*pg_strdup(constchar*string);
2018
externvoid*pg_malloc(size_tsize);
2119
externvoid*pg_calloc(size_tnmemb,size_tsize);

‎src/bin/pg_dump/dumputils.c

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616

1717
#include<ctype.h>
1818

19-
#include"dumpmem.h"
2019
#include"dumputils.h"
2120

2221
#include"parser/keywords.h"
2322

2423

24+
/* Globals exported by this file */
2525
intquote_all_identifiers=0;
26-
constchar*progname;
26+
constchar*progname=NULL;
2727

2828

2929
#definesupports_grant_options(version) ((version) >= 70400)
@@ -1214,31 +1214,51 @@ emitShSecLabels(PGconn *conn, PGresult *res, PQExpBuffer buffer,
12141214
}
12151215

12161216

1217+
/*
1218+
* Write a printf-style message to stderr.
1219+
*
1220+
* The program name is prepended, if "progname" has been set.
1221+
* Also, if modulename isn't NULL, that's included too.
1222+
* Note that we'll try to translate the modulename and the fmt string.
1223+
*/
12171224
void
12181225
write_msg(constchar*modulename,constchar*fmt,...)
12191226
{
12201227
va_listap;
12211228

12221229
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);
1230+
vwrite_msg(modulename,fmt,ap);
12281231
va_end(ap);
12291232
}
12301233

1234+
/*
1235+
* As write_msg, but pass a va_list not variable arguments.
1236+
*/
1237+
void
1238+
vwrite_msg(constchar*modulename,constchar*fmt,va_listap)
1239+
{
1240+
if (progname)
1241+
{
1242+
if (modulename)
1243+
fprintf(stderr,"%s: [%s] ",progname,_(modulename));
1244+
else
1245+
fprintf(stderr,"%s: ",progname);
1246+
}
1247+
vfprintf(stderr,_(fmt),ap);
1248+
}
1249+
12311250

1251+
/*
1252+
* Fail and die, with a message to stderr. Parameters as for write_msg.
1253+
*/
12321254
void
12331255
exit_horribly(constchar*modulename,constchar*fmt,...)
12341256
{
12351257
va_listap;
12361258

12371259
va_start(ap,fmt);
1238-
write_msg(modulename,fmt,ap);
1260+
vwrite_msg(modulename,fmt,ap);
12391261
va_end(ap);
12401262

12411263
exit(1);
12421264
}
1243-
1244-

‎src/bin/pg_dump/dumputils.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include"pqexpbuffer.h"
2121

2222
externintquote_all_identifiers;
23+
externconstchar*progname;
2324

2425
externvoidinit_parallel_dump_utils(void);
2526
externconstchar*fmtId(constchar*identifier);
@@ -53,6 +54,8 @@ extern void emitShSecLabels(PGconn *conn, PGresult *res,
5354
PQExpBufferbuffer,constchar*target,constchar*objname);
5455
externvoidwrite_msg(constchar*modulename,constchar*fmt,...)
5556
__attribute__((format(PG_PRINTF_ATTRIBUTE,2,3)));
57+
externvoidvwrite_msg(constchar*modulename,constchar*fmt,va_listap)
58+
__attribute__((format(PG_PRINTF_ATTRIBUTE,2,0)));
5659
externvoidexit_horribly(constchar*modulename,constchar*fmt,...)
5760
__attribute__((format(PG_PRINTF_ATTRIBUTE,2,3)));
5861

‎src/bin/pg_dump/nls.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ GETTEXT_FILES = pg_dump.c common.c pg_backup_archiver.c pg_backup_custom.c \
55
pg_backup_db.c pg_backup_files.c pg_backup_null.c\
66
pg_backup_tar.c pg_restore.c pg_dumpall.c\
77
../../port/exec.c
8-
GETTEXT_TRIGGERS = write_msg:2 die_horribly:3 exit_horribly:3 simple_prompt\
8+
GETTEXT_TRIGGERS = write_msg:2 die_horribly:3 exit_horribly:2 simple_prompt\
99
ExecuteSqlCommand:3 ahlog:3
1010
GETTEXT_FLAGS =\
1111
write_msg:2:c-format\
1212
die_horribly:3:c-format\
13-
exit_horribly:3:c-format\
13+
exit_horribly:2:c-format\
1414
ahlog:3:c-format

‎src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ static int_discoverArchiveFormat(ArchiveHandle *AH);
118118

119119
staticintRestoringToDB(ArchiveHandle*AH);
120120
staticvoiddump_lo_buf(ArchiveHandle*AH);
121-
staticvoid_die_horribly(ArchiveHandle*AH,constchar*modulename,constchar*fmt,va_listap) __attribute__((format(PG_PRINTF_ATTRIBUTE,3,0)));
121+
staticvoidvdie_horribly(ArchiveHandle*AH,constchar*modulename,
122+
constchar*fmt,va_listap)
123+
__attribute__((format(PG_PRINTF_ATTRIBUTE,3,0)));
122124

123125
staticvoiddumpTimestamp(ArchiveHandle*AH,constchar*msg,time_ttim);
124126
staticvoidSetOutput(ArchiveHandle*AH,char*filename,intcompression);
@@ -1299,7 +1301,7 @@ ahlog(ArchiveHandle *AH, int level, const char *fmt,...)
12991301
return;
13001302

13011303
va_start(ap,fmt);
1302-
write_msg(NULL,fmt,ap);
1304+
vwrite_msg(NULL,fmt,ap);
13031305
va_end(ap);
13041306
}
13051307

@@ -1418,10 +1420,12 @@ ahwrite(const void *ptr, size_t size, size_t nmemb, ArchiveHandle *AH)
14181420
}
14191421

14201422

1423+
/* Report a fatal error and exit(1) */
14211424
staticvoid
1422-
_die_horribly(ArchiveHandle*AH,constchar*modulename,constchar*fmt,va_listap)
1425+
vdie_horribly(ArchiveHandle*AH,constchar*modulename,
1426+
constchar*fmt,va_listap)
14231427
{
1424-
write_msg(modulename,fmt,ap);
1428+
vwrite_msg(modulename,fmt,ap);
14251429

14261430
if (AH)
14271431
{
@@ -1434,14 +1438,14 @@ _die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt, va_lis
14341438
exit(1);
14351439
}
14361440

1437-
/*Archiver use (just differentargdeclaration) */
1441+
/*As above, but with variablearglist */
14381442
void
14391443
die_horribly(ArchiveHandle*AH,constchar*modulename,constchar*fmt,...)
14401444
{
14411445
va_listap;
14421446

14431447
va_start(ap,fmt);
1444-
_die_horribly(AH,modulename,fmt,ap);
1448+
vdie_horribly(AH,modulename,fmt,ap);
14451449
va_end(ap);
14461450
}
14471451

@@ -1486,10 +1490,10 @@ warn_or_die_horribly(ArchiveHandle *AH,
14861490

14871491
va_start(ap,fmt);
14881492
if (AH->public.exit_on_error)
1489-
_die_horribly(AH,modulename,fmt,ap);
1493+
vdie_horribly(AH,modulename,fmt,ap);
14901494
else
14911495
{
1492-
write_msg(modulename,fmt,ap);
1496+
vwrite_msg(modulename,fmt,ap);
14931497
AH->public.n_errors++;
14941498
}
14951499
va_end(ap);
@@ -2218,7 +2222,7 @@ ReadToc(ArchiveHandle *AH)
22182222
if (depIdx >=depSize)
22192223
{
22202224
depSize *=2;
2221-
deps= (DumpId*)realloc(deps,sizeof(DumpId)*depSize);
2225+
deps= (DumpId*)pg_realloc(deps,sizeof(DumpId)*depSize);
22222226
}
22232227
sscanf(tmp,"%d",&deps[depIdx]);
22242228
free(tmp);
@@ -2227,7 +2231,7 @@ ReadToc(ArchiveHandle *AH)
22272231

22282232
if (depIdx>0)/* We have a non-null entry */
22292233
{
2230-
deps= (DumpId*)realloc(deps,sizeof(DumpId)*depIdx);
2234+
deps= (DumpId*)pg_realloc(deps,sizeof(DumpId)*depIdx);
22312235
te->dependencies=deps;
22322236
te->nDeps=depIdx;
22332237
}
@@ -4062,7 +4066,7 @@ identify_locking_dependencies(TocEntry *te)
40624066
return;
40634067
}
40644068

4065-
te->lockDeps=realloc(lockids,nlockids*sizeof(DumpId));
4069+
te->lockDeps=pg_realloc(lockids,nlockids*sizeof(DumpId));
40664070
te->nLockDeps=nlockids;
40674071
}
40684072

‎src/bin/pg_dump/pg_backup_archiver.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,6 @@ typedef struct _tocEntry
298298
intnLockDeps;/* number of such dependencies */
299299
}TocEntry;
300300

301-
/* Used everywhere */
302-
externconstchar*progname;
303301

304302
externvoiddie_horribly(ArchiveHandle*AH,constchar*modulename,constchar*fmt,...) __attribute__((format(PG_PRINTF_ATTRIBUTE,3,4)));
305303
externvoidwarn_or_die_horribly(ArchiveHandle*AH,constchar*modulename,constchar*fmt,...) __attribute__((format(PG_PRINTF_ATTRIBUTE,3,4)));

‎src/bin/pg_dump/pg_dumpall.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@ static PGconn *connectDatabase(const char *dbname, const char *pghost, const cha
6161
staticPGresult*executeQuery(PGconn*conn,constchar*query);
6262
staticvoidexecuteCommand(PGconn*conn,constchar*query);
6363

64-
char*pg_strdup(constchar*string);
65-
void*pg_malloc(size_tsize);
66-
6764
staticcharpg_dump_bin[MAXPGPATH];
6865
staticPQExpBufferpgdumpopts;
6966
staticboolskip_acls= false;

‎src/bin/pg_dump/pg_restore.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@
3939
*-------------------------------------------------------------------------
4040
*/
4141

42-
#include"dumpmem.h"
4342
#include"pg_backup_archiver.h"
43+
44+
#include"dumpmem.h"
4445
#include"dumputils.h"
4546

4647
#include<ctype.h>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp