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

Commit7800a71

Browse files
committed
Move some pg_dump function around.
Move functions used only by pg_dump and pg_restore from dumputils.c to a newfile, pg_backup_utils.c. dumputils.c is linked into psql and some programsin bin/scripts, so it seems good to keep it slim. The parallel functionalityis moved to parallel.c, as is exit_horribly, because the interesting code inexit_horribly is parallel-related.This refactoring gets rid of the on_exit_msg_func function pointer. It wasproblematic, because a modern gcc version with -Wmissing-format-attributecomplained if it wasn't marked with PF_PRINTF_ATTRIBUTE, but the ancient gccversion that Tom Lane's old HP-UX box has didn't accept that attribute on afunction pointer, and gave an error. We still use a similar function pointertrick for getLocalPQBuffer() function, to use a thread-local version of thatin parallel mode on Windows, but that dodges the problem because it doesn'ttake printf-like arguments.
1 parent1cea9bb commit7800a71

19 files changed

+336
-247
lines changed

‎src/bin/pg_dump/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ include $(top_builddir)/src/Makefile.global
1919
overrideCPPFLAGS := -I$(libpq_srcdir)$(CPPFLAGS)
2020

2121
OBJS=pg_backup_archiver.o pg_backup_db.o pg_backup_custom.o\
22-
pg_backup_null.o pg_backup_tar.oparallel.o\
23-
pg_backup_directory.odumputils.o compress_io.o$(WIN32RES)
22+
pg_backup_null.o pg_backup_tar.opg_backup_directory.o\
23+
pg_backup_utils.oparallel.o compress_io.o dumputils.o$(WIN32RES)
2424

2525
KEYWRDOBJS = keywords.o kwlookup.o
2626

‎src/bin/pg_dump/common.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*-------------------------------------------------------------------------
1515
*/
1616
#include"pg_backup_archiver.h"
17+
#include"pg_backup_utils.h"
1718

1819
#include<ctype.h>
1920

‎src/bin/pg_dump/compress_io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
*/
5454

5555
#include"compress_io.h"
56-
#include"dumputils.h"
56+
#include"pg_backup_utils.h"
5757
#include"parallel.h"
5858

5959
/*----------------------

‎src/bin/pg_dump/dumputils.c

Lines changed: 14 additions & 194 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,6 @@
2525
externconstScanKeywordFEScanKeywords[];
2626
externconstintNumFEScanKeywords;
2727

28-
/* Globals exported by this file */
29-
intquote_all_identifiers=0;
30-
constchar*progname=NULL;
31-
32-
#defineMAX_ON_EXIT_NICELY20
33-
34-
staticstruct
35-
{
36-
on_exit_nicely_callbackfunction;
37-
void*arg;
38-
}on_exit_nicely_list[MAX_ON_EXIT_NICELY];
39-
40-
staticinton_exit_nicely_index;
41-
void(*on_exit_msg_func) (constchar*modulename,constchar*fmt,va_listap)=vwrite_msg;
42-
4328
#definesupports_grant_options(version) ((version) >= 70400)
4429

