Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Correct constness of a few variables.
authorAndres Freund <andres@anarazel.de>
Tue, 16 Oct 2018 03:45:30 +0000 (20:45 -0700)
committerAndres Freund <andres@anarazel.de>
Tue, 16 Oct 2018 04:01:14 +0000 (21:01 -0700)
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
src/backend/foreign/foreign.c
src/backend/libpq/pqcomm.c
src/backend/libpq/pqmq.c
src/backend/replication/basebackup.c
src/backend/storage/lmgr/generate-lwlocknames.pl
src/backend/utils/adt/cash.c
src/include/libpq/libpq.h
src/include/storage/lwlock.h

index 9a702e4097ee28b58d5727febc01d70047ced6af..20a3a786929c77cda81e8fe2e4192b9ac63527e0 100644 (file)
@@ -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.
index eac78a5d315590ca74c60ef4cf3c1ba9cfc3511e..a0bcc042cea41f9fa4ae43391ebc4fdadfd3f267 100644 (file)
@@ -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;
 
            /*
index a4f6d4deeb40ca7424e6ff1ac2e013bc7997e100..0c9593d4cc9510cea7de3b445534f8ac2cd1e707 100644 (file)
@@ -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;
 
index 4fbc6b5115dda3bf153afa94c6581bbf7fc27c4b..6eaed5bf0cfcfb8a0b458f5d317542b983a917a1 100644 (file)
@@ -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,
index 91ae4489552865347cdc4ab68f6ca4feb8027226..b20f6c379c65ecb091a0d9b5c00f03bb579db287 100644 (file)
@@ -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 ||
index 3913b3dc0161e104c02fad1822da345a9e56ee0f..241f68ee5730b0e1ea1ee49995e417a0dd510508 100644 (file)
@@ -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>)
 {
index c787dd341913222acb853c0824aea879ef876df6..c92e9d5046acba7296178f4c30d7dec2cba95d98 100644 (file)
@@ -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 */
index 36baf6b9199dbdd9a07b74ff9c92300f30317451..c7762f68a6bd10f7c9314c61a534bd4f9deb6558 100644 (file)
@@ -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())
index c21bfe2f66626b9fbc706885fec736280c03a21d..b2dcb7328724c441c29b9171a018db013005fafe 100644 (file)
@@ -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