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.
This commit is contained in:
parent
0bc0bd07d4
commit
375e5b0a68
@ -521,8 +521,8 @@ execute_extension_script(Oid extensionOid, ExtensionControlFile *control,
|
|||||||
const char *schemaName, Oid schemaOid)
|
const char *schemaName, Oid schemaOid)
|
||||||
{
|
{
|
||||||
char *filename = get_extension_absolute_path(control->script);
|
char *filename = get_extension_absolute_path(control->script);
|
||||||
char *save_client_min_messages = NULL,
|
char *save_client_min_messages,
|
||||||
*save_log_min_messages = NULL,
|
*save_log_min_messages,
|
||||||
*save_search_path;
|
*save_search_path;
|
||||||
StringInfoData pathbuf;
|
StringInfoData pathbuf;
|
||||||
ListCell *lc;
|
ListCell *lc;
|
||||||
@ -535,23 +535,19 @@ execute_extension_script(Oid extensionOid, ExtensionControlFile *control,
|
|||||||
* We use the equivalent of SET LOCAL to ensure the setting is undone
|
* We use the equivalent of SET LOCAL to ensure the setting is undone
|
||||||
* upon error.
|
* upon error.
|
||||||
*/
|
*/
|
||||||
|
save_client_min_messages =
|
||||||
|
pstrdup(GetConfigOption("client_min_messages", false));
|
||||||
if (client_min_messages < WARNING)
|
if (client_min_messages < WARNING)
|
||||||
{
|
|
||||||
save_client_min_messages =
|
|
||||||
pstrdup(GetConfigOption("client_min_messages", false));
|
|
||||||
(void) set_config_option("client_min_messages", "warning",
|
(void) set_config_option("client_min_messages", "warning",
|
||||||
PGC_USERSET, PGC_S_SESSION,
|
PGC_USERSET, PGC_S_SESSION,
|
||||||
GUC_ACTION_LOCAL, true);
|
GUC_ACTION_LOCAL, true);
|
||||||
}
|
|
||||||
|
|
||||||
|
save_log_min_messages =
|
||||||
|
pstrdup(GetConfigOption("log_min_messages", false));
|
||||||
if (log_min_messages < WARNING)
|
if (log_min_messages < WARNING)
|
||||||
{
|
|
||||||
save_log_min_messages =
|
|
||||||
pstrdup(GetConfigOption("log_min_messages", false));
|
|
||||||
(void) set_config_option("log_min_messages", "warning",
|
(void) set_config_option("log_min_messages", "warning",
|
||||||
PGC_SUSET, PGC_S_SESSION,
|
PGC_SUSET, PGC_S_SESSION,
|
||||||
GUC_ACTION_LOCAL, true);
|
GUC_ACTION_LOCAL, true);
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set up the search path to contain the target schema, then the schemas
|
* Set up the search path to contain the target schema, then the schemas
|
||||||
@ -631,15 +627,12 @@ execute_extension_script(Oid extensionOid, ExtensionControlFile *control,
|
|||||||
(void) set_config_option("search_path", save_search_path,
|
(void) set_config_option("search_path", save_search_path,
|
||||||
PGC_USERSET, PGC_S_SESSION,
|
PGC_USERSET, PGC_S_SESSION,
|
||||||
GUC_ACTION_LOCAL, true);
|
GUC_ACTION_LOCAL, true);
|
||||||
|
(void) set_config_option("client_min_messages", save_client_min_messages,
|
||||||
if (save_client_min_messages != NULL)
|
PGC_USERSET, PGC_S_SESSION,
|
||||||
(void) set_config_option("client_min_messages", save_client_min_messages,
|
GUC_ACTION_LOCAL, true);
|
||||||
PGC_USERSET, PGC_S_SESSION,
|
(void) set_config_option("log_min_messages", save_log_min_messages,
|
||||||
GUC_ACTION_LOCAL, true);
|
PGC_SUSET, PGC_S_SESSION,
|
||||||
if (save_log_min_messages != NULL)
|
GUC_ACTION_LOCAL, true);
|
||||||
(void) set_config_option("log_min_messages", save_log_min_messages,
|
|
||||||
PGC_SUSET, PGC_S_SESSION,
|
|
||||||
GUC_ACTION_LOCAL, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -5612,17 +5612,16 @@ static void
|
|||||||
ATExecValidateConstraint(Relation rel, const char *constrName)
|
ATExecValidateConstraint(Relation rel, const char *constrName)
|
||||||
{
|
{
|
||||||
Relation conrel;
|
Relation conrel;
|
||||||
Form_pg_constraint con;
|
|
||||||
SysScanDesc scan;
|
SysScanDesc scan;
|
||||||
ScanKeyData key;
|
ScanKeyData key;
|
||||||
HeapTuple tuple;
|
HeapTuple tuple;
|
||||||
|
Form_pg_constraint con = NULL;
|
||||||
bool found = false;
|
bool found = false;
|
||||||
Oid conid;
|
|
||||||
|
|
||||||
conrel = heap_open(ConstraintRelationId, RowExclusiveLock);
|
conrel = heap_open(ConstraintRelationId, RowExclusiveLock);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Find and the target constraint
|
* Find and check the target constraint
|
||||||
*/
|
*/
|
||||||
ScanKeyInit(&key,
|
ScanKeyInit(&key,
|
||||||
Anum_pg_constraint_conrelid,
|
Anum_pg_constraint_conrelid,
|
||||||
@ -5634,17 +5633,23 @@ ATExecValidateConstraint(Relation rel, const char *constrName)
|
|||||||
while (HeapTupleIsValid(tuple = systable_getnext(scan)))
|
while (HeapTupleIsValid(tuple = systable_getnext(scan)))
|
||||||
{
|
{
|
||||||
con = (Form_pg_constraint) GETSTRUCT(tuple);
|
con = (Form_pg_constraint) GETSTRUCT(tuple);
|
||||||
|
if (con->contype == CONSTRAINT_FOREIGN &&
|
||||||
if (strcmp(NameStr(con->conname), constrName) != 0)
|
strcmp(NameStr(con->conname), constrName) == 0)
|
||||||
continue;
|
{
|
||||||
|
found = true;
|
||||||
conid = HeapTupleGetOid(tuple);
|
break;
|
||||||
found = true;
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (found && con->contype == CONSTRAINT_FOREIGN && !con->convalidated)
|
if (!found)
|
||||||
|
ereport(ERROR,
|
||||||
|
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
||||||
|
errmsg("foreign key constraint \"%s\" of relation \"%s\" does not exist",
|
||||||
|
constrName, RelationGetRelationName(rel))));
|
||||||
|
|
||||||
|
if (!con->convalidated)
|
||||||
{
|
{
|
||||||
|
Oid conid = HeapTupleGetOid(tuple);
|
||||||
HeapTuple copyTuple = heap_copytuple(tuple);
|
HeapTuple copyTuple = heap_copytuple(tuple);
|
||||||
Form_pg_constraint copy_con = (Form_pg_constraint) GETSTRUCT(copyTuple);
|
Form_pg_constraint copy_con = (Form_pg_constraint) GETSTRUCT(copyTuple);
|
||||||
Relation refrel;
|
Relation refrel;
|
||||||
@ -5671,19 +5676,13 @@ ATExecValidateConstraint(Relation rel, const char *constrName)
|
|||||||
simple_heap_update(conrel, ©Tuple->t_self, copyTuple);
|
simple_heap_update(conrel, ©Tuple->t_self, copyTuple);
|
||||||
CatalogUpdateIndexes(conrel, copyTuple);
|
CatalogUpdateIndexes(conrel, copyTuple);
|
||||||
heap_freetuple(copyTuple);
|
heap_freetuple(copyTuple);
|
||||||
|
|
||||||
heap_close(refrel, NoLock);
|
heap_close(refrel, NoLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
systable_endscan(scan);
|
systable_endscan(scan);
|
||||||
heap_close(conrel, RowExclusiveLock);
|
|
||||||
|
|
||||||
if (!found)
|
heap_close(conrel, RowExclusiveLock);
|
||||||
{
|
|
||||||
ereport(ERROR,
|
|
||||||
(errcode(ERRCODE_UNDEFINED_OBJECT),
|
|
||||||
errmsg("foreign key constraint \"%s\" of relation \"%s\" does not exist",
|
|
||||||
constrName, RelationGetRelationName(rel))));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user