Add const to BufFileWrite
authorPeter Eisentraut <[email protected]>
Fri, 30 Dec 2022 09:02:59 +0000 (10:02 +0100)
committerPeter Eisentraut <[email protected]>
Fri, 30 Dec 2022 09:12:24 +0000 (10:12 +0100)
Make data buffer argument to BufFileWrite a const pointer and bubble
this up to various callers and related APIs.  This makes the APIs
clearer and more consistent.

Discussion: https://www.postgresql.org/message-id/flat/11dda853-bb5b-59ba-a746-e168b1ce4bdb%40enterprisedb.com

src/backend/access/gist/gistbuildbuffers.c
src/backend/backup/backup_manifest.c
src/backend/storage/file/buffile.c
src/backend/utils/sort/logtape.c
src/include/storage/buffile.h
src/include/utils/logtape.h

index 538e3880c9eb1a2d0935d005e82e028409439c8b..60911e6aacdb3614c7b93e435dc6c2cc3bd0a144 100644 (file)
@@ -38,7 +38,7 @@ static long gistBuffersGetFreeBlock(GISTBuildBuffers *gfbb);
 static void gistBuffersReleaseBlock(GISTBuildBuffers *gfbb, long blocknum);
 
 static void ReadTempFileBlock(BufFile *file, long blknum, void *ptr);
-static void WriteTempFileBlock(BufFile *file, long blknum, void *ptr);
+static void WriteTempFileBlock(BufFile *file, long blknum, const void *ptr);
 
 
 /*
@@ -764,7 +764,7 @@ ReadTempFileBlock(BufFile *file, long blknum, void *ptr)
 }
 
 static void
-WriteTempFileBlock(BufFile *file, long blknum, void *ptr)
+WriteTempFileBlock(BufFile *file, long blknum, const void *ptr)
 {
        if (BufFileSeekBlock(file, blknum) != 0)
                elog(ERROR, "could not seek to block %ld in temporary file", blknum);
index a54185fdab8c4971415d32e0eff3a9832c2d5135..68a2337a21750fb23f0de192d2448c029c818af2 100644 (file)
@@ -21,7 +21,7 @@
 #include "utils/builtins.h"
 #include "utils/json.h"
 
-static void AppendStringToManifest(backup_manifest_info *manifest, char *s);
+static void AppendStringToManifest(backup_manifest_info *manifest, const char *s);
 
 /*
  * Does the user want a backup manifest?
@@ -385,7 +385,7 @@ SendBackupManifest(backup_manifest_info *manifest, bbsink *sink)
  * Append a cstring to the manifest.
  */
 static void
-AppendStringToManifest(backup_manifest_info *manifest, char *s)
+AppendStringToManifest(backup_manifest_info *manifest, const char *s)
 {
        int                     len = strlen(s);
 
index b07cca28d60e43116808603f35374de7f2f3fca5..2202ba43f7fa03651a2bee605fb29a22fc15e256 100644 (file)
@@ -622,7 +622,7 @@ BufFileRead(BufFile *file, void *ptr, size_t size)
  * ereport().
  */
 void
-BufFileWrite(BufFile *file, void *ptr, size_t size)
+BufFileWrite(BufFile *file, const void *ptr, size_t size)
 {
        size_t          nthistime;
 
@@ -655,7 +655,7 @@ BufFileWrite(BufFile *file, void *ptr, size_t size)
                file->pos += nthistime;
                if (file->nbytes < file->pos)
                        file->nbytes = file->pos;
-               ptr = (char *) ptr + nthistime;
+               ptr = (const char *) ptr + nthistime;
                size -= nthistime;
        }
 }
index 9db220b7ea318e17bb062a67194f8ec661a136a2..23a5e7f2a00605fbb26a0cde35fdf082be957642 100644 (file)
@@ -220,7 +220,7 @@ struct LogicalTapeSet
 };
 
 static LogicalTape *ltsCreateTape(LogicalTapeSet *lts);
-static void ltsWriteBlock(LogicalTapeSet *lts, long blocknum, void *buffer);
+static void ltsWriteBlock(LogicalTapeSet *lts, long blocknum, const void *buffer);
 static void ltsReadBlock(LogicalTapeSet *lts, long blocknum, void *buffer);
 static long ltsGetBlock(LogicalTapeSet *lts, LogicalTape *lt);
 static long ltsGetFreeBlock(LogicalTapeSet *lts);
@@ -235,7 +235,7 @@ static void ltsInitReadBuffer(LogicalTape *lt);
  * No need for an error return convention; we ereport() on any error.
  */
 static void
-ltsWriteBlock(LogicalTapeSet *lts, long blocknum, void *buffer)
+ltsWriteBlock(LogicalTapeSet *lts, long blocknum, const void *buffer)
 {
        /*
         * BufFile does not support "holes", so if we're about to write a block
@@ -759,7 +759,7 @@ LogicalTapeSetForgetFreeSpace(LogicalTapeSet *lts)
  * There are no error returns; we ereport() on failure.
  */
 void
-LogicalTapeWrite(LogicalTape *lt, void *ptr, size_t size)
+LogicalTapeWrite(LogicalTape *lt, const void *ptr, size_t size)
 {
        LogicalTapeSet *lts = lt->tapeSet;
        size_t          nthistime;
@@ -826,7 +826,7 @@ LogicalTapeWrite(LogicalTape *lt, void *ptr, size_t size)
                lt->pos += nthistime;
                if (lt->nbytes < lt->pos)
                        lt->nbytes = lt->pos;
-               ptr = (char *) ptr + nthistime;
+               ptr = (const char *) ptr + nthistime;
                size -= nthistime;
        }
 }
index a4922d18530a4aebbbc6d5281dc5bef968ae9b9b..636a0b9071b6b8326ee8d17f90d76d46dc650787 100644 (file)
@@ -39,7 +39,7 @@ typedef struct BufFile BufFile;
 extern BufFile *BufFileCreateTemp(bool interXact);
 extern void BufFileClose(BufFile *file);
 extern size_t BufFileRead(BufFile *file, void *ptr, size_t size);
-extern void BufFileWrite(BufFile *file, void *ptr, size_t size);
+extern void BufFileWrite(BufFile *file, const void *ptr, size_t size);
 extern int     BufFileSeek(BufFile *file, int fileno, off_t offset, int whence);
 extern void BufFileTell(BufFile *file, int *fileno, off_t *offset);
 extern int     BufFileSeekBlock(BufFile *file, long blknum);
index 8c742ac491d8c8d38ed65f94c59bca93c44b0547..1afd527e13d3e42c3c37e5d2f53704c3d3b5a941 100644 (file)
@@ -66,7 +66,7 @@ extern LogicalTape *LogicalTapeCreate(LogicalTapeSet *lts);
 extern LogicalTape *LogicalTapeImport(LogicalTapeSet *lts, int worker, TapeShare *shared);
 extern void LogicalTapeSetForgetFreeSpace(LogicalTapeSet *lts);
 extern size_t LogicalTapeRead(LogicalTape *lt, void *ptr, size_t size);
-extern void LogicalTapeWrite(LogicalTape *lt, void *ptr, size_t size);
+extern void LogicalTapeWrite(LogicalTape *lt, const void *ptr, size_t size);
 extern void LogicalTapeRewindForRead(LogicalTape *lt, size_t buffer_size);
 extern void LogicalTapeFreeze(LogicalTape *lt, TapeShare *share);
 extern size_t LogicalTapeBackspace(LogicalTape *lt, size_t size);