Re: Large writable variables

From: Andres Freund <andres(at)anarazel(dot)de>
To: pgsql-hackers(at)postgresql(dot)org, Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>
Subject: Re: Large writable variables
Date: 2018-10-16 06:30:13
Message-ID: 20181016063013.kigj6e5pqx6n75y3@alap3.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2018-10-16 06:33:17 Re: Large writable variables
Previous Message Andres Freund 2018-10-16 06:22:10 Re: Large writable variables