1
0
mirror of https://github.com/postgres/postgres.git synced 2026-10-23 13:29:09 +03:00

Make blkreftable API use size_t/ssize_t consistently

It was using int for the input and output length, where size_t or
ssize_t would be more appropriate.  It might not matter in practice,
but it makes the APIs consistent at all levels.

Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi>
Discussion: https://www.postgresql.org/message-id/flat/f9aab072-0078-49e4-ab93-3b08086a4406@eisentraut.org
This commit is contained in:
Peter Eisentraut
2026-07-13 11:01:36 +02:00
parent 1ae87df63f
commit 7b87f08e87
5 changed files with 23 additions and 23 deletions

View File

@@ -269,11 +269,11 @@ IsWalSummaryFilename(char *filename)
/*
* Data read callback for use with CreateBlockRefTableReader.
*/
int
ReadWalSummary(void *wal_summary_io, void *data, int length)
size_t
ReadWalSummary(void *wal_summary_io, void *data, size_t length)
{
WalSummaryIO *io = wal_summary_io;
int nbytes;
ssize_t nbytes;
nbytes = FileRead(io->file, data, length, io->filepos,
WAIT_EVENT_WAL_SUMMARY_READ);
@@ -290,11 +290,11 @@ ReadWalSummary(void *wal_summary_io, void *data, int length)
/*
* Data write callback for use with WriteBlockRefTable.
*/
int
WriteWalSummary(void *wal_summary_io, void *data, int length)
size_t
WriteWalSummary(void *wal_summary_io, void *data, size_t length)
{
WalSummaryIO *io = wal_summary_io;
int nbytes;
ssize_t nbytes;
nbytes = FileWrite(io->file, data, length, io->filepos,
WAIT_EVENT_WAL_SUMMARY_WRITE);
@@ -306,7 +306,7 @@ WriteWalSummary(void *wal_summary_io, void *data, int length)
if (nbytes != length)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not write file \"%s\": wrote only %d of %d bytes at offset %lld",
errmsg("could not write file \"%s\": wrote only %zd of %zu bytes at offset %lld",
FilePathName(io->file), nbytes,
length, (long long) io->filepos),
errhint("Check free disk space.")));

View File

@@ -41,8 +41,8 @@ static void dump_one_relation(ws_options *opt, RelFileLocator *rlocator,
BlockRefTableReader *reader);
static void help(const char *progname);
static int compare_block_numbers(const void *a, const void *b);
static int walsummary_read_callback(void *callback_arg, void *data,
int length);
static size_t walsummary_read_callback(void *callback_arg, void *data,
size_t length);
static void walsummary_error_callback(void *callback_arg, char *fmt, ...) pg_attribute_printf(2, 3);
/*
@@ -241,11 +241,11 @@ walsummary_error_callback(void *callback_arg, char *fmt, ...)
/*
* Read callback.
*/
int
walsummary_read_callback(void *callback_arg, void *data, int length)
size_t
walsummary_read_callback(void *callback_arg, void *data, size_t length)
{
ws_file_info *ws = callback_arg;
int rc;
ssize_t rc;
if ((rc = read(ws->fd, data, length)) < 0)
pg_fatal("could not read file \"%s\": %m", ws->filename);

View File

@@ -173,8 +173,8 @@ typedef struct BlockRefTableBuffer
io_callback_fn io_callback;
void *io_callback_arg;
char data[BUFSIZE];
int used;
int cursor;
size_t used;
size_t cursor;
pg_crc32c crc;
} BlockRefTableBuffer;
@@ -223,9 +223,9 @@ struct BlockRefTableWriter
static int BlockRefTableComparator(const void *a, const void *b);
static void BlockRefTableFlush(BlockRefTableBuffer *buffer);
static void BlockRefTableRead(BlockRefTableReader *reader, void *data,
int length);
size_t length);
static void BlockRefTableWrite(BlockRefTableBuffer *buffer, void *data,
int length);
size_t length);
static void BlockRefTableFileTerminate(BlockRefTableBuffer *buffer);
/*
@@ -1206,7 +1206,7 @@ BlockRefTableFlush(BlockRefTableBuffer *buffer)
* buffered but not yet actually returned).
*/
static void
BlockRefTableRead(BlockRefTableReader *reader, void *data, int length)
BlockRefTableRead(BlockRefTableReader *reader, void *data, size_t length)
{
BlockRefTableBuffer *buffer = &reader->buffer;
@@ -1219,7 +1219,7 @@ BlockRefTableRead(BlockRefTableReader *reader, void *data, int length)
* If any buffered data is available, use that to satisfy as much
* of the request as possible.
*/
int bytes_to_copy = Min(length, buffer->used - buffer->cursor);
size_t bytes_to_copy = Min(length, buffer->used - buffer->cursor);
memcpy(data, &buffer->data[buffer->cursor], bytes_to_copy);
COMP_CRC32C(buffer->crc, &buffer->data[buffer->cursor],
@@ -1234,7 +1234,7 @@ BlockRefTableRead(BlockRefTableReader *reader, void *data, int length)
* If the request length is long, read directly into caller's
* buffer.
*/
int bytes_read;
size_t bytes_read;
bytes_read = buffer->io_callback(buffer->io_callback_arg,
data, length);
@@ -1271,7 +1271,7 @@ BlockRefTableRead(BlockRefTableReader *reader, void *data, int length)
* and update the running CRC calculation for that data.
*/
static void
BlockRefTableWrite(BlockRefTableBuffer *buffer, void *data, int length)
BlockRefTableWrite(BlockRefTableBuffer *buffer, void *data, size_t length)
{
/* Update running CRC calculation. */
COMP_CRC32C(buffer->crc, data, length);

View File

@@ -42,8 +42,8 @@ extern File OpenWalSummaryFile(WalSummaryFile *ws, bool missing_ok);
extern void RemoveWalSummaryIfOlderThan(WalSummaryFile *ws,
time_t cutoff_time);
extern int ReadWalSummary(void *wal_summary_io, void *data, int length);
extern int WriteWalSummary(void *wal_summary_io, void *data, int length);
extern size_t ReadWalSummary(void *wal_summary_io, void *data, size_t length);
extern size_t WriteWalSummary(void *wal_summary_io, void *data, size_t length);
extern void ReportWalSummaryError(void *callback_arg, char *fmt, ...) pg_attribute_printf(2, 3);
#endif /* WALSUMMARY_H */

View File

@@ -43,7 +43,7 @@ typedef struct BlockRefTableWriter BlockRefTableWriter;
*
* report_error_fn should not return.
*/
typedef int (*io_callback_fn) (void *callback_arg, void *data, int length);
typedef size_t (*io_callback_fn) (void *callback_arg, void *data, size_t length);
typedef void (*report_error_fn) (void *callback_arg, char *msg, ...) pg_attribute_printf(2, 3);