Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit02a30a0

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 constproperly be propagated. Most of consts were already required forcorrectness anyway, just not represented on the type-level. Arguablywe could be more aggressive in using consts in related code, but..This requires using a few of the types underlying typedefs thatremoves pointers (e.g. const NameData *) as declaring the typedefedtype constant doesn't have the same meaning (it makes the variableconst, not what it points to).Discussion:https://postgr.es/m/20181015200754.7y7zfuzsoux2c4ya@alap3.anarazel.de
1 parentc015ccb commit02a30a0

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-
staticFormData_pg_attributea1= {
147+
staticconstFormData_pg_attributea1= {
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-
staticFormData_pg_attributea2= {
161+
staticconstFormData_pg_attributea2= {
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-
staticFormData_pg_attributea3= {
175+
staticconstFormData_pg_attributea3= {
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-
staticFormData_pg_attributea4= {
189+
staticconstFormData_pg_attributea4= {
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-
staticFormData_pg_attributea5= {
203+
staticconstFormData_pg_attributea5= {
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-
staticFormData_pg_attributea6= {
217+
staticconstFormData_pg_attributea6= {
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-
staticFormData_pg_attributea7= {
237+
staticconstFormData_pg_attributea7= {
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-
staticconstForm_pg_attributeSysAtt[]= {&a1,&a2,&a3,&a4,&a5,&a6,&a7};
251+
staticconstFormData_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+
constFormData_pg_attribute*
259259
SystemAttributeDefinition(AttrNumberattno,boolrelhasoids)
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+
constFormData_pg_attribute*
273273
SystemAttributeByName(constchar*attname,boolrelhasoids)
274274
{
275275
intj;
276276

277277
for (j=0;j< (int)lengthof(SysAtt);j++)
278278
{
279-
Form_pg_attributeatt=SysAtt[j];
279+
constFormData_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_attributefrom;
355+
constFormData_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(TupleDesctupdesc,constchar*fname)
900900
{
901901
intres;
902-
Form_pg_attributesysatt;
902+
constFormData_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(TupleDesctupdesc,intfnumber)
923923
{
924-
Form_pg_attributeatt;
924+
constFormData_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_attributeatt_tup;
1695+
constFormData_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
staticint
31363136
specialAttNum(constchar*attname)
31373137
{
3138-
Form_pg_attributesysatt;
3138+
constFormData_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+
constNameData*
31563156
attnumAttName(Relationrd,intattid)
31573157
{
31583158
if (attid <=0)
31593159
{
3160-
Form_pg_attributesysatt;
3160+
constFormData_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_attributesysatt;
3182+
constFormData_pg_attribute*sysatt;
31833183

31843184
sysatt=SystemAttributeDefinition(attid,rd->rd_rel->relhasoids);
31853185
returnsysatt->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
int16attnum=index_form->indkey.values[i];
2068-
Form_pg_attributeattform;
2068+
constFormData_pg_attribute*attform;
20692069
char*attname;
20702070
Oiddefopclass;
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
TupleDesctupdesc;
10261026
intfno;
10271027
Form_pg_attributeattr;
1028+
constFormData_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(Namen1,Namen2)
191+
namecpy(Namen1,constNameData*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
externvoidRemoveAttrDefaultById(OidattrdefId);
128128
externvoidRemoveStatistics(Oidrelid,AttrNumberattnum);
129129

130-
externForm_pg_attributeSystemAttributeDefinition(AttrNumberattno,
130+
externconstFormData_pg_attribute*SystemAttributeDefinition(AttrNumberattno,
131131
boolrelhasoids);
132132

133-
externForm_pg_attributeSystemAttributeByName(constchar*attname,
133+
externconstFormData_pg_attribute*SystemAttributeByName(constchar*attname,
134134
boolrelhasoids);
135135

136136
externvoidCheckAttributeNamesTypes(TupleDesctupdesc,charrelkind,

‎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
externList*expandRelAttrs(ParseState*pstate,RangeTblEntry*rte,
126126
intrtindex,intsublevels_up,intlocation);
127127
externintattnameAttNum(Relationrd,constchar*attname,boolsysColOK);
128-
externNameattnumAttName(Relationrd,intattid);
128+
externconstNameData*attnumAttName(Relationrd,intattid);
129129
externOidattnumTypeId(Relationrd,intattid);
130130
externOidattnumCollationId(Relationrd,intattid);
131131
externboolisQueryUsingTempRelation(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
externint2vector*buildint2vector(constint16*int2s,intn);
3838

3939
/* name.c */
40-
externintnamecpy(Namen1,Namen2);
40+
externintnamecpy(Namen1,constNameData*n2);
4141
externintnamestrcpy(Namename,constchar*str);
4242
externintnamestrcmp(Namename,constchar*str);
4343

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp