Inlining string_fmt and fixing some unused warnings with __attribute__
This commit is contained in:
1 parent
9209e0d5ec
commit
424ba074ff
12 files changed
+94
-89
No files matched your search
@@ -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) \
|
||||
|
||||
@@ -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 <inttypes.h>
|
||||
#include <limits.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
Whitespace-only changes.
+12
-13
@@ -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, \
|
||||
|
||||
+12
-13
@@ -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, \
|
||||
|
||||
+12
-13
@@ -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, \
|
||||
|
||||
+12
-14
@@ -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, \
|
||||
|
||||
+11
-12
@@ -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); \
|
||||
|
||||
+11
-12
@@ -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); \
|
||||
|
||||
+5
-3
@@ -56,6 +56,8 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#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.
|
||||
|
||||
+5
-2
@@ -64,6 +64,8 @@
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#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;
|
||||
|
||||
+8
-3
@@ -42,6 +42,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#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)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user