Skip to content

Commit

Permalink
Modify clang-format config (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyawk authored Oct 18, 2024
1 parent cd17af5 commit 699f0ff
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 27 deletions.
4 changes: 4 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
BasedOnStyle: LLVM
Language: Cpp
CommentPragmas: "(NOLINT|^ IWYU pragma:)"
5 changes: 4 additions & 1 deletion development/cli/style_check/clang_format.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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}
50 changes: 24 additions & 26 deletions libc_replacer/cc/internal/definition_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,36 @@
#include "libc_replacer/cc/internal/macro_impl.h"
#include <stdatomic.h>

/// @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 Macro for annotation.
#define LIBC_REPLACER_INTERNAL_ANNOTATE()

/// @brief Define replacer functions of a libc API.
/// @param library Name of the libc API to replace.
/// @param ret_t Return value type of the libc API.
/// @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_

0 comments on commit 699f0ff

Please sign in to comment.