mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2024-12-12 10:04:14 +02:00
Add FN_PRINTF() macro.
Bring the format(printf) attribute in line with the FN_NO_RETURN and FN_INLINE_ALWAYS macros. This is simpler to read and can be customized for different compilers.
This commit is contained in:
parent
f8ea51bf8f
commit
f91af30584
@ -194,6 +194,12 @@ configuration.set(
|
|||||||
description: 'Indicate that a function should always be inlined'
|
description: 'Indicate that a function should always be inlined'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Set FN_PRINTF macro
|
||||||
|
configuration.set(
|
||||||
|
'FN_PRINTF(fmt, args)', '__attribute__((format(printf, fmt, args)))',
|
||||||
|
description: 'Indicate that a function is formatted like printf (and provide format and args position)'
|
||||||
|
)
|
||||||
|
|
||||||
####################################################################################################################################
|
####################################################################################################################################
|
||||||
# Include subdirs
|
# Include subdirs
|
||||||
####################################################################################################################################
|
####################################################################################################################################
|
||||||
|
@ -32,6 +32,9 @@ Build Flags Generated by Configure
|
|||||||
// Indicate that a function should always be inlined
|
// Indicate that a function should always be inlined
|
||||||
#define FN_INLINE_ALWAYS __attribute__((always_inline)) static inline
|
#define FN_INLINE_ALWAYS __attribute__((always_inline)) static inline
|
||||||
|
|
||||||
|
// Indicate that a function is formatted like printf (and provide format and args position)
|
||||||
|
#define FN_PRINTF(fmt, args) __attribute__((format(printf, fmt, args)))
|
||||||
|
|
||||||
// Extern function/variable required by other compilation units. Changing these to static is a meson-only feature.
|
// Extern function/variable required by other compilation units. Changing these to static is a meson-only feature.
|
||||||
#define FN_EXTERN extern
|
#define FN_EXTERN extern
|
||||||
#define VR_EXTERN_DECLARE extern
|
#define VR_EXTERN_DECLARE extern
|
||||||
|
@ -325,18 +325,16 @@ FN_EXTERN void errorInternalTryEnd(void);
|
|||||||
FN_EXTERN FN_NO_RETURN void errorInternalThrow(
|
FN_EXTERN FN_NO_RETURN void errorInternalThrow(
|
||||||
const ErrorType *errorType, const char *fileName, const char *functionName, int fileLine, const char *message,
|
const ErrorType *errorType, const char *fileName, const char *functionName, int fileLine, const char *message,
|
||||||
const char *stackTrace);
|
const char *stackTrace);
|
||||||
FN_EXTERN FN_NO_RETURN void errorInternalThrowFmt(
|
FN_EXTERN FN_NO_RETURN FN_PRINTF(5, 6) void errorInternalThrowFmt(
|
||||||
const ErrorType *errorType, const char *fileName, const char *functionName, int fileLine, const char *format, ...)
|
const ErrorType *errorType, const char *fileName, const char *functionName, int fileLine, const char *format, ...);
|
||||||
__attribute__((format(printf, 5, 6)));
|
|
||||||
|
|
||||||
// Throw a system error
|
// Throw a system error
|
||||||
FN_EXTERN FN_NO_RETURN void errorInternalThrowSys(
|
FN_EXTERN FN_NO_RETURN void errorInternalThrowSys(
|
||||||
int errNo, const ErrorType *errorType, const char *fileName, const char *functionName, int fileLine, const char *message);
|
int errNo, const ErrorType *errorType, const char *fileName, const char *functionName, int fileLine, const char *message);
|
||||||
|
|
||||||
// Throw a formatted system error
|
// Throw a formatted system error
|
||||||
FN_EXTERN FN_NO_RETURN void errorInternalThrowSysFmt(
|
FN_EXTERN FN_NO_RETURN FN_PRINTF(6, 7) void errorInternalThrowSysFmt(
|
||||||
int errNo, const ErrorType *errorType, const char *fileName, const char *functionName, int fileLine, const char *format, ...)
|
int errNo, const ErrorType *errorType, const char *fileName, const char *functionName, int fileLine, const char *format, ...);
|
||||||
__attribute__((format(printf, 6, 7)));
|
|
||||||
|
|
||||||
// Versions of the above for coverage testing which checks the error condition inside the function
|
// Versions of the above for coverage testing which checks the error condition inside the function
|
||||||
#ifdef DEBUG_COVERAGE
|
#ifdef DEBUG_COVERAGE
|
||||||
@ -344,9 +342,9 @@ FN_EXTERN FN_NO_RETURN void errorInternalThrowSysFmt(
|
|||||||
bool error, int errNo, const ErrorType *errorType, const char *fileName, const char *functionName, int fileLine,
|
bool error, int errNo, const ErrorType *errorType, const char *fileName, const char *functionName, int fileLine,
|
||||||
const char *message);
|
const char *message);
|
||||||
|
|
||||||
FN_EXTERN void errorInternalThrowOnSysFmt(
|
FN_EXTERN FN_PRINTF(7, 8) void errorInternalThrowOnSysFmt(
|
||||||
bool error, int errNo, const ErrorType *errorType, const char *fileName, const char *functionName, int fileLine,
|
bool error, int errNo, const ErrorType *errorType, const char *fileName, const char *functionName, int fileLine,
|
||||||
const char *format, ...) __attribute__((format(printf, 7, 8)));
|
const char *format, ...);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
|
@ -157,8 +157,8 @@ FN_EXTERN void logInternal(
|
|||||||
const char *functionName, int code, const char *message);
|
const char *functionName, int code, const char *message);
|
||||||
|
|
||||||
// Log function with formatting
|
// Log function with formatting
|
||||||
FN_EXTERN void logInternalFmt(
|
FN_EXTERN FN_PRINTF(8, 9) void logInternalFmt(
|
||||||
LogLevel logLevel, LogLevel logRangeMin, LogLevel logRangeMax, unsigned int processId, const char *fileName,
|
LogLevel logLevel, LogLevel logRangeMin, LogLevel logRangeMax, unsigned int processId, const char *fileName,
|
||||||
const char *functionName, int code, const char *format, ...) __attribute__((format(printf, 8, 9)));
|
const char *functionName, int code, const char *format, ...);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -251,7 +251,7 @@ stackTracePop(void)
|
|||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
Stack trace format
|
Stack trace format
|
||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
__attribute__((format(printf, 4, 5))) static size_t
|
static FN_PRINTF(4, 5) size_t
|
||||||
stackTraceFmt(char *buffer, size_t bufferSize, size_t bufferUsed, const char *format, ...)
|
stackTraceFmt(char *buffer, size_t bufferSize, size_t bufferUsed, const char *format, ...)
|
||||||
{
|
{
|
||||||
va_list argumentList;
|
va_list argumentList;
|
||||||
|
@ -150,7 +150,7 @@ FN_EXTERN JsonWrite *jsonWriteObjectEnd(JsonWrite *this);
|
|||||||
|
|
||||||
// Write string
|
// Write string
|
||||||
FN_EXTERN JsonWrite *jsonWriteStr(JsonWrite *this, const String *value);
|
FN_EXTERN JsonWrite *jsonWriteStr(JsonWrite *this, const String *value);
|
||||||
FN_EXTERN JsonWrite *jsonWriteStrFmt(JsonWrite *this, const char *format, ...) __attribute__((format(printf, 2, 3)));
|
FN_EXTERN FN_PRINTF(2, 3) JsonWrite *jsonWriteStrFmt(JsonWrite *this, const char *format, ...);
|
||||||
FN_EXTERN JsonWrite *jsonWriteStrId(JsonWrite *this, StringId value);
|
FN_EXTERN JsonWrite *jsonWriteStrId(JsonWrite *this, StringId value);
|
||||||
FN_EXTERN JsonWrite *jsonWriteStrLst(JsonWrite *this, const StringList *value);
|
FN_EXTERN JsonWrite *jsonWriteStrLst(JsonWrite *this, const StringList *value);
|
||||||
FN_EXTERN JsonWrite *jsonWriteZ(JsonWrite *this, const char *value);
|
FN_EXTERN JsonWrite *jsonWriteZ(JsonWrite *this, const char *value);
|
||||||
|
@ -73,7 +73,7 @@ FN_EXTERN String *strNewDbl(double value);
|
|||||||
FN_EXTERN String *strNewEncode(EncodingType type, const Buffer *buffer);
|
FN_EXTERN String *strNewEncode(EncodingType type, const Buffer *buffer);
|
||||||
|
|
||||||
// Create a new fixed length string from a format string with parameters (i.e. sprintf)
|
// Create a new fixed length string from a format string with parameters (i.e. sprintf)
|
||||||
FN_EXTERN String *strNewFmt(const char *format, ...) __attribute__((format(printf, 1, 2)));
|
FN_EXTERN FN_PRINTF(1, 2) String *strNewFmt(const char *format, ...);
|
||||||
|
|
||||||
// Create a new fixed length string from a string
|
// Create a new fixed length string from a string
|
||||||
FN_EXTERN String *strDup(const String *this);
|
FN_EXTERN String *strDup(const String *this);
|
||||||
@ -130,7 +130,7 @@ FN_EXTERN String *strCatChr(String *this, char cat);
|
|||||||
FN_EXTERN String *strCatEncode(String *this, EncodingType type, const Buffer *buffer);
|
FN_EXTERN String *strCatEncode(String *this, EncodingType type, const Buffer *buffer);
|
||||||
|
|
||||||
// Append a formatted string
|
// Append a formatted string
|
||||||
FN_EXTERN String *strCatFmt(String *this, const char *format, ...) __attribute__((format(printf, 2, 3)));
|
FN_EXTERN FN_PRINTF(2, 3) String *strCatFmt(String *this, const char *format, ...);
|
||||||
|
|
||||||
// Append N characters from a zero-terminated string. Note that the string does not actually need to be zero-terminated as long as
|
// Append N characters from a zero-terminated string. Note that the string does not actually need to be zero-terminated as long as
|
||||||
// N is <= the end of the string being concatenated.
|
// N is <= the end of the string being concatenated.
|
||||||
|
@ -76,7 +76,7 @@ strLstAddSub(StringList *const this, const String *const string, const size_t si
|
|||||||
return strLstAddSubN(this, string, 0, size);
|
return strLstAddSubN(this, string, 0, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
FN_EXTERN String *strLstAddFmt(StringList *this, const char *format, ...) __attribute__((format(printf, 2, 3)));
|
FN_EXTERN FN_PRINTF(2, 3) String *strLstAddFmt(StringList *this, const char *format, ...);
|
||||||
FN_EXTERN String *strLstAddZ(StringList *this, const char *string);
|
FN_EXTERN String *strLstAddZ(StringList *this, const char *string);
|
||||||
FN_EXTERN String *strLstAddZSubN(StringList *this, const char *string, size_t offset, size_t size);
|
FN_EXTERN String *strLstAddZSubN(StringList *this, const char *string, size_t offset, size_t size);
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ strStcInit(char *const buffer, const size_t bufferSize)
|
|||||||
Functions
|
Functions
|
||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
// Cat formatted string to static string
|
// Cat formatted string to static string
|
||||||
FN_EXTERN StringStatic *strStcFmt(StringStatic *debugLog, const char *format, ...) __attribute__((format(printf, 2, 3)));
|
FN_EXTERN FN_PRINTF(2, 3) StringStatic *strStcFmt(StringStatic *debugLog, const char *format, ...);
|
||||||
|
|
||||||
// Cat zero-terminated string to static string
|
// Cat zero-terminated string to static string
|
||||||
FN_EXTERN void strStcCat(StringStatic *debugLog, const char *cat);
|
FN_EXTERN void strStcCat(StringStatic *debugLog, const char *cat);
|
||||||
|
@ -18,6 +18,6 @@ Zero-terminated strings that are generally useful
|
|||||||
Functions
|
Functions
|
||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
// Format a zero-terminated string
|
// Format a zero-terminated string
|
||||||
FN_EXTERN char *zNewFmt(const char *format, ...) __attribute__((format(printf, 1, 2)));
|
FN_EXTERN FN_PRINTF(1, 2) char *zNewFmt(const char *format, ...);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -60,10 +60,8 @@ variant that works with indexed options and allows the key to be specified, e.g.
|
|||||||
void hrnCfgArgRaw(StringList *argList, ConfigOption optionId, const String *value);
|
void hrnCfgArgRaw(StringList *argList, ConfigOption optionId, const String *value);
|
||||||
void hrnCfgArgKeyRaw(StringList *argList, ConfigOption optionId, unsigned optionKey, const String *value);
|
void hrnCfgArgKeyRaw(StringList *argList, ConfigOption optionId, unsigned optionKey, const String *value);
|
||||||
|
|
||||||
void hrnCfgArgRawFmt(StringList *argList, ConfigOption optionId, const char *format, ...)
|
FN_PRINTF(3, 4) void hrnCfgArgRawFmt(StringList *argList, ConfigOption optionId, const char *format, ...);
|
||||||
__attribute__((format(printf, 3, 4)));
|
FN_PRINTF(4, 5) void hrnCfgArgKeyRawFmt(StringList *argList, ConfigOption optionId, unsigned optionKey, const char *format, ...);
|
||||||
void hrnCfgArgKeyRawFmt(StringList *argList, ConfigOption optionId, unsigned optionKey, const char *format, ...)
|
|
||||||
__attribute__((format(printf, 4, 5)));
|
|
||||||
|
|
||||||
void hrnCfgArgRawZ(StringList *argList, ConfigOption optionId, const char *value);
|
void hrnCfgArgRawZ(StringList *argList, ConfigOption optionId, const char *value);
|
||||||
void hrnCfgArgKeyRawZ(StringList *argList, ConfigOption optionId, unsigned optionKey, const char *value);
|
void hrnCfgArgKeyRawZ(StringList *argList, ConfigOption optionId, unsigned optionKey, const char *value);
|
||||||
|
Loading…
Reference in New Issue
Block a user