Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c079673

Browse files
committed
Preventive maintenance in advance of pgindent run.
Reformat various places in which pgindent will make a mess, and fix a few small violations of coding style that I happened to notice while perusing the diffs from a pgindent dry run. There is one actual bug fix here: the need-to-enlarge-the-buffer code path in icu_convert_case was obviously broken. Perhaps it's unreachable in our usage? Or maybe this is just sadly undertested.
1 parent ddd2435 commit c079673

File tree

20 files changed

+105
-79
lines changed

20 files changed

+105
-79
lines changed

contrib/btree_gist/btree_utils_num.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,11 @@ gbt_num_union(GBT_NUMKEY *out, const GistEntryVector *entryvec, const gbtree_nin
183183
cur = (GBT_NUMKEY *) DatumGetPointer((entryvec->vector[i].key));
184184
c.lower = &cur[0];
185185
c.upper = &cur[tinfo->size];
186-
if ((*tinfo->f_gt) (o.lower, c.lower, flinfo)) /* out->lower > cur->lower */
186+
/* if out->lower > cur->lower, adopt cur as lower */
187+
if ((*tinfo->f_gt) (o.lower, c.lower, flinfo))
187188
memcpy((void *) o.lower, (void *) c.lower, tinfo->size);
188-
if ((*tinfo->f_lt) (o.upper, c.upper, flinfo)) /* out->upper < cur->upper */
189+
/* if out->upper < cur->upper, adopt cur as upper */
190+
if ((*tinfo->f_lt) (o.upper, c.upper, flinfo))
189191
memcpy((void *) o.upper, (void *) c.upper, tinfo->size);
190192
}
191193

@@ -274,7 +276,8 @@ gbt_num_consistent(const GBT_NUMKEY_R *key,
274276
if (is_leaf)
275277
retval = (*tinfo->f_eq) (query, key->lower, flinfo);
276278
else
277-
retval = ((*tinfo->f_le) (key->lower, query, flinfo) && (*tinfo->f_le) (query, key->upper, flinfo)) ? true : false;
279+
retval = ((*tinfo->f_le) (key->lower, query, flinfo) &&
280+
(*tinfo->f_le) (query, key->upper, flinfo));
278281
break;
279282
case BTGreaterStrategyNumber:
280283
if (is_leaf)
@@ -287,7 +290,7 @@ gbt_num_consistent(const GBT_NUMKEY_R *key,
287290
break;
288291
case BtreeGistNotEqualStrategyNumber:
289292
retval = (!((*tinfo->f_eq) (query, key->lower, flinfo) &&
290-
(*tinfo->f_eq) (query, key->upper, flinfo))) ? true : false;
293+
(*tinfo->f_eq) (query, key->upper, flinfo)));
291294
break;
292295
default:
293296
retval = false;

src/backend/catalog/pg_publication.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,19 +90,18 @@ check_publication_add_relation(Relation targetrel)
9090
*
9191
* Does same checks as the above, but does not need relation to be opened
9292
* and also does not throw errors.
93+
*
94+
* Note this also excludes all tables with relid < FirstNormalObjectId,
95+
* ie all tables created during initdb. This mainly affects the preinstalled
96+
* information_schema. (IsCatalogClass() only checks for these inside
97+
* pg_catalog and toast schemas.)
9398
*/
9499
static bool
95100
is_publishable_class(Oid relid, Form_pg_class reltuple)
96101
{
97102
return reltuple->relkind == RELKIND_RELATION &&
98103
!IsCatalogClass(relid, reltuple) &&
99104
reltuple->relpersistence == RELPERSISTENCE_PERMANENT &&
100-
/*
101-
* Also exclude any tables created as part of initdb. This mainly
102-
* affects the preinstalled information_schema.
103-
* Note that IsCatalogClass() only checks for these inside pg_catalog
104-
* and toast schemas.
105-
*/
106105
relid >= FirstNormalObjectId;
107106
}
108107

