From d6ec181cf14a1d3f3d8ca9400a404b9828776ca3 Mon Sep 17 00:00:00 2001 From: Alvaro Herrera Date: Tue, 21 Jul 2015 13:20:53 +0200 Subject: [PATCH] Fix omission of OCLASS_TRANSFORM in object_classes[] This was forgotten in cac76582053e (and its fixup ad89a5d115). 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 --- src/backend/catalog/dependency.c | 11 +++++++++-- src/backend/commands/event_trigger.c | 9 --------- src/include/catalog/dependency.h | 7 ++++--- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/backend/catalog/dependency.c b/src/backend/catalog/dependency.c index c1212e9075..5d7c441739 100644 --- a/src/backend/catalog/dependency.c +++ b/src/backend/catalog/dependency.c @@ -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) { diff --git a/src/backend/commands/event_trigger.c b/src/backend/commands/event_trigger.c index bf40881037..3d1cb0b8e3 100644 --- a/src/backend/commands/event_trigger.c +++ b/src/backend/commands/event_trigger.c @@ -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; diff --git a/src/include/catalog/dependency.h b/src/include/catalog/dependency.h index 5da18c2544..aa3f3d90a1 100644 --- a/src/include/catalog/dependency.h +++ b/src/include/catalog/dependency.h @@ -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 */ -- 2.40.0