This is an automated email from the git hooks/post-receive script. guillem pushed a commit to branch master in repository dpkg.
View the commit online: https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=bfee5cd63ca0786d7cc55c8593f198c0b9ed2f40 commit bfee5cd63ca0786d7cc55c8593f198c0b9ed2f40 Author: Guillem Jover <[email protected]> AuthorDate: Tue Feb 4 04:03:38 2020 +0100 libdpkg: Use a new DPKG_NULL macro that works in C and C++ Warned-by: clang++-10 -Wzero-as-null-pointer-constant --- debian/changelog | 1 + lib/dpkg/macros.h | 15 +++++++++++++++ lib/dpkg/string.h | 6 +++--- lib/dpkg/test.h | 14 ++++++++------ 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/debian/changelog b/debian/changelog index 7102efffd..62aab448d 100644 --- a/debian/changelog +++ b/debian/changelog @@ -197,6 +197,7 @@ dpkg (1.20.0) UNRELEASED; urgency=medium libcompat-test. - libdpkg: Define new VARBUF_OBJECT macro. - libdpkg: Add new ATOMIC_FILE_NORMAL enum value to avoid a cast in C++. + - libdpkg: Use a new DPKG_NULL macro that works in C and C++. * Build system: - Bump minimal Perl version to 5.24.1. - Add a serial versioning to the m4 files. diff --git a/lib/dpkg/macros.h b/lib/dpkg/macros.h index 0c1937a09..a513b6685 100644 --- a/lib/dpkg/macros.h +++ b/lib/dpkg/macros.h @@ -87,6 +87,21 @@ #define DPKG_END_DECLS #endif +/** + * @def DPKG_NULL + * + * A null pointer constant that works on C or C++. + * + * To be used only on header files, where having to conditionalize the code + * to use either NULL or nullptr would be too cumbersome. Non-header files + * should use the appropriate constant directly. + */ +#if defined(__cplusplus) +#define DPKG_NULL nullptr +#else +#define DPKG_NULL NULL +#endif + /** * @def DPKG_BIT * diff --git a/lib/dpkg/string.h b/lib/dpkg/string.h index d0f6bd7ad..4693df456 100644 --- a/lib/dpkg/string.h +++ b/lib/dpkg/string.h @@ -35,12 +35,12 @@ DPKG_BEGIN_DECLS */ /** - * Check if a string is either NULL or empty. + * Check if a string is either null or empty. */ static inline bool str_is_unset(const char *str) { - return str == NULL || str[0] == '\0'; + return str == DPKG_NULL || str[0] == '\0'; } /** @@ -49,7 +49,7 @@ str_is_unset(const char *str) static inline bool str_is_set(const char *str) { - return str != NULL && str[0] != '\0'; + return str != DPKG_NULL && str[0] != '\0'; } bool str_match_end(const char *str, const char *end); diff --git a/lib/dpkg/test.h b/lib/dpkg/test.h index a0e5ffdae..5d9cb31d4 100644 --- a/lib/dpkg/test.h +++ b/lib/dpkg/test.h @@ -25,6 +25,7 @@ #include <stdlib.h> #include <stdio.h> +#include <dpkg/macros.h> #ifndef TEST_MAIN_CTOR #include <dpkg/ehandle.h> #define TEST_MAIN_CTOR push_error_context() @@ -51,7 +52,7 @@ static inline void * test_alloc(void *ptr, const char *reason) { - if (ptr == NULL) + if (ptr == DPKG_NULL) test_bail(reason); return ptr; } @@ -88,22 +89,23 @@ static const char *test_skip_reason; printf("ok %d # SKIP %s\n", test_id++, (reason)) #define test_skip_block(cond) \ for (test_skip_prefix = " # SKIP ", \ - test_skip_reason = cond ? #cond : NULL, \ + test_skip_reason = cond ? #cond : DPKG_NULL, \ test_skip_code = 1; \ test_skip_prefix; \ - test_skip_prefix = test_skip_reason = NULL, test_skip_code = 0) + test_skip_prefix = test_skip_reason = DPKG_NULL, \ + test_skip_code = 0) #define test_todo(a, reason, desc) \ do { \ test_skip_prefix = " # TODO "; \ test_skip_reason = reason; \ test_case(a, "%s", desc); \ - test_skip_prefix = test_skip_reason = NULL; \ + test_skip_prefix = test_skip_reason = DPKG_NULL; \ } while(0) #define test_todo_block(reason) \ for (test_skip_prefix = " # TODO ", test_skip_reason = reason; \ test_skip_prefix; \ - test_skip_prefix = test_skip_reason = NULL) + test_skip_prefix = test_skip_reason = DPKG_NULL) #define test_case(a, fmt, ...) \ printf("%sok %d - " fmt "%s%s\n", \ @@ -140,7 +142,7 @@ static void name(void); \ int \ main(int argc, char **argv) \ { \ - setvbuf(stdout, NULL, _IOLBF, 0); \ + setvbuf(stdout, DPKG_NULL, _IOLBF, 0); \ \ TEST_MAIN_CTOR; \ name(); \ -- Dpkg.Org's dpkg

