pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Restructure formatting.c's NUM_processor() to add some const-san
Date: Thu, 20 Aug 2026 17:01:34 +0000
Message-ID: <E1wx68z-00000001NzQ-3Ezi@gemulon.postgresql.org> (raw)

Restructure formatting.c's NUM_processor() to add some const-sanity.

NUM_processor() is an under-documented mess.  Depending on the value
of is_to_char, it either reads "inout" and writes "number", or
the other way around.  That makes it impossible to label either
string "const", which seems like a minimum expectation in 2026.
It also complicates replacing the output buffer with a StringInfo:
we'd have to convert both strings, which is pretty pointless for
the input side.

Moreover, we're buying very little code savings by doing it like this,
since a large majority of the function's code has to be wrapped inside
"if (is_to_char)" tests.

To fix, split the function into NUM_processor_from_char() and
NUM_processor_to_char(), and rename/const-ify arguments as
appropriate.  Both paths now read from "const char *input"
and write to "char *output".

This patch doesn't intend to make any algorithmic changes, it's
just mechanical code rearrangement and symbol renaming.  The
only real exception is that I got rid of passing "input_len"
to NUM_processor_from_char()'s subroutines in favor of storing
"const char *input_end" in NUMProc.

Author: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi>
Discussion: https://postgr.es/m/3451175.1786641871@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/28c5d0724875591ff55dd85a065207badc2fa8ad

Modified Files
--------------
src/backend/utils/adt/formatting.c | 933 +++++++++++++++++++++----------------
1 file changed, 521 insertions(+), 412 deletions(-)



Message-ID: <E1wx68z-00000001NzQ-3Ezi@gemulon.postgresql.org>
Permalink:  ../E1wx68z-00000001NzQ-3Ezi@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1wx68z-00000001NzQ-3Ezi@gemulon.postgresql.org

 · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Restructure formatting.c's NUM_processor() to add some const-san
  In-Reply-To: <E1wx68z-00000001NzQ-3Ezi@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