mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2024-12-12 10:04:14 +02:00
Put logging functions unused by release builds into DEBUG blocks.
Also inline some functions that are needed in non-DEBUG builds.
This commit is contained in:
parent
4a64c5d80c
commit
8aa2b101bb
@ -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)
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user