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

Commit 02a30a0

Browse files
committed
Correct constness of system attributes in heap.c & prerequisites.
This allows the compiler / linker to mark affected pages as read-only. There's a fair number of pre-requisite changes, to allow the const properly be propagated. Most of consts were already required for correctness anyway, just not represented on the type-level. Arguably we could be more aggressive in using consts in related code, but.. This requires using a few of the types underlying typedefs that removes pointers (e.g. const NameData *) as declaring the typedefed type constant doesn't have the same meaning (it makes the variable const, not what it points to). Discussion: https://postgr.es/m/20181015200754.7y7zfuzsoux2c4ya@alap3.anarazel.de
1 parent c015ccb commit 02a30a0

File tree

11 files changed

+32
-31
lines changed

11 files changed

+32
-31
lines changed

src/backend/catalog/heap.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ static List *insert_ordered_unique_oid(List *list, Oid datum);
144144
* fixed-size portion of the structure anyway.
145145
*/
146146

147-
static FormData_pg_attribute a1 = {
147+
static const FormData_pg_attribute a1 = {
148148
.attname = {"ctid"},
149149
.atttypid = TIDOID,
150150
.attlen = sizeof(ItemPointerData),
@@ -158,7 +158,7 @@ static FormData_pg_attribute a1 = {
158158
.attislocal = true,
159159
};
160160

161-
static FormData_pg_attribute a2 = {
161+
static const FormData_pg_attribute a2 = {
162162
.attname = {"oid"},
163163
.atttypid = OIDOID,
164164
.attlen = sizeof(Oid),
@@ -172,7 +172,7 @@ static FormData_pg_attribute a2 = {
172172
.attislocal = true,
173173
};
174174

175-
static FormData_pg_attribute a3 = {
175+
static const FormData_pg_attribute a3 = {
176176
.attname = {"xmin"},
177177
.atttypid = XIDOID,
178178
.attlen = sizeof(TransactionId),
@@ -186,7 +186,7 @@ static FormData_pg_attribute a3 = {
186186
.attislocal = true,
187187
};
188188

189-
static FormData_pg_attribute a4 = {
189+
static const FormData_pg_attribute a4 = {
190190
.attname = {"cmin"},
191191
.atttypid = CIDOID,
192192
.attlen = sizeof(CommandId),
@@ -200,7 +200,7 @@ static FormData_pg_attribute a4 = {
200200
.attislocal = true,
201201
};
202202

203-
static FormData_pg_attribute a5 = {
203+
static const FormData_pg_attribute a5 = {
204204
.attname = {"xmax"},
205205
.atttypid = XIDOID,
206206
.attlen = sizeof(TransactionId),
@@ -214,7 +214,7 @@ static FormData_pg_attribute a5 = {
214214
.attislocal = true,
215215
};
216216

217-
static FormData_pg_attribute a6 = {
217+
static const FormData_pg_attribute a6 = {
218218
.attname = {"cmax"},
219219
.atttypid = CIDOID,
220220
.attlen = sizeof(CommandId),
@@ -234,7 +234,7 @@ static FormData_pg_attribute a6 = {
234234
* table of a particular class/type. In any case table is still the word
235235
* used in SQL.
236236
*/
237-
static FormData_pg_attribute a7 = {
237+
static const FormData_pg_attribute a7 = {
238238
.attname = {"tableoid"},
239239
.atttypid = OIDOID,
240240
.attlen = sizeof(Oid),
@@ -248,14 +248,14 @@ static FormData_pg_attribute a7 = {
248248
.attislocal = true,
249249
};
250250

251-
static const Form_pg_attribute SysAtt[] = {&a1, &a2, &a3, &a4, &a5, &a6, &a7};
251+
static const FormData_pg_attribute *SysAtt[] = {&a1, &a2, &a3, &a4, &a5, &a6, &a7};
252252

253253
/*
254254
* This function returns a Form_pg_attribute pointer for a system attribute.
255255
* Note that we elog if the presented attno is invalid, which would only
256256
* happen if there's a problem upstream.
257257
*/
258-
Form_pg_attribute
258+
const FormData_pg_attribute *
259259
SystemAttributeDefinition(AttrNumber attno, bool relhasoids)
260260
{
261261
if (attno >= 0 || attno < -(int) lengthof(SysAtt))
@@ -269,14 +269,14 @@ SystemAttributeDefinition(AttrNumber attno, bool relhasoids)
269269
* If the given name is a system attribute name, return a Form_pg_attribute
270270
* pointer for a prototype definition. If not, return NULL.
271271
*/
272-
Form_pg_attribute
272+
const FormData_pg_attribute *
273273
SystemAttributeByName(const char *attname, bool relhasoids)
274274
{
275275
int j;
276276

277277
for (j = 0; j < (int) lengthof(SysAtt); j++)
278278
{
279-
Form_pg_attribute att = SysAtt[j];
279+
const FormData_pg_attribute *att = SysAtt[j];
280280

281281
if (relhasoids || att->attnum != ObjectIdAttributeNumber)
282282
{

src/backend/catalog/index.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ ConstructTupleDescriptor(Relation heapRelation,
352352
if (atnum != 0)
353353
{
354354
/* Simple index column */
355-
Form_pg_attribute from;
355+
const FormData_pg_attribute *from;
356356

357357
if (atnum < 0)
358358
{

src/backend/executor/spi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ int
899899
SPI_fnumber(TupleDesc tupdesc, const char *fname)
900900
{
901901
int res;
902-
Form_pg_attribute sysatt;
902+
const FormData_pg_attribute *sysatt;
903903

904904
for (res = 0; res < tupdesc->natts; res++)
905905
{
@@ -921,7 +921,7 @@ SPI_fnumber(TupleDesc tupdesc, const char *fname)
921921
char *
922922
SPI_fname(TupleDesc tupdesc, int fnumber)
923923
{
924-
Form_pg_attribute att;
924+
const FormData_pg_attribute *att;
925925

926926
SPI_result = 0;
927927

src/backend/optimizer/util/plancat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1692,7 +1692,7 @@ build_index_tlist(PlannerInfo *root, IndexOptInfo *index,
16921692
if (indexkey != 0)
16931693
{
16941694
/* simple column */
1695-
Form_pg_attribute att_tup;
1695+
const FormData_pg_attribute *att_tup;
16961696

16971697
if (indexkey < 0)
16981698
att_tup = SystemAttributeDefinition(indexkey,

src/backend/parser/parse_relation.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3135,7 +3135,7 @@ attnameAttNum(Relation rd, const char *attname, bool sysColOK)
31353135
static int
31363136
specialAttNum(const char *attname)
31373137
{
3138-
Form_pg_attribute sysatt;
3138+
const FormData_pg_attribute *sysatt;
31393139

31403140
sysatt = SystemAttributeByName(attname,
31413141
true /* "oid" will be accepted */ );
@@ -3152,12 +3152,12 @@ specialAttNum(const char *attname)
31523152
* heap_open()'ed. Use the cache version get_atttype()
31533153
* for access to non-opened relations.
31543154
*/
3155-
Name
3155+
const NameData *
31563156
attnumAttName(Relation rd, int attid)
31573157
{
31583158
if (attid <= 0)
31593159
{
3160-
Form_pg_attribute sysatt;
3160+
const FormData_pg_attribute *sysatt;
31613161

31623162
sysatt = SystemAttributeDefinition(attid, rd->rd_rel->relhasoids);
31633163
return &sysatt->attname;
@@ -3179,7 +3179,7 @@ attnumTypeId(Relation rd, int attid)
31793179
{
31803180
if (attid <= 0)
31813181
{
3182-
Form_pg_attribute sysatt;
3182+
const FormData_pg_attribute *sysatt;
31833183

31843184
sysatt = SystemAttributeDefinition(attid, rd->rd_rel->relhasoids);
31853185
return sysatt->atttypid;

src/backend/parser/parse_utilcmd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2065,7 +2065,7 @@ transformIndexConstraint(Constraint *constraint, CreateStmtContext *cxt)
20652065
for (i = 0; i < index_form->indnatts; i++)
20662066
{
20672067
int16 attnum = index_form->indkey.values[i];
2068-
Form_pg_attribute attform;
2068+
const FormData_pg_attribute *attform;
20692069
char *attname;
20702070
Oid defopclass;
20712071

src/backend/utils/adt/expandedrecord.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,7 @@ expanded_record_lookup_field(ExpandedRecordHeader *erh, const char *fieldname,
10251025
TupleDesc tupdesc;
10261026
int fno;
10271027
Form_pg_attribute attr;
1028+
const FormData_pg_attribute *sysattr;
10281029

10291030
tupdesc = expanded_record_get_tupdesc(erh);
10301031

@@ -1044,13 +1045,13 @@ expanded_record_lookup_field(ExpandedRecordHeader *erh, const char *fieldname,
10441045
}
10451046

10461047
/* How about system attributes? */
1047-
attr = SystemAttributeByName(fieldname, tupdesc->tdhasoid);
1048-
if (attr != NULL)
1048+
sysattr = SystemAttributeByName(fieldname, tupdesc->tdhasoid);
1049+
if (sysattr != NULL)
10491050
{
1050-
finfo->fnumber = attr->attnum;
1051-
finfo->ftypeid = attr->atttypid;
1052-
finfo->ftypmod = attr->atttypmod;
1053-
finfo->fcollation = attr->attcollation;
1051+
finfo->fnumber = sysattr->attnum;
1052+
finfo->ftypeid = sysattr->atttypid;
1053+
finfo->ftypmod = sysattr->atttypmod;
1054+
finfo->fcollation = sysattr->attcollation;
10541055
return true;
10551056
}
10561057

src/backend/utils/adt/name.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ namege(PG_FUNCTION_ARGS)
188188
/* (see char.c for comparison/operation routines) */
189189

190190
int
191-
namecpy(Name n1, Name n2)
191+
namecpy(Name n1, const NameData *n2)
192192
{
193193
if (!n1 || !n2)
194194
return -1;

src/include/catalog/heap.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,10 @@ extern void RemoveAttrDefault(Oid relid, AttrNumber attnum,
127127
extern void RemoveAttrDefaultById(Oid attrdefId);
128128
extern void RemoveStatistics(Oid relid, AttrNumber attnum);
129129

130-
extern Form_pg_attribute SystemAttributeDefinition(AttrNumber attno,
130+
extern const FormData_pg_attribute *SystemAttributeDefinition(AttrNumber attno,
131131
bool relhasoids);
132132

133-
extern Form_pg_attribute SystemAttributeByName(const char *attname,
133+
extern const FormData_pg_attribute *SystemAttributeByName(const char *attname,
134134
bool relhasoids);
135135

136136
extern void CheckAttributeNamesTypes(TupleDesc tupdesc, char relkind,

src/include/parser/parse_relation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ extern void expandRTE(RangeTblEntry *rte, int rtindex, int sublevels_up,
125125
extern List *expandRelAttrs(ParseState *pstate, RangeTblEntry *rte,
126126
int rtindex, int sublevels_up, int location);
127127
extern int attnameAttNum(Relation rd, const char *attname, bool sysColOK);
128-
extern Name attnumAttName(Relation rd, int attid);
128+
extern const NameData *attnumAttName(Relation rd, int attid);
129129
extern Oid attnumTypeId(Relation rd, int attid);
130130
extern Oid attnumCollationId(Relation rd, int attid);
131131
extern bool isQueryUsingTempRelation(Query *query);

src/include/utils/builtins.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ extern unsigned hex_decode(const char *src, unsigned len, char *dst);
3737
extern int2vector *buildint2vector(const int16 *int2s, int n);
3838

3939
/* name.c */
40-
extern int namecpy(Name n1, Name n2);
40+
extern int namecpy(Name n1, const NameData *n2);
4141
extern int namestrcpy(Name name, const char *str);
4242
extern int namestrcmp(Name name, const char *str);
4343

0 commit comments

Comments
 (0)