src/backend/commands/publicationcmds.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,8 +493,10 @@ OpenTableList(List *tables)
493493

494494
rel = heap_openrv(rv, ShareUpdateExclusiveLock);
495495
myrelid = RelationGetRelid(rel);
496+
496497
/*
497-
* filter out duplicates when user specifies "foo, foo"
498+
* Filter out duplicates if user specifies "foo, foo".
499+
*
498500
* Note that this algorithm is known to not be very efficient (O(N^2))
499501
* but given that it only works on list of tables given to us by user
500502
* it's deemed acceptable.

src/backend/commands/subscriptioncmds.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ CreateSubscription(CreateSubscriptionStmt *stmt, bool isTopLevel)
296296

297297
/*
298298
* Parse and check options.
299+
*
299300
* Connection and publication should not be specified here.
300301
*/
301302
parse_subscription_options(stmt->options, &connect, &enabled_given,

src/backend/executor/nodeNamedtuplestorescan.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ ExecInitNamedTuplestoreScan(NamedTuplestoreScan *node, EState *estate, int eflag
117117

118118
/*
119119
* XXX: Should we add a function to free that read pointer when done?
120+
*
120121
* This was attempted, but it did not improve performance or memory usage
121122
* in any tested cases.
122123
*/

src/backend/replication/logical/snapbuild.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ struct SnapBuild
176176
*/
177177
TransactionId initial_xmin_horizon;
178178

179-
/* Indicates if we are building full snapshot or just catalog one .*/
179+
/* Indicates if we are building full snapshot or just catalog one. */
180180
bool building_full_snapshot;
181181

182182
/*

src/backend/replication/pgoutput/pgoutput.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,15 @@ pgoutput_begin_txn(LogicalDecodingContext *ctx, ReorderBufferTXN *txn)
221221
OutputPluginWrite(ctx, false);
222222
OutputPluginPrepareWrite(ctx, true);
223223

224-
/*
225-
* XXX: which behaviour we want here?
224+
/*----------
225+
* XXX: which behaviour do we want here?
226226
*
227227
* Alternatives:
228228
* - don't send origin message if origin name not found
229229
* (that's what we do now)
230230
* - throw error - that will break replication, not good
231231
* - send some special "unknown" origin
232+
*----------
232233
*/
233234
if (replorigin_by_oid(txn->origin_id, true, &origin))
234235
logicalrep_write_origin(ctx->out, origin, txn->origin_lsn);

src/backend/tsearch/wparser.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ ts_parse_byname(PG_FUNCTION_ARGS)
303303
Datum
304304
ts_headline_byid_opt(PG_FUNCTION_ARGS)
305305
{
306+
Oid tsconfig = PG_GETARG_OID(0);
306307
text *in = PG_GETARG_TEXT_PP(1);
307308
TSQuery query = PG_GETARG_TSQUERY(2);
308309
text *opt = (PG_NARGS() > 3 && PG_GETARG_POINTER(3)) ? PG_GETARG_TEXT_PP(3) : NULL;
@@ -312,7 +313,7 @@ ts_headline_byid_opt(PG_FUNCTION_ARGS)
312313
TSConfigCacheEntry *cfg;
313314
TSParserCacheEntry *prsobj;
314315

315-
cfg = lookup_ts_config_cache(PG_GETARG_OID(0));
316+
cfg = lookup_ts_config_cache(tsconfig);
316317
prsobj = lookup_ts_parser_cache(cfg->prsId);
317318

318319
if (!OidIsValid(prsobj->headlineOid))
@@ -381,11 +382,12 @@ ts_headline_opt(PG_FUNCTION_ARGS)
381382
Datum
382383
ts_headline_jsonb_byid_opt(PG_FUNCTION_ARGS)
383384
{
384-
Jsonb *out, *jb = PG_GETARG_JSONB(1);
385+
Oid tsconfig = PG_GETARG_OID(0);
386+
Jsonb *jb = PG_GETARG_JSONB(1);
385387
TSQuery query = PG_GETARG_TSQUERY(2);
386388
text *opt = (PG_NARGS() > 3 && PG_GETARG_POINTER(3)) ? PG_GETARG_TEXT_P(3) : NULL;
389+
Jsonb *out;
387390
JsonTransformStringValuesAction action = (JsonTransformStringValuesAction) headline_json_value;
388-
389391
HeadlineParsedText prs;
390392
HeadlineJsonState *state = palloc0(sizeof(HeadlineJsonState));
391393

@@ -394,7 +396,7 @@ ts_headline_jsonb_byid_opt(PG_FUNCTION_ARGS)
394396
prs.words = (HeadlineWordEntry *) palloc(sizeof(HeadlineWordEntry) * prs.lenwords);
395397

396398
state->prs = &prs;
397-
state->cfg = lookup_ts_config_cache(PG_GETARG_OID(0));
399+
state->cfg = lookup_ts_config_cache(tsconfig);
398400
state->prsobj = lookup_ts_parser_cache(state->cfg->prsId);
399401
state->query = query;
400402
if (opt)
@@ -456,6 +458,7 @@ ts_headline_jsonb_opt(PG_FUNCTION_ARGS)
456458
Datum
457459
ts_headline_json_byid_opt(PG_FUNCTION_ARGS)
458460
{
461+
Oid tsconfig = PG_GETARG_OID(0);
459462
text *json = PG_GETARG_TEXT_P(1);
460463
TSQuery query = PG_GETARG_TSQUERY(2);
461464
text *opt = (PG_NARGS() > 3 && PG_GETARG_POINTER(3)) ? PG_GETARG_TEXT_P(3) : NULL;
@@ -470,7 +473,7 @@ ts_headline_json_byid_opt(PG_FUNCTION_ARGS)
470473
prs.words = (HeadlineWordEntry *) palloc(sizeof(HeadlineWordEntry) * prs.lenwords);
471474

472475
state->prs = &prs;
473-
state->cfg = lookup_ts_config_cache(PG_GETARG_OID(0));
476+
state->cfg = lookup_ts_config_cache(tsconfig);
474477
state->prsobj = lookup_ts_parser_cache(state->cfg->prsId);
475478
state->query = query;
476479
if (opt)

src/backend/utils/adt/formatting.c

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,24 +1448,32 @@ str_numth(char *dest, char *num, int type)
14481448
*****************************************************************************/
14491449

14501450
#ifdef USE_ICU
1451+
1452+
typedef int32_t (*ICU_Convert_Func)(UChar *dest, int32_t destCapacity,
1453+
const UChar *src, int32_t srcLength,
1454+
const char *locale,
1455+
UErrorCode *pErrorCode);
1456+
14511457
static int32_t
1452-
icu_convert_case(int32_t (*func)(UChar *, int32_t, const UChar *, int32_t, const char *, UErrorCode *),
1453-
pg_locale_t mylocale, UChar **buff_dest, UChar *buff_source, int32_t len_source)
1458+
icu_convert_case(ICU_Convert_Func func, pg_locale_t mylocale,
1459+
UChar **buff_dest, UChar *buff_source, int32_t len_source)
14541460
{
14551461
UErrorCode status;
14561462
int32_t len_dest;
14571463

14581464
len_dest = len_source; /* try first with same length */
14591465
*buff_dest = palloc(len_dest * sizeof(**buff_dest));
14601466
status = U_ZERO_ERROR;
1461-
len_dest = func(*buff_dest, len_dest, buff_source, len_source, mylocale->info.icu.locale, &status);
1467+
len_dest = func(*buff_dest, len_dest, buff_source, len_source,
1468+
mylocale->info.icu.locale, &status);
14621469
if (status == U_BUFFER_OVERFLOW_ERROR)
14631470
{
14641471
/* try again with adjusted length */
1465-
pfree(buff_dest);
1466-
buff_dest = palloc(len_dest * sizeof(**buff_dest));
1472+
pfree(*buff_dest);
1473+
*buff_dest = palloc(len_dest * sizeof(**buff_dest));
14671474
status = U_ZERO_ERROR;
1468-
len_dest = func(*buff_dest, len_dest, buff_source, len_source, mylocale->info.icu.locale, &status);
1475+
len_dest = func(*buff_dest, len_dest, buff_source, len_source,
1476+
mylocale->info.icu.locale, &status);
14691477
}
14701478
if (U_FAILURE(status))
14711479
ereport(ERROR,
@@ -1479,9 +1487,11 @@ u_strToTitle_default_BI(UChar *dest, int32_t destCapacity,
14791487
const char *locale,
14801488
UErrorCode *pErrorCode)
14811489
{
1482-
return u_strToTitle(dest, destCapacity, src, srcLength, NULL, locale, pErrorCode);
1490+
return u_strToTitle(dest, destCapacity, src, srcLength,
1491+
NULL, locale, pErrorCode);
14831492
}
1484-
#endif
1493+
1494+
#endif /* USE_ICU */
14851495

14861496
/*
14871497
* If the system provides the needed functions for wide-character manipulation
@@ -1548,7 +1558,8 @@ str_tolower(const char *buff, size_t nbytes, Oid collid)
15481558
UChar *buff_conv;
15491559

15501560
len_uchar = icu_to_uchar(&buff_uchar, buff, nbytes);
1551-
len_conv = icu_convert_case(u_strToLower, mylocale, &buff_conv, buff_uchar, len_uchar);
1561+
len_conv = icu_convert_case(u_strToLower, mylocale,
1562+
&buff_conv, buff_uchar, len_uchar);
15521563
icu_from_uchar(&result, buff_conv, len_conv);
15531564
}
15541565
else
@@ -1666,7 +1677,8 @@ str_toupper(const char *buff, size_t nbytes, Oid collid)
16661677
UChar *buff_conv;
16671678

16681679
len_uchar = icu_to_uchar(&buff_uchar, buff, nbytes);
1669-
len_conv = icu_convert_case(u_strToUpper, mylocale, &buff_conv, buff_uchar, len_uchar);
1680+
len_conv = icu_convert_case(u_strToUpper, mylocale,
1681+
&buff_conv, buff_uchar, len_uchar);
16701682
icu_from_uchar(&result, buff_conv, len_conv);
16711683
}
16721684
else
@@ -1785,7 +1797,8 @@ str_initcap(const char *buff, size_t nbytes, Oid collid)
17851797
UChar *buff_conv;
17861798

17871799
len_uchar = icu_to_uchar(&buff_uchar, buff, nbytes);
1788-
len_conv = icu_convert_case(u_strToTitle_default_BI, mylocale, &buff_conv, buff_uchar, len_uchar);
1800+
len_conv = icu_convert_case(u_strToTitle_default_BI, mylocale,
1801+
&buff_conv, buff_uchar, len_uchar);
17891802
icu_from_uchar(&result, buff_conv, len_conv);
17901803
}
17911804
else

src/backend/utils/adt/pg_locale.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,12 +1381,14 @@ pg_newlocale_from_collation(Oid collid)
13811381

13821382
actual_versionstr = get_collation_actual_version(collform->collprovider, collcollate);
13831383
if (!actual_versionstr)
1384+
{
13841385
/* This could happen when specifying a version in CREATE
13851386
* COLLATION for a libc locale, or manually creating a mess
13861387
* in the catalogs. */
13871388
ereport(ERROR,
13881389
(errmsg("collation \"%s\" has no actual version, but a version was specified",
13891390
NameStr(collform->collname))));
1391+
}
13901392
collversionstr = TextDatumGetCString(collversion);
13911393

13921394
if (strcmp(actual_versionstr, collversionstr) != 0)

0 commit comments

Comments
 (0)