Re: [HACKERS] object_classes array is broken, again

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)com>, Jaimin Pan <jaimin(dot)pan(at)gmail(dot)com>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>, pgsql-bugs(at)postgresql(dot)org
Subject: Re: [HACKERS] object_classes array is broken, again
Date: 2015-07-20 16:59:41
Message-ID: 29788.1437411581@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

Alvaro Herrera <alvherre(at)2ndquadrant(dot)com> writes:
> Tom Lane wrote:
>> 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().

Ah. I think the point of using MAX_OCLASS there was to get a warning
if the array was too short, but evidently it doesn't work like that.

> I don't see any drawwbacks to that.

+1 to this patch, in fact I think we could remove MAX_OCLASS altogether
which would be very nice for switch purposes.

Are there any other arrays that need such tests?

regards, tom lane

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2015-07-20 17:44:58 Re: BUG #13506: jsonb || operator does not work
Previous Message Alvaro Herrera 2015-07-20 16:33:15 Re: [BUGS] object_classes array is broken, again

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2015-07-20 17:48:48 Re: [BUGS] object_classes array is broken, again
Previous Message Alvaro Herrera 2015-07-20 16:48:37 Re: Dead code in Create/RenameRole() after RoleSpec changes related to CURRENT/SESSION_USER