pgsql: Add pg_attribute_returns_nonnull to various memory allocation fu

From: Peter Eisentraut <peter(at)eisentraut(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Add pg_attribute_returns_nonnull to various memory allocation fu
Date: 2026-10-19 08:24:39
Message-ID: E1xIiff-00000002EhG-3xT8@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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(at)partin(dot)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(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Peter Eisentraut 2026-10-19 08:38:07 pgsql: Add missing dependencies to meson headerscheck target
Previous Message David Rowley 2026-10-19 08:03:31 pgsql: Recompute allocChunkLimit when reusing an AllocSet context