On 2018-10-15 22:02:00 -0700, Andres Freund wrote:
> Hi,
>
> On 2018-10-15 21:50:51 -0700, Andres Freund wrote:
> > .data 0000000000000028 spi_printtupDR
> > .data 0000000000000028 printsimpleDR
> > .data 0000000000000028 donothingDR
> > .data 0000000000000028 debugtupDR
> >
> > These we could actually make constant, but CreateDestReceiver() as an
> > API makes that inconvenient. They also are pretty darn small... There's
> > a security benefit in making them constant and casting the constness
> > away - I think that might not be insane.
>
> I.e. do something like the attached.
This just reminded me that a couple times I wanted a cast that casts
away const, but otherwise makes sure the type stays the same. I don't
think there's a way to do that in C, but we can write one that verifies
the cast doesn't do something bad if gcc is used:
#if defined(HAVE__BUILTIN_TYPES_COMPATIBLE_P)
#define unconstify(cst, var) StaticAssertExpr(__builtin_types_compatible_p(__typeof(var), const cst), "wrong cast"),
(cst)(var)
#else
#define unconstify(cst, var) ((cst) (var))
#endif
Does anybody besides me see value in adding a cleaned up version of
that?
Greetings,
Andres Freund