mirror of
https://github.com/postgres/postgres.git
synced 2025-06-12 00:01:43 -04:00
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
This commit is contained in:
parent
d1211c63f0
commit
93ca02e005
@ -67,29 +67,33 @@ donothingCleanup(DestReceiver *self)
|
|||||||
* static DestReceiver structs for dest types needing no local state
|
* static DestReceiver structs for dest types needing no local state
|
||||||
* ----------------
|
* ----------------
|
||||||
*/
|
*/
|
||||||
static DestReceiver donothingDR = {
|
static const DestReceiver donothingDR = {
|
||||||
donothingReceive, donothingStartup, donothingCleanup, donothingCleanup,
|
donothingReceive, donothingStartup, donothingCleanup, donothingCleanup,
|
||||||
DestNone
|
DestNone
|
||||||
};
|
};
|
||||||
|
|
||||||
static DestReceiver debugtupDR = {
|
static const DestReceiver debugtupDR = {
|
||||||
debugtup, debugStartup, donothingCleanup, donothingCleanup,
|
debugtup, debugStartup, donothingCleanup, donothingCleanup,
|
||||||
DestDebug
|
DestDebug
|
||||||
};
|
};
|
||||||
|
|
||||||
static DestReceiver printsimpleDR = {
|
static const DestReceiver printsimpleDR = {
|
||||||
printsimple, printsimple_startup, donothingCleanup, donothingCleanup,
|
printsimple, printsimple_startup, donothingCleanup, donothingCleanup,
|
||||||
DestRemoteSimple
|
DestRemoteSimple
|
||||||
};
|
};
|
||||||
|
|
||||||
static DestReceiver spi_printtupDR = {
|
static const DestReceiver spi_printtupDR = {
|
||||||
spi_printtup, spi_dest_startup, donothingCleanup, donothingCleanup,
|
spi_printtup, spi_dest_startup, donothingCleanup, donothingCleanup,
|
||||||
DestSPI
|
DestSPI
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Globally available receiver for DestNone */
|
/*
|
||||||
DestReceiver *None_Receiver = &donothingDR;
|
* Globally available receiver for DestNone.
|
||||||
|
*
|
||||||
|
* It's ok to cast the constness away as any modification of the none receiver
|
||||||
|
* would be a bug (which gets easier to catch this way).
|
||||||
|
*/
|
||||||
|
DestReceiver *None_Receiver = (DestReceiver *) &donothingDR;
|
||||||
|
|
||||||
/* ----------------
|
/* ----------------
|
||||||
* BeginCommand - initialize the destination at start of command
|
* BeginCommand - initialize the destination at start of command
|
||||||
@ -108,6 +112,11 @@ BeginCommand(const char *commandTag, CommandDest dest)
|
|||||||
DestReceiver *
|
DestReceiver *
|
||||||
CreateDestReceiver(CommandDest dest)
|
CreateDestReceiver(CommandDest dest)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
* It's ok to cast the constness away as any modification of the none receiver
|
||||||
|
* would be a bug (which gets easier to catch this way).
|
||||||
|
*/
|
||||||
|
|
||||||
switch (dest)
|
switch (dest)
|
||||||
{
|
{
|
||||||
case DestRemote:
|
case DestRemote:
|
||||||
@ -115,16 +124,16 @@ CreateDestReceiver(CommandDest dest)
|
|||||||
return printtup_create_DR(dest);
|
return printtup_create_DR(dest);
|
||||||
|
|
||||||
case DestRemoteSimple:
|
case DestRemoteSimple:
|
||||||
return &printsimpleDR;
|
return unconstify(DestReceiver *, &printsimpleDR);
|
||||||
|
|
||||||
case DestNone:
|
case DestNone:
|
||||||
return &donothingDR;
|
return unconstify(DestReceiver *, &donothingDR);
|
||||||
|
|
||||||
case DestDebug:
|
case DestDebug:
|
||||||
return &debugtupDR;
|
return unconstify(DestReceiver *, &debugtupDR);
|
||||||
|
|
||||||
case DestSPI:
|
case DestSPI:
|
||||||
return &spi_printtupDR;
|
return unconstify(DestReceiver *, &spi_printtupDR);
|
||||||
|
|
||||||
case DestTuplestore:
|
case DestTuplestore:
|
||||||
return CreateTuplestoreDestReceiver();
|
return CreateTuplestoreDestReceiver();
|
||||||
@ -146,7 +155,7 @@ CreateDestReceiver(CommandDest dest)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* should never get here */
|
/* should never get here */
|
||||||
return &donothingDR;
|
pg_unreachable();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------
|
/* ----------------
|
||||||
|
Loading…
x
Reference in New Issue
Block a user