Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 149b1dd

Browse files
committed
Fix omission of OCLASS_TRANSFORM in object_classes[]
This was forgotten in cac7658 (and its fixup ad89a5d). 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
1 parent eb11de8 commit 149b1dd

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

src/backend/catalog/dependency.c

+9-2
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ typedef struct
126126
* This constant table maps ObjectClasses to the corresponding catalog OIDs.
127127
* See also getObjectClass().
128128
*/
129-
static const Oid object_classes[MAX_OCLASS] = {
129+
static const Oid object_classes[] = {
130130
RelationRelationId, /* OCLASS_CLASS */
131131
ProcedureRelationId, /* OCLASS_PROC */
132132
TypeRelationId, /* OCLASS_TYPE */
@@ -158,7 +158,8 @@ static const Oid object_classes[MAX_OCLASS] = {
158158
DefaultAclRelationId, /* OCLASS_DEFACL */
159159
ExtensionRelationId, /* OCLASS_EXTENSION */
160160
EventTriggerRelationId, /* OCLASS_EVENT_TRIGGER */
161-
PolicyRelationId /* OCLASS_POLICY */
161+
PolicyRelationId, /* OCLASS_POLICY */
162+
TransformRelationId /* OCLASS_TRANSFORM */
162163
};
163164

164165

@@ -2037,6 +2038,12 @@ add_object_address(ObjectClass oclass, Oid objectId, int32 subId,
20372038
{
20382039
ObjectAddress *item;
20392040

2041+
/*
2042+
* Make sure object_classes is kept up to date with the ObjectClass enum.
2043+
*/
2044+
StaticAssertStmt(lengthof(object_classes) == LAST_OCLASS + 1,
2045+
"object_classes[] must cover all ObjectClasses");
2046+
20402047
/* enlarge array if needed */
20412048
if (addrs->numrefs >= addrs->maxrefs)
20422049
{

src/backend/commands/event_trigger.c

-9
Original file line numberDiff line numberDiff line change
@@ -1168,15 +1168,6 @@ EventTriggerSupportsObjectClass(ObjectClass objclass)
11681168
case OCLASS_EXTENSION:
11691169
case OCLASS_POLICY:
11701170
return true;
1171-
1172-
case MAX_OCLASS:
1173-
1174-
/*
1175-
* This shouldn't ever happen, but we keep the case to avoid a
1176-
* compiler warning without a "default" clause in the switch.
1177-
*/
1178-
Assert(false);
1179-
break;
11801171
}
11811172

11821173
return true;

src/include/catalog/dependency.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ typedef struct ObjectAddresses ObjectAddresses;
112112

113113
/*
114114
* This enum covers all system catalogs whose OIDs can appear in
115-
* pg_depend.classId or pg_shdepend.classId.
115+
* pg_depend.classId or pg_shdepend.classId. Keep object_classes[] in sync.
116116
*/
117117
typedef enum ObjectClass
118118
{
@@ -148,10 +148,11 @@ typedef enum ObjectClass
148148
OCLASS_EXTENSION, /* pg_extension */
149149
OCLASS_EVENT_TRIGGER, /* pg_event_trigger */
150150
OCLASS_POLICY, /* pg_policy */
151-
OCLASS_TRANSFORM, /* pg_transform */
152-
MAX_OCLASS /* MUST BE LAST */
151+
OCLASS_TRANSFORM /* pg_transform */
153152
} ObjectClass;
154153

154+
#define LAST_OCLASS OCLASS_TRANSFORM
155+
155156

156157
/* in dependency.c */
157158

0 commit comments

Comments
 (0)