4530
staticboolparseAclItem(constchar*item,constchar*type,
@@ -49,68 +34,24 @@ static bool parseAclItem(const char *item, const char *type,
4934
staticchar*copyAclUserName(PQExpBufferoutput,char*input);
5035
staticvoidAddAcl(PQExpBufferaclbuf,constchar*keyword,
5136
constchar*subname);
52-
staticPQExpBuffergetThreadLocalPQExpBuffer(void);
53-
54-
#ifdefWIN32
55-
staticvoidshutdown_parallel_dump_utils(intcode,void*unused);
56-
staticboolparallel_init_done= false;
57-
staticDWORDtls_index;
58-
staticDWORDmainThreadId;
37+
staticPQExpBufferdefaultGetLocalPQExpBuffer(void);
5938

60-
staticvoid
61-
shutdown_parallel_dump_utils(intcode,void*unused)
62-
{
63-
/* Call the cleanup function only from the main thread */
64-
if (mainThreadId==GetCurrentThreadId())
65-
WSACleanup();
66-
}
67-
#endif
68-
69-
void
70-
init_parallel_dump_utils(void)
71-
{
72-
#ifdefWIN32
73-
if (!parallel_init_done)
74-
{
75-
WSADATAwsaData;
76-
interr;
77-
78-
tls_index=TlsAlloc();
79-
mainThreadId=GetCurrentThreadId();
80-
err=WSAStartup(MAKEWORD(2,2),&wsaData);
81-
if (err!=0)
82-
{
83-
fprintf(stderr,_("WSAStartup failed: %d\n"),err);
84-
exit_nicely(1);
85-
}
86-
on_exit_nicely(shutdown_parallel_dump_utils,NULL);
87-
parallel_init_done= true;
88-
}
89-
#endif
90-
}
39+
/* Globals exported by this file */
40+
intquote_all_identifiers=0;
41+
PQExpBuffer (*getLocalPQExpBuffer) (void)=defaultGetLocalPQExpBuffer;
9142

9243
/*
93-
* Non-reentrant but reduces memory leakage. (On Windows the memory leakage
94-
* will be one buffer per thread, which is at least better than one per call).
44+
* Returns a temporary PQExpBuffer, valid until the next call to the function.
45+
* This is used by fmtId and fmtQualifiedId.
46+
*
47+
* Non-reentrant and non-thread-safe but reduces memory leakage. You can
48+
* replace this with a custom version by setting the getLocalPQExpBuffer
49+
* function pointer.
9550
*/
9651
staticPQExpBuffer
97-
getThreadLocalPQExpBuffer(void)
52+
defaultGetLocalPQExpBuffer(void)
9853
{
99-
/*
100-
* The Tls code goes awry if we use a static var, so we provide for both
101-
* static and auto, and omit any use of the static var when using Tls.
102-
*/
103-
staticPQExpBuffers_id_return=NULL;
104-
PQExpBufferid_return;
105-
106-
#ifdefWIN32
107-
if (parallel_init_done)
108-
id_return= (PQExpBuffer)TlsGetValue(tls_index);/* 0 when not set */
109-
else
110-
id_return=s_id_return;
111-
#else
112-
id_return=s_id_return;
113-
#endif
54+
staticPQExpBufferid_return=NULL;
11455

11556
if (id_return)/* first time through? */
11657
{
@@ -121,15 +62,6 @@ getThreadLocalPQExpBuffer(void)
12162
{
12263
/* new buffer */
12364
id_return=createPQExpBuffer();
124-
#ifdefWIN32
125-
if (parallel_init_done)
126-
TlsSetValue(tls_index,id_return);
127-
else
128-
s_id_return=id_return;
129-
#else
130-
s_id_return=id_return;
131-
#endif
132-
13365
}
13466

13567
returnid_return;
@@ -144,7 +76,7 @@ getThreadLocalPQExpBuffer(void)
14476
constchar*
14577
fmtId(constchar*rawid)
14678
{
147-
PQExpBufferid_return=getThreadLocalPQExpBuffer();
79+
PQExpBufferid_return=getLocalPQExpBuffer();
14880

14981
constchar*cp;
15082
boolneed_quotes= false;
@@ -238,7 +170,7 @@ fmtQualifiedId(int remoteVersion, const char *schema, const char *id)
238170
}
239171
appendPQExpBuffer(lcl_pqexp,"%s",fmtId(id));
240172

241-
id_return=getThreadLocalPQExpBuffer();
173+
id_return=getLocalPQExpBuffer();
242174

243175
appendPQExpBuffer(id_return,"%s",lcl_pqexp->data);
244176
destroyPQExpBuffer(lcl_pqexp);
@@ -1278,118 +1210,6 @@ emitShSecLabels(PGconn *conn, PGresult *res, PQExpBuffer buffer,
12781210
}
12791211

12801212

1281-
/*
1282-
* Parse a --section=foo command line argument.
1283-
*
1284-
* Set or update the bitmask in *dumpSections according to arg.
1285-
* dumpSections is initialised as DUMP_UNSECTIONED by pg_dump and
1286-
* pg_restore so they can know if this has even been called.
1287-
*/
1288-
void
1289-
set_dump_section(constchar*arg,int*dumpSections)
1290-
{
1291-
/* if this is the first call, clear all the bits */
1292-
if (*dumpSections==DUMP_UNSECTIONED)
1293-
*dumpSections=0;
1294-
1295-
if (strcmp(arg,"pre-data")==0)
1296-
*dumpSections |=DUMP_PRE_DATA;
1297-
elseif (strcmp(arg,"data")==0)
1298-
*dumpSections |=DUMP_DATA;
1299-
elseif (strcmp(arg,"post-data")==0)
1300-
*dumpSections |=DUMP_POST_DATA;
1301-
else
1302-
{
1303-
fprintf(stderr,_("%s: unrecognized section name: \"%s\"\n"),
1304-
progname,arg);
1305-
fprintf(stderr,_("Try \"%s --help\" for more information.\n"),
1306-
progname);
1307-
exit_nicely(1);
1308-
}
1309-
}
1310-
1311-
1312-
/*
1313-
* Write a printf-style message to stderr.
1314-
*
1315-
* The program name is prepended, if "progname" has been set.
1316-
* Also, if modulename isn't NULL, that's included too.
1317-
* Note that we'll try to translate the modulename and the fmt string.
1318-
*/
1319-
void
1320-
write_msg(constchar*modulename,constchar*fmt,...)
1321-
{
1322-
va_listap;
1323-
1324-
va_start(ap,fmt);
1325-
vwrite_msg(modulename,fmt,ap);
1326-
va_end(ap);
1327-
}
1328-
1329-
/*
1330-
* As write_msg, but pass a va_list not variable arguments.
1331-
*/
1332-
void
1333-
vwrite_msg(constchar*modulename,constchar*fmt,va_listap)
1334-
{
1335-
if (progname)
1336-
{
1337-
if (modulename)
1338-
fprintf(stderr,"%s: [%s] ",progname,_(modulename));
1339-
else
1340-
fprintf(stderr,"%s: ",progname);
1341-
}
1342-
vfprintf(stderr,_(fmt),ap);
1343-
}
1344-
1345-
1346-
/*
1347-
* Fail and die, with a message to stderr.Parameters as for write_msg.
1348-
*/
1349-
void
1350-
exit_horribly(constchar*modulename,constchar*fmt,...)
1351-
{
1352-
va_listap;
1353-
1354-
va_start(ap,fmt);
1355-
on_exit_msg_func(modulename,fmt,ap);
1356-
va_end(ap);
1357-
1358-
exit_nicely(1);
1359-
}
1360-
1361-
/* Register a callback to be run when exit_nicely is invoked. */
1362-
void
1363-
on_exit_nicely(on_exit_nicely_callbackfunction,void*arg)
1364-
{
1365-
if (on_exit_nicely_index >=MAX_ON_EXIT_NICELY)
1366-
exit_horribly(NULL,"out of on_exit_nicely slots\n");
1367-
on_exit_nicely_list[on_exit_nicely_index].function=function;
1368-
on_exit_nicely_list[on_exit_nicely_index].arg=arg;
1369-
on_exit_nicely_index++;
1370-
}
1371-
1372-
/*
1373-
* Run accumulated on_exit_nicely callbacks in reverse order and then exit
1374-
* quietly. This needs to be thread-safe.
1375-
*/
1376-
void
1377-
exit_nicely(intcode)
1378-
{
1379-
inti;
1380-
1381-
for (i=on_exit_nicely_index-1;i >=0;i--)
1382-
(*on_exit_nicely_list[i].function) (code,
1383-
on_exit_nicely_list[i].arg);
1384-
1385-
#ifdefWIN32
1386-
if (parallel_init_done&&GetCurrentThreadId()!=mainThreadId)
1387-
ExitThread(code);
1388-
#endif
1389-
1390-
exit(code);
1391-
}
1392-
13931213
void
13941214
simple_string_list_append(SimpleStringList*list,constchar*val)
13951215
{

‎src/bin/pg_dump/dumputils.h

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,6 @@
1919
#include"libpq-fe.h"
2020
#include"pqexpbuffer.h"
2121

22-
typedefenum/* bits returned by set_dump_section */
23-
{
24-
DUMP_PRE_DATA=0x01,
25-
DUMP_DATA=0x02,
26-
DUMP_POST_DATA=0x04,
27-
DUMP_UNSECTIONED=0xff
28-
}DumpSections;
29-
3022
typedefstructSimpleStringListCell
3123
{
3224
structSimpleStringListCell*next;
@@ -40,14 +32,9 @@ typedef struct SimpleStringList
4032
}SimpleStringList;
4133

4234

43-
typedefvoid (*on_exit_nicely_callback) (intcode,void*arg);
44-
4535
externintquote_all_identifiers;
46-
externconstchar*progname;
47-
externvoid (*on_exit_msg_func) (constchar*modulename,constchar*fmt,va_listap)
48-
__attribute__((format(PG_PRINTF_ATTRIBUTE,2,0)));
36+
externPQExpBuffer (*getLocalPQExpBuffer) (void);
4937

50-
externvoidinit_parallel_dump_utils(void);
5138
externconstchar*fmtId(constchar*identifier);
5239
externconstchar*fmtQualifiedId(intremoteVersion,
5340
constchar*schema,constchar*id);
@@ -79,17 +66,6 @@ extern void buildShSecLabelQuery(PGconn *conn, const char *catalog_name,
7966
externvoidemitShSecLabels(PGconn*conn,PGresult*res,
8067
PQExpBufferbuffer,constchar*target,constchar*objname);
8168
externvoidset_dump_section(constchar*arg,int*dumpSections);
82-
externvoid
83-
write_msg(constchar*modulename,constchar*fmt,...)
84-
__attribute__((format(PG_PRINTF_ATTRIBUTE,2,3)));
85-
externvoid
86-
vwrite_msg(constchar*modulename,constchar*fmt,va_listap)
87-
__attribute__((format(PG_PRINTF_ATTRIBUTE,2,0)));
88-
externvoid
89-
exit_horribly(constchar*modulename,constchar*fmt,...)
90-
__attribute__((format(PG_PRINTF_ATTRIBUTE,2,3),noreturn));
91-
externvoidon_exit_nicely(on_exit_nicely_callbackfunction,void*arg);
92-
externvoidexit_nicely(intcode) __attribute__((noreturn));
9369

9470
externvoidsimple_string_list_append(SimpleStringList*list,constchar*val);
9571
externboolsimple_string_list_member(SimpleStringList*list,constchar*val);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp