Re: Large writable variables - Mailing list pgsql-hackers

From Andres Freund
Subject Re: Large writable variables
Date
Msg-id 20181016063013.kigj6e5pqx6n75y3@alap3.anarazel.de
Whole thread Raw
In response to Re: Large writable variables  (Andres Freund <andres@anarazel.de>)
Responses Re: Large writable variables  (Robert Haas <robertmhaas@gmail.com>)
Re: Large writable variables  (Peter Eisentraut <peter.eisentraut@2ndquadrant.com>)
List pgsql-hackers
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


pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Re: Large writable variables
Next
From: Andres Freund
Date:
Subject: Re: Large writable variables