From: Peter Eisentraut <peter@eisentraut.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Add pg_attribute_returns_nonnull to various memory allocation fu
Date: Mon, 19 Oct 2026 08:24:39 +0000
Message-ID: <E1xIiff-00000002EhG-3xT8@gemulon.postgresql.org> (raw)
Add pg_attribute_returns_nonnull to various memory allocation functions
This function attribute tells the compiler that the function will
never return NULL. This allows the compiler to do better static
analysis and lets it optimize the caller given the non-NULL guarantee.
The attribute is placed in front of the declaration, rather than after
it, so that it can also expand to the MSVC annotation _Ret_notnull_,
which is only valid in that position.
Only functions that raise an error on allocation failure are marked.
Functions that take a flags argument, such as palloc_extended() and
palloc_mul_extended(), can return NULL when MCXT_ALLOC_NO_OOM is
passed and are therefore not marked.
Author: Tristan Partin <tristan@partin.io>
Discussion: https://www.postgresql.org/message-id/flat/DJROV5LUO7B5.DIWXYC0101KD%40partin.io
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/23192ac644e2a8f0597692aacb269321ee5acd99
Modified Files
--------------
src/include/c.h | 15 +++++++++++++++
src/include/common/fe_memutils.h | 32 ++++++++++++++++----------------
src/include/utils/palloc.h | 32 ++++++++++++++++----------------
3 files changed, 47 insertions(+), 32 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: peter@eisentraut.org
Subject: Re: pgsql: Add pg_attribute_returns_nonnull to various memory allocation fu
In-Reply-To: <E1xIiff-00000002EhG-3xT8@gemulon.postgresql.org>
References: <E1xIiff-00000002EhG-3xT8@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