Add const qualifiers to XLogRegister*() functions
authorPeter Eisentraut <peter@eisentraut.org>
Tue, 3 Sep 2024 06:00:38 +0000 (08:00 +0200)
committerPeter Eisentraut <peter@eisentraut.org>
Tue, 3 Sep 2024 06:06:03 +0000 (08:06 +0200)
Add const qualifiers to XLogRegisterData() and XLogRegisterBufData().
Several unconstify() calls can be removed.

Reviewed-by: Aleksander Alekseev <aleksander@timescale.com>
Discussion: https://www.postgresql.org/message-id/dd889784-9ce7-436a-b4f1-52e4a5e577bd@eisentraut.org

src/backend/access/brin/brin_pageops.c
src/backend/access/transam/README
src/backend/access/transam/xact.c
src/backend/access/transam/xlog.c
src/backend/access/transam/xloginsert.c
src/backend/replication/logical/message.c
src/include/access/xlog_internal.h
src/include/access/xloginsert.h
src/include/storage/bufpage.h

index b69217c1ec6d5dcc8194138dcef31103dd924fda..659936144ed490a95aebc2d65f3cbc085d0eb9cc 100644 (file)
@@ -193,7 +193,7 @@ brin_doupdate(Relation idxrel, BlockNumber pagesPerRange,
            XLogRegisterData((char *) &xlrec, SizeOfBrinSamepageUpdate);
 
            XLogRegisterBuffer(0, oldbuf, REGBUF_STANDARD);
-           XLogRegisterBufData(0, (char *) unconstify(BrinTuple *, newtup), newsz);
+           XLogRegisterBufData(0, (const char *) newtup, newsz);
 
            recptr = XLogInsert(RM_BRIN_ID, info);
 
@@ -285,7 +285,7 @@ brin_doupdate(Relation idxrel, BlockNumber pagesPerRange,
            XLogRegisterData((char *) &xlrec, SizeOfBrinUpdate);
 
            XLogRegisterBuffer(0, newbuf, REGBUF_STANDARD | (extended ? REGBUF_WILL_INIT : 0));
-           XLogRegisterBufData(0, (char *) unconstify(BrinTuple *, newtup), newsz);
+           XLogRegisterBufData(0, (const char *) newtup, newsz);
 
            /* revmap page */
            XLogRegisterBuffer(1, revmapbuf, 0);
index 28d196cf62b33baa08b88004548d09d197aa9f47..6e4711dace70cdb6689fbb744e9b6b24a5aaa11c 100644 (file)
@@ -586,13 +586,13 @@ void XLogRegisterBuffer(uint8 block_id, Buffer buf, uint8 flags);
     XLogRegisterBufData() is included in the WAL record even if a full-page
     image is taken.
 
-void XLogRegisterData(char *data, int len);
+void XLogRegisterData(const char *data, int len);
 
     XLogRegisterData is used to include arbitrary data in the WAL record.  If
     XLogRegisterData() is called multiple times, the data are appended, and
     will be made available to the redo routine as one contiguous chunk.
 
-void XLogRegisterBufData(uint8 block_id, char *data, int len);
+void XLogRegisterBufData(uint8 block_id, const char *data, int len);
 
     XLogRegisterBufData is used to include data associated with a particular
     buffer that was registered earlier with XLogRegisterBuffer().  If
index 0fe1630fca84a43c7b0baa96158acdc9e5e55835..87700c7c5c7629a0fde027c00033e66dfcfb3174 100644 (file)
@@ -5951,7 +5951,7 @@ XactLogCommitRecord(TimestampTz commit_time,
    {
        XLogRegisterData((char *) (&xl_twophase), sizeof(xl_xact_twophase));
        if (xl_xinfo.xinfo & XACT_XINFO_HAS_GID)
-           XLogRegisterData(unconstify(char *, twophase_gid), strlen(twophase_gid) + 1);
+           XLogRegisterData(twophase_gid, strlen(twophase_gid) + 1);
    }
 
    if (xl_xinfo.xinfo & XACT_XINFO_HAS_ORIGIN)
@@ -6097,7 +6097,7 @@ XactLogAbortRecord(TimestampTz abort_time,
    {
        XLogRegisterData((char *) (&xl_twophase), sizeof(xl_xact_twophase));
        if (xl_xinfo.xinfo & XACT_XINFO_HAS_GID)
-           XLogRegisterData(unconstify(char *, twophase_gid), strlen(twophase_gid) + 1);
+           XLogRegisterData(twophase_gid, strlen(twophase_gid) + 1);
    }
 
    if (xl_xinfo.xinfo & XACT_XINFO_HAS_ORIGIN)
index 4e06d86196fb3b6533fff1c8fe6184ab1186419f..5211e4e10889a3b5f736819bbe84d15db96eeb78 100644 (file)
@@ -1248,7 +1248,7 @@ CopyXLogRecordToWAL(int write_len, bool isLogSwitch, XLogRecData *rdata,
    written = 0;
    while (rdata != NULL)
    {
-       char       *rdata_data = rdata->data;
+       const char *rdata_data = rdata->data;
        int         rdata_len = rdata->len;
 
        while (rdata_len > freespace)
index 90476015347ad8d72d549d3c2178c5cf7c92ee36..f92d0626082d8eaad1132b05c3c54c2fc0e3fe67 100644 (file)
@@ -72,7 +72,7 @@ typedef struct
    RelFileLocator rlocator;    /* identifies the relation and block */
    ForkNumber  forkno;
    BlockNumber block;
-   Page        page;           /* page content */
+   const char *page;           /* page content */
    uint32      rdata_len;      /* total length of data in rdata chain */
    XLogRecData *rdata_head;    /* head of the chain of data registered with
                                 * this block */
@@ -138,7 +138,7 @@ static XLogRecData *XLogRecordAssemble(RmgrId rmid, uint8 info,
                                       XLogRecPtr RedoRecPtr, bool doPageWrites,
                                       XLogRecPtr *fpw_lsn, int *num_fpi,
                                       bool *topxid_included);
-static bool XLogCompressBackupBlock(char *page, uint16 hole_offset,
+static bool XLogCompressBackupBlock(const char *page, uint16 hole_offset,
                                    uint16 hole_length, char *dest, uint16 *dlen);
 
 /*
@@ -307,7 +307,7 @@ XLogRegisterBuffer(uint8 block_id, Buffer buffer, uint8 flags)
  */
 void
 XLogRegisterBlock(uint8 block_id, RelFileLocator *rlocator, ForkNumber forknum,
-                 BlockNumber blknum, Page page, uint8 flags)
+                 BlockNumber blknum, const char *page, uint8 flags)
 {
    registered_buffer *regbuf;
 
@@ -361,7 +361,7 @@ XLogRegisterBlock(uint8 block_id, RelFileLocator *rlocator, ForkNumber forknum,
  * XLogRecGetData().
  */
 void
-XLogRegisterData(char *data, uint32 len)
+XLogRegisterData(const char *data, uint32 len)
 {
    XLogRecData *rdata;
 
@@ -402,7 +402,7 @@ XLogRegisterData(char *data, uint32 len)
  * limited)
  */
 void
-XLogRegisterBufData(uint8 block_id, char *data, uint32 len)
+XLogRegisterBufData(uint8 block_id, const char *data, uint32 len)
 {
    registered_buffer *regbuf;
    XLogRecData *rdata;
@@ -648,7 +648,7 @@ XLogRecordAssemble(RmgrId rmid, uint8 info,
 
        if (include_image)
        {
-           Page        page = regbuf->page;
+           const char *page = regbuf->page;
            uint16      compressed_len = 0;
 
            /*
@@ -941,23 +941,23 @@ XLogRecordAssemble(RmgrId rmid, uint8 info,
  * the length of compressed block image.
  */
 static bool
-XLogCompressBackupBlock(char *page, uint16 hole_offset, uint16 hole_length,
+XLogCompressBackupBlock(const char *page, uint16 hole_offset, uint16 hole_length,
                        char *dest, uint16 *dlen)
 {
    int32       orig_len = BLCKSZ - hole_length;
    int32       len = -1;
    int32       extra_bytes = 0;
-   char       *source;
+   const char *source;
    PGAlignedBlock tmp;
 
    if (hole_length != 0)
    {
        /* must skip the hole */
-       source = tmp.data;
-       memcpy(source, page, hole_offset);
-       memcpy(source + hole_offset,
+       memcpy(tmp.data, page, hole_offset);
+       memcpy(tmp.data + hole_offset,
               page + (hole_offset + hole_length),
               BLCKSZ - (hole_length + hole_offset));
+       source = tmp.data;
 
        /*
         * Extra data needs to be stored in WAL record for the compressed
index 9e41aac28130de831817b03e7078f70e5b2f6bcd..26fca3a8e5c389bcd41ac7ba1033ceb042db447e 100644 (file)
@@ -63,8 +63,8 @@ LogLogicalMessage(const char *prefix, const char *message, size_t size,
 
    XLogBeginInsert();
    XLogRegisterData((char *) &xlrec, SizeOfLogicalMessage);
-   XLogRegisterData(unconstify(char *, prefix), xlrec.prefix_size);
-   XLogRegisterData(unconstify(char *, message), size);
+   XLogRegisterData(prefix, xlrec.prefix_size);
+   XLogRegisterData(message, size);
 
    /* allow origin filtering */
    XLogSetRecordFlags(XLOG_INCLUDE_ORIGIN);
index c6a91fb4560553c8b5148d64bc10cc61469ebee7..e5cdba0584a01aff36ca0af2b987d3a487b8afb3 100644 (file)
@@ -312,7 +312,7 @@ typedef struct xl_end_of_recovery
 typedef struct XLogRecData
 {
    struct XLogRecData *next;   /* next struct in chain, or NULL */
-   char       *data;           /* start of rmgr data to include */
+   const char *data;           /* start of rmgr data to include */
    uint32      len;            /* length of rmgr data to include */
 } XLogRecData;
 
index b44fa29eac515331c5293c01cb9a8c1636283929..652f7bc9bd1632bae85d9358639bb0065a2742c8 100644 (file)
@@ -44,12 +44,12 @@ extern void XLogBeginInsert(void);
 extern void XLogSetRecordFlags(uint8 flags);
 extern XLogRecPtr XLogInsert(RmgrId rmid, uint8 info);
 extern void XLogEnsureRecordSpace(int max_block_id, int ndatas);
-extern void XLogRegisterData(char *data, uint32 len);
+extern void XLogRegisterData(const char *data, uint32 len);
 extern void XLogRegisterBuffer(uint8 block_id, Buffer buffer, uint8 flags);
 extern void XLogRegisterBlock(uint8 block_id, RelFileLocator *rlocator,
-                             ForkNumber forknum, BlockNumber blknum, char *page,
+                             ForkNumber forknum, BlockNumber blknum, const char *page,
                              uint8 flags);
-extern void XLogRegisterBufData(uint8 block_id, char *data, uint32 len);
+extern void XLogRegisterBufData(uint8 block_id, const char *data, uint32 len);
 extern void XLogResetInsertion(void);
 extern bool XLogCheckBufferNeedsBackup(Buffer buffer);
 
index 5999e5ca5a5673bf0b4b5b7fcc56e78011ad88e8..6222d46e5355dfe2be122f6b95dfc71f0e54333c 100644 (file)
@@ -384,9 +384,9 @@ PageGetMaxOffsetNumber(Page page)
  * Additional functions for access to page headers.
  */
 static inline XLogRecPtr
-PageGetLSN(Page page)
+PageGetLSN(const char *page)
 {
-   return PageXLogRecPtrGet(((PageHeader) page)->pd_lsn);
+   return PageXLogRecPtrGet(((const PageHeaderData *) page)->pd_lsn);
 }
 static inline void
 PageSetLSN(Page page, XLogRecPtr lsn)