25
25
extern const ScanKeyword FEScanKeywords [];
26
26
extern const int NumFEScanKeywords ;
27
27
28
- /* Globals exported by this file */
29
- int quote_all_identifiers = 0 ;
30
- const char * progname = NULL ;
31
-
32
- #define MAX_ON_EXIT_NICELY 20
33
-
34
- static struct
35
- {
36
- on_exit_nicely_callback function ;
37
- void * arg ;
38
- } on_exit_nicely_list [MAX_ON_EXIT_NICELY ];
39
-
40
- static int on_exit_nicely_index ;
41
- void (* on_exit_msg_func ) (const char * modulename , const char * fmt , va_list ap ) = vwrite_msg ;
42
-
43
28
#define supports_grant_options (version ) ((version) >= 70400)
44
29
45
30
static bool parseAclItem (const char * item , const char * type ,
@@ -49,68 +34,24 @@ static bool parseAclItem(const char *item, const char *type,
49
34
static char * copyAclUserName (PQExpBuffer output , char * input );
50
35
static void AddAcl (PQExpBuffer aclbuf , const char * keyword ,
51
36
const char * subname );
52
- static PQExpBuffer getThreadLocalPQExpBuffer (void );
53
-
54
- #ifdef WIN32
55
- static void shutdown_parallel_dump_utils (int code , void * unused );
56
- static bool parallel_init_done = false;
57
- static DWORD tls_index ;
58
- static DWORD mainThreadId ;
37
+ static PQExpBuffer defaultGetLocalPQExpBuffer (void );
59
38
60
- static void
61
- shutdown_parallel_dump_utils (int code , 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
- #ifdef WIN32
73
- if (!parallel_init_done )
74
- {
75
- WSADATA wsaData ;
76
- int err ;
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
+ int quote_all_identifiers = 0 ;
41
+ PQExpBuffer (* getLocalPQExpBuffer ) (void ) = defaultGetLocalPQExpBuffer ;
91
42
92
43
/*
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.
95
50
*/
96
51
static PQExpBuffer
97
- getThreadLocalPQExpBuffer (void )
52
+ defaultGetLocalPQExpBuffer (void )
98
53
{
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
- static PQExpBuffer s_id_return = NULL ;
104
- PQExpBuffer id_return ;
105
-
106
- #ifdef WIN32
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
+ static PQExpBuffer id_return = NULL ;
114
55
115
56
if (id_return ) /* first time through? */
116
57
{
@@ -121,15 +62,6 @@ getThreadLocalPQExpBuffer(void)
121
62
{
122
63
/* new buffer */
123
64
id_return = createPQExpBuffer ();
124
- #ifdef WIN32
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
-
133
65
}
134
66
135
67
return id_return ;
@@ -144,7 +76,7 @@ getThreadLocalPQExpBuffer(void)
144
76
const char *
145
77
fmtId (const char * rawid )
146
78
{
147
- PQExpBuffer id_return = getThreadLocalPQExpBuffer ();
79
+ PQExpBuffer id_return = getLocalPQExpBuffer ();
148
80
149
81
const char * cp ;
150
82
bool need_quotes = false;
@@ -238,7 +170,7 @@ fmtQualifiedId(int remoteVersion, const char *schema, const char *id)
238
170
}
239
171
appendPQExpBuffer (lcl_pqexp , "%s" , fmtId (id ));
240
172
241
- id_return = getThreadLocalPQExpBuffer ();
173
+ id_return = getLocalPQExpBuffer ();
242
174
243
175
appendPQExpBuffer (id_return , "%s" , lcl_pqexp -> data );
244
176
destroyPQExpBuffer (lcl_pqexp );
@@ -1278,118 +1210,6 @@ emitShSecLabels(PGconn *conn, PGresult *res, PQExpBuffer buffer,
1278
1210
}
1279
1211
1280
1212
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 (const char * 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
- else if (strcmp (arg , "data" ) == 0 )
1298
- * dumpSections |= DUMP_DATA ;
1299
- else if (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 (const char * modulename , const char * fmt ,...)
1321
- {
1322
- va_list ap ;
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 (const char * modulename , const char * fmt , va_list ap )
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 (const char * modulename , const char * fmt ,...)
1351
- {
1352
- va_list ap ;
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_callback function , 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 (int code )
1378
- {
1379
- int i ;
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
- #ifdef WIN32
1386
- if (parallel_init_done && GetCurrentThreadId () != mainThreadId )
1387
- ExitThread (code );
1388
- #endif
1389
-
1390
- exit (code );
1391
- }
1392
-
1393
1213
void
1394
1214
simple_string_list_append (SimpleStringList * list , const char * val )
1395
1215
{
0 commit comments