From 5b6384c90e44a58c7999c59c52f42591d5395ada Mon Sep 17 00:00:00 2001 From: yuyawk Date: Sat, 19 Oct 2024 01:32:15 +0900 Subject: [PATCH 1/4] fix: better nolint --- libc_replacer/cc/internal/definition_helper.h | 54 ++++++++++--------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/libc_replacer/cc/internal/definition_helper.h b/libc_replacer/cc/internal/definition_helper.h index f60d47b..45a495a 100644 --- a/libc_replacer/cc/internal/definition_helper.h +++ b/libc_replacer/cc/internal/definition_helper.h @@ -4,10 +4,12 @@ #include "libc_replacer/cc/internal/macro_impl.h" #include -/// @note Suppress clang-tidy warnings occuring inside macros. -#define LIBC_REPLACER_INTERNAL_NOLINTBEGIN -/// @note Suppress clang-tidy warnings occuring inside macros. -#define LIBC_REPLACER_INTERNAL_NOLINTEND +/// @brief Implementation of @c LIBC_REPLACER_INTERNAL_ANNOTATE. +#define LIBC_REPLACER_INTERNAL_ANNOTATE_IMPL(...) +/// @brief Macro for annotation. +#define LIBC_REPLACER_INTERNAL_ANNOTATE(...) \ + LIBC_REPLACER_INTERNAL_ANNOTATE_IMPL("dummy argument to prevent zero args", \ + __VA_ARGS__) /// @brief Define replacer functions of a libc API. /// @param library Name of the libc API to replace. @@ -15,27 +17,27 @@ /// @param ... Argument value types of the libc API. /// @note Disable `cppcoreguidelines-avoid-non-const-global-variables` for /// defining a global atomic function pointer. -#define LIBC_REPLACER_INTERNAL_DEFINE(library, ret_t, ...) \ - LIBC_REPLACER_INTERNAL_NOLINTBEGIN \ - ret_t __real_##library( \ - LIBC_REPLACER_INTERNAL_GET_ARG_TYPES_AND_NAMES(__VA_ARGS__)); \ - ret_t __wrap_##library( \ - LIBC_REPLACER_INTERNAL_GET_ARG_TYPES_AND_NAMES(__VA_ARGS__)); \ - static _Atomic(libc_replacer_##library##_func_ptr_t) \ - libc_replacer_func_global = __real_##library; \ - void libc_replacer_overwrite_##library( \ - libc_replacer_##library##_func_ptr_t func_new) { \ - atomic_store(&libc_replacer_func_global, func_new); \ - } \ - void libc_replacer_reset_##library(void) { \ - atomic_store(&libc_replacer_func_global, __real_##library); \ - } \ - ret_t __wrap_##library( \ - LIBC_REPLACER_INTERNAL_GET_ARG_TYPES_AND_NAMES(__VA_ARGS__)) { \ - libc_replacer_##library##_func_ptr_t func_got = \ - atomic_load(&libc_replacer_func_global); \ - return func_got(LIBC_REPLACER_INTERNAL_GET_ARG_NAMES(__VA_ARGS__)); \ - } \ - LIBC_REPLACER_INTERNAL_NOLINTEND +#define LIBC_REPLACER_INTERNAL_DEFINE(library, ret_t, ...) \ + ret_t __real_##library( \ + LIBC_REPLACER_INTERNAL_GET_ARG_TYPES_AND_NAMES(__VA_ARGS__)); \ + ret_t __wrap_##library( \ + LIBC_REPLACER_INTERNAL_GET_ARG_TYPES_AND_NAMES(__VA_ARGS__)); \ + static _Atomic(libc_replacer_##library##_func_ptr_t) \ + LIBC_REPLACER_INTERNAL_ANNOTATE( \ + /* NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) */) \ + libc_replacer_func_global = __real_##library; \ + void libc_replacer_overwrite_##library( \ + libc_replacer_##library##_func_ptr_t func_new) { \ + atomic_store(&libc_replacer_func_global, func_new); \ + } \ + void libc_replacer_reset_##library(void) { \ + atomic_store(&libc_replacer_func_global, __real_##library); \ + } \ + ret_t __wrap_##library( \ + LIBC_REPLACER_INTERNAL_GET_ARG_TYPES_AND_NAMES(__VA_ARGS__)) { \ + libc_replacer_##library##_func_ptr_t func_got = \ + atomic_load(&libc_replacer_func_global); \ + return func_got(LIBC_REPLACER_INTERNAL_GET_ARG_NAMES(__VA_ARGS__)); \ + } #endif // INCLUDE_GUARD_LIBC_REPLACER_CC_INTERNAL_DEFINITION_HELPER_H_ From 897ecce6f7d76eb2ae77c6b8c9ef570b01023080 Mon Sep 17 00:00:00 2001 From: yuyawk Date: Sat, 19 Oct 2024 01:35:43 +0900 Subject: [PATCH 2/4] fix: use config --- .clang-format | 4 ++++ development/cli/style_check/clang_format.bash | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..745d1ca --- /dev/null +++ b/.clang-format @@ -0,0 +1,4 @@ +--- +BasedOnStyle: LLVM +Language: Cpp +CommentPragmas: "(NOLINT(NEXTLINE|BEGIN|END)|^ IWYU pragma:)" diff --git a/development/cli/style_check/clang_format.bash b/development/cli/style_check/clang_format.bash index 2858e9c..4e5a4f2 100755 --- a/development/cli/style_check/clang_format.bash +++ b/development/cli/style_check/clang_format.bash @@ -15,4 +15,7 @@ clang_format_targets="$( xargs -I{} echo "$(pwd)/{}" )" -"${BAZEL_EXECUTABLE[@]}" run -- @clang_tools//:clang_format -i ${clang_format_targets} +"${BAZEL_EXECUTABLE[@]}" run -- @clang_tools//:clang_format \ + -style=file \ + --assume-filename="${REPO_ROOT_DIR}/.clang-format" \ + -i ${clang_format_targets} From c257fbdf64a96014a463c612f1bb1ce09e31a54c Mon Sep 17 00:00:00 2001 From: yuyawk Date: Sat, 19 Oct 2024 01:36:31 +0900 Subject: [PATCH 3/4] fix config --- .clang-format | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.clang-format b/.clang-format index 745d1ca..7796597 100644 --- a/.clang-format +++ b/.clang-format @@ -1,4 +1,4 @@ --- BasedOnStyle: LLVM Language: Cpp -CommentPragmas: "(NOLINT(NEXTLINE|BEGIN|END)|^ IWYU pragma:)" +CommentPragmas: "(NOLINT|^ IWYU pragma:)" From 415013468904fe2d532d315cdb9aec5006442a6e Mon Sep 17 00:00:00 2001 From: yuyawk Date: Sat, 19 Oct 2024 01:38:43 +0900 Subject: [PATCH 4/4] simplify macro --- libc_replacer/cc/internal/definition_helper.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/libc_replacer/cc/internal/definition_helper.h b/libc_replacer/cc/internal/definition_helper.h index 45a495a..492cdb6 100644 --- a/libc_replacer/cc/internal/definition_helper.h +++ b/libc_replacer/cc/internal/definition_helper.h @@ -4,12 +4,8 @@ #include "libc_replacer/cc/internal/macro_impl.h" #include -/// @brief Implementation of @c LIBC_REPLACER_INTERNAL_ANNOTATE. -#define LIBC_REPLACER_INTERNAL_ANNOTATE_IMPL(...) /// @brief Macro for annotation. -#define LIBC_REPLACER_INTERNAL_ANNOTATE(...) \ - LIBC_REPLACER_INTERNAL_ANNOTATE_IMPL("dummy argument to prevent zero args", \ - __VA_ARGS__) +#define LIBC_REPLACER_INTERNAL_ANNOTATE() /// @brief Define replacer functions of a libc API. /// @param library Name of the libc API to replace.