diff options
Diffstat (limited to 'xbmc/utils/params_check_macros.h')
| -rw-r--r-- | xbmc/utils/params_check_macros.h | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/xbmc/utils/params_check_macros.h b/xbmc/utils/params_check_macros.h new file mode 100644 index 0000000..30f2355 --- /dev/null +++ b/xbmc/utils/params_check_macros.h | |||
| @@ -0,0 +1,62 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2014-2018 Team Kodi | ||
| 3 | * This file is part of Kodi - https://kodi.tv | ||
| 4 | * | ||
| 5 | * SPDX-License-Identifier: GPL-2.0-or-later | ||
| 6 | * See LICENSES/README.md for more information. | ||
| 7 | */ | ||
| 8 | |||
| 9 | #pragma once | ||
| 10 | |||
| 11 | // macros for gcc, clang & others | ||
| 12 | #ifndef PARAM1_PRINTF_FORMAT | ||
| 13 | #ifdef __GNUC__ | ||
| 14 | // for use in functions that take printf format string as first parameter and additional printf parameters as second parameter | ||
| 15 | // for example: int myprintf(const char* format, ...) PARAM1_PRINTF_FORMAT; | ||
| 16 | #define PARAM1_PRINTF_FORMAT __attribute__((format(printf,1,2))) | ||
| 17 | |||
| 18 | // for use in functions that take printf format string as second parameter and additional printf parameters as third parameter | ||
| 19 | // for example: bool log_string(int logLevel, const char* format, ...) PARAM2_PRINTF_FORMAT; | ||
| 20 | // note: all non-static class member functions take pointer to class object as hidden first parameter | ||
| 21 | #define PARAM2_PRINTF_FORMAT __attribute__((format(printf,2,3))) | ||
| 22 | |||
| 23 | // for use in functions that take printf format string as third parameter and additional printf parameters as fourth parameter | ||
| 24 | // note: all non-static class member functions take pointer to class object as hidden first parameter | ||
| 25 | // for example: class A { bool log_string(int logLevel, const char* functionName, const char* format, ...) PARAM3_PRINTF_FORMAT; }; | ||
| 26 | #define PARAM3_PRINTF_FORMAT __attribute__((format(printf,3,4))) | ||
| 27 | |||
| 28 | // for use in functions that take printf format string as fourth parameter and additional printf parameters as fith parameter | ||
| 29 | // note: all non-static class member functions take pointer to class object as hidden first parameter | ||
| 30 | // for example: class A { bool log_string(int logLevel, const char* functionName, int component, const char* format, ...) PARAM4_PRINTF_FORMAT; }; | ||
| 31 | #define PARAM4_PRINTF_FORMAT __attribute__((format(printf,4,5))) | ||
| 32 | #else // ! __GNUC__ | ||
| 33 | #define PARAM1_PRINTF_FORMAT | ||
| 34 | #define PARAM2_PRINTF_FORMAT | ||
| 35 | #define PARAM3_PRINTF_FORMAT | ||
| 36 | #define PARAM4_PRINTF_FORMAT | ||
| 37 | #endif // ! __GNUC__ | ||
| 38 | #endif // PARAM1_PRINTF_FORMAT | ||
| 39 | |||
| 40 | // macros for VC | ||
| 41 | // VC check parameters only when "Code Analysis" is called | ||
| 42 | #ifndef PRINTF_FORMAT_STRING | ||
| 43 | #ifdef _MSC_VER | ||
| 44 | #include <sal.h> | ||
| 45 | |||
| 46 | // for use in any function that take printf format string and parameters | ||
| 47 | // for example: bool log_string(int logLevel, PRINTF_FORMAT_STRING const char* format, ...); | ||
| 48 | #define PRINTF_FORMAT_STRING _In_z_ _Printf_format_string_ | ||
| 49 | |||
| 50 | // specify that parameter must be zero-terminated string | ||
| 51 | // for example: void SetName(IN_STRING const char* newName); | ||
| 52 | #define IN_STRING _In_z_ | ||
| 53 | |||
| 54 | // specify that parameter must be zero-terminated string or NULL | ||
| 55 | // for example: bool SetAdditionalName(IN_OPT_STRING const char* addName); | ||
| 56 | #define IN_OPT_STRING _In_opt_z_ | ||
| 57 | #else // ! _MSC_VER | ||
| 58 | #define PRINTF_FORMAT_STRING | ||
| 59 | #define IN_STRING | ||
| 60 | #define IN_OPT_STRING | ||
| 61 | #endif // ! _MSC_VER | ||
| 62 | #endif // PRINTF_FORMAT_STRING | ||
