pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andres Freund <andres@anarazel.de>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Add macro to cast away const without allowing changes to underly
Date: Tue, 16 Oct 2018 19:10:00 +0000
Message-ID: <E1gCUjA-0003Kp-Eb@gemulon.postgresql.org> (raw)

Add macro to cast away const without allowing changes to underlying type.

The new unconsitify(underlying_type, var) macro allows to cast
constness away from a variable, but doesn't allow changing the
underlying type.  Enforcement of the latter currently only works for
gcc like compilers.

Please note IT IS NOT SAFE to cast constness away if the variable will ever
be modified (it would be undefined behaviour). Doing so anyway can cause
compiler misoptimizations or runtime crashes (modifying readonly memory).
It is only safe to use when the the variable will not be modified, but API
design or language restrictions prevent you from declaring that
(e.g. because a function returns both const and non-const variables).

This'll be used in an upcoming change, but seems like it's independent
infrastructure.

Author: Andres Freund
Discussion: https://postgr.es/m/20181015200754.7y7zfuzsoux2c4ya@alap3.anarazel.de

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/d1211c63f010c4e0c22d6070872e80b8c8b4df82

Modified Files
--------------
src/include/c.h | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)



Message-ID: <E1gCUjA-0003Kp-Eb@gemulon.postgresql.org>
Permalink:  ../E1gCUjA-0003Kp-Eb@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1gCUjA-0003Kp-Eb@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: andres@anarazel.de
  Subject: Re: pgsql: Add macro to cast away const without allowing changes to underly
  In-Reply-To: <E1gCUjA-0003Kp-Eb@gemulon.postgresql.org>
  References: <E1gCUjA-0003Kp-Eb@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox