Add const to BufFileWrite

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
This commit is contained in:
Peter Eisentraut 2022-12-30 10:02:59 +01:00
parent 5f2f99c9c6
commit faf3750657
6 changed files with 12 additions and 12 deletions

View File

@ -38,7 +38,7 @@ static long gistBuffersGetFreeBlock(GISTBuildBuffers *gfbb);
static void gistBuffersReleaseBlock(GISTBuildBuffers *gfbb, long blocknum); static void gistBuffersReleaseBlock(GISTBuildBuffers *gfbb, long blocknum);
static void ReadTempFileBlock(BufFile *file, long blknum, void *ptr); 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 static void
WriteTempFileBlock(BufFile *file, long blknum, void *ptr) WriteTempFileBlock(BufFile *file, long blknum, const void *ptr)
{ {
if (BufFileSeekBlock(file, blknum) != 0) if (BufFileSeekBlock(file, blknum) != 0)
elog(ERROR, "could not seek to block %ld in temporary file", blknum); elog(ERROR, "could not seek to block %ld in temporary file", blknum);

View File

@ -21,7 +21,7 @@
#include "utils/builtins.h" #include "utils/builtins.h"
#include "utils/json.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? * Does the user want a backup manifest?
@ -385,7 +385,7 @@ SendBackupManifest(backup_manifest_info *manifest, bbsink *sink)
* Append a cstring to the manifest. * Append a cstring to the manifest.
*/ */
static void static void
AppendStringToManifest(backup_manifest_info *manifest, char *s) AppendStringToManifest(backup_manifest_info *manifest, const char *s)
{ {
int len = strlen(s); int len = strlen(s);

View File

@ -622,7 +622,7 @@ BufFileRead(BufFile *file, void *ptr, size_t size)
* ereport(). * ereport().
*/ */
void void
BufFileWrite(BufFile *file, void *ptr, size_t size) BufFileWrite(BufFile *file, const void *ptr, size_t size)
{ {
size_t nthistime; size_t nthistime;
@ -655,7 +655,7 @@ BufFileWrite(BufFile *file, void *ptr, size_t size)
file->pos += nthistime; file->pos += nthistime;
if (file->nbytes < file->pos) if (file->nbytes < file->pos)
file->nbytes = file->pos; file->nbytes = file->pos;
ptr = (char *) ptr + nthistime; ptr = (const char *) ptr + nthistime;
size -= nthistime; size -= nthistime;
} }
} }

View File

@ -220,7 +220,7 @@ struct LogicalTapeSet
}; };
static LogicalTape *ltsCreateTape(LogicalTapeSet *lts); 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 void ltsReadBlock(LogicalTapeSet *lts, long blocknum, void *buffer);
static long ltsGetBlock(LogicalTapeSet *lts, LogicalTape *lt); static long ltsGetBlock(LogicalTapeSet *lts, LogicalTape *lt);
static long ltsGetFreeBlock(LogicalTapeSet *lts); 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. * No need for an error return convention; we ereport() on any error.
*/ */
static void 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 * 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. * There are no error returns; we ereport() on failure.
*/ */
void void
LogicalTapeWrite(LogicalTape *lt, void *ptr, size_t size) LogicalTapeWrite(LogicalTape *lt, const void *ptr, size_t size)
{ {
LogicalTapeSet *lts = lt->tapeSet; LogicalTapeSet *lts = lt->tapeSet;
size_t nthistime; size_t nthistime;
@ -826,7 +826,7 @@ LogicalTapeWrite(LogicalTape *lt, void *ptr, size_t size)
lt->pos += nthistime; lt->pos += nthistime;
if (lt->nbytes < lt->pos) if (lt->nbytes < lt->pos)
lt->nbytes = lt->pos; lt->nbytes = lt->pos;
ptr = (char *) ptr + nthistime; ptr = (const char *) ptr + nthistime;
size -= nthistime; size -= nthistime;
} }
} }

View File

@ -39,7 +39,7 @@ typedef struct BufFile BufFile;
extern BufFile *BufFileCreateTemp(bool interXact); extern BufFile *BufFileCreateTemp(bool interXact);
extern void BufFileClose(BufFile *file); extern void BufFileClose(BufFile *file);
extern size_t BufFileRead(BufFile *file, void *ptr, size_t size); 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 int BufFileSeek(BufFile *file, int fileno, off_t offset, int whence);
extern void BufFileTell(BufFile *file, int *fileno, off_t *offset); extern void BufFileTell(BufFile *file, int *fileno, off_t *offset);
extern int BufFileSeekBlock(BufFile *file, long blknum); extern int BufFileSeekBlock(BufFile *file, long blknum);

View File

@ -66,7 +66,7 @@ extern LogicalTape *LogicalTapeCreate(LogicalTapeSet *lts);
extern LogicalTape *LogicalTapeImport(LogicalTapeSet *lts, int worker, TapeShare *shared); extern LogicalTape *LogicalTapeImport(LogicalTapeSet *lts, int worker, TapeShare *shared);
extern void LogicalTapeSetForgetFreeSpace(LogicalTapeSet *lts); extern void LogicalTapeSetForgetFreeSpace(LogicalTapeSet *lts);
extern size_t LogicalTapeRead(LogicalTape *lt, void *ptr, size_t size); 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 LogicalTapeRewindForRead(LogicalTape *lt, size_t buffer_size);
extern void LogicalTapeFreeze(LogicalTape *lt, TapeShare *share); extern void LogicalTapeFreeze(LogicalTape *lt, TapeShare *share);
extern size_t LogicalTapeBackspace(LogicalTape *lt, size_t size); extern size_t LogicalTapeBackspace(LogicalTape *lt, size_t size);