Commit 6a1cd8b9 authored by Peter Eisentraut's avatar Peter Eisentraut

Unwind some workarounds for lack of portable int64 format specifier

Because there is no portable int64/uint64 format specifier and we
can't stick macros like INT64_FORMAT into the middle of a translatable
string, we have been using various workarounds that put the number to
be printed into a string buffer first.  Now that we always use our own
sprintf(), we can rely on %lld and %llu to work, so we can use those.

This patch undoes this workaround in a few places where it was
egregiously verbose.
Reviewed-by: default avatarTom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/flat/CAH2-Wz%3DWbNxc5ob5NJ9yqo2RMJ0q4HXDS30GVCobeCvC9A1L9A%40mail.gmail.com
parent 7b925e12
...@@ -783,20 +783,10 @@ XLogReaderValidatePageHeader(XLogReaderState *state, XLogRecPtr recptr, ...@@ -783,20 +783,10 @@ XLogReaderValidatePageHeader(XLogReaderState *state, XLogRecPtr recptr,
if (state->system_identifier && if (state->system_identifier &&
longhdr->xlp_sysid != state->system_identifier) longhdr->xlp_sysid != state->system_identifier)
{ {
char fhdrident_str[32];
char sysident_str[32];
/*
* Format sysids separately to keep platform-dependent format code
* out of the translatable message string.
*/
snprintf(fhdrident_str, sizeof(fhdrident_str), UINT64_FORMAT,
longhdr->xlp_sysid);
snprintf(sysident_str, sizeof(sysident_str), UINT64_FORMAT,
state->system_identifier);
report_invalid_record(state, report_invalid_record(state,
"WAL file is from different database system: WAL file database system identifier is %s, pg_control database system identifier is %s", "WAL file is from different database system: WAL file database system identifier is %llu, pg_control database system identifier is %llu",
fhdrident_str, sysident_str); (unsigned long long) longhdr->xlp_sysid,
(unsigned long long) state->system_identifier);
return false; return false;
} }
else if (longhdr->xlp_seg_size != state->wal_segment_size) else if (longhdr->xlp_seg_size != state->wal_segment_size)
......
...@@ -106,7 +106,7 @@ static TimestampTz throttled_last; ...@@ -106,7 +106,7 @@ static TimestampTz throttled_last;
static XLogRecPtr startptr; static XLogRecPtr startptr;
/* Total number of checksum failures during base backup. */ /* Total number of checksum failures during base backup. */
static int64 total_checksum_failures; static long long int total_checksum_failures;
/* Do not verify checksums. */ /* Do not verify checksums. */
static bool noverify_checksums = false; static bool noverify_checksums = false;
...@@ -607,14 +607,9 @@ perform_base_backup(basebackup_options *opt) ...@@ -607,14 +607,9 @@ perform_base_backup(basebackup_options *opt)
if (total_checksum_failures) if (total_checksum_failures)
{ {
if (total_checksum_failures > 1) if (total_checksum_failures > 1)
{
char buf[64];
snprintf(buf, sizeof(buf), INT64_FORMAT, total_checksum_failures);
ereport(WARNING, ereport(WARNING,
(errmsg("%s total checksum verification failures", buf))); (errmsg("%lld total checksum verification failures", total_checksum_failures)));
}
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_DATA_CORRUPTED), (errcode(ERRCODE_DATA_CORRUPTED),
errmsg("checksum verification failure during base backup"))); errmsg("checksum verification failure during base backup")));
......
...@@ -99,7 +99,6 @@ main(int argc, char *argv[]) ...@@ -99,7 +99,6 @@ main(int argc, char *argv[])
time_t time_tmp; time_t time_tmp;
char pgctime_str[128]; char pgctime_str[128];
char ckpttime_str[128]; char ckpttime_str[128];
char sysident_str[32];
char mock_auth_nonce_str[MOCK_AUTH_NONCE_LEN * 2 + 1]; char mock_auth_nonce_str[MOCK_AUTH_NONCE_LEN * 2 + 1];
const char *strftime_fmt = "%c"; const char *strftime_fmt = "%c";
const char *progname; const char *progname;
...@@ -222,13 +221,6 @@ main(int argc, char *argv[]) ...@@ -222,13 +221,6 @@ main(int argc, char *argv[])
else else
strcpy(xlogfilename, _("???")); strcpy(xlogfilename, _("???"));
/*
* Format system_identifier and mock_authentication_nonce separately to
* keep platform-dependent format code out of the translatable message
* string.
*/
snprintf(sysident_str, sizeof(sysident_str), UINT64_FORMAT,
ControlFile->system_identifier);
for (i = 0; i < MOCK_AUTH_NONCE_LEN; i++) for (i = 0; i < MOCK_AUTH_NONCE_LEN; i++)
snprintf(&mock_auth_nonce_str[i * 2], 3, "%02x", snprintf(&mock_auth_nonce_str[i * 2], 3, "%02x",
(unsigned char) ControlFile->mock_authentication_nonce[i]); (unsigned char) ControlFile->mock_authentication_nonce[i]);
...@@ -237,8 +229,8 @@ main(int argc, char *argv[]) ...@@ -237,8 +229,8 @@ main(int argc, char *argv[])
ControlFile->pg_control_version); ControlFile->pg_control_version);
printf(_("Catalog version number: %u\n"), printf(_("Catalog version number: %u\n"),
ControlFile->catalog_version_no); ControlFile->catalog_version_no);
printf(_("Database system identifier: %s\n"), printf(_("Database system identifier: %llu\n"),
sysident_str); (unsigned long long) ControlFile->system_identifier);
printf(_("Database cluster state: %s\n"), printf(_("Database cluster state: %s\n"),
dbState(ControlFile->state)); dbState(ControlFile->state));
printf(_("pg_control last modified: %s\n"), printf(_("pg_control last modified: %s\n"),
......
...@@ -748,26 +748,17 @@ GuessControlValues(void) ...@@ -748,26 +748,17 @@ GuessControlValues(void)
static void static void
PrintControlValues(bool guessed) PrintControlValues(bool guessed)
{ {
char sysident_str[32];
if (guessed) if (guessed)
printf(_("Guessed pg_control values:\n\n")); printf(_("Guessed pg_control values:\n\n"));
else else
printf(_("Current pg_control values:\n\n")); printf(_("Current pg_control values:\n\n"));
/*
* Format system_identifier separately to keep platform-dependent format
* code out of the translatable message string.
*/
snprintf(sysident_str, sizeof(sysident_str), UINT64_FORMAT,
ControlFile.system_identifier);
printf(_("pg_control version number: %u\n"), printf(_("pg_control version number: %u\n"),
ControlFile.pg_control_version); ControlFile.pg_control_version);
printf(_("Catalog version number: %u\n"), printf(_("Catalog version number: %u\n"),
ControlFile.catalog_version_no); ControlFile.catalog_version_no);
printf(_("Database system identifier: %s\n"), printf(_("Database system identifier: %llu\n"),
sysident_str); (unsigned long long) ControlFile.system_identifier);
printf(_("Latest checkpoint's TimeLineID: %u\n"), printf(_("Latest checkpoint's TimeLineID: %u\n"),
ControlFile.checkPointCopy.ThisTimeLineID); ControlFile.checkPointCopy.ThisTimeLineID);
printf(_("Latest checkpoint's full_page_writes: %s\n"), printf(_("Latest checkpoint's full_page_writes: %s\n"),
......
...@@ -251,7 +251,6 @@ receiveFileChunks(const char *sql) ...@@ -251,7 +251,6 @@ receiveFileChunks(const char *sql)
char *filename; char *filename;
int filenamelen; int filenamelen;
int64 chunkoff; int64 chunkoff;
char chunkoff_str[32];
int chunksize; int chunksize;
char *chunk; char *chunk;
...@@ -327,13 +326,8 @@ receiveFileChunks(const char *sql) ...@@ -327,13 +326,8 @@ receiveFileChunks(const char *sql)
continue; continue;
} }
/* pg_log_debug("received chunk for file \"%s\", offset %lld, size %d",
* Separate step to keep platform-dependent format code out of filename, (long long int) chunkoff, chunksize);
* translatable strings.
*/
snprintf(chunkoff_str, sizeof(chunkoff_str), INT64_FORMAT, chunkoff);
pg_log_debug("received chunk for file \"%s\", offset %s, size %d",
filename, chunkoff_str, chunksize);
open_target_file(filename, false); open_target_file(filename, false);
......
...@@ -18,7 +18,7 @@ static uint64 test_timing(int32); ...@@ -18,7 +18,7 @@ static uint64 test_timing(int32);
static void output(uint64 loop_count); static void output(uint64 loop_count);
/* record duration in powers of 2 microseconds */ /* record duration in powers of 2 microseconds */
int64 histogram[32]; long long int histogram[32];
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
...@@ -190,14 +190,8 @@ output(uint64 loop_count) ...@@ -190,14 +190,8 @@ output(uint64 loop_count)
Max(10, len3), header3); Max(10, len3), header3);
for (i = 0; i <= max_bit; i++) for (i = 0; i <= max_bit; i++)
{ printf("%*ld %*.5f %*lld\n",
char buf[100];
/* lame hack to work around INT64_FORMAT deficiencies */
snprintf(buf, sizeof(buf), INT64_FORMAT, histogram[i]);
printf("%*ld %*.5f %*s\n",
Max(6, len1), 1l << i, Max(6, len1), 1l << i,
Max(10, len2) - 1, (double) histogram[i] * 100 / loop_count, Max(10, len2) - 1, (double) histogram[i] * 100 / loop_count,
Max(10, len3), buf); Max(10, len3), histogram[i]);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment