Commit 149b1dd8 authored by Alvaro Herrera's avatar Alvaro Herrera

Fix omission of OCLASS_TRANSFORM in object_classes[]

This was forgotten in cac76582 (and its fixup ad89a5d1).  Since it
seems way too easy to miss this, this commit also introduces a mechanism
to enforce that the array is consistent with the enum.

Problem reported independently by Robert Haas and Jaimin Pan.
Patches proposed by Jaimin Pan, Jim Nasby, Michael Paquier and myself,
though I didn't use any of these and instead went with a cleaner
approach suggested by Tom Lane.

Backpatch to 9.5.

Discussion:
https://www.postgresql.org/message-id/CA+Tgmoa6SgDaxW_n_7SEhwBAc=mniYga+obUj5fmw4rU9_mLvA@mail.gmail.com
https://www.postgresql.org/message-id/29788.1437411581@sss.pgh.pa.us
parent eb11de8f
......@@ -126,7 +126,7 @@ typedef struct
* This constant table maps ObjectClasses to the corresponding catalog OIDs.
* See also getObjectClass().
*/
static const Oid object_classes[MAX_OCLASS] = {
static const Oid object_classes[] = {
RelationRelationId, /* OCLASS_CLASS */
ProcedureRelationId, /* OCLASS_PROC */
TypeRelationId, /* OCLASS_TYPE */
......@@ -158,7 +158,8 @@ static const Oid object_classes[MAX_OCLASS] = {
DefaultAclRelationId, /* OCLASS_DEFACL */
ExtensionRelationId, /* OCLASS_EXTENSION */
EventTriggerRelationId, /* OCLASS_EVENT_TRIGGER */
PolicyRelationId /* OCLASS_POLICY */
PolicyRelationId, /* OCLASS_POLICY */
TransformRelationId /* OCLASS_TRANSFORM */
};
......@@ -2037,6 +2038,12 @@ add_object_address(ObjectClass oclass, Oid objectId, int32 subId,
{
ObjectAddress *item;
/*
* Make sure object_classes is kept up to date with the ObjectClass enum.
*/
StaticAssertStmt(lengthof(object_classes) == LAST_OCLASS + 1,
"object_classes[] must cover all ObjectClasses");
/* enlarge array if needed */
if (addrs->numrefs >= addrs->maxrefs)
{
......
......@@ -1168,15 +1168,6 @@ EventTriggerSupportsObjectClass(ObjectClass objclass)
case OCLASS_EXTENSION:
case OCLASS_POLICY:
return true;
case MAX_OCLASS:
/*
* This shouldn't ever happen, but we keep the case to avoid a
* compiler warning without a "default" clause in the switch.
*/
Assert(false);
break;
}
return true;
......
......@@ -112,7 +112,7 @@ typedef struct ObjectAddresses ObjectAddresses;
/*
* This enum covers all system catalogs whose OIDs can appear in
* pg_depend.classId or pg_shdepend.classId.
* pg_depend.classId or pg_shdepend.classId. Keep object_classes[] in sync.
*/
typedef enum ObjectClass
{
......@@ -148,10 +148,11 @@ typedef enum ObjectClass
OCLASS_EXTENSION, /* pg_extension */
OCLASS_EVENT_TRIGGER, /* pg_event_trigger */
OCLASS_POLICY, /* pg_policy */
OCLASS_TRANSFORM, /* pg_transform */
MAX_OCLASS /* MUST BE LAST */
OCLASS_TRANSFORM /* pg_transform */
} ObjectClass;
#define LAST_OCLASS OCLASS_TRANSFORM
/* in dependency.c */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment