pgsql: Add pg_attribute_counted_by()

From: Peter Eisentraut <peter(at)eisentraut(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Add pg_attribute_counted_by()
Date: 2026-09-28 08:25:17
Message-ID: E1xB6fl-00000001Zq8-1ChI@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Add pg_attribute_counted_by()

The counted_by attribute allows specifying that a flexible array
member of a struct is "counted by" another member of the same struct.
The attribute makes arrays a little more self-documenting, but it is
also a hint to the compiler such that it can improve detection of
object size information and provide better results in compile-time
diagnostics and run-time features, such as the array bounds sanitizer.

Both GCC and clang warn when the attribute is used in C++, where it is
ignored, so define it away there.

In its current form, it is best used for flexible array members only.
Pointer array support may come later on.

This commit only contains a single use of the attribute for testing.
More will be added afterwards.

Author: Tristan Partin <tristan(at)partin(dot)io>
Reviewed-by: Peter Eisentraut <peter(at)eisentraut(dot)org>
Reviewed-by: Japin Li <japinli(at)hotmail(dot)com>
Reviewed-by: Greg Burd <greg(at)burd(dot)me>
Discussion: https://www.postgresql.org/message-id/flat/DKBEBF32QLUA.3L2DJRPUYNKHZ%40partin.io

Branch
------
master

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

Modified Files
--------------
src/backend/utils/adt/jsonfuncs.c | 2 +-
src/include/c.h | 24 ++++++++++++++++++++++++
2 files changed, 25 insertions(+), 1 deletion(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Fujii Masao 2026-09-28 09:54:39 pgsql: Prevent remote notices from repeating local query details in log
Previous Message Fujii Masao 2026-09-28 05:24:41 pgsql: Prevent stale pg_locks.waitstart values