From aa59701d6904c0d21eebd4606f27bb0cf2c2b6f3 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Wed, 28 Aug 2024 09:32:11 +0200 Subject: [PATCH] Add const qualifiers to XLogRegister*() functions Add const qualifiers to XLogRegisterData() and XLogRegisterBufData(). Several unconstify() calls can be removed. --- src/backend/access/brin/brin_pageops.c | 4 ++-- src/backend/access/transam/README | 4 ++-- src/backend/access/transam/xact.c | 4 ++-- src/backend/access/transam/xlog.c | 2 +- src/backend/access/transam/xloginsert.c | 22 +++++++++++----------- src/backend/replication/logical/message.c | 4 ++-- src/include/access/xlog_internal.h | 2 +- src/include/access/xloginsert.h | 6 +++--- src/include/storage/bufpage.h | 4 ++-- 9 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/backend/access/brin/brin_pageops.c b/src/backend/access/brin/brin_pageops.c index b69217c1ec6..659936144ed 100644 --- a/src/backend/access/brin/brin_pageops.c +++ b/src/backend/access/brin/brin_pageops.c @@ -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); diff --git a/src/backend/access/transam/README b/src/backend/access/transam/README index 28d196cf62b..6e4711dace7 100644 --- a/src/backend/access/transam/README +++ b/src/backend/access/transam/README @@ -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 diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index dfc8cf2dcf2..4eecbf12ed9 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -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) diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index ee0fb0e28f8..9744ba991bf 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -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) diff --git a/src/backend/access/transam/xloginsert.c b/src/backend/access/transam/xloginsert.c index 90476015347..f92d0626082 100644 --- a/src/backend/access/transam/xloginsert.c +++ b/src/backend/access/transam/xloginsert.c @@ -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 diff --git a/src/backend/replication/logical/message.c b/src/backend/replication/logical/message.c index 9e41aac2813..26fca3a8e5c 100644 --- a/src/backend/replication/logical/message.c +++ b/src/backend/replication/logical/message.c @@ -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); diff --git a/src/include/access/xlog_internal.h b/src/include/access/xlog_internal.h index c6a91fb4560..e5cdba0584a 100644 --- a/src/include/access/xlog_internal.h +++ b/src/include/access/xlog_internal.h @@ -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; diff --git a/src/include/access/xloginsert.h b/src/include/access/xloginsert.h index b44fa29eac5..652f7bc9bd1 100644 --- a/src/include/access/xloginsert.h +++ b/src/include/access/xloginsert.h @@ -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); diff --git a/src/include/storage/bufpage.h b/src/include/storage/bufpage.h index 5999e5ca5a5..6222d46e535 100644 --- a/src/include/storage/bufpage.h +++ b/src/include/storage/bufpage.h @@ -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) base-commit: 6654bb92047b37cee053cedd6fa1829841b2ad8e -- 2.46.0