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

Skip to content

Commit 375e5b0

Browse files
committed
Suppress some compiler warnings in recent commits.
Older versions of gcc tend to throw "variable might be clobbered by `longjmp' or `vfork'" warnings whenever a variable is assigned in more than one place and then used after the end of a PG_TRY block. That's reasonably easy to work around in execute_extension_script, and the overhead of unconditionally saving/restoring the GUC variables seems unlikely to be a serious concern. Also clean up logic in ATExecValidateConstraint to make it easier to read and less likely to provoke "variable might be used uninitialized in this function" warnings.
1 parent 0bc0bd0 commit 375e5b0

File tree

2 files changed

+30
-38
lines changed

2 files changed

+30
-38
lines changed

src/backend/commands/extension.c

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -521,8 +521,8 @@ execute_extension_script(Oid extensionOid, ExtensionControlFile *control,
521521
const char *schemaName, Oid schemaOid)
522522
{
523523
char *filename = get_extension_absolute_path(control->script);
524-
char *save_client_min_messages = NULL,
525-
*save_log_min_messages = NULL,
524+
char *save_client_min_messages,
525+
*save_log_min_messages,
526526
*save_search_path;
527527
StringInfoData pathbuf;
528528
ListCell *lc;
@@ -535,23 +535,19 @@ execute_extension_script(Oid extensionOid, ExtensionControlFile *control,
535535
* We use the equivalent of SET LOCAL to ensure the setting is undone
536536
* upon error.
537537
*/
538+
save_client_min_messages =
539+
pstrdup(GetConfigOption("client_min_messages", false));
538540
if (client_min_messages < WARNING)
539-
{
540-
save_client_min_messages =
541-
pstrdup(GetConfigOption("client_min_messages", false));
542541
(void) set_config_option("client_min_messages", "warning",
543542
PGC_USERSET, PGC_S_SESSION,
544543
GUC_ACTION_LOCAL, true);
545-
}
546544

545+
save_log_min_messages =
546+
pstrdup(GetConfigOption("log_min_messages", false));
547547
if (log_min_messages < WARNING)
548-
{
549-
save_log_min_messages =
550-
pstrdup(GetConfigOption("log_min_messages", false));
551548
(void) set_config_option("log_min_messages", "warning",
552549
PGC_SUSET, PGC_S_SESSION,
553550
GUC_ACTION_LOCAL, true);
554-
}
555551

556552
/*
557553
* Set up the search path to contain the target schema, then the schemas
@@ -631,15 +627,12 @@ execute_extension_script(Oid extensionOid, ExtensionControlFile *control,
631627
(void) set_config_option("search_path", save_search_path,
632628
PGC_USERSET, PGC_S_SESSION,
633629
GUC_ACTION_LOCAL, true);
634-
635-
if (save_client_min_messages != NULL)
636-
(void) set_config_option("client_min_messages", save_client_min_messages,
637-
PGC_USERSET, PGC_S_SESSION,
638-
GUC_ACTION_LOCAL, true);
639-
if (save_log_min_messages != NULL)
640-
(void) set_config_option("log_min_messages", save_log_min_messages,
641-
PGC_SUSET, PGC_S_SESSION,
642-
GUC_ACTION_LOCAL, true);
630+
(void) set_config_option("client_min_messages", save_client_min_messages,
631+
PGC_USERSET, PGC_S_SESSION,
632+
GUC_ACTION_LOCAL, true);
633+
(void) set_config_option("log_min_messages", save_log_min_messages,
634+
PGC_SUSET, PGC_S_SESSION,
635+
GUC_ACTION_LOCAL, true);
643636
}
644637

645638
/*

src/backend/commands/tablecmds.c

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5612,17 +5612,16 @@ static void
56125612
ATExecValidateConstraint(Relation rel, const char *constrName)
56135613
{
56145614
Relation conrel;
5615-
Form_pg_constraint con;
56165615
SysScanDesc scan;
56175616
ScanKeyData key;
56185617
HeapTuple tuple;
5618+
Form_pg_constraint con = NULL;
56195619
bool found = false;
5620-
Oid conid;
56215620

56225621
conrel = heap_open(ConstraintRelationId, RowExclusiveLock);
56235622

56245623
/*
5625-
* Find and the target constraint
5624+
* Find and check the target constraint
56265625
*/
56275626
ScanKeyInit(&key,
56285627
Anum_pg_constraint_conrelid,
@@ -5634,17 +5633,23 @@ ATExecValidateConstraint(Relation rel, const char *constrName)
56345633
while (HeapTupleIsValid(tuple = systable_getnext(scan)))
56355634
{
56365635
con = (Form_pg_constraint) GETSTRUCT(tuple);
5637-
5638-
if (strcmp(NameStr(con->conname), constrName) != 0)
5639-
continue;
5640-
5641-
conid = HeapTupleGetOid(tuple);
5642-
found = true;
5643-
break;
5636+
if (con->contype == CONSTRAINT_FOREIGN &&
5637+
strcmp(NameStr(con->conname), constrName) == 0)
5638+
{
5639+
found = true;
5640+
break;
5641+
}
56445642
}
56455643

5646-
if (found && con->contype == CONSTRAINT_FOREIGN && !con->convalidated)
5644+
if (!found)
5645+
ereport(ERROR,
5646+
(errcode(ERRCODE_UNDEFINED_OBJECT),
5647+
errmsg("foreign key constraint \"%s\" of relation \"%s\" does not exist",
5648+
constrName, RelationGetRelationName(rel))));
5649+
5650+
if (!con->convalidated)
56475651
{
5652+
Oid conid = HeapTupleGetOid(tuple);
56485653
HeapTuple copyTuple = heap_copytuple(tuple);
56495654
Form_pg_constraint copy_con = (Form_pg_constraint) GETSTRUCT(copyTuple);
56505655
Relation refrel;
@@ -5671,19 +5676,13 @@ ATExecValidateConstraint(Relation rel, const char *constrName)
56715676
simple_heap_update(conrel, &copyTuple->t_self, copyTuple);
56725677
CatalogUpdateIndexes(conrel, copyTuple);
56735678
heap_freetuple(copyTuple);
5679+
56745680
heap_close(refrel, NoLock);
56755681
}
56765682

56775683
systable_endscan(scan);
5678-
heap_close(conrel, RowExclusiveLock);
56795684

5680-
if (!found)
5681-
{
5682-
ereport(ERROR,
5683-
(errcode(ERRCODE_UNDEFINED_OBJECT),
5684-
errmsg("foreign key constraint \"%s\" of relation \"%s\" does not exist",
5685-
constrName, RelationGetRelationName(rel))));
5686-
}
5685+
heap_close(conrel, RowExclusiveLock);
56875686
}
56885687

56895688
/*

0 commit comments

Comments
 (0)