Skip to content

Commit 93ca02e

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 fine though, as any modification of the statically allocated receivers would already have been a bug (and would now be caught on some platforms). Discussion: https://postgr.es/m/20181015200754.7y7zfuzsoux2c4ya@alap3.anarazel.de
1 parent d1211c6 commit 93ca02e

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-
static DestReceiver donothingDR = {
70+
static const DestReceiver donothingDR = {
7171
donothingReceive, donothingStartup, donothingCleanup, donothingCleanup,
7272
DestNone
7373
};
7474

75-
static DestReceiver debugtupDR = {
75+
static const DestReceiver debugtupDR = {
7676
debugtup, debugStartup, donothingCleanup, donothingCleanup,
7777
DestDebug
7878
};
7979

80-
static DestReceiver printsimpleDR = {
80+
static const DestReceiver printsimpleDR = {
8181
printsimple, printsimple_startup, donothingCleanup, donothingCleanup,
8282
DestRemoteSimple
8383
};
8484

85-
static DestReceiver spi_printtupDR = {
85+
static const DestReceiver spi_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(CommandDest dest)
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
case DestRemote:
114123
case DestRemoteExecute:
115124
return printtup_create_DR(dest);
116125

117126
case DestRemoteSimple:
118-
return &printsimpleDR;
127+
return unconstify(DestReceiver *, &printsimpleDR);
119128

120129
case DestNone:
121-
return &donothingDR;
130+
return unconstify(DestReceiver *, &donothingDR);
122131

123132
case DestDebug:
124-
return &debugtupDR;
133+
return unconstify(DestReceiver *, &debugtupDR);
125134

126135
case DestSPI:
127-
return &spi_printtupDR;
136+
return unconstify(DestReceiver *, &spi_printtupDR);
128137

129138
case DestTuplestore:
130139
return CreateTuplestoreDestReceiver();
@@ -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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy