From 62649bad831fb69b5d9644470acc413a35cddea6 Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Mon, 15 Oct 2018 20:45:30 -0700 Subject: [PATCH] Correct constness of a few variables. This allows the compiler / linker to mark affected pages as read-only. There's other cases, but they're a bit more invasive, and should go through some review. These are easy. They were found with objdump -j .data -t src/backend/postgres|awk '{print $4, $5, $6}'|sort -r|less Discussion: https://postgr.es/m/20181015200754.7y7zfuzsoux2c4ya@alap3.anarazel.de --- src/backend/commands/event_trigger.c | 4 ++-- src/backend/foreign/foreign.c | 6 +++--- src/backend/libpq/pqcomm.c | 4 ++-- src/backend/libpq/pqmq.c | 2 +- src/backend/replication/basebackup.c | 4 ++-- src/backend/storage/lmgr/generate-lwlocknames.pl | 2 +- src/backend/utils/adt/cash.c | 4 ++-- src/include/libpq/libpq.h | 2 +- src/include/storage/lwlock.h | 2 +- 9 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/backend/commands/event_trigger.c b/src/backend/commands/event_trigger.c index 9a702e4097..20a3a78692 100644 --- a/src/backend/commands/event_trigger.c +++ b/src/backend/commands/event_trigger.c @@ -85,7 +85,7 @@ typedef enum } event_trigger_command_tag_check_result; /* XXX merge this with ObjectTypeMap? */ -static event_trigger_support_data event_trigger_support[] = { +static const event_trigger_support_data event_trigger_support[] = { {"ACCESS METHOD", true}, {"AGGREGATE", true}, {"CAST", true}, @@ -282,7 +282,7 @@ static event_trigger_command_tag_check_result check_ddl_tag(const char *tag) { const char *obtypename; - event_trigger_support_data *etsd; + const event_trigger_support_data *etsd; /* * Handle some idiosyncratic special cases. diff --git a/src/backend/foreign/foreign.c b/src/backend/foreign/foreign.c index eac78a5d31..a0bcc042ce 100644 --- a/src/backend/foreign/foreign.c +++ b/src/backend/foreign/foreign.c @@ -560,7 +560,7 @@ struct ConnectionOption * * The list is small - don't bother with bsearch if it stays so. */ -static struct ConnectionOption libpq_conninfo_options[] = { +static const struct ConnectionOption libpq_conninfo_options[] = { {"authtype", ForeignServerRelationId}, {"service", ForeignServerRelationId}, {"user", UserMappingRelationId}, @@ -587,7 +587,7 @@ static struct ConnectionOption libpq_conninfo_options[] = { static bool is_conninfo_option(const char *option, Oid context) { - struct ConnectionOption *opt; + const struct ConnectionOption *opt; for (opt = libpq_conninfo_options; opt->optname; opt++) if (context == opt->optcontext && strcmp(opt->optname, option) == 0) @@ -622,7 +622,7 @@ postgresql_fdw_validator(PG_FUNCTION_ARGS) if (!is_conninfo_option(def->defname, catalog)) { - struct ConnectionOption *opt; + const struct ConnectionOption *opt; StringInfoData buf; /* diff --git a/src/backend/libpq/pqcomm.c b/src/backend/libpq/pqcomm.c index a4f6d4deeb..0c9593d4cc 100644 --- a/src/backend/libpq/pqcomm.c +++ b/src/backend/libpq/pqcomm.c @@ -170,7 +170,7 @@ static int Lock_AF_UNIX(char *unixSocketDir, char *unixSocketPath); static int Setup_AF_UNIX(char *sock_path); #endif /* HAVE_UNIX_SOCKETS */ -static PQcommMethods PqCommSocketMethods = { +static const PQcommMethods PqCommSocketMethods = { socket_comm_reset, socket_flush, socket_flush_if_writable, @@ -181,7 +181,7 @@ static PQcommMethods PqCommSocketMethods = { socket_endcopyout }; -PQcommMethods *PqCommMethods = &PqCommSocketMethods; +const PQcommMethods *PqCommMethods = &PqCommSocketMethods; WaitEventSet *FeBeWaitSet; diff --git a/src/backend/libpq/pqmq.c b/src/backend/libpq/pqmq.c index 4fbc6b5115..6eaed5bf0c 100644 --- a/src/backend/libpq/pqmq.c +++ b/src/backend/libpq/pqmq.c @@ -36,7 +36,7 @@ static void mq_putmessage_noblock(char msgtype, const char *s, size_t len); static void mq_startcopyout(void); static void mq_endcopyout(bool errorAbort); -static PQcommMethods PqCommMqMethods = { +static const PQcommMethods PqCommMqMethods = { mq_comm_reset, mq_flush, mq_flush_if_writable, diff --git a/src/backend/replication/basebackup.c b/src/backend/replication/basebackup.c index 91ae448955..b20f6c379c 100644 --- a/src/backend/replication/basebackup.c +++ b/src/backend/replication/basebackup.c @@ -190,7 +190,7 @@ static const char *excludeFiles[] = /* * List of files excluded from checksum validation. */ -static const char *noChecksumFiles[] = { +static const char *const noChecksumFiles[] = { "pg_control", "pg_filenode.map", "pg_internal.init", @@ -1321,7 +1321,7 @@ sendDir(const char *path, int basepathlen, bool sizeonly, List *tablespaces, static bool is_checksummed_file(const char *fullpath, const char *filename) { - const char **f; + const char *const *f; /* Check that the file is in a tablespace */ if (strncmp(fullpath, "./global/", 9) == 0 || diff --git a/src/backend/storage/lmgr/generate-lwlocknames.pl b/src/backend/storage/lmgr/generate-lwlocknames.pl index 3913b3dc01..241f68ee57 100644 --- a/src/backend/storage/lmgr/generate-lwlocknames.pl +++ b/src/backend/storage/lmgr/generate-lwlocknames.pl @@ -23,7 +23,7 @@ print $h $autogen; print $h "/* there is deliberately not an #ifndef LWLOCKNAMES_H here */\n\n"; print $c $autogen, "\n"; -print $c "char *MainLWLockNames[] = {"; +print $c "const char *const MainLWLockNames[] = {"; while (<$lwlocknames>) { diff --git a/src/backend/utils/adt/cash.c b/src/backend/utils/adt/cash.c index c787dd3419..c92e9d5046 100644 --- a/src/backend/utils/adt/cash.c +++ b/src/backend/utils/adt/cash.c @@ -39,13 +39,13 @@ static const char * num_word(Cash value) { static char buf[128]; - static const char *small[] = { + static const char *const small[] = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" }; - const char **big = small + 18; + const char *const *big = small + 18; int tu = value % 100; /* deal with the simple cases first */ diff --git a/src/include/libpq/libpq.h b/src/include/libpq/libpq.h index 36baf6b919..c7762f68a6 100644 --- a/src/include/libpq/libpq.h +++ b/src/include/libpq/libpq.h @@ -33,7 +33,7 @@ typedef struct void (*endcopyout) (bool errorAbort); } PQcommMethods; -extern PGDLLIMPORT PQcommMethods *PqCommMethods; +extern const PGDLLIMPORT PQcommMethods *PqCommMethods; #define pq_comm_reset() (PqCommMethods->comm_reset()) #define pq_flush() (PqCommMethods->flush()) diff --git a/src/include/storage/lwlock.h b/src/include/storage/lwlock.h index c21bfe2f66..b2dcb73287 100644 --- a/src/include/storage/lwlock.h +++ b/src/include/storage/lwlock.h @@ -88,7 +88,7 @@ typedef union LWLockMinimallyPadded } LWLockMinimallyPadded; extern PGDLLIMPORT LWLockPadded *MainLWLockArray; -extern char *MainLWLockNames[]; +extern const char *const MainLWLockNames[]; /* struct for storing named tranche information */ typedef struct NamedLWLockTranche