pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Unify parsing logic for command-line integer options
Date: Sat, 24 Jul 2021 09:37:08 +0000
Message-ID: <E1m7E5k-0000Ma-FK@gemulon.postgresql.org> (raw)

Unify parsing logic for command-line integer options

Most of the integer options for command-line binaries now make use of a
single routine able to do the job, fixing issues with the detection of
sloppy values caused for example by the use of atoi(), that fails on
strings beginning with numerical characters with junk trailing
characters.

This commit cuts down the number of strings requiring translation by 26
per my count, switching the code to have two error types for invalid and
out-of-range values instead.

Much more could be done here, with float or even int64 options, but
int32 was the most appealing case as it is possible to rely on strtol()
to do the job reliably.  Note that there are some exceptions for now,
like pg_ctl or pg_upgrade that use their own logging logic.  A couple of
negative TAP tests required some adjustments for the new errors
generated.

pg_dump and pg_restore tracked the maximum number of parallel jobs
within the option parsing.  The code is refactored a bit to track that
in the code dedicated to parallelism instead.

Author: Kyotaro Horiguchi, Michael Paquier
Reviewed-by: David Rowley, Álvaro Herrera
Discussion: https://postgr.es/m/CALj2ACXqdG9WhqVoJ9zYf-iZt7sgK7Szv5USs=he6NnWQ2ofTA@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/6f164e6d17616a157ea5d9e34dbb1b211c080c41

Modified Files
--------------
src/bin/pg_amcheck/pg_amcheck.c            |  8 ++--
src/bin/pg_basebackup/pg_basebackup.c      | 17 ++++-----
src/bin/pg_basebackup/pg_receivewal.c      | 23 ++++--------
src/bin/pg_basebackup/pg_recvlogical.c     | 25 +++++--------
src/bin/pg_checksums/Makefile              |  3 ++
src/bin/pg_checksums/pg_checksums.c        |  9 +++--
src/bin/pg_dump/parallel.h                 | 13 +++++++
src/bin/pg_dump/pg_dump.c                  | 47 ++++++-----------------
src/bin/pg_dump/pg_restore.c               | 22 +++--------
src/bin/pg_dump/t/001_basic.pl             | 20 +++++-----
src/bin/pgbench/pgbench.c                  | 60 ++++++++++--------------------
src/bin/pgbench/t/002_pgbench_no_server.pl | 34 +++++++++++------
src/bin/scripts/createuser.c               | 13 +++----
src/bin/scripts/reindexdb.c                |  9 ++---
src/bin/scripts/vacuumdb.c                 | 31 +++++----------
src/fe_utils/option_utils.c                | 39 +++++++++++++++++++
src/include/fe_utils/option_utils.h        |  3 ++
17 files changed, 177 insertions(+), 199 deletions(-)



Message-ID: <E1m7E5k-0000Ma-FK@gemulon.postgresql.org>
Permalink:  ../E1m7E5k-0000Ma-FK@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1m7E5k-0000Ma-FK@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 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: Unify parsing logic for command-line integer options
  In-Reply-To: <E1m7E5k-0000Ma-FK@gemulon.postgresql.org>
  References: <E1m7E5k-0000Ma-FK@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