1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-03 01:21:48 +03:00

Add INT64_HEX_FORMAT and UINT64_HEX_FORMAT to c.h.

Like INT64_FORMAT and UINT64_FORMAT, these macros produce format
strings for 64-bit integers.  However, INT64_HEX_FORMAT and
UINT64_HEX_FORMAT generate the output in hexadecimal instead of
decimal.  Besides introducing these macros, this commit makes use
of them in several places.  This was originally intended to be part
of commit 5d6187d2a2, but I left it out because I felt there was a
nonzero chance that back-patching these new macros into c.h could
cause problems with third-party code.  We tend to be less cautious
with such changes in new major versions.

Note that UINT64_HEX_FORMAT was originally added in commit
ee1b30f128, but it was placed in test_radixtree.c, so it wasn't
widely available.  This commit moves UINT64_HEX_FORMAT to c.h.

Discussion: https://postgr.es/m/ZwQvtUbPKaaRQezd%40nathan
This commit is contained in:
Nathan Bossart 2024-11-22 12:41:57 -06:00
parent 8589876b79
commit efdc7d7475
6 changed files with 7 additions and 7 deletions

View File

@ -521,7 +521,7 @@ process_pgfdw_appname(const char *appname)
appendStringInfoString(&buf, application_name);
break;
case 'c':
appendStringInfo(&buf, "%" INT64_MODIFIER "x.%x", MyStartTime, MyProcPid);
appendStringInfo(&buf, INT64_HEX_FORMAT ".%x", MyStartTime, MyProcPid);
break;
case 'C':
appendStringInfoString(&buf, cluster_name);

View File

@ -120,7 +120,7 @@ write_csvlog(ErrorData *edata)
appendStringInfoChar(&buf, ',');
/* session id */
appendStringInfo(&buf, "%" INT64_MODIFIER "x.%x", MyStartTime, MyProcPid);
appendStringInfo(&buf, INT64_HEX_FORMAT ".%x", MyStartTime, MyProcPid);
appendStringInfoChar(&buf, ',');
/* Line number */

View File

@ -2947,12 +2947,12 @@ log_status_format(StringInfo buf, const char *format, ErrorData *edata)
{
char strfbuf[128];
snprintf(strfbuf, sizeof(strfbuf) - 1, "%" INT64_MODIFIER "x.%x",
snprintf(strfbuf, sizeof(strfbuf) - 1, INT64_HEX_FORMAT ".%x",
MyStartTime, MyProcPid);
appendStringInfo(buf, "%*s", padding, strfbuf);
}
else
appendStringInfo(buf, "%" INT64_MODIFIER "x.%x", MyStartTime, MyProcPid);
appendStringInfo(buf, INT64_HEX_FORMAT ".%x", MyStartTime, MyProcPid);
break;
case 'p':
if (padding != 0)

View File

@ -168,7 +168,7 @@ write_jsonlog(ErrorData *edata)
}
/* Session id */
appendJSONKeyValueFmt(&buf, "session_id", true, "%" INT64_MODIFIER "x.%x",
appendJSONKeyValueFmt(&buf, "session_id", true, INT64_HEX_FORMAT ".%x",
MyStartTime, MyProcPid);
/* Line number */

View File

@ -550,6 +550,8 @@ typedef unsigned long long int uint64;
/* snprintf format strings to use for 64-bit integers */
#define INT64_FORMAT "%" INT64_MODIFIER "d"
#define UINT64_FORMAT "%" INT64_MODIFIER "u"
#define INT64_HEX_FORMAT "%" INT64_MODIFIER "x"
#define UINT64_HEX_FORMAT "%" INT64_MODIFIER "x"
/*
* 128-bit signed and unsigned integers

View File

@ -21,8 +21,6 @@
/* uncomment to use shared memory for the tree */
/* #define TEST_SHARED_RT */
#define UINT64_HEX_FORMAT "%" INT64_MODIFIER "X"
/* Convenient macros to test results */
#define EXPECT_TRUE(expr) \
do { \