Skip to content

Commit 9daa66d

Browse files
Version 2 with API enhancements (#7)
* Actualize the tooling * Add spelling dictionary * Remove critical section hooks; fix #4 * Clean up redundant declarations * Add support for O1HEAP_CONFIG_HEADER, fix #5
1 parent d1c19dd commit 9daa66d

File tree

14 files changed

+162
-252
lines changed

14 files changed

+162
-252
lines changed

.github/workflows/main.yml

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ on: [push, pull_request]
55
jobs:
66
test:
77
runs-on: ubuntu-latest
8-
98
strategy:
109
matrix:
1110
toolchain: ['clang', 'gcc']
@@ -15,17 +14,22 @@ jobs:
1514
c-compiler: gcc
1615
cxx-compiler: g++
1716
- toolchain: clang
18-
c-compiler: clang-11
19-
cxx-compiler: clang++-11
20-
17+
c-compiler: clang
18+
cxx-compiler: clang++
2119
steps:
2220
- uses: actions/checkout@v2
2321

2422
- name: Install Dependencies
25-
run: sudo apt install gcc-multilib g++-multilib clang-tidy-9 clang-format-9
23+
run: sudo apt install gcc-multilib g++-multilib clang-tidy-12
2624

2725
- name: Configure CMake
28-
run: cmake -B ${{ github.workspace }}/build -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCMAKE_C_COMPILER=${{ matrix.c-compiler }} -DCMAKE_CXX_COMPILER=${{ matrix.cxx-compiler }} tests
26+
run: >
27+
cmake
28+
-B ${{ github.workspace }}/build
29+
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
30+
-DCMAKE_C_COMPILER=${{ matrix.c-compiler }}
31+
-DCMAKE_CXX_COMPILER=${{ matrix.cxx-compiler }}
32+
tests
2933
3034
- name: Build
3135
working-directory: ${{github.workspace}}/build
@@ -36,24 +40,23 @@ jobs:
3640
run: make test
3741

3842
sonarcloud:
43+
if: endsWith(github.base_ref, 'master') || endsWith(github.ref, 'master')
44+
runs-on: ubuntu-latest
3945
env:
4046
SONAR_SCANNER_VERSION: 4.6.1.2450
4147
SONAR_SERVER_URL: "https://sonarcloud.io"
4248
BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory
4349
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4450
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
45-
CC: gcc-9
46-
CXX: g++-9
47-
48-
runs-on: ubuntu-latest
49-
51+
CC: gcc
52+
CXX: g++
5053
steps:
5154
- uses: actions/checkout@v2
5255
with:
5356
fetch-depth: 0
5457

5558
- name: Install Dependencies
56-
run: sudo apt install g++-9 g++-9-multilib gcc-9-multilib
59+
run: sudo apt install g++ g++-multilib gcc-multilib
5760

5861
- name: Set up JDK 11
5962
uses: actions/setup-java@v1
@@ -72,7 +75,7 @@ jobs:
7275
SONAR_SCANNER_DOWNLOAD_URL: https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${{ env.SONAR_SCANNER_VERSION }}-linux.zip
7376
run: |
7477
mkdir -p $HOME/.sonar
75-
curl -sSLo $HOME/.sonar/sonar-scanner.zip ${{ env.SONAR_SCANNER_DOWNLOAD_URL }}
78+
curl -sSLo $HOME/.sonar/sonar-scanner.zip ${{ env.SONAR_SCANNER_DOWNLOAD_URL }}
7679
unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/
7780
echo "$HOME/.sonar/sonar-scanner-${{ env.SONAR_SCANNER_VERSION }}-linux/bin" >> $GITHUB_PATH
7881
@@ -89,8 +92,30 @@ jobs:
8992
cmake tests -DCMAKE_BUILD_TYPE=Debug -DNO_STATIC_ANALYSIS=1
9093
build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} make all
9194
make test
92-
gcov-10 --preserve-paths --long-file-names $(find CMakeFiles/test_private_cov.dir -name '*.gcno')
95+
gcov --preserve-paths --long-file-names $(find CMakeFiles/test_general_cov.dir -name '*.gcno')
96+
gcov --preserve-paths --long-file-names $(find CMakeFiles/test_private_cov.dir -name '*.gcno')
9397
9498
- name: Run sonar-scanner
95-
run: |
96-
sonar-scanner --define sonar.host.url="${{ env.SONAR_SERVER_URL }}" --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}" --define sonar.login=${{ secrets.SONAR_TOKEN }}
99+
run: >
100+
sonar-scanner
101+
--define sonar.projectKey="pavel-kirienko_o1heap"
102+
--define sonar.organization="pavel-kirienko"
103+
--define sonar.sources="o1heap/"
104+
--define sonar.sourceEncoding="UTF-8"
105+
--define sonar.cfamily.gcov.reportsPath="."
106+
--define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}"
107+
--define sonar.cfamily.cache.enabled="false"
108+
--define sonar.cfamily.threads=1
109+
--define sonar.host.url="${{ env.SONAR_SERVER_URL }}"
110+
--define sonar.login=${{ secrets.SONAR_TOKEN }}
111+
112+
style_check:
113+
runs-on: ubuntu-latest
114+
steps:
115+
- uses: actions/checkout@v2
116+
- uses: DoozyX/[email protected]
117+
with:
118+
source: './o1heap ./tests'
119+
exclude: './tests/catch'
120+
extensions: 'c,h,cpp,hpp'
121+
clangFormatVersion: 12

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ Mkfile.old
5252
dkms.conf
5353

5454
# IDE & outputs
55-
.idea/
55+
**/.idea/*
56+
!**/.idea/dictionaries
57+
!**/.idea/dictionaries/*
5658
cmake-build-*/
5759
build/

README.md

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ which makes it suitable for use in high-integrity embedded systems.
1616

1717
The codebase is implemented in C99/C11 following MISRA C:2012, with several intended deviations which are unavoidable
1818
due to the fact that a memory allocator has to rely on inherently unsafe operations to fulfill its purpose.
19-
The codebase is extremely compact (<500 SLoC) and is therefore trivial to validate.
19+
The codebase is extremely compact (<500 LoC) and is therefore trivial to validate.
2020

2121
The allocator is designed to be portable across all conventional architectures, from 8-bit to 64-bit systems.
2222
Multi-threaded environments are supported with the help of external synchronization hooks provided by the application.
@@ -77,9 +77,9 @@ a memory allocation request even if there is enough free memory due to its subop
7777
By definition, if the amount of memory available to the allocator is not less than *H*, then the state of
7878
catastrophic fragmentation cannot occur.
7979

80-
Memory allocators used in general-purpose (non real-time) applications often leverage a different class of algorithms
80+
Memory allocators used in general-purpose (non-real-time) applications often leverage a different class of algorithms
8181
which may feature poorer worst-case performance metrics but perform (much) better on average.
82-
For a hard real-time system, the average case performance is generally less relevant
82+
For a hard real-time system, the average case performance is generally less relevant,
8383
so it can be excluded from analysis.
8484

8585
The above-defined theoretical worst-case upper bound H may be prohibitively high for some
@@ -90,7 +90,7 @@ the probability of a (de-)allocation sequence that results in catastrophic fragm
9090
When combined with an acceptable failure probability and a set of adequate assumptions about the behaviors of
9191
the application, this property may allow the designer to drastically reduce the amount of memory dedicated to
9292
the heap while ensuring a sufficient degree of predictability and reliability.
93-
The methods of such optimization are outside of the scope of this document;
93+
The methods of such optimization are outside the scope of this document;
9494
interested readers are advised to consult with the referred publications.
9595

9696
Following some of the ideas expressed in the discussion about memory caching in real-time systems in [Herter 2014],
@@ -173,15 +173,18 @@ and its internal data structures are not damaged.
173173

