From 165ec0906101ca5bf97985c9aeec3c8603f43779 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Sat, 20 Feb 2021 00:10:26 +0100 Subject: [PATCH] Rename user customizable macros to be compliant with other and clearer that they can be customized. --- m-core.h | 20 ++++++++++---------- m-deque.h | 24 ++++++++++++------------ m-mempool.h | 10 +++++----- m-serial-json.h | 12 ++++++------ m-variant.h | 4 ++-- tests/test-mdeque.c | 2 +- 6 files changed, 36 insertions(+), 36 deletions(-) diff --git a/m-core.h b/m-core.h index 2db1b193..88846dd6 100644 --- a/m-core.h +++ b/m-core.h @@ -1832,8 +1832,8 @@ M_BEGIN_PROTECTED_CODE NOTE: Used by variant & serial JSON to translate a field name into a structure offset. */ -#ifndef M_MAX_IDENTIFIER_LENGTH -#define M_MAX_IDENTIFIER_LENGTH 128 /* (including of final null char) */ +#ifndef M_USE_IDENTIFIER_ALLOC +#define M_USE_IDENTIFIER_ALLOC 128 /* (including of final null char) */ #endif /* Return the string format of a variable */ @@ -3455,8 +3455,8 @@ m_core_parse2_enum (const char str[], const char **endptr) /* Can be increased / decreased by user code if needed to increase / decrease backoff of code */ -#ifndef M_BACKOFF_MAX_COUNT -#define M_BACKOFF_MAX_COUNT 6 +#ifndef M_USE_BACKOFF_MAX_COUNT +#define M_USE_BACKOFF_MAX_COUNT 6 #endif /* Exponential backoff object. @@ -3505,7 +3505,7 @@ m_core_backoff_wait(m_core_backoff_ct backoff) x = 0; (void) x; /* Increment count for next step if needed */ - backoff->count += (backoff->count < M_BACKOFF_MAX_COUNT); + backoff->count += (backoff->count < M_USE_BACKOFF_MAX_COUNT); } /* Clear the backoff object */ @@ -3551,8 +3551,8 @@ inline m_serial_return_code_t operator&(m_serial_return_code_t a, m_serial_retur /* Maximum data size of a serializator structure * Can be overloaded by user */ -#ifndef M_SERIAL_MAX_DATA_SIZE -#define M_SERIAL_MAX_DATA_SIZE 4 +#ifndef M_USE_SERIAL_MAX_DATA_SIZE +#define M_USE_SERIAL_MAX_DATA_SIZE 4 #endif /* Different types of types that can be stored in a serial object to represent it: @@ -3575,7 +3575,7 @@ typedef union m_serial_ll_u { It is common to all calls to the same object. It shall be used as a local state of the object being parsed */ typedef struct m_serial_local_s { - m_serial_ll_ct data[M_SERIAL_MAX_DATA_SIZE]; + m_serial_ll_ct data[M_USE_SERIAL_MAX_DATA_SIZE]; } m_serial_local_t[1]; /* Object to handle the generic serial read of an object: @@ -3588,7 +3588,7 @@ typedef struct m_serial_local_s { typedef struct m_serial_read_s { const struct m_serial_read_interface_s *m_interface; m_serial_ll_ct tmp; - m_serial_ll_ct data[M_SERIAL_MAX_DATA_SIZE]; + m_serial_ll_ct data[M_USE_SERIAL_MAX_DATA_SIZE]; } m_serial_read_t[1]; /* Interface that has to be exported by the serial read object. @@ -3621,7 +3621,7 @@ typedef struct m_serial_read_interface_s { typedef struct m_serial_write_s { const struct m_serial_write_interface_s *m_interface; m_serial_ll_ct tmp; - m_serial_ll_ct data[M_SERIAL_MAX_DATA_SIZE]; + m_serial_ll_ct data[M_USE_SERIAL_MAX_DATA_SIZE]; } m_serial_write_t[1]; /* Interface that has to be exported by the serial write object. diff --git a/m-deque.h b/m-deque.h index 1528b490..32cdd58d 100644 --- a/m-deque.h +++ b/m-deque.h @@ -51,17 +51,17 @@ ((__VA_ARGS__, M_DEFAULT_OPLIST), \ (__VA_ARGS__ ))) -/********************************** INTERNAL ************************************/ - /* Default initial size of a bucket of items */ -#ifndef M_D3QU3_DEFAULT_SIZE -#define M_D3QU3_DEFAULT_SIZE 8 +#ifndef M_USE_DEQUE_DEFAULT_SIZE +#define M_USE_DEQUE_DEFAULT_SIZE 8 #endif +/********************************** INTERNAL ************************************/ + /* Define the internal contract of a deque */ #define M_D3QU3_CONTRACT(d) do { \ M_ASSERT ((d) != NULL); \ - M_ASSERT ((d)->default_size >= M_D3QU3_DEFAULT_SIZE); \ + M_ASSERT ((d)->default_size >= M_USE_DEQUE_DEFAULT_SIZE); \ M_ASSERT ((d)->front->node != NULL); \ M_ASSERT ((d)->front->index <= (d)->front->node->size); \ M_ASSERT ((d)->back->node != NULL); \ @@ -188,15 +188,15 @@ M_C(name, _init)(deque_t d) \ { \ M_C(name, _node_list_init)(d->list); \ - d->default_size = M_D3QU3_DEFAULT_SIZE; \ + d->default_size = M_USE_DEQUE_DEFAULT_SIZE; \ d->count = 0; \ node_t *n = M_C3(m_d3qu3_,name,_new_node)(d); \ if (n == NULL) return; \ M_C(name, _node_list_push_back)(d->list, n); \ d->front->node = n; \ - d->front->index = M_D3QU3_DEFAULT_SIZE/2; \ + d->front->index = M_USE_DEQUE_DEFAULT_SIZE/2; \ d->back->node = n; \ - d->back->index = M_D3QU3_DEFAULT_SIZE/2; \ + d->back->index = M_USE_DEQUE_DEFAULT_SIZE/2; \ M_D3QU3_CONTRACT(d); \ } \ \ @@ -655,18 +655,18 @@ M_D3QU3_CONTRACT(src); \ M_ASSERT (d != NULL); \ M_C(name, _node_list_init)(d->list); \ - d->default_size = M_D3QU3_DEFAULT_SIZE + src->count; \ + d->default_size = M_USE_DEQUE_DEFAULT_SIZE + src->count; \ d->count = src->count; \ node_t *n = M_C3(m_d3qu3_,name,_new_node)(d); \ if (n == NULL) return; \ d->default_size /= 2; \ M_C(name, _node_list_push_back)(d->list, n); \ d->front->node = n; \ - d->front->index = M_D3QU3_DEFAULT_SIZE/2; \ + d->front->index = M_USE_DEQUE_DEFAULT_SIZE/2; \ d->back->node = n; \ - d->back->index = M_D3QU3_DEFAULT_SIZE/2 + src->count; \ + d->back->index = M_USE_DEQUE_DEFAULT_SIZE/2 + src->count; \ it_t it; \ - size_t i = M_D3QU3_DEFAULT_SIZE/2; \ + size_t i = M_USE_DEQUE_DEFAULT_SIZE/2; \ for(M_C(name, _it)(it, src); !M_C(name, _end_p)(it) ; M_C(name, _next)(it)) { \ type const *obj = M_C(name, _cref)(it); \ M_CALL_INIT_SET(oplist, n->data[i], *obj); \ diff --git a/m-mempool.h b/m-mempool.h index 2a106e7e..92c4aa2a 100644 --- a/m-mempool.h +++ b/m-mempool.h @@ -57,8 +57,8 @@ the minimun number of elements. The default is the number of elements that fits in 16KB. */ -#ifndef MEMPOOL_MAX_PER_SEGMENT -#define MEMPOOL_MAX_PER_SEGMENT(type) \ +#ifndef M_USE_MEMPOOL_MAX_PER_SEGMENT +#define M_USE_MEMPOOL_MAX_PER_SEGMENT(type) \ M_MAX((16*1024-sizeof(unsigned int) - 2*sizeof(void*)) / sizeof (type), 256U) #endif @@ -79,7 +79,7 @@ typedef struct M_C(name,_segment_s) { \ unsigned int count; \ struct M_C(name,_segment_s) *next; \ - M_C(name,_union_ct) tab[MEMPOOL_MAX_PER_SEGMENT(type)]; \ + M_C(name,_union_ct) tab[M_USE_MEMPOOL_MAX_PER_SEGMENT(type)]; \ } M_C(name,_segment_ct); \ \ /* Define a mempool. \ @@ -135,7 +135,7 @@ M_ASSERT(segment != NULL); \ unsigned int count = segment->count; \ /* If segment is full, allocate a new one from the system */ \ - if (M_UNLIKELY (count >= MEMPOOL_MAX_PER_SEGMENT(type))) { \ + if (M_UNLIKELY (count >= M_USE_MEMPOOL_MAX_PER_SEGMENT(type))) { \ M_C(name,_segment_ct) *new_segment = M_MEMORY_ALLOC (M_C(name,_segment_ct)); \ if (M_UNLIKELY (new_segment == NULL)) { \ M_MEMORY_FULL(sizeof (M_C(name,_segment_ct))); \ @@ -173,7 +173,7 @@ #define M_M3MPOOL_CONTRACT(mempool, type) do { \ M_ASSERT((mempool) != NULL); \ M_ASSERT((mempool)->current_segment != NULL); \ - M_ASSERT((mempool)->current_segment->count <= MEMPOOL_MAX_PER_SEGMENT(type)); \ + M_ASSERT((mempool)->current_segment->count <= M_USE_MEMPOOL_MAX_PER_SEGMENT(type)); \ } while (0) #endif diff --git a/m-serial-json.h b/m-serial-json.h index 28037592..089734b2 100644 --- a/m-serial-json.h +++ b/m-serial-json.h @@ -473,9 +473,9 @@ m_serial_json_read_tuple_id(m_serial_local_t local, m_serial_read_t serial, cons } /* Read the field in the JSON */ c = -1; - char field[M_MAX_IDENTIFIER_LENGTH+1]; - int nn = m_core_fscanf(f, " \"%" M_AS_STR(M_MAX_IDENTIFIER_LENGTH) "[^ \t\n\"]\":%n", - m_core_arg_size(field, M_MAX_IDENTIFIER_LENGTH+1), &c); + char field[M_USE_IDENTIFIER_ALLOC+1]; + int nn = m_core_fscanf(f, " \"%" M_AS_STR(M_USE_IDENTIFIER_ALLOC) "[^ \t\n\"]\":%n", + m_core_arg_size(field, M_USE_IDENTIFIER_ALLOC+1), &c); (void) nn ; // Unused. Check is done through 'c' (more robust). if (c <= 0) return m_core_serial_fail(); @@ -509,9 +509,9 @@ m_serial_json_read_variant_start(m_serial_local_t local, m_serial_read_t serial, if (final2 > 0) return M_SERIAL_OK_DONE; /* Read the field in the JSON */ - char field[M_MAX_IDENTIFIER_LENGTH+1]; - nn = m_core_fscanf(f, " \"%" M_AS_STR(M_MAX_IDENTIFIER_LENGTH) "[^ \t\n\"]\":%n", - m_core_arg_size(field, M_MAX_IDENTIFIER_LENGTH+1), &final2); + char field[M_USE_IDENTIFIER_ALLOC+1]; + nn = m_core_fscanf(f, " \"%" M_AS_STR(M_USE_IDENTIFIER_ALLOC) "[^ \t\n\"]\":%n", + m_core_arg_size(field, M_USE_IDENTIFIER_ALLOC+1), &final2); (void) nn ; // Unused. Check is done through final (more robust). if (final2 <= 0) return m_core_serial_fail(); diff --git a/m-variant.h b/m-variant.h index 563b12bc..f2a7b69c 100644 --- a/m-variant.h +++ b/m-variant.h @@ -547,7 +547,7 @@ M_VAR1ANT_CONTRACT(name, el); \ M_ASSERT (str != NULL); \ bool success = false; \ - char variantTypeBuf[M_MAX_IDENTIFIER_LENGTH+1]; \ + char variantTypeBuf[M_USE_IDENTIFIER_ALLOC+1]; \ int c = *str++; \ unsigned int i = 0; \ M_C(name, _clean)(el); \ @@ -609,7 +609,7 @@ FILE *f) { \ M_VAR1ANT_CONTRACT(name, el); \ M_ASSERT (f != NULL); \ - char variantTypeBuf[M_MAX_IDENTIFIER_LENGTH+1]; \ + char variantTypeBuf[M_USE_IDENTIFIER_ALLOC+1]; \ M_C(name, _clean)(el); \ if (fgetc(f) != '@') return false; \ /* First read the name of the type */ \ diff --git a/tests/test-mdeque.c b/tests/test-mdeque.c index d754104a..6a83b6ad 100644 --- a/tests/test-mdeque.c +++ b/tests/test-mdeque.c @@ -52,7 +52,7 @@ static void test_ti1(int n) deque_t d; deque_init(d); - assert(deque_capacity(d) == M_D3QU3_DEFAULT_SIZE); + assert(deque_capacity(d) == M_USE_DEQUE_DEFAULT_SIZE); for(int i =0; i < n ;i++) { deque_push_back(d, i);