Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZHE0Q-0005ae-Tj for pgsql-hackers@arkaria.postgresql.org; Mon, 20 Jul 2015 16:33:31 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZHE0Q-0005NN-4G for pgsql-hackers@arkaria.postgresql.org; Mon, 20 Jul 2015 16:33:30 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZHE0N-0005Ko-40; Mon, 20 Jul 2015 16:33:27 +0000 Received: from smtp-auth.no-ip.com ([8.23.224.61] helo=out.smtp-auth.no-ip.com) by magus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1ZHE0G-0001WQ-ED; Mon, 20 Jul 2015 16:33:25 +0000 X-No-IP: alvh.no-ip.org@noip-smtp X-Report-Spam-To: abuse@no-ip.com Received: from alvin.alvh.no-ip.org (unknown [89.176.99.192]) (Authenticated sender: alvh.no-ip.org@noip-smtp) by smtp-auth.no-ip.com (Postfix) with ESMTPA id 5AC5E400D8D; Mon, 20 Jul 2015 09:33:17 -0700 (PDT) Received: by alvin.alvh.no-ip.org (Postfix, from userid 1000) id 4EAB836F0; Mon, 20 Jul 2015 20:33:15 +0400 (SAMT) Date: Mon, 20 Jul 2015 18:33:15 +0200 From: Alvaro Herrera To: Tom Lane Cc: Robert Haas , Jim Nasby , Jaimin Pan , Michael Paquier , "pgsql-hackers@postgresql.org" , pgsql-bugs@postgresql.org Subject: Re: [BUGS] object_classes array is broken, again Message-ID: <20150720163315.GS2301@postgresql.org> References: <20150720101431.GJ2301@postgresql.org> <13760.1437400153@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="FsscpQKzF/jJk6ya" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <13760.1437400153@sss.pgh.pa.us> User-Agent: Mutt/1.5.23 (2014-03-12) X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org --FsscpQKzF/jJk6ya Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit Tom Lane wrote: > Alvaro Herrera 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 --FsscpQKzF/jJk6ya Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="objclass-2.patch" 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 { --FsscpQKzF/jJk6ya Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers --FsscpQKzF/jJk6ya--