1
0
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:
David Steele 2023-01-30 10:51:48 +07:00
parent f8ea51bf8f
commit f91af30584
11 changed files with 26 additions and 21 deletions

View File

@ -194,6 +194,12 @@ configuration.set(
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
####################################################################################################################################

View File

@ -32,6 +32,9 @@ Build Flags Generated by Configure
// Indicate that a function should always be inlined
#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.
#define FN_EXTERN extern
#define VR_EXTERN_DECLARE extern

View File

@ -325,18 +325,16 @@ FN_EXTERN void errorInternalTryEnd(void);
FN_EXTERN FN_NO_RETURN void errorInternalThrow(
const ErrorType *errorType, const char *fileName, const char *functionName, int fileLine, const char *message,
const char *stackTrace);
FN_EXTERN FN_NO_RETURN void errorInternalThrowFmt(
const ErrorType *errorType, const char *fileName, const char *functionName, int fileLine, const char *format, ...)
__attribute__((format(printf, 5, 6)));
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, ...);
// Throw a system error
FN_EXTERN FN_NO_RETURN void errorInternalThrowSys(
int errNo, const ErrorType *errorType, const char *fileName, const char *functionName, int fileLine, const char *message);
// Throw a formatted system error
FN_EXTERN FN_NO_RETURN void errorInternalThrowSysFmt(
int errNo, const ErrorType *errorType, const char *fileName, const char *functionName, int fileLine, const char *format, ...)
__attribute__((format(printf, 6, 7)));
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, ...);
// Versions of the above for coverage testing which checks the error condition inside the function
#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,
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,
const char *format, ...) __attribute__((format(printf, 7, 8)));
const char *format, ...);
#endif
/***********************************************************************************************************************************

View File

@ -157,8 +157,8 @@ FN_EXTERN void logInternal(
const char *functionName, int code, const char *message);
// 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,
const char *functionName, int code, const char *format, ...) __attribute__((format(printf, 8, 9)));
const char *functionName, int code, const char *format, ...);
#endif

View File

@ -251,7 +251,7 @@ stackTracePop(void)
/***********************************************************************************************************************************
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, ...)
{
va_list argumentList;

View File

@ -150,7 +150,7 @@ FN_EXTERN JsonWrite *jsonWriteObjectEnd(JsonWrite *this);
// Write string
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 *jsonWriteStrLst(JsonWrite *this, const StringList *value);
FN_EXTERN JsonWrite *jsonWriteZ(JsonWrite *this, const char *value);

View File

@ -73,7 +73,7 @@ FN_EXTERN String *strNewDbl(double value);
FN_EXTERN String *strNewEncode(EncodingType type, const Buffer *buffer);
// 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
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);
// 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
// N is <= the end of the string being concatenated.

View File

@ -76,7 +76,7 @@ strLstAddSub(StringList *const this, const String *const string, const size_t si
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 *strLstAddZSubN(StringList *this, const char *string, size_t offset, size_t size);

View File

@ -33,7 +33,7 @@ strStcInit(char *const buffer, const size_t bufferSize)
Functions
***********************************************************************************************************************************/
// 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
FN_EXTERN void strStcCat(StringStatic *debugLog, const char *cat);

View File

@ -18,6 +18,6 @@ Zero-terminated strings that are generally useful
Functions
***********************************************************************************************************************************/
// 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

View File

@ -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 hrnCfgArgKeyRaw(StringList *argList, ConfigOption optionId, unsigned optionKey, const String *value);
void hrnCfgArgRawFmt(StringList *argList, ConfigOption optionId, const char *format, ...)
__attribute__((format(printf, 3, 4)));
void hrnCfgArgKeyRawFmt(StringList *argList, ConfigOption optionId, unsigned optionKey, const char *format, ...)
__attribute__((format(printf, 4, 5)));
FN_PRINTF(3, 4) void hrnCfgArgRawFmt(StringList *argList, ConfigOption optionId, const char *format, ...);
FN_PRINTF(4, 5) void hrnCfgArgKeyRawFmt(StringList *argList, ConfigOption optionId, unsigned optionKey, const char *format, ...);
void hrnCfgArgRawZ(StringList *argList, ConfigOption optionId, const char *value);
void hrnCfgArgKeyRawZ(StringList *argList, ConfigOption optionId, unsigned optionKey, const char *value);