Small const correctness patch

Started by Mark Gover 6 years ago8 messages
#1Mark G
markg735@gmail.com
1 attachment(s)

Hello all,

Please find attached a trivial patch making a few arrays const (in addition
to the data they point to).

Attachments:

constify-arrays.patchtext/x-patch; charset=US-ASCII; name=constify-arrays.patchDownload
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index f553523857..aafc7187b0 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -769,7 +769,7 @@ typedef enum
 } XLogSource;
 
 /* human-readable names for XLogSources, for debugging output */
-static const char *xlogSourceNames[] = {"any", "archive", "pg_wal", "stream"};
+static const char *const xlogSourceNames[] = {"any", "archive", "pg_wal", "stream"};
 
 /*
  * openLogFile is -1 or a kernel FD for an open log file segment.
diff --git a/src/backend/replication/basebackup.c b/src/backend/replication/basebackup.c
index d5f9b617c8..0bba32cde5 100644
--- a/src/backend/replication/basebackup.c
+++ b/src/backend/replication/basebackup.c
@@ -119,7 +119,7 @@ static bool noverify_checksums = false;
  * Note: this list should be kept in sync with the filter lists in pg_rewind's
  * filemap.c.
  */
-static const char *excludeDirContents[] =
+static const char *const excludeDirContents[] =
 {
 	/*
 	 * Skip temporary statistics files. PG_STAT_TMP_DIR must be skipped even
@@ -160,7 +160,7 @@ static const char *excludeDirContents[] =
 /*
  * List of files excluded from backups.
  */
-static const char *excludeFiles[] =
+static const char *const excludeFiles[] =
 {
 	/* Skip auto conf temporary file. */
 	PG_AUTOCONF_FILENAME ".tmp",
#2Ibrar Ahmed
ibrar.ahmad@gmail.com
In reply to: Mark G (#1)
Re: Small const correctness patch

+1

Patch successfully applied to the master (
43211c2a02f39d6568496168413dc00e0399dc2e)

On Thu, Aug 8, 2019 at 12:30 PM Mark G <markg735@gmail.com> wrote:

Hello all,

Please find attached a trivial patch making a few arrays const (in
addition to the data they point to).

--
Ibrar Ahmed

#3Peter Eisentraut
peter.eisentraut@2ndquadrant.com
In reply to: Mark G (#1)
Re: Small const correctness patch

On 2019-08-08 08:46, Mark G wrote:

Please find attached a trivial patch making a few arrays const (in
addition to the data they point to).

How did you find this? Any special compiler settings?

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

#4Mark G
markg735@gmail.com
In reply to: Peter Eisentraut (#3)
Re: Small const correctness patch

On Thu, Aug 8, 2019 at 8:51 PM Peter Eisentraut <
peter.eisentraut@2ndquadrant.com> wrote:

How did you find this? Any special compiler settings?

16 hours stuck in a plane on an international flight. I was just eyeballing
the code to kill the boredom.

-Mark

#5Mark G
markg735@gmail.com
In reply to: Ibrar Ahmed (#2)
Re: Small const correctness patch

On Thu, Aug 8, 2019 at 8:25 PM Ibrar Ahmed <ibrar.ahmad@gmail.com> wrote:

+1

Patch successfully applied to the master (
43211c2a02f39d6568496168413dc00e0399dc2e)

That change looks like an unrelated patch for initdb. I'm still not seeing
my patch there.

-Mark

#6Ibrar Ahmed
ibrar.ahmad@gmail.com
In reply to: Mark G (#5)
Re: Small const correctness patch

On Fri, Aug 9, 2019 at 1:25 AM Mark G <markg735@gmail.com> wrote:

On Thu, Aug 8, 2019 at 8:25 PM Ibrar Ahmed <ibrar.ahmad@gmail.com> wrote:

+1

Patch successfully applied to the master (
43211c2a02f39d6568496168413dc00e0399dc2e)

That change looks like an unrelated patch for initdb. I'm still not seeing
my patch there.

I said I checked and verified patch against that hash. It applied to that
without any failure. Sorry for the confusion.

-Mark

--
Ibrar Ahmed

#7Kyotaro Horiguchi
horikyota.ntt@gmail.com
In reply to: Mark G (#4)
Re: Small const correctness patch

At Thu, 8 Aug 2019 22:56:02 +0300, Mark G <markg735@gmail.com> wrote in <CAEeOP_Y3SAXe8u++9e-CN_+MgY9_u+vu3a80sw+7gzR4s7KjqQ@mail.gmail.com>

On Thu, Aug 8, 2019 at 8:51 PM Peter Eisentraut <
peter.eisentraut@2ndquadrant.com> wrote:

How did you find this? Any special compiler settings?

16 hours stuck in a plane on an international flight. I was just eyeballing
the code to kill the boredom.

A similar loose typing is seen, for example:p

-const char *
+const char * const

src/backend/access/rmgrdesc/*.c
relmap_identify(uint8 info)
seq_identify(uint8 info)
smgr_identify(uint8 info)
.... (many)...

src/backend/access/transam/xact.c:
BlockStateAsString(TBlockState blockState)

I foundnd them by

find $(TOP) -type f -exec egrep -nH -e '^(static )?const char \*' {} +

then eyeballing on the first ones. I don't know an automated way
to detect such possibly-loose constness of variables or
functions.

regards.

--
Kyotaro Horiguchi
NTT Open Source Software Center

#8Peter Eisentraut
peter.eisentraut@2ndquadrant.com
In reply to: Mark G (#1)
Re: Small const correctness patch

On 2019-08-08 08:46, Mark G wrote:

Please find attached a trivial patch making a few arrays const (in
addition to the data they point to).

committed

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services