Skip to content

Commit 4765c6f

Browse files
committed
Disable expensive debug checks
Expensive debug checks are under the ifdef from now: #if !defined(NDEBUG) && defined(UMF_DEVELOPER_MODE) Fixes: #1325 Signed-off-by: Lukasz Dorau <[email protected]>
1 parent 93c9ab0 commit 4765c6f

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

src/base_alloc/base_alloc.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ struct umf_ba_next_pool_t {
6666
char data[];
6767
};
6868

69-
#ifndef NDEBUG
69+
#if !defined(NDEBUG) && defined(UMF_DEVELOPER_MODE)
7070
static void ba_debug_checks(umf_ba_pool_t *pool) {
7171
// count pools
7272
size_t n_pools = 1;
@@ -89,7 +89,12 @@ static void ba_debug_checks(umf_ba_pool_t *pool) {
8989
}
9090
assert(n_free_chunks == pool->metadata.n_chunks - pool->metadata.n_allocs);
9191
}
92-
#endif /* NDEBUG */
92+
#else /* defined(NDEBUG) || !defined(UMF_DEVELOPER_MODE) */
93+
#define ba_debug_checks(pool) \
94+
do { \
95+
(void)(pool); /* suppress unused variable warning */ \
96+
} while (0)
97+
#endif /* defined(NDEBUG) || !defined(UMF_DEVELOPER_MODE) */
9398

9499
// ba_divide_memory_into_chunks - divide given memory into chunks of chunk_size and add them to the free_list
95100
static void ba_divide_memory_into_chunks(umf_ba_pool_t *pool, void *ptr,

src/coarse/coarse.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ static inline ravl_node_t *get_node_next(ravl_node_t *node) {
130130
return ravl_node_successor(node);
131131
}
132132

133-
#ifndef NDEBUG
133+
#if !defined(NDEBUG) && defined(UMF_DEVELOPER_MODE)
134134
static block_t *get_block_prev(ravl_node_t *node) {
135135
ravl_node_t *ravl_prev = ravl_node_predecessor(node);
136136
if (!ravl_prev) {
@@ -148,7 +148,7 @@ static block_t *get_block_next(ravl_node_t *node) {
148148

149149
return get_node_block(ravl_next);
150150
}
151-
#endif /* NDEBUG */
151+
#endif /* !defined(NDEBUG) && defined(UMF_DEVELOPER_MODE) */
152152

153153
// The functions "coarse_ravl_*" handles the coarse->all_blocks list of blocks
154154
// sorted by a pointer (block_t->data) to the beginning of the block data.
@@ -527,7 +527,8 @@ static ravl_node_t *free_block_merge_with_next(coarse_t *coarse,
527527
return merged_node;
528528
}
529529

530-
#ifndef NDEBUG // begin of DEBUG code
530+
// begin of DEBUG code
531+
#if !defined(NDEBUG) && defined(UMF_DEVELOPER_MODE)
531532

532533
typedef struct debug_cb_args_t {
533534
coarse_t *provider;
@@ -606,7 +607,13 @@ static bool debug_check(coarse_t *provider) {
606607

607608
return true;
608609
}
609-
#endif /* NDEBUG */ // end of DEBUG code
610+
#else /* defined(NDEBUG) || !defined(UMF_DEVELOPER_MODE) */
611+
static inline bool debug_check(coarse_t *provider) {
612+
(void)provider; // suppress unused variable warning
613+
return true;
614+
}
615+
#endif /* defined(NDEBUG) || !defined(UMF_DEVELOPER_MODE) */
616+
// end of DEBUG code
610617

611618
static umf_result_t coarse_add_used_block(coarse_t *coarse, void *addr,
612619
size_t size) {

0 commit comments

Comments
 (0)