Skip to content

Commit 659cbb1

Browse files
committed
clang-format src/libAtomVM/*.c and src/libAtomVM/*.h
Run recent clang-format in order to apply other formatting rules that are not IndentPPDirectives. Also upgrade to clang-format 20. Signed-off-by: Davide Bettio <[email protected]>
1 parent f9fc402 commit 659cbb1

File tree

7 files changed

+36
-15
lines changed

7 files changed

+36
-15
lines changed

.github/workflows/check-formatting.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,8 @@ jobs:
3636

3737
- name: "Install run-clang-format"
3838
run: |
39-
wget -q -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
40-
echo "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-16 main" | sudo tee -a /etc/apt/sources.list
41-
echo "deb-src http://apt.llvm.org/focal/ llvm-toolchain-focal-16 main" | sudo tee -a /etc/apt/sources.list
4239
sudo apt-get update
43-
sudo apt-get install -y clang-format-16
40+
sudo apt-get install -y clang-format-20
4441
curl -sSfL https://raw.githubusercontent.com/Sarcasm/run-clang-format/master/run-clang-format.py -o run-clang-format
4542
chmod +x run-clang-format
4643

src/libAtomVM/atom_table.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ static inline int read_encoded_len(const uint8_t **len_bytes)
427427
}
428428

429429
// -1 is not a valid atom index as we're limited to 2^20
430-
#define ATOM_TABLE_NOT_FOUND_MARKER ((atom_index_t) -1)
430+
#define ATOM_TABLE_NOT_FOUND_MARKER ((atom_index_t) - 1)
431431

432432
enum AtomTableEnsureAtomResult atom_table_ensure_atoms(struct AtomTable *table, const void *atoms, size_t count,
433433
atom_index_t *translate_table, enum EnsureAtomsOpt opt)

src/libAtomVM/bitstring.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,14 @@
2626

2727
static inline uint64_t from_le64(uint64_t value)
2828
{
29-
return ((((value) &0xFF) << 56) | (((value) &0xFF00) << 40) | (((value) &0xFF0000) << 24) | (((value) &0xFF000000) << 8) | (((value) &0xFF00000000) >> 8) | (((value) &0xFF0000000000) >> 24) | (((value) &0xFF000000000000) >> 40) | (((value) &0xFF00000000000000) >> 56));
29+
return ((((value) & 0xFF) << 56)
30+
| (((value) & 0xFF00) << 40)
31+
| (((value) & 0xFF0000) << 24)
32+
| (((value) & 0xFF000000) << 8)
33+
| (((value) & 0xFF00000000) >> 8)
34+
| (((value) & 0xFF0000000000) >> 24)
35+
| (((value) & 0xFF000000000000) >> 40)
36+
| (((value) & 0xFF00000000000000) >> 56));
3037
}
3138

3239
bool bitstring_extract_any_integer(const uint8_t *src, size_t offset, avm_int_t n,

src/libAtomVM/nifs.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4121,7 +4121,9 @@ static term nif_erlang_fun_info_2(Context *ctx, int argc, term argv[])
41214121
RAISE_ERROR(BADARG_ATOM);
41224122
}
41234123

4124-
if (UNLIKELY(memory_ensure_free_with_roots(ctx, TUPLE_SIZE(2), 2, (term[]){ key, value }, MEMORY_CAN_SHRINK) != MEMORY_GC_OK)) {
4124+
if (UNLIKELY(memory_ensure_free_with_roots(
4125+
ctx, TUPLE_SIZE(2), 2, (term[]) { key, value }, MEMORY_CAN_SHRINK)
4126+
!= MEMORY_GC_OK)) {
41254127
RAISE_ERROR(OUT_OF_MEMORY_ATOM);
41264128
}
41274129
term fun_info_tuple = term_alloc_tuple(2, &ctx->heap);

src/libAtomVM/term.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1807,7 +1807,7 @@ static inline bool term_is_nomatch_binary_pos_len(BinaryPosLen pos_len)
18071807

18081808
static inline BinaryPosLen term_nomatch_binary_pos_len(void)
18091809
{
1810-
return (BinaryPosLen){ .pos = -1, .len = -1 };
1810+
return (BinaryPosLen) { .pos = -1, .len = -1 };
18111811
}
18121812

18131813
/**

src/libAtomVM/utils.h

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,15 @@ extern "C" {
6767
*((uint16_t *) (ptr)) = __builtin_bswap16(val)
6868

6969
# else
70-
# define READ_64_UNALIGNED(ptr) \
71-
((((uint64_t) ((uint8_t *) (ptr))[0]) << 56) | (((uint64_t) ((uint8_t *) (ptr))[1]) << 48) | (((uint64_t) ((uint8_t *) (ptr))[2]) << 40) | (((uint64_t) ((uint8_t *) (ptr))[3]) << 32) | (((uint64_t) ((uint8_t *) (ptr))[4]) << 24) | (((uint64_t) ((uint8_t *) (ptr))[5]) << 16) | (((uint64_t) ((uint8_t *) (ptr))[6]) << 8) | (((uint64_t) ((uint8_t *) (ptr))[7])))
70+
# define READ_64_UNALIGNED(ptr) \
71+
((((uint64_t) ((uint8_t *) (ptr))[0]) << 56) \
72+
| (((uint64_t) ((uint8_t *) (ptr))[1]) << 48) \
73+
| (((uint64_t) ((uint8_t *) (ptr))[2]) << 40) \
74+
| (((uint64_t) ((uint8_t *) (ptr))[3]) << 32) \
75+
| (((uint64_t) ((uint8_t *) (ptr))[4]) << 24) \
76+
| (((uint64_t) ((uint8_t *) (ptr))[5]) << 16) \
77+
| (((uint64_t) ((uint8_t *) (ptr))[6]) << 8) \
78+
| (((uint64_t) ((uint8_t *) (ptr))[7])))
7279

7380
# define WRITE_64_UNALIGNED(ptr, val) \
7481
{ \
@@ -82,8 +89,9 @@ extern "C" {
8289
((uint8_t *) (ptr))[7] = ((uint64_t) val) & 0xff; \
8390
}
8491

85-
# define READ_32_UNALIGNED(ptr) \
86-
((((uint8_t *) (ptr))[0] << 24) | (((uint8_t *) (ptr))[1] << 16) | (((uint8_t *) (ptr))[2] << 8) | ((uint8_t *) (ptr))[3])
92+
# define READ_32_UNALIGNED(ptr) \
93+
((((uint8_t *) (ptr))[0] << 24) | (((uint8_t *) (ptr))[1] << 16) \
94+
| (((uint8_t *) (ptr))[2] << 8) | ((uint8_t *) (ptr))[3])
8795

8896
# define WRITE_32_UNALIGNED(ptr, val) \
8997
{ \
@@ -106,7 +114,9 @@ extern "C" {
106114
# ifdef __GNUC__
107115
# define ENDIAN_SWAP_32(value) __builtin_bswap32(value)
108116
# else
109-
# define ENDIAN_SWAP_32(value) ((((value) & 0xFF) << 24) | (((value) & 0xFF00) << 8) | (((value) & 0xFF0000) >> 8) | (((value) & 0xFF000000) >> 24))
117+
# define ENDIAN_SWAP_32(value) \
118+
((((value) & 0xFF) << 24) | (((value) & 0xFF00) << 8) | (((value) & 0xFF0000) >> 8) \
119+
| (((value) & 0xFF000000) >> 24))
110120
# endif
111121

112122
# ifdef __GNUC__
@@ -593,7 +603,7 @@ static inline bool uint64_does_overflow_int64(uint64_t u64, bool is_negative)
593603
*/
594604
static inline uint32_t int32_safe_unsigned_abs(int32_t i32)
595605
{
596-
return (i32 < 0) ? ((uint32_t) - (i32 + 1)) + 1 : (uint32_t) i32;
606+
return (i32 < 0) ? ((uint32_t) -(i32 + 1)) + 1 : (uint32_t) i32;
597607
}
598608

599609
/**
@@ -611,7 +621,7 @@ static inline uint32_t int32_safe_unsigned_abs(int32_t i32)
611621
*/
612622
static inline uint64_t int64_safe_unsigned_abs(int64_t i64)
613623
{
614-
return (i64 < 0) ? ((uint64_t) - (i64 + 1)) + 1 : (uint64_t) i64;
624+
return (i64 < 0) ? ((uint64_t) -(i64 + 1)) + 1 : (uint64_t) i64;
615625
}
616626

617627
/**

src/platforms/.clang-format

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1+
# Copyright 2025 Davide Bettio <[email protected]>
2+
#
3+
# SPDX-License-Identifier: CC0-1.0
4+
5+
---
16
BasedOnStyle: InheritParentConfig
27
IndentPPDirectives: None

0 commit comments

Comments
 (0)