pgsql: Add macro to cast away const without allowing changes tounderly

Поиск
Список
Период
Сортировка
От Andres Freund
Тема pgsql: Add macro to cast away const without allowing changes tounderly
Дата
Msg-id E1gCUjA-0003Kp-Eb@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
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(+)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: pgsql: Be smarter about age-counter overflow in formatting.c caches.
Следующее
От: Tom Lane
Дата:
Сообщение: pgsql: Back off using -isysroot on Darwin.