Add INT64_HEX_FORMAT and UINT64_HEX_FORMAT to c.h.
authorNathan Bossart <[email protected]>
Fri, 22 Nov 2024 18:41:57 +0000 (12:41 -0600)
committerNathan Bossart <[email protected]>
Fri, 22 Nov 2024 18:41:57 +0000 (12:41 -0600)
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

contrib/postgres_fdw/option.c
src/backend/utils/error/csvlog.c
src/backend/utils/error/elog.c
src/backend/utils/error/jsonlog.c
src/include/c.h
src/test/modules/test_radixtree/test_radixtree.c

index ed11126c09e187a8be880fc0c6367e0e32454306..232d85354b2980180a52c0a967418a8faeccdec1 100644 (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);
index eab8df3fcc3fffa4fc08ffd59716b94040fa870f..acdffb6d0673f10c705f64988e2dab89f799d5ef 100644 (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 */
index 8acca3e0a0b5b33d4e70dfdccf7c820e5ced820e..20b4b33228e1ba495aa7ca3f5031e7914d589cbb 100644 (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)
index 2c7b14cacb14b048ca8a815dc007a806aac07686..492383a89e250e36d716005ed914dd5005aaa697 100644 (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 */
index 0a548d69d7f483b59aa22b0eef7f67eec7d32a0f..4a6b361231ce623c16e204c190ba5f2e154c5d93 100644 (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
index 3e072fa5ec6efe4a7e987680f6e6c6458232cad0..3e5aa3720c76f8494d452bc0f7a2ce85465c300c 100644 (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 { \