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

Commitaca9920

Browse files
committed
Update some more ObjectType switch statements to not have default
This allows the compiler to complain if a case has been missed. Inthese instances, the tradeoff of having to list a few unneeded casesto silence the compiler seems better than the risk of actually missingone.Discussion:https://www.postgresql.org/message-id/flat/fce5c98a-45da-19e7-dad0-21096bccd66e%40enterprisedb.com
1 parentadaf342 commitaca9920

File tree

2 files changed

+53
-12
lines changed

2 files changed

+53
-12
lines changed

‎src/backend/catalog/objectaddress.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ ObjectAddress
960960
get_object_address(ObjectTypeobjtype,Node*object,
961961
Relation*relp,LOCKMODElockmode,boolmissing_ok)
962962
{
963-
ObjectAddressaddress;
963+
ObjectAddressaddress= {InvalidOid,InvalidOid,0};
964964
ObjectAddressold_address= {InvalidOid,InvalidOid,0};
965965
Relationrelation=NULL;
966966
uint64inval_count;
@@ -991,6 +991,7 @@ get_object_address(ObjectType objtype, Node *object,
991991
&relation,lockmode,
992992
missing_ok);
993993
break;
994+
caseOBJECT_ATTRIBUTE:
994995
caseOBJECT_COLUMN:
995996
address=
996997
get_object_address_attribute(objtype,castNode(List,object),
@@ -1163,14 +1164,12 @@ get_object_address(ObjectType objtype, Node *object,
11631164
missing_ok);
11641165
address.objectSubId=0;
11651166
break;
1166-
default:
1167-
elog(ERROR,"unrecognized object type: %d", (int)objtype);
1168-
/* placate compiler, in case it thinks elog might return */
1169-
address.classId=InvalidOid;
1170-
address.objectId=InvalidOid;
1171-
address.objectSubId=0;
1167+
/* no default, to let compiler warn about missing case */
11721168
}
11731169

1170+
if (!address.classId)
1171+
elog(ERROR,"unrecognized object type: %d", (int)objtype);
1172+
11741173
/*
11751174
* If we could not find the supplied object, return without locking.
11761175
*/
@@ -2571,9 +2570,16 @@ check_object_ownership(Oid roleid, ObjectType objtype, ObjectAddress address,
25712570
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
25722571
errmsg("must be superuser")));
25732572
break;
2574-
default:
2575-
elog(ERROR,"unrecognized object type: %d",
2576-
(int)objtype);
2573+
caseOBJECT_AMOP:
2574+
caseOBJECT_AMPROC:
2575+
caseOBJECT_DEFAULT:
2576+
caseOBJECT_DEFACL:
2577+
caseOBJECT_PUBLICATION_NAMESPACE:
2578+
caseOBJECT_PUBLICATION_REL:
2579+
caseOBJECT_USER_MAPPING:
2580+
/* These are currently not supported or don't make sense here. */
2581+
elog(ERROR,"unsupported object type: %d", (int)objtype);
2582+
break;
25772583
}
25782584
}
25792585

‎src/backend/commands/dropcmds.c

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,10 +481,45 @@ does_not_exist_skipping(ObjectType objtype, Node *object)
481481
msg=gettext_noop("publication \"%s\" does not exist, skipping");
482482
name=strVal(object);
483483
break;
484-
default:
485-
elog(ERROR,"unrecognized object type: %d", (int)objtype);
484+
485+
caseOBJECT_COLUMN:
486+
caseOBJECT_DATABASE:
487+
caseOBJECT_FOREIGN_TABLE:
488+
caseOBJECT_INDEX:
489+
caseOBJECT_MATVIEW:
490+
caseOBJECT_ROLE:
491+
caseOBJECT_SEQUENCE:
492+
caseOBJECT_SUBSCRIPTION:
493+
caseOBJECT_TABLE:
494+
caseOBJECT_TABLESPACE:
495+
caseOBJECT_VIEW:
496+
/*
497+
* These are handled elsewhere, so if someone gets here the code
498+
* is probably wrong or should be revisited.
499+
*/
500+
elog(ERROR,"unsupported object type: %d", (int)objtype);
501+
break;
502+
503+
caseOBJECT_AMOP:
504+
caseOBJECT_AMPROC:
505+
caseOBJECT_ATTRIBUTE:
506+
caseOBJECT_DEFAULT:
507+
caseOBJECT_DEFACL:
508+
caseOBJECT_DOMCONSTRAINT:
509+
caseOBJECT_LARGEOBJECT:
510+
caseOBJECT_PARAMETER_ACL:
511+
caseOBJECT_PUBLICATION_NAMESPACE:
512+
caseOBJECT_PUBLICATION_REL:
513+
caseOBJECT_TABCONSTRAINT:
514+
caseOBJECT_USER_MAPPING:
515+
/* These are currently not used or needed. */
516+
elog(ERROR,"unsupported object type: %d", (int)objtype);
486517
break;
518+
519+
/* no default, to let compiler warn about missing case */
487520
}
521+
if (!msg)
522+
elog(ERROR,"unrecognized object type: %d", (int)objtype);
488523

489524
if (!args)
490525
ereport(NOTICE, (errmsg(msg,name)));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp