|
11 | 11 | // OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
12 | 12 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
13 | 13 | //
|
14 |
| -// Copyright (c) 2020 Pavel Kirienko |
| 14 | +// Copyright (c) Pavel Kirienko |
15 | 15 | // Authors: Pavel Kirienko <[email protected]>
|
16 | 16 |
|
| 17 | +// ReSharper disable CppDFANullDereference |
| 18 | + |
17 | 19 | #include "o1heap.h"
|
18 | 20 | #include <assert.h>
|
19 | 21 | #include <limits.h>
|
20 | 22 |
|
21 |
| -#ifdef O1HEAP_INCLUDE_CONFIG_HEADER |
22 |
| -#include "o1heap_config.h" |
23 |
| -#endif |
24 |
| - |
25 | 23 | // ---------------------------------------- BUILD CONFIGURATION OPTIONS ----------------------------------------
|
26 | 24 |
|
27 | 25 | /// Define this macro to include build configuration header. This is an alternative to the -D compiler flag.
|
@@ -83,19 +81,18 @@ O1HEAP_PRIVATE uint_fast8_t O1HEAP_CLZ(const size_t x)
|
83 | 81 | }
|
84 | 82 | #endif
|
85 | 83 |
|
86 |
| -/// By defining these symbols, preferably in o1heap_config.h (define O1HEAP_INCLUDE_CONFIG_HEADER to include, see |
87 |
| -/// above), trace tools can get events when o1heap memory is allocated or free'ed. For allocations, note that |
88 |
| -/// if the allocated memory pointer is NULL an allocation failure has occurred. In this case the size reported is |
89 |
| -// the number of bytes requested that the allocator could not provide. |
90 |
| -/// |
91 |
| -/// When using the pointer provided via O1HEAP_TRACE_FREE the pointer memory must not be accessed. This pointer |
92 |
| -/// should only be used for its address. |
93 |
| - |
94 |
| -#ifndef O1HEAP_TRACE_ALLOCATE |
95 |
| -# define O1HEAP_TRACE_ALLOCATE(handle, pointer, size) |
| 84 | +/// If O1HEAP_TRACE is defined and is nonzero, trace tools can get events when o1heap memory is allocated or freed. |
| 85 | +/// The corresponding events are delivered by invoking extern functions o1heapTraceAllocate() etc, defined in the |
| 86 | +/// application. Please refer to the documentation for those functions for the additional information. |
| 87 | +#ifndef O1HEAP_TRACE |
| 88 | +# define O1HEAP_TRACE 0 |
96 | 89 | #endif
|
97 |
| -#ifndef O1HEAP_TRACE_FREE |
98 |
| -# define O1HEAP_TRACE_FREE(handle, pointer, size) |
| 90 | +#if O1HEAP_TRACE |
| 91 | +# define O1HEAP_TRACE_ALLOCATE(handle, pointer, size) o1heapTraceAllocate(handle, pointer, size) |
| 92 | +# define O1HEAP_TRACE_FREE(handle, pointer, size) o1heapTraceFree(handle, pointer, size) |
| 93 | +#else |
| 94 | +# define O1HEAP_TRACE_ALLOCATE(handle, pointer, size) (void) 0 |
| 95 | +# define O1HEAP_TRACE_FREE(handle, pointer, size) (void) 0 |
99 | 96 | #endif
|
100 | 97 |
|
101 | 98 | // ---------------------------------------- INTERNAL DEFINITIONS ----------------------------------------
|
@@ -259,12 +256,6 @@ O1HEAP_PRIVATE void unbin(O1HeapInstance* const handle, const Fragment* const fr
|
259 | 256 | }
|
260 | 257 | }
|
261 | 258 |
|
262 |
| -#ifdef O1HEAP_TRACE |
263 |
| -// The user must implement these functions or linking will fail. |
264 |
| -extern void o1heapAllocateTrace(O1HeapInstance* const handle, void* const allocated_memory, size_t size_bytes); |
265 |
| -extern void o1heapFreeTrace(O1HeapInstance* const handle, void* const freed_memory, size_t size_bytes); |
266 |
| -#endif |
267 |
| - |
268 | 259 | // ---------------------------------------- PUBLIC API IMPLEMENTATION ----------------------------------------
|
269 | 260 |
|
270 | 261 | O1HeapInstance* o1heapInit(void* const base, const size_t size)
|
@@ -391,10 +382,14 @@ void* o1heapAllocate(O1HeapInstance* const handle, const size_t amount)
|
391 | 382 |
|
392 | 383 | out = ((char*) frag) + O1HEAP_ALIGNMENT;
|
393 | 384 | O1HEAP_TRACE_ALLOCATE(handle, out, frag->header.size);
|
394 |
| - } else { |
| 385 | + } |
| 386 | + else |
| 387 | + { |
395 | 388 | O1HEAP_TRACE_ALLOCATE(handle, out, amount);
|
396 | 389 | }
|
397 |
| - } else { |
| 390 | + } |
| 391 | + else |
| 392 | + { |
398 | 393 | O1HEAP_TRACE_ALLOCATE(handle, out, amount);
|
399 | 394 | }
|
400 | 395 |
|
|
0 commit comments