From: Michael Paquier <michael@paquier.xyz>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Add overflow-safe math inline functions for unsigned integers
Date: Mon, 02 Sep 2019 00:50:03 +0000
Message-ID: <E1i4aXj-0008Cr-36@gemulon.postgresql.org> (raw)
Add overflow-safe math inline functions for unsigned integers
Similarly to the signed versions added in 4d6ad31, this adds a set of
inline functions for overflow checks with unsigned integers, including
uint16, uint32 and uint64. This relies on compiler built-in overflow
checks by default if available. The behavior of unsigned integers is
well-defined so the fallback implementations checks are simple for
additions and subtractions. Multiplications avoid division-based checks
which are expensive if possible, still this can happen for uint64 if
128-bit integers are not available.
While on it, the code in common/int.h is reorganized to avoid too many
duplicated comments. The new macros will be used in a follow-up patch.
All thanks to Andres Freund for the input provided.
Author: Fabien Coelho, Michael Paquier
Discussion: https://postgr.es/m/20190830073423.GB2354@paquier.xyz
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/7dedfd22b79822b7f4210e6255b672ea82db6678
Modified Files
--------------
src/include/common/int.h | 242 +++++++++++++++++++++++++++++++++++++++--------
1 file changed, 203 insertions(+), 39 deletions(-)
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: michael@paquier.xyz
Subject: Re: pgsql: Add overflow-safe math inline functions for unsigned integers
In-Reply-To: <E1i4aXj-0008Cr-36@gemulon.postgresql.org>
References: <E1i4aXj-0008Cr-36@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