Create M_ASSERT macro to encapsulate assert within M*LIB
The goal is to enable the user to override this macro if needed so that it can enable or disable the M*LIB witout impacting its own assertions.
This commit is contained in:
1 parent
f5afd6e275
commit
a29682ca29
26 files changed
+901
-888
No files matched your search
@@ -285,14 +285,14 @@
|
|||||||
M_CALL_SPLICE_BACK(cont_oplist, (b ? l1 : l2), l, it); \
|
M_CALL_SPLICE_BACK(cont_oplist, (b ? l1 : l2), l, it); \
|
||||||
b = !b; \
|
b = !b; \
|
||||||
} \
|
} \
|
||||||
/* assert(M_CALL_EMPTY_P (cont_oplist, l)); */ \
|
/* M_ASSERT(M_CALL_EMPTY_P (cont_oplist, l)); */ \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
/* Merge in empty 'l' the sorted container 'l1' and 'l2' */ \
|
/* Merge in empty 'l' the sorted container 'l1' and 'l2' */ \
|
||||||
static inline void \
|
static inline void \
|
||||||
M_C3(name,sort_name,_merge)(container_t l, container_t l1, container_t l2 cmp_param(name)) \
|
M_C3(name,sort_name,_merge)(container_t l, container_t l1, container_t l2 cmp_param(name)) \
|
||||||
{ \
|
{ \
|
||||||
/* assert(M_CALL_EMPTY_P (cont_oplist, l)); */ \
|
/* M_ASSERT(M_CALL_EMPTY_P (cont_oplist, l)); */ \
|
||||||
it_t it; \
|
it_t it; \
|
||||||
it_t it1; \
|
it_t it1; \
|
||||||
it_t it2; \
|
it_t it2; \
|
||||||
@@ -448,8 +448,8 @@
|
|||||||
it_t itSrc; \
|
it_t itSrc; \
|
||||||
it_t itDst; \
|
it_t itDst; \
|
||||||
it_t itIns; \
|
it_t itIns; \
|
||||||
assert(M_C3(name,sort_name,_p)(dst cmp_arg)); \
|
M_ASSERT(M_C3(name,sort_name,_p)(dst cmp_arg)); \
|
||||||
assert(M_C3(name,sort_name,_p)(src cmp_arg)); \
|
M_ASSERT(M_C3(name,sort_name,_p)(src cmp_arg)); \
|
||||||
/* Iterate over both dst & src containers */ \
|
/* Iterate over both dst & src containers */ \
|
||||||
M_CALL_IT_FIRST(cont_oplist, itSrc, src); \
|
M_CALL_IT_FIRST(cont_oplist, itSrc, src); \
|
||||||
M_CALL_IT_FIRST(cont_oplist, itDst, dst); \
|
M_CALL_IT_FIRST(cont_oplist, itDst, dst); \
|
||||||
@@ -492,8 +492,8 @@
|
|||||||
{ \
|
{ \
|
||||||
it_t itSrc; \
|
it_t itSrc; \
|
||||||
it_t itDst; \
|
it_t itDst; \
|
||||||
assert(M_C3(name,sort_name,_p)(dst cmp_arg)); \
|
M_ASSERT(M_C3(name,sort_name,_p)(dst cmp_arg)); \
|
||||||
assert(M_C3(name,sort_name,_p)(src cmp_arg)); \
|
M_ASSERT(M_C3(name,sort_name,_p)(src cmp_arg)); \
|
||||||
M_CALL_IT_FIRST(cont_oplist, itSrc, src); \
|
M_CALL_IT_FIRST(cont_oplist, itSrc, src); \
|
||||||
M_CALL_IT_FIRST(cont_oplist, itDst, dst); \
|
M_CALL_IT_FIRST(cont_oplist, itDst, dst); \
|
||||||
/* TODO: Not optimized at all for array ! O(n^2) */ \
|
/* TODO: Not optimized at all for array ! O(n^2) */ \
|
||||||
@@ -770,7 +770,7 @@
|
|||||||
container_t src, \
|
container_t src, \
|
||||||
M_C(name, _transform_cb_ct) func) \
|
M_C(name, _transform_cb_ct) func) \
|
||||||
{ \
|
{ \
|
||||||
assert(dst != src); \
|
M_ASSERT(dst != src); \
|
||||||
M_CALL_CLEAN(cont_oplist, dst); \
|
M_CALL_CLEAN(cont_oplist, dst); \
|
||||||
for M_EACH(item, src, cont_oplist) { \
|
for M_EACH(item, src, cont_oplist) { \
|
||||||
type_t tmp; \
|
type_t tmp; \
|
||||||
@@ -919,7 +919,7 @@
|
|||||||
{ \
|
{ \
|
||||||
it_t it1; \
|
it_t it1; \
|
||||||
it_t it2; \
|
it_t it2; \
|
||||||
assert(M_C(name, _sort_p)(l)); \
|
M_ASSERT(M_C(name, _sort_p)(l)); \
|
||||||
M_CALL_IT_FIRST(cont_oplist, it1, l); \
|
M_CALL_IT_FIRST(cont_oplist, it1, l); \
|
||||||
M_CALL_IT_SET(cont_oplist, it2, it1); \
|
M_CALL_IT_SET(cont_oplist, it2, it1); \
|
||||||
M_CALL_IT_NEXT(cont_oplist, it2); \
|
M_CALL_IT_NEXT(cont_oplist, it2); \
|
||||||
|
|||||||
@@ -134,9 +134,9 @@
|
|||||||
|
|
||||||
/* Define the internal contract of an array */
|
/* Define the internal contract of an array */
|
||||||
#define ARRAYI_CONTRACT(a) do { \
|
#define ARRAYI_CONTRACT(a) do { \
|
||||||
assert (a != NULL); \
|
M_ASSERT (a != NULL); \
|
||||||
assert (a->size <= a->alloc); \
|
M_ASSERT (a->size <= a->alloc); \
|
||||||
assert (a->size == 0 || a->ptr != NULL); \
|
M_ASSERT (a->size == 0 || a->ptr != NULL); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
/* Deferred evaluation for the array definition,
|
/* Deferred evaluation for the array definition,
|
||||||
@@ -185,7 +185,7 @@
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _init)(array_t v) \
|
M_C(name, _init)(array_t v) \
|
||||||
{ \
|
{ \
|
||||||
assert (v != NULL); \
|
M_ASSERT (v != NULL); \
|
||||||
/* Initially, the array is empty with nothing allocated */ \
|
/* Initially, the array is empty with nothing allocated */ \
|
||||||
v->size = 0; \
|
v->size = 0; \
|
||||||
v->alloc = 0; \
|
v->alloc = 0; \
|
||||||
@@ -245,7 +245,7 @@
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _init_set)(array_t d, const array_t s) \
|
M_C(name, _init_set)(array_t d, const array_t s) \
|
||||||
{ \
|
{ \
|
||||||
assert (d != s); \
|
M_ASSERT (d != s); \
|
||||||
M_C(name, _init)(d); \
|
M_C(name, _init)(d); \
|
||||||
M_C(name, _set)(d, s); \
|
M_C(name, _set)(d, s); \
|
||||||
} \
|
} \
|
||||||
@@ -254,7 +254,7 @@
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _init_move)(array_t d, array_t s) \
|
M_C(name, _init_move)(array_t d, array_t s) \
|
||||||
{ \
|
{ \
|
||||||
assert (d != s); \
|
M_ASSERT (d != s); \
|
||||||
ARRAYI_CONTRACT(s); \
|
ARRAYI_CONTRACT(s); \
|
||||||
d->size = s->size; \
|
d->size = s->size; \
|
||||||
d->alloc = s->alloc; \
|
d->alloc = s->alloc; \
|
||||||
@@ -267,7 +267,7 @@
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _move)(array_t d, array_t s) \
|
M_C(name, _move)(array_t d, array_t s) \
|
||||||
{ \
|
{ \
|
||||||
assert (d != s); \
|
M_ASSERT (d != s); \
|
||||||
M_C(name, _clear)(d); \
|
M_C(name, _clear)(d); \
|
||||||
M_C(name, _init_move)(d, s); \
|
M_C(name, _init_move)(d, s); \
|
||||||
} \
|
} \
|
||||||
@@ -277,7 +277,7 @@
|
|||||||
M_C(name, _set_at)(array_t v, size_t i, type const x) \
|
M_C(name, _set_at)(array_t v, size_t i, type const x) \
|
||||||
{ \
|
{ \
|
||||||
ARRAYI_CONTRACT(v); \
|
ARRAYI_CONTRACT(v); \
|
||||||
assert(v->size > 0 && v->ptr != NULL); \
|
M_ASSERT(v->size > 0 && v->ptr != NULL); \
|
||||||
M_ASSERT_INDEX(i, v->size); \
|
M_ASSERT_INDEX(i, v->size); \
|
||||||
M_CALL_SET(oplist, v->ptr[i], x); \
|
M_CALL_SET(oplist, v->ptr[i], x); \
|
||||||
} \
|
} \
|
||||||
@@ -287,7 +287,7 @@
|
|||||||
M_C(name, _back)(array_t v) \
|
M_C(name, _back)(array_t v) \
|
||||||
{ \
|
{ \
|
||||||
ARRAYI_CONTRACT(v); \
|
ARRAYI_CONTRACT(v); \
|
||||||
assert(v->ptr != NULL); \
|
M_ASSERT(v->ptr != NULL); \
|
||||||
M_ASSERT_INDEX(0, v->size); \
|
M_ASSERT_INDEX(0, v->size); \
|
||||||
return M_CONST_CAST(type, &v->ptr[v->size-1]); \
|
return M_CONST_CAST(type, &v->ptr[v->size-1]); \
|
||||||
} \
|
} \
|
||||||
@@ -297,13 +297,13 @@
|
|||||||
{ \
|
{ \
|
||||||
ARRAYI_CONTRACT(v); \
|
ARRAYI_CONTRACT(v); \
|
||||||
if (M_UNLIKELY (v->size >= v->alloc)) { \
|
if (M_UNLIKELY (v->size >= v->alloc)) { \
|
||||||
assert(v->size == v->alloc); \
|
M_ASSERT(v->size == v->alloc); \
|
||||||
size_t alloc = M_CALL_INC_ALLOC(oplist, v->alloc); \
|
size_t alloc = M_CALL_INC_ALLOC(oplist, v->alloc); \
|
||||||
if (M_UNLIKELY (alloc <= v->alloc)) { \
|
if (M_UNLIKELY (alloc <= v->alloc)) { \
|
||||||
M_MEMORY_FULL(sizeof (type) * alloc); \
|
M_MEMORY_FULL(sizeof (type) * alloc); \
|
||||||
return NULL; \
|
return NULL; \
|
||||||
} \
|
} \
|
||||||
assert (alloc > v->size); \
|
M_ASSERT (alloc > v->size); \
|
||||||
type *ptr = M_CALL_REALLOC(oplist, type, v->ptr, alloc); \
|
type *ptr = M_CALL_REALLOC(oplist, type, v->ptr, alloc); \
|
||||||
if (M_UNLIKELY (ptr == NULL) ) { \
|
if (M_UNLIKELY (ptr == NULL) ) { \
|
||||||
M_MEMORY_FULL(sizeof (type) * alloc); \
|
M_MEMORY_FULL(sizeof (type) * alloc); \
|
||||||
@@ -312,7 +312,7 @@
|
|||||||
v->ptr = ptr; \
|
v->ptr = ptr; \
|
||||||
v->alloc = alloc; \
|
v->alloc = alloc; \
|
||||||
} \
|
} \
|
||||||
assert(v->ptr != NULL); \
|
M_ASSERT(v->ptr != NULL); \
|
||||||
type *ret = &v->ptr[v->size]; \
|
type *ret = &v->ptr[v->size]; \
|
||||||
v->size++; \
|
v->size++; \
|
||||||
ARRAYI_CONTRACT(v); \
|
ARRAYI_CONTRACT(v); \
|
||||||
@@ -347,7 +347,7 @@
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _push_move)(array_t v, type *x) \
|
M_C(name, _push_move)(array_t v, type *x) \
|
||||||
{ \
|
{ \
|
||||||
assert (x != NULL); \
|
M_ASSERT (x != NULL); \
|
||||||
type *data = M_C(name, _push_raw)(v); \
|
type *data = M_C(name, _push_raw)(v); \
|
||||||
if (M_UNLIKELY (data == NULL) ) \
|
if (M_UNLIKELY (data == NULL) ) \
|
||||||
return; \
|
return; \
|
||||||
@@ -362,13 +362,13 @@
|
|||||||
ARRAYI_CONTRACT(v); \
|
ARRAYI_CONTRACT(v); \
|
||||||
M_ASSERT_INDEX(key, v->size+1); \
|
M_ASSERT_INDEX(key, v->size+1); \
|
||||||
if (M_UNLIKELY (v->size >= v->alloc) ) { \
|
if (M_UNLIKELY (v->size >= v->alloc) ) { \
|
||||||
assert(v->size == v->alloc); \
|
M_ASSERT(v->size == v->alloc); \
|
||||||
size_t alloc = M_CALL_INC_ALLOC(oplist, v->alloc); \
|
size_t alloc = M_CALL_INC_ALLOC(oplist, v->alloc); \
|
||||||
if (M_UNLIKELY (alloc <= v->alloc)) { \
|
if (M_UNLIKELY (alloc <= v->alloc)) { \
|
||||||
M_MEMORY_FULL(sizeof (type) * alloc); \
|
M_MEMORY_FULL(sizeof (type) * alloc); \
|
||||||
return ; \
|
return ; \
|
||||||
} \
|
} \
|
||||||
assert (alloc > v->size); \
|
M_ASSERT (alloc > v->size); \
|
||||||
type *ptr = M_CALL_REALLOC(oplist, type, v->ptr, alloc); \
|
type *ptr = M_CALL_REALLOC(oplist, type, v->ptr, alloc); \
|
||||||
if (M_UNLIKELY (ptr == NULL) ) { \
|
if (M_UNLIKELY (ptr == NULL) ) { \
|
||||||
M_MEMORY_FULL(sizeof (type) * alloc); \
|
M_MEMORY_FULL(sizeof (type) * alloc); \
|
||||||
@@ -377,7 +377,7 @@
|
|||||||
v->ptr = ptr; \
|
v->ptr = ptr; \
|
||||||
v->alloc = alloc; \
|
v->alloc = alloc; \
|
||||||
} \
|
} \
|
||||||
assert(v->ptr != NULL); \
|
M_ASSERT(v->ptr != NULL); \
|
||||||
memmove(&v->ptr[key+1], &v->ptr[key], (v->size-key)*sizeof(type)); \
|
memmove(&v->ptr[key+1], &v->ptr[key], (v->size-key)*sizeof(type)); \
|
||||||
v->size++; \
|
v->size++; \
|
||||||
M_CALL_INIT_SET(oplist, v->ptr[key], x); \
|
M_CALL_INIT_SET(oplist, v->ptr[key], x); \
|
||||||
@@ -467,7 +467,7 @@
|
|||||||
M_CALL_INIT(oplist, v->ptr[i]); \
|
M_CALL_INIT(oplist, v->ptr[i]); \
|
||||||
v->size = size; \
|
v->size = size; \
|
||||||
} \
|
} \
|
||||||
assert (idx < v->size); \
|
M_ASSERT (idx < v->size); \
|
||||||
ARRAYI_CONTRACT(v); \
|
ARRAYI_CONTRACT(v); \
|
||||||
return &v->ptr[idx]; \
|
return &v->ptr[idx]; \
|
||||||
} \
|
} \
|
||||||
@@ -478,7 +478,7 @@
|
|||||||
M_C(name, _pop_back)(type *dest, array_t v) \
|
M_C(name, _pop_back)(type *dest, array_t v) \
|
||||||
{ \
|
{ \
|
||||||
ARRAYI_CONTRACT(v); \
|
ARRAYI_CONTRACT(v); \
|
||||||
assert (v->ptr != NULL); \
|
M_ASSERT (v->ptr != NULL); \
|
||||||
M_ASSERT_INDEX(0, v->size); \
|
M_ASSERT_INDEX(0, v->size); \
|
||||||
v->size--; \
|
v->size--; \
|
||||||
if (dest) { \
|
if (dest) { \
|
||||||
@@ -495,9 +495,9 @@
|
|||||||
M_C(name, _pop_move)(type *dest, array_t v) \
|
M_C(name, _pop_move)(type *dest, array_t v) \
|
||||||
{ \
|
{ \
|
||||||
ARRAYI_CONTRACT(v); \
|
ARRAYI_CONTRACT(v); \
|
||||||
assert (v->ptr != NULL); \
|
M_ASSERT (v->ptr != NULL); \
|
||||||
M_ASSERT_INDEX(0, v->size); \
|
M_ASSERT_INDEX(0, v->size); \
|
||||||
assert (dest != NULL); \
|
M_ASSERT (dest != NULL); \
|
||||||
v->size--; \
|
v->size--; \
|
||||||
M_DO_INIT_MOVE (oplist, *dest, v->ptr[v->size]); \
|
M_DO_INIT_MOVE (oplist, *dest, v->ptr[v->size]); \
|
||||||
ARRAYI_CONTRACT(v); \
|
ARRAYI_CONTRACT(v); \
|
||||||
@@ -509,7 +509,7 @@
|
|||||||
M_C(name, _pop_until)(array_t v, it_t pos) \
|
M_C(name, _pop_until)(array_t v, it_t pos) \
|
||||||
{ \
|
{ \
|
||||||
ARRAYI_CONTRACT(v); \
|
ARRAYI_CONTRACT(v); \
|
||||||
assert (v == pos->array); \
|
M_ASSERT (v == pos->array); \
|
||||||
M_ASSERT_INDEX(pos->index, v->size+1); \
|
M_ASSERT_INDEX(pos->index, v->size+1); \
|
||||||
M_C(name, _resize)(v, pos->index); \
|
M_C(name, _resize)(v, pos->index); \
|
||||||
} \
|
} \
|
||||||
@@ -541,7 +541,7 @@
|
|||||||
M_C(name, _pop_at)(type *dest, array_t v, size_t i) \
|
M_C(name, _pop_at)(type *dest, array_t v, size_t i) \
|
||||||
{ \
|
{ \
|
||||||
ARRAYI_CONTRACT(v); \
|
ARRAYI_CONTRACT(v); \
|
||||||
assert (v->size > 0 && v->ptr != NULL); \
|
M_ASSERT (v->size > 0 && v->ptr != NULL); \
|
||||||
M_ASSERT_INDEX(i, v->size); \
|
M_ASSERT_INDEX(i, v->size); \
|
||||||
if (dest) \
|
if (dest) \
|
||||||
M_DO_MOVE (oplist, *dest, v->ptr[i]); \
|
M_DO_MOVE (oplist, *dest, v->ptr[i]); \
|
||||||
@@ -603,7 +603,7 @@
|
|||||||
M_C(name, _remove_v)(array_t v, size_t i, size_t j) \
|
M_C(name, _remove_v)(array_t v, size_t i, size_t j) \
|
||||||
{ \
|
{ \
|
||||||
ARRAYI_CONTRACT(v); \
|
ARRAYI_CONTRACT(v); \
|
||||||
assert(i < j && v->ptr != NULL); \
|
M_ASSERT(i < j && v->ptr != NULL); \
|
||||||
M_ASSERT_INDEX(i, v->size); \
|
M_ASSERT_INDEX(i, v->size); \
|
||||||
M_ASSERT_INDEX(j, v->size+1); \
|
M_ASSERT_INDEX(j, v->size+1); \
|
||||||
for(size_t k = i ; k < j; k++) \
|
for(size_t k = i ; k < j; k++) \
|
||||||
@@ -636,7 +636,7 @@
|
|||||||
M_C(name, _swap_at)(array_t v, size_t i, size_t j) \
|
M_C(name, _swap_at)(array_t v, size_t i, size_t j) \
|
||||||
{ \
|
{ \
|
||||||
ARRAYI_CONTRACT(v); \
|
ARRAYI_CONTRACT(v); \
|
||||||
assert(v->ptr != NULL); \
|
M_ASSERT(v->ptr != NULL); \
|
||||||
M_ASSERT_INDEX(i, v->size); \
|
M_ASSERT_INDEX(i, v->size); \
|
||||||
M_ASSERT_INDEX(j, v->size); \
|
M_ASSERT_INDEX(j, v->size); \
|
||||||
type tmp; \
|
type tmp; \
|
||||||
@@ -651,7 +651,7 @@
|
|||||||
M_C(name, _get)(const array_t v, size_t i) \
|
M_C(name, _get)(const array_t v, size_t i) \
|
||||||
{ \
|
{ \
|
||||||
ARRAYI_CONTRACT(v); \
|
ARRAYI_CONTRACT(v); \
|
||||||
assert (v->ptr != NULL); \
|
M_ASSERT (v->ptr != NULL); \
|
||||||
M_ASSERT_INDEX(i, v->size); \
|
M_ASSERT_INDEX(i, v->size); \
|
||||||
return &v->ptr[i]; \
|
return &v->ptr[i]; \
|
||||||
} \
|
} \
|
||||||
@@ -660,7 +660,7 @@
|
|||||||
M_C(name, _cget)(const array_t v, size_t i) \
|
M_C(name, _cget)(const array_t v, size_t i) \
|
||||||
{ \
|
{ \
|
||||||
ARRAYI_CONTRACT(v); \
|
ARRAYI_CONTRACT(v); \
|
||||||
assert (v->ptr != NULL); \
|
M_ASSERT (v->ptr != NULL); \
|
||||||
M_ASSERT_INDEX(i, v->size); \
|
M_ASSERT_INDEX(i, v->size); \
|
||||||
return M_CONST_CAST(type, &v->ptr[i]); \
|
return M_CONST_CAST(type, &v->ptr[i]); \
|
||||||
} \
|
} \
|
||||||
@@ -677,7 +677,7 @@
|
|||||||
M_C(name, _it)(it_t it, const array_t v) \
|
M_C(name, _it)(it_t it, const array_t v) \
|
||||||
{ \
|
{ \
|
||||||
ARRAYI_CONTRACT(v); \
|
ARRAYI_CONTRACT(v); \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
it->index = 0; \
|
it->index = 0; \
|
||||||
it->array = v; \
|
it->array = v; \
|
||||||
} \
|
} \
|
||||||
@@ -686,7 +686,7 @@
|
|||||||
M_C(name, _it_last)(it_t it, const array_t v) \
|
M_C(name, _it_last)(it_t it, const array_t v) \
|
||||||
{ \
|
{ \
|
||||||
ARRAYI_CONTRACT(v); \
|
ARRAYI_CONTRACT(v); \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
/* If size is 0, index is -1 as unsigned, so it is greater than end */ \
|
/* If size is 0, index is -1 as unsigned, so it is greater than end */ \
|
||||||
it->index = v->size - 1; \
|
it->index = v->size - 1; \
|
||||||
it->array = v; \
|
it->array = v; \
|
||||||
@@ -696,7 +696,7 @@
|
|||||||
M_C(name, _it_end)(it_t it, const array_t v) \
|
M_C(name, _it_end)(it_t it, const array_t v) \
|
||||||
{ \
|
{ \
|
||||||
ARRAYI_CONTRACT(v); \
|
ARRAYI_CONTRACT(v); \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
it->index = v->size; \
|
it->index = v->size; \
|
||||||
it->array = v; \
|
it->array = v; \
|
||||||
} \
|
} \
|
||||||
@@ -704,7 +704,7 @@
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _it_set)(it_t it, const it_t org) \
|
M_C(name, _it_set)(it_t it, const it_t org) \
|
||||||
{ \
|
{ \
|
||||||
assert (it != NULL && org != NULL); \
|
M_ASSERT (it != NULL && org != NULL); \
|
||||||
it->index = org->index; \
|
it->index = org->index; \
|
||||||
it->array = org->array; \
|
it->array = org->array; \
|
||||||
ARRAYI_CONTRACT(it->array); \
|
ARRAYI_CONTRACT(it->array); \
|
||||||
@@ -713,14 +713,14 @@
|
|||||||
static inline bool \
|
static inline bool \
|
||||||
M_C(name, _end_p)(const it_t it) \
|
M_C(name, _end_p)(const it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert(it != NULL && it->array != NULL); \
|
M_ASSERT(it != NULL && it->array != NULL); \
|
||||||
return it->index >= it->array->size; \
|
return it->index >= it->array->size; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline bool \
|
static inline bool \
|
||||||
M_C(name, _last_p)(const it_t it) \
|
M_C(name, _last_p)(const it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert(it != NULL && it->array != NULL); \
|
M_ASSERT(it != NULL && it->array != NULL); \
|
||||||
/* NOTE: Can not compute 'size-1' due to potential overflow \
|
/* NOTE: Can not compute 'size-1' due to potential overflow \
|
||||||
if size is 0 */ \
|
if size is 0 */ \
|
||||||
return it->index + 1 >= it->array->size; \
|
return it->index + 1 >= it->array->size; \
|
||||||
@@ -730,21 +730,21 @@
|
|||||||
M_C(name, _it_equal_p)(const it_t it1, \
|
M_C(name, _it_equal_p)(const it_t it1, \
|
||||||
const it_t it2) \
|
const it_t it2) \
|
||||||
{ \
|
{ \
|
||||||
assert(it1 != NULL && it2 != NULL); \
|
M_ASSERT(it1 != NULL && it2 != NULL); \
|
||||||
return it1->array == it2->array && it1->index == it2->index; \
|
return it1->array == it2->array && it1->index == it2->index; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _next)(it_t it) \
|
M_C(name, _next)(it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert(it != NULL && it->array != NULL); \
|
M_ASSERT(it != NULL && it->array != NULL); \
|
||||||
it->index ++; \
|
it->index ++; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _previous)(it_t it) \
|
M_C(name, _previous)(it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert(it != NULL && it->array != NULL); \
|
M_ASSERT(it != NULL && it->array != NULL); \
|
||||||
/* NOTE: In the case index=0, it will be set to (unsigned) -1 \
|
/* NOTE: In the case index=0, it will be set to (unsigned) -1 \
|
||||||
==> it will be greater than size ==> end_p will return true */ \
|
==> it will be greater than size ==> end_p will return true */ \
|
||||||
it->index --; \
|
it->index --; \
|
||||||
@@ -753,14 +753,14 @@
|
|||||||
static inline type * \
|
static inline type * \
|
||||||
M_C(name, _ref)(const it_t it) \
|
M_C(name, _ref)(const it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert(it != NULL); \
|
M_ASSERT(it != NULL); \
|
||||||
return M_C(name, _get)(it->array, it->index); \
|
return M_C(name, _get)(it->array, it->index); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline type const * \
|
static inline type const * \
|
||||||
M_C(name, _cref)(const it_t it) \
|
M_C(name, _cref)(const it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert(it != NULL); \
|
M_ASSERT(it != NULL); \
|
||||||
return M_C(name, _cget)(it->array, it->index); \
|
return M_C(name, _cget)(it->array, it->index); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
@@ -768,7 +768,7 @@
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _insert)(array_t a, it_t it, type const x) \
|
M_C(name, _insert)(array_t a, it_t it, type const x) \
|
||||||
{ \
|
{ \
|
||||||
assert (it != NULL && a == it->array); \
|
M_ASSERT (it != NULL && a == it->array); \
|
||||||
M_C(name, _push_at)(a, it->index + 1, x); \
|
M_C(name, _push_at)(a, it->index + 1, x); \
|
||||||
it->index ++; \
|
it->index ++; \
|
||||||
} \
|
} \
|
||||||
@@ -778,7 +778,7 @@
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _remove)(array_t a, it_t it) \
|
M_C(name, _remove)(array_t a, it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert (it != NULL && a == it->array); \
|
M_ASSERT (it != NULL && a == it->array); \
|
||||||
M_C(name, _pop_at)(NULL, a, it->index); \
|
M_C(name, _pop_at)(NULL, a, it->index); \
|
||||||
/* NOTE: it->index will naturaly point to the next element */ \
|
/* NOTE: it->index will naturaly point to the next element */ \
|
||||||
} \
|
} \
|
||||||
@@ -803,7 +803,7 @@
|
|||||||
{ \
|
{ \
|
||||||
size_t th = 4; \
|
size_t th = 4; \
|
||||||
M_IF_DEBUG(type *org_tab = tab;) \
|
M_IF_DEBUG(type *org_tab = tab;) \
|
||||||
assert (size > 1); \
|
M_ASSERT (size > 1); \
|
||||||
/* Let's select the threshold of the pass 1 to be sure \
|
/* Let's select the threshold of the pass 1 to be sure \
|
||||||
the final result is in tab.*/ \
|
the final result is in tab.*/ \
|
||||||
if (m_core_clz64(size-1) & 1) \
|
if (m_core_clz64(size-1) & 1) \
|
||||||
@@ -832,9 +832,9 @@
|
|||||||
type *el2 = &tab[k+th]; \
|
type *el2 = &tab[k+th]; \
|
||||||
size_t n1 = th; \
|
size_t n1 = th; \
|
||||||
size_t n2 = size-k <= 3*th ? size-k-th : th; \
|
size_t n2 = size-k <= 3*th ? size-k-th : th; \
|
||||||
assert (size-k > th); \
|
M_ASSERT (size-k > th); \
|
||||||
assert (0 < n1 && n1 <= size); \
|
M_ASSERT (0 < n1 && n1 <= size); \
|
||||||
assert (0 < n2 && n2 <= size); \
|
M_ASSERT (0 < n2 && n2 <= size); \
|
||||||
k += n1+n2; \
|
k += n1+n2; \
|
||||||
for (;;) { \
|
for (;;) { \
|
||||||
if (M_CALL_CMP(oplist, *el1, *el2) <= 0) { \
|
if (M_CALL_CMP(oplist, *el1, *el2) <= 0) { \
|
||||||
@@ -867,7 +867,7 @@
|
|||||||
/* Increase th for next pass */ \
|
/* Increase th for next pass */ \
|
||||||
th += th; \
|
th += th; \
|
||||||
} \
|
} \
|
||||||
assert (org_tab == tab); \
|
M_ASSERT (org_tab == tab); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void \
|
static inline void \
|
||||||
@@ -916,7 +916,7 @@
|
|||||||
M_C(name, _out_str)(FILE *file, const array_t array) \
|
M_C(name, _out_str)(FILE *file, const array_t array) \
|
||||||
{ \
|
{ \
|
||||||
ARRAYI_CONTRACT(array); \
|
ARRAYI_CONTRACT(array); \
|
||||||
assert (file != NULL); \
|
M_ASSERT (file != NULL); \
|
||||||
fputc ('[', file); \
|
fputc ('[', file); \
|
||||||
for (size_t i = 0; i < array->size; i++) { \
|
for (size_t i = 0; i < array->size; i++) { \
|
||||||
type const *item = M_C(name, _cget)(array, i); \
|
type const *item = M_C(name, _cget)(array, i); \
|
||||||
@@ -933,7 +933,7 @@
|
|||||||
M_C(name, _parse_str)(array_t array, const char str[], const char**endp) \
|
M_C(name, _parse_str)(array_t array, const char str[], const char**endp) \
|
||||||
{ \
|
{ \
|
||||||
ARRAYI_CONTRACT(array); \
|
ARRAYI_CONTRACT(array); \
|
||||||
assert (str != NULL); \
|
M_ASSERT (str != NULL); \
|
||||||
M_C(name,_clean)(array); \
|
M_C(name,_clean)(array); \
|
||||||
bool success = false; \
|
bool success = false; \
|
||||||
int c = *str++; \
|
int c = *str++; \
|
||||||
@@ -965,7 +965,7 @@
|
|||||||
M_C(name, _in_str)(array_t array, FILE *file) \
|
M_C(name, _in_str)(array_t array, FILE *file) \
|
||||||
{ \
|
{ \
|
||||||
ARRAYI_CONTRACT(array); \
|
ARRAYI_CONTRACT(array); \
|
||||||
assert (file != NULL); \
|
M_ASSERT (file != NULL); \
|
||||||
M_C(name,_clean)(array); \
|
M_C(name,_clean)(array); \
|
||||||
int c = fgetc(file); \
|
int c = fgetc(file); \
|
||||||
if (M_UNLIKELY (c != '[')) return false; \
|
if (M_UNLIKELY (c != '[')) return false; \
|
||||||
@@ -992,7 +992,7 @@
|
|||||||
M_C(name, _out_serial)(m_serial_write_t f, const array_t array) \
|
M_C(name, _out_serial)(m_serial_write_t f, const array_t array) \
|
||||||
{ \
|
{ \
|
||||||
ARRAYI_CONTRACT(array); \
|
ARRAYI_CONTRACT(array); \
|
||||||
assert (f != NULL && f->m_interface != NULL); \
|
M_ASSERT (f != NULL && f->m_interface != NULL); \
|
||||||
m_serial_return_code_t ret; \
|
m_serial_return_code_t ret; \
|
||||||
m_serial_local_t local; \
|
m_serial_local_t local; \
|
||||||
ret = f->m_interface->write_array_start(local, f, array->size); \
|
ret = f->m_interface->write_array_start(local, f, array->size); \
|
||||||
@@ -1013,7 +1013,7 @@
|
|||||||
M_C(name, _in_serial)(array_t array, m_serial_read_t f) \
|
M_C(name, _in_serial)(array_t array, m_serial_read_t f) \
|
||||||
{ \
|
{ \
|
||||||
ARRAYI_CONTRACT(array); \
|
ARRAYI_CONTRACT(array); \
|
||||||
assert (f != NULL && f->m_interface != NULL); \
|
M_ASSERT (f != NULL && f->m_interface != NULL); \
|
||||||
m_serial_return_code_t ret; \
|
m_serial_return_code_t ret; \
|
||||||
m_serial_local_t local; \
|
m_serial_local_t local; \
|
||||||
size_t estimated_size = 0; \
|
size_t estimated_size = 0; \
|
||||||
|
|||||||
+26
-26
@@ -48,12 +48,12 @@ typedef uint64_t bitset_limb_ct;
|
|||||||
|
|
||||||
// Contract of a bitset
|
// Contract of a bitset
|
||||||
#define BITSETI_CONTRACT(t) do { \
|
#define BITSETI_CONTRACT(t) do { \
|
||||||
assert (t != NULL); \
|
M_ASSERT (t != NULL); \
|
||||||
assert (t->size <= BITSETI_FROM_ALLOC (t->alloc)); \
|
M_ASSERT (t->size <= BITSETI_FROM_ALLOC (t->alloc)); \
|
||||||
assert (t->alloc <= ((size_t)-1) / BITSET_LIMB_BIT); \
|
M_ASSERT (t->alloc <= ((size_t)-1) / BITSET_LIMB_BIT); \
|
||||||
assert (t->size < ((size_t)-1) - BITSET_LIMB_BIT); \
|
M_ASSERT (t->size < ((size_t)-1) - BITSET_LIMB_BIT); \
|
||||||
assert (t->size == 0 || t->ptr != NULL); \
|
M_ASSERT (t->size == 0 || t->ptr != NULL); \
|
||||||
assert (t->alloc == 0 || t->ptr != NULL); \
|
M_ASSERT (t->alloc == 0 || t->ptr != NULL); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
|
||||||
@@ -83,7 +83,7 @@ typedef struct bitset_it_s {
|
|||||||
static inline void
|
static inline void
|
||||||
bitset_init(bitset_t t)
|
bitset_init(bitset_t t)
|
||||||
{
|
{
|
||||||
assert (t != NULL);
|
M_ASSERT (t != NULL);
|
||||||
M_STATIC_ASSERT (M_POWEROF2_P(BITSET_LIMB_BIT), MLIB_INTERNAL, "M*LIB: BITSET LIMB shall be a power of 2.");
|
M_STATIC_ASSERT (M_POWEROF2_P(BITSET_LIMB_BIT), MLIB_INTERNAL, "M*LIB: BITSET LIMB shall be a power of 2.");
|
||||||
t->size = 0;
|
t->size = 0;
|
||||||
t->alloc = 0;
|
t->alloc = 0;
|
||||||
@@ -138,7 +138,7 @@ bitset_set(bitset_t d, const bitset_t s)
|
|||||||
static inline void
|
static inline void
|
||||||
bitset_init_set(bitset_t d, const bitset_t s)
|
bitset_init_set(bitset_t d, const bitset_t s)
|
||||||
{
|
{
|
||||||
assert (d != s);
|
M_ASSERT (d != s);
|
||||||
bitset_init(d);
|
bitset_init(d);
|
||||||
bitset_set(d, s);
|
bitset_set(d, s);
|
||||||
}
|
}
|
||||||
@@ -169,7 +169,7 @@ static inline void
|
|||||||
bitset_set_at(bitset_t v, size_t i, bool x)
|
bitset_set_at(bitset_t v, size_t i, bool x)
|
||||||
{
|
{
|
||||||
BITSETI_CONTRACT(v);
|
BITSETI_CONTRACT(v);
|
||||||
assert (v->ptr != NULL);
|
M_ASSERT (v->ptr != NULL);
|
||||||
M_ASSERT_INDEX(i, v->size);
|
M_ASSERT_INDEX(i, v->size);
|
||||||
const size_t offset = i / BITSET_LIMB_BIT;
|
const size_t offset = i / BITSET_LIMB_BIT;
|
||||||
const size_t index = i % BITSET_LIMB_BIT;
|
const size_t index = i % BITSET_LIMB_BIT;
|
||||||
@@ -184,7 +184,7 @@ static inline void
|
|||||||
bitset_flip_at(bitset_t v, size_t i)
|
bitset_flip_at(bitset_t v, size_t i)
|
||||||
{
|
{
|
||||||
BITSETI_CONTRACT(v);
|
BITSETI_CONTRACT(v);
|
||||||
assert (v->ptr != NULL);
|
M_ASSERT (v->ptr != NULL);
|
||||||
M_ASSERT_INDEX(i, v->size);
|
M_ASSERT_INDEX(i, v->size);
|
||||||
size_t offset = i / BITSET_LIMB_BIT;
|
size_t offset = i / BITSET_LIMB_BIT;
|
||||||
size_t index = i % BITSET_LIMB_BIT;
|
size_t index = i % BITSET_LIMB_BIT;
|
||||||
@@ -219,7 +219,7 @@ bitset_push_back (bitset_t v, bool x)
|
|||||||
v->ptr = ptr;
|
v->ptr = ptr;
|
||||||
v->alloc = needAlloc;
|
v->alloc = needAlloc;
|
||||||
}
|
}
|
||||||
assert(v->ptr != NULL);
|
M_ASSERT(v->ptr != NULL);
|
||||||
v->size ++;
|
v->size ++;
|
||||||
bitset_set_at (v, v->size - 1, x);
|
bitset_set_at (v, v->size - 1, x);
|
||||||
}
|
}
|
||||||
@@ -288,7 +288,7 @@ static inline bool
|
|||||||
bitset_get(const bitset_t v, size_t i)
|
bitset_get(const bitset_t v, size_t i)
|
||||||
{
|
{
|
||||||
BITSETI_CONTRACT(v);
|
BITSETI_CONTRACT(v);
|
||||||
assert (v->ptr != NULL);
|
M_ASSERT (v->ptr != NULL);
|
||||||
M_ASSERT_INDEX(i, v->size);
|
M_ASSERT_INDEX(i, v->size);
|
||||||
size_t offset = i / BITSET_LIMB_BIT;
|
size_t offset = i / BITSET_LIMB_BIT;
|
||||||
size_t index = i % BITSET_LIMB_BIT;
|
size_t index = i % BITSET_LIMB_BIT;
|
||||||
@@ -417,7 +417,7 @@ bitset_push_at(bitset_t set, size_t key, bool value)
|
|||||||
BITSETI_CONTRACT (set);
|
BITSETI_CONTRACT (set);
|
||||||
// First push another value to extend the array to the right size
|
// First push another value to extend the array to the right size
|
||||||
bitset_push_back(set, false);
|
bitset_push_back(set, false);
|
||||||
assert (set->ptr != NULL);
|
M_ASSERT (set->ptr != NULL);
|
||||||
M_ASSERT_INDEX(key, set->size);
|
M_ASSERT_INDEX(key, set->size);
|
||||||
|
|
||||||
// Then shift it
|
// Then shift it
|
||||||
@@ -429,7 +429,7 @@ bitset_push_at(bitset_t set, size_t key, bool value)
|
|||||||
v = (v & mask) | ((unsigned int) value << index) | ((v & ~mask) << 1);
|
v = (v & mask) | ((unsigned int) value << index) | ((v & ~mask) << 1);
|
||||||
set->ptr[offset] = v;
|
set->ptr[offset] = v;
|
||||||
size_t size = (set->size + BITSET_LIMB_BIT - 1) / BITSET_LIMB_BIT;
|
size_t size = (set->size + BITSET_LIMB_BIT - 1) / BITSET_LIMB_BIT;
|
||||||
assert (size >= offset + 1);
|
M_ASSERT (size >= offset + 1);
|
||||||
v = bitseti_lshift(&set->ptr[offset+1], size - offset - 1, carry);
|
v = bitseti_lshift(&set->ptr[offset+1], size - offset - 1, carry);
|
||||||
// v is unused.
|
// v is unused.
|
||||||
(void) v;
|
(void) v;
|
||||||
@@ -442,7 +442,7 @@ static inline void
|
|||||||
bitset_pop_at(bool *dest, bitset_t set, size_t key)
|
bitset_pop_at(bool *dest, bitset_t set, size_t key)
|
||||||
{
|
{
|
||||||
BITSETI_CONTRACT (set);
|
BITSETI_CONTRACT (set);
|
||||||
assert (set->ptr != NULL);
|
M_ASSERT (set->ptr != NULL);
|
||||||
M_ASSERT_INDEX(key, set->size);
|
M_ASSERT_INDEX(key, set->size);
|
||||||
|
|
||||||
if (dest) {
|
if (dest) {
|
||||||
@@ -500,7 +500,7 @@ bitset_it(bitset_it_t it, bitset_t set)
|
|||||||
static inline void
|
static inline void
|
||||||
bitset_it_set(bitset_it_t it, const bitset_it_t itorg)
|
bitset_it_set(bitset_it_t it, const bitset_it_t itorg)
|
||||||
{
|
{
|
||||||
assert (it != NULL && itorg != NULL);
|
M_ASSERT (it != NULL && itorg != NULL);
|
||||||
it->index = itorg->index;
|
it->index = itorg->index;
|
||||||
it->set = itorg->set;
|
it->set = itorg->set;
|
||||||
}
|
}
|
||||||
@@ -527,7 +527,7 @@ bitset_it_end(bitset_it_t it, bitset_t set)
|
|||||||
static inline bool
|
static inline bool
|
||||||
bitset_end_p(const bitset_it_t it)
|
bitset_end_p(const bitset_it_t it)
|
||||||
{
|
{
|
||||||
assert (it != NULL && it->set != NULL);
|
M_ASSERT (it != NULL && it->set != NULL);
|
||||||
return (it->index) >= (it->set->size);
|
return (it->index) >= (it->set->size);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -535,7 +535,7 @@ bitset_end_p(const bitset_it_t it)
|
|||||||
static inline bool
|
static inline bool
|
||||||
bitset_last_p(const bitset_it_t it)
|
bitset_last_p(const bitset_it_t it)
|
||||||
{
|
{
|
||||||
assert (it != NULL && it->set != NULL);
|
M_ASSERT (it != NULL && it->set != NULL);
|
||||||
return (it->index) >= (it->set->size)-1;
|
return (it->index) >= (it->set->size)-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -543,7 +543,7 @@ bitset_last_p(const bitset_it_t it)
|
|||||||
static inline bool
|
static inline bool
|
||||||
bitset_it_equal_p(const bitset_it_t it1, const bitset_it_t it2)
|
bitset_it_equal_p(const bitset_it_t it1, const bitset_it_t it2)
|
||||||
{
|
{
|
||||||
assert (it1 != NULL && it2 != NULL);
|
M_ASSERT (it1 != NULL && it2 != NULL);
|
||||||
return it1->index == it2->index && it1->set == it2->set;
|
return it1->index == it2->index && it1->set == it2->set;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -551,7 +551,7 @@ bitset_it_equal_p(const bitset_it_t it1, const bitset_it_t it2)
|
|||||||
static inline void
|
static inline void
|
||||||
bitset_next(bitset_it_t it)
|
bitset_next(bitset_it_t it)
|
||||||
{
|
{
|
||||||
assert (it != NULL && it->set != NULL);
|
M_ASSERT (it != NULL && it->set != NULL);
|
||||||
it->index++;
|
it->index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -559,7 +559,7 @@ bitset_next(bitset_it_t it)
|
|||||||
static inline void
|
static inline void
|
||||||
bitset_previous(bitset_it_t it)
|
bitset_previous(bitset_it_t it)
|
||||||
{
|
{
|
||||||
assert (it != NULL && it->set != NULL);
|
M_ASSERT (it != NULL && it->set != NULL);
|
||||||
it->index--;
|
it->index--;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -570,7 +570,7 @@ bitset_previous(bitset_it_t it)
|
|||||||
static inline const bool *
|
static inline const bool *
|
||||||
bitset_cref(bitset_it_t it)
|
bitset_cref(bitset_it_t it)
|
||||||
{
|
{
|
||||||
assert (it != NULL && it->set != NULL);
|
M_ASSERT (it != NULL && it->set != NULL);
|
||||||
it->value = bitset_get(it->set, it->index);
|
it->value = bitset_get(it->set, it->index);
|
||||||
return &it->value;
|
return &it->value;
|
||||||
}
|
}
|
||||||
@@ -580,7 +580,7 @@ static inline void
|
|||||||
bitset_out_str(FILE *file, const bitset_t set)
|
bitset_out_str(FILE *file, const bitset_t set)
|
||||||
{
|
{
|
||||||
BITSETI_CONTRACT (set);
|
BITSETI_CONTRACT (set);
|
||||||
assert(file != NULL);
|
M_ASSERT(file != NULL);
|
||||||
fputc ('[', file);
|
fputc ('[', file);
|
||||||
for(size_t i = 0; i < set->size; i++) {
|
for(size_t i = 0; i < set->size; i++) {
|
||||||
const bool b = bitset_get (set, i);
|
const bool b = bitset_get (set, i);
|
||||||
@@ -595,7 +595,7 @@ static inline bool
|
|||||||
bitset_in_str(bitset_t set, FILE *file)
|
bitset_in_str(bitset_t set, FILE *file)
|
||||||
{
|
{
|
||||||
BITSETI_CONTRACT (set);
|
BITSETI_CONTRACT (set);
|
||||||
assert(file != NULL);
|
M_ASSERT(file != NULL);
|
||||||
bitset_clean(set);
|
bitset_clean(set);
|
||||||
int c = fgetc(file);
|
int c = fgetc(file);
|
||||||
if (c != '[') return false;
|
if (c != '[') return false;
|
||||||
@@ -614,7 +614,7 @@ static inline bool
|
|||||||
bitset_parse_str(bitset_t set, const char str[], const char **endptr)
|
bitset_parse_str(bitset_t set, const char str[], const char **endptr)
|
||||||
{
|
{
|
||||||
BITSETI_CONTRACT (set);
|
BITSETI_CONTRACT (set);
|
||||||
assert(str != NULL);
|
M_ASSERT(str != NULL);
|
||||||
bool success = false;
|
bool success = false;
|
||||||
bitset_clean(set);
|
bitset_clean(set);
|
||||||
char c = *str++;
|
char c = *str++;
|
||||||
@@ -814,7 +814,7 @@ static inline void
|
|||||||
bitset_get_str(string_t str, const bitset_t set, bool append)
|
bitset_get_str(string_t str, const bitset_t set, bool append)
|
||||||
{
|
{
|
||||||
BITSETI_CONTRACT (set);
|
BITSETI_CONTRACT (set);
|
||||||
assert(str != NULL);
|
M_ASSERT(str != NULL);
|
||||||
(append ? string_cat_str : string_set_str) (str, "[");
|
(append ? string_cat_str : string_set_str) (str, "[");
|
||||||
for(size_t i = 0; i < set->size; i++) {
|
for(size_t i = 0; i < set->size; i++) {
|
||||||
const bool b = bitset_get (set, i);
|
const bool b = bitset_get (set, i);
|
||||||
|
|||||||
+76
-76
@@ -271,39 +271,39 @@
|
|||||||
# define BPTREEI_NODE_CONTRACT(N, isMulti, key_oplist, node, root) do { } while (0)
|
# define BPTREEI_NODE_CONTRACT(N, isMulti, key_oplist, node, root) do { } while (0)
|
||||||
#else
|
#else
|
||||||
# define BPTREEI_NODE_CONTRACT(N, isMulti, key_oplist, node, root) do { \
|
# define BPTREEI_NODE_CONTRACT(N, isMulti, key_oplist, node, root) do { \
|
||||||
assert ((node) != NULL); \
|
M_ASSERT ((node) != NULL); \
|
||||||
assert ((root) != NULL); \
|
M_ASSERT ((root) != NULL); \
|
||||||
int num2 = (node)->num; \
|
int num2 = (node)->num; \
|
||||||
bool is_leaf2 = num2 <= 0; \
|
bool is_leaf2 = num2 <= 0; \
|
||||||
num2 = num2 < 0 ? -num2 : num2; \
|
num2 = num2 < 0 ? -num2 : num2; \
|
||||||
if ((node) == (root)) { \
|
if ((node) == (root)) { \
|
||||||
/* Contract of the root node. num can be 0 */ \
|
/* Contract of the root node. num can be 0 */ \
|
||||||
assert( 0 <= num2 && num2 <= N); \
|
M_ASSERT( 0 <= num2 && num2 <= N); \
|
||||||
if (num2 == 0) assert (is_leaf2); \
|
if (num2 == 0) M_ASSERT (is_leaf2); \
|
||||||
} else { \
|
} else { \
|
||||||
/* Contract of a non-root node. num cannot be 0 */ \
|
/* Contract of a non-root node. num cannot be 0 */ \
|
||||||
int c2 = N / 2; \
|
int c2 = N / 2; \
|
||||||
assert (c2 > 0); \
|
M_ASSERT (c2 > 0); \
|
||||||
assert (c2 <= num2 && num2 <= N); \
|
M_ASSERT (c2 <= num2 && num2 <= N); \
|
||||||
} \
|
} \
|
||||||
/* The node is sorted */ \
|
/* The node is sorted */ \
|
||||||
for(int i2 = 1; i2 < num2 ; i2++) { \
|
for(int i2 = 1; i2 < num2 ; i2++) { \
|
||||||
assert (M_CALL_CMP(key_oplist, (node)->key[i2-1], (node)->key[i2]) M_IF(isMulti)(<=, <) 0); \
|
M_ASSERT (M_CALL_CMP(key_oplist, (node)->key[i2-1], (node)->key[i2]) M_IF(isMulti)(<=, <) 0); \
|
||||||
} \
|
} \
|
||||||
/* The chain node is also sorted */ \
|
/* The chain node is also sorted */ \
|
||||||
if ((node)->next != NULL) { \
|
if ((node)->next != NULL) { \
|
||||||
assert (num2 >= 1); \
|
M_ASSERT (num2 >= 1); \
|
||||||
assert (M_CALL_CMP(key_oplist, (node)->key[num2-1], (node)->next->key[0]) M_IF(isMulti)(<=, <) 0); \
|
M_ASSERT (M_CALL_CMP(key_oplist, (node)->key[num2-1], (node)->next->key[0]) M_IF(isMulti)(<=, <) 0); \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Contract for a B+TREE of size N named 'b' */
|
/* Contract for a B+TREE of size N named 'b' */
|
||||||
#define BPTREEI_CONTRACT(N, isMulti, key_oplist, b) do { \
|
#define BPTREEI_CONTRACT(N, isMulti, key_oplist, b) do { \
|
||||||
assert (N >= 3); /* TBC: 2 instead ? */ \
|
M_ASSERT (N >= 3); /* TBC: 2 instead ? */ \
|
||||||
BPTREEI_NODE_CONTRACT(N, isMulti, key_oplist, (b)->root, (b)->root); \
|
BPTREEI_NODE_CONTRACT(N, isMulti, key_oplist, (b)->root, (b)->root); \
|
||||||
assert ((b)->root->next == NULL); \
|
M_ASSERT ((b)->root->next == NULL); \
|
||||||
if ((b)->root->num <= 0) assert (-(b)->root->num == (int) (b)->size); \
|
if ((b)->root->num <= 0) M_ASSERT (-(b)->root->num == (int) (b)->size); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
/* Max depth of any B+tree
|
/* Max depth of any B+tree
|
||||||
@@ -414,7 +414,7 @@
|
|||||||
node_t n = M_CALL_NEW(key_oplist, struct M_C(name, _node_s)); \
|
node_t n = M_CALL_NEW(key_oplist, struct M_C(name, _node_s)); \
|
||||||
if (M_UNLIKELY (n == NULL)) { \
|
if (M_UNLIKELY (n == NULL)) { \
|
||||||
M_MEMORY_FULL(sizeof (node_t)); \
|
M_MEMORY_FULL(sizeof (node_t)); \
|
||||||
assert (0); \
|
M_ASSERT (0); \
|
||||||
} \
|
} \
|
||||||
n->next = NULL; \
|
n->next = NULL; \
|
||||||
n->num = 0; \
|
n->num = 0; \
|
||||||
@@ -440,7 +440,7 @@
|
|||||||
{ \
|
{ \
|
||||||
int num = n->num; \
|
int num = n->num; \
|
||||||
num = num < 0 ? -num : num; \
|
num = num < 0 ? -num : num; \
|
||||||
assert (num <= N); \
|
M_ASSERT (num <= N); \
|
||||||
return num; \
|
return num; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
@@ -454,11 +454,11 @@
|
|||||||
/* Scan down the nodes to the left down node */ \
|
/* Scan down the nodes to the left down node */ \
|
||||||
while (!M_C(name, _is_leaf)(n)) { \
|
while (!M_C(name, _is_leaf)(n)) { \
|
||||||
pit->parent[np++] = n; \
|
pit->parent[np++] = n; \
|
||||||
assert (np <= BPTREEI_MAX_STACK); \
|
M_ASSERT (np <= BPTREEI_MAX_STACK); \
|
||||||
n = n->kind.node[0]; \
|
n = n->kind.node[0]; \
|
||||||
} \
|
} \
|
||||||
pit->parent[np++] = n; \
|
pit->parent[np++] = n; \
|
||||||
assert (np <= BPTREEI_MAX_STACK); \
|
M_ASSERT (np <= BPTREEI_MAX_STACK); \
|
||||||
/* Clean & free non root */ \
|
/* Clean & free non root */ \
|
||||||
for(int i = 0; i < np; i++) { \
|
for(int i = 0; i < np; i++) { \
|
||||||
n = pit->parent[i]; \
|
n = pit->parent[i]; \
|
||||||
@@ -520,7 +520,7 @@
|
|||||||
} else { \
|
} else { \
|
||||||
/* Copy recursively the associated nodes if it is not a leaf */ \
|
/* Copy recursively the associated nodes if it is not a leaf */ \
|
||||||
for(int i = 0; i <= num; i++) { \
|
for(int i = 0; i <= num; i++) { \
|
||||||
assert(o->kind.node[i] != root); \
|
M_ASSERT(o->kind.node[i] != root); \
|
||||||
n->kind.node[i] = M_C(name, _copy_node)(o->kind.node[i], root); \
|
n->kind.node[i] = M_C(name, _copy_node)(o->kind.node[i], root); \
|
||||||
} \
|
} \
|
||||||
/* The copied nodes don't have their next field correct */ \
|
/* The copied nodes don't have their next field correct */ \
|
||||||
@@ -532,7 +532,7 @@
|
|||||||
/* Go down the tree up to the leaf \
|
/* Go down the tree up to the leaf \
|
||||||
and fix the final 'next' link with the copied node */ \
|
and fix the final 'next' link with the copied node */ \
|
||||||
while (!M_C(name, _is_leaf)(current)) { \
|
while (!M_C(name, _is_leaf)(current)) { \
|
||||||
assert(!M_C(name, _is_leaf)(next)); \
|
M_ASSERT(!M_C(name, _is_leaf)(next)); \
|
||||||
current = current->kind.node[current->num]; \
|
current = current->kind.node[current->num]; \
|
||||||
next = next->kind.node[0]; \
|
next = next->kind.node[0]; \
|
||||||
current->next = next; \
|
current->next = next; \
|
||||||
@@ -546,7 +546,7 @@
|
|||||||
static inline void M_C(name, _init_set)(tree_t b, const tree_t o) \
|
static inline void M_C(name, _init_set)(tree_t b, const tree_t o) \
|
||||||
{ \
|
{ \
|
||||||
BPTREEI_CONTRACT(N, isMulti, key_oplist, o); \
|
BPTREEI_CONTRACT(N, isMulti, key_oplist, o); \
|
||||||
assert (b != NULL); \
|
M_ASSERT (b != NULL); \
|
||||||
/* Just copy recursively the root node */ \
|
/* Just copy recursively the root node */ \
|
||||||
b->root = M_C(name, _copy_node)(o->root, o->root); \
|
b->root = M_C(name, _copy_node)(o->root, o->root); \
|
||||||
b->size = o->size; \
|
b->size = o->size; \
|
||||||
@@ -581,9 +581,9 @@
|
|||||||
BPTREEI_NODE_CONTRACT(N, isMulti, key_oplist, n, b->root); \
|
BPTREEI_NODE_CONTRACT(N, isMulti, key_oplist, n, b->root); \
|
||||||
/* Go down the tree while searching for key */ \
|
/* Go down the tree while searching for key */ \
|
||||||
while (!M_C(name, _is_leaf)(n)) { \
|
while (!M_C(name, _is_leaf)(n)) { \
|
||||||
assert (np <= BPTREEI_MAX_STACK); \
|
M_ASSERT (np <= BPTREEI_MAX_STACK); \
|
||||||
int i, hi = n->num; \
|
int i, hi = n->num; \
|
||||||
assert (hi > 0); \
|
M_ASSERT (hi > 0); \
|
||||||
/* Linear search is usually faster than binary search for \
|
/* Linear search is usually faster than binary search for \
|
||||||
B+TREE (due to cache effect). If a binary tree is faster for \
|
B+TREE (due to cache effect). If a binary tree is faster for \
|
||||||
the choosen type and size , it probably means that the \
|
the choosen type and size , it probably means that the \
|
||||||
@@ -596,7 +596,7 @@
|
|||||||
pit->parent[np++] = n; \
|
pit->parent[np++] = n; \
|
||||||
/* Select the new node to go down to */ \
|
/* Select the new node to go down to */ \
|
||||||
n = n->kind.node[i]; \
|
n = n->kind.node[i]; \
|
||||||
assert (n != NULL); \
|
M_ASSERT (n != NULL); \
|
||||||
BPTREEI_NODE_CONTRACT(N, isMulti, key_oplist, n, b->root); \
|
BPTREEI_NODE_CONTRACT(N, isMulti, key_oplist, n, b->root); \
|
||||||
} \
|
} \
|
||||||
pit->num = np; \
|
pit->num = np; \
|
||||||
@@ -632,9 +632,9 @@
|
|||||||
M_C(name, _search_and_insert_in_leaf)(node_t n, key_t const key \
|
M_C(name, _search_and_insert_in_leaf)(node_t n, key_t const key \
|
||||||
M_IF(isMap)( M_DEFERRED_COMMA value_t const value,) ) \
|
M_IF(isMap)( M_DEFERRED_COMMA value_t const value,) ) \
|
||||||
{ \
|
{ \
|
||||||
assert (M_C(name, _is_leaf)(n)); \
|
M_ASSERT (M_C(name, _is_leaf)(n)); \
|
||||||
int i, num = M_C(name, _get_num)(n); \
|
int i, num = M_C(name, _get_num)(n); \
|
||||||
assert (num <= N); \
|
M_ASSERT (num <= N); \
|
||||||
/* Search for the key in the node n (a leaf) for insertion */ \
|
/* Search for the key in the node n (a leaf) for insertion */ \
|
||||||
for(i = 0; i < num; i++) { \
|
for(i = 0; i < num; i++) { \
|
||||||
int cmp = M_CALL_CMP(key_oplist, key, n->key[i]); \
|
int cmp = M_CALL_CMP(key_oplist, key, n->key[i]); \
|
||||||
@@ -663,9 +663,9 @@
|
|||||||
static inline int \
|
static inline int \
|
||||||
M_C(name, _search_and_insert_in_node)(node_t n, node_t l, key_t key) \
|
M_C(name, _search_and_insert_in_node)(node_t n, node_t l, key_t key) \
|
||||||
{ \
|
{ \
|
||||||
assert (!M_C(name, _is_leaf)(n)); \
|
M_ASSERT (!M_C(name, _is_leaf)(n)); \
|
||||||
int i, num = M_C(name, _get_num)(n); \
|
int i, num = M_C(name, _get_num)(n); \
|
||||||
assert (num <= N); \
|
M_ASSERT (num <= N); \
|
||||||
/* Search for the key in the node n (not a leaf) for insertion */ \
|
/* Search for the key in the node n (not a leaf) for insertion */ \
|
||||||
for(i = 0; i < num; i++) { \
|
for(i = 0; i < num; i++) { \
|
||||||
if (n->kind.node[i] == l) { \
|
if (n->kind.node[i] == l) { \
|
||||||
@@ -702,13 +702,13 @@
|
|||||||
b->size ++; \
|
b->size ++; \
|
||||||
/* Most likely case: leaf can accept key */ \
|
/* Most likely case: leaf can accept key */ \
|
||||||
int num = -leaf->num; \
|
int num = -leaf->num; \
|
||||||
assert (num > 0); \
|
M_ASSERT (num > 0); \
|
||||||
if (M_LIKELY (num <= N)) { \
|
if (M_LIKELY (num <= N)) { \
|
||||||
/* nothing more to do */ \
|
/* nothing more to do */ \
|
||||||
BPTREEI_CONTRACT(N, isMulti, key_oplist, b); \
|
BPTREEI_CONTRACT(N, isMulti, key_oplist, b); \
|
||||||
return; \
|
return; \
|
||||||
} \
|
} \
|
||||||
assert (num == N+1); \
|
M_ASSERT (num == N+1); \
|
||||||
\
|
\
|
||||||
/* Needs to rebalance the B+TREE */ \
|
/* Needs to rebalance the B+TREE */ \
|
||||||
/* leaf is full: need to slip the leaf in two */ \
|
/* leaf is full: need to slip the leaf in two */ \
|
||||||
@@ -750,11 +750,11 @@
|
|||||||
BPTREEI_CONTRACT(N, isMulti, key_oplist, b); \
|
BPTREEI_CONTRACT(N, isMulti, key_oplist, b); \
|
||||||
return; /* No need to split parent.*/ \
|
return; /* No need to split parent.*/ \
|
||||||
} \
|
} \
|
||||||
assert (parent->num == N+1); \
|
M_ASSERT (parent->num == N+1); \
|
||||||
/* Need to split parent in {np} {med} {nnp} */ \
|
/* Need to split parent in {np} {med} {nnp} */ \
|
||||||
int nnp = N / 2; \
|
int nnp = N / 2; \
|
||||||
int np = N - nnp; \
|
int np = N - nnp; \
|
||||||
assert (nnp > 0 && np > 0 && nnp+np+1 == N+1); \
|
M_ASSERT (nnp > 0 && np > 0 && nnp+np+1 == N+1); \
|
||||||
node_t nparent = M_C(name, _new_node)(); \
|
node_t nparent = M_C(name, _new_node)(); \
|
||||||
/* Move half items to new node (Like a classic B-TREE) \
|
/* Move half items to new node (Like a classic B-TREE) \
|
||||||
and the median key to the grand-parent*/ \
|
and the median key to the grand-parent*/ \
|
||||||
@@ -776,7 +776,7 @@
|
|||||||
static inline int \
|
static inline int \
|
||||||
M_C(name, _search_and_remove_in_leaf)(node_t n, key_t const key) \
|
M_C(name, _search_and_remove_in_leaf)(node_t n, key_t const key) \
|
||||||
{ \
|
{ \
|
||||||
assert(M_C(name, _is_leaf)(n)); \
|
M_ASSERT(M_C(name, _is_leaf)(n)); \
|
||||||
const int num = M_C(name, _get_num)(n); \
|
const int num = M_C(name, _get_num)(n); \
|
||||||
for(int i = 0; i < num; i++) { \
|
for(int i = 0; i < num; i++) { \
|
||||||
const int cmp = M_CALL_CMP(key_oplist, key, n->key[i]); \
|
const int cmp = M_CALL_CMP(key_oplist, key, n->key[i]); \
|
||||||
@@ -795,15 +795,15 @@
|
|||||||
\
|
\
|
||||||
static inline void M_C(name, _left_shift)(node_t parent, int k) \
|
static inline void M_C(name, _left_shift)(node_t parent, int k) \
|
||||||
{ \
|
{ \
|
||||||
assert (parent != NULL && !M_C(name, _is_leaf)(parent)); \
|
M_ASSERT (parent != NULL && !M_C(name, _is_leaf)(parent)); \
|
||||||
assert (0 <= k && k < M_C(name, _get_num)(parent)); \
|
M_ASSERT (0 <= k && k < M_C(name, _get_num)(parent)); \
|
||||||
node_t left = parent->kind.node[k]; \
|
node_t left = parent->kind.node[k]; \
|
||||||
node_t right = parent->kind.node[k+1]; \
|
node_t right = parent->kind.node[k+1]; \
|
||||||
assert (left != NULL && right != NULL); \
|
M_ASSERT (left != NULL && right != NULL); \
|
||||||
int num_left = M_C(name, _get_num)(left); \
|
int num_left = M_C(name, _get_num)(left); \
|
||||||
int num_right = M_C(name, _get_num)(right); \
|
int num_right = M_C(name, _get_num)(right); \
|
||||||
assert (num_left > N/2); \
|
M_ASSERT (num_left > N/2); \
|
||||||
assert (num_right < N/2); \
|
M_ASSERT (num_right < N/2); \
|
||||||
\
|
\
|
||||||
/* Move one item from the left node to the right node */ \
|
/* Move one item from the left node to the right node */ \
|
||||||
memmove(&right->key[1], &right->key[0], sizeof(key_t)*(unsigned int)num_right); \
|
memmove(&right->key[1], &right->key[0], sizeof(key_t)*(unsigned int)num_right); \
|
||||||
@@ -824,21 +824,21 @@
|
|||||||
/* left[n-1] is move to parent[k] (clear). left[n-1] is therefore clear */ \
|
/* left[n-1] is move to parent[k] (clear). left[n-1] is therefore clear */ \
|
||||||
memmove(&parent->key[k], &left->key[num_left-1], sizeof (key_t)); \
|
memmove(&parent->key[k], &left->key[num_left-1], sizeof (key_t)); \
|
||||||
} \
|
} \
|
||||||
assert (right->num != 0); \
|
M_ASSERT (right->num != 0); \
|
||||||
assert (left->num != 0); \
|
M_ASSERT (left->num != 0); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void M_C(name, _right_shift)(node_t parent, int k) \
|
static inline void M_C(name, _right_shift)(node_t parent, int k) \
|
||||||
{ \
|
{ \
|
||||||
assert (parent != NULL && !M_C(name, _is_leaf)(parent)); \
|
M_ASSERT (parent != NULL && !M_C(name, _is_leaf)(parent)); \
|
||||||
assert (0 <= k && k < M_C(name, _get_num)(parent)); \
|
M_ASSERT (0 <= k && k < M_C(name, _get_num)(parent)); \
|
||||||
node_t left = parent->kind.node[k]; \
|
node_t left = parent->kind.node[k]; \
|
||||||
node_t right = parent->kind.node[k+1]; \
|
node_t right = parent->kind.node[k+1]; \
|
||||||
assert (left != NULL && right != NULL); \
|
M_ASSERT (left != NULL && right != NULL); \
|
||||||
int num_left = M_C(name, _get_num)(left); \
|
int num_left = M_C(name, _get_num)(left); \
|
||||||
int num_right = M_C(name, _get_num)(right); \
|
int num_right = M_C(name, _get_num)(right); \
|
||||||
assert (num_left < N/2); \
|
M_ASSERT (num_left < N/2); \
|
||||||
assert (num_right > N/2); \
|
M_ASSERT (num_right > N/2); \
|
||||||
\
|
\
|
||||||
/* Move one item from the right node to the left node. */ \
|
/* Move one item from the right node to the left node. */ \
|
||||||
if (M_C(name, _is_leaf)(right)) { \
|
if (M_C(name, _is_leaf)(right)) { \
|
||||||
@@ -858,29 +858,29 @@
|
|||||||
right->num = num_right - 1; \
|
right->num = num_right - 1; \
|
||||||
left->num = num_left + 1; \
|
left->num = num_left + 1; \
|
||||||
} \
|
} \
|
||||||
assert (right->num != 0); \
|
M_ASSERT (right->num != 0); \
|
||||||
assert (left->num != 0); \
|
M_ASSERT (left->num != 0); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void M_C(name, _merge_node)(node_t parent, int k, bool leaf) \
|
static inline void M_C(name, _merge_node)(node_t parent, int k, bool leaf) \
|
||||||
{ \
|
{ \
|
||||||
assert (parent != NULL && !M_C(name, _is_leaf)(parent)); \
|
M_ASSERT (parent != NULL && !M_C(name, _is_leaf)(parent)); \
|
||||||
assert (0 <= k && k < M_C(name, _get_num(parent))); \
|
M_ASSERT (0 <= k && k < M_C(name, _get_num(parent))); \
|
||||||
node_t left = parent->kind.node[k]; \
|
node_t left = parent->kind.node[k]; \
|
||||||
node_t right = parent->kind.node[k+1]; \
|
node_t right = parent->kind.node[k+1]; \
|
||||||
assert (left != NULL && right != NULL); \
|
M_ASSERT (left != NULL && right != NULL); \
|
||||||
int num_parent = M_C(name, _get_num)(parent); \
|
int num_parent = M_C(name, _get_num)(parent); \
|
||||||
int num_left = M_C(name, _get_num)(left); \
|
int num_left = M_C(name, _get_num)(left); \
|
||||||
int num_right = M_C(name, _get_num)(right); \
|
int num_right = M_C(name, _get_num)(right); \
|
||||||
\
|
\
|
||||||
/* Merge node 'k' and 'k+1' into a single one */ \
|
/* Merge node 'k' and 'k+1' into a single one */ \
|
||||||
if (leaf) { \
|
if (leaf) { \
|
||||||
assert (num_left + num_right <= N); \
|
M_ASSERT (num_left + num_right <= N); \
|
||||||
memmove(&left->key[num_left], &right->key[0], sizeof(key_t)*(unsigned int)num_right); \
|
memmove(&left->key[num_left], &right->key[0], sizeof(key_t)*(unsigned int)num_right); \
|
||||||
M_IF(isMap)(memmove(&left->kind.value[num_left], &right->kind.value[0], sizeof(value_t)*(unsigned int)num_right);,) \
|
M_IF(isMap)(memmove(&left->kind.value[num_left], &right->kind.value[0], sizeof(value_t)*(unsigned int)num_right);,) \
|
||||||
left->num = -num_left - num_right; \
|
left->num = -num_left - num_right; \
|
||||||
} else { \
|
} else { \
|
||||||
assert (num_left + num_right <= N -1); \
|
M_ASSERT (num_left + num_right <= N -1); \
|
||||||
memmove(&left->key[num_left+1], &right->key[0], sizeof(key_t)*(unsigned int)num_right); \
|
memmove(&left->key[num_left+1], &right->key[0], sizeof(key_t)*(unsigned int)num_right); \
|
||||||
memmove(&left->kind.node[num_left+1], &right->kind.node[0], sizeof(node_t)*(unsigned int)(num_right+1)); \
|
memmove(&left->kind.node[num_left+1], &right->kind.node[0], sizeof(node_t)*(unsigned int)(num_right+1)); \
|
||||||
M_CALL_INIT_SET(key_oplist, left->key[num_left], parent->key[k]); \
|
M_CALL_INIT_SET(key_oplist, left->key[num_left], parent->key[k]); \
|
||||||
@@ -900,13 +900,13 @@
|
|||||||
static inline int \
|
static inline int \
|
||||||
M_C(name, _search_for_node)(node_t parent, node_t child) \
|
M_C(name, _search_for_node)(node_t parent, node_t child) \
|
||||||
{ \
|
{ \
|
||||||
assert (!M_C(name, _is_leaf)(parent)); \
|
M_ASSERT (!M_C(name, _is_leaf)(parent)); \
|
||||||
const int num = M_C(name, _get_num)(parent); \
|
const int num = M_C(name, _get_num)(parent); \
|
||||||
for(int i = 0; i <= num; i++) { \
|
for(int i = 0; i <= num; i++) { \
|
||||||
if (parent->kind.node[i] == child) \
|
if (parent->kind.node[i] == child) \
|
||||||
return i; \
|
return i; \
|
||||||
} \
|
} \
|
||||||
assert(false); \
|
M_ASSERT(false); \
|
||||||
return -1; /* unreachable */ \
|
return -1; /* unreachable */ \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
@@ -924,13 +924,13 @@
|
|||||||
if (M_LIKELY (M_C(name, _get_num)(leaf) >= N/2) || pit->num == 0) \
|
if (M_LIKELY (M_C(name, _get_num)(leaf) >= N/2) || pit->num == 0) \
|
||||||
return true; \
|
return true; \
|
||||||
/* Leaf is too small. Needs rebalancing */ \
|
/* Leaf is too small. Needs rebalancing */ \
|
||||||
assert (M_C(name, _get_num)(leaf) == N/2-1); \
|
M_ASSERT (M_C(name, _get_num)(leaf) == N/2-1); \
|
||||||
bool pass1 = true; \
|
bool pass1 = true; \
|
||||||
while (true) { \
|
while (true) { \
|
||||||
assert (pit->num > 0); \
|
M_ASSERT (pit->num > 0); \
|
||||||
/* Search for node 'leaf' in parent */ \
|
/* Search for node 'leaf' in parent */ \
|
||||||
node_t parent = pit->parent[--pit->num]; \
|
node_t parent = pit->parent[--pit->num]; \
|
||||||
assert (parent != NULL); \
|
M_ASSERT (parent != NULL); \
|
||||||
k = M_C(name, _search_for_node)(parent, leaf); \
|
k = M_C(name, _search_for_node)(parent, leaf); \
|
||||||
/* Look for the neighboor of the removed key. */ \
|
/* Look for the neighboor of the removed key. */ \
|
||||||
/* if we can steal one key from them to keep our node balanced */ \
|
/* if we can steal one key from them to keep our node balanced */ \
|
||||||
@@ -945,7 +945,7 @@
|
|||||||
/* Merge both nodes, removing 'k' from parent */ \
|
/* Merge both nodes, removing 'k' from parent */ \
|
||||||
if (k == M_C(name, _get_num)(parent)) \
|
if (k == M_C(name, _get_num)(parent)) \
|
||||||
k--; \
|
k--; \
|
||||||
assert(k >= 0 && k < M_C(name, _get_num)(parent)); \
|
M_ASSERT(k >= 0 && k < M_C(name, _get_num)(parent)); \
|
||||||
/* Merge 'k' & 'k+1' & remove 'k' from parent */ \
|
/* Merge 'k' & 'k+1' & remove 'k' from parent */ \
|
||||||
M_C(name, _merge_node)(parent, k, pass1); \
|
M_C(name, _merge_node)(parent, k, pass1); \
|
||||||
/* Check if we need to continue */ \
|
/* Check if we need to continue */ \
|
||||||
@@ -982,7 +982,7 @@
|
|||||||
M_C(name, _it)(it_t it, const tree_t b) \
|
M_C(name, _it)(it_t it, const tree_t b) \
|
||||||
{ \
|
{ \
|
||||||
BPTREEI_CONTRACT(N, isMulti, key_oplist, b); \
|
BPTREEI_CONTRACT(N, isMulti, key_oplist, b); \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
node_t n = b->root; \
|
node_t n = b->root; \
|
||||||
/* Scan down the nodes */ \
|
/* Scan down the nodes */ \
|
||||||
while (!M_C(name, _is_leaf)(n)) { \
|
while (!M_C(name, _is_leaf)(n)) { \
|
||||||
@@ -996,7 +996,7 @@
|
|||||||
M_C(name, _it_end)(it_t it, const tree_t b) \
|
M_C(name, _it_end)(it_t it, const tree_t b) \
|
||||||
{ \
|
{ \
|
||||||
BPTREEI_CONTRACT(N, isMulti, key_oplist, b); \
|
BPTREEI_CONTRACT(N, isMulti, key_oplist, b); \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
node_t n = b->root; \
|
node_t n = b->root; \
|
||||||
/* Scan down the nodes */ \
|
/* Scan down the nodes */ \
|
||||||
while (!M_C(name, _is_leaf)(n)) { \
|
while (!M_C(name, _is_leaf)(n)) { \
|
||||||
@@ -1009,7 +1009,7 @@
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _it_set)(it_t itd, const it_t its) \
|
M_C(name, _it_set)(it_t itd, const it_t its) \
|
||||||
{ \
|
{ \
|
||||||
assert (itd != NULL && its != NULL); \
|
M_ASSERT (itd != NULL && its != NULL); \
|
||||||
itd->node = its->node; \
|
itd->node = its->node; \
|
||||||
itd->idx = its->idx; \
|
itd->idx = its->idx; \
|
||||||
} \
|
} \
|
||||||
@@ -1017,8 +1017,8 @@
|
|||||||
static inline bool \
|
static inline bool \
|
||||||
M_C(name, _end_p)(it_t it) \
|
M_C(name, _end_p)(it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert (it != NULL && it->node != NULL); \
|
M_ASSERT (it != NULL && it->node != NULL); \
|
||||||
assert (M_C(name, _is_leaf)(it->node)); \
|
M_ASSERT (M_C(name, _is_leaf)(it->node)); \
|
||||||
return it->node->next ==NULL && it->idx >= -it->node->num; \
|
return it->node->next ==NULL && it->idx >= -it->node->num; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
@@ -1031,7 +1031,7 @@
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _next)(it_t it) \
|
M_C(name, _next)(it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert (it != NULL && it->node != NULL); \
|
M_ASSERT (it != NULL && it->node != NULL); \
|
||||||
it->idx ++; \
|
it->idx ++; \
|
||||||
if (it->idx >= -it->node->num && it->node->next != NULL) { \
|
if (it->idx >= -it->node->num && it->node->next != NULL) { \
|
||||||
it->node = it->node->next; \
|
it->node = it->node->next; \
|
||||||
@@ -1042,8 +1042,8 @@
|
|||||||
static inline subtype_t * \
|
static inline subtype_t * \
|
||||||
M_C(name, _ref)(it_t it) \
|
M_C(name, _ref)(it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert (it != NULL && it->node != NULL); \
|
M_ASSERT (it != NULL && it->node != NULL); \
|
||||||
assert (it->idx <= -it->node->num); \
|
M_ASSERT (it->idx <= -it->node->num); \
|
||||||
M_IF(isMap)( \
|
M_IF(isMap)( \
|
||||||
it->pair.key_ptr = &it->node->key[it->idx]; \
|
it->pair.key_ptr = &it->node->key[it->idx]; \
|
||||||
it->pair.value_ptr = &it->node->kind.value[it->idx]; \
|
it->pair.value_ptr = &it->node->kind.value[it->idx]; \
|
||||||
@@ -1064,7 +1064,7 @@
|
|||||||
M_C(name, _it_from)(it_t it, const tree_t b, key_t const key) \
|
M_C(name, _it_from)(it_t it, const tree_t b, key_t const key) \
|
||||||
{ \
|
{ \
|
||||||
BPTREEI_CONTRACT(N, isMulti, key_oplist, b); \
|
BPTREEI_CONTRACT(N, isMulti, key_oplist, b); \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
pit_t pit; \
|
pit_t pit; \
|
||||||
node_t n = M_C(name, _search_for_leaf)(pit, b, key); \
|
node_t n = M_C(name, _search_for_leaf)(pit, b, key); \
|
||||||
it->node = n; \
|
it->node = n; \
|
||||||
@@ -1084,7 +1084,7 @@
|
|||||||
static inline bool \
|
static inline bool \
|
||||||
M_C(name, _it_until_p)(it_t it, key_t const key) \
|
M_C(name, _it_until_p)(it_t it, key_t const key) \
|
||||||
{ \
|
{ \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
node_t n = it->node; \
|
node_t n = it->node; \
|
||||||
if (it->idx >= -n->num) return true; \
|
if (it->idx >= -n->num) return true; \
|
||||||
int cmp = M_CALL_CMP(key_oplist, n->key[it->idx], key); \
|
int cmp = M_CALL_CMP(key_oplist, n->key[it->idx], key); \
|
||||||
@@ -1094,7 +1094,7 @@
|
|||||||
static inline bool \
|
static inline bool \
|
||||||
M_C(name, _it_while_p)(it_t it, key_t const key) \
|
M_C(name, _it_while_p)(it_t it, key_t const key) \
|
||||||
{ \
|
{ \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
node_t n = it->node; \
|
node_t n = it->node; \
|
||||||
if (it->idx >= -n->num) return false; \
|
if (it->idx >= -n->num) return false; \
|
||||||
int cmp = M_CALL_CMP(key_oplist, n->key[it->idx], key); \
|
int cmp = M_CALL_CMP(key_oplist, n->key[it->idx], key); \
|
||||||
@@ -1111,7 +1111,7 @@
|
|||||||
M_C(name, _min)(const tree_t b) \
|
M_C(name, _min)(const tree_t b) \
|
||||||
{ \
|
{ \
|
||||||
BPTREEI_CONTRACT(N, isMulti, key_oplist, b); \
|
BPTREEI_CONTRACT(N, isMulti, key_oplist, b); \
|
||||||
assert (b->size > 0); \
|
M_ASSERT (b->size > 0); \
|
||||||
node_t n = b->root; \
|
node_t n = b->root; \
|
||||||
/* Scan down the nodes */ \
|
/* Scan down the nodes */ \
|
||||||
while (!M_C(name, _is_leaf)(n)) { \
|
while (!M_C(name, _is_leaf)(n)) { \
|
||||||
@@ -1148,7 +1148,7 @@
|
|||||||
M_C(name, _init_move)(tree_t b, tree_t ref) \
|
M_C(name, _init_move)(tree_t b, tree_t ref) \
|
||||||
{ \
|
{ \
|
||||||
BPTREEI_CONTRACT(N, isMulti, key_oplist, ref); \
|
BPTREEI_CONTRACT(N, isMulti, key_oplist, ref); \
|
||||||
assert (b != NULL && b != ref); \
|
M_ASSERT (b != NULL && b != ref); \
|
||||||
b->size = ref->size; \
|
b->size = ref->size; \
|
||||||
b->root = ref->root; \
|
b->root = ref->root; \
|
||||||
ref->root = NULL; \
|
ref->root = NULL; \
|
||||||
@@ -1160,7 +1160,7 @@
|
|||||||
{ \
|
{ \
|
||||||
BPTREEI_CONTRACT(N, isMulti, key_oplist, b); \
|
BPTREEI_CONTRACT(N, isMulti, key_oplist, b); \
|
||||||
BPTREEI_CONTRACT(N, isMulti, key_oplist, ref); \
|
BPTREEI_CONTRACT(N, isMulti, key_oplist, ref); \
|
||||||
assert (b != ref); \
|
M_ASSERT (b != ref); \
|
||||||
M_C(name,_clear)(b); \
|
M_C(name,_clear)(b); \
|
||||||
M_C(name,_init_move)(b, ref); \
|
M_C(name,_init_move)(b, ref); \
|
||||||
BPTREEI_CONTRACT(N, isMulti, key_oplist, b); \
|
BPTREEI_CONTRACT(N, isMulti, key_oplist, b); \
|
||||||
@@ -1246,7 +1246,7 @@
|
|||||||
static inline void M_C(name, _get_str)(string_t str, \
|
static inline void M_C(name, _get_str)(string_t str, \
|
||||||
const tree_t t1, bool append) { \
|
const tree_t t1, bool append) { \
|
||||||
BPTREEI_CONTRACT(N, isMulti, key_oplist, t1); \
|
BPTREEI_CONTRACT(N, isMulti, key_oplist, t1); \
|
||||||
assert(str != NULL); \
|
M_ASSERT(str != NULL); \
|
||||||
(append ? string_cat_str : string_set_str) (str, "["); \
|
(append ? string_cat_str : string_set_str) (str, "["); \
|
||||||
/* NOTE: The print is really naive, and not really efficient */ \
|
/* NOTE: The print is really naive, and not really efficient */ \
|
||||||
bool commaToPrint = false; \
|
bool commaToPrint = false; \
|
||||||
@@ -1275,7 +1275,7 @@
|
|||||||
M_C(name, _out_str)(FILE *file, tree_t const t1) \
|
M_C(name, _out_str)(FILE *file, tree_t const t1) \
|
||||||
{ \
|
{ \
|
||||||
BPTREEI_CONTRACT(N, isMulti, key_oplist, t1); \
|
BPTREEI_CONTRACT(N, isMulti, key_oplist, t1); \
|
||||||
assert (file != NULL); \
|
M_ASSERT (file != NULL); \
|
||||||
fputc ('[', file); \
|
fputc ('[', file); \
|
||||||
bool commaToPrint = false; \
|
bool commaToPrint = false; \
|
||||||
it_t it; \
|
it_t it; \
|
||||||
@@ -1303,7 +1303,7 @@
|
|||||||
M_C(name, _parse_str)(tree_t t1, const char str[], const char **endp) \
|
M_C(name, _parse_str)(tree_t t1, const char str[], const char **endp) \
|
||||||
{ \
|
{ \
|
||||||
BPTREEI_CONTRACT(N, isMulti, key_oplist, t1); \
|
BPTREEI_CONTRACT(N, isMulti, key_oplist, t1); \
|
||||||
assert (str != NULL); \
|
M_ASSERT (str != NULL); \
|
||||||
M_C(name,_clean)(t1); \
|
M_C(name,_clean)(t1); \
|
||||||
bool success = false; \
|
bool success = false; \
|
||||||
int c = *str++; \
|
int c = *str++; \
|
||||||
@@ -1345,7 +1345,7 @@
|
|||||||
M_C(name, _in_str)(tree_t t1, FILE *file) \
|
M_C(name, _in_str)(tree_t t1, FILE *file) \
|
||||||
{ \
|
{ \
|
||||||
BPTREEI_CONTRACT(N, isMulti, key_oplist, t1); \
|
BPTREEI_CONTRACT(N, isMulti, key_oplist, t1); \
|
||||||
assert (file != NULL); \
|
M_ASSERT (file != NULL); \
|
||||||
M_C(name,_clean)(t1); \
|
M_C(name,_clean)(t1); \
|
||||||
int c = fgetc(file); \
|
int c = fgetc(file); \
|
||||||
if (M_UNLIKELY (c != '[')) return false; \
|
if (M_UNLIKELY (c != '[')) return false; \
|
||||||
@@ -1383,7 +1383,7 @@
|
|||||||
M_C(name, _out_serial)(m_serial_write_t f, tree_t const t1) \
|
M_C(name, _out_serial)(m_serial_write_t f, tree_t const t1) \
|
||||||
{ \
|
{ \
|
||||||
BPTREEI_CONTRACT(N, isMulti, key_oplist, t1); \
|
BPTREEI_CONTRACT(N, isMulti, key_oplist, t1); \
|
||||||
assert (f != NULL && f->m_interface != NULL); \
|
M_ASSERT (f != NULL && f->m_interface != NULL); \
|
||||||
m_serial_return_code_t ret; \
|
m_serial_return_code_t ret; \
|
||||||
m_serial_local_t local; \
|
m_serial_local_t local; \
|
||||||
subtype_t const *item; \
|
subtype_t const *item; \
|
||||||
@@ -1427,7 +1427,7 @@
|
|||||||
M_C(name, _in_serial)(tree_t t1, m_serial_read_t f) \
|
M_C(name, _in_serial)(tree_t t1, m_serial_read_t f) \
|
||||||
{ \
|
{ \
|
||||||
BPTREEI_CONTRACT(N, isMulti, key_oplist, t1); \
|
BPTREEI_CONTRACT(N, isMulti, key_oplist, t1); \
|
||||||
assert (f != NULL && f->m_interface != NULL); \
|
M_ASSERT (f != NULL && f->m_interface != NULL); \
|
||||||
m_serial_local_t local; \
|
m_serial_local_t local; \
|
||||||
m_serial_return_code_t ret; \
|
m_serial_return_code_t ret; \
|
||||||
size_t estimated_size = 0; \
|
size_t estimated_size = 0; \
|
||||||
|
|||||||
+29
-29
@@ -141,12 +141,12 @@ typedef enum {
|
|||||||
(((policy) & (val)) != 0)
|
(((policy) & (val)) != 0)
|
||||||
|
|
||||||
#define BUFFERI_CONTRACT(buffer, size) do { \
|
#define BUFFERI_CONTRACT(buffer, size) do { \
|
||||||
assert (buffer != NULL); \
|
M_ASSERT (buffer != NULL); \
|
||||||
assert (buffer->data != NULL); \
|
M_ASSERT (buffer->data != NULL); \
|
||||||
}while (0)
|
}while (0)
|
||||||
|
|
||||||
#define BUFFERI_PROTECTED_CONTRACT(buffer, size) do { \
|
#define BUFFERI_PROTECTED_CONTRACT(buffer, size) do { \
|
||||||
assert (atomic_load(&buffer->number[0]) <= BUFFERI_SIZE(size)); \
|
M_ASSERT (atomic_load(&buffer->number[0]) <= BUFFERI_SIZE(size)); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
/* Deferred evaluation for the definition,
|
/* Deferred evaluation for the definition,
|
||||||
@@ -200,7 +200,7 @@ typedef enum {
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _init)(buffer_t v, size_t size) \
|
M_C(name, _init)(buffer_t v, size_t size) \
|
||||||
{ \
|
{ \
|
||||||
BUFFERI_IF_CTE_SIZE(m_size)(assert(size == m_size), v->size = size); \
|
BUFFERI_IF_CTE_SIZE(m_size)(M_ASSERT(size == m_size), v->size = size); \
|
||||||
v->idx_prod = v->idx_cons = v->overwrite = 0; \
|
v->idx_prod = v->idx_cons = v->overwrite = 0; \
|
||||||
atomic_init (&v->number[0], 0UL); \
|
atomic_init (&v->number[0], 0UL); \
|
||||||
if (BUFFERI_POLICY_P(policy, BUFFER_DEFERRED_POP)) \
|
if (BUFFERI_POLICY_P(policy, BUFFER_DEFERRED_POP)) \
|
||||||
@@ -211,7 +211,7 @@ M_C(name, _init)(buffer_t v, size_t size) \
|
|||||||
m_cond_init(v->there_is_data); \
|
m_cond_init(v->there_is_data); \
|
||||||
m_cond_init(v->there_is_room_for_data); \
|
m_cond_init(v->there_is_room_for_data); \
|
||||||
} else { \
|
} else { \
|
||||||
assert(BUFFERI_POLICY_P((policy), BUFFER_UNBLOCKING)); \
|
M_ASSERT(BUFFERI_POLICY_P((policy), BUFFER_UNBLOCKING)); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
BUFFERI_IF_CTE_SIZE(m_size)( /* Statically allocated */ , \
|
BUFFERI_IF_CTE_SIZE(m_size)( /* Statically allocated */ , \
|
||||||
@@ -309,7 +309,7 @@ M_C(name, _init)(buffer_t v, size_t size) \
|
|||||||
M_C(name, _uptr_ct) vu; \
|
M_C(name, _uptr_ct) vu; \
|
||||||
vu.cptr = src; \
|
vu.cptr = src; \
|
||||||
M_C(name, _ptr) v = vu.ptr; \
|
M_C(name, _ptr) v = vu.ptr; \
|
||||||
assert (dest != v); \
|
M_ASSERT (dest != v); \
|
||||||
BUFFERI_CONTRACT(v,m_size); \
|
BUFFERI_CONTRACT(v,m_size); \
|
||||||
M_C(name, _init)(dest, BUFFERI_SIZE(m_size)); \
|
M_C(name, _init)(dest, BUFFERI_SIZE(m_size)); \
|
||||||
if (!BUFFERI_POLICY_P((policy), BUFFER_THREAD_UNSAFE)) { \
|
if (!BUFFERI_POLICY_P((policy), BUFFER_THREAD_UNSAFE)) { \
|
||||||
@@ -530,7 +530,7 @@ M_C(name, _init)(buffer_t v, size_t size) \
|
|||||||
M_C(name, _pop_blocking)(type *data, buffer_t v, bool blocking) \
|
M_C(name, _pop_blocking)(type *data, buffer_t v, bool blocking) \
|
||||||
{ \
|
{ \
|
||||||
BUFFERI_CONTRACT(v,m_size); \
|
BUFFERI_CONTRACT(v,m_size); \
|
||||||
assert (data != NULL); \
|
M_ASSERT (data != NULL); \
|
||||||
\
|
\
|
||||||
/* BUFFER lock */ \
|
/* BUFFER lock */ \
|
||||||
if (!BUFFERI_POLICY_P((policy), BUFFER_THREAD_UNSAFE)) { \
|
if (!BUFFERI_POLICY_P((policy), BUFFER_THREAD_UNSAFE)) { \
|
||||||
@@ -665,13 +665,13 @@ M_C(name, _init)(buffer_t v, size_t size) \
|
|||||||
# define QUEUEI_MPMC_CONTRACT(v) /* nothing */
|
# define QUEUEI_MPMC_CONTRACT(v) /* nothing */
|
||||||
#else
|
#else
|
||||||
# define QUEUEI_MPMC_CONTRACT(v) do { \
|
# define QUEUEI_MPMC_CONTRACT(v) do { \
|
||||||
assert (v != 0); \
|
M_ASSERT (v != 0); \
|
||||||
assert (v->Tab != NULL); \
|
M_ASSERT (v->Tab != NULL); \
|
||||||
unsigned int _r = atomic_load(&v->ConsoIdx); \
|
unsigned int _r = atomic_load(&v->ConsoIdx); \
|
||||||
unsigned int _w = atomic_load(&v->ProdIdx); \
|
unsigned int _w = atomic_load(&v->ProdIdx); \
|
||||||
_r = atomic_load(&v->ConsoIdx); \
|
_r = atomic_load(&v->ConsoIdx); \
|
||||||
assert (_r > _w || _w-_r <= v->size); \
|
M_ASSERT (_r > _w || _w-_r <= v->size); \
|
||||||
assert (M_POWEROF2_P(v->size)); \
|
M_ASSERT (M_POWEROF2_P(v->size)); \
|
||||||
} while (0)
|
} while (0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -747,7 +747,7 @@ M_C(name, _init)(buffer_t v, size_t size) \
|
|||||||
M_C(name, _pop)(type *ptr, buffer_t table) \
|
M_C(name, _pop)(type *ptr, buffer_t table) \
|
||||||
{ \
|
{ \
|
||||||
QUEUEI_MPMC_CONTRACT(table); \
|
QUEUEI_MPMC_CONTRACT(table); \
|
||||||
assert (ptr != NULL); \
|
M_ASSERT (ptr != NULL); \
|
||||||
unsigned int iC = atomic_load_explicit(&table->ConsoIdx, \
|
unsigned int iC = atomic_load_explicit(&table->ConsoIdx, \
|
||||||
memory_order_relaxed); \
|
memory_order_relaxed); \
|
||||||
const unsigned int i = (iC & (table->size -1)); \
|
const unsigned int i = (iC & (table->size -1)); \
|
||||||
@@ -775,10 +775,10 @@ M_C(name, _init)(buffer_t v, size_t size) \
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _init)(buffer_t buffer, size_t size) \
|
M_C(name, _init)(buffer_t buffer, size_t size) \
|
||||||
{ \
|
{ \
|
||||||
assert (buffer != NULL); \
|
M_ASSERT (buffer != NULL); \
|
||||||
assert( M_POWEROF2_P(size)); \
|
M_ASSERT( M_POWEROF2_P(size)); \
|
||||||
assert (0 < size && size <= UINT_MAX); \
|
M_ASSERT (0 < size && size <= UINT_MAX); \
|
||||||
assert(((policy) & (BUFFER_STACK|BUFFER_THREAD_UNSAFE|BUFFER_PUSH_OVERWRITE)) == 0); \
|
M_ASSERT(((policy) & (BUFFER_STACK|BUFFER_THREAD_UNSAFE|BUFFER_PUSH_OVERWRITE)) == 0); \
|
||||||
atomic_init(&buffer->ProdIdx, (unsigned int) size); \
|
atomic_init(&buffer->ProdIdx, (unsigned int) size); \
|
||||||
atomic_init(&buffer->ConsoIdx, (unsigned int) size); \
|
atomic_init(&buffer->ConsoIdx, (unsigned int) size); \
|
||||||
buffer->size = (unsigned int) size; \
|
buffer->size = (unsigned int) size; \
|
||||||
@@ -886,13 +886,13 @@ M_C(name, _init)(buffer_t v, size_t size) \
|
|||||||
#define QUEUEI_SPSC_CONTRACT(table) do { } while (0)
|
#define QUEUEI_SPSC_CONTRACT(table) do { } while (0)
|
||||||
#else
|
#else
|
||||||
#define QUEUEI_SPSC_CONTRACT(table) do { \
|
#define QUEUEI_SPSC_CONTRACT(table) do { \
|
||||||
assert (table != NULL); \
|
M_ASSERT (table != NULL); \
|
||||||
unsigned int _r = atomic_load(&table->consoIdx); \
|
unsigned int _r = atomic_load(&table->consoIdx); \
|
||||||
unsigned int _w = atomic_load(&table->prodIdx); \
|
unsigned int _w = atomic_load(&table->prodIdx); \
|
||||||
/* Due to overflow we don't have assert (_r <= _w); */ \
|
/* Due to overflow we don't have M_ASSERT (_r <= _w); */ \
|
||||||
_r = atomic_load(&table->consoIdx); \
|
_r = atomic_load(&table->consoIdx); \
|
||||||
assert (_r > _w || _w-_r <= table->size); \
|
M_ASSERT (_r > _w || _w-_r <= table->size); \
|
||||||
assert (M_POWEROF2_P(table->size)); \
|
M_ASSERT (M_POWEROF2_P(table->size)); \
|
||||||
} while (0)
|
} while (0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -966,7 +966,7 @@ M_C(name, _init)(buffer_t v, size_t size) \
|
|||||||
M_C(name, _pop)(type *ptr, buffer_t table) \
|
M_C(name, _pop)(type *ptr, buffer_t table) \
|
||||||
{ \
|
{ \
|
||||||
QUEUEI_SPSC_CONTRACT(table); \
|
QUEUEI_SPSC_CONTRACT(table); \
|
||||||
assert (ptr != NULL); \
|
M_ASSERT (ptr != NULL); \
|
||||||
unsigned int w = atomic_load_explicit(&table->prodIdx, \
|
unsigned int w = atomic_load_explicit(&table->prodIdx, \
|
||||||
memory_order_relaxed); \
|
memory_order_relaxed); \
|
||||||
unsigned int r = atomic_load_explicit(&table->consoIdx, \
|
unsigned int r = atomic_load_explicit(&table->consoIdx, \
|
||||||
@@ -988,8 +988,8 @@ M_C(name, _init)(buffer_t v, size_t size) \
|
|||||||
M_C(name, _push_bulk)(buffer_t table, unsigned n, type const x[]) \
|
M_C(name, _push_bulk)(buffer_t table, unsigned n, type const x[]) \
|
||||||
{ \
|
{ \
|
||||||
QUEUEI_SPSC_CONTRACT(table); \
|
QUEUEI_SPSC_CONTRACT(table); \
|
||||||
assert (x != NULL); \
|
M_ASSERT (x != NULL); \
|
||||||
assert (n <= table->size); \
|
M_ASSERT (n <= table->size); \
|
||||||
unsigned int r = atomic_load_explicit(&table->consoIdx, \
|
unsigned int r = atomic_load_explicit(&table->consoIdx, \
|
||||||
memory_order_relaxed); \
|
memory_order_relaxed); \
|
||||||
unsigned int w = atomic_load_explicit(&table->prodIdx, \
|
unsigned int w = atomic_load_explicit(&table->prodIdx, \
|
||||||
@@ -1014,8 +1014,8 @@ M_C(name, _init)(buffer_t v, size_t size) \
|
|||||||
M_C(name, _pop_bulk)(unsigned int n, type ptr[], buffer_t table) \
|
M_C(name, _pop_bulk)(unsigned int n, type ptr[], buffer_t table) \
|
||||||
{ \
|
{ \
|
||||||
QUEUEI_SPSC_CONTRACT(table); \
|
QUEUEI_SPSC_CONTRACT(table); \
|
||||||
assert (ptr != NULL); \
|
M_ASSERT (ptr != NULL); \
|
||||||
assert (n <= table->size); \
|
M_ASSERT (n <= table->size); \
|
||||||
unsigned int w = atomic_load_explicit(&table->prodIdx, \
|
unsigned int w = atomic_load_explicit(&table->prodIdx, \
|
||||||
memory_order_relaxed); \
|
memory_order_relaxed); \
|
||||||
unsigned int r = atomic_load_explicit(&table->consoIdx, \
|
unsigned int r = atomic_load_explicit(&table->consoIdx, \
|
||||||
@@ -1101,10 +1101,10 @@ M_C(name, _init)(buffer_t v, size_t size) \
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _init)(buffer_t buffer, size_t size) \
|
M_C(name, _init)(buffer_t buffer, size_t size) \
|
||||||
{ \
|
{ \
|
||||||
assert (buffer != NULL); \
|
M_ASSERT (buffer != NULL); \
|
||||||
assert( M_POWEROF2_P(size)); \
|
M_ASSERT( M_POWEROF2_P(size)); \
|
||||||
assert (0 < size && size <= UINT_MAX); \
|
M_ASSERT (0 < size && size <= UINT_MAX); \
|
||||||
assert(((policy) & (BUFFER_STACK|BUFFER_THREAD_UNSAFE|BUFFER_PUSH_OVERWRITE)) == 0); \
|
M_ASSERT(((policy) & (BUFFER_STACK|BUFFER_THREAD_UNSAFE|BUFFER_PUSH_OVERWRITE)) == 0); \
|
||||||
atomic_init(&buffer->prodIdx, (unsigned int) size); \
|
atomic_init(&buffer->prodIdx, (unsigned int) size); \
|
||||||
atomic_init(&buffer->consoIdx, (unsigned int) size); \
|
atomic_init(&buffer->consoIdx, (unsigned int) size); \
|
||||||
buffer->size = (unsigned int) size; \
|
buffer->size = (unsigned int) size; \
|
||||||
|
|||||||
+31
-31
@@ -70,7 +70,7 @@ M_BEGIN_PROTECTED_CODE
|
|||||||
static inline M_C(name, _slist_node_ct) * \
|
static inline M_C(name, _slist_node_ct) * \
|
||||||
M_C(name, _slist_pop)(M_C(name, _slist_ct) list) \
|
M_C(name, _slist_pop)(M_C(name, _slist_ct) list) \
|
||||||
{ \
|
{ \
|
||||||
assert (*list != NULL); \
|
M_ASSERT (*list != NULL); \
|
||||||
M_C(name, _slist_node_ct) *node = *list; \
|
M_C(name, _slist_node_ct) *node = *list; \
|
||||||
*list = node->next; \
|
*list = node->next; \
|
||||||
M_IF_DEBUG(node->next = NULL;) \
|
M_IF_DEBUG(node->next = NULL;) \
|
||||||
@@ -404,7 +404,7 @@ M_BEGIN_PROTECTED_CODE
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _lfmp_thread_clear)(M_C(name, _lfmp_thread_ct) *t) \
|
M_C(name, _lfmp_thread_clear)(M_C(name, _lfmp_thread_ct) *t) \
|
||||||
{ \
|
{ \
|
||||||
assert(M_C(name, _slist_empty_p)(t->to_be_reclaimed)); \
|
M_ASSERT(M_C(name, _slist_empty_p)(t->to_be_reclaimed)); \
|
||||||
M_C(name, _slist_clear)(t->free); \
|
M_C(name, _slist_clear)(t->free); \
|
||||||
M_C(name, _slist_clear)(t->to_be_reclaimed); \
|
M_C(name, _slist_clear)(t->to_be_reclaimed); \
|
||||||
} \
|
} \
|
||||||
@@ -440,9 +440,9 @@ M_BEGIN_PROTECTED_CODE
|
|||||||
/* Fail to get an empty group of node. \
|
/* Fail to get an empty group of node. \
|
||||||
Alloc a new one from the system */ \
|
Alloc a new one from the system */ \
|
||||||
node = M_C(name, _alloc_node)(0); \
|
node = M_C(name, _alloc_node)(0); \
|
||||||
assert(node != NULL); \
|
M_ASSERT(node != NULL); \
|
||||||
} \
|
} \
|
||||||
assert(M_C(name, _slist_empty_p)(node->list)); \
|
M_ASSERT(M_C(name, _slist_empty_p)(node->list)); \
|
||||||
M_C(name, _slist_move)(node->list, mempool->thread_data[id].to_be_reclaimed); \
|
M_C(name, _slist_move)(node->list, mempool->thread_data[id].to_be_reclaimed); \
|
||||||
atomic_store_explicit(&node->cpt, ticket, memory_order_relaxed); \
|
atomic_store_explicit(&node->cpt, ticket, memory_order_relaxed); \
|
||||||
M_C(name, _lflist_push)(mempool->to_be_reclaimed, node, gc_mem->thread_data[id].bkoff); \
|
M_C(name, _lflist_push)(mempool->to_be_reclaimed, node, gc_mem->thread_data[id].bkoff); \
|
||||||
@@ -501,7 +501,7 @@ M_BEGIN_PROTECTED_CODE
|
|||||||
mem->thread_data = NULL; \
|
mem->thread_data = NULL; \
|
||||||
M_C(name, _lflist_clear)(mem->empty); \
|
M_C(name, _lflist_clear)(mem->empty); \
|
||||||
M_C(name, _lflist_clear)(mem->free); \
|
M_C(name, _lflist_clear)(mem->free); \
|
||||||
assert(M_C(name, _lflist_empty_p)(mem->to_be_reclaimed)); \
|
M_ASSERT(M_C(name, _lflist_empty_p)(mem->to_be_reclaimed)); \
|
||||||
M_C(name, _lflist_clear)(mem->to_be_reclaimed); \
|
M_C(name, _lflist_clear)(mem->to_be_reclaimed); \
|
||||||
/* TODO: Unregister from the GC? */ \
|
/* TODO: Unregister from the GC? */ \
|
||||||
} \
|
} \
|
||||||
@@ -521,14 +521,14 @@ M_BEGIN_PROTECTED_CODE
|
|||||||
node = M_C(name, _lflist_pop)(mem->free, mem->gc_mem->thread_data[id].bkoff); \
|
node = M_C(name, _lflist_pop)(mem->free, mem->gc_mem->thread_data[id].bkoff); \
|
||||||
if (M_UNLIKELY (node == NULL)) { \
|
if (M_UNLIKELY (node == NULL)) { \
|
||||||
/* Request a new group to the system. Non Lock Free path */ \
|
/* Request a new group to the system. Non Lock Free path */ \
|
||||||
assert(mem->initial > 0); \
|
M_ASSERT(mem->initial > 0); \
|
||||||
node = M_C(name, _alloc_node)(mem->initial); \
|
node = M_C(name, _alloc_node)(mem->initial); \
|
||||||
assert(node != NULL); \
|
M_ASSERT(node != NULL); \
|
||||||
assert(!M_C(name, _slist_empty_p)(node->list)); \
|
M_ASSERT(!M_C(name, _slist_empty_p)(node->list)); \
|
||||||
} \
|
} \
|
||||||
M_C(name, _slist_move)(mem->thread_data[id].free, node->list); \
|
M_C(name, _slist_move)(mem->thread_data[id].free, node->list); \
|
||||||
/* Push back the empty group */ \
|
/* Push back the empty group */ \
|
||||||
assert (M_C(name, _slist_empty_p)(node->list)); \
|
M_ASSERT (M_C(name, _slist_empty_p)(node->list)); \
|
||||||
M_C(name, _lflist_push)(mem->empty, node, mem->gc_mem->thread_data[id].bkoff); \
|
M_C(name, _lflist_push)(mem->empty, node, mem->gc_mem->thread_data[id].bkoff); \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
@@ -537,7 +537,7 @@ M_BEGIN_PROTECTED_CODE
|
|||||||
M_C(name, _del)(M_C(name, _t) mem, type_t *d, m_gc_tid_t id) \
|
M_C(name, _del)(M_C(name, _t) mem, type_t *d, m_gc_tid_t id) \
|
||||||
{ \
|
{ \
|
||||||
M_C(name, _slist_node_ct) *snode; \
|
M_C(name, _slist_node_ct) *snode; \
|
||||||
assert( d != NULL); \
|
M_ASSERT( d != NULL); \
|
||||||
snode = M_TYPE_FROM_FIELD(M_C(name, _slist_node_ct), d, type_t, data); \
|
snode = M_TYPE_FROM_FIELD(M_C(name, _slist_node_ct), d, type_t, data); \
|
||||||
M_C(name, _slist_push)(mem->thread_data[id].to_be_reclaimed, snode); \
|
M_C(name, _slist_push)(mem->thread_data[id].to_be_reclaimed, snode); \
|
||||||
} \
|
} \
|
||||||
@@ -582,8 +582,8 @@ typedef struct m_gc_s {
|
|||||||
static inline void
|
static inline void
|
||||||
m_gc_init(m_gc_t gc_mem, size_t max_thread)
|
m_gc_init(m_gc_t gc_mem, size_t max_thread)
|
||||||
{
|
{
|
||||||
assert(gc_mem != NULL);
|
M_ASSERT(gc_mem != NULL);
|
||||||
assert(max_thread > 0 && max_thread < INT_MAX);
|
M_ASSERT(max_thread > 0 && max_thread < INT_MAX);
|
||||||
|
|
||||||
atomic_init(&gc_mem->ticket, 0UL);
|
atomic_init(&gc_mem->ticket, 0UL);
|
||||||
genint_init(gc_mem->thread_alloc, (unsigned int) max_thread);
|
genint_init(gc_mem->thread_alloc, (unsigned int) max_thread);
|
||||||
@@ -603,7 +603,7 @@ m_gc_init(m_gc_t gc_mem, size_t max_thread)
|
|||||||
static inline void
|
static inline void
|
||||||
m_gc_clear(m_gc_t gc_mem)
|
m_gc_clear(m_gc_t gc_mem)
|
||||||
{
|
{
|
||||||
assert(gc_mem != NULL && gc_mem->max_thread > 0);
|
M_ASSERT(gc_mem != NULL && gc_mem->max_thread > 0);
|
||||||
|
|
||||||
for(m_gc_tid_t i = 0; i < gc_mem->max_thread;i++) {
|
for(m_gc_tid_t i = 0; i < gc_mem->max_thread;i++) {
|
||||||
m_core_backoff_clear(gc_mem->thread_data[i].bkoff);
|
m_core_backoff_clear(gc_mem->thread_data[i].bkoff);
|
||||||
@@ -616,7 +616,7 @@ m_gc_clear(m_gc_t gc_mem)
|
|||||||
static inline m_gc_tid_t
|
static inline m_gc_tid_t
|
||||||
m_gc_attach_thread(m_gc_t gc_mem)
|
m_gc_attach_thread(m_gc_t gc_mem)
|
||||||
{
|
{
|
||||||
assert(gc_mem != NULL && gc_mem->max_thread > 0);
|
M_ASSERT(gc_mem != NULL && gc_mem->max_thread > 0);
|
||||||
|
|
||||||
unsigned id = genint_pop(gc_mem->thread_alloc);
|
unsigned id = genint_pop(gc_mem->thread_alloc);
|
||||||
return M_ASSIGN_CAST(m_gc_tid_t, id);
|
return M_ASSIGN_CAST(m_gc_tid_t, id);
|
||||||
@@ -625,9 +625,9 @@ m_gc_attach_thread(m_gc_t gc_mem)
|
|||||||
static inline void
|
static inline void
|
||||||
m_gc_detach_thread(m_gc_t gc_mem, m_gc_tid_t id)
|
m_gc_detach_thread(m_gc_t gc_mem, m_gc_tid_t id)
|
||||||
{
|
{
|
||||||
assert(gc_mem != NULL && gc_mem->max_thread > 0);
|
M_ASSERT(gc_mem != NULL && gc_mem->max_thread > 0);
|
||||||
assert(id < gc_mem->max_thread);
|
M_ASSERT(id < gc_mem->max_thread);
|
||||||
assert(atomic_load(&gc_mem->thread_data[id].ticket) == ULONG_MAX);
|
M_ASSERT(atomic_load(&gc_mem->thread_data[id].ticket) == ULONG_MAX);
|
||||||
|
|
||||||
genint_push(gc_mem->thread_alloc, id);
|
genint_push(gc_mem->thread_alloc, id);
|
||||||
}
|
}
|
||||||
@@ -635,9 +635,9 @@ m_gc_detach_thread(m_gc_t gc_mem, m_gc_tid_t id)
|
|||||||
static inline void
|
static inline void
|
||||||
m_gc_awake(m_gc_t gc_mem, m_gc_tid_t id)
|
m_gc_awake(m_gc_t gc_mem, m_gc_tid_t id)
|
||||||
{
|
{
|
||||||
assert(gc_mem != NULL && gc_mem->max_thread > 0);
|
M_ASSERT(gc_mem != NULL && gc_mem->max_thread > 0);
|
||||||
assert(id < gc_mem->max_thread);
|
M_ASSERT(id < gc_mem->max_thread);
|
||||||
assert(atomic_load(&gc_mem->thread_data[id].ticket) == ULONG_MAX);
|
M_ASSERT(atomic_load(&gc_mem->thread_data[id].ticket) == ULONG_MAX);
|
||||||
|
|
||||||
m_gc_ticket_ct t = atomic_fetch_add(&gc_mem->ticket, 1UL) + 1;
|
m_gc_ticket_ct t = atomic_fetch_add(&gc_mem->ticket, 1UL) + 1;
|
||||||
atomic_store(&gc_mem->thread_data[id].ticket, t);
|
atomic_store(&gc_mem->thread_data[id].ticket, t);
|
||||||
@@ -699,7 +699,7 @@ m_vlapool_lfmp_thread_init(m_vlapool_lfmp_thread_ct *t)
|
|||||||
static inline void
|
static inline void
|
||||||
m_vlapool_lfmp_thread_clear(m_vlapool_lfmp_thread_ct *t)
|
m_vlapool_lfmp_thread_clear(m_vlapool_lfmp_thread_ct *t)
|
||||||
{
|
{
|
||||||
assert(m_vlapool_slist_empty_p(t->to_be_reclaimed));
|
M_ASSERT(m_vlapool_slist_empty_p(t->to_be_reclaimed));
|
||||||
m_vlapool_slist_clear(t->to_be_reclaimed);
|
m_vlapool_slist_clear(t->to_be_reclaimed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -729,9 +729,9 @@ m_vlapool_int_gc_on_sleep(m_gc_t gc_mem, m_gc_mempool_list_ct *data,
|
|||||||
/* Fail to get an empty group of node.
|
/* Fail to get an empty group of node.
|
||||||
Alloc a new one from the system */
|
Alloc a new one from the system */
|
||||||
node = m_vlapool_alloc_node(0);
|
node = m_vlapool_alloc_node(0);
|
||||||
assert(node != NULL);
|
M_ASSERT(node != NULL);
|
||||||
}
|
}
|
||||||
assert(m_vlapool_slist_empty_p(node->list));
|
M_ASSERT(m_vlapool_slist_empty_p(node->list));
|
||||||
m_vlapool_slist_move(node->list, vlapool->thread_data[id].to_be_reclaimed);
|
m_vlapool_slist_move(node->list, vlapool->thread_data[id].to_be_reclaimed);
|
||||||
atomic_store_explicit(&node->cpt, ticket, memory_order_relaxed);
|
atomic_store_explicit(&node->cpt, ticket, memory_order_relaxed);
|
||||||
m_vlapool_lflist_push(vlapool->to_be_reclaimed, node, gc_mem->thread_data[id].bkoff);
|
m_vlapool_lflist_push(vlapool->to_be_reclaimed, node, gc_mem->thread_data[id].bkoff);
|
||||||
@@ -787,7 +787,7 @@ m_vlapool_clear(m_vlapool_t mem)
|
|||||||
M_MEMORY_FREE(mem->thread_data);
|
M_MEMORY_FREE(mem->thread_data);
|
||||||
mem->thread_data = NULL;
|
mem->thread_data = NULL;
|
||||||
m_vlapool_lflist_clear(mem->empty);
|
m_vlapool_lflist_clear(mem->empty);
|
||||||
assert(m_vlapool_lflist_empty_p(mem->to_be_reclaimed));
|
M_ASSERT(m_vlapool_lflist_empty_p(mem->to_be_reclaimed));
|
||||||
m_vlapool_lflist_clear(mem->to_be_reclaimed);
|
m_vlapool_lflist_clear(mem->to_be_reclaimed);
|
||||||
/* TODO: Unregister from the GC? */
|
/* TODO: Unregister from the GC? */
|
||||||
}
|
}
|
||||||
@@ -795,9 +795,9 @@ m_vlapool_clear(m_vlapool_t mem)
|
|||||||
static inline void *
|
static inline void *
|
||||||
m_vlapool_new(m_vlapool_t mem, m_gc_tid_t id, size_t size)
|
m_vlapool_new(m_vlapool_t mem, m_gc_tid_t id, size_t size)
|
||||||
{
|
{
|
||||||
assert(mem != NULL && mem->gc_mem != NULL);
|
M_ASSERT(mem != NULL && mem->gc_mem != NULL);
|
||||||
assert(id < mem->gc_mem->max_thread);
|
M_ASSERT(id < mem->gc_mem->max_thread);
|
||||||
assert( atomic_load(&mem->gc_mem->thread_data[id].ticket) != ULONG_MAX);
|
M_ASSERT( atomic_load(&mem->gc_mem->thread_data[id].ticket) != ULONG_MAX);
|
||||||
|
|
||||||
// Nothing to do with theses parameters yet
|
// Nothing to do with theses parameters yet
|
||||||
(void) mem;
|
(void) mem;
|
||||||
@@ -814,10 +814,10 @@ m_vlapool_new(m_vlapool_t mem, m_gc_tid_t id, size_t size)
|
|||||||
static inline void
|
static inline void
|
||||||
m_vlapool_del(m_vlapool_t mem, void *d, m_gc_tid_t id)
|
m_vlapool_del(m_vlapool_t mem, void *d, m_gc_tid_t id)
|
||||||
{
|
{
|
||||||
assert(mem != NULL && mem->gc_mem != NULL);
|
M_ASSERT(mem != NULL && mem->gc_mem != NULL);
|
||||||
assert(id < mem->gc_mem->max_thread);
|
M_ASSERT(id < mem->gc_mem->max_thread);
|
||||||
assert(atomic_load(&mem->gc_mem->thread_data[id].ticket) != ULONG_MAX);
|
M_ASSERT(atomic_load(&mem->gc_mem->thread_data[id].ticket) != ULONG_MAX);
|
||||||
assert(d != NULL);
|
M_ASSERT(d != NULL);
|
||||||
|
|
||||||
// Get back the pointer to a struct m_vlapool_slist_node_s.
|
// Get back the pointer to a struct m_vlapool_slist_node_s.
|
||||||
d = M_ASSIGN_CAST(void *, M_ASSIGN_CAST(char *, d) - offsetof(struct m_vlapool_slist_node_s, data));
|
d = M_ASSIGN_CAST(void *, M_ASSIGN_CAST(char *, d) - offsetof(struct m_vlapool_slist_node_s, data));
|
||||||
|
|||||||
+17
-17
@@ -144,7 +144,7 @@
|
|||||||
Nothing notable. Can't check too much without locking the structure itself
|
Nothing notable. Can't check too much without locking the structure itself
|
||||||
*/
|
*/
|
||||||
#define CONCURRENTI_CONTRACT(c) do { \
|
#define CONCURRENTI_CONTRACT(c) do { \
|
||||||
assert ((c) != NULL); \
|
M_ASSERT ((c) != NULL); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
/* Deferred evaluation for the concurrent definition,
|
/* Deferred evaluation for the concurrent definition,
|
||||||
@@ -198,7 +198,7 @@
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _internal_clear)(concurrent_t out) \
|
M_C(name, _internal_clear)(concurrent_t out) \
|
||||||
{ \
|
{ \
|
||||||
assert (out->self == out); \
|
M_ASSERT (out->self == out); \
|
||||||
m_mutex_clear(out->lock); \
|
m_mutex_clear(out->lock); \
|
||||||
m_cond_clear(out->there_is_data); \
|
m_cond_clear(out->there_is_data); \
|
||||||
out->self = NULL; \
|
out->self = NULL; \
|
||||||
@@ -207,21 +207,21 @@
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _read_lock)(const concurrent_t out) \
|
M_C(name, _read_lock)(const concurrent_t out) \
|
||||||
{ \
|
{ \
|
||||||
assert (out->self == out); \
|
M_ASSERT (out->self == out); \
|
||||||
m_mutex_lock (out->self->lock); \
|
m_mutex_lock (out->self->lock); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _read_unlock)(const concurrent_t out) \
|
M_C(name, _read_unlock)(const concurrent_t out) \
|
||||||
{ \
|
{ \
|
||||||
assert (out->self == out); \
|
M_ASSERT (out->self == out); \
|
||||||
m_mutex_unlock (out->self->lock); \
|
m_mutex_unlock (out->self->lock); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _read_wait)(const concurrent_t out) \
|
M_C(name, _read_wait)(const concurrent_t out) \
|
||||||
{ \
|
{ \
|
||||||
assert (out->self == out); \
|
M_ASSERT (out->self == out); \
|
||||||
m_cond_wait(out->self->there_is_data, out->self->lock); \
|
m_cond_wait(out->self->there_is_data, out->self->lock); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
@@ -275,7 +275,7 @@
|
|||||||
M_C(name, _init_set)(concurrent_t out, concurrent_t const src) \
|
M_C(name, _init_set)(concurrent_t out, concurrent_t const src) \
|
||||||
{ \
|
{ \
|
||||||
CONCURRENTI_CONTRACT(src); \
|
CONCURRENTI_CONTRACT(src); \
|
||||||
assert (out != src); \
|
M_ASSERT (out != src); \
|
||||||
M_C(name, _internal_init)(out); \
|
M_C(name, _internal_init)(out); \
|
||||||
M_C(name, _read_lock)(src); \
|
M_C(name, _read_lock)(src); \
|
||||||
M_CALL_INIT_SET(oplist, out->data, src->data); \
|
M_CALL_INIT_SET(oplist, out->data, src->data); \
|
||||||
@@ -325,7 +325,7 @@
|
|||||||
M_C(name, _init_move)(concurrent_t out, concurrent_t src) \
|
M_C(name, _init_move)(concurrent_t out, concurrent_t src) \
|
||||||
{ \
|
{ \
|
||||||
CONCURRENTI_CONTRACT(src); \
|
CONCURRENTI_CONTRACT(src); \
|
||||||
assert (out != src); \
|
M_ASSERT (out != src); \
|
||||||
/* No need to lock 'src' ? */ \
|
/* No need to lock 'src' ? */ \
|
||||||
M_C(name, _internal_init)(out); \
|
M_C(name, _internal_init)(out); \
|
||||||
M_CALL_INIT_MOVE(oplist, out->data, src->data); \
|
M_CALL_INIT_MOVE(oplist, out->data, src->data); \
|
||||||
@@ -425,7 +425,7 @@
|
|||||||
M_C(name, _get_copy)(M_GET_VALUE_TYPE oplist *out_data, const concurrent_t out, M_GET_KEY_TYPE oplist const key) \
|
M_C(name, _get_copy)(M_GET_VALUE_TYPE oplist *out_data, const concurrent_t out, M_GET_KEY_TYPE oplist const key) \
|
||||||
{ \
|
{ \
|
||||||
CONCURRENTI_CONTRACT(out); \
|
CONCURRENTI_CONTRACT(out); \
|
||||||
assert (out_data != NULL); \
|
M_ASSERT (out_data != NULL); \
|
||||||
M_C(name, _read_lock)(out); \
|
M_C(name, _read_lock)(out); \
|
||||||
M_GET_VALUE_TYPE oplist *p = M_CALL_GET_KEY(oplist, out->data, key); \
|
M_GET_VALUE_TYPE oplist *p = M_CALL_GET_KEY(oplist, out->data, key); \
|
||||||
if (p != NULL) { \
|
if (p != NULL) { \
|
||||||
@@ -441,10 +441,10 @@
|
|||||||
M_C(name, _get_at_copy)(M_GET_VALUE_TYPE oplist *out_data, concurrent_t out, M_GET_KEY_TYPE oplist const key) \
|
M_C(name, _get_at_copy)(M_GET_VALUE_TYPE oplist *out_data, concurrent_t out, M_GET_KEY_TYPE oplist const key) \
|
||||||
{ \
|
{ \
|
||||||
CONCURRENTI_CONTRACT(out); \
|
CONCURRENTI_CONTRACT(out); \
|
||||||
assert (out_data != NULL); \
|
M_ASSERT (out_data != NULL); \
|
||||||
M_C(name, _write_lock)(out); \
|
M_C(name, _write_lock)(out); \
|
||||||
M_GET_VALUE_TYPE oplist *p = M_CALL_GET_SET_KEY(oplist, out->data, key); \
|
M_GET_VALUE_TYPE oplist *p = M_CALL_GET_SET_KEY(oplist, out->data, key); \
|
||||||
assert (p != NULL); \
|
M_ASSERT (p != NULL); \
|
||||||
M_CALL_SET(M_GET_VALUE_OPLIST oplist, *out_data, *p); \
|
M_CALL_SET(M_GET_VALUE_OPLIST oplist, *out_data, *p); \
|
||||||
M_C(name, _write_unlock)(out); \
|
M_C(name, _write_unlock)(out); \
|
||||||
} \
|
} \
|
||||||
@@ -612,7 +612,7 @@
|
|||||||
M_C(name, _get_blocking)(M_GET_VALUE_TYPE oplist *out_data, const concurrent_t out, M_GET_KEY_TYPE oplist const key, bool blocking) \
|
M_C(name, _get_blocking)(M_GET_VALUE_TYPE oplist *out_data, const concurrent_t out, M_GET_KEY_TYPE oplist const key, bool blocking) \
|
||||||
{ \
|
{ \
|
||||||
CONCURRENTI_CONTRACT(out); \
|
CONCURRENTI_CONTRACT(out); \
|
||||||
assert (out_data != NULL); \
|
M_ASSERT (out_data != NULL); \
|
||||||
bool ret = false; \
|
bool ret = false; \
|
||||||
M_C(name, _read_lock)(out); \
|
M_C(name, _read_lock)(out); \
|
||||||
while (true) { \
|
while (true) { \
|
||||||
@@ -635,7 +635,7 @@
|
|||||||
M_C(name, _pop_blocking)(M_GET_SUBTYPE oplist *p, concurrent_t out, bool blocking) \
|
M_C(name, _pop_blocking)(M_GET_SUBTYPE oplist *p, concurrent_t out, bool blocking) \
|
||||||
{ \
|
{ \
|
||||||
CONCURRENTI_CONTRACT(out); \
|
CONCURRENTI_CONTRACT(out); \
|
||||||
assert (p != NULL); \
|
M_ASSERT (p != NULL); \
|
||||||
bool ret = false; \
|
bool ret = false; \
|
||||||
M_C(name, _write_lock)(out); \
|
M_C(name, _write_lock)(out); \
|
||||||
while (true) { \
|
while (true) { \
|
||||||
@@ -657,7 +657,7 @@
|
|||||||
M_C(name, _pop_move_blocking)(M_GET_SUBTYPE oplist *p, concurrent_t out, bool blocking) \
|
M_C(name, _pop_move_blocking)(M_GET_SUBTYPE oplist *p, concurrent_t out, bool blocking) \
|
||||||
{ \
|
{ \
|
||||||
CONCURRENTI_CONTRACT(out); \
|
CONCURRENTI_CONTRACT(out); \
|
||||||
assert (p != NULL); \
|
M_ASSERT (p != NULL); \
|
||||||
bool ret = false; \
|
bool ret = false; \
|
||||||
M_C(name, _write_lock)(out); \
|
M_C(name, _write_lock)(out); \
|
||||||
while (true) { \
|
while (true) { \
|
||||||
@@ -738,7 +738,7 @@
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _internal_clear)(concurrent_t out) \
|
M_C(name, _internal_clear)(concurrent_t out) \
|
||||||
{ \
|
{ \
|
||||||
assert (out->self == out); \
|
M_ASSERT (out->self == out); \
|
||||||
m_mutex_clear(out->lock); \
|
m_mutex_clear(out->lock); \
|
||||||
m_cond_clear(out->rw_done); \
|
m_cond_clear(out->rw_done); \
|
||||||
m_cond_clear(out->there_is_data); \
|
m_cond_clear(out->there_is_data); \
|
||||||
@@ -749,7 +749,7 @@
|
|||||||
M_C(name, _read_lock)(const concurrent_t out) \
|
M_C(name, _read_lock)(const concurrent_t out) \
|
||||||
{ \
|
{ \
|
||||||
struct M_C(name, _s) *self = out->self; \
|
struct M_C(name, _s) *self = out->self; \
|
||||||
assert (self == out); \
|
M_ASSERT (self == out); \
|
||||||
m_mutex_lock (self->lock); \
|
m_mutex_lock (self->lock); \
|
||||||
while (self->writer_waiting == true) { \
|
while (self->writer_waiting == true) { \
|
||||||
m_cond_wait(self->rw_done, self->lock); \
|
m_cond_wait(self->rw_done, self->lock); \
|
||||||
@@ -762,7 +762,7 @@
|
|||||||
M_C(name, _read_unlock)(const concurrent_t out) \
|
M_C(name, _read_unlock)(const concurrent_t out) \
|
||||||
{ \
|
{ \
|
||||||
struct M_C(name, _s) *self = out->self; \
|
struct M_C(name, _s) *self = out->self; \
|
||||||
assert (self == out); \
|
M_ASSERT (self == out); \
|
||||||
m_mutex_lock (self->lock); \
|
m_mutex_lock (self->lock); \
|
||||||
self->read_count --; \
|
self->read_count --; \
|
||||||
if (self->read_count == 0) { \
|
if (self->read_count == 0) { \
|
||||||
@@ -798,7 +798,7 @@
|
|||||||
M_C(name, _read_wait)(const concurrent_t out) \
|
M_C(name, _read_wait)(const concurrent_t out) \
|
||||||
{ \
|
{ \
|
||||||
struct M_C(name, _s) *self = out->self; \
|
struct M_C(name, _s) *self = out->self; \
|
||||||
assert (self == out); \
|
M_ASSERT (self == out); \
|
||||||
m_mutex_lock (out->self->lock); \
|
m_mutex_lock (out->self->lock); \
|
||||||
self->read_count --; \
|
self->read_count --; \
|
||||||
if (self->read_count == 0) { \
|
if (self->read_count == 0) { \
|
||||||
|
|||||||
@@ -54,11 +54,11 @@
|
|||||||
#define M_CORE_VERSION_MINOR 4
|
#define M_CORE_VERSION_MINOR 4
|
||||||
#define M_CORE_VERSION_PATCHLEVEL 1
|
#define M_CORE_VERSION_PATCHLEVEL 1
|
||||||
|
|
||||||
/* M_ASSUME is equivalent to assert, but gives hints to compiler
|
/* M_ASSUME is equivalent to M_ASSERT, but gives hints to compiler
|
||||||
about how to optimize the code if NDEBUG is defined.
|
about how to optimize the code if NDEBUG is defined.
|
||||||
It is worth in very specific places usually. */
|
It is worth in very specific places usually. */
|
||||||
#if !defined(NDEBUG)
|
#if !defined(NDEBUG)
|
||||||
# define M_ASSUME(x) assert(x)
|
# define M_ASSUME(x) M_ASSERT(x)
|
||||||
#elif defined(__GNUC__) \
|
#elif defined(__GNUC__) \
|
||||||
&& (__GNUC__ * 100 + __GNUC_MINOR__) >= 408
|
&& (__GNUC__ * 100 + __GNUC_MINOR__) >= 408
|
||||||
# define M_ASSUME(x) \
|
# define M_ASSUME(x) \
|
||||||
@@ -67,7 +67,7 @@
|
|||||||
#elif defined(_MSC_VER)
|
#elif defined(_MSC_VER)
|
||||||
# define M_ASSUME(x) __assume(x)
|
# define M_ASSUME(x) __assume(x)
|
||||||
#else
|
#else
|
||||||
# define M_ASSUME(x) assert(x)
|
# define M_ASSUME(x) M_ASSERT(x)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* M_LIKELY / M_UNLIKELY gives hints on the compiler of the likehood
|
/* M_LIKELY / M_UNLIKELY gives hints on the compiler of the likehood
|
||||||
@@ -203,6 +203,145 @@
|
|||||||
|
|
||||||
M_BEGIN_PROTECTED_CODE
|
M_BEGIN_PROTECTED_CODE
|
||||||
|
|
||||||
|
/************************************************************/
|
||||||
|
/********************* MEMORY handling **********************/
|
||||||
|
/************************************************************/
|
||||||
|
|
||||||
|
/* Default MEMORY handling macros.
|
||||||
|
Can be overloaded by user code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Define a C and C++ version for default memory allocators.
|
||||||
|
Note: For C build, we explicitly don't cast the return value of
|
||||||
|
malloc, realloc as it is safer (compilers shall warn in case
|
||||||
|
of invalid implicit cast, whereas they won't if there is an
|
||||||
|
explicit cast) */
|
||||||
|
|
||||||
|
/* Define allocators for object:
|
||||||
|
* void *M_MEMORY_ALLOC(type): Return a pointer to a new object of type 'type'
|
||||||
|
* It returns NULL in case of memory allocation failure.
|
||||||
|
* void M_MEMORY_DEL(ptr): Free the object associated to the pointer.
|
||||||
|
*/
|
||||||
|
#ifndef M_MEMORY_ALLOC
|
||||||
|
#ifdef __cplusplus
|
||||||
|
# include <cstdlib>
|
||||||
|
# define M_MEMORY_ALLOC(type) ((type*)std::malloc (sizeof (type)))
|
||||||
|
# define M_MEMORY_DEL(ptr) std::free(ptr)
|
||||||
|
#else
|
||||||
|
# define M_MEMORY_ALLOC(type) malloc (sizeof (type))
|
||||||
|
# define M_MEMORY_DEL(ptr) free(ptr)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Define allocators for array
|
||||||
|
* void *M_MEMORY_REALLOC(type, ptr, n): Return a pointer to a new array of 'n' object of type 'type'
|
||||||
|
* If ptr is NULL, it creates a new array.
|
||||||
|
* If ptr is not null, it reallocates the given array to the new size.
|
||||||
|
* It returns NULL in case of memory allocation failure.
|
||||||
|
* void M_MEMORY_FREE(ptr): Free the object associated to the array.
|
||||||
|
*/
|
||||||
|
#ifndef M_MEMORY_REALLOC
|
||||||
|
#ifdef __cplusplus
|
||||||
|
# include <cstdlib>
|
||||||
|
# define M_MEMORY_REALLOC(type, ptr, n) \
|
||||||
|
((type*) (M_UNLIKELY ((n) > SIZE_MAX / sizeof(type)) ? NULL : std::realloc ((ptr), (n)*sizeof (type))))
|
||||||
|
# define M_MEMORY_FREE(ptr) std::free(ptr)
|
||||||
|
#else
|
||||||
|
# define M_MEMORY_REALLOC(type, ptr, n) (M_UNLIKELY ((n) > SIZE_MAX / sizeof(type)) ? NULL : realloc ((ptr), (n)*sizeof (type)))
|
||||||
|
# define M_MEMORY_FREE(ptr) free(ptr)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* This macro is called on memory allocation failure.
|
||||||
|
* By default, it aborts the program execution.
|
||||||
|
* NOTE: Can be overloaded by user code.
|
||||||
|
*/
|
||||||
|
#ifndef M_MEMORY_FULL
|
||||||
|
#define M_MEMORY_FULL(size) do { \
|
||||||
|
fprintf(stderr, "ERROR(M*LIB): Cannot allocate %zu bytes of memory at (%s:%s:%d).\n", \
|
||||||
|
(size_t) (size), __FILE__, __func__, __LINE__); \
|
||||||
|
abort(); \
|
||||||
|
} while (0)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/************************************************************/
|
||||||
|
/********************* ERROR handling **********************/
|
||||||
|
/************************************************************/
|
||||||
|
|
||||||
|
/* Define the default assertion macro used by M*LIB.
|
||||||
|
By default, it is an encapsulation of CLIB assert.
|
||||||
|
* NOTE: Can be overiden by user if it needs to keep finer access
|
||||||
|
* on the assertions.
|
||||||
|
*/
|
||||||
|
#ifndef M_ASSERT
|
||||||
|
#define M_ASSERT(expr) assert(expr)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* Always perform a runtime check of the given condition
|
||||||
|
* NOTE: Can be overiden by user if it needs to keep finer access
|
||||||
|
* on the assertions or display message on another device.
|
||||||
|
*/
|
||||||
|
#ifndef M_ASSERT_INIT
|
||||||
|
#define M_ASSERT_INIT(expr, object) { \
|
||||||
|
if (!(expr)) { \
|
||||||
|
fprintf(stderr, "ERROR(M*LIB): Cannot initialize %s at (%s:%s:%d): %s\n", \
|
||||||
|
(object), __FILE__, __func__, __LINE__, #expr); \
|
||||||
|
abort(); \
|
||||||
|
} } while (0)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* Define an assertion check on an index, compared to its maximum.
|
||||||
|
* The index is supposed to be unsigned.
|
||||||
|
* It is only used to valid user input, not an intermediary calculus.
|
||||||
|
* NOTE: Can be overiden by user if it needs to keep access under control
|
||||||
|
* even on release mode */
|
||||||
|
#ifndef M_ASSERT_INDEX
|
||||||
|
#define M_ASSERT_INDEX(index, max) do { \
|
||||||
|
M_ASSERT((index) < (max)); \
|
||||||
|
} while (0)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* Terminate the compilation of the current unit with an error message.
|
||||||
|
The error is classidied as error
|
||||||
|
with an optional message detailling the error.
|
||||||
|
Either use C11 to get a proper message, or at least a good hint in C99.
|
||||||
|
error shall be a C name, msg a string.
|
||||||
|
Quite usefull to terminate with a proper error message rather than
|
||||||
|
a garbage of error due to incorrect code generation in the methods
|
||||||
|
expansion.
|
||||||
|
*/
|
||||||
|
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
|
||||||
|
# define M_STATIC_FAILURE(error, msg) static_assert(false, #error ": " msg);
|
||||||
|
#else
|
||||||
|
# define M_STATIC_FAILURE(error, msg) struct error { int error : 0;};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* Test at compile time if the given condition is true.
|
||||||
|
The error is classidied as error
|
||||||
|
with an optional message detailling the error.
|
||||||
|
NOTE: Use bitfield to be compatible with most compilers
|
||||||
|
(so that it properly displays 'error' on the command line
|
||||||
|
NOTE: Cannot use C11 Static Assert as is not usable in expression.
|
||||||
|
NOTE: In C++, use of lambda to encapsulate static_assert in
|
||||||
|
an expression.
|
||||||
|
*/
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
# define M_STATIC_ASSERT(cond, error, msg) \
|
||||||
|
([] { static_assert(cond, #error ": " msg); } ())
|
||||||
|
#elif defined(__GNUC__) && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
|
||||||
|
# define M_STATIC_ASSERT(cond, error, msg) \
|
||||||
|
M_ATTR_EXTENSION ({ static_assert(cond, #error ": " msg); })
|
||||||
|
#else
|
||||||
|
# define M_STATIC_ASSERT(cond, error, msg) \
|
||||||
|
((void) sizeof(struct { int error : !!(cond);}))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
/****************** Preprocessing Times Macro ******************/
|
/****************** Preprocessing Times Macro ******************/
|
||||||
/***************************************************************/
|
/***************************************************************/
|
||||||
@@ -1904,12 +2043,12 @@ M_PARSE_DEFAULT_TYPE_DEF(m_core_parse_ldouble, long double, strtold, )
|
|||||||
*/
|
*/
|
||||||
static inline uint32_t m_core_rotl32a (uint32_t x, uint32_t n)
|
static inline uint32_t m_core_rotl32a (uint32_t x, uint32_t n)
|
||||||
{
|
{
|
||||||
assert (n > 0 && n<32);
|
M_ASSERT (n > 0 && n<32);
|
||||||
return (x<<n) | (x>>(32-n));
|
return (x<<n) | (x>>(32-n));
|
||||||
}
|
}
|
||||||
static inline uint64_t m_core_rotl64a (uint64_t x, uint32_t n)
|
static inline uint64_t m_core_rotl64a (uint64_t x, uint32_t n)
|
||||||
{
|
{
|
||||||
assert (n > 0 && n<64);
|
M_ASSERT (n > 0 && n<64);
|
||||||
return (x<<n) | (x>>(64-n));
|
return (x<<n) | (x>>(64-n));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2025,8 +2164,8 @@ m_core_hash (const void *str, size_t length)
|
|||||||
uint32_t hash32 = 2166136261U ^ M_HASH_SEED;
|
uint32_t hash32 = 2166136261U ^ M_HASH_SEED;
|
||||||
const uint8_t *p = (const uint8_t *)str;
|
const uint8_t *p = (const uint8_t *)str;
|
||||||
|
|
||||||
assert (str != NULL || length == 0);
|
M_ASSERT (str != NULL || length == 0);
|
||||||
assert ( (( (uintptr_t)p & (sizeof(uint32_t)-1) ) == 0) || (length <= sizeof(uint32_t)));
|
M_ASSERT ( (( (uintptr_t)p & (sizeof(uint32_t)-1) ) == 0) || (length <= sizeof(uint32_t)));
|
||||||
|
|
||||||
while (length >= 2*sizeof(uint32_t)) {
|
while (length >= 2*sizeof(uint32_t)) {
|
||||||
const uint32_t *ptr = (const uint32_t *) (uintptr_t) p;
|
const uint32_t *ptr = (const uint32_t *) (uintptr_t) p;
|
||||||
@@ -2058,8 +2197,8 @@ m_core_hash (const void *str, size_t length)
|
|||||||
uint64_t hash64 = 14695981039346656037ULL ^ M_HASH_SEED;
|
uint64_t hash64 = 14695981039346656037ULL ^ M_HASH_SEED;
|
||||||
const uint8_t *p = M_ASSIGN_CAST(const uint8_t *, str);
|
const uint8_t *p = M_ASSIGN_CAST(const uint8_t *, str);
|
||||||
|
|
||||||
assert (str != NULL || length == 0);
|
M_ASSERT (str != NULL || length == 0);
|
||||||
assert ( (( (uintptr_t)p & (sizeof(uint64_t)-1) ) == 0) || (length <= sizeof(uint32_t)));
|
M_ASSERT ( (( (uintptr_t)p & (sizeof(uint64_t)-1) ) == 0) || (length <= sizeof(uint32_t)));
|
||||||
|
|
||||||
while (length >= 2*sizeof(uint64_t)) {
|
while (length >= 2*sizeof(uint64_t)) {
|
||||||
const uint64_t *ptr = (const uint64_t *) (uintptr_t) p;
|
const uint64_t *ptr = (const uint64_t *) (uintptr_t) p;
|
||||||
@@ -2978,132 +3117,6 @@ m_core_parse2_enum (const char str[], const char **endptr)
|
|||||||
M_PAIR_2 d (M_PAIR_1 d, M_PAIR_1 a, M_PAIR_2 a)
|
M_PAIR_2 d (M_PAIR_1 d, M_PAIR_1 a, M_PAIR_2 a)
|
||||||
|
|
||||||
|
|
||||||
/************************************************************/
|
|
||||||
/********************* MEMORY handling **********************/
|
|
||||||
/************************************************************/
|
|
||||||
|
|
||||||
/* Default MEMORY handling macros.
|
|
||||||
Can be overloaded by user code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* Define a C and C++ version for default memory allocators.
|
|
||||||
Note: For C build, we explicitly don't cast the return value of
|
|
||||||
malloc, realloc as it is safer (compilers shall warn in case
|
|
||||||
of invalid implicit cast, whereas they won't if there is an
|
|
||||||
explicit cast) */
|
|
||||||
|
|
||||||
/* Define allocators for object:
|
|
||||||
* void *M_MEMORY_ALLOC(type): Return a pointer to a new object of type 'type'
|
|
||||||
* It returns NULL in case of memory allocation failure.
|
|
||||||
* void M_MEMORY_DEL(ptr): Free the object associated to the pointer.
|
|
||||||
*/
|
|
||||||
#ifndef M_MEMORY_ALLOC
|
|
||||||
#ifdef __cplusplus
|
|
||||||
# include <cstdlib>
|
|
||||||
# define M_MEMORY_ALLOC(type) ((type*)std::malloc (sizeof (type)))
|
|
||||||
# define M_MEMORY_DEL(ptr) std::free(ptr)
|
|
||||||
#else
|
|
||||||
# define M_MEMORY_ALLOC(type) malloc (sizeof (type))
|
|
||||||
# define M_MEMORY_DEL(ptr) free(ptr)
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Define allocators for array
|
|
||||||
* void *M_MEMORY_REALLOC(type, ptr, n): Return a pointer to a new array of 'n' object of type 'type'
|
|
||||||
* If ptr is NULL, it creates a new array.
|
|
||||||
* If ptr is not null, it reallocates the given array to the new size.
|
|
||||||
* It returns NULL in case of memory allocation failure.
|
|
||||||
* void M_MEMORY_FREE(ptr): Free the object associated to the array.
|
|
||||||
*/
|
|
||||||
#ifndef M_MEMORY_REALLOC
|
|
||||||
#ifdef __cplusplus
|
|
||||||
# include <cstdlib>
|
|
||||||
# define M_MEMORY_REALLOC(type, ptr, n) \
|
|
||||||
((type*) (M_UNLIKELY ((n) > SIZE_MAX / sizeof(type)) ? NULL : std::realloc ((ptr), (n)*sizeof (type))))
|
|
||||||
# define M_MEMORY_FREE(ptr) std::free(ptr)
|
|
||||||
#else
|
|
||||||
# define M_MEMORY_REALLOC(type, ptr, n) (M_UNLIKELY ((n) > SIZE_MAX / sizeof(type)) ? NULL : realloc ((ptr), (n)*sizeof (type)))
|
|
||||||
# define M_MEMORY_FREE(ptr) free(ptr)
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* This macro is called on memory allocation failure.
|
|
||||||
* By default, it aborts the program execution.
|
|
||||||
* NOTE: Can be overloaded by user code.
|
|
||||||
*/
|
|
||||||
#ifndef M_MEMORY_FULL
|
|
||||||
#define M_MEMORY_FULL(size) do { \
|
|
||||||
fprintf(stderr, "ERROR(M*LIB): Cannot allocate %zu bytes of memory at (%s:%s:%d).\n", \
|
|
||||||
(size_t) (size), __FILE__, __func__, __LINE__); \
|
|
||||||
abort(); \
|
|
||||||
} while (0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/************************************************************/
|
|
||||||
/********************* ERROR handling **********************/
|
|
||||||
/************************************************************/
|
|
||||||
|
|
||||||
/* Always perform a runtime check of the given condition */
|
|
||||||
#ifndef M_ASSERT_INIT
|
|
||||||
#define M_ASSERT_INIT(expr, object) { \
|
|
||||||
if (!(expr)) { \
|
|
||||||
fprintf(stderr, "ERROR(M*LIB): Cannot initialize %s at (%s:%s:%d): %s\n", \
|
|
||||||
(object), __FILE__, __func__, __LINE__, #expr); \
|
|
||||||
abort(); \
|
|
||||||
} } while (0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/* Define an assertion check on an index, compared to its maximum.
|
|
||||||
* The index is supposed to be unsigned.
|
|
||||||
* It is only used to valid user input, not an intermediary calculus.
|
|
||||||
* NOTE: Can be overiden by user if it needs to keep access under control
|
|
||||||
* even on release mode */
|
|
||||||
#ifndef M_ASSERT_INDEX
|
|
||||||
#define M_ASSERT_INDEX(index, max) do { \
|
|
||||||
assert(index < max); \
|
|
||||||
} while (0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/* Terminate the compilation of the current unit with an error message.
|
|
||||||
The error is classidied as error
|
|
||||||
with an optional message detailling the error.
|
|
||||||
Either use C11 to get a proper message, or at least a good hint in C99.
|
|
||||||
error shall be a C name, msg a string.
|
|
||||||
Quite usefull to terminate with a proper error message rather than
|
|
||||||
a garbage of error due to incorrect code generation in the methods
|
|
||||||
expansion.
|
|
||||||
*/
|
|
||||||
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
|
|
||||||
# define M_STATIC_FAILURE(error, msg) static_assert(false, #error ": " msg);
|
|
||||||
#else
|
|
||||||
# define M_STATIC_FAILURE(error, msg) struct error { int error : 0;};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/* Test at compile time if the given condition is true.
|
|
||||||
The error is classidied as error
|
|
||||||
with an optional message detailling the error.
|
|
||||||
NOTE: Use bitfield to be compatible with most compilers
|
|
||||||
(so that it properly displays 'error' on the command line
|
|
||||||
NOTE: Cannot use C11 Static Assert as is not usable in expression.
|
|
||||||
NOTE: In C++, use of lambda to encapsulate static_assert in
|
|
||||||
an expression.
|
|
||||||
*/
|
|
||||||
#if defined(__cplusplus)
|
|
||||||
# define M_STATIC_ASSERT(cond, error, msg) \
|
|
||||||
([] { static_assert(cond, #error ": " msg); } ())
|
|
||||||
#elif defined(__GNUC__) && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
|
|
||||||
# define M_STATIC_ASSERT(cond, error, msg) \
|
|
||||||
M_ATTR_EXTENSION ({ static_assert(cond, #error ": " msg); })
|
|
||||||
#else
|
|
||||||
# define M_STATIC_ASSERT(cond, error, msg) \
|
|
||||||
((void) sizeof(struct { int error : !!(cond);}))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/************************************************************/
|
/************************************************************/
|
||||||
/******************* Exponential Backoff ********************/
|
/******************* Exponential Backoff ********************/
|
||||||
/************************************************************/
|
/************************************************************/
|
||||||
@@ -3399,7 +3412,7 @@ m_core_in_serial_enum(m_serial_read_t serial)
|
|||||||
static inline size_t
|
static inline size_t
|
||||||
m_core_out_serial_strlen(const char s[])
|
m_core_out_serial_strlen(const char s[])
|
||||||
{
|
{
|
||||||
assert(s != NULL);
|
M_ASSERT(s != NULL);
|
||||||
return strlen(s);
|
return strlen(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -64,15 +64,15 @@
|
|||||||
|
|
||||||
/* Define the internal contract of a deque */
|
/* Define the internal contract of a deque */
|
||||||
#define DEQUEI_CONTRACT(d) do { \
|
#define DEQUEI_CONTRACT(d) do { \
|
||||||
assert ((d) != NULL); \
|
M_ASSERT ((d) != NULL); \
|
||||||
assert ((d)->default_size >= DEQUEUI_DEFAULT_SIZE); \
|
M_ASSERT ((d)->default_size >= DEQUEUI_DEFAULT_SIZE); \
|
||||||
assert ((d)->front->node != NULL); \
|
M_ASSERT ((d)->front->node != NULL); \
|
||||||
assert ((d)->front->index <= (d)->front->node->size); \
|
M_ASSERT ((d)->front->index <= (d)->front->node->size); \
|
||||||
assert ((d)->back->node != NULL); \
|
M_ASSERT ((d)->back->node != NULL); \
|
||||||
assert ((d)->back->index <= (d)->back->node->size); \
|
M_ASSERT ((d)->back->index <= (d)->back->node->size); \
|
||||||
assert ((d)->front->node != (d)->back->node || \
|
M_ASSERT ((d)->front->node != (d)->back->node || \
|
||||||
(d)->front->index <= (d)->back->index); \
|
(d)->front->index <= (d)->back->index); \
|
||||||
assert ((d)->front->node != (d)->back->node || \
|
M_ASSERT ((d)->front->node != (d)->back->node || \
|
||||||
(d)->back->index - (d)->front->index == (d)->count); \
|
(d)->back->index - (d)->front->index == (d)->count); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
@@ -219,7 +219,7 @@
|
|||||||
} \
|
} \
|
||||||
min_node = (min_node == NULL || min_node->size > n->size) ? n : min_node; \
|
min_node = (min_node == NULL || min_node->size > n->size) ? n : min_node; \
|
||||||
} \
|
} \
|
||||||
assert (min_node != NULL); \
|
M_ASSERT (min_node != NULL); \
|
||||||
d->front->node = min_node; \
|
d->front->node = min_node; \
|
||||||
d->front->index = min_node->size / 2; \
|
d->front->index = min_node->size / 2; \
|
||||||
d->back->node = min_node; \
|
d->back->node = min_node; \
|
||||||
@@ -291,7 +291,7 @@
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _push_back_move)(deque_t d, type *x) \
|
M_C(name, _push_back_move)(deque_t d, type *x) \
|
||||||
{ \
|
{ \
|
||||||
assert (x != NULL); \
|
M_ASSERT (x != NULL); \
|
||||||
type *p = M_C(name, _push_back_raw)(d); \
|
type *p = M_C(name, _push_back_raw)(d); \
|
||||||
if (M_UNLIKELY(p == NULL)) \
|
if (M_UNLIKELY(p == NULL)) \
|
||||||
return; \
|
return; \
|
||||||
@@ -347,7 +347,7 @@
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _push_front_move)(deque_t d, type *x) \
|
M_C(name, _push_front_move)(deque_t d, type *x) \
|
||||||
{ \
|
{ \
|
||||||
assert (x != NULL); \
|
M_ASSERT (x != NULL); \
|
||||||
type *p = M_C(name, _push_front_raw)(d); \
|
type *p = M_C(name, _push_front_raw)(d); \
|
||||||
if (M_UNLIKELY(p == NULL)) \
|
if (M_UNLIKELY(p == NULL)) \
|
||||||
return; \
|
return; \
|
||||||
@@ -358,7 +358,7 @@
|
|||||||
M_C(name, _pop_back)(type *ptr, deque_t d) \
|
M_C(name, _pop_back)(type *ptr, deque_t d) \
|
||||||
{ \
|
{ \
|
||||||
DEQUEI_CONTRACT(d); \
|
DEQUEI_CONTRACT(d); \
|
||||||
assert(d->count > 0); \
|
M_ASSERT(d->count > 0); \
|
||||||
node_t *n = d->back->node; \
|
node_t *n = d->back->node; \
|
||||||
size_t index = d->back->index; \
|
size_t index = d->back->index; \
|
||||||
index --; \
|
index --; \
|
||||||
@@ -369,11 +369,11 @@
|
|||||||
node_t *next = M_C(name, _node_list_next_obj)(d->list, n); \
|
node_t *next = M_C(name, _node_list_next_obj)(d->list, n); \
|
||||||
if (next != NULL) { \
|
if (next != NULL) { \
|
||||||
next = M_C(name, _node_list_pop_back)(d->list); \
|
next = M_C(name, _node_list_pop_back)(d->list); \
|
||||||
assert (next != n); \
|
M_ASSERT (next != n); \
|
||||||
M_C(name, _node_list_push_front)(d->list, next); \
|
M_C(name, _node_list_push_front)(d->list, next); \
|
||||||
} \
|
} \
|
||||||
n = M_C(name, _node_list_previous_obj)(d->list, n); \
|
n = M_C(name, _node_list_previous_obj)(d->list, n); \
|
||||||
assert (n != NULL); \
|
M_ASSERT (n != NULL); \
|
||||||
d->back->node = n; \
|
d->back->node = n; \
|
||||||
index = n->size-1; \
|
index = n->size-1; \
|
||||||
} \
|
} \
|
||||||
@@ -393,7 +393,7 @@
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _pop_back_move)(type *ptr, deque_t d) \
|
M_C(name, _pop_back_move)(type *ptr, deque_t d) \
|
||||||
{ \
|
{ \
|
||||||
assert(ptr != NULL); \
|
M_ASSERT(ptr != NULL); \
|
||||||
/* Note: Lazy implementation. Can be improved if needed */ \
|
/* Note: Lazy implementation. Can be improved if needed */ \
|
||||||
M_CALL_INIT(oplist, *ptr); \
|
M_CALL_INIT(oplist, *ptr); \
|
||||||
M_C(name, _pop_back)(ptr, d); \
|
M_C(name, _pop_back)(ptr, d); \
|
||||||
@@ -404,7 +404,7 @@
|
|||||||
M_C(name, _pop_front)(type *ptr, deque_t d) \
|
M_C(name, _pop_front)(type *ptr, deque_t d) \
|
||||||
{ \
|
{ \
|
||||||
DEQUEI_CONTRACT(d); \
|
DEQUEI_CONTRACT(d); \
|
||||||
assert(d->count > 0); \
|
M_ASSERT(d->count > 0); \
|
||||||
node_t *n = d->front->node; \
|
node_t *n = d->front->node; \
|
||||||
size_t index = d->front->index; \
|
size_t index = d->front->index; \
|
||||||
if (M_UNLIKELY (n->size <= index)) { \
|
if (M_UNLIKELY (n->size <= index)) { \
|
||||||
@@ -414,11 +414,11 @@
|
|||||||
node_t *prev = M_C(name, _node_list_previous_obj)(d->list, n); \
|
node_t *prev = M_C(name, _node_list_previous_obj)(d->list, n); \
|
||||||
if (prev != NULL) { \
|
if (prev != NULL) { \
|
||||||
prev = M_C(name, _node_list_pop_front)(d->list); \
|
prev = M_C(name, _node_list_pop_front)(d->list); \
|
||||||
assert (prev != n); \
|
M_ASSERT (prev != n); \
|
||||||
M_C(name, _node_list_push_back)(d->list, prev); \
|
M_C(name, _node_list_push_back)(d->list, prev); \
|
||||||
} \
|
} \
|
||||||
n = M_C(name, _node_list_next_obj)(d->list, n); \
|
n = M_C(name, _node_list_next_obj)(d->list, n); \
|
||||||
assert (n != NULL); \
|
M_ASSERT (n != NULL); \
|
||||||
d->front->node = n; \
|
d->front->node = n; \
|
||||||
index = 0; \
|
index = 0; \
|
||||||
} \
|
} \
|
||||||
@@ -438,7 +438,7 @@
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _pop_front_move)(type *ptr, deque_t d) \
|
M_C(name, _pop_front_move)(type *ptr, deque_t d) \
|
||||||
{ \
|
{ \
|
||||||
assert(ptr != NULL); \
|
M_ASSERT(ptr != NULL); \
|
||||||
/* Note: Lazy implementation */ \
|
/* Note: Lazy implementation */ \
|
||||||
M_CALL_INIT(oplist, *ptr); \
|
M_CALL_INIT(oplist, *ptr); \
|
||||||
M_C(name, _pop_front)(ptr, d); \
|
M_C(name, _pop_front)(ptr, d); \
|
||||||
@@ -449,12 +449,12 @@
|
|||||||
M_C(name, _back)(const deque_t d) \
|
M_C(name, _back)(const deque_t d) \
|
||||||
{ \
|
{ \
|
||||||
DEQUEI_CONTRACT(d); \
|
DEQUEI_CONTRACT(d); \
|
||||||
assert (d->count > 0); \
|
M_ASSERT (d->count > 0); \
|
||||||
size_t i = d->back->index; \
|
size_t i = d->back->index; \
|
||||||
node_t *n = d->back->node; \
|
node_t *n = d->back->node; \
|
||||||
if (M_UNLIKELY (i == 0)) { \
|
if (M_UNLIKELY (i == 0)) { \
|
||||||
n = M_C(name, _node_list_previous_obj)(d->list, n); \
|
n = M_C(name, _node_list_previous_obj)(d->list, n); \
|
||||||
assert (n != NULL); \
|
M_ASSERT (n != NULL); \
|
||||||
i = n->size; \
|
i = n->size; \
|
||||||
} \
|
} \
|
||||||
return &n->data[i-1]; \
|
return &n->data[i-1]; \
|
||||||
@@ -464,12 +464,12 @@
|
|||||||
M_C(name, _front)(const deque_t d) \
|
M_C(name, _front)(const deque_t d) \
|
||||||
{ \
|
{ \
|
||||||
DEQUEI_CONTRACT(d); \
|
DEQUEI_CONTRACT(d); \
|
||||||
assert (d->count > 0); \
|
M_ASSERT (d->count > 0); \
|
||||||
size_t i = d->front->index; \
|
size_t i = d->front->index; \
|
||||||
node_t *n = d->front->node; \
|
node_t *n = d->front->node; \
|
||||||
if (M_UNLIKELY (n->size <= i)) { \
|
if (M_UNLIKELY (n->size <= i)) { \
|
||||||
n = M_C(name, _node_list_next_obj)(d->list, n); \
|
n = M_C(name, _node_list_next_obj)(d->list, n); \
|
||||||
assert (n != NULL); \
|
M_ASSERT (n != NULL); \
|
||||||
i = 0; \
|
i = 0; \
|
||||||
} \
|
} \
|
||||||
return &n->data[i]; \
|
return &n->data[i]; \
|
||||||
@@ -527,7 +527,7 @@
|
|||||||
M_C(name, _it)(it_t it, const deque_t d) \
|
M_C(name, _it)(it_t it, const deque_t d) \
|
||||||
{ \
|
{ \
|
||||||
DEQUEI_CONTRACT(d); \
|
DEQUEI_CONTRACT(d); \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
it->node = d->front->node; \
|
it->node = d->front->node; \
|
||||||
it->index = d->front->index; \
|
it->index = d->front->index; \
|
||||||
it->deque = d; \
|
it->deque = d; \
|
||||||
@@ -537,13 +537,13 @@
|
|||||||
M_C(name, _it_last)(it_t it, const deque_t d) \
|
M_C(name, _it_last)(it_t it, const deque_t d) \
|
||||||
{ \
|
{ \
|
||||||
DEQUEI_CONTRACT(d); \
|
DEQUEI_CONTRACT(d); \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
it->node = d->back->node; \
|
it->node = d->back->node; \
|
||||||
it->index = d->back->index - 1; \
|
it->index = d->back->index - 1; \
|
||||||
it->deque = d; \
|
it->deque = d; \
|
||||||
if (M_UNLIKELY (it->index >= it->node->size)) { \
|
if (M_UNLIKELY (it->index >= it->node->size)) { \
|
||||||
it->node = M_C(name, _node_list_previous_obj)(d->list, it->node); \
|
it->node = M_C(name, _node_list_previous_obj)(d->list, it->node); \
|
||||||
assert (it->node != NULL); \
|
M_ASSERT (it->node != NULL); \
|
||||||
it->index = it->node->size-1; \
|
it->index = it->node->size-1; \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
@@ -552,7 +552,7 @@
|
|||||||
M_C(name, _it_end)(it_t it, const deque_t d) \
|
M_C(name, _it_end)(it_t it, const deque_t d) \
|
||||||
{ \
|
{ \
|
||||||
DEQUEI_CONTRACT(d); \
|
DEQUEI_CONTRACT(d); \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
it->node = d->back->node; \
|
it->node = d->back->node; \
|
||||||
it->index = d->back->index; \
|
it->index = d->back->index; \
|
||||||
it->deque = d; \
|
it->deque = d; \
|
||||||
@@ -561,8 +561,8 @@
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _it_set)(it_t it1, const it_t it2) \
|
M_C(name, _it_set)(it_t it1, const it_t it2) \
|
||||||
{ \
|
{ \
|
||||||
assert (it1 != NULL); \
|
M_ASSERT (it1 != NULL); \
|
||||||
assert (it2 != NULL); \
|
M_ASSERT (it2 != NULL); \
|
||||||
it1->node = it2->node; \
|
it1->node = it2->node; \
|
||||||
it1->index = it2->index; \
|
it1->index = it2->index; \
|
||||||
it1->deque = it2->deque; \
|
it1->deque = it2->deque; \
|
||||||
@@ -571,7 +571,7 @@
|
|||||||
static inline bool \
|
static inline bool \
|
||||||
M_C(name, _end_p)(it_t it) \
|
M_C(name, _end_p)(it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
return (it->node == it->deque->back->node \
|
return (it->node == it->deque->back->node \
|
||||||
&& it->index >= it->deque->back->index) \
|
&& it->index >= it->deque->back->index) \
|
||||||
|| (it->node == it->deque->front->node \
|
|| (it->node == it->deque->front->node \
|
||||||
@@ -581,7 +581,7 @@
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _next)(it_t it) \
|
M_C(name, _next)(it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
node_t *n = it->node; \
|
node_t *n = it->node; \
|
||||||
it->index ++; \
|
it->index ++; \
|
||||||
if (M_UNLIKELY (it->index >= n->size)) { \
|
if (M_UNLIKELY (it->index >= n->size)) { \
|
||||||
@@ -600,7 +600,7 @@
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _previous)(it_t it) \
|
M_C(name, _previous)(it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
node_t *n = it->node; \
|
node_t *n = it->node; \
|
||||||
it->index --; \
|
it->index --; \
|
||||||
if (M_UNLIKELY (it->index >= n->size)) { \
|
if (M_UNLIKELY (it->index >= n->size)) { \
|
||||||
@@ -619,7 +619,7 @@
|
|||||||
static inline bool \
|
static inline bool \
|
||||||
M_C(name, _last_p)(it_t it) \
|
M_C(name, _last_p)(it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
it_t it2; \
|
it_t it2; \
|
||||||
M_C(name, _it_set)(it2, it); \
|
M_C(name, _it_set)(it2, it); \
|
||||||
M_C(name, _next)(it2); \
|
M_C(name, _next)(it2); \
|
||||||
@@ -629,8 +629,8 @@
|
|||||||
static inline bool \
|
static inline bool \
|
||||||
M_C(name, _it_equal_p)(it_t it1, const it_t it2) \
|
M_C(name, _it_equal_p)(it_t it1, const it_t it2) \
|
||||||
{ \
|
{ \
|
||||||
assert (it1 != NULL); \
|
M_ASSERT (it1 != NULL); \
|
||||||
assert (it2 != NULL); \
|
M_ASSERT (it2 != NULL); \
|
||||||
return it1->deque == it2->deque \
|
return it1->deque == it2->deque \
|
||||||
&& it1->node == it2->node \
|
&& it1->node == it2->node \
|
||||||
&& it1->index == it2->index; \
|
&& it1->index == it2->index; \
|
||||||
@@ -639,16 +639,16 @@
|
|||||||
static inline type * \
|
static inline type * \
|
||||||
M_C(name, _ref)(it_t it) \
|
M_C(name, _ref)(it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
assert (it->index < it->node->size); \
|
M_ASSERT (it->index < it->node->size); \
|
||||||
return &it->node->data[it->index]; \
|
return &it->node->data[it->index]; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline type const * \
|
static inline type const * \
|
||||||
M_C(name, _cref)(it_t it) \
|
M_C(name, _cref)(it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
assert (it->index < it->node->size); \
|
M_ASSERT (it->index < it->node->size); \
|
||||||
return M_CONST_CAST(type, &it->node->data[it->index]); \
|
return M_CONST_CAST(type, &it->node->data[it->index]); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
@@ -656,7 +656,7 @@
|
|||||||
M_C(name, _init_set)(deque_t d, const deque_t src) \
|
M_C(name, _init_set)(deque_t d, const deque_t src) \
|
||||||
{ \
|
{ \
|
||||||
DEQUEI_CONTRACT(src); \
|
DEQUEI_CONTRACT(src); \
|
||||||
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 = DEQUEUI_DEFAULT_SIZE + src->count; \
|
d->default_size = DEQUEUI_DEFAULT_SIZE + src->count; \
|
||||||
d->count = src->count; \
|
d->count = src->count; \
|
||||||
@@ -674,7 +674,7 @@
|
|||||||
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); \
|
||||||
i++; \
|
i++; \
|
||||||
assert (i <= d->back->index); \
|
M_ASSERT (i <= d->back->index); \
|
||||||
} \
|
} \
|
||||||
DEQUEI_CONTRACT(d); \
|
DEQUEI_CONTRACT(d); \
|
||||||
} \
|
} \
|
||||||
@@ -693,7 +693,7 @@
|
|||||||
M_C(name, _init_move)(deque_t d, deque_t src) \
|
M_C(name, _init_move)(deque_t d, deque_t src) \
|
||||||
{ \
|
{ \
|
||||||
DEQUEI_CONTRACT(src); \
|
DEQUEI_CONTRACT(src); \
|
||||||
assert (d!= NULL); \
|
M_ASSERT (d!= NULL); \
|
||||||
M_C(name,_node_list_init_move)(d->list, src->list); \
|
M_C(name,_node_list_init_move)(d->list, src->list); \
|
||||||
d->front->node = src->front->node; \
|
d->front->node = src->front->node; \
|
||||||
d->front->index = src->front->index; \
|
d->front->index = src->front->index; \
|
||||||
@@ -748,7 +748,7 @@
|
|||||||
} \
|
} \
|
||||||
count += n->size; \
|
count += n->size; \
|
||||||
} \
|
} \
|
||||||
assert(false); \
|
M_ASSERT(false); \
|
||||||
return NULL; \
|
return NULL; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
@@ -786,7 +786,7 @@
|
|||||||
if (M_CALL_EQUAL(oplist, *obj1, *obj2) == false) \
|
if (M_CALL_EQUAL(oplist, *obj1, *obj2) == false) \
|
||||||
return false; \
|
return false; \
|
||||||
} \
|
} \
|
||||||
assert (M_C(name, _end_p)(it2)); \
|
M_ASSERT (M_C(name, _end_p)(it2)); \
|
||||||
return true; \
|
return true; \
|
||||||
} \
|
} \
|
||||||
, /* NO EQUAL */) \
|
, /* NO EQUAL */) \
|
||||||
@@ -846,7 +846,7 @@
|
|||||||
M_C(name, _out_str)(FILE *file, const deque_t deque) \
|
M_C(name, _out_str)(FILE *file, const deque_t deque) \
|
||||||
{ \
|
{ \
|
||||||
DEQUEI_CONTRACT(deque); \
|
DEQUEI_CONTRACT(deque); \
|
||||||
assert (file != NULL); \
|
M_ASSERT (file != NULL); \
|
||||||
fputc ('[', file); \
|
fputc ('[', file); \
|
||||||
it_t it; \
|
it_t it; \
|
||||||
for (M_C(name, _it)(it, deque) ; \
|
for (M_C(name, _it)(it, deque) ; \
|
||||||
@@ -866,7 +866,7 @@
|
|||||||
M_C(name, _parse_str)(deque_t deque, const char str[], const char **endp) \
|
M_C(name, _parse_str)(deque_t deque, const char str[], const char **endp) \
|
||||||
{ \
|
{ \
|
||||||
DEQUEI_CONTRACT(deque); \
|
DEQUEI_CONTRACT(deque); \
|
||||||
assert (str != NULL); \
|
M_ASSERT (str != NULL); \
|
||||||
M_C(name,_clean)(deque); \
|
M_C(name,_clean)(deque); \
|
||||||
bool success = false; \
|
bool success = false; \
|
||||||
int c = *str++; \
|
int c = *str++; \
|
||||||
@@ -898,7 +898,7 @@
|
|||||||
M_C(name, _in_str)(deque_t deque, FILE *file) \
|
M_C(name, _in_str)(deque_t deque, FILE *file) \
|
||||||
{ \
|
{ \
|
||||||
DEQUEI_CONTRACT(deque); \
|
DEQUEI_CONTRACT(deque); \
|
||||||
assert (file != NULL); \
|
M_ASSERT (file != NULL); \
|
||||||
M_C(name,_clean)(deque); \
|
M_C(name,_clean)(deque); \
|
||||||
int c = fgetc(file); \
|
int c = fgetc(file); \
|
||||||
if (M_UNLIKELY (c != '[')) return false; \
|
if (M_UNLIKELY (c != '[')) return false; \
|
||||||
@@ -925,7 +925,7 @@
|
|||||||
M_C(name, _out_serial)(m_serial_write_t f, const deque_t deque) \
|
M_C(name, _out_serial)(m_serial_write_t f, const deque_t deque) \
|
||||||
{ \
|
{ \
|
||||||
DEQUEI_CONTRACT(deque); \
|
DEQUEI_CONTRACT(deque); \
|
||||||
assert (f != NULL && f->m_interface != NULL); \
|
M_ASSERT (f != NULL && f->m_interface != NULL); \
|
||||||
m_serial_local_t local; \
|
m_serial_local_t local; \
|
||||||
m_serial_return_code_t ret; \
|
m_serial_return_code_t ret; \
|
||||||
bool first_done = false; \
|
bool first_done = false; \
|
||||||
@@ -950,7 +950,7 @@
|
|||||||
M_C(name, _in_serial)(deque_t deque, m_serial_read_t f) \
|
M_C(name, _in_serial)(deque_t deque, m_serial_read_t f) \
|
||||||
{ \
|
{ \
|
||||||
DEQUEI_CONTRACT(deque); \
|
DEQUEI_CONTRACT(deque); \
|
||||||
assert (f != NULL && f->m_interface != NULL); \
|
M_ASSERT (f != NULL && f->m_interface != NULL); \
|
||||||
m_serial_local_t local; \
|
m_serial_local_t local; \
|
||||||
m_serial_return_code_t ret; \
|
m_serial_return_code_t ret; \
|
||||||
size_t estimated_size = 0; \
|
size_t estimated_size = 0; \
|
||||||
|
|||||||
@@ -355,7 +355,7 @@
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _init)(dict_t map) \
|
M_C(name, _init)(dict_t map) \
|
||||||
{ \
|
{ \
|
||||||
assert (map != NULL); \
|
M_ASSERT (map != NULL); \
|
||||||
map->used = 0; \
|
map->used = 0; \
|
||||||
M_C(name, _array_list_pair_init)(map->table); \
|
M_C(name, _array_list_pair_init)(map->table); \
|
||||||
M_C(name, _array_list_pair_resize)(map->table, DICTI_INITIAL_SIZE); \
|
M_C(name, _array_list_pair_resize)(map->table, DICTI_INITIAL_SIZE); \
|
||||||
@@ -368,7 +368,7 @@
|
|||||||
M_C(name, _init_set)(dict_t map, const dict_t org) \
|
M_C(name, _init_set)(dict_t map, const dict_t org) \
|
||||||
{ \
|
{ \
|
||||||
DICTI_CONTRACT(name, org); \
|
DICTI_CONTRACT(name, org); \
|
||||||
assert (map != org); \
|
M_ASSERT (map != org); \
|
||||||
map->used = org->used; \
|
map->used = org->used; \
|
||||||
map->lower_limit = org->lower_limit; \
|
map->lower_limit = org->lower_limit; \
|
||||||
map->upper_limit = org->upper_limit; \
|
map->upper_limit = org->upper_limit; \
|
||||||
@@ -424,7 +424,7 @@
|
|||||||
{ \
|
{ \
|
||||||
DICTI_CONTRACT(name, map); \
|
DICTI_CONTRACT(name, map); \
|
||||||
DICTI_CONTRACT(name, org); \
|
DICTI_CONTRACT(name, org); \
|
||||||
assert (map != org); \
|
M_ASSERT (map != org); \
|
||||||
M_C(name,_clear)(map); \
|
M_C(name,_clear)(map); \
|
||||||
M_C(name,_init_move)(map, org); \
|
M_C(name,_init_move)(map, org); \
|
||||||
DICTI_CONTRACT(name, map); \
|
DICTI_CONTRACT(name, map); \
|
||||||
@@ -506,7 +506,7 @@
|
|||||||
M_C(name, _pair_ptr) pair = *M_C(name, _list_pair_ref)(it); \
|
M_C(name, _pair_ptr) pair = *M_C(name, _list_pair_ref)(it); \
|
||||||
size_t hash = M_IF(isStoreHash)(pair->hash, M_CALL_HASH(key_oplist, pair->key)); \
|
size_t hash = M_IF(isStoreHash)(pair->hash, M_CALL_HASH(key_oplist, pair->key)); \
|
||||||
if ((hash & (new_size-1)) >= old_size) { \
|
if ((hash & (new_size-1)) >= old_size) { \
|
||||||
assert( (hash & (new_size-1)) == (i + old_size)); \
|
M_ASSERT( (hash & (new_size-1)) == (i + old_size)); \
|
||||||
M_C(name, _list_pair_ct) *new_list = \
|
M_C(name, _list_pair_ct) *new_list = \
|
||||||
M_C(name, _array_list_pair_get)(map->table, i + old_size); \
|
M_C(name, _array_list_pair_get)(map->table, i + old_size); \
|
||||||
M_C(name, _list_pair_splice_back)(*new_list, *list, it); \
|
M_C(name, _list_pair_splice_back)(*new_list, *list, it); \
|
||||||
@@ -525,9 +525,9 @@
|
|||||||
{ \
|
{ \
|
||||||
/* NOTE: Contract may not be fullfilled here */ \
|
/* NOTE: Contract may not be fullfilled here */ \
|
||||||
size_t old_size = M_C(name, _array_list_pair_size)(map->table); \
|
size_t old_size = M_C(name, _array_list_pair_size)(map->table); \
|
||||||
assert ((old_size % 2) == 0); \
|
M_ASSERT ((old_size % 2) == 0); \
|
||||||
size_t new_size = old_size / 2; \
|
size_t new_size = old_size / 2; \
|
||||||
assert (new_size >= DICTI_INITIAL_SIZE); \
|
M_ASSERT (new_size >= DICTI_INITIAL_SIZE); \
|
||||||
/* Move all items from the upper part to the lower part of the table */ \
|
/* Move all items from the upper part to the lower part of the table */ \
|
||||||
/* NOTE: We don't need to recompute the hash to move them! */ \
|
/* NOTE: We don't need to recompute the hash to move them! */ \
|
||||||
for(size_t i = new_size; i < old_size; i++) { \
|
for(size_t i = new_size; i < old_size; i++) { \
|
||||||
@@ -658,7 +658,7 @@
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _it_set)(dict_it_t it, const dict_it_t ref) \
|
M_C(name, _it_set)(dict_it_t it, const dict_it_t ref) \
|
||||||
{ \
|
{ \
|
||||||
assert (it != NULL && ref != NULL); \
|
M_ASSERT (it != NULL && ref != NULL); \
|
||||||
M_C(name, _array_list_pair_it_set)(it->array_it, \
|
M_C(name, _array_list_pair_it_set)(it->array_it, \
|
||||||
ref->array_it); \
|
ref->array_it); \
|
||||||
M_C(name, _list_pair_it_set)(it->list_it, ref->list_it); \
|
M_C(name, _list_pair_it_set)(it->list_it, ref->list_it); \
|
||||||
@@ -674,14 +674,14 @@
|
|||||||
static inline bool \
|
static inline bool \
|
||||||
M_C(name, _end_p)(const dict_it_t it) \
|
M_C(name, _end_p)(const dict_it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
return M_C(name, _list_pair_end_p)(it->list_it); \
|
return M_C(name, _list_pair_end_p)(it->list_it); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _next)(dict_it_t it) \
|
M_C(name, _next)(dict_it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert(it != NULL); \
|
M_ASSERT(it != NULL); \
|
||||||
M_C(name, _list_pair_next)(it->list_it); \
|
M_C(name, _list_pair_next)(it->list_it); \
|
||||||
M_C(name, _list_pair_ct) *ref; \
|
M_C(name, _list_pair_ct) *ref; \
|
||||||
while (M_C(name, _list_pair_end_p)(it->list_it)) { \
|
while (M_C(name, _list_pair_end_p)(it->list_it)) { \
|
||||||
@@ -696,7 +696,7 @@
|
|||||||
static inline bool \
|
static inline bool \
|
||||||
M_C(name, _last_p)(const dict_it_t it) \
|
M_C(name, _last_p)(const dict_it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
dict_it_t it2; \
|
dict_it_t it2; \
|
||||||
M_C(name,_it_set)(it2, it); \
|
M_C(name,_it_set)(it2, it); \
|
||||||
M_C(name, _next)(it2); \
|
M_C(name, _next)(it2); \
|
||||||
@@ -706,7 +706,7 @@
|
|||||||
static inline bool \
|
static inline bool \
|
||||||
M_C(name, _it_equal_p)(const dict_it_t it1, const dict_it_t it2) \
|
M_C(name, _it_equal_p)(const dict_it_t it1, const dict_it_t it2) \
|
||||||
{ \
|
{ \
|
||||||
assert (it1 != NULL && it2 != NULL); \
|
M_ASSERT (it1 != NULL && it2 != NULL); \
|
||||||
return M_C(name, _list_pair_it_equal_p)(it1->list_it, \
|
return M_C(name, _list_pair_it_equal_p)(it1->list_it, \
|
||||||
it2->list_it); \
|
it2->list_it); \
|
||||||
} \
|
} \
|
||||||
@@ -714,7 +714,7 @@
|
|||||||
static inline it_deref_t * \
|
static inline it_deref_t * \
|
||||||
M_C(name, _ref)(const dict_it_t it) \
|
M_C(name, _ref)(const dict_it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert(it != NULL); \
|
M_ASSERT(it != NULL); \
|
||||||
/* NOTE: partially unsafe if the user modify the 'key' \
|
/* NOTE: partially unsafe if the user modify the 'key' \
|
||||||
in a non equivalent way */ \
|
in a non equivalent way */ \
|
||||||
M_IF(isSet)( \
|
M_IF(isSet)( \
|
||||||
@@ -727,7 +727,7 @@
|
|||||||
static inline const it_deref_t * \
|
static inline const it_deref_t * \
|
||||||
M_C(name, _cref)(const dict_it_t it) \
|
M_C(name, _cref)(const dict_it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert(it != NULL); \
|
M_ASSERT(it != NULL); \
|
||||||
M_IF(isSet)( \
|
M_IF(isSet)( \
|
||||||
return &(*M_C(name, _list_pair_cref)(it->list_it))->key; \
|
return &(*M_C(name, _list_pair_cref)(it->list_it))->key; \
|
||||||
, \
|
, \
|
||||||
@@ -739,7 +739,7 @@
|
|||||||
static inline bool \
|
static inline bool \
|
||||||
M_C(name, _equal_p)(const dict_t dict1, const dict_t dict2) \
|
M_C(name, _equal_p)(const dict_t dict1, const dict_t dict2) \
|
||||||
{ \
|
{ \
|
||||||
assert (dict1 != NULL && dict2 != NULL); \
|
M_ASSERT (dict1 != NULL && dict2 != NULL); \
|
||||||
/* NOTE: Key type has mandatory equal operator */ \
|
/* NOTE: Key type has mandatory equal operator */ \
|
||||||
/* First the easy cases */ \
|
/* First the easy cases */ \
|
||||||
if (M_LIKELY (dict1->used != dict2->used)) \
|
if (M_LIKELY (dict1->used != dict2->used)) \
|
||||||
@@ -804,7 +804,7 @@
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _out_str)(FILE *file, const dict_t dict) \
|
M_C(name, _out_str)(FILE *file, const dict_t dict) \
|
||||||
{ \
|
{ \
|
||||||
assert (file != NULL); \
|
M_ASSERT (file != NULL); \
|
||||||
fputc ('{', file); \
|
fputc ('{', file); \
|
||||||
dict_it_t it; \
|
dict_it_t it; \
|
||||||
bool print_comma = false; \
|
bool print_comma = false; \
|
||||||
@@ -831,7 +831,7 @@
|
|||||||
static inline bool \
|
static inline bool \
|
||||||
M_C(name, _parse_str)(dict_t dict, const char str[], const char **endp) \
|
M_C(name, _parse_str)(dict_t dict, const char str[], const char **endp) \
|
||||||
{ \
|
{ \
|
||||||
assert (str != NULL); \
|
M_ASSERT (str != NULL); \
|
||||||
M_C(name, _clean)(dict); \
|
M_C(name, _clean)(dict); \
|
||||||
bool success = false; \
|
bool success = false; \
|
||||||
int c = *str++; \
|
int c = *str++; \
|
||||||
@@ -873,7 +873,7 @@
|
|||||||
static inline bool \
|
static inline bool \
|
||||||
M_C(name, _in_str)(dict_t dict, FILE *file) \
|
M_C(name, _in_str)(dict_t dict, FILE *file) \
|
||||||
{ \
|
{ \
|
||||||
assert (file != NULL); \
|
M_ASSERT (file != NULL); \
|
||||||
M_C(name, _clean)(dict); \
|
M_C(name, _clean)(dict); \
|
||||||
int c = fgetc(file); \
|
int c = fgetc(file); \
|
||||||
if (M_UNLIKELY (c != '{')) return false; \
|
if (M_UNLIKELY (c != '{')) return false; \
|
||||||
@@ -916,7 +916,7 @@
|
|||||||
static inline m_serial_return_code_t \
|
static inline m_serial_return_code_t \
|
||||||
M_C(name, _out_serial)(m_serial_write_t f, dict_t const t1) \
|
M_C(name, _out_serial)(m_serial_write_t f, dict_t const t1) \
|
||||||
{ \
|
{ \
|
||||||
assert (f != NULL && f->m_interface != NULL); \
|
M_ASSERT (f != NULL && f->m_interface != NULL); \
|
||||||
m_serial_local_t local; \
|
m_serial_local_t local; \
|
||||||
m_serial_return_code_t ret; \
|
m_serial_return_code_t ret; \
|
||||||
const it_deref_t *item; \
|
const it_deref_t *item; \
|
||||||
@@ -959,7 +959,7 @@
|
|||||||
static inline m_serial_return_code_t \
|
static inline m_serial_return_code_t \
|
||||||
M_C(name, _in_serial)(dict_t t1, m_serial_read_t f) \
|
M_C(name, _in_serial)(dict_t t1, m_serial_read_t f) \
|
||||||
{ \
|
{ \
|
||||||
assert (f != NULL && f->m_interface != NULL); \
|
M_ASSERT (f != NULL && f->m_interface != NULL); \
|
||||||
m_serial_local_t local; \
|
m_serial_local_t local; \
|
||||||
m_serial_return_code_t ret; \
|
m_serial_return_code_t ret; \
|
||||||
size_t estimated_size = 0; \
|
size_t estimated_size = 0; \
|
||||||
@@ -1178,11 +1178,11 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define DICTI_CONTRACT(name, map) do { \
|
#define DICTI_CONTRACT(name, map) do { \
|
||||||
assert(map != NULL); \
|
M_ASSERT(map != NULL); \
|
||||||
assert(map->used <= map->upper_limit); \
|
M_ASSERT(map->used <= map->upper_limit); \
|
||||||
assert(map->upper_limit >= DICTI_UPPER_BOUND(DICTI_INITIAL_SIZE)); \
|
M_ASSERT(map->upper_limit >= DICTI_UPPER_BOUND(DICTI_INITIAL_SIZE)); \
|
||||||
assert(map->used >= map->lower_limit); \
|
M_ASSERT(map->used >= map->lower_limit); \
|
||||||
assert(M_POWEROF2_P(M_C(name, _array_list_pair_size)(map->table))); \
|
M_ASSERT(M_POWEROF2_P(M_C(name, _array_list_pair_size)(map->table))); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
|
||||||
@@ -1210,13 +1210,13 @@ enum dicti_oa_element_e {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define DICTI_OA_CONTRACT(dict) do { \
|
#define DICTI_OA_CONTRACT(dict) do { \
|
||||||
assert ( (dict) != NULL); \
|
M_ASSERT ( (dict) != NULL); \
|
||||||
assert( (dict)->lower_limit <= (dict)->count); \
|
M_ASSERT( (dict)->lower_limit <= (dict)->count); \
|
||||||
assert( (dict)->count <= (dict)->upper_limit ); \
|
M_ASSERT( (dict)->count <= (dict)->upper_limit ); \
|
||||||
assert( (dict)->data != NULL); \
|
M_ASSERT( (dict)->data != NULL); \
|
||||||
assert( M_POWEROF2_P((dict)->mask+1)); \
|
M_ASSERT( M_POWEROF2_P((dict)->mask+1)); \
|
||||||
assert( (dict)->mask+1 >= DICTI_INITIAL_SIZE); \
|
M_ASSERT( (dict)->mask+1 >= DICTI_INITIAL_SIZE); \
|
||||||
assert( (dict)->count <= (dict)->mask+1); \
|
M_ASSERT( (dict)->count <= (dict)->mask+1); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define DICTI_OA_DEF_P1(args) DICTI_OA_DEF_P2 args
|
#define DICTI_OA_DEF_P1(args) DICTI_OA_DEF_P2 args
|
||||||
@@ -1308,7 +1308,7 @@ enum dicti_oa_element_e {
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _init)(dict_t dict) \
|
M_C(name, _init)(dict_t dict) \
|
||||||
{ \
|
{ \
|
||||||
assert(0 <= (coeff_down) && (coeff_down)*2 < (coeff_up) && (coeff_up) < 1); \
|
M_ASSERT(0 <= (coeff_down) && (coeff_down)*2 < (coeff_up) && (coeff_up) < 1); \
|
||||||
dict->mask = DICTI_INITIAL_SIZE-1; \
|
dict->mask = DICTI_INITIAL_SIZE-1; \
|
||||||
dict->count = 0; \
|
dict->count = 0; \
|
||||||
dict->count_delete = 0; \
|
dict->count_delete = 0; \
|
||||||
@@ -1346,8 +1346,8 @@ enum dicti_oa_element_e {
|
|||||||
{ \
|
{ \
|
||||||
DICTI_OA_CONTRACT(dict); \
|
DICTI_OA_CONTRACT(dict); \
|
||||||
/* NOTE: Key can not be the representation of empty or deleted */ \
|
/* NOTE: Key can not be the representation of empty or deleted */ \
|
||||||
assert (!M_CALL_OOR_EQUAL(key_oplist, key, DICTI_OA_EMPTY)); \
|
M_ASSERT (!M_CALL_OOR_EQUAL(key_oplist, key, DICTI_OA_EMPTY)); \
|
||||||
assert (!M_CALL_OOR_EQUAL(key_oplist, key, DICTI_OA_DELETED)); \
|
M_ASSERT (!M_CALL_OOR_EQUAL(key_oplist, key, DICTI_OA_DELETED)); \
|
||||||
\
|
\
|
||||||
M_C(name, _pair_ct) *const data = dict->data; \
|
M_C(name, _pair_ct) *const data = dict->data; \
|
||||||
const size_t mask = dict->mask; \
|
const size_t mask = dict->mask; \
|
||||||
@@ -1365,7 +1365,7 @@ enum dicti_oa_element_e {
|
|||||||
p = (p + DICTI_OA_PROBING(s)) & mask; \
|
p = (p + DICTI_OA_PROBING(s)) & mask; \
|
||||||
if (M_CALL_EQUAL(key_oplist, data[p].key, key)) \
|
if (M_CALL_EQUAL(key_oplist, data[p].key, key)) \
|
||||||
return &data[p].M_IF(isSet)(key, value); \
|
return &data[p].M_IF(isSet)(key, value); \
|
||||||
assert (s <= dict->mask); \
|
M_ASSERT (s <= dict->mask); \
|
||||||
} while (!M_CALL_OOR_EQUAL(key_oplist, data[p].key, DICTI_OA_EMPTY) ); \
|
} while (!M_CALL_OOR_EQUAL(key_oplist, data[p].key, DICTI_OA_EMPTY) ); \
|
||||||
\
|
\
|
||||||
return NULL; \
|
return NULL; \
|
||||||
@@ -1390,8 +1390,8 @@ enum dicti_oa_element_e {
|
|||||||
empty += M_CALL_OOR_EQUAL(key_oplist, data[i].key, DICTI_OA_EMPTY); \
|
empty += M_CALL_OOR_EQUAL(key_oplist, data[i].key, DICTI_OA_EMPTY); \
|
||||||
del += M_CALL_OOR_EQUAL(key_oplist, data[i].key, DICTI_OA_DELETED); \
|
del += M_CALL_OOR_EQUAL(key_oplist, data[i].key, DICTI_OA_DELETED); \
|
||||||
} \
|
} \
|
||||||
assert(del == 0); \
|
M_ASSERT(del == 0); \
|
||||||
assert(empty + h->count == h->mask + 1); \
|
M_ASSERT(empty + h->count == h->mask + 1); \
|
||||||
return true; \
|
return true; \
|
||||||
} \
|
} \
|
||||||
) \
|
) \
|
||||||
@@ -1400,8 +1400,8 @@ enum dicti_oa_element_e {
|
|||||||
M_C(name,_int_resize_up)(dict_t h, size_t newSize, bool updateLimit) \
|
M_C(name,_int_resize_up)(dict_t h, size_t newSize, bool updateLimit) \
|
||||||
{ \
|
{ \
|
||||||
size_t oldSize = h->mask+1; \
|
size_t oldSize = h->mask+1; \
|
||||||
assert (newSize >= oldSize); \
|
M_ASSERT (newSize >= oldSize); \
|
||||||
assert (M_POWEROF2_P(newSize)); \
|
M_ASSERT (M_POWEROF2_P(newSize)); \
|
||||||
M_C(name, _pair_ct) *data = h->data; \
|
M_C(name, _pair_ct) *data = h->data; \
|
||||||
/* resize can be called just to delete the items */ \
|
/* resize can be called just to delete the items */ \
|
||||||
if (newSize > oldSize) { \
|
if (newSize > oldSize) { \
|
||||||
@@ -1455,7 +1455,7 @@ enum dicti_oa_element_e {
|
|||||||
size_t s = 1; \
|
size_t s = 1; \
|
||||||
do { \
|
do { \
|
||||||
p = (p + DICTI_OA_PROBING(s)) & mask; \
|
p = (p + DICTI_OA_PROBING(s)) & mask; \
|
||||||
assert (s <= h->mask); \
|
M_ASSERT (s <= h->mask); \
|
||||||
} while (!M_CALL_OOR_EQUAL(key_oplist, data[p].key, DICTI_OA_EMPTY) ); \
|
} while (!M_CALL_OOR_EQUAL(key_oplist, data[p].key, DICTI_OA_EMPTY) ); \
|
||||||
} \
|
} \
|
||||||
M_C(name, _array_pair_pop_move)(&data[p], tmp); \
|
M_C(name, _array_pair_pop_move)(&data[p], tmp); \
|
||||||
@@ -1468,7 +1468,7 @@ enum dicti_oa_element_e {
|
|||||||
M_C(name,_int_limit)(h, newSize); \
|
M_C(name,_int_limit)(h, newSize); \
|
||||||
} \
|
} \
|
||||||
h->data = data; \
|
h->data = data; \
|
||||||
M_IF_DEBUG (assert (M_C(name,_int_control_after_resize)(h));) \
|
M_IF_DEBUG (M_ASSERT (M_C(name,_int_control_after_resize)(h));) \
|
||||||
DICTI_OA_CONTRACT(h); \
|
DICTI_OA_CONTRACT(h); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
@@ -1479,8 +1479,8 @@ enum dicti_oa_element_e {
|
|||||||
{ \
|
{ \
|
||||||
DICTI_OA_CONTRACT(dict); \
|
DICTI_OA_CONTRACT(dict); \
|
||||||
/* NOTE: key can not be the representation of empty or deleted */ \
|
/* NOTE: key can not be the representation of empty or deleted */ \
|
||||||
assert (!M_CALL_OOR_EQUAL(key_oplist, key, DICTI_OA_EMPTY)); \
|
M_ASSERT (!M_CALL_OOR_EQUAL(key_oplist, key, DICTI_OA_EMPTY)); \
|
||||||
assert (!M_CALL_OOR_EQUAL(key_oplist, key, DICTI_OA_DELETED)); \
|
M_ASSERT (!M_CALL_OOR_EQUAL(key_oplist, key, DICTI_OA_DELETED)); \
|
||||||
\
|
\
|
||||||
M_C(name, _pair_ct) *const data = dict->data; \
|
M_C(name, _pair_ct) *const data = dict->data; \
|
||||||
const size_t mask = dict->mask; \
|
const size_t mask = dict->mask; \
|
||||||
@@ -1501,7 +1501,7 @@ enum dicti_oa_element_e {
|
|||||||
M_CALL_SET(value_oplist, data[p].value, value); \
|
M_CALL_SET(value_oplist, data[p].value, value); \
|
||||||
return; \
|
return; \
|
||||||
} \
|
} \
|
||||||
assert (s <= dict->mask); \
|
M_ASSERT (s <= dict->mask); \
|
||||||
if (M_CALL_OOR_EQUAL(key_oplist, data[p].key, DICTI_OA_DELETED) && delPos == (size_t)-1) delPos = p; \
|
if (M_CALL_OOR_EQUAL(key_oplist, data[p].key, DICTI_OA_DELETED) && delPos == (size_t)-1) delPos = p; \
|
||||||
} while (!M_CALL_OOR_EQUAL(key_oplist, data[p].key, DICTI_OA_EMPTY) ); \
|
} while (!M_CALL_OOR_EQUAL(key_oplist, data[p].key, DICTI_OA_EMPTY) ); \
|
||||||
if (delPos != SIZE_MAX) { \
|
if (delPos != SIZE_MAX) { \
|
||||||
@@ -1533,8 +1533,8 @@ enum dicti_oa_element_e {
|
|||||||
{ \
|
{ \
|
||||||
DICTI_OA_CONTRACT(dict); \
|
DICTI_OA_CONTRACT(dict); \
|
||||||
/* NOTE: key can not be the representation of empty or deleted */ \
|
/* NOTE: key can not be the representation of empty or deleted */ \
|
||||||
assert (!M_CALL_OOR_EQUAL(key_oplist, key, DICTI_OA_EMPTY)); \
|
M_ASSERT (!M_CALL_OOR_EQUAL(key_oplist, key, DICTI_OA_EMPTY)); \
|
||||||
assert (!M_CALL_OOR_EQUAL(key_oplist, key, DICTI_OA_DELETED)); \
|
M_ASSERT (!M_CALL_OOR_EQUAL(key_oplist, key, DICTI_OA_DELETED)); \
|
||||||
\
|
\
|
||||||
M_C(name, _pair_ct) *const data = dict->data; \
|
M_C(name, _pair_ct) *const data = dict->data; \
|
||||||
const size_t mask = dict->mask; \
|
const size_t mask = dict->mask; \
|
||||||
@@ -1552,7 +1552,7 @@ enum dicti_oa_element_e {
|
|||||||
if (M_CALL_EQUAL(key_oplist, data[p].key, key)) { \
|
if (M_CALL_EQUAL(key_oplist, data[p].key, key)) { \
|
||||||
return &data[p].M_IF(isSet)(key, value); \
|
return &data[p].M_IF(isSet)(key, value); \
|
||||||
} \
|
} \
|
||||||
assert (s <= dict->mask); \
|
M_ASSERT (s <= dict->mask); \
|
||||||
if (M_CALL_OOR_EQUAL(key_oplist, data[p].key, DICTI_OA_DELETED) && delPos == (size_t)-1) delPos = p; \
|
if (M_CALL_OOR_EQUAL(key_oplist, data[p].key, DICTI_OA_DELETED) && delPos == (size_t)-1) delPos = p; \
|
||||||
} while (!M_CALL_OOR_EQUAL(key_oplist, data[p].key, DICTI_OA_EMPTY) ); \
|
} while (!M_CALL_OOR_EQUAL(key_oplist, data[p].key, DICTI_OA_EMPTY) ); \
|
||||||
if (delPos != SIZE_MAX) { \
|
if (delPos != SIZE_MAX) { \
|
||||||
@@ -1586,7 +1586,7 @@ enum dicti_oa_element_e {
|
|||||||
M_C(name,_int_resize_down)(dict_t h, size_t newSize) \
|
M_C(name,_int_resize_down)(dict_t h, size_t newSize) \
|
||||||
{ \
|
{ \
|
||||||
size_t oldSize = h->mask+1; \
|
size_t oldSize = h->mask+1; \
|
||||||
assert (newSize <= oldSize && M_POWEROF2_P(newSize)); \
|
M_ASSERT (newSize <= oldSize && M_POWEROF2_P(newSize)); \
|
||||||
if (M_UNLIKELY (newSize < DICTI_INITIAL_SIZE)) \
|
if (M_UNLIKELY (newSize < DICTI_INITIAL_SIZE)) \
|
||||||
newSize = DICTI_INITIAL_SIZE; \
|
newSize = DICTI_INITIAL_SIZE; \
|
||||||
const size_t mask = newSize -1; \
|
const size_t mask = newSize -1; \
|
||||||
@@ -1620,12 +1620,12 @@ enum dicti_oa_element_e {
|
|||||||
if (!M_CALL_OOR_EQUAL(key_oplist, data[i].key, DICTI_OA_DELETED) \
|
if (!M_CALL_OOR_EQUAL(key_oplist, data[i].key, DICTI_OA_DELETED) \
|
||||||
&& !M_CALL_OOR_EQUAL(key_oplist, data[i].key, DICTI_OA_EMPTY)) { \
|
&& !M_CALL_OOR_EQUAL(key_oplist, data[i].key, DICTI_OA_EMPTY)) { \
|
||||||
size_t p = M_CALL_HASH(key_oplist, data[i].key) & mask; \
|
size_t p = M_CALL_HASH(key_oplist, data[i].key) & mask; \
|
||||||
assert (p < i); \
|
M_ASSERT (p < i); \
|
||||||
if (!M_CALL_OOR_EQUAL(key_oplist, data[p].key, DICTI_OA_EMPTY)) { \
|
if (!M_CALL_OOR_EQUAL(key_oplist, data[p].key, DICTI_OA_EMPTY)) { \
|
||||||
size_t s = 1; \
|
size_t s = 1; \
|
||||||
do { \
|
do { \
|
||||||
p = (p + DICTI_OA_PROBING(s)) & mask; \
|
p = (p + DICTI_OA_PROBING(s)) & mask; \
|
||||||
assert (s <= h->mask); \
|
M_ASSERT (s <= h->mask); \
|
||||||
} while (!M_CALL_OOR_EQUAL(key_oplist, data[p].key, DICTI_OA_EMPTY) ); \
|
} while (!M_CALL_OOR_EQUAL(key_oplist, data[p].key, DICTI_OA_EMPTY) ); \
|
||||||
} \
|
} \
|
||||||
M_DO_INIT_MOVE(key_oplist, data[p].key, data[i].key); \
|
M_DO_INIT_MOVE(key_oplist, data[p].key, data[i].key); \
|
||||||
@@ -1640,7 +1640,7 @@ enum dicti_oa_element_e {
|
|||||||
size_t s = 1; \
|
size_t s = 1; \
|
||||||
do { \
|
do { \
|
||||||
p = (p + DICTI_OA_PROBING(s)) & mask; \
|
p = (p + DICTI_OA_PROBING(s)) & mask; \
|
||||||
assert (s <= h->mask); \
|
M_ASSERT (s <= h->mask); \
|
||||||
} while (!M_CALL_OOR_EQUAL(key_oplist, data[p].key, DICTI_OA_EMPTY) ); \
|
} while (!M_CALL_OOR_EQUAL(key_oplist, data[p].key, DICTI_OA_EMPTY) ); \
|
||||||
} \
|
} \
|
||||||
M_C(name, _array_pair_pop_move)(&data[p], tmp); \
|
M_C(name, _array_pair_pop_move)(&data[p], tmp); \
|
||||||
@@ -1652,10 +1652,10 @@ enum dicti_oa_element_e {
|
|||||||
h->mask = newSize-1; \
|
h->mask = newSize-1; \
|
||||||
M_C(name,_int_limit)(h, newSize); \
|
M_C(name,_int_limit)(h, newSize); \
|
||||||
h->data = M_CALL_REALLOC(key_oplist, M_C(name, _pair_ct), data, newSize); \
|
h->data = M_CALL_REALLOC(key_oplist, M_C(name, _pair_ct), data, newSize); \
|
||||||
assert (h->data != NULL); \
|
M_ASSERT (h->data != NULL); \
|
||||||
} \
|
} \
|
||||||
M_IF_DEBUG (assert (M_C(name,_int_control_after_resize)(h));) \
|
M_IF_DEBUG (M_ASSERT (M_C(name,_int_control_after_resize)(h));) \
|
||||||
assert (h->lower_limit < h->count && h->count < h->upper_limit); \
|
M_ASSERT (h->lower_limit < h->count && h->count < h->upper_limit); \
|
||||||
DICTI_OA_CONTRACT(h); \
|
DICTI_OA_CONTRACT(h); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
@@ -1664,8 +1664,8 @@ enum dicti_oa_element_e {
|
|||||||
{ \
|
{ \
|
||||||
DICTI_OA_CONTRACT(dict); \
|
DICTI_OA_CONTRACT(dict); \
|
||||||
/* NOTE: key can't be the representation of empty or deleted */ \
|
/* NOTE: key can't be the representation of empty or deleted */ \
|
||||||
assert (!M_CALL_OOR_EQUAL(key_oplist, key, DICTI_OA_EMPTY)); \
|
M_ASSERT (!M_CALL_OOR_EQUAL(key_oplist, key, DICTI_OA_EMPTY)); \
|
||||||
assert (!M_CALL_OOR_EQUAL(key_oplist, key, DICTI_OA_DELETED)); \
|
M_ASSERT (!M_CALL_OOR_EQUAL(key_oplist, key, DICTI_OA_DELETED)); \
|
||||||
\
|
\
|
||||||
M_C(name, _pair_ct) *const data = dict->data; \
|
M_C(name, _pair_ct) *const data = dict->data; \
|
||||||
const size_t mask = dict->mask; \
|
const size_t mask = dict->mask; \
|
||||||
@@ -1680,13 +1680,13 @@ enum dicti_oa_element_e {
|
|||||||
p = (p + DICTI_OA_PROBING(s)) & mask; \
|
p = (p + DICTI_OA_PROBING(s)) & mask; \
|
||||||
if (M_CALL_OOR_EQUAL(key_oplist, data[p].key, DICTI_OA_EMPTY) ) \
|
if (M_CALL_OOR_EQUAL(key_oplist, data[p].key, DICTI_OA_EMPTY) ) \
|
||||||
return false; \
|
return false; \
|
||||||
assert (s <= dict->mask); \
|
M_ASSERT (s <= dict->mask); \
|
||||||
} while (!M_CALL_EQUAL(key_oplist, data[p].key, key)); \
|
} while (!M_CALL_EQUAL(key_oplist, data[p].key, key)); \
|
||||||
} \
|
} \
|
||||||
M_CALL_CLEAR(key_oplist, data[p].key); \
|
M_CALL_CLEAR(key_oplist, data[p].key); \
|
||||||
M_CALL_CLEAR(value_oplist, data[p].value); \
|
M_CALL_CLEAR(value_oplist, data[p].value); \
|
||||||
M_CALL_OOR_SET(key_oplist, data[p].key, DICTI_OA_DELETED); \
|
M_CALL_OOR_SET(key_oplist, data[p].key, DICTI_OA_DELETED); \
|
||||||
assert (dict->count >= 1); \
|
M_ASSERT (dict->count >= 1); \
|
||||||
dict->count--; \
|
dict->count--; \
|
||||||
if (M_UNLIKELY (dict->count < dict->lower_limit)) { \
|
if (M_UNLIKELY (dict->count < dict->lower_limit)) { \
|
||||||
M_C(name,_int_resize_down)(dict, (dict->mask+1) >> 1); \
|
M_C(name,_int_resize_down)(dict, (dict->mask+1) >> 1); \
|
||||||
@@ -1713,7 +1713,7 @@ enum dicti_oa_element_e {
|
|||||||
M_C(name, _init_set)(dict_t map, const dict_t org) \
|
M_C(name, _init_set)(dict_t map, const dict_t org) \
|
||||||
{ \
|
{ \
|
||||||
DICTI_OA_CONTRACT(org); \
|
DICTI_OA_CONTRACT(org); \
|
||||||
assert (map != org); \
|
M_ASSERT (map != org); \
|
||||||
map->mask = org->mask; \
|
map->mask = org->mask; \
|
||||||
map->count = org->count; \
|
map->count = org->count; \
|
||||||
map->count_delete = org->count_delete; \
|
map->count_delete = org->count_delete; \
|
||||||
@@ -1753,7 +1753,7 @@ enum dicti_oa_element_e {
|
|||||||
M_C(name, _init_move)(dict_t map, dict_t org) \
|
M_C(name, _init_move)(dict_t map, dict_t org) \
|
||||||
{ \
|
{ \
|
||||||
DICTI_OA_CONTRACT(org); \
|
DICTI_OA_CONTRACT(org); \
|
||||||
assert (map != org); \
|
M_ASSERT (map != org); \
|
||||||
map->mask = org->mask; \
|
map->mask = org->mask; \
|
||||||
map->count = org->count; \
|
map->count = org->count; \
|
||||||
map->count_delete = org->count_delete; \
|
map->count_delete = org->count_delete; \
|
||||||
@@ -1810,7 +1810,7 @@ enum dicti_oa_element_e {
|
|||||||
M_C(name,_int_limit)(d, DICTI_INITIAL_SIZE); \
|
M_C(name,_int_limit)(d, DICTI_INITIAL_SIZE); \
|
||||||
d->data = M_CALL_REALLOC(key_oplist, M_C(name, _pair_ct), \
|
d->data = M_CALL_REALLOC(key_oplist, M_C(name, _pair_ct), \
|
||||||
d->data, DICTI_INITIAL_SIZE); \
|
d->data, DICTI_INITIAL_SIZE); \
|
||||||
assert(d->data != NULL); \
|
M_ASSERT(d->data != NULL); \
|
||||||
for(size_t i = 0; i <= d->mask; i++) { \
|
for(size_t i = 0; i <= d->mask; i++) { \
|
||||||
M_CALL_OOR_SET(key_oplist, d->data[i].key, DICTI_OA_EMPTY); \
|
M_CALL_OOR_SET(key_oplist, d->data[i].key, DICTI_OA_EMPTY); \
|
||||||
} \
|
} \
|
||||||
@@ -1821,7 +1821,7 @@ enum dicti_oa_element_e {
|
|||||||
M_C(name, _it)(dict_it_t it, const dict_t d) \
|
M_C(name, _it)(dict_it_t it, const dict_t d) \
|
||||||
{ \
|
{ \
|
||||||
DICTI_OA_CONTRACT(d); \
|
DICTI_OA_CONTRACT(d); \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
it->dict = d; \
|
it->dict = d; \
|
||||||
size_t i = 0; \
|
size_t i = 0; \
|
||||||
while ((M_CALL_OOR_EQUAL(key_oplist, d->data[i].key, DICTI_OA_EMPTY) \
|
while ((M_CALL_OOR_EQUAL(key_oplist, d->data[i].key, DICTI_OA_EMPTY) \
|
||||||
@@ -1835,8 +1835,8 @@ enum dicti_oa_element_e {
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _it_set)(dict_it_t it, const dict_it_t ref) \
|
M_C(name, _it_set)(dict_it_t it, const dict_it_t ref) \
|
||||||
{ \
|
{ \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
assert (ref != NULL); \
|
M_ASSERT (ref != NULL); \
|
||||||
it->dict = ref->dict; \
|
it->dict = ref->dict; \
|
||||||
it->index = ref->index; \
|
it->index = ref->index; \
|
||||||
DICTI_OA_CONTRACT (it->dict); \
|
DICTI_OA_CONTRACT (it->dict); \
|
||||||
@@ -1846,7 +1846,7 @@ enum dicti_oa_element_e {
|
|||||||
M_C(name, _it_last)(dict_it_t it, const dict_t d) \
|
M_C(name, _it_last)(dict_it_t it, const dict_t d) \
|
||||||
{ \
|
{ \
|
||||||
DICTI_OA_CONTRACT(d); \
|
DICTI_OA_CONTRACT(d); \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
it->dict = d; \
|
it->dict = d; \
|
||||||
size_t i = d->mask; \
|
size_t i = d->mask; \
|
||||||
while ((M_CALL_OOR_EQUAL(key_oplist, d->data[i].key, DICTI_OA_EMPTY) \
|
while ((M_CALL_OOR_EQUAL(key_oplist, d->data[i].key, DICTI_OA_EMPTY) \
|
||||||
@@ -1861,7 +1861,7 @@ enum dicti_oa_element_e {
|
|||||||
M_C(name, _it_end)(dict_it_t it, const dict_t d) \
|
M_C(name, _it_end)(dict_it_t it, const dict_t d) \
|
||||||
{ \
|
{ \
|
||||||
DICTI_OA_CONTRACT(d); \
|
DICTI_OA_CONTRACT(d); \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
it->dict = d; \
|
it->dict = d; \
|
||||||
it->index = d->mask+1; \
|
it->index = d->mask+1; \
|
||||||
} \
|
} \
|
||||||
@@ -1869,7 +1869,7 @@ enum dicti_oa_element_e {
|
|||||||
static inline bool \
|
static inline bool \
|
||||||
M_C(name, _end_p)(const dict_it_t it) \
|
M_C(name, _end_p)(const dict_it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
DICTI_OA_CONTRACT (it->dict); \
|
DICTI_OA_CONTRACT (it->dict); \
|
||||||
return it->index > it->dict->mask; \
|
return it->index > it->dict->mask; \
|
||||||
} \
|
} \
|
||||||
@@ -1877,7 +1877,7 @@ enum dicti_oa_element_e {
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _next)(dict_it_t it) \
|
M_C(name, _next)(dict_it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
DICTI_OA_CONTRACT (it->dict); \
|
DICTI_OA_CONTRACT (it->dict); \
|
||||||
size_t i = it->index + 1; \
|
size_t i = it->index + 1; \
|
||||||
while (i <= it->dict->mask && \
|
while (i <= it->dict->mask && \
|
||||||
@@ -1891,7 +1891,7 @@ enum dicti_oa_element_e {
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _previous)(dict_it_t it) \
|
M_C(name, _previous)(dict_it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
DICTI_OA_CONTRACT (it->dict); \
|
DICTI_OA_CONTRACT (it->dict); \
|
||||||
/* if index was 0, the operation will overflow, and stops the loop */ \
|
/* if index was 0, the operation will overflow, and stops the loop */ \
|
||||||
size_t i = it->index - 1; \
|
size_t i = it->index - 1; \
|
||||||
@@ -1906,7 +1906,7 @@ enum dicti_oa_element_e {
|
|||||||
static inline bool \
|
static inline bool \
|
||||||
M_C(name, _last_p)(const dict_it_t it) \
|
M_C(name, _last_p)(const dict_it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
dict_it_t it2; \
|
dict_it_t it2; \
|
||||||
M_C(name,_it_set)(it2, it); \
|
M_C(name,_it_set)(it2, it); \
|
||||||
M_C(name, _next)(it2); \
|
M_C(name, _next)(it2); \
|
||||||
@@ -1916,7 +1916,7 @@ enum dicti_oa_element_e {
|
|||||||
static inline bool \
|
static inline bool \
|
||||||
M_C(name, _it_equal_p)(const dict_it_t it1,const dict_it_t it2) \
|
M_C(name, _it_equal_p)(const dict_it_t it1,const dict_it_t it2) \
|
||||||
{ \
|
{ \
|
||||||
assert (it1 != NULL && it2 != NULL); \
|
M_ASSERT (it1 != NULL && it2 != NULL); \
|
||||||
DICTI_OA_CONTRACT (it1->dict); \
|
DICTI_OA_CONTRACT (it1->dict); \
|
||||||
DICTI_OA_CONTRACT (it2->dict); \
|
DICTI_OA_CONTRACT (it2->dict); \
|
||||||
return it1->dict == it2->dict && it1->index == it2->index; \
|
return it1->dict == it2->dict && it1->index == it2->index; \
|
||||||
@@ -1925,12 +1925,12 @@ enum dicti_oa_element_e {
|
|||||||
static inline it_deref_t * \
|
static inline it_deref_t * \
|
||||||
M_C(name, _ref)(const dict_it_t it) \
|
M_C(name, _ref)(const dict_it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
DICTI_OA_CONTRACT (it -> dict); \
|
DICTI_OA_CONTRACT (it -> dict); \
|
||||||
const size_t i = it->index; \
|
const size_t i = it->index; \
|
||||||
assert (i <= it->dict->mask); \
|
M_ASSERT (i <= it->dict->mask); \
|
||||||
assert (!M_CALL_OOR_EQUAL(key_oplist, it->dict->data[i].key, DICTI_OA_EMPTY)); \
|
M_ASSERT (!M_CALL_OOR_EQUAL(key_oplist, it->dict->data[i].key, DICTI_OA_EMPTY)); \
|
||||||
assert (!M_CALL_OOR_EQUAL(key_oplist, it->dict->data[i].key, DICTI_OA_DELETED)); \
|
M_ASSERT (!M_CALL_OOR_EQUAL(key_oplist, it->dict->data[i].key, DICTI_OA_DELETED)); \
|
||||||
return &it->dict->data[i] M_IF(isSet)(.key, ); \
|
return &it->dict->data[i] M_IF(isSet)(.key, ); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
@@ -1953,7 +1953,7 @@ enum dicti_oa_element_e {
|
|||||||
if (M_UNLIKELY (size < capacity)) { \
|
if (M_UNLIKELY (size < capacity)) { \
|
||||||
M_MEMORY_FULL((size_t)-1); \
|
M_MEMORY_FULL((size_t)-1); \
|
||||||
} \
|
} \
|
||||||
assert (M_POWEROF2_P(size)); \
|
M_ASSERT (M_POWEROF2_P(size)); \
|
||||||
if (size > dict->mask+1) { \
|
if (size > dict->mask+1) { \
|
||||||
dict->upper_limit = (size_t) ((double) size * coeff_up) - 1; \
|
dict->upper_limit = (size_t) ((double) size * coeff_up) - 1; \
|
||||||
M_C(name,_int_resize_up)(dict, size, false); \
|
M_C(name,_int_resize_up)(dict, size, false); \
|
||||||
|
|||||||
+12
-12
@@ -68,10 +68,10 @@ typedef struct genint_s {
|
|||||||
|
|
||||||
// Define the contract of a genint
|
// Define the contract of a genint
|
||||||
#define GENINT_CONTRACT(s) do { \
|
#define GENINT_CONTRACT(s) do { \
|
||||||
assert (s != NULL); \
|
M_ASSERT (s != NULL); \
|
||||||
assert (s->n > 0 && s->n <= GENINT_MAX_ALLOC); \
|
M_ASSERT (s->n > 0 && s->n <= GENINT_MAX_ALLOC); \
|
||||||
assert ((s->max+1) * GENINT_LIMBSIZE >= s->n); \
|
M_ASSERT ((s->max+1) * GENINT_LIMBSIZE >= s->n); \
|
||||||
assert (s->data != NULL); \
|
M_ASSERT (s->data != NULL); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
// Define the limb one
|
// Define the limb one
|
||||||
@@ -108,7 +108,7 @@ typedef struct genint_s {
|
|||||||
static inline void
|
static inline void
|
||||||
genint_init(genint_t s, unsigned int n)
|
genint_init(genint_t s, unsigned int n)
|
||||||
{
|
{
|
||||||
assert (s != NULL && n > 0 && n <= GENINT_MAX_ALLOC);
|
M_ASSERT (s != NULL && n > 0 && n <= GENINT_MAX_ALLOC);
|
||||||
const size_t alloc = (n + GENINT_LIMBSIZE - 1) / GENINT_LIMBSIZE;
|
const size_t alloc = (n + GENINT_LIMBSIZE - 1) / GENINT_LIMBSIZE;
|
||||||
const unsigned int index = n % GENINT_LIMBSIZE;
|
const unsigned int index = n % GENINT_LIMBSIZE;
|
||||||
atomic_ullong *ptr = M_MEMORY_REALLOC (atomic_ullong, NULL, alloc);
|
atomic_ullong *ptr = M_MEMORY_REALLOC (atomic_ullong, NULL, alloc);
|
||||||
@@ -156,7 +156,7 @@ genint_pop(genint_t s)
|
|||||||
while ((master >> GENINT_ABA_CPT) != s->mask_master) {
|
while ((master >> GENINT_ABA_CPT) != s->mask_master) {
|
||||||
// Let's get the index i of the first not full limb according to master.
|
// Let's get the index i of the first not full limb according to master.
|
||||||
unsigned int i = m_core_clz64(~master);
|
unsigned int i = m_core_clz64(~master);
|
||||||
assert (i < GENINT_LIMBSIZE);
|
M_ASSERT (i < GENINT_LIMBSIZE);
|
||||||
// Let's compute the mask of this limb representing the limb as being full
|
// Let's compute the mask of this limb representing the limb as being full
|
||||||
genint_limb_ct mask = s->mask0;
|
genint_limb_ct mask = s->mask0;
|
||||||
mask = (i == s->max) ? mask : GENINT_FULL_MASK;
|
mask = (i == s->max) ? mask : GENINT_FULL_MASK;
|
||||||
@@ -167,12 +167,12 @@ genint_pop(genint_t s)
|
|||||||
// If it is now full, we have been preempted by another.
|
// If it is now full, we have been preempted by another.
|
||||||
if (M_UNLIKELY (org == mask))
|
if (M_UNLIKELY (org == mask))
|
||||||
goto next_element;
|
goto next_element;
|
||||||
assert (org != GENINT_FULL_MASK);
|
M_ASSERT (org != GENINT_FULL_MASK);
|
||||||
// At least one bit is free in the limb. Find one.
|
// At least one bit is free in the limb. Find one.
|
||||||
bit = GENINT_LIMBSIZE - 1 - m_core_clz64(~org);
|
bit = GENINT_LIMBSIZE - 1 - m_core_clz64(~org);
|
||||||
assert (bit < GENINT_LIMBSIZE);
|
M_ASSERT (bit < GENINT_LIMBSIZE);
|
||||||
assert ((org & (GENINT_ONE<<bit)) == 0);
|
M_ASSERT ((org & (GENINT_ONE<<bit)) == 0);
|
||||||
assert (i * GENINT_LIMBSIZE + GENINT_LIMBSIZE - 1 - bit < s->n);
|
M_ASSERT (i * GENINT_LIMBSIZE + GENINT_LIMBSIZE - 1 - bit < s->n);
|
||||||
// Set the integer as being used.
|
// Set the integer as being used.
|
||||||
next = org | (GENINT_ONE << bit);
|
next = org | (GENINT_ONE << bit);
|
||||||
// Try to reserve the integer
|
// Try to reserve the integer
|
||||||
@@ -210,14 +210,14 @@ static inline void
|
|||||||
genint_push(genint_t s, unsigned int n)
|
genint_push(genint_t s, unsigned int n)
|
||||||
{
|
{
|
||||||
GENINT_CONTRACT(s);
|
GENINT_CONTRACT(s);
|
||||||
assert (n < s->n);
|
M_ASSERT (n < s->n);
|
||||||
const unsigned int i = n / GENINT_LIMBSIZE;
|
const unsigned int i = n / GENINT_LIMBSIZE;
|
||||||
const unsigned int bit = GENINT_LIMBSIZE - 1 - (n % GENINT_LIMBSIZE);
|
const unsigned int bit = GENINT_LIMBSIZE - 1 - (n % GENINT_LIMBSIZE);
|
||||||
genint_limb_ct master = atomic_load(&s->master);
|
genint_limb_ct master = atomic_load(&s->master);
|
||||||
// Load the limb
|
// Load the limb
|
||||||
genint_limb_ct next, org = atomic_load(&s->data[i]);
|
genint_limb_ct next, org = atomic_load(&s->data[i]);
|
||||||
do {
|
do {
|
||||||
assert ((org & (GENINT_ONE << bit)) != 0);
|
M_ASSERT ((org & (GENINT_ONE << bit)) != 0);
|
||||||
// Reset it
|
// Reset it
|
||||||
next = org & (~(GENINT_ONE << bit));
|
next = org & (~(GENINT_ONE << bit));
|
||||||
// Try to unreserve it.
|
// Try to unreserve it.
|
||||||
|
|||||||
+45
-45
@@ -127,20 +127,20 @@ typedef struct ilist_head_s {
|
|||||||
|
|
||||||
/* Contract respected by all intrusive lists */
|
/* Contract respected by all intrusive lists */
|
||||||
#define ILISTI_CONTRACT(name, list) do { \
|
#define ILISTI_CONTRACT(name, list) do { \
|
||||||
assert(list != NULL); \
|
M_ASSERT(list != NULL); \
|
||||||
assert(list->name.prev != NULL); \
|
M_ASSERT(list->name.prev != NULL); \
|
||||||
assert(list->name.next != NULL); \
|
M_ASSERT(list->name.next != NULL); \
|
||||||
assert(list->name.next->prev == &list->name); \
|
M_ASSERT(list->name.next->prev == &list->name); \
|
||||||
assert(list->name.prev->next == &list->name); \
|
M_ASSERT(list->name.prev->next == &list->name); \
|
||||||
assert(!(list->name.prev == &list->name) || list->name.prev == list->name.next); \
|
M_ASSERT(!(list->name.prev == &list->name) || list->name.prev == list->name.next); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define ILISTI_NODE_CONTRACT(node) do { \
|
#define ILISTI_NODE_CONTRACT(node) do { \
|
||||||
assert((node) != NULL); \
|
M_ASSERT((node) != NULL); \
|
||||||
assert((node)->prev != NULL); \
|
M_ASSERT((node)->prev != NULL); \
|
||||||
assert((node)->next != NULL); \
|
M_ASSERT((node)->next != NULL); \
|
||||||
assert((node)->next->prev == node); \
|
M_ASSERT((node)->next->prev == node); \
|
||||||
assert((node)->prev->next == node); \
|
M_ASSERT((node)->prev->next == node); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
/* Indirection call to allow expanding all arguments (TBC) */
|
/* Indirection call to allow expanding all arguments (TBC) */
|
||||||
@@ -192,7 +192,7 @@ typedef struct ilist_head_s {
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _init)(list_t list) \
|
M_C(name, _init)(list_t list) \
|
||||||
{ \
|
{ \
|
||||||
assert (list != NULL); \
|
M_ASSERT (list != NULL); \
|
||||||
list->name.next = &list->name; \
|
list->name.next = &list->name; \
|
||||||
list->name.prev = &list->name; \
|
list->name.prev = &list->name; \
|
||||||
ILISTI_CONTRACT(name, list); \
|
ILISTI_CONTRACT(name, list); \
|
||||||
@@ -209,7 +209,7 @@ typedef struct ilist_head_s {
|
|||||||
struct ilist_head_s, name); \
|
struct ilist_head_s, name); \
|
||||||
/* Read next now before the object is destroyed */ \
|
/* Read next now before the object is destroyed */ \
|
||||||
next = it->next; \
|
next = it->next; \
|
||||||
assert (next != NULL); \
|
M_ASSERT (next != NULL); \
|
||||||
M_CALL_CLEAR(oplist, *obj); \
|
M_CALL_CLEAR(oplist, *obj); \
|
||||||
/* Delete also the object if a DELETE operand is registered */ \
|
/* Delete also the object if a DELETE operand is registered */ \
|
||||||
M_IF_METHOD(DEL, oplist)(M_CALL_DEL(oplist, obj), (void) 0); \
|
M_IF_METHOD(DEL, oplist)(M_CALL_DEL(oplist, obj), (void) 0); \
|
||||||
@@ -242,7 +242,7 @@ typedef struct ilist_head_s {
|
|||||||
M_C(name, _init_move)(list_t list, list_t ref) \
|
M_C(name, _init_move)(list_t list, list_t ref) \
|
||||||
{ \
|
{ \
|
||||||
ILISTI_CONTRACT(name, ref); \
|
ILISTI_CONTRACT(name, ref); \
|
||||||
assert (list != ref); \
|
M_ASSERT (list != ref); \
|
||||||
M_C(name,_init)(list); \
|
M_C(name,_init)(list); \
|
||||||
if (!M_C(name,_empty_p)(ref)) { \
|
if (!M_C(name,_empty_p)(ref)) { \
|
||||||
list->name.next = ref->name.next; \
|
list->name.next = ref->name.next; \
|
||||||
@@ -280,7 +280,7 @@ typedef struct ilist_head_s {
|
|||||||
M_C(name, _push_back)(list_t list, type *obj) \
|
M_C(name, _push_back)(list_t list, type *obj) \
|
||||||
{ \
|
{ \
|
||||||
ILISTI_CONTRACT(name, list); \
|
ILISTI_CONTRACT(name, list); \
|
||||||
assert (obj != NULL); \
|
M_ASSERT (obj != NULL); \
|
||||||
struct ilist_head_s *prev = list->name.prev; \
|
struct ilist_head_s *prev = list->name.prev; \
|
||||||
list->name.prev = &obj->name; \
|
list->name.prev = &obj->name; \
|
||||||
obj->name.prev = prev; \
|
obj->name.prev = prev; \
|
||||||
@@ -293,7 +293,7 @@ typedef struct ilist_head_s {
|
|||||||
M_C(name, _push_front)(list_t list, type *obj) \
|
M_C(name, _push_front)(list_t list, type *obj) \
|
||||||
{ \
|
{ \
|
||||||
ILISTI_CONTRACT(name, list); \
|
ILISTI_CONTRACT(name, list); \
|
||||||
assert (obj != NULL); \
|
M_ASSERT (obj != NULL); \
|
||||||
struct ilist_head_s *next = list->name.next; \
|
struct ilist_head_s *next = list->name.next; \
|
||||||
list->name.next = &obj->name; \
|
list->name.next = &obj->name; \
|
||||||
obj->name.next = next; \
|
obj->name.next = next; \
|
||||||
@@ -305,7 +305,7 @@ typedef struct ilist_head_s {
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _push_after)(type *obj_pos, type *obj) \
|
M_C(name, _push_after)(type *obj_pos, type *obj) \
|
||||||
{ \
|
{ \
|
||||||
assert (obj_pos != NULL && obj != NULL); \
|
M_ASSERT (obj_pos != NULL && obj != NULL); \
|
||||||
/* We don't have the list, so we have no contract at list level */ \
|
/* We don't have the list, so we have no contract at list level */ \
|
||||||
ILISTI_NODE_CONTRACT(&obj_pos->name); \
|
ILISTI_NODE_CONTRACT(&obj_pos->name); \
|
||||||
struct ilist_head_s *next = obj_pos->name.next; \
|
struct ilist_head_s *next = obj_pos->name.next; \
|
||||||
@@ -318,7 +318,7 @@ typedef struct ilist_head_s {
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _init_field)(type *obj) \
|
M_C(name, _init_field)(type *obj) \
|
||||||
{ \
|
{ \
|
||||||
assert (obj != NULL); \
|
M_ASSERT (obj != NULL); \
|
||||||
/* Init the fields of the node. To be used in object constructor */ \
|
/* Init the fields of the node. To be used in object constructor */ \
|
||||||
obj->name.next = NULL; \
|
obj->name.next = NULL; \
|
||||||
obj->name.prev = NULL; \
|
obj->name.prev = NULL; \
|
||||||
@@ -327,7 +327,7 @@ typedef struct ilist_head_s {
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _unlink)(type *obj) \
|
M_C(name, _unlink)(type *obj) \
|
||||||
{ \
|
{ \
|
||||||
assert (obj != NULL); \
|
M_ASSERT (obj != NULL); \
|
||||||
/* We don't have the list, so we have no contract at list level */ \
|
/* We don't have the list, so we have no contract at list level */ \
|
||||||
ILISTI_NODE_CONTRACT(&obj->name); \
|
ILISTI_NODE_CONTRACT(&obj->name); \
|
||||||
struct ilist_head_s *next = obj->name.next; \
|
struct ilist_head_s *next = obj->name.next; \
|
||||||
@@ -343,7 +343,7 @@ typedef struct ilist_head_s {
|
|||||||
M_C(name, _back)(const list_t list) \
|
M_C(name, _back)(const list_t list) \
|
||||||
{ \
|
{ \
|
||||||
ILISTI_CONTRACT(name, list); \
|
ILISTI_CONTRACT(name, list); \
|
||||||
assert(!M_C(name, _empty_p)(list)); \
|
M_ASSERT(!M_C(name, _empty_p)(list)); \
|
||||||
return M_TYPE_FROM_FIELD(type, list->name.prev, \
|
return M_TYPE_FROM_FIELD(type, list->name.prev, \
|
||||||
struct ilist_head_s, name); \
|
struct ilist_head_s, name); \
|
||||||
} \
|
} \
|
||||||
@@ -352,7 +352,7 @@ typedef struct ilist_head_s {
|
|||||||
M_C(name, _front)(const list_t list) \
|
M_C(name, _front)(const list_t list) \
|
||||||
{ \
|
{ \
|
||||||
ILISTI_CONTRACT(name, list); \
|
ILISTI_CONTRACT(name, list); \
|
||||||
assert(!M_C(name, _empty_p)(list)); \
|
M_ASSERT(!M_C(name, _empty_p)(list)); \
|
||||||
return M_TYPE_FROM_FIELD(type, list->name.next, \
|
return M_TYPE_FROM_FIELD(type, list->name.next, \
|
||||||
struct ilist_head_s, name); \
|
struct ilist_head_s, name); \
|
||||||
} \
|
} \
|
||||||
@@ -361,7 +361,7 @@ typedef struct ilist_head_s {
|
|||||||
M_C(name, _next_obj)(const list_t list, type const *obj) \
|
M_C(name, _next_obj)(const list_t list, type const *obj) \
|
||||||
{ \
|
{ \
|
||||||
ILISTI_CONTRACT(name, list); \
|
ILISTI_CONTRACT(name, list); \
|
||||||
assert (obj != NULL); \
|
M_ASSERT (obj != NULL); \
|
||||||
ILISTI_NODE_CONTRACT(&obj->name); \
|
ILISTI_NODE_CONTRACT(&obj->name); \
|
||||||
return obj->name.next == &list->name ? NULL : \
|
return obj->name.next == &list->name ? NULL : \
|
||||||
M_TYPE_FROM_FIELD(type, obj->name.next, \
|
M_TYPE_FROM_FIELD(type, obj->name.next, \
|
||||||
@@ -372,7 +372,7 @@ typedef struct ilist_head_s {
|
|||||||
M_C(name, _previous_obj)(const list_t list, type const *obj) \
|
M_C(name, _previous_obj)(const list_t list, type const *obj) \
|
||||||
{ \
|
{ \
|
||||||
ILISTI_CONTRACT(name, list); \
|
ILISTI_CONTRACT(name, list); \
|
||||||
assert (obj != NULL); \
|
M_ASSERT (obj != NULL); \
|
||||||
ILISTI_NODE_CONTRACT(&obj->name); \
|
ILISTI_NODE_CONTRACT(&obj->name); \
|
||||||
return obj->name.prev == &list->name ? NULL : \
|
return obj->name.prev == &list->name ? NULL : \
|
||||||
M_TYPE_FROM_FIELD(type, obj->name.prev, \
|
M_TYPE_FROM_FIELD(type, obj->name.prev, \
|
||||||
@@ -383,7 +383,7 @@ typedef struct ilist_head_s {
|
|||||||
M_C(name, _it)(it_t it, const list_t list) \
|
M_C(name, _it)(it_t it, const list_t list) \
|
||||||
{ \
|
{ \
|
||||||
ILISTI_CONTRACT(name, list); \
|
ILISTI_CONTRACT(name, list); \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
it->head = list->name.next->prev; \
|
it->head = list->name.next->prev; \
|
||||||
it->current = list->name.next; \
|
it->current = list->name.next; \
|
||||||
it->next = list->name.next->next; \
|
it->next = list->name.next->next; \
|
||||||
@@ -394,7 +394,7 @@ typedef struct ilist_head_s {
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _it_set)(it_t it, const it_t cit) \
|
M_C(name, _it_set)(it_t it, const it_t cit) \
|
||||||
{ \
|
{ \
|
||||||
assert (it != NULL && cit != NULL); \
|
M_ASSERT (it != NULL && cit != NULL); \
|
||||||
it->head = cit->head; \
|
it->head = cit->head; \
|
||||||
it->current = cit->current; \
|
it->current = cit->current; \
|
||||||
it->next = cit->next; \
|
it->next = cit->next; \
|
||||||
@@ -406,7 +406,7 @@ typedef struct ilist_head_s {
|
|||||||
M_C(name, _it_last)(it_t it, list_t const list) \
|
M_C(name, _it_last)(it_t it, list_t const list) \
|
||||||
{ \
|
{ \
|
||||||
ILISTI_CONTRACT(name, list); \
|
ILISTI_CONTRACT(name, list); \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
it->head = list->name.next->prev; \
|
it->head = list->name.next->prev; \
|
||||||
it->current = list->name.prev; \
|
it->current = list->name.prev; \
|
||||||
it->next = it->head; \
|
it->next = it->head; \
|
||||||
@@ -417,7 +417,7 @@ typedef struct ilist_head_s {
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _it_end)(it_t it, list_t const list) \
|
M_C(name, _it_end)(it_t it, list_t const list) \
|
||||||
{ \
|
{ \
|
||||||
assert (it != NULL && list != NULL); \
|
M_ASSERT (it != NULL && list != NULL); \
|
||||||
it->head = list->name.next->prev; \
|
it->head = list->name.next->prev; \
|
||||||
it->current = it->head; \
|
it->current = it->head; \
|
||||||
it->next = list->name.next; \
|
it->next = list->name.next; \
|
||||||
@@ -428,7 +428,7 @@ typedef struct ilist_head_s {
|
|||||||
static inline bool \
|
static inline bool \
|
||||||
M_C(name, _end_p)(const it_t it) \
|
M_C(name, _end_p)(const it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
ILISTI_NODE_CONTRACT(it->current); \
|
ILISTI_NODE_CONTRACT(it->current); \
|
||||||
return it->current == it->head; \
|
return it->current == it->head; \
|
||||||
} \
|
} \
|
||||||
@@ -436,7 +436,7 @@ typedef struct ilist_head_s {
|
|||||||
static inline bool \
|
static inline bool \
|
||||||
M_C(name, _last_p)(const it_t it) \
|
M_C(name, _last_p)(const it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
ILISTI_NODE_CONTRACT(it->current); \
|
ILISTI_NODE_CONTRACT(it->current); \
|
||||||
return it->next == it->head || it->current == it->head; \
|
return it->next == it->head || it->current == it->head; \
|
||||||
} \
|
} \
|
||||||
@@ -444,37 +444,37 @@ typedef struct ilist_head_s {
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _next)(it_t it) \
|
M_C(name, _next)(it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
/* Cannot check node for it->current: it may have been deleted! */ \
|
/* Cannot check node for it->current: it may have been deleted! */ \
|
||||||
/* Note: Can't set it->previous to it->current. \
|
/* Note: Can't set it->previous to it->current. \
|
||||||
it->current may have been unlinked from the list */ \
|
it->current may have been unlinked from the list */ \
|
||||||
it->current = it->next; \
|
it->current = it->next; \
|
||||||
assert (it->current != NULL); \
|
M_ASSERT (it->current != NULL); \
|
||||||
it->next = it->current->next; \
|
it->next = it->current->next; \
|
||||||
it->previous = it->current->prev; \
|
it->previous = it->current->prev; \
|
||||||
assert (it->next != NULL && it->previous != NULL); \
|
M_ASSERT (it->next != NULL && it->previous != NULL); \
|
||||||
ILISTI_NODE_CONTRACT(it->current); \
|
ILISTI_NODE_CONTRACT(it->current); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _previous)(it_t it) \
|
M_C(name, _previous)(it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
/* Cannot check node for it->current: it may have been deleted! */ \
|
/* Cannot check node for it->current: it may have been deleted! */ \
|
||||||
/* Note: Can't set it->next to it->current. \
|
/* Note: Can't set it->next to it->current. \
|
||||||
it->current may have been unlinked from the list */ \
|
it->current may have been unlinked from the list */ \
|
||||||
it->current = it->previous; \
|
it->current = it->previous; \
|
||||||
assert (it->current != NULL); \
|
M_ASSERT (it->current != NULL); \
|
||||||
it->next = it->current->next; \
|
it->next = it->current->next; \
|
||||||
it->previous = it->current->prev; \
|
it->previous = it->current->prev; \
|
||||||
assert (it->next != NULL && it->previous != NULL); \
|
M_ASSERT (it->next != NULL && it->previous != NULL); \
|
||||||
ILISTI_NODE_CONTRACT(it->current); \
|
ILISTI_NODE_CONTRACT(it->current); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline bool \
|
static inline bool \
|
||||||
M_C(name, _it_equal_p)(const it_t it1, const it_t it2 ) \
|
M_C(name, _it_equal_p)(const it_t it1, const it_t it2 ) \
|
||||||
{ \
|
{ \
|
||||||
assert (it1 != NULL && it2 != NULL); \
|
M_ASSERT (it1 != NULL && it2 != NULL); \
|
||||||
/* No need to check for next & previous */ \
|
/* No need to check for next & previous */ \
|
||||||
return it1->head == it2->head && it1->current == it2->current; \
|
return it1->head == it2->head && it1->current == it2->current; \
|
||||||
} \
|
} \
|
||||||
@@ -482,12 +482,12 @@ typedef struct ilist_head_s {
|
|||||||
static inline type * \
|
static inline type * \
|
||||||
M_C(name, _ref)(const it_t it) \
|
M_C(name, _ref)(const it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert (it != NULL && it->current != NULL); \
|
M_ASSERT (it != NULL && it->current != NULL); \
|
||||||
ILISTI_NODE_CONTRACT(it->current); \
|
ILISTI_NODE_CONTRACT(it->current); \
|
||||||
/* check if 'it' was not deleted */ \
|
/* check if 'it' was not deleted */ \
|
||||||
assert (it->current->next == it->next); \
|
M_ASSERT (it->current->next == it->next); \
|
||||||
assert (it->current->prev == it->previous); \
|
M_ASSERT (it->current->prev == it->previous); \
|
||||||
assert (!M_C(name, _end_p)(it)); \
|
M_ASSERT (!M_C(name, _end_p)(it)); \
|
||||||
return M_TYPE_FROM_FIELD(type, it->current, \
|
return M_TYPE_FROM_FIELD(type, it->current, \
|
||||||
struct ilist_head_s, name); \
|
struct ilist_head_s, name); \
|
||||||
} \
|
} \
|
||||||
@@ -537,7 +537,7 @@ typedef struct ilist_head_s {
|
|||||||
M_C(name, _pop_back)(list_t list) \
|
M_C(name, _pop_back)(list_t list) \
|
||||||
{ \
|
{ \
|
||||||
ILISTI_CONTRACT(name, list); \
|
ILISTI_CONTRACT(name, list); \
|
||||||
assert (!M_C(name, _empty_p)(list)); \
|
M_ASSERT (!M_C(name, _empty_p)(list)); \
|
||||||
type *obj = M_C(name, _back)(list); \
|
type *obj = M_C(name, _back)(list); \
|
||||||
list->name.prev = list->name.prev->prev; \
|
list->name.prev = list->name.prev->prev; \
|
||||||
list->name.prev->next = &list->name; \
|
list->name.prev->next = &list->name; \
|
||||||
@@ -548,7 +548,7 @@ typedef struct ilist_head_s {
|
|||||||
M_C(name, _pop_front)(list_t list) \
|
M_C(name, _pop_front)(list_t list) \
|
||||||
{ \
|
{ \
|
||||||
ILISTI_CONTRACT(name, list); \
|
ILISTI_CONTRACT(name, list); \
|
||||||
assert (!M_C(name, _empty_p)(list)); \
|
M_ASSERT (!M_C(name, _empty_p)(list)); \
|
||||||
type *obj = M_C(name, _front)(list); \
|
type *obj = M_C(name, _front)(list); \
|
||||||
list->name.next = list->name.next->next; \
|
list->name.next = list->name.next->next; \
|
||||||
list->name.next->prev = &list->name; \
|
list->name.next->prev = &list->name; \
|
||||||
@@ -578,7 +578,7 @@ typedef struct ilist_head_s {
|
|||||||
ILISTI_CONTRACT(name, nv); \
|
ILISTI_CONTRACT(name, nv); \
|
||||||
ILISTI_CONTRACT(name, ov); \
|
ILISTI_CONTRACT(name, ov); \
|
||||||
ILISTI_NODE_CONTRACT(it->current); \
|
ILISTI_NODE_CONTRACT(it->current); \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
(void) ov; \
|
(void) ov; \
|
||||||
type *obj = M_C(name, _ref)(it); \
|
type *obj = M_C(name, _ref)(it); \
|
||||||
M_C(name, _unlink)(obj); \
|
M_C(name, _unlink)(obj); \
|
||||||
@@ -594,8 +594,8 @@ typedef struct ilist_head_s {
|
|||||||
{ \
|
{ \
|
||||||
ILISTI_CONTRACT(name, nlist); \
|
ILISTI_CONTRACT(name, nlist); \
|
||||||
ILISTI_CONTRACT(name, olist); \
|
ILISTI_CONTRACT(name, olist); \
|
||||||
assert (npos != NULL && opos != NULL); \
|
M_ASSERT (npos != NULL && opos != NULL); \
|
||||||
assert (!M_C(name, _end_p)(opos)); \
|
M_ASSERT (!M_C(name, _end_p)(opos)); \
|
||||||
/* npos may be end */ \
|
/* npos may be end */ \
|
||||||
(void) olist, (void) nlist; \
|
(void) olist, (void) nlist; \
|
||||||
type *obj = M_C(name, _ref)(opos); \
|
type *obj = M_C(name, _ref)(opos); \
|
||||||
|
|||||||
+3
-3
@@ -140,7 +140,7 @@ M_BEGIN_PROTECTED_CODE
|
|||||||
static inline void M_ATTR_DEPRECATED \
|
static inline void M_ATTR_DEPRECATED \
|
||||||
M_C(name, _init_set2)(shared_t *ptr, shared_t shared) \
|
M_C(name, _init_set2)(shared_t *ptr, shared_t shared) \
|
||||||
{ \
|
{ \
|
||||||
assert (ptr != NULL); \
|
M_ASSERT (ptr != NULL); \
|
||||||
*ptr = M_C(name, _init_set)(shared); \
|
*ptr = M_C(name, _init_set)(shared); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
@@ -176,7 +176,7 @@ M_BEGIN_PROTECTED_CODE
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _clear_ptr)(shared_t *shared) \
|
M_C(name, _clear_ptr)(shared_t *shared) \
|
||||||
{ \
|
{ \
|
||||||
assert(shared != NULL); \
|
M_ASSERT(shared != NULL); \
|
||||||
M_C(name, _clear)(*shared); \
|
M_C(name, _clear)(*shared); \
|
||||||
*shared = NULL; \
|
*shared = NULL; \
|
||||||
} \
|
} \
|
||||||
@@ -191,7 +191,7 @@ M_BEGIN_PROTECTED_CODE
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _set)(shared_t *ptr, shared_t shared) \
|
M_C(name, _set)(shared_t *ptr, shared_t shared) \
|
||||||
{ \
|
{ \
|
||||||
assert (ptr != NULL); \
|
M_ASSERT (ptr != NULL); \
|
||||||
if (M_LIKELY (*ptr != shared)) { \
|
if (M_LIKELY (*ptr != shared)) { \
|
||||||
M_C(name, _clear)(*ptr); \
|
M_C(name, _clear)(*ptr); \
|
||||||
*ptr = M_C(name, _init_set)(shared); \
|
*ptr = M_C(name, _init_set)(shared); \
|
||||||
|
|||||||
@@ -213,7 +213,7 @@
|
|||||||
/* Define the internal contract of a list
|
/* Define the internal contract of a list
|
||||||
(there is nothing worthy to be checked) */
|
(there is nothing worthy to be checked) */
|
||||||
#define LISTI_CONTRACT(v) do { \
|
#define LISTI_CONTRACT(v) do { \
|
||||||
assert (v != NULL); \
|
M_ASSERT (v != NULL); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
|
||||||
@@ -229,7 +229,7 @@
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _init)(list_t v) \
|
M_C(name, _init)(list_t v) \
|
||||||
{ \
|
{ \
|
||||||
assert (v != NULL); \
|
M_ASSERT (v != NULL); \
|
||||||
*v = NULL; \
|
*v = NULL; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
@@ -258,7 +258,7 @@
|
|||||||
M_C(name, _back)(const list_t v) \
|
M_C(name, _back)(const list_t v) \
|
||||||
{ \
|
{ \
|
||||||
LISTI_CONTRACT(v); \
|
LISTI_CONTRACT(v); \
|
||||||
assert(*v != NULL); \
|
M_ASSERT(*v != NULL); \
|
||||||
return M_CONST_CAST(type, &((*v)->data)); \
|
return M_CONST_CAST(type, &((*v)->data)); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
@@ -304,7 +304,7 @@
|
|||||||
M_C(name, _pop_back)(type *data, list_t v) \
|
M_C(name, _pop_back)(type *data, list_t v) \
|
||||||
{ \
|
{ \
|
||||||
LISTI_CONTRACT(v); \
|
LISTI_CONTRACT(v); \
|
||||||
assert(*v != NULL); \
|
M_ASSERT(*v != NULL); \
|
||||||
if (data != NULL) { \
|
if (data != NULL) { \
|
||||||
M_DO_MOVE (oplist, *data, (*v)->data); \
|
M_DO_MOVE (oplist, *data, (*v)->data); \
|
||||||
} else { \
|
} else { \
|
||||||
@@ -319,7 +319,7 @@
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _push_move)(list_t v, type *x) \
|
M_C(name, _push_move)(list_t v, type *x) \
|
||||||
{ \
|
{ \
|
||||||
assert (x != NULL); \
|
M_ASSERT (x != NULL); \
|
||||||
type *data = M_C(name, _push_raw)(v); \
|
type *data = M_C(name, _push_raw)(v); \
|
||||||
if (M_UNLIKELY (data == NULL)) \
|
if (M_UNLIKELY (data == NULL)) \
|
||||||
return; \
|
return; \
|
||||||
@@ -330,7 +330,7 @@
|
|||||||
M_C(name, _pop_move)(type *data, list_t v) \
|
M_C(name, _pop_move)(type *data, list_t v) \
|
||||||
{ \
|
{ \
|
||||||
LISTI_CONTRACT(v); \
|
LISTI_CONTRACT(v); \
|
||||||
assert(*v != NULL && data != NULL); \
|
M_ASSERT(*v != NULL && data != NULL); \
|
||||||
M_DO_INIT_MOVE (oplist, *data, (*v)->data); \
|
M_DO_INIT_MOVE (oplist, *data, (*v)->data); \
|
||||||
struct M_C(name, _s) *tofree = *v; \
|
struct M_C(name, _s) *tofree = *v; \
|
||||||
*v = (*v)->next; \
|
*v = (*v)->next; \
|
||||||
@@ -361,7 +361,7 @@
|
|||||||
M_C(name, _it)(it_t it, const list_t v) \
|
M_C(name, _it)(it_t it, const list_t v) \
|
||||||
{ \
|
{ \
|
||||||
LISTI_CONTRACT(v); \
|
LISTI_CONTRACT(v); \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
it->current = *v; \
|
it->current = *v; \
|
||||||
it->previous = NULL; \
|
it->previous = NULL; \
|
||||||
} \
|
} \
|
||||||
@@ -369,7 +369,7 @@
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _it_set)(it_t it1, const it_t it2) \
|
M_C(name, _it_set)(it_t it1, const it_t it2) \
|
||||||
{ \
|
{ \
|
||||||
assert (it1 != NULL && it2 != NULL); \
|
M_ASSERT (it1 != NULL && it2 != NULL); \
|
||||||
it1->current = it2->current; \
|
it1->current = it2->current; \
|
||||||
it1->previous = it2->previous; \
|
it1->previous = it2->previous; \
|
||||||
} \
|
} \
|
||||||
@@ -378,7 +378,7 @@
|
|||||||
M_C(name, _it_end)(it_t it1, const list_t v) \
|
M_C(name, _it_end)(it_t it1, const list_t v) \
|
||||||
{ \
|
{ \
|
||||||
LISTI_CONTRACT(v); \
|
LISTI_CONTRACT(v); \
|
||||||
assert (it1 != NULL); \
|
M_ASSERT (it1 != NULL); \
|
||||||
(void)v; /* unused */ \
|
(void)v; /* unused */ \
|
||||||
it1->current = NULL; \
|
it1->current = NULL; \
|
||||||
it1->previous = NULL; \
|
it1->previous = NULL; \
|
||||||
@@ -387,21 +387,21 @@
|
|||||||
static inline bool \
|
static inline bool \
|
||||||
M_C(name, _end_p)(const it_t it) \
|
M_C(name, _end_p)(const it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
return it->current == NULL; \
|
return it->current == NULL; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline bool \
|
static inline bool \
|
||||||
M_C(name, _last_p)(const it_t it) \
|
M_C(name, _last_p)(const it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
return it->current == NULL || it->current->next == NULL; \
|
return it->current == NULL || it->current->next == NULL; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _next)(it_t it) \
|
M_C(name, _next)(it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert(it != NULL && it->current != NULL); \
|
M_ASSERT(it != NULL && it->current != NULL); \
|
||||||
it->previous = it->current; \
|
it->previous = it->current; \
|
||||||
it->current = it->current->next; \
|
it->current = it->current->next; \
|
||||||
} \
|
} \
|
||||||
@@ -409,21 +409,21 @@
|
|||||||
static inline bool \
|
static inline bool \
|
||||||
M_C(name, _it_equal_p)(const it_t it1, const it_t it2) \
|
M_C(name, _it_equal_p)(const it_t it1, const it_t it2) \
|
||||||
{ \
|
{ \
|
||||||
assert(it1 != NULL && it2 != NULL); \
|
M_ASSERT(it1 != NULL && it2 != NULL); \
|
||||||
return it1->current == it2->current; \
|
return it1->current == it2->current; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline type * \
|
static inline type * \
|
||||||
M_C(name, _ref)(const it_t it) \
|
M_C(name, _ref)(const it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert(it != NULL && it->current != NULL); \
|
M_ASSERT(it != NULL && it->current != NULL); \
|
||||||
return &(it->current->data); \
|
return &(it->current->data); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline type const * \
|
static inline type const * \
|
||||||
M_C(name, _cref)(const it_t it) \
|
M_C(name, _cref)(const it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert(it != NULL && it->current != NULL); \
|
M_ASSERT(it != NULL && it->current != NULL); \
|
||||||
return M_CONST_CAST(type, &(it->current->data)); \
|
return M_CONST_CAST(type, &(it->current->data)); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
@@ -444,7 +444,7 @@
|
|||||||
M_C(name, _sublist_p)(const list_t list, const it_t itsub) \
|
M_C(name, _sublist_p)(const list_t list, const it_t itsub) \
|
||||||
{ \
|
{ \
|
||||||
LISTI_CONTRACT(list); \
|
LISTI_CONTRACT(list); \
|
||||||
assert (itsub != NULL); \
|
M_ASSERT (itsub != NULL); \
|
||||||
struct M_C(name, _s) *it = *list; \
|
struct M_C(name, _s) *it = *list; \
|
||||||
while (it != NULL) { \
|
while (it != NULL) { \
|
||||||
if (it == itsub->current) return true; \
|
if (it == itsub->current) return true; \
|
||||||
@@ -464,7 +464,7 @@
|
|||||||
M_ASSERT_INDEX (i, len); \
|
M_ASSERT_INDEX (i, len); \
|
||||||
size_t j = len-1; \
|
size_t j = len-1; \
|
||||||
while (true) { \
|
while (true) { \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
if (i == j) return &it->data; \
|
if (i == j) return &it->data; \
|
||||||
it = it->next; \
|
it = it->next; \
|
||||||
j--; \
|
j--; \
|
||||||
@@ -482,8 +482,8 @@
|
|||||||
type const x) \
|
type const x) \
|
||||||
{ \
|
{ \
|
||||||
LISTI_CONTRACT(list); \
|
LISTI_CONTRACT(list); \
|
||||||
assert (insertion_point != NULL); \
|
M_ASSERT (insertion_point != NULL); \
|
||||||
assert(M_C(name, _sublist_p)(list, insertion_point)); \
|
M_ASSERT(M_C(name, _sublist_p)(list, insertion_point)); \
|
||||||
struct M_C(name, _s) *next = M_C(name, _int_new)(); \
|
struct M_C(name, _s) *next = M_C(name, _int_new)(); \
|
||||||
if (M_UNLIKELY (next == NULL)) { \
|
if (M_UNLIKELY (next == NULL)) { \
|
||||||
M_MEMORY_FULL(sizeof (struct M_C(name, _s))); \
|
M_MEMORY_FULL(sizeof (struct M_C(name, _s))); \
|
||||||
@@ -507,9 +507,9 @@
|
|||||||
M_C(name, _remove)(list_t list, it_t removing_point) \
|
M_C(name, _remove)(list_t list, it_t removing_point) \
|
||||||
{ \
|
{ \
|
||||||
LISTI_CONTRACT(list); \
|
LISTI_CONTRACT(list); \
|
||||||
assert (removing_point != NULL); \
|
M_ASSERT (removing_point != NULL); \
|
||||||
assert (removing_point->current != NULL); \
|
M_ASSERT (removing_point->current != NULL); \
|
||||||
assert(M_C(name, _sublist_p)(list, removing_point)); \
|
M_ASSERT(M_C(name, _sublist_p)(list, removing_point)); \
|
||||||
struct M_C(name, _s) *next = removing_point->current->next; \
|
struct M_C(name, _s) *next = removing_point->current->next; \
|
||||||
if (M_UNLIKELY (removing_point->previous == NULL)) { \
|
if (M_UNLIKELY (removing_point->previous == NULL)) { \
|
||||||
*list = next; \
|
*list = next; \
|
||||||
@@ -558,7 +558,7 @@
|
|||||||
M_C(name, _init_move)(list_t list, list_t org) \
|
M_C(name, _init_move)(list_t list, list_t org) \
|
||||||
{ \
|
{ \
|
||||||
LISTI_CONTRACT(org); \
|
LISTI_CONTRACT(org); \
|
||||||
assert (list != NULL && list != org); \
|
M_ASSERT (list != NULL && list != org); \
|
||||||
*list = *org; \
|
*list = *org; \
|
||||||
*org = NULL; /* safer */ \
|
*org = NULL; /* safer */ \
|
||||||
} \
|
} \
|
||||||
@@ -566,7 +566,7 @@
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _move)(list_t list, list_t org) \
|
M_C(name, _move)(list_t list, list_t org) \
|
||||||
{ \
|
{ \
|
||||||
assert (list != org); \
|
M_ASSERT (list != org); \
|
||||||
M_C(name, _clear)(list); \
|
M_C(name, _clear)(list); \
|
||||||
M_C(name, _init_move)(list, org); \
|
M_C(name, _init_move)(list, org); \
|
||||||
} \
|
} \
|
||||||
@@ -576,9 +576,9 @@
|
|||||||
{ \
|
{ \
|
||||||
LISTI_CONTRACT(nv); \
|
LISTI_CONTRACT(nv); \
|
||||||
LISTI_CONTRACT(ov); \
|
LISTI_CONTRACT(ov); \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
assert (it->current != NULL); \
|
M_ASSERT (it->current != NULL); \
|
||||||
assert (M_C(name, _sublist_p)(ov, it)); \
|
M_ASSERT (M_C(name, _sublist_p)(ov, it)); \
|
||||||
/* Remove the item 'it' from the list 'ov' */ \
|
/* Remove the item 'it' from the list 'ov' */ \
|
||||||
struct M_C(name, _s) *current = it->current; \
|
struct M_C(name, _s) *current = it->current; \
|
||||||
struct M_C(name, _s) *next = current->next; \
|
struct M_C(name, _s) *next = current->next; \
|
||||||
@@ -601,10 +601,10 @@
|
|||||||
{ \
|
{ \
|
||||||
LISTI_CONTRACT(nlist); \
|
LISTI_CONTRACT(nlist); \
|
||||||
LISTI_CONTRACT(olist); \
|
LISTI_CONTRACT(olist); \
|
||||||
assert (npos != NULL); \
|
M_ASSERT (npos != NULL); \
|
||||||
assert (opos != NULL); \
|
M_ASSERT (opos != NULL); \
|
||||||
assert (M_C(name, _sublist_p)(nlist, npos)); \
|
M_ASSERT (M_C(name, _sublist_p)(nlist, npos)); \
|
||||||
assert (M_C(name, _sublist_p)(olist, opos)); \
|
M_ASSERT (M_C(name, _sublist_p)(olist, opos)); \
|
||||||
/* Remove the item 'opos' from the list 'olist' */ \
|
/* Remove the item 'opos' from the list 'olist' */ \
|
||||||
struct M_C(name, _s) *current = opos->current; \
|
struct M_C(name, _s) *current = opos->current; \
|
||||||
struct M_C(name, _s) *next = current->next; \
|
struct M_C(name, _s) *next = current->next; \
|
||||||
@@ -636,7 +636,7 @@
|
|||||||
{ \
|
{ \
|
||||||
LISTI_CONTRACT(list1); \
|
LISTI_CONTRACT(list1); \
|
||||||
LISTI_CONTRACT(list2); \
|
LISTI_CONTRACT(list2); \
|
||||||
assert (list1 != list2); \
|
M_ASSERT (list1 != list2); \
|
||||||
struct M_C(name, _s) **update_list = list1; \
|
struct M_C(name, _s) **update_list = list1; \
|
||||||
struct M_C(name, _s) *it = *list1; \
|
struct M_C(name, _s) *it = *list1; \
|
||||||
while (it != NULL) { \
|
while (it != NULL) { \
|
||||||
@@ -679,7 +679,7 @@
|
|||||||
M_C(name, _get_str)(string_t str, const list_t list, \
|
M_C(name, _get_str)(string_t str, const list_t list, \
|
||||||
bool append) \
|
bool append) \
|
||||||
{ \
|
{ \
|
||||||
assert (str != NULL && list != NULL); \
|
M_ASSERT (str != NULL && list != NULL); \
|
||||||
(append ? string_cat_str : string_set_str) (str, "["); \
|
(append ? string_cat_str : string_set_str) (str, "["); \
|
||||||
it_t it; \
|
it_t it; \
|
||||||
for (M_C(name, _it)(it, list) ; \
|
for (M_C(name, _it)(it, list) ; \
|
||||||
@@ -698,7 +698,7 @@
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _out_str)(FILE *file, const list_t list) \
|
M_C(name, _out_str)(FILE *file, const list_t list) \
|
||||||
{ \
|
{ \
|
||||||
assert (file != NULL && list != NULL); \
|
M_ASSERT (file != NULL && list != NULL); \
|
||||||
fputc ('[', file); \
|
fputc ('[', file); \
|
||||||
it_t it; \
|
it_t it; \
|
||||||
for (M_C(name, _it)(it, list) ; \
|
for (M_C(name, _it)(it, list) ; \
|
||||||
@@ -717,7 +717,7 @@
|
|||||||
static inline bool \
|
static inline bool \
|
||||||
M_C(name, _parse_str)(list_t list, const char str[], const char **endp) \
|
M_C(name, _parse_str)(list_t list, const char str[], const char **endp) \
|
||||||
{ \
|
{ \
|
||||||
assert (str != NULL && list != NULL); \
|
M_ASSERT (str != NULL && list != NULL); \
|
||||||
M_C(name,_clean)(list); \
|
M_C(name,_clean)(list); \
|
||||||
bool success = false; \
|
bool success = false; \
|
||||||
int c = *str++; \
|
int c = *str++; \
|
||||||
@@ -748,7 +748,7 @@
|
|||||||
static inline bool \
|
static inline bool \
|
||||||
M_C(name, _in_str)(list_t list, FILE *file) \
|
M_C(name, _in_str)(list_t list, FILE *file) \
|
||||||
{ \
|
{ \
|
||||||
assert (file != NULL && list != NULL); \
|
M_ASSERT (file != NULL && list != NULL); \
|
||||||
M_C(name,_clean)(list); \
|
M_C(name,_clean)(list); \
|
||||||
int c = fgetc(file); \
|
int c = fgetc(file); \
|
||||||
if (M_UNLIKELY (c != '[')) return false; \
|
if (M_UNLIKELY (c != '[')) return false; \
|
||||||
@@ -774,8 +774,8 @@
|
|||||||
static inline m_serial_return_code_t \
|
static inline m_serial_return_code_t \
|
||||||
M_C(name, _out_serial)(m_serial_write_t f, const list_t list) \
|
M_C(name, _out_serial)(m_serial_write_t f, const list_t list) \
|
||||||
{ \
|
{ \
|
||||||
assert (list != NULL); \
|
M_ASSERT (list != NULL); \
|
||||||
assert (f != NULL && f->m_interface != NULL); \
|
M_ASSERT (f != NULL && f->m_interface != NULL); \
|
||||||
m_serial_return_code_t ret; \
|
m_serial_return_code_t ret; \
|
||||||
m_serial_local_t local; \
|
m_serial_local_t local; \
|
||||||
bool first_done = false; \
|
bool first_done = false; \
|
||||||
@@ -799,8 +799,8 @@
|
|||||||
static inline m_serial_return_code_t \
|
static inline m_serial_return_code_t \
|
||||||
M_C(name, _in_serial)(list_t list, m_serial_read_t f) \
|
M_C(name, _in_serial)(list_t list, m_serial_read_t f) \
|
||||||
{ \
|
{ \
|
||||||
assert (list != NULL); \
|
M_ASSERT (list != NULL); \
|
||||||
assert (f != NULL && f->m_interface != NULL); \
|
M_ASSERT (f != NULL && f->m_interface != NULL); \
|
||||||
m_serial_return_code_t ret; \
|
m_serial_return_code_t ret; \
|
||||||
m_serial_local_t local; \
|
m_serial_local_t local; \
|
||||||
size_t estimated_size = 0; \
|
size_t estimated_size = 0; \
|
||||||
@@ -825,7 +825,7 @@
|
|||||||
static inline bool \
|
static inline bool \
|
||||||
M_C(name, _equal_p)(const list_t list1, const list_t list2) \
|
M_C(name, _equal_p)(const list_t list1, const list_t list2) \
|
||||||
{ \
|
{ \
|
||||||
assert (list1 != NULL && list2 != NULL); \
|
M_ASSERT (list1 != NULL && list2 != NULL); \
|
||||||
it_t it1; \
|
it_t it1; \
|
||||||
it_t it2; \
|
it_t it2; \
|
||||||
if (list1 == list2) return true; \
|
if (list1 == list2) return true; \
|
||||||
@@ -849,7 +849,7 @@
|
|||||||
static inline size_t \
|
static inline size_t \
|
||||||
M_C(name, _hash)(const list_t list) \
|
M_C(name, _hash)(const list_t list) \
|
||||||
{ \
|
{ \
|
||||||
assert (list != NULL); \
|
M_ASSERT (list != NULL); \
|
||||||
M_HASH_DECL(hash); \
|
M_HASH_DECL(hash); \
|
||||||
it_t it; \
|
it_t it; \
|
||||||
for(M_C(name, _it)(it, list) ; \
|
for(M_C(name, _it)(it, list) ; \
|
||||||
@@ -923,8 +923,8 @@
|
|||||||
|
|
||||||
/* Define the internal contract of an dual-push list */
|
/* Define the internal contract of an dual-push list */
|
||||||
#define LISTI_DUAL_PUSH_CONTRACT(l) do { \
|
#define LISTI_DUAL_PUSH_CONTRACT(l) do { \
|
||||||
assert (l != NULL); \
|
M_ASSERT (l != NULL); \
|
||||||
assert ( (l->back == NULL && l->front == NULL) \
|
M_ASSERT ( (l->back == NULL && l->front == NULL) \
|
||||||
|| (l->back != NULL && l->front != NULL)); \
|
|| (l->back != NULL && l->front != NULL)); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
@@ -940,7 +940,7 @@
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _init)(list_t v) \
|
M_C(name, _init)(list_t v) \
|
||||||
{ \
|
{ \
|
||||||
assert( v != NULL); \
|
M_ASSERT( v != NULL); \
|
||||||
v->front = NULL; \
|
v->front = NULL; \
|
||||||
v->back = NULL; \
|
v->back = NULL; \
|
||||||
LISTI_DUAL_PUSH_CONTRACT(v); \
|
LISTI_DUAL_PUSH_CONTRACT(v); \
|
||||||
@@ -972,7 +972,7 @@
|
|||||||
M_C(name, _back)(const list_t v) \
|
M_C(name, _back)(const list_t v) \
|
||||||
{ \
|
{ \
|
||||||
LISTI_DUAL_PUSH_CONTRACT(v); \
|
LISTI_DUAL_PUSH_CONTRACT(v); \
|
||||||
assert (v->back != NULL); \
|
M_ASSERT (v->back != NULL); \
|
||||||
return M_CONST_CAST(type, &(v->back->data)); \
|
return M_CONST_CAST(type, &(v->back->data)); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
@@ -1021,7 +1021,7 @@
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _push_back_move)(list_t v, type *x) \
|
M_C(name, _push_back_move)(list_t v, type *x) \
|
||||||
{ \
|
{ \
|
||||||
assert (x != NULL); \
|
M_ASSERT (x != NULL); \
|
||||||
type *data = M_C(name, _push_back_raw)(v); \
|
type *data = M_C(name, _push_back_raw)(v); \
|
||||||
if (M_UNLIKELY (data == NULL)) \
|
if (M_UNLIKELY (data == NULL)) \
|
||||||
return; \
|
return; \
|
||||||
@@ -1038,7 +1038,7 @@
|
|||||||
M_C(name, _pop_back)(type *data, list_t v) \
|
M_C(name, _pop_back)(type *data, list_t v) \
|
||||||
{ \
|
{ \
|
||||||
LISTI_DUAL_PUSH_CONTRACT(v); \
|
LISTI_DUAL_PUSH_CONTRACT(v); \
|
||||||
assert (v->back != NULL); \
|
M_ASSERT (v->back != NULL); \
|
||||||
struct M_C(name, _s) *tofree = v->back; \
|
struct M_C(name, _s) *tofree = v->back; \
|
||||||
if (data != NULL) { \
|
if (data != NULL) { \
|
||||||
M_DO_MOVE(oplist, *data, tofree->data); \
|
M_DO_MOVE(oplist, *data, tofree->data); \
|
||||||
@@ -1059,8 +1059,8 @@
|
|||||||
M_C(name, _pop_move)(type *data, list_t v) \
|
M_C(name, _pop_move)(type *data, list_t v) \
|
||||||
{ \
|
{ \
|
||||||
LISTI_DUAL_PUSH_CONTRACT(v); \
|
LISTI_DUAL_PUSH_CONTRACT(v); \
|
||||||
assert (v->back != NULL); \
|
M_ASSERT (v->back != NULL); \
|
||||||
assert (data != NULL); \
|
M_ASSERT (data != NULL); \
|
||||||
struct M_C(name, _s) *tofree = v->back; \
|
struct M_C(name, _s) *tofree = v->back; \
|
||||||
M_DO_INIT_MOVE (oplist, *data, tofree->data); \
|
M_DO_INIT_MOVE (oplist, *data, tofree->data); \
|
||||||
v->back = tofree->next; \
|
v->back = tofree->next; \
|
||||||
@@ -1077,7 +1077,7 @@
|
|||||||
M_C(name, _front)(list_t v) \
|
M_C(name, _front)(list_t v) \
|
||||||
{ \
|
{ \
|
||||||
LISTI_DUAL_PUSH_CONTRACT(v); \
|
LISTI_DUAL_PUSH_CONTRACT(v); \
|
||||||
assert (v->front != NULL); \
|
M_ASSERT (v->front != NULL); \
|
||||||
return M_CONST_CAST(type, &(v->front->data)); \
|
return M_CONST_CAST(type, &(v->front->data)); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
@@ -1115,7 +1115,7 @@
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _push_front_move)(list_t v, type *x) \
|
M_C(name, _push_front_move)(list_t v, type *x) \
|
||||||
{ \
|
{ \
|
||||||
assert (x != NULL); \
|
M_ASSERT (x != NULL); \
|
||||||
type *data = M_C(name, _push_front_raw)(v); \
|
type *data = M_C(name, _push_front_raw)(v); \
|
||||||
if (M_UNLIKELY (data == NULL)) \
|
if (M_UNLIKELY (data == NULL)) \
|
||||||
return; \
|
return; \
|
||||||
@@ -1154,7 +1154,7 @@
|
|||||||
M_C(name, _it)(it_t it, const list_t v) \
|
M_C(name, _it)(it_t it, const list_t v) \
|
||||||
{ \
|
{ \
|
||||||
LISTI_DUAL_PUSH_CONTRACT(v); \
|
LISTI_DUAL_PUSH_CONTRACT(v); \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
it->current = v->back; \
|
it->current = v->back; \
|
||||||
it->previous = NULL; \
|
it->previous = NULL; \
|
||||||
} \
|
} \
|
||||||
@@ -1162,7 +1162,7 @@
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _it_set)(it_t it1, const it_t it2) \
|
M_C(name, _it_set)(it_t it1, const it_t it2) \
|
||||||
{ \
|
{ \
|
||||||
assert (it1 != NULL && it2 != NULL); \
|
M_ASSERT (it1 != NULL && it2 != NULL); \
|
||||||
it1->current = it2->current; \
|
it1->current = it2->current; \
|
||||||
it1->previous = it2->previous; \
|
it1->previous = it2->previous; \
|
||||||
} \
|
} \
|
||||||
@@ -1170,7 +1170,7 @@
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _it_end)(it_t it1, const list_t v) \
|
M_C(name, _it_end)(it_t it1, const list_t v) \
|
||||||
{ \
|
{ \
|
||||||
assert (it1 != NULL); \
|
M_ASSERT (it1 != NULL); \
|
||||||
LISTI_DUAL_PUSH_CONTRACT(v); \
|
LISTI_DUAL_PUSH_CONTRACT(v); \
|
||||||
(void)v; /* unused */ \
|
(void)v; /* unused */ \
|
||||||
it1->current = NULL; \
|
it1->current = NULL; \
|
||||||
@@ -1180,21 +1180,21 @@
|
|||||||
static inline bool \
|
static inline bool \
|
||||||
M_C(name, _end_p)(const it_t it) \
|
M_C(name, _end_p)(const it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
return it->current == NULL; \
|
return it->current == NULL; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline bool \
|
static inline bool \
|
||||||
M_C(name, _last_p)(const it_t it) \
|
M_C(name, _last_p)(const it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
return it->current == NULL || it->current->next == NULL; \
|
return it->current == NULL || it->current->next == NULL; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _next)(it_t it) \
|
M_C(name, _next)(it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert(it != NULL && it->current != NULL); \
|
M_ASSERT(it != NULL && it->current != NULL); \
|
||||||
it->previous = it->current; \
|
it->previous = it->current; \
|
||||||
it->current = it->current->next; \
|
it->current = it->current->next; \
|
||||||
} \
|
} \
|
||||||
@@ -1202,21 +1202,21 @@
|
|||||||
static inline bool \
|
static inline bool \
|
||||||
M_C(name, _it_equal_p)(const it_t it1, const it_t it2) \
|
M_C(name, _it_equal_p)(const it_t it1, const it_t it2) \
|
||||||
{ \
|
{ \
|
||||||
assert(it1 != NULL && it2 != NULL); \
|
M_ASSERT(it1 != NULL && it2 != NULL); \
|
||||||
return it1->current == it2->current; \
|
return it1->current == it2->current; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline type * \
|
static inline type * \
|
||||||
M_C(name, _ref)(const it_t it) \
|
M_C(name, _ref)(const it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert(it != NULL && it->current != NULL); \
|
M_ASSERT(it != NULL && it->current != NULL); \
|
||||||
return &(it->current->data); \
|
return &(it->current->data); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline type const * \
|
static inline type const * \
|
||||||
M_C(name, _cref)(const it_t it) \
|
M_C(name, _cref)(const it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert(it != NULL && it->current != NULL); \
|
M_ASSERT(it != NULL && it->current != NULL); \
|
||||||
return M_CONST_CAST(type, &(it->current->data)); \
|
return M_CONST_CAST(type, &(it->current->data)); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
@@ -1238,7 +1238,7 @@
|
|||||||
type const x) \
|
type const x) \
|
||||||
{ \
|
{ \
|
||||||
LISTI_DUAL_PUSH_CONTRACT(list); \
|
LISTI_DUAL_PUSH_CONTRACT(list); \
|
||||||
assert (insertion_point != NULL); \
|
M_ASSERT (insertion_point != NULL); \
|
||||||
struct M_C(name, _s) *next = M_C(name, _int_new)(); \
|
struct M_C(name, _s) *next = M_C(name, _int_new)(); \
|
||||||
if (M_UNLIKELY (next == NULL)) { \
|
if (M_UNLIKELY (next == NULL)) { \
|
||||||
M_MEMORY_FULL(sizeof (struct M_C(name, _s))); \
|
M_MEMORY_FULL(sizeof (struct M_C(name, _s))); \
|
||||||
@@ -1266,8 +1266,8 @@
|
|||||||
M_C(name, _remove)(list_t list, it_t removing_point) \
|
M_C(name, _remove)(list_t list, it_t removing_point) \
|
||||||
{ \
|
{ \
|
||||||
LISTI_DUAL_PUSH_CONTRACT(list); \
|
LISTI_DUAL_PUSH_CONTRACT(list); \
|
||||||
assert (removing_point != NULL); \
|
M_ASSERT (removing_point != NULL); \
|
||||||
assert(removing_point->current != NULL); \
|
M_ASSERT(removing_point->current != NULL); \
|
||||||
struct M_C(name, _s) *next = removing_point->current->next; \
|
struct M_C(name, _s) *next = removing_point->current->next; \
|
||||||
struct M_C(name, _s) *previous = removing_point->previous; \
|
struct M_C(name, _s) *previous = removing_point->previous; \
|
||||||
if (M_UNLIKELY (previous == NULL)) { \
|
if (M_UNLIKELY (previous == NULL)) { \
|
||||||
@@ -1315,7 +1315,7 @@
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _init_set)(list_t list, const list_t org) \
|
M_C(name, _init_set)(list_t list, const list_t org) \
|
||||||
{ \
|
{ \
|
||||||
assert (list != org); \
|
M_ASSERT (list != org); \
|
||||||
M_C(name, _init)(list); \
|
M_C(name, _init)(list); \
|
||||||
M_C(name, _set)(list, org); \
|
M_C(name, _set)(list, org); \
|
||||||
} \
|
} \
|
||||||
@@ -1323,7 +1323,7 @@
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _init_move)(list_t list, list_t org) \
|
M_C(name, _init_move)(list_t list, list_t org) \
|
||||||
{ \
|
{ \
|
||||||
assert (list != org); \
|
M_ASSERT (list != org); \
|
||||||
list->back = org->back; \
|
list->back = org->back; \
|
||||||
list->front = org->front; \
|
list->front = org->front; \
|
||||||
org->back = NULL; \
|
org->back = NULL; \
|
||||||
@@ -1342,7 +1342,7 @@
|
|||||||
{ \
|
{ \
|
||||||
LISTI_DUAL_PUSH_CONTRACT(list1); \
|
LISTI_DUAL_PUSH_CONTRACT(list1); \
|
||||||
LISTI_DUAL_PUSH_CONTRACT(list2); \
|
LISTI_DUAL_PUSH_CONTRACT(list2); \
|
||||||
assert (it->current != NULL); \
|
M_ASSERT (it->current != NULL); \
|
||||||
/* First remove the item 'it' from the list 'list2' */ \
|
/* First remove the item 'it' from the list 'list2' */ \
|
||||||
struct M_C(name, _s) *current = it->current; \
|
struct M_C(name, _s) *current = it->current; \
|
||||||
struct M_C(name, _s) *next = current->next; \
|
struct M_C(name, _s) *next = current->next; \
|
||||||
@@ -1375,7 +1375,7 @@
|
|||||||
{ \
|
{ \
|
||||||
LISTI_DUAL_PUSH_CONTRACT(nlist); \
|
LISTI_DUAL_PUSH_CONTRACT(nlist); \
|
||||||
LISTI_DUAL_PUSH_CONTRACT(olist); \
|
LISTI_DUAL_PUSH_CONTRACT(olist); \
|
||||||
assert (npos != NULL && opos != NULL); \
|
M_ASSERT (npos != NULL && opos != NULL); \
|
||||||
/* First remove the item 'opos' from the list 'olist' */ \
|
/* First remove the item 'opos' from the list 'olist' */ \
|
||||||
struct M_C(name, _s) *current = opos->current; \
|
struct M_C(name, _s) *current = opos->current; \
|
||||||
struct M_C(name, _s) *next = current->next; \
|
struct M_C(name, _s) *next = current->next; \
|
||||||
@@ -1420,7 +1420,7 @@
|
|||||||
{ \
|
{ \
|
||||||
LISTI_DUAL_PUSH_CONTRACT(list1); \
|
LISTI_DUAL_PUSH_CONTRACT(list1); \
|
||||||
LISTI_DUAL_PUSH_CONTRACT(list2); \
|
LISTI_DUAL_PUSH_CONTRACT(list2); \
|
||||||
assert (list1 != list2); \
|
M_ASSERT (list1 != list2); \
|
||||||
if (M_LIKELY (list1->front != NULL)) { \
|
if (M_LIKELY (list1->front != NULL)) { \
|
||||||
list1->front->next = list2->back; \
|
list1->front->next = list2->back; \
|
||||||
list1->front = list2->front; \
|
list1->front = list2->front; \
|
||||||
|
|||||||
+4
-4
@@ -134,7 +134,7 @@
|
|||||||
} \
|
} \
|
||||||
/* No cheap free object exist. Test within a segment */ \
|
/* No cheap free object exist. Test within a segment */ \
|
||||||
M_C(name,_segment_ct) *segment = mem->current_segment; \
|
M_C(name,_segment_ct) *segment = mem->current_segment; \
|
||||||
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 >= MEMPOOL_MAX_PER_SEGMENT(type))) { \
|
||||||
@@ -173,9 +173,9 @@
|
|||||||
|
|
||||||
/* MEMPOOL contract */
|
/* MEMPOOL contract */
|
||||||
#define MEMPOOLI_CONTRACT(mempool, type) do { \
|
#define MEMPOOLI_CONTRACT(mempool, type) do { \
|
||||||
assert((mempool) != NULL); \
|
M_ASSERT((mempool) != NULL); \
|
||||||
assert((mempool)->current_segment != NULL); \
|
M_ASSERT((mempool)->current_segment != NULL); \
|
||||||
assert((mempool)->current_segment->count <= MEMPOOL_MAX_PER_SEGMENT(type)); \
|
M_ASSERT((mempool)->current_segment->count <= MEMPOOL_MAX_PER_SEGMENT(type)); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -129,7 +129,7 @@ static inline void m_thread_create(m_thread_t t, void (*func)(void*), void* arg)
|
|||||||
static inline void m_thread_join(m_thread_t t)
|
static inline void m_thread_join(m_thread_t t)
|
||||||
{
|
{
|
||||||
int rc = thrd_join(*t, NULL);
|
int rc = thrd_join(*t, NULL);
|
||||||
assert (rc == thrd_success);
|
M_ASSERT (rc == thrd_success);
|
||||||
// Avoid warning about variable unused.
|
// Avoid warning about variable unused.
|
||||||
(void) rc;
|
(void) rc;
|
||||||
}
|
}
|
||||||
@@ -288,7 +288,7 @@ static inline void m_thread_join(m_thread_t t)
|
|||||||
{
|
{
|
||||||
DWORD dwWaitResult = WaitForSingleObject(*t, INFINITE);
|
DWORD dwWaitResult = WaitForSingleObject(*t, INFINITE);
|
||||||
(void) dwWaitResult;
|
(void) dwWaitResult;
|
||||||
assert (dwWaitResult == WAIT_OBJECT_0);
|
M_ASSERT (dwWaitResult == WAIT_OBJECT_0);
|
||||||
CloseHandle(*t);
|
CloseHandle(*t);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -304,7 +304,7 @@ static inline void m_thread_yield(void)
|
|||||||
static inline bool m_thread_sleep(unsigned long long usec)
|
static inline bool m_thread_sleep(unsigned long long usec)
|
||||||
{
|
{
|
||||||
LARGE_INTEGER ft;
|
LARGE_INTEGER ft;
|
||||||
assert (usec <= LLONG_MAX);
|
M_ASSERT (usec <= LLONG_MAX);
|
||||||
ft.QuadPart = -(10LL*(long long) usec);
|
ft.QuadPart = -(10LL*(long long) usec);
|
||||||
HANDLE hd = CreateWaitableTimer(NULL, TRUE, NULL);
|
HANDLE hd = CreateWaitableTimer(NULL, TRUE, NULL);
|
||||||
M_ASSERT_INIT (hd != NULL, "timer");
|
M_ASSERT_INIT (hd != NULL, "timer");
|
||||||
@@ -449,7 +449,7 @@ static inline void m_thread_join(m_thread_t t)
|
|||||||
{
|
{
|
||||||
int _rc = pthread_join(*t, NULL);
|
int _rc = pthread_join(*t, NULL);
|
||||||
(void)_rc; // Avoid warning about variable unused.
|
(void)_rc; // Avoid warning about variable unused.
|
||||||
assert (_rc == 0);
|
M_ASSERT (_rc == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The thread has nothing meaningfull to do.
|
/* The thread has nothing meaningfull to do.
|
||||||
|
|||||||
+5
-5
@@ -197,21 +197,21 @@
|
|||||||
static inline size_t \
|
static inline size_t \
|
||||||
M_C(name, _i_parent)(size_t i) \
|
M_C(name, _i_parent)(size_t i) \
|
||||||
{ \
|
{ \
|
||||||
assert (i > 0); \
|
M_ASSERT (i > 0); \
|
||||||
return (i - 1) / 2; \
|
return (i - 1) / 2; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline size_t \
|
static inline size_t \
|
||||||
M_C(name, _i_lchild)(size_t i) \
|
M_C(name, _i_lchild)(size_t i) \
|
||||||
{ \
|
{ \
|
||||||
assert(i <= ((SIZE_MAX)-2)/2); \
|
M_ASSERT(i <= ((SIZE_MAX)-2)/2); \
|
||||||
return 2*i + 1; \
|
return 2*i + 1; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline size_t \
|
static inline size_t \
|
||||||
M_C(name, _i_rchild)(size_t i) \
|
M_C(name, _i_rchild)(size_t i) \
|
||||||
{ \
|
{ \
|
||||||
assert(i <= ((SIZE_MAX)-2)/2); \
|
M_ASSERT(i <= ((SIZE_MAX)-2)/2); \
|
||||||
return 2*i + 2; \
|
return 2*i + 2; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
@@ -388,7 +388,7 @@
|
|||||||
M_C(name, _update_further)(prioqueue_t p, type xold, type xnew) \
|
M_C(name, _update_further)(prioqueue_t p, type xold, type xnew) \
|
||||||
{ \
|
{ \
|
||||||
/* This update assumes that the new position is further in the heap */ \
|
/* This update assumes that the new position is further in the heap */ \
|
||||||
assert (M_CALL_CMP(oplist, xold, xnew) > 0); \
|
M_ASSERT (M_CALL_CMP(oplist, xold, xnew) > 0); \
|
||||||
/* First pass: search for an item EQUAL to x */ \
|
/* First pass: search for an item EQUAL to x */ \
|
||||||
size_t size = M_C(name, _array_size)(p->array); \
|
size_t size = M_C(name, _array_size)(p->array); \
|
||||||
size_t i = 0; \
|
size_t i = 0; \
|
||||||
@@ -397,7 +397,7 @@
|
|||||||
break; \
|
break; \
|
||||||
} \
|
} \
|
||||||
/* We shall have found the item */ \
|
/* We shall have found the item */ \
|
||||||
assert (i < size); \
|
M_ASSERT (i < size); \
|
||||||
/* Set the found item to the new element */ \
|
/* Set the found item to the new element */ \
|
||||||
M_C(name, _array_set_at) (p->array, i, xnew); \
|
M_C(name, _array_set_at) (p->array, i, xnew); \
|
||||||
/* Move back the updated element to its right position in the heap */ \
|
/* Move back the updated element to its right position in the heap */ \
|
||||||
|
|||||||
+72
-72
@@ -140,16 +140,16 @@ typedef enum {
|
|||||||
|
|
||||||
// General contact of a Read/Black tree
|
// General contact of a Read/Black tree
|
||||||
#define RBTREEI_CONTRACT(tree) do { \
|
#define RBTREEI_CONTRACT(tree) do { \
|
||||||
assert ((tree) != NULL); \
|
M_ASSERT ((tree) != NULL); \
|
||||||
assert ((tree)->node == NULL || RBTREEI_IS_BLACK((tree)->node)); \
|
M_ASSERT ((tree)->node == NULL || RBTREEI_IS_BLACK((tree)->node)); \
|
||||||
assert ((tree)->size != 0 || (tree)->node == NULL); \
|
M_ASSERT ((tree)->size != 0 || (tree)->node == NULL); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
// Contract of a node (doesn't check for equal depth in black)
|
// Contract of a node (doesn't check for equal depth in black)
|
||||||
#define RBTREEI_CONTRACT_NODE(node) do { \
|
#define RBTREEI_CONTRACT_NODE(node) do { \
|
||||||
assert((node) != NULL); \
|
M_ASSERT((node) != NULL); \
|
||||||
assert(RBTREEI_IS_BLACK(node) || RBTREEI_IS_RED(node)); \
|
M_ASSERT(RBTREEI_IS_BLACK(node) || RBTREEI_IS_RED(node)); \
|
||||||
assert(RBTREEI_IS_BLACK(node) \
|
M_ASSERT(RBTREEI_IS_BLACK(node) \
|
||||||
|| (((node)->child[0] == NULL || RBTREEI_IS_BLACK(node->child[0])) \
|
|| (((node)->child[0] == NULL || RBTREEI_IS_BLACK(node->child[0])) \
|
||||||
&& ((node)->child[1] == NULL || RBTREEI_IS_BLACK(node->child[1])))); \
|
&& ((node)->child[1] == NULL || RBTREEI_IS_BLACK(node->child[1])))); \
|
||||||
} while (0)
|
} while (0)
|
||||||
@@ -245,7 +245,7 @@ typedef enum {
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _init)(tree_t tree) \
|
M_C(name, _init)(tree_t tree) \
|
||||||
{ \
|
{ \
|
||||||
assert (tree != NULL); \
|
M_ASSERT (tree != NULL); \
|
||||||
tree->size = 0; \
|
tree->size = 0; \
|
||||||
tree->node = NULL; \
|
tree->node = NULL; \
|
||||||
RBTREEI_CONTRACT(tree); \
|
RBTREEI_CONTRACT(tree); \
|
||||||
@@ -268,13 +268,13 @@ typedef enum {
|
|||||||
RBTREEI_CONTRACT_NODE(n); \
|
RBTREEI_CONTRACT_NODE(n); \
|
||||||
/* If there is a left child, get it */ \
|
/* If there is a left child, get it */ \
|
||||||
if (n->child[0] != NULL) { \
|
if (n->child[0] != NULL) { \
|
||||||
assert (cpt < RBTREEI_MAX_STACK); \
|
M_ASSERT (cpt < RBTREEI_MAX_STACK); \
|
||||||
stack[cpt++] = n->child[0]; \
|
stack[cpt++] = n->child[0]; \
|
||||||
n = n->child[0]; \
|
n = n->child[0]; \
|
||||||
stack[cpt-2]->child[0] = NULL; \
|
stack[cpt-2]->child[0] = NULL; \
|
||||||
/* If there is a right child, get it */ \
|
/* If there is a right child, get it */ \
|
||||||
} else if (n->child[1] != NULL) { \
|
} else if (n->child[1] != NULL) { \
|
||||||
assert (cpt < RBTREEI_MAX_STACK); \
|
M_ASSERT (cpt < RBTREEI_MAX_STACK); \
|
||||||
stack[cpt++] = n->child[1]; \
|
stack[cpt++] = n->child[1]; \
|
||||||
n = n->child[1]; \
|
n = n->child[1]; \
|
||||||
stack[cpt-2]->child[1] = NULL; \
|
stack[cpt-2]->child[1] = NULL; \
|
||||||
@@ -283,11 +283,11 @@ typedef enum {
|
|||||||
break; \
|
break; \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
assert (n == stack[cpt - 1]); \
|
M_ASSERT (n == stack[cpt - 1]); \
|
||||||
/* Clear the bottom left node */ \
|
/* Clear the bottom left node */ \
|
||||||
M_CALL_CLEAR(oplist, n->data); \
|
M_CALL_CLEAR(oplist, n->data); \
|
||||||
M_C(name,_int_del) (n); \
|
M_C(name,_int_del) (n); \
|
||||||
assert((stack[cpt-1] = NULL) == NULL); \
|
M_ASSERT((stack[cpt-1] = NULL) == NULL); \
|
||||||
/* Go up to the parent */ \
|
/* Go up to the parent */ \
|
||||||
cpt--; \
|
cpt--; \
|
||||||
} \
|
} \
|
||||||
@@ -324,7 +324,7 @@ typedef enum {
|
|||||||
n->child[0] = n->child[1] = NULL; \
|
n->child[0] = n->child[1] = NULL; \
|
||||||
RBTREEI_SET_BLACK (n); \
|
RBTREEI_SET_BLACK (n); \
|
||||||
tree->node = n; \
|
tree->node = n; \
|
||||||
assert(tree->size == 0); \
|
M_ASSERT(tree->size == 0); \
|
||||||
tree->size = 1; \
|
tree->size = 1; \
|
||||||
RBTREEI_CONTRACT(tree); \
|
RBTREEI_CONTRACT(tree); \
|
||||||
return; \
|
return; \
|
||||||
@@ -344,7 +344,7 @@ typedef enum {
|
|||||||
n = n->child[s]; \
|
n = n->child[s]; \
|
||||||
} \
|
} \
|
||||||
/* We cannot overflow the max depth of a tree */ \
|
/* We cannot overflow the max depth of a tree */ \
|
||||||
assert (cpt < RBTREEI_MAX_STACK); \
|
M_ASSERT (cpt < RBTREEI_MAX_STACK); \
|
||||||
tab[cpt] = n; \
|
tab[cpt] = n; \
|
||||||
} \
|
} \
|
||||||
/* If found, update the data (default is set) */ \
|
/* If found, update the data (default is set) */ \
|
||||||
@@ -366,11 +366,11 @@ typedef enum {
|
|||||||
n->child[0] = n->child[1] = NULL; \
|
n->child[0] = n->child[1] = NULL; \
|
||||||
RBTREEI_SET_RED (n); \
|
RBTREEI_SET_RED (n); \
|
||||||
/* Add it in the iterator */ \
|
/* Add it in the iterator */ \
|
||||||
assert (tab[cpt] == NULL); \
|
M_ASSERT (tab[cpt] == NULL); \
|
||||||
tab[cpt] = n; \
|
tab[cpt] = n; \
|
||||||
/* Add it in the tree */ \
|
/* Add it in the tree */ \
|
||||||
tree->size ++; \
|
tree->size ++; \
|
||||||
assert(tab[cpt-1]->child[0+which[cpt-1]] == NULL); \
|
M_ASSERT(tab[cpt-1]->child[0+which[cpt-1]] == NULL); \
|
||||||
tab[cpt-1]->child[0+which[cpt-1]] = n; \
|
tab[cpt-1]->child[0+which[cpt-1]] = n; \
|
||||||
/* Fix the tree to still respect the red/back properties */ \
|
/* Fix the tree to still respect the red/back properties */ \
|
||||||
while (cpt >= 2 \
|
while (cpt >= 2 \
|
||||||
@@ -394,7 +394,7 @@ typedef enum {
|
|||||||
node_t *x = tab[cpt]; \
|
node_t *x = tab[cpt]; \
|
||||||
int i = which[cpt-2]; \
|
int i = which[cpt-2]; \
|
||||||
int j = 1 - i; \
|
int j = 1 - i; \
|
||||||
assert (i == 0 || i == 1); \
|
M_ASSERT (i == 0 || i == 1); \
|
||||||
/* We need to do some rotations */ \
|
/* We need to do some rotations */ \
|
||||||
if (i == which[cpt-1]) { \
|
if (i == which[cpt-1]) { \
|
||||||
/* The child is the left child of its parent */ \
|
/* The child is the left child of its parent */ \
|
||||||
@@ -407,7 +407,7 @@ typedef enum {
|
|||||||
RBTREEI_SET_BLACK(p); \
|
RBTREEI_SET_BLACK(p); \
|
||||||
RBTREEI_SET_RED(pp); \
|
RBTREEI_SET_RED(pp); \
|
||||||
} else { \
|
} else { \
|
||||||
assert (j == which[cpt-1]); \
|
M_ASSERT (j == which[cpt-1]); \
|
||||||
/* The child is the right child of its parent */ \
|
/* The child is the right child of its parent */ \
|
||||||
/* OR The child is the left child of its parent */ \
|
/* OR The child is the left child of its parent */ \
|
||||||
/* Left rotation */ \
|
/* Left rotation */ \
|
||||||
@@ -424,7 +424,7 @@ typedef enum {
|
|||||||
if (cpt == 2) { \
|
if (cpt == 2) { \
|
||||||
tree->node = p; \
|
tree->node = p; \
|
||||||
} else { \
|
} else { \
|
||||||
assert (cpt >= 3); \
|
M_ASSERT (cpt >= 3); \
|
||||||
tab[cpt-3]->child[which[cpt-3]] = p; \
|
tab[cpt-3]->child[which[cpt-3]] = p; \
|
||||||
} \
|
} \
|
||||||
/* Done */ \
|
/* Done */ \
|
||||||
@@ -443,20 +443,20 @@ typedef enum {
|
|||||||
M_C(name, _int_it)(it_t it, const tree_t tree, int child) \
|
M_C(name, _int_it)(it_t it, const tree_t tree, int child) \
|
||||||
{ \
|
{ \
|
||||||
RBTREEI_CONTRACT (tree); \
|
RBTREEI_CONTRACT (tree); \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
assert (child == 0 || child == 1); \
|
M_ASSERT (child == 0 || child == 1); \
|
||||||
unsigned int cpt = 0; \
|
unsigned int cpt = 0; \
|
||||||
if (tree->node != NULL) { \
|
if (tree->node != NULL) { \
|
||||||
it->which[cpt] = (int8_t) child; \
|
it->which[cpt] = (int8_t) child; \
|
||||||
node_t *n = it->stack[cpt++] = tree->node; \
|
node_t *n = it->stack[cpt++] = tree->node; \
|
||||||
/* Go down the tree and fill in the iterator */ \
|
/* Go down the tree and fill in the iterator */ \
|
||||||
while (n->child[child] != NULL) { \
|
while (n->child[child] != NULL) { \
|
||||||
assert (cpt < RBTREEI_MAX_STACK); \
|
M_ASSERT (cpt < RBTREEI_MAX_STACK); \
|
||||||
n = n->child[child]; \
|
n = n->child[child]; \
|
||||||
it->which[cpt] = (int8_t) child; \
|
it->which[cpt] = (int8_t) child; \
|
||||||
it->stack[cpt++] = n; \
|
it->stack[cpt++] = n; \
|
||||||
} \
|
} \
|
||||||
assert (n == it->stack[cpt - 1]); \
|
M_ASSERT (n == it->stack[cpt - 1]); \
|
||||||
} \
|
} \
|
||||||
it->cpt = cpt; \
|
it->cpt = cpt; \
|
||||||
} \
|
} \
|
||||||
@@ -477,21 +477,21 @@ typedef enum {
|
|||||||
M_C(name, _it_end)(it_t it, const tree_t tree) \
|
M_C(name, _it_end)(it_t it, const tree_t tree) \
|
||||||
{ \
|
{ \
|
||||||
RBTREEI_CONTRACT (tree); \
|
RBTREEI_CONTRACT (tree); \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
it->cpt = 0; \
|
it->cpt = 0; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _it_set)(it_t it, const it_t ref) \
|
M_C(name, _it_set)(it_t it, const it_t ref) \
|
||||||
{ \
|
{ \
|
||||||
assert (it != NULL && ref != NULL); \
|
M_ASSERT (it != NULL && ref != NULL); \
|
||||||
*it = *ref; \
|
*it = *ref; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline bool \
|
static inline bool \
|
||||||
M_C(name, _end_p)(const it_t it) \
|
M_C(name, _end_p)(const it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
return it->cpt == 0; \
|
return it->cpt == 0; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
@@ -499,8 +499,8 @@ typedef enum {
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _int_next)(it_t it, int child) \
|
M_C(name, _int_next)(it_t it, int child) \
|
||||||
{ \
|
{ \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
assert (child == 0 || child == 1); \
|
M_ASSERT (child == 0 || child == 1); \
|
||||||
if (it->cpt == 0) return; \
|
if (it->cpt == 0) return; \
|
||||||
unsigned int cpt = it->cpt - 1; \
|
unsigned int cpt = it->cpt - 1; \
|
||||||
node_t *n = it->stack[cpt]; \
|
node_t *n = it->stack[cpt]; \
|
||||||
@@ -508,19 +508,19 @@ typedef enum {
|
|||||||
const int right = 1 ^ child; \
|
const int right = 1 ^ child; \
|
||||||
if (n->child[right] != NULL && it->which[cpt] == child) { \
|
if (n->child[right] != NULL && it->which[cpt] == child) { \
|
||||||
/* Going right */ \
|
/* Going right */ \
|
||||||
assert (cpt < RBTREEI_MAX_STACK); \
|
M_ASSERT (cpt < RBTREEI_MAX_STACK); \
|
||||||
n = n->child[right]; \
|
n = n->child[right]; \
|
||||||
it->which[cpt++] = (int8_t) right; \
|
it->which[cpt++] = (int8_t) right; \
|
||||||
it->stack[cpt] = n; \
|
it->stack[cpt] = n; \
|
||||||
it->which[cpt++] = (int8_t) child; \
|
it->which[cpt++] = (int8_t) child; \
|
||||||
/* Going left */ \
|
/* Going left */ \
|
||||||
while (n->child[child] != NULL) { \
|
while (n->child[child] != NULL) { \
|
||||||
assert (cpt < RBTREEI_MAX_STACK); \
|
M_ASSERT (cpt < RBTREEI_MAX_STACK); \
|
||||||
n = n->child[child]; \
|
n = n->child[child]; \
|
||||||
it->which[cpt] = (int8_t) child; \
|
it->which[cpt] = (int8_t) child; \
|
||||||
it->stack[cpt++] = n; \
|
it->stack[cpt++] = n; \
|
||||||
} \
|
} \
|
||||||
assert (n == it->stack[cpt - 1]); \
|
M_ASSERT (n == it->stack[cpt - 1]); \
|
||||||
} else { \
|
} else { \
|
||||||
/* Going up */ \
|
/* Going up */ \
|
||||||
while (cpt > 0 && it->which[cpt-1] == right) cpt--; \
|
while (cpt > 0 && it->which[cpt-1] == right) cpt--; \
|
||||||
@@ -543,7 +543,7 @@ typedef enum {
|
|||||||
static inline type * \
|
static inline type * \
|
||||||
M_C(name, _ref)(const it_t it) \
|
M_C(name, _ref)(const it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert(it != NULL && it->cpt > 0); \
|
M_ASSERT(it != NULL && it->cpt > 0); \
|
||||||
/* NOTE: partially unsafe if the user modify the order of the el */ \
|
/* NOTE: partially unsafe if the user modify the order of the el */ \
|
||||||
return &(it->stack[it->cpt-1]->data); \
|
return &(it->stack[it->cpt-1]->data); \
|
||||||
} \
|
} \
|
||||||
@@ -557,7 +557,7 @@ typedef enum {
|
|||||||
static inline bool \
|
static inline bool \
|
||||||
M_C(name, _it_equal_p)(const it_t it1, const it_t it2) \
|
M_C(name, _it_equal_p)(const it_t it1, const it_t it2) \
|
||||||
{ \
|
{ \
|
||||||
assert(it1 != NULL && it2 != NULL); \
|
M_ASSERT(it1 != NULL && it2 != NULL); \
|
||||||
return it1->cpt == it2->cpt \
|
return it1->cpt == it2->cpt \
|
||||||
&& it1->stack[it1->cpt-1] == it2->stack[it2->cpt-1]; \
|
&& it1->stack[it1->cpt-1] == it2->stack[it2->cpt-1]; \
|
||||||
} \
|
} \
|
||||||
@@ -567,7 +567,7 @@ typedef enum {
|
|||||||
M_C(name, _it_from)(it_t it, const tree_t tree, type const data) \
|
M_C(name, _it_from)(it_t it, const tree_t tree, type const data) \
|
||||||
{ \
|
{ \
|
||||||
RBTREEI_CONTRACT (tree); \
|
RBTREEI_CONTRACT (tree); \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
unsigned int cpt = 0; \
|
unsigned int cpt = 0; \
|
||||||
node_t *n = tree->node; \
|
node_t *n = tree->node; \
|
||||||
it->stack[cpt] = n; \
|
it->stack[cpt] = n; \
|
||||||
@@ -578,7 +578,7 @@ typedef enum {
|
|||||||
int child = (cmp < 0); \
|
int child = (cmp < 0); \
|
||||||
it->which[cpt++] = (int8_t) child; \
|
it->which[cpt++] = (int8_t) child; \
|
||||||
n = n->child[child]; \
|
n = n->child[child]; \
|
||||||
assert (cpt < RBTREEI_MAX_STACK); \
|
M_ASSERT (cpt < RBTREEI_MAX_STACK); \
|
||||||
it->stack[cpt] = n; \
|
it->stack[cpt] = n; \
|
||||||
} \
|
} \
|
||||||
it->cpt = cpt; \
|
it->cpt = cpt; \
|
||||||
@@ -587,9 +587,9 @@ typedef enum {
|
|||||||
static inline bool \
|
static inline bool \
|
||||||
M_C(name, _it_until_p)(it_t it, type const data) \
|
M_C(name, _it_until_p)(it_t it, type const data) \
|
||||||
{ \
|
{ \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
if (it->cpt == 0) return true; \
|
if (it->cpt == 0) return true; \
|
||||||
assert (it->cpt > 0 && it->cpt < RBTREEI_MAX_STACK); \
|
M_ASSERT (it->cpt > 0 && it->cpt < RBTREEI_MAX_STACK); \
|
||||||
node_t *n = it->stack[it->cpt-1]; \
|
node_t *n = it->stack[it->cpt-1]; \
|
||||||
int cmp = M_CALL_CMP(oplist, n->data, data); \
|
int cmp = M_CALL_CMP(oplist, n->data, data); \
|
||||||
return (cmp >= 0); \
|
return (cmp >= 0); \
|
||||||
@@ -598,9 +598,9 @@ typedef enum {
|
|||||||
static inline bool \
|
static inline bool \
|
||||||
M_C(name, _it_while_p)(it_t it, type const data) \
|
M_C(name, _it_while_p)(it_t it, type const data) \
|
||||||
{ \
|
{ \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
if (it->cpt == 0) return true; \
|
if (it->cpt == 0) return true; \
|
||||||
assert (it->cpt > 0 && it->cpt < RBTREEI_MAX_STACK); \
|
M_ASSERT (it->cpt > 0 && it->cpt < RBTREEI_MAX_STACK); \
|
||||||
node_t *n = it->stack[it->cpt-1]; \
|
node_t *n = it->stack[it->cpt-1]; \
|
||||||
int cmp = M_CALL_CMP(oplist, n->data, data); \
|
int cmp = M_CALL_CMP(oplist, n->data, data); \
|
||||||
return (cmp <= 0); \
|
return (cmp <= 0); \
|
||||||
@@ -696,7 +696,7 @@ typedef enum {
|
|||||||
M_C(name, _init_set)(tree_t tree, const tree_t ref) \
|
M_C(name, _init_set)(tree_t tree, const tree_t ref) \
|
||||||
{ \
|
{ \
|
||||||
RBTREEI_CONTRACT (ref); \
|
RBTREEI_CONTRACT (ref); \
|
||||||
assert (tree != NULL && tree != ref); \
|
M_ASSERT (tree != NULL && tree != ref); \
|
||||||
tree->size = ref->size; \
|
tree->size = ref->size; \
|
||||||
/* Copy the root node recursively */ \
|
/* Copy the root node recursively */ \
|
||||||
tree->node = M_C(name, _int_copyn)(ref->node); \
|
tree->node = M_C(name, _int_copyn)(ref->node); \
|
||||||
@@ -717,7 +717,7 @@ typedef enum {
|
|||||||
M_C(name, _init_move)(tree_t tree, tree_t ref) \
|
M_C(name, _init_move)(tree_t tree, tree_t ref) \
|
||||||
{ \
|
{ \
|
||||||
RBTREEI_CONTRACT (ref); \
|
RBTREEI_CONTRACT (ref); \
|
||||||
assert (tree != NULL && tree != ref); \
|
M_ASSERT (tree != NULL && tree != ref); \
|
||||||
tree->size = ref->size; \
|
tree->size = ref->size; \
|
||||||
tree->node = ref->node; \
|
tree->node = ref->node; \
|
||||||
ref->node = NULL; \
|
ref->node = NULL; \
|
||||||
@@ -730,7 +730,7 @@ typedef enum {
|
|||||||
{ \
|
{ \
|
||||||
RBTREEI_CONTRACT (tree); \
|
RBTREEI_CONTRACT (tree); \
|
||||||
RBTREEI_CONTRACT (ref); \
|
RBTREEI_CONTRACT (ref); \
|
||||||
assert (tree != ref); \
|
M_ASSERT (tree != ref); \
|
||||||
M_C(name,_clear)(tree); \
|
M_C(name,_clear)(tree); \
|
||||||
M_C(name,_init_move)(tree, ref); \
|
M_C(name,_init_move)(tree, ref); \
|
||||||
RBTREEI_CONTRACT (tree); \
|
RBTREEI_CONTRACT (tree); \
|
||||||
@@ -770,14 +770,14 @@ typedef enum {
|
|||||||
static inline node_t * \
|
static inline node_t * \
|
||||||
M_C(name, _int_rotate)(node_t *pp, node_t *ppp, const bool right) \
|
M_C(name, _int_rotate)(node_t *pp, node_t *ppp, const bool right) \
|
||||||
{ \
|
{ \
|
||||||
assert (pp != NULL && ppp != NULL); \
|
M_ASSERT (pp != NULL && ppp != NULL); \
|
||||||
bool left = !right; \
|
bool left = !right; \
|
||||||
node_t *p = pp->child[right]; \
|
node_t *p = pp->child[right]; \
|
||||||
assert (p != NULL); \
|
M_ASSERT (p != NULL); \
|
||||||
pp->child[right] = p->child[left]; \
|
pp->child[right] = p->child[left]; \
|
||||||
p->child[left] = pp; \
|
p->child[left] = pp; \
|
||||||
/* Fix grandparent with new parent */ \
|
/* Fix grandparent with new parent */ \
|
||||||
assert(ppp->child[0] == pp || ppp->child[1] == pp); \
|
M_ASSERT(ppp->child[0] == pp || ppp->child[1] == pp); \
|
||||||
ppp->child[(ppp->child[0] != pp)] = p; \
|
ppp->child[(ppp->child[0] != pp)] = p; \
|
||||||
return p; \
|
return p; \
|
||||||
} \
|
} \
|
||||||
@@ -807,7 +807,7 @@ typedef enum {
|
|||||||
tab[cpt] = n; \
|
tab[cpt] = n; \
|
||||||
while (n != NULL) { \
|
while (n != NULL) { \
|
||||||
RBTREEI_CONTRACT_NODE (n); \
|
RBTREEI_CONTRACT_NODE (n); \
|
||||||
assert(M_C(name, _int_depth)(n->child[0]) \
|
M_ASSERT(M_C(name, _int_depth)(n->child[0]) \
|
||||||
== M_C(name, _int_depth)(n->child[1])); \
|
== M_C(name, _int_depth)(n->child[1])); \
|
||||||
int cmp = M_CALL_CMP(oplist, n->data, key); \
|
int cmp = M_CALL_CMP(oplist, n->data, key); \
|
||||||
if (cmp == 0) { \
|
if (cmp == 0) { \
|
||||||
@@ -816,10 +816,10 @@ typedef enum {
|
|||||||
int i = (cmp < 0); \
|
int i = (cmp < 0); \
|
||||||
which[cpt++] = (int8_t) i; \
|
which[cpt++] = (int8_t) i; \
|
||||||
n = n->child[i]; \
|
n = n->child[i]; \
|
||||||
assert (cpt < RBTREEI_MAX_STACK); \
|
M_ASSERT (cpt < RBTREEI_MAX_STACK); \
|
||||||
tab[cpt] = n; \
|
tab[cpt] = n; \
|
||||||
} \
|
} \
|
||||||
assert (tab[cpt] == n); \
|
M_ASSERT (tab[cpt] == n); \
|
||||||
/* If not found, fail */ \
|
/* If not found, fail */ \
|
||||||
if (n == NULL) { \
|
if (n == NULL) { \
|
||||||
return false; \
|
return false; \
|
||||||
@@ -838,23 +838,23 @@ typedef enum {
|
|||||||
while (v != NULL) { \
|
while (v != NULL) { \
|
||||||
/* Always left node */ \
|
/* Always left node */ \
|
||||||
RBTREEI_CONTRACT_NODE (v); \
|
RBTREEI_CONTRACT_NODE (v); \
|
||||||
assert(M_C(name, _int_depth)(v->child[0]) \
|
M_ASSERT(M_C(name, _int_depth)(v->child[0]) \
|
||||||
== M_C(name, _int_depth)(v->child[1])); \
|
== M_C(name, _int_depth)(v->child[1])); \
|
||||||
which[cpt++] = 0; \
|
which[cpt++] = 0; \
|
||||||
v = v->child[0]; \
|
v = v->child[0]; \
|
||||||
assert (cpt < RBTREEI_MAX_STACK); \
|
M_ASSERT (cpt < RBTREEI_MAX_STACK); \
|
||||||
tab[cpt] = v; \
|
tab[cpt] = v; \
|
||||||
} \
|
} \
|
||||||
/* Pop the last element to get the last non-null element */ \
|
/* Pop the last element to get the last non-null element */ \
|
||||||
v = tab[--cpt]; \
|
v = tab[--cpt]; \
|
||||||
assert (v != NULL); \
|
M_ASSERT (v != NULL); \
|
||||||
u = v->child[1]; \
|
u = v->child[1]; \
|
||||||
/* Replace 'v' by 'u' in the tree */ \
|
/* Replace 'v' by 'u' in the tree */ \
|
||||||
assert(tab[cpt-1]->child[which[cpt-1]] == v); \
|
M_ASSERT(tab[cpt-1]->child[which[cpt-1]] == v); \
|
||||||
tab[cpt-1]->child[which[cpt-1]] = u; \
|
tab[cpt-1]->child[which[cpt-1]] = u; \
|
||||||
/* Replace 'n' by 'v' in the tree */ \
|
/* Replace 'n' by 'v' in the tree */ \
|
||||||
assert(tab[cpt_n-1] != NULL); \
|
M_ASSERT(tab[cpt_n-1] != NULL); \
|
||||||
assert(tab[cpt_n-1]->child[which[cpt_n-1]] == n); \
|
M_ASSERT(tab[cpt_n-1]->child[which[cpt_n-1]] == n); \
|
||||||
tab[cpt_n-1]->child[which[cpt_n-1]] = v; \
|
tab[cpt_n-1]->child[which[cpt_n-1]] = v; \
|
||||||
v->child[0] = n->child[0]; \
|
v->child[0] = n->child[0]; \
|
||||||
v->child[1] = n->child[1]; \
|
v->child[1] = n->child[1]; \
|
||||||
@@ -866,8 +866,8 @@ typedef enum {
|
|||||||
/* 1 or no child to the node. Replace the element */ \
|
/* 1 or no child to the node. Replace the element */ \
|
||||||
v = n; \
|
v = n; \
|
||||||
u = v->child[(n->child[0] == NULL)]; \
|
u = v->child[(n->child[0] == NULL)]; \
|
||||||
assert (cpt_n >= 1 && tab[cpt_n-1]->child[which[cpt_n-1]] == n); \
|
M_ASSERT (cpt_n >= 1 && tab[cpt_n-1]->child[which[cpt_n-1]] == n); \
|
||||||
assert (n->child[(n->child[0] != NULL)] == NULL); \
|
M_ASSERT (n->child[(n->child[0] != NULL)] == NULL); \
|
||||||
tab[cpt_n-1]->child[which[cpt_n-1]] = u; \
|
tab[cpt_n-1]->child[which[cpt_n-1]] = u; \
|
||||||
/* in all cases, this node shall be set to black */ \
|
/* in all cases, this node shall be set to black */ \
|
||||||
} \
|
} \
|
||||||
@@ -880,7 +880,7 @@ typedef enum {
|
|||||||
while (cpt >= 2) { \
|
while (cpt >= 2) { \
|
||||||
p = tab[--cpt]; \
|
p = tab[--cpt]; \
|
||||||
bool nbChild = which[cpt]; \
|
bool nbChild = which[cpt]; \
|
||||||
assert (p != NULL && u == p->child[nbChild]); \
|
M_ASSERT (p != NULL && u == p->child[nbChild]); \
|
||||||
s = p->child[!nbChild]; \
|
s = p->child[!nbChild]; \
|
||||||
/* if sibling is red, perform a rotation to move sibling up */ \
|
/* if sibling is red, perform a rotation to move sibling up */ \
|
||||||
if (!M_C(name, _int_is_black)(s)) { \
|
if (!M_C(name, _int_is_black)(s)) { \
|
||||||
@@ -889,28 +889,28 @@ typedef enum {
|
|||||||
tab[cpt] = p; \
|
tab[cpt] = p; \
|
||||||
which[cpt++] = nbChild; \
|
which[cpt++] = nbChild; \
|
||||||
p = p->child[nbChild]; /* was parent */ \
|
p = p->child[nbChild]; /* was parent */ \
|
||||||
assert (p != NULL); \
|
M_ASSERT (p != NULL); \
|
||||||
RBTREEI_SET_RED(p); \
|
RBTREEI_SET_RED(p); \
|
||||||
s = p->child[!nbChild]; \
|
s = p->child[!nbChild]; \
|
||||||
assert (M_C(name, _int_is_black)(s)); \
|
M_ASSERT (M_C(name, _int_is_black)(s)); \
|
||||||
} \
|
} \
|
||||||
assert (p != NULL && u == p->child[nbChild]); \
|
M_ASSERT (p != NULL && u == p->child[nbChild]); \
|
||||||
/* if both childreen of s are black */ \
|
/* if both childreen of s are black */ \
|
||||||
/* perform recoloring and recur on parent if black */ \
|
/* perform recoloring and recur on parent if black */ \
|
||||||
if (s != NULL \
|
if (s != NULL \
|
||||||
&& M_C(name, _int_is_black)(s->child[0]) \
|
&& M_C(name, _int_is_black)(s->child[0]) \
|
||||||
&& M_C(name, _int_is_black)(s->child[1])) { \
|
&& M_C(name, _int_is_black)(s->child[1])) { \
|
||||||
assert(M_C(name, _int_depth)(s->child[0]) == M_C(name, _int_depth)(s->child[1])); \
|
M_ASSERT(M_C(name, _int_depth)(s->child[0]) == M_C(name, _int_depth)(s->child[1])); \
|
||||||
RBTREEI_SET_RED(s); \
|
RBTREEI_SET_RED(s); \
|
||||||
if (RBTREEI_IS_RED(p)) { \
|
if (RBTREEI_IS_RED(p)) { \
|
||||||
RBTREEI_SET_BLACK(p); \
|
RBTREEI_SET_BLACK(p); \
|
||||||
RBTREEI_CONTRACT_NODE(p); \
|
RBTREEI_CONTRACT_NODE(p); \
|
||||||
assert(M_C(name, _int_depth)(p->child[0]) == M_C(name, _int_depth)(p->child[1])); \
|
M_ASSERT(M_C(name, _int_depth)(p->child[0]) == M_C(name, _int_depth)(p->child[1])); \
|
||||||
break; \
|
break; \
|
||||||
} \
|
} \
|
||||||
u = p; \
|
u = p; \
|
||||||
} else { \
|
} else { \
|
||||||
assert (s != NULL); \
|
M_ASSERT (s != NULL); \
|
||||||
/* at least one child of 's' is red */ \
|
/* at least one child of 's' is red */ \
|
||||||
/* perform rotation(s) */ \
|
/* perform rotation(s) */ \
|
||||||
bool childIsRight = !M_C(name, _int_is_black)(s->child[1]); \
|
bool childIsRight = !M_C(name, _int_is_black)(s->child[1]); \
|
||||||
@@ -923,22 +923,22 @@ typedef enum {
|
|||||||
p = M_C(name, _int_rotate) (p, tab[cpt-1], !nbChild); \
|
p = M_C(name, _int_rotate) (p, tab[cpt-1], !nbChild); \
|
||||||
} \
|
} \
|
||||||
RBTREEI_SET_COLOR(p, p_color); \
|
RBTREEI_SET_COLOR(p, p_color); \
|
||||||
assert(p->child[0] != NULL && p->child[1] != NULL); \
|
M_ASSERT(p->child[0] != NULL && p->child[1] != NULL); \
|
||||||
RBTREEI_SET_BLACK(p->child[0]); \
|
RBTREEI_SET_BLACK(p->child[0]); \
|
||||||
RBTREEI_SET_BLACK(p->child[1]); \
|
RBTREEI_SET_BLACK(p->child[1]); \
|
||||||
RBTREEI_CONTRACT_NODE(p); \
|
RBTREEI_CONTRACT_NODE(p); \
|
||||||
assert(M_C(name, _int_depth)(p->child[0]) == M_C(name, _int_depth)(p->child[1])); \
|
M_ASSERT(M_C(name, _int_depth)(p->child[0]) == M_C(name, _int_depth)(p->child[1])); \
|
||||||
break; \
|
break; \
|
||||||
} \
|
} \
|
||||||
} /* while */ \
|
} /* while */ \
|
||||||
if (cpt == 1 /* root has been reached? */ ) { \
|
if (cpt == 1 /* root has been reached? */ ) { \
|
||||||
M_C(name, _int_set_black)(p); \
|
M_C(name, _int_set_black)(p); \
|
||||||
assert (tree->node == p); \
|
M_ASSERT (tree->node == p); \
|
||||||
} \
|
} \
|
||||||
} else { \
|
} else { \
|
||||||
M_C(name, _int_set_black)(u); \
|
M_C(name, _int_set_black)(u); \
|
||||||
} \
|
} \
|
||||||
assert (tree->node == NULL || RBTREEI_IS_BLACK(tree->node)); \
|
M_ASSERT (tree->node == NULL || RBTREEI_IS_BLACK(tree->node)); \
|
||||||
/* delete it */ \
|
/* delete it */ \
|
||||||
if (data_ptr != NULL) \
|
if (data_ptr != NULL) \
|
||||||
M_DO_MOVE(oplist, *data_ptr, n->data); \
|
M_DO_MOVE(oplist, *data_ptr, n->data); \
|
||||||
@@ -998,7 +998,7 @@ typedef enum {
|
|||||||
static inline void M_C(name, _get_str)(string_t str, \
|
static inline void M_C(name, _get_str)(string_t str, \
|
||||||
tree_t const t1, bool append) { \
|
tree_t const t1, bool append) { \
|
||||||
RBTREEI_CONTRACT(t1); \
|
RBTREEI_CONTRACT(t1); \
|
||||||
assert(str != NULL); \
|
M_ASSERT(str != NULL); \
|
||||||
(append ? string_cat_str : string_set_str) (str, "["); \
|
(append ? string_cat_str : string_set_str) (str, "["); \
|
||||||
/* NOTE: The print is really naive, and not really efficient */ \
|
/* NOTE: The print is really naive, and not really efficient */ \
|
||||||
bool commaToPrint = false; \
|
bool commaToPrint = false; \
|
||||||
@@ -1021,7 +1021,7 @@ typedef enum {
|
|||||||
M_C(name, _out_str)(FILE *file, tree_t const rbtree) \
|
M_C(name, _out_str)(FILE *file, tree_t const rbtree) \
|
||||||
{ \
|
{ \
|
||||||
RBTREEI_CONTRACT(rbtree); \
|
RBTREEI_CONTRACT(rbtree); \
|
||||||
assert (file != NULL); \
|
M_ASSERT (file != NULL); \
|
||||||
fputc ('[', file); \
|
fputc ('[', file); \
|
||||||
it_t it; \
|
it_t it; \
|
||||||
bool commaToPrint = false; \
|
bool commaToPrint = false; \
|
||||||
@@ -1043,7 +1043,7 @@ typedef enum {
|
|||||||
M_C(name, _parse_str)(tree_t rbtree, const char str[], const char **endp) \
|
M_C(name, _parse_str)(tree_t rbtree, const char str[], const char **endp) \
|
||||||
{ \
|
{ \
|
||||||
RBTREEI_CONTRACT(rbtree); \
|
RBTREEI_CONTRACT(rbtree); \
|
||||||
assert (str != NULL); \
|
M_ASSERT (str != NULL); \
|
||||||
M_C(name,_clean)(rbtree); \
|
M_C(name,_clean)(rbtree); \
|
||||||
bool success = false; \
|
bool success = false; \
|
||||||
int c = *str++; \
|
int c = *str++; \
|
||||||
@@ -1074,7 +1074,7 @@ typedef enum {
|
|||||||
M_C(name, _in_str)(tree_t rbtree, FILE *file) \
|
M_C(name, _in_str)(tree_t rbtree, FILE *file) \
|
||||||
{ \
|
{ \
|
||||||
RBTREEI_CONTRACT(rbtree); \
|
RBTREEI_CONTRACT(rbtree); \
|
||||||
assert (file != NULL); \
|
M_ASSERT (file != NULL); \
|
||||||
M_C(name,_clean)(rbtree); \
|
M_C(name,_clean)(rbtree); \
|
||||||
int c = fgetc(file); \
|
int c = fgetc(file); \
|
||||||
if (M_UNLIKELY (c != '[')) return false; \
|
if (M_UNLIKELY (c != '[')) return false; \
|
||||||
@@ -1100,7 +1100,7 @@ typedef enum {
|
|||||||
M_C(name, _out_serial)(m_serial_write_t f, tree_t const t1) \
|
M_C(name, _out_serial)(m_serial_write_t f, tree_t const t1) \
|
||||||
{ \
|
{ \
|
||||||
RBTREEI_CONTRACT(t1); \
|
RBTREEI_CONTRACT(t1); \
|
||||||
assert (f != NULL && f->m_interface != NULL); \
|
M_ASSERT (f != NULL && f->m_interface != NULL); \
|
||||||
m_serial_local_t local; \
|
m_serial_local_t local; \
|
||||||
m_serial_return_code_t ret; \
|
m_serial_return_code_t ret; \
|
||||||
M_C(name, _subtype_ct) const *item; \
|
M_C(name, _subtype_ct) const *item; \
|
||||||
@@ -1126,7 +1126,7 @@ typedef enum {
|
|||||||
M_C(name, _in_serial)(tree_t t1, m_serial_read_t f) \
|
M_C(name, _in_serial)(tree_t t1, m_serial_read_t f) \
|
||||||
{ \
|
{ \
|
||||||
RBTREEI_CONTRACT(t1); \
|
RBTREEI_CONTRACT(t1); \
|
||||||
assert (f != NULL && f->m_interface != NULL); \
|
M_ASSERT (f != NULL && f->m_interface != NULL); \
|
||||||
m_serial_local_t local; \
|
m_serial_local_t local; \
|
||||||
m_serial_return_code_t ret; \
|
m_serial_return_code_t ret; \
|
||||||
size_t estimated_size = 0; \
|
size_t estimated_size = 0; \
|
||||||
|
|||||||
+3
-3
@@ -183,7 +183,7 @@ m_serial_bin_write_string(m_serial_write_t serial, const char data[], size_t len
|
|||||||
{
|
{
|
||||||
STRINGI_ASSERT_SLOW(length == strlen(data) );
|
STRINGI_ASSERT_SLOW(length == strlen(data) );
|
||||||
FILE *f = (FILE *)serial->data[0].p;
|
FILE *f = (FILE *)serial->data[0].p;
|
||||||
assert(f != NULL && data != NULL);
|
M_ASSERT(f != NULL && data != NULL);
|
||||||
// Write first the number of (non null) characters
|
// Write first the number of (non null) characters
|
||||||
if (m_serial_bin_write_size(f, length) != true) return m_core_serial_fail();
|
if (m_serial_bin_write_size(f, length) != true) return m_core_serial_fail();
|
||||||
// Write the characters (excluding the final null char)
|
// Write the characters (excluding the final null char)
|
||||||
@@ -424,7 +424,7 @@ m_serial_bin_read_float(m_serial_read_t serial, long double *r, const size_t siz
|
|||||||
static inline m_serial_return_code_t
|
static inline m_serial_return_code_t
|
||||||
m_serial_bin_read_string(m_serial_read_t serial, struct string_s *s){
|
m_serial_bin_read_string(m_serial_read_t serial, struct string_s *s){
|
||||||
FILE *f = (FILE*) serial->data[0].p;
|
FILE *f = (FILE*) serial->data[0].p;
|
||||||
assert(f != NULL && s != NULL);
|
M_ASSERT(f != NULL && s != NULL);
|
||||||
// First read the number of non null characters
|
// First read the number of non null characters
|
||||||
size_t length;
|
size_t length;
|
||||||
if (m_serial_bin_read_size(f, &length) != true) return m_core_serial_fail();
|
if (m_serial_bin_read_size(f, &length) != true) return m_core_serial_fail();
|
||||||
@@ -482,7 +482,7 @@ m_serial_bin_read_array_next(m_serial_local_t local, m_serial_read_t serial)
|
|||||||
return m_core_serial_fail();
|
return m_core_serial_fail();
|
||||||
return p == 0xABCDEF ? M_SERIAL_OK_CONTINUE : p == 0x12345678 ? M_SERIAL_OK_DONE : m_core_serial_fail();
|
return p == 0xABCDEF ? M_SERIAL_OK_CONTINUE : p == 0x12345678 ? M_SERIAL_OK_DONE : m_core_serial_fail();
|
||||||
} else {
|
} else {
|
||||||
assert(local->data[1].s > 0);
|
M_ASSERT(local->data[1].s > 0);
|
||||||
local->data[1].s --;
|
local->data[1].s --;
|
||||||
return local->data[1].s == 0 ? M_SERIAL_OK_DONE : M_SERIAL_OK_CONTINUE;
|
return local->data[1].s == 0 ? M_SERIAL_OK_DONE : M_SERIAL_OK_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -69,7 +69,7 @@ m_serial_json_write_string(m_serial_write_t serial, const char data[], size_t le
|
|||||||
{
|
{
|
||||||
STRINGI_ASSERT_SLOW(length == strlen(data) );
|
STRINGI_ASSERT_SLOW(length == strlen(data) );
|
||||||
FILE *f = (FILE *)serial->data[0].p;
|
FILE *f = (FILE *)serial->data[0].p;
|
||||||
assert(f != NULL && data != NULL);
|
M_ASSERT(f != NULL && data != NULL);
|
||||||
/* HACK: Build dummy string to reuse string_out_str */
|
/* HACK: Build dummy string to reuse string_out_str */
|
||||||
string_t v2;
|
string_t v2;
|
||||||
uintptr_t ptr = (uintptr_t) data;
|
uintptr_t ptr = (uintptr_t) data;
|
||||||
@@ -216,7 +216,7 @@ m_serial_json_write_variant_start(m_serial_local_t local, m_serial_write_t seria
|
|||||||
FILE *f = (FILE *)serial->data[0].p;
|
FILE *f = (FILE *)serial->data[0].p;
|
||||||
int n;
|
int n;
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
assert (index < max);
|
M_ASSERT (index < max);
|
||||||
n = fprintf(f, "{\"%s\":", field_name[index]);
|
n = fprintf(f, "{\"%s\":", field_name[index]);
|
||||||
return n > 0 ? M_SERIAL_OK_CONTINUE : m_core_serial_fail();
|
return n > 0 ? M_SERIAL_OK_CONTINUE : m_core_serial_fail();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+23
-23
@@ -155,8 +155,8 @@ static inline int sharedi_integer_cref(int *p) { return *p; }
|
|||||||
|
|
||||||
/* Contract of a shared pointer */
|
/* Contract of a shared pointer */
|
||||||
#define SHAREDI_CONTRACT(shared, cpt_oplist) do { \
|
#define SHAREDI_CONTRACT(shared, cpt_oplist) do { \
|
||||||
assert(shared != NULL); \
|
M_ASSERT(shared != NULL); \
|
||||||
assert(*shared == NULL || M_CALL_IT_CREF(cpt_oplist, &(*shared)->cpt) >= 1); \
|
M_ASSERT(*shared == NULL || M_CALL_IT_CREF(cpt_oplist, &(*shared)->cpt) >= 1); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
// deferred evaluation
|
// deferred evaluation
|
||||||
@@ -200,7 +200,7 @@ static inline int sharedi_integer_cref(int *p) { return *p; }
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _init2)(shared_t shared, type *data) \
|
M_C(name, _init2)(shared_t shared, type *data) \
|
||||||
{ \
|
{ \
|
||||||
assert (shared != NULL); \
|
M_ASSERT (shared != NULL); \
|
||||||
/* The shared ptr get exclusive access to data */ \
|
/* The shared ptr get exclusive access to data */ \
|
||||||
struct M_C(name, _s) *ptr; \
|
struct M_C(name, _s) *ptr; \
|
||||||
if (M_UNLIKELY (data == NULL)) { \
|
if (M_UNLIKELY (data == NULL)) { \
|
||||||
@@ -251,7 +251,7 @@ static inline int sharedi_integer_cref(int *p) { return *p; }
|
|||||||
const shared_t shared) \
|
const shared_t shared) \
|
||||||
{ \
|
{ \
|
||||||
SHAREDI_CONTRACT(shared, cpt_oplist); \
|
SHAREDI_CONTRACT(shared, cpt_oplist); \
|
||||||
assert (dest != shared); \
|
M_ASSERT (dest != shared); \
|
||||||
*dest = *shared; \
|
*dest = *shared; \
|
||||||
if (*dest != NULL) { \
|
if (*dest != NULL) { \
|
||||||
int n = M_CALL_ADD(cpt_oplist, &((*dest)->cpt), 1); \
|
int n = M_CALL_ADD(cpt_oplist, &((*dest)->cpt), 1); \
|
||||||
@@ -303,7 +303,7 @@ static inline int sharedi_integer_cref(int *p) { return *p; }
|
|||||||
shared_t shared) \
|
shared_t shared) \
|
||||||
{ \
|
{ \
|
||||||
SHAREDI_CONTRACT(shared, cpt_oplist); \
|
SHAREDI_CONTRACT(shared, cpt_oplist); \
|
||||||
assert (dest != NULL && dest != shared); \
|
M_ASSERT (dest != NULL && dest != shared); \
|
||||||
*dest = *shared; \
|
*dest = *shared; \
|
||||||
*shared = NULL; \
|
*shared = NULL; \
|
||||||
SHAREDI_CONTRACT(dest, cpt_oplist); \
|
SHAREDI_CONTRACT(dest, cpt_oplist); \
|
||||||
@@ -315,7 +315,7 @@ static inline int sharedi_integer_cref(int *p) { return *p; }
|
|||||||
{ \
|
{ \
|
||||||
SHAREDI_CONTRACT(dest, cpt_oplist); \
|
SHAREDI_CONTRACT(dest, cpt_oplist); \
|
||||||
SHAREDI_CONTRACT(shared, cpt_oplist); \
|
SHAREDI_CONTRACT(shared, cpt_oplist); \
|
||||||
assert (dest != shared); \
|
M_ASSERT (dest != shared); \
|
||||||
M_C(name, _clear)(dest); \
|
M_C(name, _clear)(dest); \
|
||||||
M_C(name, _init_move)(dest, shared); \
|
M_C(name, _init_move)(dest, shared); \
|
||||||
} \
|
} \
|
||||||
@@ -345,9 +345,9 @@ static inline int sharedi_integer_cref(int *p) { return *p; }
|
|||||||
M_C(name, _cref)(const shared_t shared) \
|
M_C(name, _cref)(const shared_t shared) \
|
||||||
{ \
|
{ \
|
||||||
SHAREDI_CONTRACT(shared, cpt_oplist); \
|
SHAREDI_CONTRACT(shared, cpt_oplist); \
|
||||||
assert(*shared != NULL); \
|
M_ASSERT(*shared != NULL); \
|
||||||
type *data = (*shared)->data; \
|
type *data = (*shared)->data; \
|
||||||
assert (data != NULL); \
|
M_ASSERT (data != NULL); \
|
||||||
return M_CONST_CAST (type, data); \
|
return M_CONST_CAST (type, data); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
@@ -355,9 +355,9 @@ static inline int sharedi_integer_cref(int *p) { return *p; }
|
|||||||
M_C(name, _ref)(shared_t shared) \
|
M_C(name, _ref)(shared_t shared) \
|
||||||
{ \
|
{ \
|
||||||
SHAREDI_CONTRACT(shared, cpt_oplist); \
|
SHAREDI_CONTRACT(shared, cpt_oplist); \
|
||||||
assert(*shared != NULL); \
|
M_ASSERT(*shared != NULL); \
|
||||||
type *data = (*shared)->data; \
|
type *data = (*shared)->data; \
|
||||||
assert (data != NULL); \
|
M_ASSERT (data != NULL); \
|
||||||
return data; \
|
return data; \
|
||||||
} \
|
} \
|
||||||
|
|
||||||
@@ -366,8 +366,8 @@ static inline int sharedi_integer_cref(int *p) { return *p; }
|
|||||||
/********************************** SHARED RESOURCE ************************************/
|
/********************************** SHARED RESOURCE ************************************/
|
||||||
|
|
||||||
#define SHAREDI_RESOURCE_CONTRACT(s) do { \
|
#define SHAREDI_RESOURCE_CONTRACT(s) do { \
|
||||||
assert (s != NULL); \
|
M_ASSERT (s != NULL); \
|
||||||
assert (s->buffer != NULL); \
|
M_ASSERT (s->buffer != NULL); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
// deferred
|
// deferred
|
||||||
@@ -407,8 +407,8 @@ static inline int sharedi_integer_cref(int *p) { return *p; }
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _init)(shared_t s, size_t n) \
|
M_C(name, _init)(shared_t s, size_t n) \
|
||||||
{ \
|
{ \
|
||||||
assert(s != NULL); \
|
M_ASSERT(s != NULL); \
|
||||||
assert (n > 0 && n < UINT_MAX); \
|
M_ASSERT (n > 0 && n < UINT_MAX); \
|
||||||
s->buffer = M_CALL_REALLOC(oplist, M_C(name, _atype_ct), NULL, n); \
|
s->buffer = M_CALL_REALLOC(oplist, M_C(name, _atype_ct), NULL, n); \
|
||||||
if (M_UNLIKELY (s->buffer == NULL)) { \
|
if (M_UNLIKELY (s->buffer == NULL)) { \
|
||||||
M_MEMORY_FULL(sizeof(M_C(name, _atype_ct)) * n); \
|
M_MEMORY_FULL(sizeof(M_C(name, _atype_ct)) * n); \
|
||||||
@@ -439,12 +439,12 @@ static inline int sharedi_integer_cref(int *p) { return *p; }
|
|||||||
M_C(name, _it)(it_t it, shared_t s) \
|
M_C(name, _it)(it_t it, shared_t s) \
|
||||||
{ \
|
{ \
|
||||||
SHAREDI_RESOURCE_CONTRACT(s); \
|
SHAREDI_RESOURCE_CONTRACT(s); \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
unsigned int idx = genint_pop(s->core); \
|
unsigned int idx = genint_pop(s->core); \
|
||||||
it->idx = idx; \
|
it->idx = idx; \
|
||||||
it->ref = s; \
|
it->ref = s; \
|
||||||
if (M_LIKELY (idx != GENINT_ERROR)) { \
|
if (M_LIKELY (idx != GENINT_ERROR)) { \
|
||||||
assert(atomic_load(&s->buffer[idx].cpt) == 0); \
|
M_ASSERT(atomic_load(&s->buffer[idx].cpt) == 0); \
|
||||||
atomic_store(&s->buffer[idx].cpt, 1U); \
|
atomic_store(&s->buffer[idx].cpt, 1U); \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
@@ -452,14 +452,14 @@ static inline int sharedi_integer_cref(int *p) { return *p; }
|
|||||||
static inline bool \
|
static inline bool \
|
||||||
M_C(name, _end_p)(it_t it) \
|
M_C(name, _end_p)(it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
return it->idx == GENINT_ERROR; \
|
return it->idx == GENINT_ERROR; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline type * \
|
static inline type * \
|
||||||
M_C(name, _ref)(it_t it) \
|
M_C(name, _ref)(it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert (it != NULL && it->ref != NULL && it->idx != GENINT_ERROR); \
|
M_ASSERT (it != NULL && it->ref != NULL && it->idx != GENINT_ERROR); \
|
||||||
SHAREDI_RESOURCE_CONTRACT(it->ref); \
|
SHAREDI_RESOURCE_CONTRACT(it->ref); \
|
||||||
return &it->ref->buffer[it->idx].x; \
|
return &it->ref->buffer[it->idx].x; \
|
||||||
} \
|
} \
|
||||||
@@ -467,7 +467,7 @@ static inline int sharedi_integer_cref(int *p) { return *p; }
|
|||||||
static inline type const * \
|
static inline type const * \
|
||||||
M_C(name, _cref)(it_t it) \
|
M_C(name, _cref)(it_t it) \
|
||||||
{ \
|
{ \
|
||||||
assert (it != NULL && it->ref != NULL && it->idx != GENINT_ERROR); \
|
M_ASSERT (it != NULL && it->ref != NULL && it->idx != GENINT_ERROR); \
|
||||||
SHAREDI_RESOURCE_CONTRACT(it->ref); \
|
SHAREDI_RESOURCE_CONTRACT(it->ref); \
|
||||||
return M_CONST_CAST (type, &it->ref->buffer[it->idx].x); \
|
return M_CONST_CAST (type, &it->ref->buffer[it->idx].x); \
|
||||||
} \
|
} \
|
||||||
@@ -476,8 +476,8 @@ static inline int sharedi_integer_cref(int *p) { return *p; }
|
|||||||
M_C(name, _end)(it_t it, shared_t s) \
|
M_C(name, _end)(it_t it, shared_t s) \
|
||||||
{ \
|
{ \
|
||||||
SHAREDI_RESOURCE_CONTRACT(s); \
|
SHAREDI_RESOURCE_CONTRACT(s); \
|
||||||
assert (it != NULL); \
|
M_ASSERT (it != NULL); \
|
||||||
assert (it->ref == s); \
|
M_ASSERT (it->ref == s); \
|
||||||
unsigned int idx = it->idx; \
|
unsigned int idx = it->idx; \
|
||||||
if (M_LIKELY (idx != GENINT_ERROR)) { \
|
if (M_LIKELY (idx != GENINT_ERROR)) { \
|
||||||
unsigned int c = atomic_fetch_sub (&it->ref->buffer[idx].cpt, 1U); \
|
unsigned int c = atomic_fetch_sub (&it->ref->buffer[idx].cpt, 1U); \
|
||||||
@@ -491,14 +491,14 @@ static inline int sharedi_integer_cref(int *p) { return *p; }
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _it_set)(it_t itd, it_t its) \
|
M_C(name, _it_set)(it_t itd, it_t its) \
|
||||||
{ \
|
{ \
|
||||||
assert (itd != NULL && its != NULL); \
|
M_ASSERT (itd != NULL && its != NULL); \
|
||||||
SHAREDI_RESOURCE_CONTRACT(its->ref); \
|
SHAREDI_RESOURCE_CONTRACT(its->ref); \
|
||||||
itd->ref = its->ref; \
|
itd->ref = its->ref; \
|
||||||
unsigned int idx = its->idx; \
|
unsigned int idx = its->idx; \
|
||||||
itd->idx = idx; \
|
itd->idx = idx; \
|
||||||
if (M_LIKELY (idx != GENINT_ERROR)) { \
|
if (M_LIKELY (idx != GENINT_ERROR)) { \
|
||||||
unsigned int c = atomic_fetch_add(&itd->ref->buffer[idx].cpt, 1U); \
|
unsigned int c = atomic_fetch_add(&itd->ref->buffer[idx].cpt, 1U); \
|
||||||
assert (c >= 1); \
|
M_ASSERT (c >= 1); \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
|
|
||||||
|
|||||||
+37
-37
@@ -152,12 +152,12 @@ M_BEGIN_PROTECTED_CODE
|
|||||||
/* NOTE: Due to atomic_load only accepting non-const pointer,
|
/* NOTE: Due to atomic_load only accepting non-const pointer,
|
||||||
we can't have any const in the interface. */
|
we can't have any const in the interface. */
|
||||||
#define SNAPSHOTI_SPSC_FLAGS_CONTRACT(flags) \
|
#define SNAPSHOTI_SPSC_FLAGS_CONTRACT(flags) \
|
||||||
assert(SNAPSHOTI_SPSC_R(flags) != SNAPSHOTI_SPSC_W(flags) \
|
M_ASSERT(SNAPSHOTI_SPSC_R(flags) != SNAPSHOTI_SPSC_W(flags) \
|
||||||
&& SNAPSHOTI_SPSC_R(flags) != SNAPSHOTI_SPSC_F(flags) \
|
&& SNAPSHOTI_SPSC_R(flags) != SNAPSHOTI_SPSC_F(flags) \
|
||||||
&& SNAPSHOTI_SPSC_W(flags) != SNAPSHOTI_SPSC_F(flags))
|
&& SNAPSHOTI_SPSC_W(flags) != SNAPSHOTI_SPSC_F(flags))
|
||||||
|
|
||||||
#define SNAPSHOTI_SPSC_CONTRACT(snap) do { \
|
#define SNAPSHOTI_SPSC_CONTRACT(snap) do { \
|
||||||
assert((snap) != NULL); \
|
M_ASSERT((snap) != NULL); \
|
||||||
unsigned char f = atomic_load (&(snap)->flags); \
|
unsigned char f = atomic_load (&(snap)->flags); \
|
||||||
SNAPSHOTI_SPSC_FLAGS_CONTRACT(f); \
|
SNAPSHOTI_SPSC_FLAGS_CONTRACT(f); \
|
||||||
} while (0)
|
} while (0)
|
||||||
@@ -202,7 +202,7 @@ M_BEGIN_PROTECTED_CODE
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _init)(snapshot_t snap) \
|
M_C(name, _init)(snapshot_t snap) \
|
||||||
{ \
|
{ \
|
||||||
assert(snap != NULL); \
|
M_ASSERT(snap != NULL); \
|
||||||
for(int i = 0; i < SNAPSHOTI_SPSC_MAX_BUFFER; i++) { \
|
for(int i = 0; i < SNAPSHOTI_SPSC_MAX_BUFFER; i++) { \
|
||||||
M_CALL_INIT(oplist, snap->data[i].x); \
|
M_CALL_INIT(oplist, snap->data[i].x); \
|
||||||
} \
|
} \
|
||||||
@@ -224,7 +224,7 @@ M_BEGIN_PROTECTED_CODE
|
|||||||
M_C(name, _init_set)(snapshot_t snap, snapshot_t org) \
|
M_C(name, _init_set)(snapshot_t snap, snapshot_t org) \
|
||||||
{ \
|
{ \
|
||||||
SNAPSHOTI_SPSC_CONTRACT(org); \
|
SNAPSHOTI_SPSC_CONTRACT(org); \
|
||||||
assert(snap != NULL && snap != org); \
|
M_ASSERT(snap != NULL && snap != org); \
|
||||||
for(int i = 0; i < SNAPSHOTI_SPSC_MAX_BUFFER; i++) { \
|
for(int i = 0; i < SNAPSHOTI_SPSC_MAX_BUFFER; i++) { \
|
||||||
M_CALL_INIT_SET(oplist, snap->data[i].x, org->data[i].x); \
|
M_CALL_INIT_SET(oplist, snap->data[i].x, org->data[i].x); \
|
||||||
} \
|
} \
|
||||||
@@ -250,7 +250,7 @@ M_BEGIN_PROTECTED_CODE
|
|||||||
M_C(name, _init_move)(snapshot_t snap, snapshot_t org) \
|
M_C(name, _init_move)(snapshot_t snap, snapshot_t org) \
|
||||||
{ \
|
{ \
|
||||||
SNAPSHOTI_SPSC_CONTRACT(org); \
|
SNAPSHOTI_SPSC_CONTRACT(org); \
|
||||||
assert(snap != NULL && snap != org); \
|
M_ASSERT(snap != NULL && snap != org); \
|
||||||
for(int i = 0; i < SNAPSHOTI_SPSC_MAX_BUFFER; i++) { \
|
for(int i = 0; i < SNAPSHOTI_SPSC_MAX_BUFFER; i++) { \
|
||||||
M_CALL_INIT_MOVE(oplist, snap->data[i].x, org->data[i].x); \
|
M_CALL_INIT_MOVE(oplist, snap->data[i].x, org->data[i].x); \
|
||||||
} \
|
} \
|
||||||
@@ -267,7 +267,7 @@ M_BEGIN_PROTECTED_CODE
|
|||||||
{ \
|
{ \
|
||||||
SNAPSHOTI_SPSC_CONTRACT(snap); \
|
SNAPSHOTI_SPSC_CONTRACT(snap); \
|
||||||
SNAPSHOTI_SPSC_CONTRACT(org); \
|
SNAPSHOTI_SPSC_CONTRACT(org); \
|
||||||
assert(snap != org); \
|
M_ASSERT(snap != org); \
|
||||||
for(int i = 0; i < SNAPSHOTI_SPSC_MAX_BUFFER; i++) { \
|
for(int i = 0; i < SNAPSHOTI_SPSC_MAX_BUFFER; i++) { \
|
||||||
M_CALL_MOVE(oplist, snap->data[i].x, org->data[i].x); \
|
M_CALL_MOVE(oplist, snap->data[i].x, org->data[i].x); \
|
||||||
} \
|
} \
|
||||||
@@ -377,19 +377,19 @@ typedef struct snapshot_mrsw_int_s {
|
|||||||
|
|
||||||
// can't check currentWrite due to potential data race on it
|
// can't check currentWrite due to potential data race on it
|
||||||
#define SNAPSHOTI_SPMC_INT_CONTRACT(s) do { \
|
#define SNAPSHOTI_SPMC_INT_CONTRACT(s) do { \
|
||||||
assert (s != NULL); \
|
M_ASSERT (s != NULL); \
|
||||||
assert (s->n_reader > 0 && s->n_reader <= SNAPSHOTI_SPMC_MAX_READER); \
|
M_ASSERT (s->n_reader > 0 && s->n_reader <= SNAPSHOTI_SPMC_MAX_READER); \
|
||||||
assert ((size_t)SNAPSHOTI_SPMC_INT_FLAG_W(atomic_load(&s->lastNext)) \
|
M_ASSERT ((size_t)SNAPSHOTI_SPMC_INT_FLAG_W(atomic_load(&s->lastNext)) \
|
||||||
<= s->n_reader + SNAPSHOTI_SPMC_EXTRA_BUFFER); \
|
<= s->n_reader + SNAPSHOTI_SPMC_EXTRA_BUFFER); \
|
||||||
assert (s->cptTab != NULL); \
|
M_ASSERT (s->cptTab != NULL); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
/* Initialize snapshot_mrsw_int_ct for n readers (constructor) */
|
/* Initialize snapshot_mrsw_int_ct for n readers (constructor) */
|
||||||
static inline void
|
static inline void
|
||||||
snapshot_mrsw_int_init(snapshot_mrsw_int_ct s, size_t n)
|
snapshot_mrsw_int_init(snapshot_mrsw_int_ct s, size_t n)
|
||||||
{
|
{
|
||||||
assert (s != NULL);
|
M_ASSERT (s != NULL);
|
||||||
assert (n >= 1 && n <= SNAPSHOTI_SPMC_MAX_READER);
|
M_ASSERT (n >= 1 && n <= SNAPSHOTI_SPMC_MAX_READER);
|
||||||
s->n_reader = n;
|
s->n_reader = n;
|
||||||
n += SNAPSHOTI_SPMC_EXTRA_BUFFER;
|
n += SNAPSHOTI_SPMC_EXTRA_BUFFER;
|
||||||
|
|
||||||
@@ -406,13 +406,13 @@ snapshot_mrsw_int_init(snapshot_mrsw_int_ct s, size_t n)
|
|||||||
|
|
||||||
// Get a free buffer and set it as available for readers
|
// Get a free buffer and set it as available for readers
|
||||||
unsigned int w = genint_pop(s->freeList);
|
unsigned int w = genint_pop(s->freeList);
|
||||||
assert (w != GENINT_ERROR);
|
M_ASSERT (w != GENINT_ERROR);
|
||||||
atomic_store(&s->cptTab[w], 1U);
|
atomic_store(&s->cptTab[w], 1U);
|
||||||
atomic_init(&s->lastNext, SNAPSHOTI_SPMC_INT_FLAG(w, true));
|
atomic_init(&s->lastNext, SNAPSHOTI_SPMC_INT_FLAG(w, true));
|
||||||
|
|
||||||
// Get working buffer
|
// Get working buffer
|
||||||
s->currentWrite = genint_pop(s->freeList);
|
s->currentWrite = genint_pop(s->freeList);
|
||||||
assert (s->currentWrite != GENINT_ERROR);
|
M_ASSERT (s->currentWrite != GENINT_ERROR);
|
||||||
atomic_store(&s->cptTab[s->currentWrite], 1U);
|
atomic_store(&s->cptTab[s->currentWrite], 1U);
|
||||||
SNAPSHOTI_SPMC_INT_CONTRACT(s);
|
SNAPSHOTI_SPMC_INT_CONTRACT(s);
|
||||||
}
|
}
|
||||||
@@ -468,19 +468,19 @@ snapshot_mrsw_int_write_idx(snapshot_mrsw_int_ct s, unsigned int idx)
|
|||||||
// Remove the writer thread counter from the count of the previous buffer
|
// Remove the writer thread counter from the count of the previous buffer
|
||||||
idx = SNAPSHOTI_SPMC_INT_FLAG_W(previous);
|
idx = SNAPSHOTI_SPMC_INT_FLAG_W(previous);
|
||||||
unsigned int c = atomic_fetch_sub(&s->cptTab[idx], 1U);
|
unsigned int c = atomic_fetch_sub(&s->cptTab[idx], 1U);
|
||||||
assert (c != 0 && c <= s->n_reader + 1);
|
M_ASSERT (c != 0 && c <= s->n_reader + 1);
|
||||||
// Get a new buffer.
|
// Get a new buffer.
|
||||||
if (c != 1) {
|
if (c != 1) {
|
||||||
// If someone else keeps a ref on the buffer, we can't reuse it
|
// If someone else keeps a ref on the buffer, we can't reuse it
|
||||||
// get another free one.
|
// get another free one.
|
||||||
idx = genint_pop(s->freeList);
|
idx = genint_pop(s->freeList);
|
||||||
assert(idx != GENINT_ERROR);
|
M_ASSERT(idx != GENINT_ERROR);
|
||||||
} else {
|
} else {
|
||||||
// No other thread keep track of this buffer.
|
// No other thread keep track of this buffer.
|
||||||
// Reuse it.
|
// Reuse it.
|
||||||
}
|
}
|
||||||
assert (idx < s->n_reader + SNAPSHOTI_SPMC_EXTRA_BUFFER);
|
M_ASSERT (idx < s->n_reader + SNAPSHOTI_SPMC_EXTRA_BUFFER);
|
||||||
assert (atomic_load(&s->cptTab[idx]) == 0);
|
M_ASSERT (atomic_load(&s->cptTab[idx]) == 0);
|
||||||
atomic_store(&s->cptTab[idx], 1U);
|
atomic_store(&s->cptTab[idx], 1U);
|
||||||
}
|
}
|
||||||
SNAPSHOTI_SPMC_INT_CONTRACT(s);
|
SNAPSHOTI_SPMC_INT_CONTRACT(s);
|
||||||
@@ -503,9 +503,9 @@ snapshot_mrsw_int_write_start(snapshot_mrsw_int_ct s)
|
|||||||
SNAPSHOTI_SPMC_INT_CONTRACT(s);
|
SNAPSHOTI_SPMC_INT_CONTRACT(s);
|
||||||
// Get a new buffer.
|
// Get a new buffer.
|
||||||
unsigned int idx = genint_pop(s->freeList);
|
unsigned int idx = genint_pop(s->freeList);
|
||||||
assert (idx != GENINT_ERROR);
|
M_ASSERT (idx != GENINT_ERROR);
|
||||||
assert (idx < s->n_reader + SNAPSHOTI_SPMC_EXTRA_BUFFER);
|
M_ASSERT (idx < s->n_reader + SNAPSHOTI_SPMC_EXTRA_BUFFER);
|
||||||
assert (atomic_load(&s->cptTab[idx]) == 0);
|
M_ASSERT (atomic_load(&s->cptTab[idx]) == 0);
|
||||||
atomic_store(&s->cptTab[idx], 1U);
|
atomic_store(&s->cptTab[idx], 1U);
|
||||||
SNAPSHOTI_SPMC_INT_CONTRACT(s);
|
SNAPSHOTI_SPMC_INT_CONTRACT(s);
|
||||||
return idx;
|
return idx;
|
||||||
@@ -526,7 +526,7 @@ snapshot_mrsw_int_write_end(snapshot_mrsw_int_ct s, unsigned int idx)
|
|||||||
// Free the previous write buffer
|
// Free the previous write buffer
|
||||||
idx = SNAPSHOTI_SPMC_INT_FLAG_W(previous);
|
idx = SNAPSHOTI_SPMC_INT_FLAG_W(previous);
|
||||||
unsigned int c = atomic_fetch_sub(&s->cptTab[idx], 1U);
|
unsigned int c = atomic_fetch_sub(&s->cptTab[idx], 1U);
|
||||||
assert (c != 0 && c <= s->n_reader + 1);
|
M_ASSERT (c != 0 && c <= s->n_reader + 1);
|
||||||
if (c == 1) {
|
if (c == 1) {
|
||||||
genint_push(s->freeList, idx);
|
genint_push(s->freeList, idx);
|
||||||
}
|
}
|
||||||
@@ -547,7 +547,7 @@ snapshot_mrsw_int_read_start(snapshot_mrsw_int_ct s)
|
|||||||
idx = SNAPSHOTI_SPMC_INT_FLAG_W(previous);
|
idx = SNAPSHOTI_SPMC_INT_FLAG_W(previous);
|
||||||
// Load the number of threads using this index
|
// Load the number of threads using this index
|
||||||
unsigned int c = atomic_load(&s->cptTab[idx]);
|
unsigned int c = atomic_load(&s->cptTab[idx]);
|
||||||
assert (c <= s->n_reader + 1);
|
M_ASSERT (c <= s->n_reader + 1);
|
||||||
// Reserve the index if it still being reserved by someone else
|
// Reserve the index if it still being reserved by someone else
|
||||||
if (M_UNLIKELY (c == 0
|
if (M_UNLIKELY (c == 0
|
||||||
|| !atomic_compare_exchange_strong(&s->cptTab[idx], &c, c+1)))
|
|| !atomic_compare_exchange_strong(&s->cptTab[idx], &c, c+1)))
|
||||||
@@ -567,7 +567,7 @@ snapshot_mrsw_int_read_start(snapshot_mrsw_int_ct s)
|
|||||||
}
|
}
|
||||||
// Free the reserved index as we failed it to ack it
|
// Free the reserved index as we failed it to ack it
|
||||||
c = atomic_fetch_sub(&s->cptTab[idx], 1U);
|
c = atomic_fetch_sub(&s->cptTab[idx], 1U);
|
||||||
assert (c != 0 && c <= s->n_reader + 1);
|
M_ASSERT (c != 0 && c <= s->n_reader + 1);
|
||||||
if (c == 1) {
|
if (c == 1) {
|
||||||
genint_push(s->freeList, idx);
|
genint_push(s->freeList, idx);
|
||||||
}
|
}
|
||||||
@@ -581,10 +581,10 @@ static inline void
|
|||||||
snapshot_mrsw_int_read_end(snapshot_mrsw_int_ct s, unsigned int idx)
|
snapshot_mrsw_int_read_end(snapshot_mrsw_int_ct s, unsigned int idx)
|
||||||
{
|
{
|
||||||
SNAPSHOTI_SPMC_INT_CONTRACT(s);
|
SNAPSHOTI_SPMC_INT_CONTRACT(s);
|
||||||
assert (idx < s->n_reader + SNAPSHOTI_SPMC_EXTRA_BUFFER);
|
M_ASSERT (idx < s->n_reader + SNAPSHOTI_SPMC_EXTRA_BUFFER);
|
||||||
// Decrement reference counter of the buffer
|
// Decrement reference counter of the buffer
|
||||||
unsigned int c = atomic_fetch_sub(&s->cptTab[idx], 1U);
|
unsigned int c = atomic_fetch_sub(&s->cptTab[idx], 1U);
|
||||||
assert (c != 0 && c <= s->n_reader + 1);
|
M_ASSERT (c != 0 && c <= s->n_reader + 1);
|
||||||
if (c == 1) {
|
if (c == 1) {
|
||||||
// Buffer no longer used by any reader thread.
|
// Buffer no longer used by any reader thread.
|
||||||
// Push back index in free list
|
// Push back index in free list
|
||||||
@@ -596,8 +596,8 @@ snapshot_mrsw_int_read_end(snapshot_mrsw_int_ct s, unsigned int idx)
|
|||||||
/* Contract of a SPMC snapshot.
|
/* Contract of a SPMC snapshot.
|
||||||
Nothing notable as it can be accessed concurrently */
|
Nothing notable as it can be accessed concurrently */
|
||||||
#define SNAPSHOTI_SPMC_CONTRACT(snap) do { \
|
#define SNAPSHOTI_SPMC_CONTRACT(snap) do { \
|
||||||
assert (snap != NULL); \
|
M_ASSERT (snap != NULL); \
|
||||||
assert (snap->data != NULL); \
|
M_ASSERT (snap->data != NULL); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
|
||||||
@@ -635,8 +635,8 @@ snapshot_mrsw_int_read_end(snapshot_mrsw_int_ct s, unsigned int idx)
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _init)(snapshot_t snap, size_t nReader) \
|
M_C(name, _init)(snapshot_t snap, size_t nReader) \
|
||||||
{ \
|
{ \
|
||||||
assert (snap != NULL); \
|
M_ASSERT (snap != NULL); \
|
||||||
assert (nReader > 0 && nReader <= SNAPSHOTI_SPMC_MAX_READER); \
|
M_ASSERT (nReader > 0 && nReader <= SNAPSHOTI_SPMC_MAX_READER); \
|
||||||
snap->data = M_CALL_REALLOC(oplist, M_C(name, _aligned_type_ct), \
|
snap->data = M_CALL_REALLOC(oplist, M_C(name, _aligned_type_ct), \
|
||||||
NULL, nReader+SNAPSHOTI_SPMC_EXTRA_BUFFER); \
|
NULL, nReader+SNAPSHOTI_SPMC_EXTRA_BUFFER); \
|
||||||
if (M_UNLIKELY (snap->data == NULL)) { \
|
if (M_UNLIKELY (snap->data == NULL)) { \
|
||||||
@@ -683,12 +683,12 @@ snapshot_mrsw_int_read_end(snapshot_mrsw_int_ct s, unsigned int idx)
|
|||||||
M_C(name, _read_end)(snapshot_t snap, type const *old) \
|
M_C(name, _read_end)(snapshot_t snap, type const *old) \
|
||||||
{ \
|
{ \
|
||||||
SNAPSHOTI_SPMC_CONTRACT(snap); \
|
SNAPSHOTI_SPMC_CONTRACT(snap); \
|
||||||
assert (old != NULL); \
|
M_ASSERT (old != NULL); \
|
||||||
const M_C(name, _aligned_type_ct) *oldx; \
|
const M_C(name, _aligned_type_ct) *oldx; \
|
||||||
oldx = M_CTYPE_FROM_FIELD(M_C(name, _aligned_type_ct), old, type, x); \
|
oldx = M_CTYPE_FROM_FIELD(M_C(name, _aligned_type_ct), old, type, x); \
|
||||||
assert (oldx >= snap->data); \
|
M_ASSERT (oldx >= snap->data); \
|
||||||
assert (oldx < snap->data + snap->core->n_reader + SNAPSHOTI_SPMC_EXTRA_BUFFER); \
|
M_ASSERT (oldx < snap->data + snap->core->n_reader + SNAPSHOTI_SPMC_EXTRA_BUFFER); \
|
||||||
assert(snap->core->n_reader +SNAPSHOTI_SPMC_EXTRA_BUFFER < UINT_MAX); \
|
M_ASSERT(snap->core->n_reader +SNAPSHOTI_SPMC_EXTRA_BUFFER < UINT_MAX); \
|
||||||
const unsigned int idx = (unsigned int) (oldx - snap->data); \
|
const unsigned int idx = (unsigned int) (oldx - snap->data); \
|
||||||
snapshot_mrsw_int_read_end(snap->core, idx); \
|
snapshot_mrsw_int_read_end(snap->core, idx); \
|
||||||
} \
|
} \
|
||||||
@@ -765,9 +765,9 @@ snapshot_mrsw_int_read_end(snapshot_mrsw_int_ct s, unsigned int idx)
|
|||||||
SNAPSHOTI_SPMC_CONTRACT(snap->core); \
|
SNAPSHOTI_SPMC_CONTRACT(snap->core); \
|
||||||
const M_C(name, _mrsw_aligned_type_ct) *oldx; \
|
const M_C(name, _mrsw_aligned_type_ct) *oldx; \
|
||||||
oldx = M_CTYPE_FROM_FIELD(M_C(name, _mrsw_aligned_type_ct), old, type, x); \
|
oldx = M_CTYPE_FROM_FIELD(M_C(name, _mrsw_aligned_type_ct), old, type, x); \
|
||||||
assert (oldx >= snap->core->data); \
|
M_ASSERT (oldx >= snap->core->data); \
|
||||||
assert (oldx < snap->core->data + snap->core->core->n_reader + SNAPSHOTI_SPMC_EXTRA_BUFFER); \
|
M_ASSERT (oldx < snap->core->data + snap->core->core->n_reader + SNAPSHOTI_SPMC_EXTRA_BUFFER); \
|
||||||
assert(snap->core->core->n_reader + SNAPSHOTI_SPMC_EXTRA_BUFFER < UINT_MAX); \
|
M_ASSERT(snap->core->core->n_reader + SNAPSHOTI_SPMC_EXTRA_BUFFER < UINT_MAX); \
|
||||||
const unsigned int idx = (unsigned int) (oldx - snap->core->data); \
|
const unsigned int idx = (unsigned int) (oldx - snap->core->data); \
|
||||||
snapshot_mrsw_int_write_end(snap->core->core, idx); \
|
snapshot_mrsw_int_write_end(snap->core->core, idx); \
|
||||||
} \
|
} \
|
||||||
|
|||||||
+73
-73
@@ -39,7 +39,7 @@ M_BEGIN_PROTECTED_CODE
|
|||||||
|
|
||||||
/* If within the string tests, perform additional (potentialy slow) checks */
|
/* If within the string tests, perform additional (potentialy slow) checks */
|
||||||
#ifdef STRING_WITHIN_TEST
|
#ifdef STRING_WITHIN_TEST
|
||||||
# define STRINGI_ASSERT_SLOW(n) assert(n)
|
# define STRINGI_ASSERT_SLOW(n) M_ASSERT(n)
|
||||||
#else
|
#else
|
||||||
# define STRINGI_ASSERT_SLOW(n) (void) 0
|
# define STRINGI_ASSERT_SLOW(n) (void) 0
|
||||||
#endif
|
#endif
|
||||||
@@ -48,11 +48,11 @@ M_BEGIN_PROTECTED_CODE
|
|||||||
// Note: A ==> B is represented as not(A) or B
|
// Note: A ==> B is represented as not(A) or B
|
||||||
// Note: use of strlen can slow down a lot the program in some cases.
|
// Note: use of strlen can slow down a lot the program in some cases.
|
||||||
#define STRINGI_CONTRACT(v) do { \
|
#define STRINGI_CONTRACT(v) do { \
|
||||||
assert (v != NULL); \
|
M_ASSERT (v != NULL); \
|
||||||
STRINGI_ASSERT_SLOW (string_size(v) == strlen(string_get_cstr(v))); \
|
STRINGI_ASSERT_SLOW (string_size(v) == strlen(string_get_cstr(v))); \
|
||||||
assert (string_get_cstr(v)[string_size(v)] == 0); \
|
M_ASSERT (string_get_cstr(v)[string_size(v)] == 0); \
|
||||||
assert (string_size(v) < string_capacity(v)); \
|
M_ASSERT (string_size(v) < string_capacity(v)); \
|
||||||
assert (string_capacity(v) < sizeof (string_heap_ct) || !stringi_stack_p(v)); \
|
M_ASSERT (string_capacity(v) < sizeof (string_heap_ct) || !stringi_stack_p(v)); \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
|
|
||||||
@@ -119,7 +119,7 @@ stringi_set_size(string_t s, size_t size)
|
|||||||
{
|
{
|
||||||
// Function can be called when contract is not fullfilled
|
// Function can be called when contract is not fullfilled
|
||||||
if (stringi_stack_p(s)) {
|
if (stringi_stack_p(s)) {
|
||||||
assert (size < sizeof (string_heap_ct) - 1);
|
M_ASSERT (size < sizeof (string_heap_ct) - 1);
|
||||||
s->u.stack.buffer[sizeof (string_heap_ct) - 1] = (char) size;
|
s->u.stack.buffer[sizeof (string_heap_ct) - 1] = (char) size;
|
||||||
} else
|
} else
|
||||||
s->u.heap.size = size;
|
s->u.heap.size = size;
|
||||||
@@ -215,7 +215,7 @@ string_clear_get_str(string_t v)
|
|||||||
M_MEMORY_FULL(sizeof (char) * alloc);
|
M_MEMORY_FULL(sizeof (char) * alloc);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
assert(ptr != NULL && p != NULL);
|
M_ASSERT(ptr != NULL && p != NULL);
|
||||||
memcpy(ptr, p, alloc);
|
memcpy(ptr, p, alloc);
|
||||||
p = ptr;
|
p = ptr;
|
||||||
}
|
}
|
||||||
@@ -279,7 +279,7 @@ stringi_fit2size (string_t v, size_t size_alloc)
|
|||||||
abort();
|
abort();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
assert(ptr != &v->u.stack.buffer[0]);
|
M_ASSERT(ptr != &v->u.stack.buffer[0]);
|
||||||
if (stringi_stack_p(v)) {
|
if (stringi_stack_p(v)) {
|
||||||
/* Copy the stack allocation into the heap allocation */
|
/* Copy the stack allocation into the heap allocation */
|
||||||
memcpy(ptr, &v->u.stack.buffer[0],
|
memcpy(ptr, &v->u.stack.buffer[0],
|
||||||
@@ -303,7 +303,7 @@ string_reserve(string_t v, size_t alloc)
|
|||||||
if (size + 1 > alloc) {
|
if (size + 1 > alloc) {
|
||||||
alloc = size+1;
|
alloc = size+1;
|
||||||
}
|
}
|
||||||
assert (alloc > 0);
|
M_ASSERT (alloc > 0);
|
||||||
if (alloc < sizeof (string_heap_ct)) {
|
if (alloc < sizeof (string_heap_ct)) {
|
||||||
// Allocation can fit in the stack space
|
// Allocation can fit in the stack space
|
||||||
if (!stringi_stack_p(v)) {
|
if (!stringi_stack_p(v)) {
|
||||||
@@ -341,7 +341,7 @@ static inline void
|
|||||||
string_set_str(string_t v, const char str[])
|
string_set_str(string_t v, const char str[])
|
||||||
{
|
{
|
||||||
STRINGI_CONTRACT (v);
|
STRINGI_CONTRACT (v);
|
||||||
assert(str != NULL);
|
M_ASSERT(str != NULL);
|
||||||
size_t size = strlen(str);
|
size_t size = strlen(str);
|
||||||
char *ptr = stringi_fit2size(v, size+1);
|
char *ptr = stringi_fit2size(v, size+1);
|
||||||
memcpy(ptr, str, size+1);
|
memcpy(ptr, str, size+1);
|
||||||
@@ -354,7 +354,7 @@ static inline void
|
|||||||
string_set_strn(string_t v, const char str[], size_t n)
|
string_set_strn(string_t v, const char str[], size_t n)
|
||||||
{
|
{
|
||||||
STRINGI_CONTRACT (v);
|
STRINGI_CONTRACT (v);
|
||||||
assert(str != NULL);
|
M_ASSERT(str != NULL);
|
||||||
size_t len = strlen(str);
|
size_t len = strlen(str);
|
||||||
size_t size = M_MIN (len, n);
|
size_t size = M_MIN (len, n);
|
||||||
char *ptr = stringi_fit2size(v, size+1);
|
char *ptr = stringi_fit2size(v, size+1);
|
||||||
@@ -466,7 +466,7 @@ static inline void
|
|||||||
string_cat_str(string_t v, const char str[])
|
string_cat_str(string_t v, const char str[])
|
||||||
{
|
{
|
||||||
STRINGI_CONTRACT (v);
|
STRINGI_CONTRACT (v);
|
||||||
assert (str != NULL);
|
M_ASSERT (str != NULL);
|
||||||
const size_t old_size = string_size(v);
|
const size_t old_size = string_size(v);
|
||||||
const size_t size = strlen(str);
|
const size_t size = strlen(str);
|
||||||
char *ptr = stringi_fit2size(v, old_size + size + 1);
|
char *ptr = stringi_fit2size(v, old_size + size + 1);
|
||||||
@@ -498,7 +498,7 @@ static inline int
|
|||||||
string_cmp_str(const string_t v1, const char str[])
|
string_cmp_str(const string_t v1, const char str[])
|
||||||
{
|
{
|
||||||
STRINGI_CONTRACT (v1);
|
STRINGI_CONTRACT (v1);
|
||||||
assert (str != NULL);
|
M_ASSERT (str != NULL);
|
||||||
return strcmp(string_get_cstr(v1), str);
|
return strcmp(string_get_cstr(v1), str);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -517,7 +517,7 @@ static inline bool
|
|||||||
string_equal_str_p(const string_t v1, const char str[])
|
string_equal_str_p(const string_t v1, const char str[])
|
||||||
{
|
{
|
||||||
STRINGI_CONTRACT(v1);
|
STRINGI_CONTRACT(v1);
|
||||||
assert (str != NULL);
|
M_ASSERT (str != NULL);
|
||||||
return string_cmp_str(v1, str) == 0;
|
return string_cmp_str(v1, str) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -529,8 +529,8 @@ string_equal_p(const string_t v1, const string_t v2)
|
|||||||
In case of OOR value, .ptr is NULL and .size is maximum.
|
In case of OOR value, .ptr is NULL and .size is maximum.
|
||||||
It will detect a heap based string, and read size from heap structure.
|
It will detect a heap based string, and read size from heap structure.
|
||||||
*/
|
*/
|
||||||
assert(v1 != NULL);
|
M_ASSERT(v1 != NULL);
|
||||||
assert(v2 != NULL);
|
M_ASSERT(v2 != NULL);
|
||||||
/* Optimization: both strings shall have at least the same size */
|
/* Optimization: both strings shall have at least the same size */
|
||||||
return string_size(v1) == string_size(v2) && string_cmp(v1, v2) == 0;
|
return string_size(v1) == string_size(v2) && string_cmp(v1, v2) == 0;
|
||||||
}
|
}
|
||||||
@@ -543,7 +543,7 @@ static inline int
|
|||||||
string_cmpi_str(const string_t v1, const char p2[])
|
string_cmpi_str(const string_t v1, const char p2[])
|
||||||
{
|
{
|
||||||
STRINGI_CONTRACT (v1);
|
STRINGI_CONTRACT (v1);
|
||||||
assert (p2 != NULL);
|
M_ASSERT (p2 != NULL);
|
||||||
// strcasecmp is POSIX only
|
// strcasecmp is POSIX only
|
||||||
const char *p1 = string_get_cstr(v1);
|
const char *p1 = string_get_cstr(v1);
|
||||||
int c1, c2;
|
int c1, c2;
|
||||||
@@ -608,7 +608,7 @@ string_search_str (const string_t v, const char str[], size_t start)
|
|||||||
{
|
{
|
||||||
STRINGI_CONTRACT (v);
|
STRINGI_CONTRACT (v);
|
||||||
M_ASSERT_INDEX (start, string_size(v)+1);
|
M_ASSERT_INDEX (start, string_size(v)+1);
|
||||||
assert (str != NULL);
|
M_ASSERT (str != NULL);
|
||||||
const char *p = M_ASSIGN_CAST(const char*,
|
const char *p = M_ASSIGN_CAST(const char*,
|
||||||
strstr(string_get_cstr(v)+start, str));
|
strstr(string_get_cstr(v)+start, str));
|
||||||
return p == NULL ? STRING_FAILURE : (size_t) (p-string_get_cstr(v));
|
return p == NULL ? STRING_FAILURE : (size_t) (p-string_get_cstr(v));
|
||||||
@@ -634,7 +634,7 @@ string_search_pbrk(const string_t v1, const char first_of[], size_t start)
|
|||||||
{
|
{
|
||||||
STRINGI_CONTRACT (v1);
|
STRINGI_CONTRACT (v1);
|
||||||
M_ASSERT_INDEX (start, string_size(v1)+1);
|
M_ASSERT_INDEX (start, string_size(v1)+1);
|
||||||
assert (first_of != NULL);
|
M_ASSERT (first_of != NULL);
|
||||||
const char *p = M_ASSIGN_CAST(const char*,
|
const char *p = M_ASSIGN_CAST(const char*,
|
||||||
strpbrk(string_get_cstr(v1)+start, first_of));
|
strpbrk(string_get_cstr(v1)+start, first_of));
|
||||||
return p == NULL ? STRING_FAILURE : (size_t) (p-string_get_cstr(v1));
|
return p == NULL ? STRING_FAILURE : (size_t) (p-string_get_cstr(v1));
|
||||||
@@ -662,7 +662,7 @@ static inline size_t
|
|||||||
string_spn(const string_t v1, const char accept[])
|
string_spn(const string_t v1, const char accept[])
|
||||||
{
|
{
|
||||||
STRINGI_CONTRACT (v1);
|
STRINGI_CONTRACT (v1);
|
||||||
assert (accept != NULL);
|
M_ASSERT (accept != NULL);
|
||||||
return strspn(string_get_cstr(v1), accept);
|
return strspn(string_get_cstr(v1), accept);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -672,7 +672,7 @@ static inline size_t
|
|||||||
string_cspn(const string_t v1, const char reject[])
|
string_cspn(const string_t v1, const char reject[])
|
||||||
{
|
{
|
||||||
STRINGI_CONTRACT (v1);
|
STRINGI_CONTRACT (v1);
|
||||||
assert (reject != NULL);
|
M_ASSERT (reject != NULL);
|
||||||
return strcspn(string_get_cstr(v1), reject);
|
return strcspn(string_get_cstr(v1), reject);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -723,13 +723,13 @@ static inline size_t
|
|||||||
string_replace_str (string_t v, const char str1[], const char str2[], size_t start)
|
string_replace_str (string_t v, const char str1[], const char str2[], size_t start)
|
||||||
{
|
{
|
||||||
STRINGI_CONTRACT (v);
|
STRINGI_CONTRACT (v);
|
||||||
assert (str1 != NULL && str2 != NULL);
|
M_ASSERT (str1 != NULL && str2 != NULL);
|
||||||
size_t i = string_search_str(v, str1, start);
|
size_t i = string_search_str(v, str1, start);
|
||||||
if (i != STRING_FAILURE) {
|
if (i != STRING_FAILURE) {
|
||||||
const size_t str1_l = strlen(str1);
|
const size_t str1_l = strlen(str1);
|
||||||
const size_t str2_l = strlen(str2);
|
const size_t str2_l = strlen(str2);
|
||||||
const size_t size = string_size(v);
|
const size_t size = string_size(v);
|
||||||
assert(size + 1 + str2_l > str1_l);
|
M_ASSERT(size + 1 + str2_l > str1_l);
|
||||||
char *ptr = stringi_fit2size (v, size + str2_l - str1_l + 1);
|
char *ptr = stringi_fit2size (v, size + str2_l - str1_l + 1);
|
||||||
if (str1_l != str2_l) {
|
if (str1_l != str2_l) {
|
||||||
memmove(&ptr[i+str2_l], &ptr[i+str1_l], size - i - str1_l + 1);
|
memmove(&ptr[i+str2_l], &ptr[i+str1_l], size - i - str1_l + 1);
|
||||||
@@ -759,7 +759,7 @@ static inline void
|
|||||||
string_replace_at (string_t v, size_t pos, size_t len, const char str2[])
|
string_replace_at (string_t v, size_t pos, size_t len, const char str2[])
|
||||||
{
|
{
|
||||||
STRINGI_CONTRACT (v);
|
STRINGI_CONTRACT (v);
|
||||||
assert(str2 != NULL);
|
M_ASSERT(str2 != NULL);
|
||||||
const size_t str1_l = len;
|
const size_t str1_l = len;
|
||||||
const size_t str2_l = strlen(str2);
|
const size_t str2_l = strlen(str2);
|
||||||
const size_t size = string_size(v);
|
const size_t size = string_size(v);
|
||||||
@@ -782,7 +782,7 @@ static inline int
|
|||||||
string_printf (string_t v, const char format[], ...)
|
string_printf (string_t v, const char format[], ...)
|
||||||
{
|
{
|
||||||
STRINGI_CONTRACT (v);
|
STRINGI_CONTRACT (v);
|
||||||
assert (format != NULL);
|
M_ASSERT (format != NULL);
|
||||||
va_list args;
|
va_list args;
|
||||||
int size;
|
int size;
|
||||||
char *ptr = stringi_get_str(v);
|
char *ptr = stringi_get_str(v);
|
||||||
@@ -797,7 +797,7 @@ string_printf (string_t v, const char format[], ...)
|
|||||||
va_end (args);
|
va_end (args);
|
||||||
va_start (args, format);
|
va_start (args, format);
|
||||||
size = vsnprintf (ptr, alloc, format, args);
|
size = vsnprintf (ptr, alloc, format, args);
|
||||||
assert (size > 0 && (size_t)size < alloc);
|
M_ASSERT (size > 0 && (size_t)size < alloc);
|
||||||
}
|
}
|
||||||
if (size >= 0) {
|
if (size >= 0) {
|
||||||
stringi_set_size(v, (size_t) size);
|
stringi_set_size(v, (size_t) size);
|
||||||
@@ -812,7 +812,7 @@ static inline int
|
|||||||
string_cat_printf (string_t v, const char format[], ...)
|
string_cat_printf (string_t v, const char format[], ...)
|
||||||
{
|
{
|
||||||
STRINGI_CONTRACT (v);
|
STRINGI_CONTRACT (v);
|
||||||
assert (format != NULL);
|
M_ASSERT (format != NULL);
|
||||||
va_list args;
|
va_list args;
|
||||||
int size;
|
int size;
|
||||||
size_t old_size = string_size(v);
|
size_t old_size = string_size(v);
|
||||||
@@ -828,7 +828,7 @@ string_cat_printf (string_t v, const char format[], ...)
|
|||||||
va_end (args);
|
va_end (args);
|
||||||
va_start (args, format);
|
va_start (args, format);
|
||||||
size = vsnprintf (&ptr[old_size], alloc - old_size, format, args);
|
size = vsnprintf (&ptr[old_size], alloc - old_size, format, args);
|
||||||
assert (size >= 0);
|
M_ASSERT (size >= 0);
|
||||||
}
|
}
|
||||||
if (size >= 0) {
|
if (size >= 0) {
|
||||||
stringi_set_size(v, old_size + (size_t) size);
|
stringi_set_size(v, old_size + (size_t) size);
|
||||||
@@ -847,7 +847,7 @@ static inline bool
|
|||||||
string_fgets(string_t v, FILE *f, string_fgets_t arg)
|
string_fgets(string_t v, FILE *f, string_fgets_t arg)
|
||||||
{
|
{
|
||||||
STRINGI_CONTRACT(v);
|
STRINGI_CONTRACT(v);
|
||||||
assert (f != NULL);
|
M_ASSERT (f != NULL);
|
||||||
char *ptr = stringi_fit2size (v, 100);
|
char *ptr = stringi_fit2size (v, 100);
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
size_t alloc = string_capacity(v);
|
size_t alloc = string_capacity(v);
|
||||||
@@ -891,7 +891,7 @@ string_fget_word (string_t v, const char separator[], FILE *f)
|
|||||||
char c = 0;
|
char c = 0;
|
||||||
int d;
|
int d;
|
||||||
STRINGI_CONTRACT(v);
|
STRINGI_CONTRACT(v);
|
||||||
assert (f != NULL);
|
M_ASSERT (f != NULL);
|
||||||
M_ASSERT_INDEX (1+20+2+strlen(separator)+3, sizeof buffer);
|
M_ASSERT_INDEX (1+20+2+strlen(separator)+3, sizeof buffer);
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
bool retcode = false;
|
bool retcode = false;
|
||||||
@@ -931,7 +931,7 @@ string_fget_word (string_t v, const char separator[], FILE *f)
|
|||||||
stringi_set_size(v, size);
|
stringi_set_size(v, size);
|
||||||
ptr = stringi_fit2size (v, alloc + alloc/2);
|
ptr = stringi_fit2size (v, alloc + alloc/2);
|
||||||
alloc = string_capacity(v);
|
alloc = string_capacity(v);
|
||||||
assert (alloc > size + 1);
|
M_ASSERT (alloc > size + 1);
|
||||||
ptr[size++] = c;
|
ptr[size++] = c;
|
||||||
ptr[size] = 0;
|
ptr[size] = 0;
|
||||||
// Invalid c character for next iteration
|
// Invalid c character for next iteration
|
||||||
@@ -947,7 +947,7 @@ static inline bool
|
|||||||
string_fputs(FILE *f, const string_t v)
|
string_fputs(FILE *f, const string_t v)
|
||||||
{
|
{
|
||||||
STRINGI_CONTRACT (v);
|
STRINGI_CONTRACT (v);
|
||||||
assert (f != NULL);
|
M_ASSERT (f != NULL);
|
||||||
return fputs(string_get_cstr(v), f) >= 0;
|
return fputs(string_get_cstr(v), f) >= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -956,7 +956,7 @@ static inline bool
|
|||||||
string_start_with_str_p(const string_t v, const char str[])
|
string_start_with_str_p(const string_t v, const char str[])
|
||||||
{
|
{
|
||||||
STRINGI_CONTRACT (v);
|
STRINGI_CONTRACT (v);
|
||||||
assert (str != NULL);
|
M_ASSERT (str != NULL);
|
||||||
const char *v_str = string_get_cstr(v);
|
const char *v_str = string_get_cstr(v);
|
||||||
while (*str){
|
while (*str){
|
||||||
if (*str != *v_str)
|
if (*str != *v_str)
|
||||||
@@ -980,7 +980,7 @@ static inline bool
|
|||||||
string_end_with_str_p(const string_t v, const char str[])
|
string_end_with_str_p(const string_t v, const char str[])
|
||||||
{
|
{
|
||||||
STRINGI_CONTRACT (v);
|
STRINGI_CONTRACT (v);
|
||||||
assert (str != NULL);
|
M_ASSERT (str != NULL);
|
||||||
const char *v_str = string_get_cstr(v);
|
const char *v_str = string_get_cstr(v);
|
||||||
const size_t v_l = string_size(v);
|
const size_t v_l = string_size(v);
|
||||||
const size_t str_l = strlen(str);
|
const size_t str_l = strlen(str);
|
||||||
@@ -1034,7 +1034,7 @@ string_strim(string_t v, const char charac[])
|
|||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
while (stringi_strim_char(*b, charac))
|
while (stringi_strim_char(*b, charac))
|
||||||
b++;
|
b++;
|
||||||
assert (b >= ptr && size >= (size_t) (b - ptr) );
|
M_ASSERT (b >= ptr && size >= (size_t) (b - ptr) );
|
||||||
size -= (size_t) (b - ptr);
|
size -= (size_t) (b - ptr);
|
||||||
memmove (ptr, b, size);
|
memmove (ptr, b, size);
|
||||||
}
|
}
|
||||||
@@ -1071,7 +1071,7 @@ string_get_str(string_t v, const string_t v2, bool append)
|
|||||||
{
|
{
|
||||||
STRINGI_CONTRACT(v2);
|
STRINGI_CONTRACT(v2);
|
||||||
STRINGI_CONTRACT(v);
|
STRINGI_CONTRACT(v);
|
||||||
assert (v != v2); // Limitation
|
M_ASSERT (v != v2); // Limitation
|
||||||
size_t size = append ? string_size(v) : 0;
|
size_t size = append ? string_size(v) : 0;
|
||||||
size_t v2_size = string_size(v2);
|
size_t v2_size = string_size(v2);
|
||||||
size_t targetSize = size + v2_size + 3;
|
size_t targetSize = size + v2_size + 3;
|
||||||
@@ -1112,7 +1112,7 @@ string_get_str(string_t v, const string_t v2, bool append)
|
|||||||
ptr[size ++] = '"';
|
ptr[size ++] = '"';
|
||||||
ptr[size] = 0;
|
ptr[size] = 0;
|
||||||
stringi_set_size(v, size);
|
stringi_set_size(v, size);
|
||||||
assert (size <= targetSize);
|
M_ASSERT (size <= targetSize);
|
||||||
STRINGI_CONTRACT (v);
|
STRINGI_CONTRACT (v);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1122,7 +1122,7 @@ static inline void
|
|||||||
string_out_str(FILE *f, const string_t v)
|
string_out_str(FILE *f, const string_t v)
|
||||||
{
|
{
|
||||||
STRINGI_CONTRACT(v);
|
STRINGI_CONTRACT(v);
|
||||||
assert (f != NULL);
|
M_ASSERT (f != NULL);
|
||||||
fputc('"', f);
|
fputc('"', f);
|
||||||
size_t size = string_size(v);
|
size_t size = string_size(v);
|
||||||
for(size_t i = 0 ; i < size; i++) {
|
for(size_t i = 0 ; i < size; i++) {
|
||||||
@@ -1159,7 +1159,7 @@ static inline bool
|
|||||||
string_in_str(string_t v, FILE *f)
|
string_in_str(string_t v, FILE *f)
|
||||||
{
|
{
|
||||||
STRINGI_CONTRACT(v);
|
STRINGI_CONTRACT(v);
|
||||||
assert (f != NULL);
|
M_ASSERT (f != NULL);
|
||||||
int c = fgetc(f);
|
int c = fgetc(f);
|
||||||
if (c != '"') return false;
|
if (c != '"') return false;
|
||||||
string_clean(v);
|
string_clean(v);
|
||||||
@@ -1208,7 +1208,7 @@ static inline bool
|
|||||||
string_parse_str(string_t v, const char str[], const char **endptr)
|
string_parse_str(string_t v, const char str[], const char **endptr)
|
||||||
{
|
{
|
||||||
STRINGI_CONTRACT(v);
|
STRINGI_CONTRACT(v);
|
||||||
assert (str != NULL);
|
M_ASSERT (str != NULL);
|
||||||
bool success = false;
|
bool success = false;
|
||||||
int c = *str++;
|
int c = *str++;
|
||||||
if (c != '"') goto exit;
|
if (c != '"') goto exit;
|
||||||
@@ -1259,7 +1259,7 @@ string_parse_str(string_t v, const char str[], const char **endptr)
|
|||||||
static inline m_serial_return_code_t
|
static inline m_serial_return_code_t
|
||||||
string_out_serial(m_serial_write_t serial, const string_t v)
|
string_out_serial(m_serial_write_t serial, const string_t v)
|
||||||
{
|
{
|
||||||
assert (serial != NULL && serial->m_interface != NULL);
|
M_ASSERT (serial != NULL && serial->m_interface != NULL);
|
||||||
return serial->m_interface->write_string(serial, string_get_cstr(v), string_size(v) );
|
return serial->m_interface->write_string(serial, string_get_cstr(v), string_size(v) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1270,7 +1270,7 @@ string_out_serial(m_serial_write_t serial, const string_t v)
|
|||||||
static inline m_serial_return_code_t
|
static inline m_serial_return_code_t
|
||||||
string_in_serial(string_t v, m_serial_read_t serial)
|
string_in_serial(string_t v, m_serial_read_t serial)
|
||||||
{
|
{
|
||||||
assert (serial != NULL && serial->m_interface != NULL);
|
M_ASSERT (serial != NULL && serial->m_interface != NULL);
|
||||||
return serial->m_interface->read_string(serial, v);
|
return serial->m_interface->read_string(serial, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1411,7 +1411,7 @@ static inline void
|
|||||||
string_it(string_it_t it, const string_t str)
|
string_it(string_it_t it, const string_t str)
|
||||||
{
|
{
|
||||||
STRINGI_CONTRACT(str);
|
STRINGI_CONTRACT(str);
|
||||||
assert(it != NULL);
|
M_ASSERT(it != NULL);
|
||||||
it->ptr = string_get_cstr(str);
|
it->ptr = string_get_cstr(str);
|
||||||
it->next_ptr = it->ptr;
|
it->next_ptr = it->ptr;
|
||||||
it->u = 0;
|
it->u = 0;
|
||||||
@@ -1424,7 +1424,7 @@ static inline void
|
|||||||
string_it_end(string_it_t it, const string_t str)
|
string_it_end(string_it_t it, const string_t str)
|
||||||
{
|
{
|
||||||
STRINGI_CONTRACT(str);
|
STRINGI_CONTRACT(str);
|
||||||
assert(it != NULL);
|
M_ASSERT(it != NULL);
|
||||||
it->ptr = &string_get_cstr(str)[string_size(str)];
|
it->ptr = &string_get_cstr(str)[string_size(str)];
|
||||||
it->next_ptr = 0;
|
it->next_ptr = 0;
|
||||||
it->u = 0;
|
it->u = 0;
|
||||||
@@ -1434,7 +1434,7 @@ string_it_end(string_it_t it, const string_t str)
|
|||||||
static inline void
|
static inline void
|
||||||
string_it_set(string_it_t it, const string_it_t itsrc)
|
string_it_set(string_it_t it, const string_it_t itsrc)
|
||||||
{
|
{
|
||||||
assert(it != NULL && itsrc != NULL);
|
M_ASSERT(it != NULL && itsrc != NULL);
|
||||||
it->ptr = itsrc->ptr;
|
it->ptr = itsrc->ptr;
|
||||||
it->next_ptr = itsrc->next_ptr;
|
it->next_ptr = itsrc->next_ptr;
|
||||||
it->u = itsrc->u;
|
it->u = itsrc->u;
|
||||||
@@ -1444,7 +1444,7 @@ string_it_set(string_it_t it, const string_it_t itsrc)
|
|||||||
static inline bool
|
static inline bool
|
||||||
string_end_p (string_it_t it)
|
string_end_p (string_it_t it)
|
||||||
{
|
{
|
||||||
assert (it != NULL);
|
M_ASSERT (it != NULL);
|
||||||
if (M_UNLIKELY (*it->ptr == 0))
|
if (M_UNLIKELY (*it->ptr == 0))
|
||||||
return true;
|
return true;
|
||||||
stringi_utf8_state_e state = STRINGI_UTF8_STARTING;
|
stringi_utf8_state_e state = STRINGI_UTF8_STARTING;
|
||||||
@@ -1463,9 +1463,9 @@ string_end_p (string_it_t it)
|
|||||||
static inline bool
|
static inline bool
|
||||||
string_it_equal_p(const string_it_t it1, const string_it_t it2)
|
string_it_equal_p(const string_it_t it1, const string_it_t it2)
|
||||||
{
|
{
|
||||||
assert(it1 != NULL && it2 != NULL);
|
M_ASSERT(it1 != NULL && it2 != NULL);
|
||||||
// IT1.ptr == IT2.ptr ==> IT1 == IT2 ==> All fields are equal
|
// IT1.ptr == IT2.ptr ==> IT1 == IT2 ==> All fields are equal
|
||||||
assert(it1->ptr != it2->ptr || (it1->next_ptr == it2->next_ptr && it1->u == it2->u));
|
M_ASSERT(it1->ptr != it2->ptr || (it1->next_ptr == it2->next_ptr && it1->u == it2->u));
|
||||||
return it1->ptr == it2->ptr;
|
return it1->ptr == it2->ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1473,7 +1473,7 @@ string_it_equal_p(const string_it_t it1, const string_it_t it2)
|
|||||||
static inline void
|
static inline void
|
||||||
string_next (string_it_t it)
|
string_next (string_it_t it)
|
||||||
{
|
{
|
||||||
assert (it != NULL);
|
M_ASSERT (it != NULL);
|
||||||
it->ptr = it->next_ptr;
|
it->ptr = it->next_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1481,7 +1481,7 @@ string_next (string_it_t it)
|
|||||||
static inline string_unicode_t
|
static inline string_unicode_t
|
||||||
string_get_cref (const string_it_t it)
|
string_get_cref (const string_it_t it)
|
||||||
{
|
{
|
||||||
assert (it != NULL);
|
M_ASSERT (it != NULL);
|
||||||
return it->u;
|
return it->u;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1489,7 +1489,7 @@ string_get_cref (const string_it_t it)
|
|||||||
static inline const string_unicode_t *
|
static inline const string_unicode_t *
|
||||||
string_cref (const string_it_t it)
|
string_cref (const string_it_t it)
|
||||||
{
|
{
|
||||||
assert (it != NULL);
|
M_ASSERT (it != NULL);
|
||||||
return &it->u;
|
return &it->u;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1796,8 +1796,8 @@ namespace m_string {
|
|||||||
/* Contract of a bounded string.
|
/* Contract of a bounded string.
|
||||||
* A bounded string last characters is always zero. */
|
* A bounded string last characters is always zero. */
|
||||||
#define BOUNDED_STRINGI_CONTRACT(var, max_size) do { \
|
#define BOUNDED_STRINGI_CONTRACT(var, max_size) do { \
|
||||||
assert(var != NULL); \
|
M_ASSERT(var != NULL); \
|
||||||
assert(var->s[max_size] == 0); \
|
M_ASSERT(var->s[max_size] == 0); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
/* Expand the functions for a bounded string */
|
/* Expand the functions for a bounded string */
|
||||||
@@ -1816,7 +1816,7 @@ namespace m_string {
|
|||||||
static inline void \
|
static inline void \
|
||||||
M_C(name, _init)(bounded_t s) \
|
M_C(name, _init)(bounded_t s) \
|
||||||
{ \
|
{ \
|
||||||
assert(s != NULL); \
|
M_ASSERT(s != NULL); \
|
||||||
M_STATIC_ASSERT(max_size >= 1, M_LIB_INTERNAL, "M*LIB: max_size parameter shall be greater than 0."); \
|
M_STATIC_ASSERT(max_size >= 1, M_LIB_INTERNAL, "M*LIB: max_size parameter shall be greater than 0."); \
|
||||||
s->s[0] = 0; \
|
s->s[0] = 0; \
|
||||||
s->s[max_size] = 0; \
|
s->s[max_size] = 0; \
|
||||||
@@ -1880,7 +1880,7 @@ namespace m_string {
|
|||||||
M_C(name, _set_strn)(bounded_t s, const char str[], size_t n) \
|
M_C(name, _set_strn)(bounded_t s, const char str[], size_t n) \
|
||||||
{ \
|
{ \
|
||||||
BOUNDED_STRINGI_CONTRACT(s, max_size); \
|
BOUNDED_STRINGI_CONTRACT(s, max_size); \
|
||||||
assert(str != NULL); \
|
M_ASSERT(str != NULL); \
|
||||||
size_t len = M_MIN(max_size, n); \
|
size_t len = M_MIN(max_size, n); \
|
||||||
m_core_strncpy(s->s, str, len); \
|
m_core_strncpy(s->s, str, len); \
|
||||||
s->s[len] = 0; \
|
s->s[len] = 0; \
|
||||||
@@ -1930,7 +1930,7 @@ namespace m_string {
|
|||||||
M_C(name, _cat_str)(bounded_t s, const char str[]) \
|
M_C(name, _cat_str)(bounded_t s, const char str[]) \
|
||||||
{ \
|
{ \
|
||||||
BOUNDED_STRINGI_CONTRACT(s, max_size); \
|
BOUNDED_STRINGI_CONTRACT(s, max_size); \
|
||||||
assert (str != NULL); \
|
M_ASSERT (str != NULL); \
|
||||||
M_ASSERT_INDEX (strlen(s->s), max_size+1); \
|
M_ASSERT_INDEX (strlen(s->s), max_size+1); \
|
||||||
m_core_strncat(s->s, str, max_size-strlen(s->s)); \
|
m_core_strncat(s->s, str, max_size-strlen(s->s)); \
|
||||||
} \
|
} \
|
||||||
@@ -1946,7 +1946,7 @@ namespace m_string {
|
|||||||
M_C(name, _cmp_str)(const bounded_t s, const char str[]) \
|
M_C(name, _cmp_str)(const bounded_t s, const char str[]) \
|
||||||
{ \
|
{ \
|
||||||
BOUNDED_STRINGI_CONTRACT(s, max_size); \
|
BOUNDED_STRINGI_CONTRACT(s, max_size); \
|
||||||
assert(str != NULL); \
|
M_ASSERT(str != NULL); \
|
||||||
return strcmp(s->s, str); \
|
return strcmp(s->s, str); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
@@ -1962,7 +1962,7 @@ namespace m_string {
|
|||||||
M_C(name, _equal_str_p)(const bounded_t s, const char str[]) \
|
M_C(name, _equal_str_p)(const bounded_t s, const char str[]) \
|
||||||
{ \
|
{ \
|
||||||
BOUNDED_STRINGI_CONTRACT(s, max_size); \
|
BOUNDED_STRINGI_CONTRACT(s, max_size); \
|
||||||
assert(str != NULL); \
|
M_ASSERT(str != NULL); \
|
||||||
return strcmp(s->s, str) == 0; \
|
return strcmp(s->s, str) == 0; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
@@ -1977,7 +1977,7 @@ namespace m_string {
|
|||||||
M_C(name, _printf)(bounded_t s, const char format[], ...) \
|
M_C(name, _printf)(bounded_t s, const char format[], ...) \
|
||||||
{ \
|
{ \
|
||||||
BOUNDED_STRINGI_CONTRACT(s, max_size); \
|
BOUNDED_STRINGI_CONTRACT(s, max_size); \
|
||||||
assert(format != NULL); \
|
M_ASSERT(format != NULL); \
|
||||||
va_list args; \
|
va_list args; \
|
||||||
int ret; \
|
int ret; \
|
||||||
va_start (args, format); \
|
va_start (args, format); \
|
||||||
@@ -1990,12 +1990,12 @@ namespace m_string {
|
|||||||
M_C(name, _cat_printf)(bounded_t s, const char format[], ...) \
|
M_C(name, _cat_printf)(bounded_t s, const char format[], ...) \
|
||||||
{ \
|
{ \
|
||||||
BOUNDED_STRINGI_CONTRACT(s, max_size); \
|
BOUNDED_STRINGI_CONTRACT(s, max_size); \
|
||||||
assert(format != NULL); \
|
M_ASSERT(format != NULL); \
|
||||||
va_list args; \
|
va_list args; \
|
||||||
int ret; \
|
int ret; \
|
||||||
va_start (args, format); \
|
va_start (args, format); \
|
||||||
size_t length = strlen(s->s); \
|
size_t length = strlen(s->s); \
|
||||||
assert(length <= max_size); \
|
M_ASSERT(length <= max_size); \
|
||||||
ret = vsnprintf (&s->s[length], max_size+1-length, format, args); \
|
ret = vsnprintf (&s->s[length], max_size+1-length, format, args); \
|
||||||
va_end (args); \
|
va_end (args); \
|
||||||
return ret; \
|
return ret; \
|
||||||
@@ -2005,8 +2005,8 @@ namespace m_string {
|
|||||||
M_C(name, _fgets)(bounded_t s, FILE *f, string_fgets_t arg) \
|
M_C(name, _fgets)(bounded_t s, FILE *f, string_fgets_t arg) \
|
||||||
{ \
|
{ \
|
||||||
BOUNDED_STRINGI_CONTRACT(s, max_size); \
|
BOUNDED_STRINGI_CONTRACT(s, max_size); \
|
||||||
assert(f != NULL); \
|
M_ASSERT(f != NULL); \
|
||||||
assert(arg != STRING_READ_FILE); \
|
M_ASSERT(arg != STRING_READ_FILE); \
|
||||||
char *ret = fgets(s->s, max_size+1, f); \
|
char *ret = fgets(s->s, max_size+1, f); \
|
||||||
s->s[max_size] = 0; \
|
s->s[max_size] = 0; \
|
||||||
if (ret != NULL && arg == STRING_READ_PURE_LINE) { \
|
if (ret != NULL && arg == STRING_READ_PURE_LINE) { \
|
||||||
@@ -2021,7 +2021,7 @@ namespace m_string {
|
|||||||
M_C(name, _fputs)(FILE *f, const bounded_t s) \
|
M_C(name, _fputs)(FILE *f, const bounded_t s) \
|
||||||
{ \
|
{ \
|
||||||
BOUNDED_STRINGI_CONTRACT(s, max_size); \
|
BOUNDED_STRINGI_CONTRACT(s, max_size); \
|
||||||
assert(f != NULL); \
|
M_ASSERT(f != NULL); \
|
||||||
return fputs(s->s, f) >= 0; \
|
return fputs(s->s, f) >= 0; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
@@ -2043,8 +2043,8 @@ namespace m_string {
|
|||||||
M_C(name, _oor_equal_p)(const bounded_t s, unsigned char n) \
|
M_C(name, _oor_equal_p)(const bounded_t s, unsigned char n) \
|
||||||
{ \
|
{ \
|
||||||
/* s may be invalid contract */ \
|
/* s may be invalid contract */ \
|
||||||
assert (s != NULL); \
|
M_ASSERT (s != NULL); \
|
||||||
assert ( (n == 0) || (n == 1)); \
|
M_ASSERT ( (n == 0) || (n == 1)); \
|
||||||
return s->s[max_size] == (char) (n+1); \
|
return s->s[max_size] == (char) (n+1); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
@@ -2052,8 +2052,8 @@ namespace m_string {
|
|||||||
M_C(name, _oor_set)(bounded_t s, unsigned char n) \
|
M_C(name, _oor_set)(bounded_t s, unsigned char n) \
|
||||||
{ \
|
{ \
|
||||||
/* s may be invalid contract */ \
|
/* s may be invalid contract */ \
|
||||||
assert (s != NULL); \
|
M_ASSERT (s != NULL); \
|
||||||
assert ( (n == 0) || (n == 1)); \
|
M_ASSERT ( (n == 0) || (n == 1)); \
|
||||||
s->s[max_size] = (char) (n+1); \
|
s->s[max_size] = (char) (n+1); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
@@ -2075,7 +2075,7 @@ namespace m_string {
|
|||||||
M_C(name, _out_str)(FILE *f, const bounded_t s) \
|
M_C(name, _out_str)(FILE *f, const bounded_t s) \
|
||||||
{ \
|
{ \
|
||||||
BOUNDED_STRINGI_CONTRACT(s, max_size); \
|
BOUNDED_STRINGI_CONTRACT(s, max_size); \
|
||||||
assert(f != NULL); \
|
M_ASSERT(f != NULL); \
|
||||||
/* Build dummy string to reuse string_get_str */ \
|
/* Build dummy string to reuse string_get_str */ \
|
||||||
uintptr_t ptr = (uintptr_t) &s->s[0]; \
|
uintptr_t ptr = (uintptr_t) &s->s[0]; \
|
||||||
string_t v2; \
|
string_t v2; \
|
||||||
@@ -2089,7 +2089,7 @@ namespace m_string {
|
|||||||
M_C(name, _in_str)(bounded_t v, FILE *f) \
|
M_C(name, _in_str)(bounded_t v, FILE *f) \
|
||||||
{ \
|
{ \
|
||||||
BOUNDED_STRINGI_CONTRACT(v, max_size); \
|
BOUNDED_STRINGI_CONTRACT(v, max_size); \
|
||||||
assert(f != NULL); \
|
M_ASSERT(f != NULL); \
|
||||||
string_t v2; \
|
string_t v2; \
|
||||||
string_init(v2); \
|
string_init(v2); \
|
||||||
bool ret = string_in_str(v2, f); \
|
bool ret = string_in_str(v2, f); \
|
||||||
@@ -2102,7 +2102,7 @@ namespace m_string {
|
|||||||
M_C(name, _parse_str)(bounded_t v, const char str[], const char **endptr) \
|
M_C(name, _parse_str)(bounded_t v, const char str[], const char **endptr) \
|
||||||
{ \
|
{ \
|
||||||
BOUNDED_STRINGI_CONTRACT(v, max_size); \
|
BOUNDED_STRINGI_CONTRACT(v, max_size); \
|
||||||
assert(str != NULL); \
|
M_ASSERT(str != NULL); \
|
||||||
string_t v2; \
|
string_t v2; \
|
||||||
string_init(v2); \
|
string_init(v2); \
|
||||||
bool ret = string_parse_str(v2, str, endptr); \
|
bool ret = string_parse_str(v2, str, endptr); \
|
||||||
@@ -2115,7 +2115,7 @@ namespace m_string {
|
|||||||
M_C(name, _out_serial)(m_serial_write_t serial, const bounded_t v) \
|
M_C(name, _out_serial)(m_serial_write_t serial, const bounded_t v) \
|
||||||
{ \
|
{ \
|
||||||
BOUNDED_STRINGI_CONTRACT(v, max_size); \
|
BOUNDED_STRINGI_CONTRACT(v, max_size); \
|
||||||
assert (serial != NULL && serial->m_interface != NULL); \
|
M_ASSERT (serial != NULL && serial->m_interface != NULL); \
|
||||||
return serial->m_interface->write_string(serial, v->s, strlen(v->s) ); \
|
return serial->m_interface->write_string(serial, v->s, strlen(v->s) ); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
@@ -2123,7 +2123,7 @@ namespace m_string {
|
|||||||
M_C(name, _in_serial)(bounded_t v, m_serial_read_t serial) \
|
M_C(name, _in_serial)(bounded_t v, m_serial_read_t serial) \
|
||||||
{ \
|
{ \
|
||||||
BOUNDED_STRINGI_CONTRACT(v, max_size); \
|
BOUNDED_STRINGI_CONTRACT(v, max_size); \
|
||||||
assert (serial != NULL && serial->m_interface != NULL); \
|
M_ASSERT (serial != NULL && serial->m_interface != NULL); \
|
||||||
string_t tmp; \
|
string_t tmp; \
|
||||||
/* TODO: Not optimum */ \
|
/* TODO: Not optimum */ \
|
||||||
string_init(tmp); \
|
string_init(tmp); \
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ namespace m_tuple {
|
|||||||
|
|
||||||
/* Contract of a tuple. Nothing notable */
|
/* Contract of a tuple. Nothing notable */
|
||||||
#define TUPLEI_CONTRACT(tup) do { \
|
#define TUPLEI_CONTRACT(tup) do { \
|
||||||
assert(tup != NULL); \
|
M_ASSERT(tup != NULL); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
/* Inject the oplist within the list of arguments */
|
/* Inject the oplist within the list of arguments */
|
||||||
@@ -368,7 +368,7 @@ namespace m_tuple {
|
|||||||
switch (i) { \
|
switch (i) { \
|
||||||
case 0: return 0; \
|
case 0: return 0; \
|
||||||
M_MAP2(TUPLEI_DEFINE_CMP_ORDER_FUNC , name, __VA_ARGS__) \
|
M_MAP2(TUPLEI_DEFINE_CMP_ORDER_FUNC , name, __VA_ARGS__) \
|
||||||
default: assert(0); \
|
default: M_ASSERT(0); \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
@@ -435,7 +435,7 @@ namespace m_tuple {
|
|||||||
bool append) { \
|
bool append) { \
|
||||||
bool comma = false; \
|
bool comma = false; \
|
||||||
TUPLEI_CONTRACT(el); \
|
TUPLEI_CONTRACT(el); \
|
||||||
assert (str != NULL); \
|
M_ASSERT (str != NULL); \
|
||||||
(append ? string_cat_str : string_set_str) (str, "("); \
|
(append ? string_cat_str : string_set_str) (str, "("); \
|
||||||
M_MAP(TUPLEI_DEFINE_GET_STR_FUNC , __VA_ARGS__) \
|
M_MAP(TUPLEI_DEFINE_GET_STR_FUNC , __VA_ARGS__) \
|
||||||
string_push_back (str, ')'); \
|
string_push_back (str, ')'); \
|
||||||
@@ -453,7 +453,7 @@ namespace m_tuple {
|
|||||||
M_C(name,_ct) const el) { \
|
M_C(name,_ct) const el) { \
|
||||||
bool comma = false; \
|
bool comma = false; \
|
||||||
TUPLEI_CONTRACT(el); \
|
TUPLEI_CONTRACT(el); \
|
||||||
assert (f != NULL); \
|
M_ASSERT (f != NULL); \
|
||||||
fputc('(', f); \
|
fputc('(', f); \
|
||||||
M_MAP(TUPLEI_DEFINE_OUT_STR_FUNC , __VA_ARGS__) \
|
M_MAP(TUPLEI_DEFINE_OUT_STR_FUNC , __VA_ARGS__) \
|
||||||
fputc (')', f); \
|
fputc (')', f); \
|
||||||
@@ -470,7 +470,7 @@ namespace m_tuple {
|
|||||||
static inline bool M_C(name, _in_str)(M_C(name,_ct) el, FILE *f) { \
|
static inline bool M_C(name, _in_str)(M_C(name,_ct) el, FILE *f) { \
|
||||||
bool comma = false; \
|
bool comma = false; \
|
||||||
TUPLEI_CONTRACT(el); \
|
TUPLEI_CONTRACT(el); \
|
||||||
assert (f != NULL); \
|
M_ASSERT (f != NULL); \
|
||||||
int c = fgetc(f); \
|
int c = fgetc(f); \
|
||||||
if (c != '(') return false; \
|
if (c != '(') return false; \
|
||||||
M_MAP(TUPLEI_DEFINE_IN_STR_FUNC , __VA_ARGS__) \
|
M_MAP(TUPLEI_DEFINE_IN_STR_FUNC , __VA_ARGS__) \
|
||||||
@@ -494,7 +494,7 @@ namespace m_tuple {
|
|||||||
const char str[], \
|
const char str[], \
|
||||||
const char **endptr) { \
|
const char **endptr) { \
|
||||||
TUPLEI_CONTRACT(el); \
|
TUPLEI_CONTRACT(el); \
|
||||||
assert (str != NULL); \
|
M_ASSERT (str != NULL); \
|
||||||
bool success = false; \
|
bool success = false; \
|
||||||
bool comma = false; \
|
bool comma = false; \
|
||||||
int c = *str++; \
|
int c = *str++; \
|
||||||
@@ -528,7 +528,7 @@ namespace m_tuple {
|
|||||||
M_C(name, _out_serial)(m_serial_write_t f, \
|
M_C(name, _out_serial)(m_serial_write_t f, \
|
||||||
M_C(name,_ct) const el) { \
|
M_C(name,_ct) const el) { \
|
||||||
TUPLEI_CONTRACT(el); \
|
TUPLEI_CONTRACT(el); \
|
||||||
assert (f != NULL && f->m_interface != NULL); \
|
M_ASSERT (f != NULL && f->m_interface != NULL); \
|
||||||
const int field_max = M_NARGS(__VA_ARGS__); \
|
const int field_max = M_NARGS(__VA_ARGS__); \
|
||||||
/* Define a constant static table of all fields names */ \
|
/* Define a constant static table of all fields names */ \
|
||||||
static const char *const field_name[] = \
|
static const char *const field_name[] = \
|
||||||
@@ -538,7 +538,7 @@ namespace m_tuple {
|
|||||||
m_serial_return_code_t ret; \
|
m_serial_return_code_t ret; \
|
||||||
ret = f->m_interface->write_tuple_start(local, f); \
|
ret = f->m_interface->write_tuple_start(local, f); \
|
||||||
M_MAP(TUPLEI_DEFINE_OUT_SERIAL_FUNC , __VA_ARGS__) \
|
M_MAP(TUPLEI_DEFINE_OUT_SERIAL_FUNC , __VA_ARGS__) \
|
||||||
assert( index == field_max); \
|
M_ASSERT( index == field_max); \
|
||||||
ret |= f->m_interface->write_tuple_end(local, f); \
|
ret |= f->m_interface->write_tuple_end(local, f); \
|
||||||
return ret & M_SERIAL_FAIL; \
|
return ret & M_SERIAL_FAIL; \
|
||||||
}
|
}
|
||||||
@@ -554,7 +554,7 @@ namespace m_tuple {
|
|||||||
static inline m_serial_return_code_t \
|
static inline m_serial_return_code_t \
|
||||||
M_C(name, _in_serial)(M_C(name,_ct) el, m_serial_read_t f) { \
|
M_C(name, _in_serial)(M_C(name,_ct) el, m_serial_read_t f) { \
|
||||||
TUPLEI_CONTRACT(el); \
|
TUPLEI_CONTRACT(el); \
|
||||||
assert (f != NULL && f->m_interface != NULL); \
|
M_ASSERT (f != NULL && f->m_interface != NULL); \
|
||||||
int index = -1; \
|
int index = -1; \
|
||||||
const int field_max = M_NARGS(__VA_ARGS__); \
|
const int field_max = M_NARGS(__VA_ARGS__); \
|
||||||
static const char *const field_name[] = \
|
static const char *const field_name[] = \
|
||||||
@@ -565,10 +565,10 @@ namespace m_tuple {
|
|||||||
while (ret == M_SERIAL_OK_CONTINUE) { \
|
while (ret == M_SERIAL_OK_CONTINUE) { \
|
||||||
ret = f->m_interface->read_tuple_id(local, f, field_name, field_max, &index); \
|
ret = f->m_interface->read_tuple_id(local, f, field_name, field_max, &index); \
|
||||||
if (ret == M_SERIAL_OK_CONTINUE) { \
|
if (ret == M_SERIAL_OK_CONTINUE) { \
|
||||||
assert (index >= 0 && index < field_max); \
|
M_ASSERT (index >= 0 && index < field_max); \
|
||||||
switch (1+index) { \
|
switch (1+index) { \
|
||||||
M_MAP2(TUPLEI_DEFINE_IN_SERIAL_FUNC , name, __VA_ARGS__) \
|
M_MAP2(TUPLEI_DEFINE_IN_SERIAL_FUNC , name, __VA_ARGS__) \
|
||||||
default: assert(0); \
|
default: M_ASSERT(0); \
|
||||||
} \
|
} \
|
||||||
ret = (ret == M_SERIAL_OK_DONE) ? M_SERIAL_OK_CONTINUE : M_SERIAL_FAIL; \
|
ret = (ret == M_SERIAL_OK_DONE) ? M_SERIAL_OK_CONTINUE : M_SERIAL_FAIL; \
|
||||||
} \
|
} \
|
||||||
|
|||||||
+23
-23
@@ -61,9 +61,9 @@
|
|||||||
|
|
||||||
/* Contract of a variant. */
|
/* Contract of a variant. */
|
||||||
#define VARIANTI_CONTRACT(name, my) do { \
|
#define VARIANTI_CONTRACT(name, my) do { \
|
||||||
assert(my != NULL); \
|
M_ASSERT(my != NULL); \
|
||||||
assert(my->type >= M_C(name, _EMPTY)); \
|
M_ASSERT(my->type >= M_C(name, _EMPTY)); \
|
||||||
assert(my->type <= (enum M_C(name, _enum)) M_C(name, _MAX_TYPE)); \
|
M_ASSERT(my->type <= (enum M_C(name, _enum)) M_C(name, _MAX_TYPE)); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
/* Inject the oplist within the list of arguments */
|
/* Inject the oplist within the list of arguments */
|
||||||
@@ -235,7 +235,7 @@
|
|||||||
switch (org->type) { \
|
switch (org->type) { \
|
||||||
case M_C(name, _EMPTY): break; \
|
case M_C(name, _EMPTY): break; \
|
||||||
M_MAP2(VARIANTI_DEFINE_INIT_SET_FUNC, name, __VA_ARGS__) \
|
M_MAP2(VARIANTI_DEFINE_INIT_SET_FUNC, name, __VA_ARGS__) \
|
||||||
default: assert(false); break; \
|
default: M_ASSERT(false); break; \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -261,7 +261,7 @@
|
|||||||
switch (org->type) { \
|
switch (org->type) { \
|
||||||
case M_C(name, _EMPTY): break; \
|
case M_C(name, _EMPTY): break; \
|
||||||
M_MAP2(VARIANTI_DEFINE_SET_FUNC, name, __VA_ARGS__) \
|
M_MAP2(VARIANTI_DEFINE_SET_FUNC, name, __VA_ARGS__) \
|
||||||
default: assert(false); break; \
|
default: M_ASSERT(false); break; \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
@@ -280,7 +280,7 @@
|
|||||||
switch (my->type) { \
|
switch (my->type) { \
|
||||||
case M_C(name, _EMPTY): break; \
|
case M_C(name, _EMPTY): break; \
|
||||||
M_MAP2(VARIANTI_DEFINE_CLEAR_FUNC, name, __VA_ARGS__) \
|
M_MAP2(VARIANTI_DEFINE_CLEAR_FUNC, name, __VA_ARGS__) \
|
||||||
default: assert(false); break; \
|
default: M_ASSERT(false); break; \
|
||||||
} \
|
} \
|
||||||
my->type = M_C(name, _EMPTY); \
|
my->type = M_C(name, _EMPTY); \
|
||||||
}
|
}
|
||||||
@@ -396,7 +396,7 @@
|
|||||||
switch (e1->type) { \
|
switch (e1->type) { \
|
||||||
case M_C(name, _EMPTY): break; \
|
case M_C(name, _EMPTY): break; \
|
||||||
M_MAP2(VARIANTI_DEFINE_EQUAL_FUNC , name, __VA_ARGS__) \
|
M_MAP2(VARIANTI_DEFINE_EQUAL_FUNC , name, __VA_ARGS__) \
|
||||||
default: assert(false); break; \
|
default: M_ASSERT(false); break; \
|
||||||
} \
|
} \
|
||||||
return true; \
|
return true; \
|
||||||
}
|
}
|
||||||
@@ -418,7 +418,7 @@
|
|||||||
switch (e1->type) { \
|
switch (e1->type) { \
|
||||||
case M_C(name, _EMPTY): break; \
|
case M_C(name, _EMPTY): break; \
|
||||||
M_MAP2(VARIANTI_DEFINE_HASH_FUNC , name, __VA_ARGS__) \
|
M_MAP2(VARIANTI_DEFINE_HASH_FUNC , name, __VA_ARGS__) \
|
||||||
default: assert(false); break; \
|
default: M_ASSERT(false); break; \
|
||||||
} \
|
} \
|
||||||
return M_HASH_FINAL (hash); \
|
return M_HASH_FINAL (hash); \
|
||||||
}
|
}
|
||||||
@@ -438,7 +438,7 @@
|
|||||||
switch (el->type) { \
|
switch (el->type) { \
|
||||||
case M_C(name, _EMPTY): break; \
|
case M_C(name, _EMPTY): break; \
|
||||||
M_MAP2(VARIANTI_DEFINE_INIT_MOVE_FUNC , name, __VA_ARGS__) \
|
M_MAP2(VARIANTI_DEFINE_INIT_MOVE_FUNC , name, __VA_ARGS__) \
|
||||||
default: assert(false); break; \
|
default: M_ASSERT(false); break; \
|
||||||
} \
|
} \
|
||||||
org -> type = M_C(name, _EMPTY); \
|
org -> type = M_C(name, _EMPTY); \
|
||||||
}
|
}
|
||||||
@@ -491,7 +491,7 @@
|
|||||||
switch (el1->type) { \
|
switch (el1->type) { \
|
||||||
case M_C(name, _EMPTY): break; \
|
case M_C(name, _EMPTY): break; \
|
||||||
M_MAP2(VARIANTI_DEFINE_INIT_SWAP_FUNC , name, __VA_ARGS__) \
|
M_MAP2(VARIANTI_DEFINE_INIT_SWAP_FUNC , name, __VA_ARGS__) \
|
||||||
default: assert(false); break; \
|
default: M_ASSERT(false); break; \
|
||||||
} \
|
} \
|
||||||
} else { \
|
} else { \
|
||||||
M_C(name,_ct) tmp; \
|
M_C(name,_ct) tmp; \
|
||||||
@@ -523,13 +523,13 @@
|
|||||||
M_C(name,_ct) const el, \
|
M_C(name,_ct) const el, \
|
||||||
bool append) { \
|
bool append) { \
|
||||||
VARIANTI_CONTRACT(name, el); \
|
VARIANTI_CONTRACT(name, el); \
|
||||||
assert (str != NULL); \
|
M_ASSERT (str != NULL); \
|
||||||
void (*func)(string_t, const char *); \
|
void (*func)(string_t, const char *); \
|
||||||
func = append ? string_cat_str : string_set_str; \
|
func = append ? string_cat_str : string_set_str; \
|
||||||
switch (el->type) { \
|
switch (el->type) { \
|
||||||
case M_C(name, _EMPTY): func(str, "@EMPTY@"); break; \
|
case M_C(name, _EMPTY): func(str, "@EMPTY@"); break; \
|
||||||
M_MAP2(VARIANTI_DEFINE_GET_STR_FUNC , name, __VA_ARGS__) \
|
M_MAP2(VARIANTI_DEFINE_GET_STR_FUNC , name, __VA_ARGS__) \
|
||||||
default: assert(false); break; \
|
default: M_ASSERT(false); break; \
|
||||||
} \
|
} \
|
||||||
string_push_back (str, '@'); \
|
string_push_back (str, '@'); \
|
||||||
}
|
}
|
||||||
@@ -547,7 +547,7 @@
|
|||||||
const char str[], \
|
const char str[], \
|
||||||
const char **endp) { \
|
const char **endp) { \
|
||||||
VARIANTI_CONTRACT(name, el); \
|
VARIANTI_CONTRACT(name, el); \
|
||||||
assert (str != NULL); \
|
M_ASSERT (str != NULL); \
|
||||||
bool success = false; \
|
bool success = false; \
|
||||||
char variantTypeBuf[M_MAX_IDENTIFIER_LENGTH+1]; \
|
char variantTypeBuf[M_MAX_IDENTIFIER_LENGTH+1]; \
|
||||||
int c = *str++; \
|
int c = *str++; \
|
||||||
@@ -562,7 +562,7 @@
|
|||||||
} \
|
} \
|
||||||
if (c != '@') goto exit; \
|
if (c != '@') goto exit; \
|
||||||
variantTypeBuf[i++] = 0; \
|
variantTypeBuf[i++] = 0; \
|
||||||
assert(i < sizeof(variantTypeBuf)); \
|
M_ASSERT(i < sizeof(variantTypeBuf)); \
|
||||||
/* In function of the type */ \
|
/* In function of the type */ \
|
||||||
if (strcmp(variantTypeBuf, "EMPTY") == 0) { \
|
if (strcmp(variantTypeBuf, "EMPTY") == 0) { \
|
||||||
el->type = M_C(name, _EMPTY); \
|
el->type = M_C(name, _EMPTY); \
|
||||||
@@ -589,11 +589,11 @@
|
|||||||
static inline void M_C(name, _out_str)(FILE *f, \
|
static inline void M_C(name, _out_str)(FILE *f, \
|
||||||
M_C(name,_ct) const el) { \
|
M_C(name,_ct) const el) { \
|
||||||
VARIANTI_CONTRACT(name, el); \
|
VARIANTI_CONTRACT(name, el); \
|
||||||
assert (f != NULL); \
|
M_ASSERT (f != NULL); \
|
||||||
switch (el->type) { \
|
switch (el->type) { \
|
||||||
case M_C(name, _EMPTY): fprintf(f, "@EMPTY@"); break; \
|
case M_C(name, _EMPTY): fprintf(f, "@EMPTY@"); break; \
|
||||||
M_MAP2(VARIANTI_DEFINE_OUT_STR_FUNC , name, __VA_ARGS__) \
|
M_MAP2(VARIANTI_DEFINE_OUT_STR_FUNC , name, __VA_ARGS__) \
|
||||||
default: assert(false); break; \
|
default: M_ASSERT(false); break; \
|
||||||
} \
|
} \
|
||||||
fputc ('@', f); \
|
fputc ('@', f); \
|
||||||
}
|
}
|
||||||
@@ -610,7 +610,7 @@
|
|||||||
static inline bool M_C(name, _in_str)(M_C(name,_ct) el, \
|
static inline bool M_C(name, _in_str)(M_C(name,_ct) el, \
|
||||||
FILE *f) { \
|
FILE *f) { \
|
||||||
VARIANTI_CONTRACT(name, el); \
|
VARIANTI_CONTRACT(name, el); \
|
||||||
assert (f != NULL); \
|
M_ASSERT (f != NULL); \
|
||||||
char variantTypeBuf[M_MAX_IDENTIFIER_LENGTH+1]; \
|
char variantTypeBuf[M_MAX_IDENTIFIER_LENGTH+1]; \
|
||||||
M_C(name, _clean)(el); \
|
M_C(name, _clean)(el); \
|
||||||
if (fgetc(f) != '@') return false; \
|
if (fgetc(f) != '@') return false; \
|
||||||
@@ -624,7 +624,7 @@
|
|||||||
} \
|
} \
|
||||||
if (c != '@') return false; \
|
if (c != '@') return false; \
|
||||||
variantTypeBuf[i++] = 0; \
|
variantTypeBuf[i++] = 0; \
|
||||||
assert(i < sizeof(variantTypeBuf)); \
|
M_ASSERT(i < sizeof(variantTypeBuf)); \
|
||||||
/* In function of the type */ \
|
/* In function of the type */ \
|
||||||
if (strcmp(variantTypeBuf, "EMPTY") == 0) { \
|
if (strcmp(variantTypeBuf, "EMPTY") == 0) { \
|
||||||
el->type = M_C(name, _EMPTY); \
|
el->type = M_C(name, _EMPTY); \
|
||||||
@@ -656,7 +656,7 @@
|
|||||||
const int field_max = M_NARGS(__VA_ARGS__); \
|
const int field_max = M_NARGS(__VA_ARGS__); \
|
||||||
static const char *const field_name[] = \
|
static const char *const field_name[] = \
|
||||||
{ M_REDUCE(VARIANTI_STRINGIFY_NAME, M_ID, __VA_ARGS__) }; \
|
{ M_REDUCE(VARIANTI_STRINGIFY_NAME, M_ID, __VA_ARGS__) }; \
|
||||||
assert (f != NULL && f->m_interface != NULL); \
|
M_ASSERT (f != NULL && f->m_interface != NULL); \
|
||||||
m_serial_local_t local; \
|
m_serial_local_t local; \
|
||||||
m_serial_return_code_t ret; \
|
m_serial_return_code_t ret; \
|
||||||
switch (el->type) { \
|
switch (el->type) { \
|
||||||
@@ -664,7 +664,7 @@
|
|||||||
return f->m_interface->write_variant_start(local, f, field_name, field_max, -1); \
|
return f->m_interface->write_variant_start(local, f, field_name, field_max, -1); \
|
||||||
break; \
|
break; \
|
||||||
M_MAP2(VARIANTI_DEFINE_OUT_SERIAL_FUNC , name, __VA_ARGS__) \
|
M_MAP2(VARIANTI_DEFINE_OUT_SERIAL_FUNC , name, __VA_ARGS__) \
|
||||||
default: assert(false); break; \
|
default: M_ASSERT(false); break; \
|
||||||
} \
|
} \
|
||||||
ret |= f->m_interface->write_variant_end(local, f); \
|
ret |= f->m_interface->write_variant_end(local, f); \
|
||||||
return ret & M_SERIAL_FAIL; \
|
return ret & M_SERIAL_FAIL; \
|
||||||
@@ -687,18 +687,18 @@
|
|||||||
const int field_max = M_NARGS(__VA_ARGS__); \
|
const int field_max = M_NARGS(__VA_ARGS__); \
|
||||||
static const char *const field_name[] = \
|
static const char *const field_name[] = \
|
||||||
{ M_REDUCE(VARIANTI_STRINGIFY_NAME, M_ID, __VA_ARGS__) }; \
|
{ M_REDUCE(VARIANTI_STRINGIFY_NAME, M_ID, __VA_ARGS__) }; \
|
||||||
assert (f != NULL && f->m_interface != NULL); \
|
M_ASSERT (f != NULL && f->m_interface != NULL); \
|
||||||
m_serial_local_t local; \
|
m_serial_local_t local; \
|
||||||
m_serial_return_code_t ret; \
|
m_serial_return_code_t ret; \
|
||||||
int id = -1; \
|
int id = -1; \
|
||||||
M_C(name, _clean)(el); \
|
M_C(name, _clean)(el); \
|
||||||
ret = f->m_interface->read_variant_start(local, f, field_name, field_max, &id); \
|
ret = f->m_interface->read_variant_start(local, f, field_name, field_max, &id); \
|
||||||
if (ret != M_SERIAL_OK_CONTINUE) return ret; \
|
if (ret != M_SERIAL_OK_CONTINUE) return ret; \
|
||||||
assert (id >= 0 && id < field_max); \
|
M_ASSERT (id >= 0 && id < field_max); \
|
||||||
el->type = (enum M_C(name, _enum))(id+1); \
|
el->type = (enum M_C(name, _enum))(id+1); \
|
||||||
switch (id+1) { \
|
switch (id+1) { \
|
||||||
M_MAP2(VARIANTI_DEFINE_IN_SERIAL_FUNC , name, __VA_ARGS__) \
|
M_MAP2(VARIANTI_DEFINE_IN_SERIAL_FUNC , name, __VA_ARGS__) \
|
||||||
default: assert(false); break; \
|
default: M_ASSERT(false); break; \
|
||||||
} \
|
} \
|
||||||
if (ret == M_SERIAL_OK_DONE) \
|
if (ret == M_SERIAL_OK_DONE) \
|
||||||
ret = f->m_interface->read_variant_end(local, f); \
|
ret = f->m_interface->read_variant_end(local, f); \
|
||||||
|
|||||||
+5
-5
@@ -181,7 +181,7 @@ workeri_get_cpu_count(void)
|
|||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
SYSTEM_INFO sysinfo;
|
SYSTEM_INFO sysinfo;
|
||||||
GetSystemInfo(&sysinfo);
|
GetSystemInfo(&sysinfo);
|
||||||
assert(sysinfo.dwNumberOfProcessors <= INT_MAX);
|
M_ASSERT(sysinfo.dwNumberOfProcessors <= INT_MAX);
|
||||||
return (int) sysinfo.dwNumberOfProcessors;
|
return (int) sysinfo.dwNumberOfProcessors;
|
||||||
#elif defined(M_USE_WORKER_SYSCTL)
|
#elif defined(M_USE_WORKER_SYSCTL)
|
||||||
int nm[2];
|
int nm[2];
|
||||||
@@ -209,7 +209,7 @@ workeri_get_cpu_count(void)
|
|||||||
static inline void
|
static inline void
|
||||||
workeri_exec(worker_order_ct *w)
|
workeri_exec(worker_order_ct *w)
|
||||||
{
|
{
|
||||||
assert (w!= NULL && w->block != NULL);
|
M_ASSERT (w!= NULL && w->block != NULL);
|
||||||
WORKERI_DEBUG ("Starting thread with data %p\n", w->data);
|
WORKERI_DEBUG ("Starting thread with data %p\n", w->data);
|
||||||
#if M_USE_WORKER_CLANG_BLOCK
|
#if M_USE_WORKER_CLANG_BLOCK
|
||||||
WORKERI_DEBUG ("Running %s f=%p b=%p\n", (w->func == NULL) ? "Blocks" : "Function", w->func, w->blockFunc);
|
WORKERI_DEBUG ("Running %s f=%p b=%p\n", (w->func == NULL) ? "Blocks" : "Function", w->func, w->blockFunc);
|
||||||
@@ -274,13 +274,13 @@ workeri_thread(void *arg)
|
|||||||
static inline void
|
static inline void
|
||||||
worker_init(worker_t g, int numWorker, unsigned int extraQueue, void (*resetFunc)(void), void (*clearFunc)(void))
|
worker_init(worker_t g, int numWorker, unsigned int extraQueue, void (*resetFunc)(void), void (*clearFunc)(void))
|
||||||
{
|
{
|
||||||
assert (numWorker >= -1);
|
M_ASSERT (numWorker >= -1);
|
||||||
// Auto compute number of workers if the argument is 0
|
// Auto compute number of workers if the argument is 0
|
||||||
if (numWorker <= 0)
|
if (numWorker <= 0)
|
||||||
numWorker = (1 + (numWorker == -1))*workeri_get_cpu_count()-1;
|
numWorker = (1 + (numWorker == -1))*workeri_get_cpu_count()-1;
|
||||||
WORKERI_DEBUG ("Starting queue with: %d\n", numWorker + extraQueue);
|
WORKERI_DEBUG ("Starting queue with: %d\n", numWorker + extraQueue);
|
||||||
// Initialization
|
// Initialization
|
||||||
assert(numWorker > 0);
|
M_ASSERT(numWorker > 0);
|
||||||
size_t numWorker_st = (size_t) numWorker;
|
size_t numWorker_st = (size_t) numWorker;
|
||||||
g->worker = M_MEMORY_REALLOC(worker_thread_ct, NULL, numWorker_st);
|
g->worker = M_MEMORY_REALLOC(worker_thread_ct, NULL, numWorker_st);
|
||||||
if (g->worker == NULL) {
|
if (g->worker == NULL) {
|
||||||
@@ -312,7 +312,7 @@ worker_init(worker_t g, int numWorker, unsigned int extraQueue, void (*resetFunc
|
|||||||
static inline void
|
static inline void
|
||||||
worker_clear(worker_t g)
|
worker_clear(worker_t g)
|
||||||
{
|
{
|
||||||
assert (worker_queue_empty_p (g->queue_g));
|
M_ASSERT (worker_queue_empty_p (g->queue_g));
|
||||||
// Push the terminate order on the queue
|
// Push the terminate order on the queue
|
||||||
for(unsigned int i = 0; i < g->numWorker_g; i++) {
|
for(unsigned int i = 0; i < g->numWorker_g; i++) {
|
||||||
worker_order_ct w = WORKERI_EMPTY_ORDER;
|
worker_order_ct w = WORKERI_EMPTY_ORDER;
|
||||||
|
|||||||
Reference in new issue
Block a user