pgbackrest.git / summary / log / commit / refs
commit 8aa2b101bbd9fe07971794bf4bb4c8d2a61c7b07
Author: David Steele <david@pgmasters.net>
Date: Sat Dec 31 09:41:01 2022 +0000
Put logging functions unused by release builds into DEBUG blocks.
Also inline some functions that are needed in non-DEBUG builds.
src/common/debug.c | 7 -------
src/common/debug.h | 6 +++++-
src/common/io/http/url.c | 4 ++++
src/common/io/http/url.h | 4 ++++
src/common/type/convert.c | 20 --------------------
src/common/type/convert.h | 13 +++++++++++--
src/common/type/json.c | 8 ++++++++
src/common/type/json.h | 12 ++++++++----
test/src/module/common/typeConvertTest.c | 2 --
9 files changed, 40 insertions(+), 36 deletions(-)
diff --git a/src/common/debug.c b/src/common/debug.c
index 0ef6df345..e5e929025 100644
--- a/src/common/debug.c
+++ b/src/common/debug.c
@@ -35,13 +35,6 @@ ptrToLog(const void *pointer, const char *pointerName, char *buffer, size_t buff
return result;
}
-/**********************************************************************************************************************************/
-size_t
-strzToLog(const char *string, char *buffer, size_t bufferSize)
-{
- return (size_t)snprintf(buffer, bufferSize, string == NULL ? "%s" : "\"%s\"", string == NULL ? NULL_Z : string);
-}
-
/**********************************************************************************************************************************/
size_t
typeToLog(const char *typeName, char *buffer, size_t bufferSize)
diff --git a/src/common/debug.h b/src/common/debug.h
index 96989a22f..b40698881 100644
--- a/src/common/debug.h
+++ b/src/common/debug.h
@@ -104,7 +104,11 @@ size_t objToLog(const void *object, const char *objectName, char *buffer, size_t
size_t ptrToLog(const void *pointer, const char *pointerName, char *buffer, size_t bufferSize);
// Convert zero-terminated string for logging
-size_t strzToLog(const char *string, char *buffer, size_t bufferSize);
+FN_INLINE_ALWAYS size_t
+strzToLog(const char *const string, char *const buffer, const size_t bufferSize)
+{
+ return (size_t)snprintf(buffer, bufferSize, string == NULL ? "%s" : "\"%s\"", string == NULL ? NULL_Z : string);
+}
// Convert a type name to a zero-terminated string for logging
size_t typeToLog(const char *typeName, char *buffer, size_t bufferSize);
diff --git a/src/common/io/http/url.c b/src/common/io/http/url.c
index 8dd8234e6..6866ebf55 100644
--- a/src/common/io/http/url.c
+++ b/src/common/io/http/url.c
@@ -195,6 +195,8 @@ httpUrlNewParse(const String *const url, HttpUrlNewParseParam param)
}
/**********************************************************************************************************************************/
+#ifdef DEBUG
+
String *
httpUrlToLog(const HttpUrl *this)
{
@@ -205,3 +207,5 @@ httpUrlToLog(const HttpUrl *this)
"{%s://%s%s%s:%u%s}", strZ(httpProtocolTypeStr(this->pub.type)), ipv6 ? "[" : "", strZ(this->pub.host), ipv6 ? "]" : "",
this->pub.port, strZ(this->pub.path));
}
+
+#endif // DEBUG
diff --git a/src/common/io/http/url.h b/src/common/io/http/url.h
index ffce6886a..21f7aaaa5 100644
--- a/src/common/io/http/url.h
+++ b/src/common/io/http/url.h
@@ -98,6 +98,8 @@ httpUrlFree(HttpUrl *const this)
/***********************************************************************************************************************************
Macros for function logging
***********************************************************************************************************************************/
+#ifdef DEBUG
+
String *httpUrlToLog(const HttpUrl *this);
#define FUNCTION_LOG_HTTP_URL_TYPE \
@@ -105,4 +107,6 @@ String *httpUrlToLog(const HttpUrl *this);
#define FUNCTION_LOG_HTTP_URL_FORMAT(value, buffer, bufferSize) \
FUNCTION_LOG_STRING_OBJECT_FORMAT(value, httpUrlToLog, buffer, bufferSize)
+#endif // DEBUG
+
#endif
diff --git a/src/common/type/convert.c b/src/common/type/convert.c
index ee211b918..acaa2baba 100644
--- a/src/common/type/convert.c
+++ b/src/common/type/convert.c
@@ -117,26 +117,6 @@ cvtBoolToConstZ(bool value)
return value ? TRUE_Z : FALSE_Z;
}
-/**********************************************************************************************************************************/
-size_t
-cvtCharToZ(char value, char *buffer, size_t bufferSize)
-{
- FUNCTION_TEST_BEGIN();
- FUNCTION_TEST_PARAM(BOOL, value);
- FUNCTION_TEST_PARAM_P(CHARDATA, buffer);
- FUNCTION_TEST_PARAM(SIZE, bufferSize);
- FUNCTION_TEST_END();
-
- ASSERT(buffer != NULL);
-
- size_t result = (size_t)snprintf(buffer, bufferSize, "%c", value);
-
- if (result >= bufferSize)
- THROW(AssertError, "buffer overflow");
-
- FUNCTION_TEST_RETURN(SIZE, result);
-}
-
/**********************************************************************************************************************************/
size_t
cvtDoubleToZ(double value, char *buffer, size_t bufferSize)
diff --git a/src/common/type/convert.h b/src/common/type/convert.h
index 09edffdb9..f5f0d4080 100644
--- a/src/common/type/convert.h
+++ b/src/common/type/convert.h
@@ -8,8 +8,11 @@ Contains conversions to/from native C types. Conversions of project types should
#include <inttypes.h>
#include <stdbool.h>
+#include <stdio.h>
#include <sys/types.h>
+#include "common/assert.h"
+
/***********************************************************************************************************************************
Required buffer sizes
***********************************************************************************************************************************/
@@ -21,7 +24,14 @@ Required buffer sizes
Functions
***********************************************************************************************************************************/
// Convert char to zero-terminated string
-size_t cvtCharToZ(char value, char *buffer, size_t bufferSize);
+FN_INLINE_ALWAYS size_t
+cvtCharToZ(const char value, char *const buffer, const size_t bufferSize)
+{
+ ASSERT_INLINE(buffer != NULL);
+ ASSERT_INLINE(bufferSize >= 2);
+
+ return (size_t)snprintf(buffer, bufferSize, "%c", value);
+}
// Convert double to zero-terminated string and vice versa
size_t cvtDoubleToZ(double value, char *buffer, size_t bufferSize);
@@ -51,7 +61,6 @@ cvtZSubNToInt64(const char *const value, const size_t offset, const size_t size)
return cvtZSubNToInt64Base(value, offset, size, 10);
}
-
// Convert int32/64 to uint32/64 using zigzag encoding and vice versa. Zigzag encoding places the sign in the least significant bit
// so that signed and unsigned values alternate, e.g. 0 = 0, -1 = 1, 1 = 2, -2 = 3, 2 = 4, -3 = 5, 3 = 6, etc. This moves as many
// bits as possible into the low order bits which is good for other types of encoding, e.g. base-128. See
diff --git a/src/common/type/json.c b/src/common/type/json.c
index bab2ee6be..790d9a3c6 100644
--- a/src/common/type/json.c
+++ b/src/common/type/json.c
@@ -1293,12 +1293,16 @@ jsonValidate(const String *const json)
}
/**********************************************************************************************************************************/
+#ifdef DEBUG
+
String *
jsonReadToLog(const JsonRead *const this)
{
return strNewFmt("{json: %s}", this->json);
}
+#endif // DEBUG
+
/**********************************************************************************************************************************/
JsonWrite *
jsonWriteNew(JsonWriteNewParam param)
@@ -2041,8 +2045,12 @@ jsonFromVar(const Variant *const value)
}
/**********************************************************************************************************************************/
+#ifdef DEBUG
+
String *
jsonWriteToLog(const JsonWrite *const this)
{
return strNewFmt("{size: %zu}", strSize(this->json));
}
+
+#endif // DEBUG
diff --git a/src/common/type/json.h b/src/common/type/json.h
index 97ab1b8f8..3ea64ab02 100644
--- a/src/common/type/json.h
+++ b/src/common/type/json.h
@@ -182,18 +182,22 @@ String *jsonFromVar(const Variant *value);
/***********************************************************************************************************************************
Macros for function logging
***********************************************************************************************************************************/
+#ifdef DEBUG
+
String *jsonReadToLog(const JsonRead *this);
-#define FUNCTION_LOG_JSON_READ_TYPE \
+#define FUNCTION_LOG_JSON_READ_TYPE \
JsonRead *
-#define FUNCTION_LOG_JSON_READ_FORMAT(value, buffer, bufferSize) \
+#define FUNCTION_LOG_JSON_READ_FORMAT(value, buffer, bufferSize) \
FUNCTION_LOG_STRING_OBJECT_FORMAT(value, jsonReadToLog, buffer, bufferSize)
String *jsonWriteToLog(const JsonWrite *this);
-#define FUNCTION_LOG_JSON_WRITE_TYPE \
+#define FUNCTION_LOG_JSON_WRITE_TYPE \
JsonWrite *
-#define FUNCTION_LOG_JSON_WRITE_FORMAT(value, buffer, bufferSize) \
+#define FUNCTION_LOG_JSON_WRITE_FORMAT(value, buffer, bufferSize) \
FUNCTION_LOG_STRING_OBJECT_FORMAT(value, jsonWriteToLog, buffer, bufferSize)
+#endif // DEBUG
+
#endif
diff --git a/test/src/module/common/typeConvertTest.c b/test/src/module/common/typeConvertTest.c
index 45863b411..a669e1ef6 100644
--- a/test/src/module/common/typeConvertTest.c
+++ b/test/src/module/common/typeConvertTest.c
@@ -29,8 +29,6 @@ testRun(void)
{
char buffer[STACK_TRACE_PARAM_MAX];
- TEST_ERROR(cvtCharToZ('A', buffer, 1), AssertError, "buffer overflow");
-
TEST_RESULT_UINT(cvtCharToZ('C', buffer, STACK_TRACE_PARAM_MAX), 1, "convert char to string");
TEST_RESULT_Z(buffer, "C", " check buffer");
}
[parent: 4a64c5d80c9a]