From 424ba074ffc39c066035ecaa675ddfe8b386108a Mon Sep 17 00:00:00 2001 From: Leonardo Vencovsky Date: Tue, 2 Jun 2020 11:14:34 -0300 Subject: [PATCH] Inlining string_fmt and fixing some unused warnings with __attribute__ --- src/cmc/hashset.h | 4 ---- src/cor/core.h | 6 ++++++ src/dev/deque.h | 0 src/ext/cmc/deque.h | 25 ++++++++++++------------- src/ext/cmc/hashmap.h | 25 ++++++++++++------------- src/ext/cmc/hashmultimap.h | 25 ++++++++++++------------- src/ext/cmc/hashmultiset.h | 26 ++++++++++++-------------- src/ext/cmc/hashset.h | 23 +++++++++++------------ src/ext/cmc/heap.h | 23 +++++++++++------------ src/utl/assert.h | 8 +++++--- src/utl/log.h | 7 +++++-- src/utl/test.h | 11 ++++++++--- 12 files changed, 94 insertions(+), 89 deletions(-) create mode 100644 src/dev/deque.h diff --git a/src/cmc/hashset.h b/src/cmc/hashset.h index 8af3ec2..4b230da 100644 --- a/src/cmc/hashset.h +++ b/src/cmc/hashset.h @@ -172,10 +172,6 @@ static struct CMC_DEF_ENTRY(SNAME) * \ CMC_(PFX, _impl_get_entry)(struct SNAME * _set_, V value); \ static size_t CMC_(PFX, _impl_calculate_size)(size_t required); \ - static struct CMC_DEF_ITER(SNAME) \ - CMC_(PFX, _impl_it_start)(struct SNAME * _set_); \ - static struct CMC_DEF_ITER(SNAME) \ - CMC_(PFX, _impl_it_end)(struct SNAME * _set_); \ \ struct SNAME *CMC_(PFX, _new)(size_t capacity, double load, \ struct CMC_DEF_FVAL(SNAME) * f_val) \ diff --git a/src/cor/core.h b/src/cor/core.h index 68f6832..430d35d 100644 --- a/src/cor/core.h +++ b/src/cor/core.h @@ -22,6 +22,12 @@ #ifndef CMC_COR_CORE_H #define CMC_COR_CORE_H +#if defined(__GNUC__) || defined(__clang__) +#define CMC_UNUSED __attribute__((__unused__)) +#else +#define CMC_UNUSED +#endif + #include #include #include diff --git a/src/dev/deque.h b/src/dev/deque.h new file mode 100644 index 0000000..e69de29 diff --git a/src/ext/cmc/deque.h b/src/ext/cmc/deque.h index 9106969..188a90c 100644 --- a/src/ext/cmc/deque.h +++ b/src/ext/cmc/deque.h @@ -361,18 +361,6 @@ /** * STR */ -static const char *cmc_cmc_string_fmt_deque = "struct %s<%s> " - "at %p { " - "buffer:%p, " - "capacity:%" PRIuMAX ", " - "count:%" PRIuMAX ", " - "front:%" PRIuMAX ", " - "back:%" PRIuMAX ", " - "flag:%d, " - "f_val:%p, " - "alloc:%p, " - "callbacks:%p }"; - #define CMC_EXT_CMC_DEQUE_STR(PARAMS) \ CMC_EXT_CMC_DEQUE_STR_HEADER(PARAMS) \ CMC_EXT_CMC_DEQUE_STR_SOURCE(PARAMS) @@ -398,7 +386,18 @@ static const char *cmc_cmc_string_fmt_deque = "struct %s<%s> " { \ struct SNAME *d_ = _deque_; \ \ - return 0 <= fprintf(fptr, cmc_cmc_string_fmt_deque, \ + return 0 <= fprintf(fptr, \ + "struct %s<%s> " \ + "at %p { " \ + "buffer:%p, " \ + "capacity:%" PRIuMAX ", " \ + "count:%" PRIuMAX ", " \ + "front:%" PRIuMAX ", " \ + "back:%" PRIuMAX ", " \ + "flag:%d, " \ + "f_val:%p, " \ + "alloc:%p, " \ + "callbacks:%p }", \ CMC_TO_STRING(SNAME), CMC_TO_STRING(V), d_, \ d_->buffer, d_->capacity, d_->count, d_->front, \ d_->back, d_->flag, d_->f_val, d_->alloc, \ diff --git a/src/ext/cmc/hashmap.h b/src/ext/cmc/hashmap.h index 3354a21..10ba62b 100644 --- a/src/ext/cmc/hashmap.h +++ b/src/ext/cmc/hashmap.h @@ -437,18 +437,6 @@ /** * STR */ -static const char *cmc_cmc_string_fmt_hashmap = "struct %s<%s, %s> " - "at %p { " - "buffer:%p, " - "capacity:%" PRIuMAX ", " - "count:%" PRIuMAX ", " - "load:%lf, " - "flag:%d, " - "f_key:%p, " - "f_val:%p, " - "alloc:%p, " - "callbacks:%p }"; - #define CMC_EXT_CMC_HASHMAP_STR(PARAMS) \ CMC_EXT_CMC_HASHMAP_STR_HEADER(PARAMS) \ CMC_EXT_CMC_HASHMAP_STR_SOURCE(PARAMS) @@ -476,7 +464,18 @@ static const char *cmc_cmc_string_fmt_hashmap = "struct %s<%s, %s> " { \ struct SNAME *m_ = _map_; \ \ - return 0 <= fprintf(fptr, cmc_cmc_string_fmt_hashmap, \ + return 0 <= fprintf(fptr, \ + "struct %s<%s, %s> " \ + "at %p { " \ + "buffer:%p, " \ + "capacity:%" PRIuMAX ", " \ + "count:%" PRIuMAX ", " \ + "load:%lf, " \ + "flag:%d, " \ + "f_key:%p, " \ + "f_val:%p, " \ + "alloc:%p, " \ + "callbacks:%p }", \ CMC_TO_STRING(SNAME), CMC_TO_STRING(K), \ CMC_TO_STRING(V), m_, m_->buffer, m_->capacity, \ m_->count, m_->load, m_->flag, m_->f_key, \ diff --git a/src/ext/cmc/hashmultimap.h b/src/ext/cmc/hashmultimap.h index 51c8436..3730f45 100644 --- a/src/ext/cmc/hashmultimap.h +++ b/src/ext/cmc/hashmultimap.h @@ -379,18 +379,6 @@ /** * STR */ -static const char *cmc_cmc_string_fmt_hashmultimap = "struct %s<%s, %s> " - "at %p { " - "buffer:%p, " - "capacity:%" PRIuMAX ", " - "count:%" PRIuMAX ", " - "load:%lf, " - "flag:%d, " - "f_key:%p, " - "f_val:%p, " - "alloc:%p, " - "callbacks:%p }"; - #define CMC_EXT_CMC_HASHMULTIMAP_STR(PARAMS) \ CMC_EXT_CMC_HASHMULTIMAP_STR_HEADER(PARAMS) \ CMC_EXT_CMC_HASHMULTIMAP_STR_SOURCE(PARAMS) @@ -418,7 +406,18 @@ static const char *cmc_cmc_string_fmt_hashmultimap = "struct %s<%s, %s> " { \ struct SNAME *m_ = _map_; \ \ - return 0 <= fprintf(fptr, cmc_cmc_string_fmt_hashmultimap, \ + return 0 <= fprintf(fptr, \ + "struct %s<%s, %s> " \ + "at %p { " \ + "buffer:%p, " \ + "capacity:%" PRIuMAX ", " \ + "count:%" PRIuMAX ", " \ + "load:%lf, " \ + "flag:%d, " \ + "f_key:%p, " \ + "f_val:%p, " \ + "alloc:%p, " \ + "callbacks:%p }", \ CMC_TO_STRING(SNAME), CMC_TO_STRING(K), \ CMC_TO_STRING(V), m_, m_->buffer, m_->capacity, \ m_->count, m_->load, m_->flag, m_->f_key, \ diff --git a/src/ext/cmc/hashmultiset.h b/src/ext/cmc/hashmultiset.h index c2d10c5..518eea0 100644 --- a/src/ext/cmc/hashmultiset.h +++ b/src/ext/cmc/hashmultiset.h @@ -345,19 +345,6 @@ /** * STR */ -static const char *cmc_cmc_string_fmt_hashmultiset = - "struct %s<%s> " - "at %p { " - "buffer:%p, " - "capacity:%" PRIuMAX ", " - "count:%" PRIuMAX ", " - "cardinality:%" PRIuMAX ", " - "load:%lf, " - "flag:%d, " - "f_val:%p, " - "alloc:%p, " - "callbacks:%p }"; - #define CMC_EXT_CMC_HASHMULTISET_STR(PARAMS) \ CMC_EXT_CMC_HASHMULTISET_STR_HEADER(PARAMS) \ CMC_EXT_CMC_HASHMULTISET_STR_SOURCE(PARAMS) @@ -383,7 +370,18 @@ static const char *cmc_cmc_string_fmt_hashmultiset = { \ struct SNAME *s_ = _set_; \ \ - return 0 <= fprintf(fptr, cmc_cmc_string_fmt_hashmultiset, \ + return 0 <= fprintf(fptr, \ + "struct %s<%s> " \ + "at %p { " \ + "buffer:%p, " \ + "capacity:%" PRIuMAX ", " \ + "count:%" PRIuMAX ", " \ + "cardinality:%" PRIuMAX ", " \ + "load:%lf, " \ + "flag:%d, " \ + "f_val:%p, " \ + "alloc:%p, " \ + "callbacks:%p }", \ CMC_TO_STRING(SNAME), CMC_TO_STRING(V), s_, \ s_->buffer, s_->capacity, s_->count, \ s_->cardinality, s_->load, s_->flag, s_->f_val, \ diff --git a/src/ext/cmc/hashset.h b/src/ext/cmc/hashset.h index 344738c..933ce46 100644 --- a/src/ext/cmc/hashset.h +++ b/src/ext/cmc/hashset.h @@ -336,17 +336,6 @@ /** * STR */ -static const char *cmc_cmc_string_fmt_hashset = "struct %s<%s> " - "at %p { " - "buffer:%p, " - "capacity:%" PRIuMAX ", " - "count:%" PRIuMAX ", " - "load:%lf, " - "flag:%d, " - "f_val:%p, " - "alloc:%p, " - "callbacks: %p }"; - #define CMC_EXT_CMC_HASHSET_STR(PARAMS) \ CMC_EXT_CMC_HASHSET_STR_HEADER(PARAMS) \ CMC_EXT_CMC_HASHSET_STR_SOURCE(PARAMS) @@ -372,7 +361,17 @@ static const char *cmc_cmc_string_fmt_hashset = "struct %s<%s> " { \ struct SNAME *s_ = _set_; \ \ - return 0 <= fprintf(fptr, cmc_cmc_string_fmt_hashset, \ + return 0 <= fprintf(fptr, \ + "struct %s<%s> " \ + "at %p { " \ + "buffer:%p, " \ + "capacity:%" PRIuMAX ", " \ + "count:%" PRIuMAX ", " \ + "load:%lf, " \ + "flag:%d, " \ + "f_val:%p, " \ + "alloc:%p, " \ + "callbacks: %p }", \ CMC_TO_STRING(SNAME), CMC_TO_STRING(V), s_, \ s_->buffer, s_->capacity, s_->count, s_->load, \ s_->flag, s_->f_val, s_->alloc, s_->callbacks); \ diff --git a/src/ext/cmc/heap.h b/src/ext/cmc/heap.h index bc98c8d..33d8cc1 100644 --- a/src/ext/cmc/heap.h +++ b/src/ext/cmc/heap.h @@ -253,17 +253,6 @@ /** * STR */ -static const char *cmc_cmc_string_fmt_heap = "struct %s<%s> " - "at %p { " - "buffer:%p, " - "capacity:%" PRIuMAX ", " - "count:%" PRIuMAX ", " - "type:%s, " - "flag:%d, " - "f_val:%p, " - "alloc:%p, " - "callbacks: %p}"; - #define CMC_EXT_CMC_HEAP_STR(PARAMS) \ CMC_EXT_CMC_HEAP_STR_HEADER(PARAMS) \ CMC_EXT_CMC_HEAP_STR_SOURCE(PARAMS) @@ -290,7 +279,17 @@ static const char *cmc_cmc_string_fmt_heap = "struct %s<%s> " struct SNAME *h_ = _heap_; \ const char *t = h_->HO == 1 ? "MaxHeap" : "MinHeap"; \ \ - return 0 <= fprintf(fptr, cmc_cmc_string_fmt_heap, \ + return 0 <= fprintf(fptr, \ + "struct %s<%s> " \ + "at %p { " \ + "buffer:%p, " \ + "capacity:%" PRIuMAX ", " \ + "count:%" PRIuMAX ", " \ + "type:%s, " \ + "flag:%d, " \ + "f_val:%p, " \ + "alloc:%p, " \ + "callbacks: %p}", \ CMC_TO_STRING(SNAME), CMC_TO_STRING(V), h_, \ h_->buffer, h_->capacity, h_->count, t, h_->flag, \ h_->f_val, h_->alloc, h_->callbacks); \ diff --git a/src/utl/assert.h b/src/utl/assert.h index 0d3a844..c63883c 100644 --- a/src/utl/assert.h +++ b/src/utl/assert.h @@ -56,6 +56,8 @@ #include #include +#include "../cor/core.h" + #define CMC_ASSERT_GLUE_(dtype, assertion) cmc_assert_##assertion##_##dtype #define CMC_ASSERT_GLUE(dtype, assertion) CMC_ASSERT_GLUE_(dtype, assertion) @@ -68,21 +70,21 @@ * This variable is also used in test.h utility to automatically pass or fail a * unit test. Once the unit test finishes, this variable is set back to true. */ -static bool cmc_assert_state = true; +CMC_UNUSED static bool cmc_assert_state = true; /** * cmc_assert_total * * Tracks the total calls to any type of assertion. */ -static uintmax_t cmc_assert_total = 0; +CMC_UNUSED static uintmax_t cmc_assert_total = 0; /** * cmc_assert_failed * * Tracks the total failed assertions. */ -static uintmax_t cmc_assert_failed = 0; +CMC_UNUSED static uintmax_t cmc_assert_failed = 0; /** * expression : An expression that is expected to be evaluated to true. diff --git a/src/utl/log.h b/src/utl/log.h index eada5f5..6027ee3 100644 --- a/src/utl/log.h +++ b/src/utl/log.h @@ -64,6 +64,8 @@ #include #include +#include "../cor/core.h" + static const char *cmc_log_names[] = { "TRACE", "DEBUG", "INFO", "WARN", "ERROR", "FATAL" }; @@ -106,8 +108,9 @@ static struct #define cmc_log_fatal(fmt, ...) \ cmc_log(CMC_LOG_FATAL, __FILE__, __func__, __LINE__, fmt, ##__VA_ARGS__) -static void cmc_log(enum cmc_log_type log, const char *filename, - const char *funcname, unsigned line, const char *fmt, ...) +CMC_UNUSED static void cmc_log(enum cmc_log_type log, const char *filename, + const char *funcname, unsigned line, + const char *fmt, ...) { if (!cmc_log_config.enabled) return; diff --git a/src/utl/test.h b/src/utl/test.h index 7111421..be7b76f 100644 --- a/src/utl/test.h +++ b/src/utl/test.h @@ -42,6 +42,7 @@ #include #include +#include "../cor/core.h" #include "assert.h" #include "timer.h" @@ -56,9 +57,9 @@ struct cmc_test_info bool verbose; }; +#ifdef CMC_TEST_COLOR static inline const char *cmc_test_color(int i) { -#ifdef CMC_TEST_COLOR // 0 - Default, all off // 1 - Failed (red) // 2 - Passed (green) @@ -70,13 +71,17 @@ static inline const char *cmc_test_color(int i) }; return cmc_test_colors[i]; #else +static inline const char *cmc_test_color(int i) +{ + (void)i; return ""; #endif } /* Logging function */ -static void cmc_test_log(const char *unit_name, const char *current_test, - bool aborted, bool passed) +CMC_UNUSED static void cmc_test_log(const char *unit_name, + const char *current_test, bool aborted, + bool passed) { if (aborted) {