174174
### Build configuration options
175175

176-
The preprocessor options given below can be overridden (e.g., using the `-D` compiler flag, depending on the compiler)
177-
to fine-tune the implementation.
176+
The preprocessor options given below can be overridden to fine-tune the implementation.
178177
None of them are mandatory to use.
179178

179+
#### O1HEAP_CONFIG_HEADER
180+
181+
Define this optional macro like `O1HEAP_CONFIG_HEADER="path/to/my_o1heap_config.h"` to pass build configuration macros.
182+
This is useful because some build systems do not allow passing function-like macros via command line flags.
183+
180184
#### O1HEAP_ASSERT(x)
181185

182186
The macro `O1HEAP_ASSERT(x)` can be defined to customize the assertion handling or to disable it.
183187
To disable assertion checks, the macro should expand into `(void)(x)`.
184-
185188
If not specified, the macro expands into the standard assertion check macro `assert(x)` as defined in `<assert.h>`.
186189

187190
#### O1HEAP_LIKELY(x)
@@ -195,7 +198,7 @@ or into the original expression `(x)` if no such hinting is desired.
195198
If not specified, the macro expands as follows:
196199

197200
- For some well-known compilers the macro automatically expands into appropriate branch weighting intrinsics.
198-
For example, for GCC, Clang, and ARM Compiler, it expands into `__builtin_expect((x), 1)`.
201+
For example, for GCC, Clang, and ARM Compiler, it expands into `__builtin_expect((x), 1)`.
199202
- For other (unknown) compilers it expands into the original expression with no modifications: `(x)`.
200203

201204
## Development
@@ -204,9 +207,7 @@ For example, for GCC, Clang, and ARM Compiler, it expands into `__builtin_expect
204207

205208
The following tools should be available locally to conduct library development:
206209

207-
- GCC v9 or newer.
208-
- Clang and Clang-Tools v9 or newer.
209-
- CMake v3.12 or newer.
210+
- Modern versions of CMake, GCC, Clang, and Clang-Tools.
210211
- An AMD64 machine.
211212
- (optional) Valgrind.
212213

@@ -223,6 +224,10 @@ Compliance is enforced through the following means:
223224

224225
Please refer to the continuous integration configuration to see how to invoke the tests.
225226

227+
### Releasing
228+
229+
Update the version number macro in the header file and create a new git tag like `1.0`.
230+
226231
### MISRA compliance
227232

228233
MISRA compliance is enforced with the help of the following tools:
@@ -252,6 +257,17 @@ An exception applies for the case of false-positive (invalid) warnings -- those
252257
- [Dynamic Memory Allocation In SQLite](https://sqlite.org/malloc.html) -- on Robson proof and deterministic fragmentation.
253258
- *[Russian]* [Динамическая память в системах жёсткого реального времени](https://habr.com/ru/post/486650/) -- issues with dynamic memory allocation in modern embedded RTOS and related popular misconceptions.
254259

260+
## Changelog
261+
262+
### v2.0
263+
264+
- Remove critical section hooks to enhance MISRA conformance [#4](https://github.com/pavel-kirienko/o1heap/issues/4)
265+
- Add support for config header via `O1HEAP_CONFIG_HEADER` [#5](https://github.com/pavel-kirienko/o1heap/issues/5)
266+
267+
### v1.0
268+
269+
The first release.
270+
255271
## License
256272

257273
The library is available under the terms of the MIT License.

o1heap/.clang-tidy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ Checks: >-
1616
-google-readability-todo,
1717
-readability-avoid-const-params-in-decls,
1818
-llvm-header-guard,
19+
CheckOptions:
20+
- key: readability-function-cognitive-complexity.Threshold
21+
value: '199'
1922
WarningsAsErrors: '*'
2023
HeaderFilterRegex: '.*'
2124
AnalyzeTemporaryDtors: false

0 commit comments

Comments
 (0)