Rename user customizable macros

to be compliant with other
and clearer that they can be customized.
This commit is contained in:
Patrick Pelissier committed 2021-02-20 00:10:26 +01:00
1 parent 6cc972bab2
commit 165ec09061
6 files changed
+36 -36

No files matched your search

+10 -10
View File
@@ -1832,8 +1832,8 @@ M_BEGIN_PROTECTED_CODE
NOTE: Used by variant & serial JSON to translate a field name into NOTE: Used by variant & serial JSON to translate a field name into
a structure offset. a structure offset.
*/ */
#ifndef M_MAX_IDENTIFIER_LENGTH #ifndef M_USE_IDENTIFIER_ALLOC
#define M_MAX_IDENTIFIER_LENGTH 128 /* (including of final null char) */ #define M_USE_IDENTIFIER_ALLOC 128 /* (including of final null char) */
#endif #endif
/* Return the string format of a variable */ /* 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 /* Can be increased / decreased by user code if needed
to increase / decrease backoff of code */ to increase / decrease backoff of code */
#ifndef M_BACKOFF_MAX_COUNT #ifndef M_USE_BACKOFF_MAX_COUNT
#define M_BACKOFF_MAX_COUNT 6 #define M_USE_BACKOFF_MAX_COUNT 6
#endif #endif
/* Exponential backoff object. /* Exponential backoff object.
@@ -3505,7 +3505,7 @@ m_core_backoff_wait(m_core_backoff_ct backoff)
x = 0; x = 0;
(void) x; (void) x;
/* Increment count for next step if needed */ /* 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 */ /* 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 /* Maximum data size of a serializator structure
* Can be overloaded by user */ * Can be overloaded by user */
#ifndef M_SERIAL_MAX_DATA_SIZE #ifndef M_USE_SERIAL_MAX_DATA_SIZE
#define M_SERIAL_MAX_DATA_SIZE 4 #define M_USE_SERIAL_MAX_DATA_SIZE 4
#endif #endif
/* Different types of types that can be stored in a serial object to represent it: /* 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 is common to all calls to the same object.
It shall be used as a local state of the object being parsed */ It shall be used as a local state of the object being parsed */
typedef struct m_serial_local_s { 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]; } m_serial_local_t[1];
/* Object to handle the generic serial read of an object: /* 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 { typedef struct m_serial_read_s {
const struct m_serial_read_interface_s *m_interface; const struct m_serial_read_interface_s *m_interface;
m_serial_ll_ct tmp; 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]; } m_serial_read_t[1];
/* Interface that has to be exported by the serial read object. /* 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 { typedef struct m_serial_write_s {
const struct m_serial_write_interface_s *m_interface; const struct m_serial_write_interface_s *m_interface;
m_serial_ll_ct tmp; 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]; } m_serial_write_t[1];
/* Interface that has to be exported by the serial write object. /* Interface that has to be exported by the serial write object.
+12 -12
View File
@@ -51,17 +51,17 @@
((__VA_ARGS__, M_DEFAULT_OPLIST), \ ((__VA_ARGS__, M_DEFAULT_OPLIST), \
(__VA_ARGS__ ))) (__VA_ARGS__ )))
/********************************** INTERNAL ************************************/
/* Default initial size of a bucket of items */ /* Default initial size of a bucket of items */
#ifndef M_D3QU3_DEFAULT_SIZE #ifndef M_USE_DEQUE_DEFAULT_SIZE
#define M_D3QU3_DEFAULT_SIZE 8 #define M_USE_DEQUE_DEFAULT_SIZE 8
#endif #endif
/********************************** INTERNAL ************************************/
/* Define the internal contract of a deque */ /* Define the internal contract of a deque */
#define M_D3QU3_CONTRACT(d) do { \ #define M_D3QU3_CONTRACT(d) do { \
M_ASSERT ((d) != NULL); \ 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->node != NULL); \
M_ASSERT ((d)->front->index <= (d)->front->node->size); \ M_ASSERT ((d)->front->index <= (d)->front->node->size); \
M_ASSERT ((d)->back->node != NULL); \ M_ASSERT ((d)->back->node != NULL); \
@@ -188,15 +188,15 @@
M_C(name, _init)(deque_t d) \ M_C(name, _init)(deque_t d) \
{ \ { \
M_C(name, _node_list_init)(d->list); \ 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; \ d->count = 0; \
node_t *n = M_C3(m_d3qu3_,name,_new_node)(d); \ node_t *n = M_C3(m_d3qu3_,name,_new_node)(d); \
if (n == NULL) return; \ if (n == NULL) return; \
M_C(name, _node_list_push_back)(d->list, n); \ M_C(name, _node_list_push_back)(d->list, n); \
d->front->node = 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->node = n; \
d->back->index = M_D3QU3_DEFAULT_SIZE/2; \ d->back->index = M_USE_DEQUE_DEFAULT_SIZE/2; \
M_D3QU3_CONTRACT(d); \ M_D3QU3_CONTRACT(d); \
} \ } \
\ \
@@ -655,18 +655,18 @@
M_D3QU3_CONTRACT(src); \ M_D3QU3_CONTRACT(src); \
M_ASSERT (d != NULL); \ M_ASSERT (d != NULL); \
M_C(name, _node_list_init)(d->list); \ 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; \ d->count = src->count; \
node_t *n = M_C3(m_d3qu3_,name,_new_node)(d); \ node_t *n = M_C3(m_d3qu3_,name,_new_node)(d); \
if (n == NULL) return; \ if (n == NULL) return; \
d->default_size /= 2; \ d->default_size /= 2; \
M_C(name, _node_list_push_back)(d->list, n); \ M_C(name, _node_list_push_back)(d->list, n); \
d->front->node = 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->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; \ 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)) { \ 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); \ type const *obj = M_C(name, _cref)(it); \
M_CALL_INIT_SET(oplist, n->data[i], *obj); \ M_CALL_INIT_SET(oplist, n->data[i], *obj); \
+5 -5
View File
@@ -57,8 +57,8 @@
the minimun number of elements. the minimun number of elements.
The default is the number of elements that fits in 16KB. The default is the number of elements that fits in 16KB.
*/ */
#ifndef MEMPOOL_MAX_PER_SEGMENT #ifndef M_USE_MEMPOOL_MAX_PER_SEGMENT
#define MEMPOOL_MAX_PER_SEGMENT(type) \ #define M_USE_MEMPOOL_MAX_PER_SEGMENT(type) \
M_MAX((16*1024-sizeof(unsigned int) - 2*sizeof(void*)) / sizeof (type), 256U) M_MAX((16*1024-sizeof(unsigned int) - 2*sizeof(void*)) / sizeof (type), 256U)
#endif #endif
@@ -79,7 +79,7 @@
typedef struct M_C(name,_segment_s) { \ typedef struct M_C(name,_segment_s) { \
unsigned int count; \ unsigned int count; \
struct M_C(name,_segment_s) *next; \ 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); \ } M_C(name,_segment_ct); \
\ \
/* Define a mempool. \ /* Define a mempool. \
@@ -135,7 +135,7 @@
M_ASSERT(segment != NULL); \ M_ASSERT(segment != NULL); \
unsigned int count = segment->count; \ unsigned int count = segment->count; \
/* If segment is full, allocate a new one from the system */ \ /* 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)); \ M_C(name,_segment_ct) *new_segment = M_MEMORY_ALLOC (M_C(name,_segment_ct)); \
if (M_UNLIKELY (new_segment == NULL)) { \ if (M_UNLIKELY (new_segment == NULL)) { \
M_MEMORY_FULL(sizeof (M_C(name,_segment_ct))); \ M_MEMORY_FULL(sizeof (M_C(name,_segment_ct))); \
@@ -173,7 +173,7 @@
#define M_M3MPOOL_CONTRACT(mempool, type) do { \ #define M_M3MPOOL_CONTRACT(mempool, type) do { \
M_ASSERT((mempool) != NULL); \ M_ASSERT((mempool) != NULL); \
M_ASSERT((mempool)->current_segment != 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) } while (0)
#endif #endif
+6 -6
View File
@@ -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 */ /* Read the field in the JSON */
c = -1; c = -1;
char field[M_MAX_IDENTIFIER_LENGTH+1]; char field[M_USE_IDENTIFIER_ALLOC+1];
int nn = m_core_fscanf(f, " \"%" M_AS_STR(M_MAX_IDENTIFIER_LENGTH) "[^ \t\n\"]\":%n", int nn = m_core_fscanf(f, " \"%" M_AS_STR(M_USE_IDENTIFIER_ALLOC) "[^ \t\n\"]\":%n",
m_core_arg_size(field, M_MAX_IDENTIFIER_LENGTH+1), &c); m_core_arg_size(field, M_USE_IDENTIFIER_ALLOC+1), &c);
(void) nn ; // Unused. Check is done through 'c' (more robust). (void) nn ; // Unused. Check is done through 'c' (more robust).
if (c <= 0) if (c <= 0)
return m_core_serial_fail(); 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; if (final2 > 0) return M_SERIAL_OK_DONE;
/* Read the field in the JSON */ /* Read the field in the JSON */
char field[M_MAX_IDENTIFIER_LENGTH+1]; char field[M_USE_IDENTIFIER_ALLOC+1];
nn = m_core_fscanf(f, " \"%" M_AS_STR(M_MAX_IDENTIFIER_LENGTH) "[^ \t\n\"]\":%n", nn = m_core_fscanf(f, " \"%" M_AS_STR(M_USE_IDENTIFIER_ALLOC) "[^ \t\n\"]\":%n",
m_core_arg_size(field, M_MAX_IDENTIFIER_LENGTH+1), &final2); m_core_arg_size(field, M_USE_IDENTIFIER_ALLOC+1), &final2);
(void) nn ; // Unused. Check is done through final (more robust). (void) nn ; // Unused. Check is done through final (more robust).
if (final2 <= 0) return m_core_serial_fail(); if (final2 <= 0) return m_core_serial_fail();
+2 -2
View File
@@ -547,7 +547,7 @@
M_VAR1ANT_CONTRACT(name, el); \ M_VAR1ANT_CONTRACT(name, el); \
M_ASSERT (str != NULL); \ M_ASSERT (str != NULL); \
bool success = false; \ bool success = false; \
char variantTypeBuf[M_MAX_IDENTIFIER_LENGTH+1]; \ char variantTypeBuf[M_USE_IDENTIFIER_ALLOC+1]; \
int c = *str++; \ int c = *str++; \
unsigned int i = 0; \ unsigned int i = 0; \
M_C(name, _clean)(el); \ M_C(name, _clean)(el); \
@@ -609,7 +609,7 @@
FILE *f) { \ FILE *f) { \
M_VAR1ANT_CONTRACT(name, el); \ M_VAR1ANT_CONTRACT(name, el); \
M_ASSERT (f != NULL); \ M_ASSERT (f != NULL); \
char variantTypeBuf[M_MAX_IDENTIFIER_LENGTH+1]; \ char variantTypeBuf[M_USE_IDENTIFIER_ALLOC+1]; \
M_C(name, _clean)(el); \ M_C(name, _clean)(el); \
if (fgetc(f) != '@') return false; \ if (fgetc(f) != '@') return false; \
/* First read the name of the type */ \ /* First read the name of the type */ \
+1 -1
View File
@@ -52,7 +52,7 @@ static void test_ti1(int n)
deque_t d; deque_t d;
deque_init(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++) { for(int i =0; i < n ;i++) {
deque_push_back(d, i); deque_push_back(d, i);