From 5108c95a66a98147b7ad743e568419b02bedfeea Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Thu, 31 Oct 2024 17:10:18 +0100 Subject: [PATCH 1/4] chore: make format --- examples/example.c | 2 +- src/backends/sentry_backend_crashpad.cpp | 2 +- src/backends/sentry_backend_inproc.c | 5 +---- src/modulefinder/sentry_modulefinder_apple.c | 4 ++-- src/path/sentry_path_windows.c | 4 ++-- src/sentry_core.c | 2 +- src/sentry_core.h | 2 +- src/sentry_scope.h | 6 +++--- src/sentry_string.h | 2 +- src/sentry_sync.h | 13 ++----------- tests/unit/test_sync.c | 2 +- 11 files changed, 16 insertions(+), 28 deletions(-) diff --git a/examples/example.c b/examples/example.c index 42e76231e..5c87b3f32 100644 --- a/examples/example.c +++ b/examples/example.c @@ -19,7 +19,7 @@ #ifdef SENTRY_PLATFORM_WINDOWS # include # include -# define sleep_s(SECONDS) Sleep((SECONDS)*1000) +# define sleep_s(SECONDS) Sleep((SECONDS) * 1000) #else # include diff --git a/src/backends/sentry_backend_crashpad.cpp b/src/backends/sentry_backend_crashpad.cpp index 49e93a160..38e92c9de 100644 --- a/src/backends/sentry_backend_crashpad.cpp +++ b/src/backends/sentry_backend_crashpad.cpp @@ -406,7 +406,7 @@ crashpad_backend_startup( // register attachments for (sentry_attachment_t *attachment = options->attachments; attachment; - attachment = attachment->next) { + attachment = attachment->next) { attachments.emplace_back(attachment->path->path); } diff --git a/src/backends/sentry_backend_inproc.c b/src/backends/sentry_backend_inproc.c index 18869ef6b..042729be1 100644 --- a/src/backends/sentry_backend_inproc.c +++ b/src/backends/sentry_backend_inproc.c @@ -37,10 +37,7 @@ * Both breakpad and crashpad are way more defensive in the setup of their * signal stacks and take existing stacks into account (or reuse them). */ -#define SIGNAL_DEF(Sig, Desc) \ - { \ - Sig, #Sig, Desc \ - } +#define SIGNAL_DEF(Sig, Desc) { Sig, #Sig, Desc } #define MAX_FRAMES 128 diff --git a/src/modulefinder/sentry_modulefinder_apple.c b/src/modulefinder/sentry_modulefinder_apple.c index 93957e0cb..26ef5088e 100644 --- a/src/modulefinder/sentry_modulefinder_apple.c +++ b/src/modulefinder/sentry_modulefinder_apple.c @@ -55,9 +55,9 @@ add_image(const struct mach_header *mh, intptr_t UNUSED(vmaddr_slide)) bool has_uuid = false; for (size_t i = 0; cmd && (i < header->ncmds) && (!has_uuid || !has_size); - ++i, + ++i, cmd - = (const struct load_command *)((const char *)cmd + cmd->cmdsize)) { + = (const struct load_command *)((const char *)cmd + cmd->cmdsize)) { if (cmd->cmd == CMD_SEGMENT) { const mach_segment_command_type *seg = (const mach_segment_command_type *)cmd; diff --git a/src/path/sentry_path_windows.c b/src/path/sentry_path_windows.c index 95f71db9b..531f5cf26 100644 --- a/src/path/sentry_path_windows.c +++ b/src/path/sentry_path_windows.c @@ -18,8 +18,8 @@ static const size_t MAX_READ_TO_BUFFER = 134217728; #ifndef __MINGW32__ -# define S_ISREG(m) (((m)&_S_IFMT) == _S_IFREG) -# define S_ISDIR(m) (((m)&_S_IFMT) == _S_IFDIR) +# define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG) +# define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR) #endif struct sentry_pathiter_s { diff --git a/src/sentry_core.c b/src/sentry_core.c index 4a74f8978..2e2cab505 100644 --- a/src/sentry_core.c +++ b/src/sentry_core.c @@ -501,7 +501,7 @@ sentry__prepare_event(const sentry_options_t *options, sentry_value_t event, SENTRY_TRACE("adding attachments to envelope"); for (sentry_attachment_t *attachment = options->attachments; attachment; - attachment = attachment->next) { + attachment = attachment->next) { sentry_envelope_item_t *item = sentry__envelope_add_from_path( envelope, attachment->path, "attachment"); if (!item) { diff --git a/src/sentry_core.h b/src/sentry_core.h index 6ee6c387e..1b35f92ef 100644 --- a/src/sentry_core.h +++ b/src/sentry_core.h @@ -112,7 +112,7 @@ void sentry__options_unlock(void); #define SENTRY_WITH_OPTIONS(Options) \ for (const sentry_options_t *Options = sentry__options_getref(); Options; \ - sentry_options_free((sentry_options_t *)Options), Options = NULL) + sentry_options_free((sentry_options_t *)Options), Options = NULL) // these for now are only needed outside of core for tests #ifdef SENTRY_UNITTEST diff --git a/src/sentry_scope.h b/src/sentry_scope.h index 5b2ba5fe6..26bb8df78 100644 --- a/src/sentry_scope.h +++ b/src/sentry_scope.h @@ -86,13 +86,13 @@ void sentry__scope_apply_to_event(const sentry_scope_t *scope, */ #define SENTRY_WITH_SCOPE(Scope) \ for (const sentry_scope_t *Scope = sentry__scope_lock(); Scope; \ - sentry__scope_unlock(), Scope = NULL) + sentry__scope_unlock(), Scope = NULL) #define SENTRY_WITH_SCOPE_MUT(Scope) \ for (sentry_scope_t *Scope = sentry__scope_lock(); Scope; \ - sentry__scope_flush_unlock(), Scope = NULL) + sentry__scope_flush_unlock(), Scope = NULL) #define SENTRY_WITH_SCOPE_MUT_NO_FLUSH(Scope) \ for (sentry_scope_t *Scope = sentry__scope_lock(); Scope; \ - sentry__scope_unlock(), Scope = NULL) + sentry__scope_unlock(), Scope = NULL) #endif diff --git a/src/sentry_string.h b/src/sentry_string.h index ee933d4da..6b98c5766 100644 --- a/src/sentry_string.h +++ b/src/sentry_string.h @@ -213,6 +213,6 @@ size_t sentry__unichar_to_utf8(uint32_t c, char *buf); #define sentry__is_lead_surrogate(c) ((c) >= 0xd800 && (c) < 0xdc00) #define sentry__is_trail_surrogate(c) ((c) >= 0xdc00 && (c) < 0xe000) #define sentry__surrogate_value(lead, trail) \ - (((((lead)-0xd800) << 10) | ((trail)-0xdc00)) + 0x10000) + (((((lead) - 0xd800) << 10) | ((trail) - 0xdc00)) + 0x10000) #endif diff --git a/src/sentry_sync.h b/src/sentry_sync.h index 73531235b..0b7bc033a 100644 --- a/src/sentry_sync.h +++ b/src/sentry_sync.h @@ -35,10 +35,7 @@ # if _WIN32_WINNT < 0x0600 -# define INIT_ONCE_STATIC_INIT \ - { \ - 0 \ - } +# define INIT_ONCE_STATIC_INIT { 0 } typedef union { PVOID Ptr; @@ -165,13 +162,7 @@ sentry__winmutex_lock(struct sentry__winmutex_s *mutex) typedef HANDLE sentry_threadid_t; typedef struct sentry__winmutex_s sentry_mutex_t; -# define SENTRY__MUTEX_INIT \ - { \ - INIT_ONCE_STATIC_INIT, \ - { \ - 0 \ - } \ - } +# define SENTRY__MUTEX_INIT { INIT_ONCE_STATIC_INIT, { 0 } } # define sentry__mutex_init(Lock) sentry__winmutex_init(Lock) # define sentry__mutex_lock(Lock) sentry__winmutex_lock(Lock) # define sentry__mutex_unlock(Lock) \ diff --git a/tests/unit/test_sync.c b/tests/unit/test_sync.c index aba8e8290..9e72430d7 100644 --- a/tests/unit/test_sync.c +++ b/tests/unit/test_sync.c @@ -4,7 +4,7 @@ #ifdef SENTRY_PLATFORM_WINDOWS # include -# define sleep_s(SECONDS) Sleep((SECONDS)*1000) +# define sleep_s(SECONDS) Sleep((SECONDS) * 1000) #else # include # define sleep_s(SECONDS) sleep(SECONDS) From 6245b45fea06aa39f2f8a8461f317f3af8534a2d Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Fri, 1 Nov 2024 14:08:35 +0100 Subject: [PATCH 2/4] roll-back linter changes in CI --- .github/workflows/ci.yml | 5 +---- Makefile | 6 ------ 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f06c083e1..fc124271f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,10 +17,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - run: | - sudo apt update - sudo apt install clang-format-15 - make style-15 + - run: make style build-ios: name: Xcode Build for iOS diff --git a/Makefile b/Makefile index a936b143f..6925df596 100644 --- a/Makefile +++ b/Makefile @@ -83,9 +83,3 @@ style: setup-venv @.venv/bin/python ./scripts/check-clang-format.py -r examples include src tests/unit @.venv/bin/black --diff --check tests .PHONY: style - -# TODO: workaround for clang-format 15+ where local formatting breaks with clang-format-14 based style checks on CI -style-15: setup-venv - @.venv/bin/python ./scripts/check-clang-format.py --clang-format-executable /usr/bin/clang-format-15 -r examples include src tests/unit - @.venv/bin/black --diff --check tests -.PHONY: style-15 From aab7229ca7205b936dddcd84074aa7e5f8ad0284 Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Fri, 1 Nov 2024 14:20:34 +0100 Subject: [PATCH 3/4] chore: add clang-format to venv --- Makefile | 6 ++++-- tests/requirements.txt | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 6925df596..93a3177c4 100644 --- a/Makefile +++ b/Makefile @@ -66,7 +66,7 @@ setup-venv: .venv/bin/python .venv/bin/pip install --upgrade --requirement tests/requirements.txt format: setup-venv - @clang-format -i \ + @.venv/bin/clang-format -i \ examples/*.c \ include/*.h \ src/*.c \ @@ -80,6 +80,8 @@ format: setup-venv .PHONY: format style: setup-venv - @.venv/bin/python ./scripts/check-clang-format.py -r examples include src tests/unit + @.venv/bin/python ./scripts/check-clang-format.py \ + --clang-format-executable .venv/bin/clang-format \ + -r examples include src tests/unit @.venv/bin/black --diff --check tests .PHONY: style diff --git a/tests/requirements.txt b/tests/requirements.txt index cbc8051ec..73cc2f63d 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -2,4 +2,5 @@ black==24.3.0 pytest==8.1.1 pytest-httpserver==1.0.10 msgpack==1.0.8 -pytest-xdist==3.5.0 \ No newline at end of file +pytest-xdist==3.5.0 +clang-format==19.1.3 From bd1c16e4bec79d07109b8d1b8c1825a85ab99820 Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Fri, 1 Nov 2024 14:22:00 +0100 Subject: [PATCH 4/4] more references to clang-format --- CONTRIBUTING.md | 6 +++--- scripts/git-precommit-hook.sh | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4678c4d74..2bdf6e097 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -14,7 +14,7 @@ Building and testing `sentry-native` currently requires the following tools: - **clang-format** and **black**, to format the C/C++ and python code respectively. - **curl** and **zlib** libraries (e.g. on Ubuntu: libcurl4-openssl-dev, libz-dev) -`pytest` and `black` are installed as virtualenv dependencies automatically. +`pytest`, `clang-format` and `black` are installed as virtualenv dependencies automatically. ## Setting up Environment @@ -142,12 +142,12 @@ The example currently supports the following commands: - `disable-backend`: Disables the build-configured crash-handler backend. - `before-send`: Installs a `before_send()` callback that retains the event. - `discarding-before-send`: Installs a `before_send()` callback that discards the event. -- `on-crash`: Installs an `on_crash()` callback that retains the crash event. +- `on-crash`: Installs an `on_crash()` callback that retains the crash event. - `discarding-on-crash`: Installs an `on_crash()` callback that discards the crash event. - `override-sdk-name`: Changes the SDK name via the options at runtime. - `stack-overflow`: Provokes a stack-overflow. -Only on Windows using crashpad with its WER handler module: +Only on Windows using crashpad with its WER handler module: - `fastfail`: Crashes the application using the `__fastfail` intrinsic directly, thus by-passing SEH. - `stack-buffer-overrun`: Triggers the Windows Control Flow Guard, which also fast fails and in turn by-passes SEH. diff --git a/scripts/git-precommit-hook.sh b/scripts/git-precommit-hook.sh index 18eee7d66..bf777f1c1 100755 --- a/scripts/git-precommit-hook.sh +++ b/scripts/git-precommit-hook.sh @@ -1,10 +1,10 @@ #!/usr/bin/env bash -CFILES=`git diff-index --cached --name-only HEAD | grep -E "^(examples|include|src|tests/unit).*\.(c|h|cpp)$"` -PYFILES=`git diff-index --cached --name-only HEAD | grep -E "^tests.*\.py$"` +CFILES=$(git diff-index --cached --name-only HEAD | grep -E "^(examples|include|src|tests/unit).*\.(c|h|cpp)$") +PYFILES=$(git diff-index --cached --name-only HEAD | grep -E "^tests.*\.py$") if [ -n "$CFILES" ]; then - clang-format -i $CFILES + .venv/bin/clang-format -i $CFILES fi if [ -n "$PYFILES" ]; then .venv/bin/black $PYFILES