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

Commit93ca02e

Browse files
committed
Mark constantly allocated dest receiver as const.
This allows the compiler / linker to mark affected pages as read-only.Doing so requires casting constness away, as CreateDestReceiver()returns both constant and non-constant dest receivers. That's finethough, as any modification of the statically allocated receiverswould already have been a bug (and would now be caught on someplatforms).Discussion:https://postgr.es/m/20181015200754.7y7zfuzsoux2c4ya@alap3.anarazel.de
1 parentd1211c6 commit93ca02e

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

‎src/backend/tcop/dest.c

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,29 +67,33 @@ donothingCleanup(DestReceiver *self)
6767
*static DestReceiver structs for dest types needing no local state
6868
* ----------------
6969
*/
70-
staticDestReceiverdonothingDR= {
70+
staticconstDestReceiverdonothingDR= {
7171
donothingReceive,donothingStartup,donothingCleanup,donothingCleanup,
7272
DestNone
7373
};
7474

75-
staticDestReceiverdebugtupDR= {
75+
staticconstDestReceiverdebugtupDR= {
7676
debugtup,debugStartup,donothingCleanup,donothingCleanup,
7777
DestDebug
7878
};
7979

80-
staticDestReceiverprintsimpleDR= {
80+
staticconstDestReceiverprintsimpleDR= {
8181
printsimple,printsimple_startup,donothingCleanup,donothingCleanup,
8282
DestRemoteSimple
8383
};
8484

85-
staticDestReceiverspi_printtupDR= {
85+
staticconstDestReceiverspi_printtupDR= {
8686
spi_printtup,spi_dest_startup,donothingCleanup,donothingCleanup,
8787
DestSPI
8888
};
8989

90-
/* Globally available receiver for DestNone */
91-
DestReceiver*None_Receiver=&donothingDR;
92-
90+
/*
91+
* Globally available receiver for DestNone.
92+
*
93+
* It's ok to cast the constness away as any modification of the none receiver
94+
* would be a bug (which gets easier to catch this way).
95+
*/
96+
DestReceiver*None_Receiver= (DestReceiver*)&donothingDR;
9397

9498
/* ----------------
9599
*BeginCommand - initialize the destination at start of command
@@ -108,23 +112,28 @@ BeginCommand(const char *commandTag, CommandDest dest)
108112
DestReceiver*
109113
CreateDestReceiver(CommandDestdest)
110114
{
115+
/*
116+
* It's ok to cast the constness away as any modification of the none receiver
117+
* would be a bug (which gets easier to catch this way).
118+
*/
119+
111120
switch (dest)
112121
{
113122
caseDestRemote:
114123
caseDestRemoteExecute:
115124
returnprinttup_create_DR(dest);
116125

117126
caseDestRemoteSimple:
118-
return&printsimpleDR;
127+
returnunconstify(DestReceiver*,&printsimpleDR);
119128

120129
caseDestNone:
121-
return&donothingDR;
130+
returnunconstify(DestReceiver*,&donothingDR);
122131

123132
caseDestDebug:
124-
return&debugtupDR;
133+
returnunconstify(DestReceiver*,&debugtupDR);
125134

126135
caseDestSPI:
127-
return&spi_printtupDR;
136+
returnunconstify(DestReceiver*,&spi_printtupDR);
128137

129138
caseDestTuplestore:
130139
returnCreateTuplestoreDestReceiver();
@@ -146,7 +155,7 @@ CreateDestReceiver(CommandDest dest)
146155
}
147156

148157
/* should never get here */
149-
return&donothingDR;
158+
pg_unreachable();
150159
}
151160

152161
/* ----------------

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp