pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alvaro Herrera <alvherre@2ndquadrant.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Robert Haas <robertmhaas@gmail.com>
Cc: Jim Nasby <Jim.Nasby@BlueTreble.com>
Cc: Jaimin Pan <jaimin.pan@gmail.com>
Cc: Michael Paquier <michael.paquier@gmail.com>
Cc: pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>
Cc: pgsql-bugs@postgresql.org
Subject: Re: [BUGS] object_classes array is broken, again
Date: Mon, 20 Jul 2015 18:33:15 +0200
Message-ID: <20150720163315.GS2301@postgresql.org> (raw)
In-Reply-To: <13760.1437400153@sss.pgh.pa.us>
References: <20150720101431.GJ2301@postgresql.org>
	<13760.1437400153@sss.pgh.pa.us>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>

Tom Lane wrote:
> Alvaro Herrera <alvherre@2ndquadrant.com> writes:
> > Any opinions on this idea?  I don't like it all that much, but it's
> > plenty effective.
> 
> I don't like it much either.
> 
> What about adding StaticAsserts that lengthof() the relevant constant
> arrays is equal to MAX_OCLASS?  (Or other similar ways of checking
> that they have the right number of entries.)

Well, the array itself is declared like this:
	static const Oid object_classes[MAX_OCLASS] = {
so testing lengthof() of it is useless because it's a constant and the
assertion always holds.  If it were declared like this instead:
	static const Oid object_classes[] = {
then we could use lengthof().

I don't see any drawwbacks to that.

-- 
Álvaro Herrera                http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Attachments:

objclass-2.patch (text/x-diff, 1.7K) download diff --git a/src/backend/catalog/dependency.c b/src/backend/catalog/dependency.c index c1212e9..de2e2f2 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) == MAX_OCLASS), + "object_classes[] must cover all ObjectClasses"); + /* enlarge array if needed */ if (addrs->numrefs >= addrs->maxrefs) { diff --git a/src/include/catalog/dependency.h b/src/include/catalog/dependency.h index 5da18c2..138788e 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. See object_classes[]. */ typedef enum ObjectClass {

view thread (12+ messages)  latest in thread

Message-ID: <20150720163315.GS2301@postgresql.org>
Permalink:  ../20150720163315.GS2301@postgresql.org/
Also on:    postgresql.org/message-id/20150720163315.GS2301@postgresql.org

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: alvherre@2ndquadrant.com, tgl@sss.pgh.pa.us, robertmhaas@gmail.com, Jim.Nasby@BlueTreble.com, jaimin.pan@gmail.com, michael.paquier@gmail.com, pgsql-bugs@postgresql.org
  Subject: Re: [BUGS] object_classes array is broken, again
  In-Reply-To: <20150720163315.GS2301@postgresql.org>
  References: <20150720101431.GJ2301@postgresql.org> <13760.1437400153@sss.pgh.pa.us> <20150720163315.GS2301@postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox