diff --git a/README.md b/README.md index 590fe57b..38d2e9f2 100644 --- a/README.md +++ b/README.md @@ -5785,6 +5785,18 @@ It is currently 52 (even if some local macros may have increased this limit). Return a symbol corresponding to the concatenation of the input arguments. +##### M\_F(base, suffix) + +Return a function name corresponding to the concatenation of the input arguments. +In developer mode, it can be overrided before inclusion of any header to support user customization of suffix. +To do this you need to define M\_F as M\_OVERRIDE\_F, then define as many suffix macros as needed. As suffix macro shall be named M_OVERRIDE_ ## suffix () and each generated suffix shall start with a comma (preliminary interface). + +Example: + + #define M_F(a,b) M_OVERRIDE_F(a,b) + #define M_OVERRIDE__clear() , _cleanup , + #include "m-core.h" + ##### M\_INC(number) Increment the number given as argument and return diff --git a/m-algo.h b/m-algo.h index 83503689..96a08f67 100644 --- a/m-algo.h +++ b/m-algo.h @@ -129,16 +129,16 @@ , /* NO EQUAL */) \ \ M_ALG0_DEF_FIND_IF(name, container_t, cont_oplist, type_t, type_oplist, it_t, \ - if, M_C(name,_test_cb_ct), M_C(name,_eq_cb_ct), M_APPLY, M_APPLY) \ + if, M_F(name,_test_cb_ct), M_F(name,_eq_cb_ct), M_APPLY, M_APPLY) \ M_IF_FUNCOBJ(M_ALG0_DEF_FIND_IF(name, container_t, cont_oplist, type_t, type_oplist, it_t, \ - fo, M_C(name,_test_obj_t), M_C(name,_eq_obj_t), M_C(name, _test_obj_call), M_C(name, _eq_obj_call))) \ + fo, M_F(name,_test_obj_t), M_F(name,_eq_obj_t), M_F(name, _test_obj_call), M_F(name, _eq_obj_call))) \ \ M_ALG0_DEF_MAP(name, container_t, cont_oplist, type_t, type_oplist, it_t) \ \ M_ALG0_DEF_ALL_OF(name, container_t, cont_oplist, type_t, type_oplist, it_t, \ - _, M_C(name,_test_cb_ct), M_APPLY) \ + _, M_F(name,_test_cb_ct), M_APPLY) \ M_IF_FUNCOBJ(M_ALG0_DEF_ALL_OF(name, container_t, cont_oplist, type_t, type_oplist, it_t, \ - _fo_, M_C(name,_test_obj_t), M_C(name,_test_obj_call)) ) \ + _fo_, M_F(name,_test_obj_t), M_F(name,_test_obj_call)) ) \ \ /* If there is a IT_REF method, we consider the container as modifiable through iterator */ \ M_IF_METHOD(IT_REF, cont_oplist)( \ @@ -167,22 +167,22 @@ * Types remain internal */ #define M_ALG0_DEF_CALLBACK(name, container_t, cont_oplist, type_t, type_oplist, it_t) \ \ - typedef bool (*M_C(name, _test_cb_ct))(type_t const); \ - typedef bool (*M_C(name, _eq_cb_ct))(type_t const, type_t const); \ - typedef int (*M_C(name, _cmp_cb_ct))(type_t const, type_t const); \ - typedef void (*M_C(name, _transform_cb_ct))(type_t *, type_t const); \ - typedef void (*M_C(name, _apply_cb_ct))(type_t); \ + typedef bool (*M_F(name, _test_cb_ct))(type_t const); \ + typedef bool (*M_F(name, _eq_cb_ct))(type_t const, type_t const); \ + typedef int (*M_F(name, _cmp_cb_ct))(type_t const, type_t const); \ + typedef void (*M_F(name, _transform_cb_ct))(type_t *, type_t const); \ + typedef void (*M_F(name, _apply_cb_ct))(type_t); \ /* Define the function objects associated to the algorithms. * Created Function objects are part of the public interface */ #define M_ALG0_DEF_FUNCOBJ(name, container_t, cont_oplist, type_t, type_oplist, it_t) \ \ - FUNC_OBJ_ITF_DEF(M_C(name, _test_obj), bool, type_t const) \ - FUNC_OBJ_ITF_DEF(M_C(name, _eq_obj), bool, type_t const, type_t const ) \ - FUNC_OBJ_ITF_DEF(M_C(name, _cmp_obj), int, type_t const, type_t const ) \ - FUNC_OBJ_ITF_DEF(M_C(name, _transform_obj), void, type_t *, type_t const ) \ - FUNC_OBJ_ITF_DEF(M_C(name, _apply_obj), void, type_t * ) \ + FUNC_OBJ_ITF_DEF(M_F(name, _test_obj), bool, type_t const) \ + FUNC_OBJ_ITF_DEF(M_F(name, _eq_obj), bool, type_t const, type_t const ) \ + FUNC_OBJ_ITF_DEF(M_F(name, _cmp_obj), int, type_t const, type_t const ) \ + FUNC_OBJ_ITF_DEF(M_F(name, _transform_obj), void, type_t *, type_t const ) \ + FUNC_OBJ_ITF_DEF(M_F(name, _apply_obj), void, type_t * ) \ /* Define the sort functions with the CMP operator using the order selected */ @@ -203,9 +203,9 @@ // Call the created function object #define M_ALG0_SORT_CALL_OBJ_P4(name, sort_name, ref1, ref2) \ - M_C(name, _cmp_obj_call)(funcobj, *ref1, *ref2) + M_F(name, _cmp_obj_call)(funcobj, *ref1, *ref2) // Adding a parameter named 'funcobj' to the algorithm functions -#define M_ALG0_SORT_PARAM_OBJ_P4(name) M_DEFERRED_COMMA M_C(name, _cmp_obj_t) funcobj +#define M_ALG0_SORT_PARAM_OBJ_P4(name) M_DEFERRED_COMMA M_F(name, _cmp_obj_t) funcobj #define M_ALG0_SORT_ARG_OBJ_P4 M_DEFERRED_COMMA funcobj @@ -253,7 +253,7 @@ /* - a selection sort */ \ M_IF(M_AND(M_TEST_METHOD_P(SORT, cont_oplist), M_EMPTY_P(cmp_arg)))( \ /******** OPTIMIZED SORT FOR CONTAINER *********/ \ - static inline void M_C(name,sort_name)(container_t l) \ + static inline void M_F(name,sort_name)(container_t l) \ { \ M_CALL_SORT(cont_oplist, l, M_C3(name, sort_name,_cmp)); \ } \ @@ -321,7 +321,7 @@ \ /* Sort the container 'l' */ \ static inline void \ - M_C(name,sort_name)(container_t l cmp_param(name)) \ + M_F(name,sort_name)(container_t l cmp_param(name)) \ { \ container_t l1; \ container_t l2; \ @@ -353,8 +353,8 @@ M_CALL_INIT(cont_oplist, l1); \ M_CALL_INIT(cont_oplist, l2); \ M_C3(name,sort_name,_split)(l1, l2, l); \ - M_C(name,sort_name)(l1 cmp_arg); \ - M_C(name,sort_name)(l2 cmp_arg); \ + M_F(name,sort_name)(l1 cmp_arg); \ + M_F(name,sort_name)(l2 cmp_arg); \ M_C3(name,sort_name,_merge)(l, l1, l2 cmp_arg); \ /* l1 & l2 shall be empty now */ \ M_CALL_CLEAR(cont_oplist, l2); \ @@ -363,7 +363,7 @@ , \ M_IF_METHOD(IT_PREVIOUS, cont_oplist)( \ /******** GENERIC INSERTION SORT *********/ \ - static inline void M_C(name,sort_name)(container_t l cmp_param(name)) \ + static inline void M_F(name,sort_name)(container_t l cmp_param(name)) \ { \ it_t it1; \ it_t it2; \ @@ -400,7 +400,7 @@ \ , \ /********** GENERIC SELECTION SORT ************/ \ - static inline void M_C(name,sort_name)(container_t l cmp_param(name)) \ + static inline void M_F(name,sort_name)(container_t l cmp_param(name)) \ { \ it_t it1; \ it_t it2; \ @@ -518,7 +518,7 @@ /* It supposes that the container is not sorted */ \ /* Find the next occurrence from it (included) of data */ \ static inline void \ - M_C(name, _find_again) (it_t it, type_t const data) \ + M_F(name, _find_again) (it_t it, type_t const data) \ { \ for ( /*nothing*/ ; !M_CALL_IT_END_P(cont_oplist, it) ; \ M_CALL_IT_NEXT(cont_oplist, it)) { \ @@ -529,18 +529,18 @@ \ /* Find the first occurrence of data */ \ static inline void \ - M_C(name, _find) (it_t it, container_t const l, type_t const data) \ + M_F(name, _find) (it_t it, container_t const l, type_t const data) \ { \ M_CALL_IT_FIRST(cont_oplist, it, l); \ - M_C(name, _find_again)(it, data); \ + M_F(name, _find_again)(it, data); \ } \ \ /* Test if data is within the container */ \ static inline bool \ - M_C(name, _contain_p) (container_t const l, type_t const data) \ + M_F(name, _contain_p) (container_t const l, type_t const data) \ { \ it_t it; \ - M_C(name,_find)(it, l, data); \ + M_F(name,_find)(it, l, data); \ return !M_CALL_IT_END_P(cont_oplist, it); \ } \ \ @@ -550,7 +550,7 @@ M_IF_METHOD2(PREVIOUS, IT_LAST, cont_oplist) \ ( \ static inline void \ - M_C(name, _find_last) (it_t it, container_t const l, type_t const data) \ + M_F(name, _find_last) (it_t it, container_t const l, type_t const data) \ { \ for (M_CALL_IT_LAST(cont_oplist, it, l); \ !M_CALL_IT_END_P(cont_oplist, it) ; \ @@ -563,7 +563,7 @@ , \ /* Otherwise search forward, but don't stop on the first occurrence */ \ static inline void \ - M_C(name, _find_last) (it_t it, container_t const l, type_t const data) \ + M_F(name, _find_last) (it_t it, container_t const l, type_t const data) \ { \ M_CALL_IT_END(cont_oplist, it, l); \ it_t it2; \ @@ -579,7 +579,7 @@ \ /* Count the number of occurrence of data in the container */ \ static inline size_t \ - M_C(name, _count) (container_t const l, type_t const data) \ + M_F(name, _count) (container_t const l, type_t const data) \ { \ it_t it; \ size_t count = 0; \ @@ -595,7 +595,7 @@ \ /* Find the next mismatch between the containers */ \ static inline void \ - M_C(name, _mismatch_again) (it_t it1, it_t it2) \ + M_F(name, _mismatch_again) (it_t it1, it_t it2) \ { \ for (/* nothing */ ; !M_CALL_IT_END_P(cont_oplist, it1) && \ !M_CALL_IT_END_P(cont_oplist, it2); \ @@ -609,11 +609,11 @@ \ /* Find the first mismatch between the containers */ \ static inline void \ - M_C(name, _mismatch) (it_t it1, it_t it2, container_t const l1, container_t const l2 ) \ + M_F(name, _mismatch) (it_t it1, it_t it2, container_t const l1, container_t const l2 ) \ { \ M_CALL_IT_FIRST(cont_oplist, it1, l1); \ M_CALL_IT_FIRST(cont_oplist, it2, l2); \ - M_C(name, _mismatch_again)(it1, it2); \ + M_F(name, _mismatch_again)(it1, it2); \ } \ @@ -689,7 +689,7 @@ \ /* Fill all the container with value (overwritten) */ \ static inline void \ - M_C(name, _fill) (container_t l, type_t const value) \ + M_F(name, _fill) (container_t l, type_t const value) \ { \ for M_EACH(item, l, cont_oplist) { \ M_CALL_SET(type_oplist, *item, value); \ @@ -699,7 +699,7 @@ /* Fill the container with exactly 'n' occurrence of 'value' */ \ M_IF_METHOD(PUSH, cont_oplist)( \ static inline void \ - M_C(name, _fill_n) (container_t l, size_t n, type_t const value) \ + M_F(name, _fill_n) (container_t l, size_t n, type_t const value) \ { \ M_CALL_RESET(cont_oplist, l); \ for(size_t i = 0; i < n; i++) { \ @@ -711,7 +711,7 @@ /* Fill the container with FOR('value'; 'value'+'inc') */ \ M_IF_METHOD(ADD, type_oplist)( \ static inline void \ - M_C(name, _fill_a) (container_t l, type_t const value, type_t const inc) \ + M_F(name, _fill_a) (container_t l, type_t const value, type_t const inc) \ { \ type_t tmp; \ M_CALL_INIT_SET(type_oplist, tmp, value); \ @@ -725,7 +725,7 @@ /* Fill the container with n occurences of FOR('value'; 'value'+'inc') */ \ M_IF_METHOD(PUSH, cont_oplist)( \ static inline void \ - M_C(name, _fill_an) (container_t l, size_t n, type_t const value, type_t const inc) \ + M_F(name, _fill_an) (container_t l, size_t n, type_t const value, type_t const inc) \ { \ type_t tmp; \ M_CALL_INIT_SET(type_oplist, tmp, value); \ @@ -745,7 +745,7 @@ \ /* Apply func for all elements of the container */ \ static inline void \ - M_C(name, _for_each) (container_t l, M_C(name, _apply_cb_ct) func) \ + M_F(name, _for_each) (container_t l, M_F(name, _apply_cb_ct) func) \ { \ for M_EACH(item, l, cont_oplist) { \ func(*item); \ @@ -757,9 +757,9 @@ \ /* Apply func for all elements of the container src and push the result in dst */ \ static inline void \ - M_C(name, _transform) (container_t dst, \ + M_F(name, _transform) (container_t dst, \ container_t src, \ - M_C(name, _transform_cb_ct) func) \ + M_F(name, _transform_cb_ct) func) \ { \ M_ASSERT(dst != src); \ M_CALL_RESET(cont_oplist, dst); \ @@ -776,8 +776,8 @@ /* Reduce all elements of the container in dst in function of func */ \ M_IF_METHOD(SET, type_oplist)( \ static inline void \ - M_C(name, _reduce) (type_t *dest, container_t const l, \ - M_C(name, _transform_cb_ct) func) \ + M_F(name, _reduce) (type_t *dest, container_t const l, \ + M_F(name, _transform_cb_ct) func) \ { \ bool initDone = false; \ for M_EACH(item, l, cont_oplist) { \ @@ -794,10 +794,10 @@ /* Reduce all transformed elements of the container in dst in function of func */ \ M_IF_METHOD(INIT, type_oplist)( \ static inline \ - void M_C(name, _map_reduce) (type_t *dest, \ + void M_F(name, _map_reduce) (type_t *dest, \ const container_t l, \ - M_C(name, _transform_cb_ct) redFunc, \ - M_C(name, _transform_cb_ct) mapFunc) \ + M_F(name, _transform_cb_ct) redFunc, \ + M_F(name, _transform_cb_ct) mapFunc) \ { \ bool initDone = false; \ type_t tmp; \ @@ -857,7 +857,7 @@ #define M_ALG0_DEF_MINMAX(name, container_t, cont_oplist, type_t, type_oplist, it_t) \ \ static inline type_t * \ - M_C(name, _min) (const container_t l) \ + M_F(name, _min) (const container_t l) \ { \ type_t *min = NULL; \ for M_EACH(cref, l, cont_oplist) { \ @@ -870,7 +870,7 @@ } \ \ static inline type_t * \ - M_C(name, _max) (const container_t l) \ + M_F(name, _max) (const container_t l) \ { \ type_t *max = NULL; \ for M_EACH(cref, l, cont_oplist) { \ @@ -883,7 +883,7 @@ } \ \ static inline void \ - M_C(name, _minmax) (type_t **min_p, type_t **max_p, \ + M_F(name, _minmax) (type_t **min_p, type_t **max_p, \ const container_t l) \ { \ type_t *min = NULL; \ @@ -906,11 +906,11 @@ #define M_ALG0_DEF_REMOVE(name, container_t, cont_oplist, type_t, type_oplist, it_t) \ \ static inline void \ - M_C(name, _uniq)(container_t l) \ + M_F(name, _uniq)(container_t l) \ { \ it_t it1; \ it_t it2; \ - M_ASSERT(M_C(name, _sort_p)(l)); \ + M_ASSERT(M_F(name, _sort_p)(l)); \ M_CALL_IT_FIRST(cont_oplist, it1, l); \ M_CALL_IT_SET(cont_oplist, it2, it1); \ M_CALL_IT_NEXT(cont_oplist, it2); \ @@ -928,7 +928,7 @@ } \ \ static inline void \ - M_C(name, _remove_val)(container_t l, type_t const val) \ + M_F(name, _remove_val)(container_t l, type_t const val) \ { \ it_t it1; \ M_CALL_IT_FIRST(cont_oplist, it1, l); \ @@ -943,7 +943,7 @@ } \ \ static inline void \ - M_C(name, _remove_if)(container_t l, M_C(name, _test_cb_ct) func) \ + M_F(name, _remove_if)(container_t l, M_F(name, _test_cb_ct) func) \ { \ it_t it1; \ M_CALL_IT_FIRST(cont_oplist, it1, l); \ @@ -961,7 +961,7 @@ #define M_ALG0_DEF_VECTOR(name, container_t, cont_oplist, type_t, type_oplist, it_t) \ \ M_IF_METHOD(ADD, type_oplist)( \ - static inline void M_C(name, _add) (container_t dst, const container_t src) \ + static inline void M_F(name, _add) (container_t dst, const container_t src) \ { \ it_t itSrc; \ it_t itDst; \ @@ -979,7 +979,7 @@ , /* NO_ADD METHOD */ ) \ \ M_IF_METHOD(SUB, type_oplist)( \ - static inline void M_C(name, _sub) (container_t dst, const container_t src) \ + static inline void M_F(name, _sub) (container_t dst, const container_t src) \ { \ it_t itSrc; \ it_t itDst; \ @@ -997,7 +997,7 @@ , /* NO_SUB METHOD */ ) \ \ M_IF_METHOD(MUL, type_oplist)( \ - static inline void M_C(name, _mul) (container_t dst, const container_t src) \ + static inline void M_F(name, _mul) (container_t dst, const container_t src) \ { \ it_t itSrc; \ it_t itDst; \ @@ -1015,7 +1015,7 @@ , /* NO_MUL METHOD */ ) \ \ M_IF_METHOD(DIV, type_oplist)( \ - static inline void M_C(name, _div) (container_t dst, const container_t src) \ + static inline void M_F(name, _div) (container_t dst, const container_t src) \ { \ it_t itSrc; \ it_t itDst; \ diff --git a/m-array.h b/m-array.h index dc0cf3aa..56b6a75c 100644 --- a/m-array.h +++ b/m-array.h @@ -30,7 +30,7 @@ /* Define a dynamic array of the given type and its associated functions. USAGE: ARRAY_DEF(name, type [, oplist_of_the_type]) */ #define M_ARRAY_DEF(name, ...) \ - M_ARRAY_DEF_AS(name, M_C(name,_t), M_C(name,_it_t), __VA_ARGS__) + M_ARRAY_DEF_AS(name, M_F(name,_t), M_F(name,_it_t), __VA_ARGS__) /* Define a dynamic array of the given type and its associated functions @@ -81,56 +81,56 @@ /* FIXME: Do we want to export some methods as they are slow and are not fit to be used for building other methods (like _it_remove)? */ #define M_ARRA4_OPLIST_P3(name, oplist) \ - (INIT(M_C(name, _init)) \ - ,M_IF_METHOD2(INIT_SET,SET, oplist)(INIT_SET(M_C(name, _init_set)),) \ + (INIT(M_F(name, _init)) \ + ,M_IF_METHOD2(INIT_SET,SET, oplist)(INIT_SET(M_F(name, _init_set)),) \ ,M_IF_METHOD(INIT_SET, oplist)(INIT_WITH(API_1(M_INIT_WITH_VAI)),) \ - ,M_IF_METHOD2(INIT_SET,SET, oplist)(SET(M_C(name, _set)), ) \ - ,CLEAR(M_C(name, _clear)) \ - ,INIT_MOVE(M_C(name, _init_move)) \ - ,MOVE(M_C(name, _move)) \ - ,SWAP(M_C(name, _swap)) \ - ,TYPE(M_C(name,_ct)) \ + ,M_IF_METHOD2(INIT_SET,SET, oplist)(SET(M_F(name, _set)), ) \ + ,CLEAR(M_F(name, _clear)) \ + ,INIT_MOVE(M_F(name, _init_move)) \ + ,MOVE(M_F(name, _move)) \ + ,SWAP(M_F(name, _swap)) \ + ,TYPE(M_F(name,_ct)) \ ,NAME(name) \ - ,SUBTYPE(M_C(name, _subtype_ct)) \ - ,EMPTY_P(M_C(name,_empty_p)) \ - ,IT_TYPE(M_C(name,_it_ct)), \ - ,IT_FIRST(M_C(name,_it)) \ - ,IT_LAST(M_C(name,_it_last)) \ - ,IT_END(M_C(name,_it_end)) \ - ,IT_SET(M_C(name,_it_set)) \ - ,IT_END_P(M_C(name,_end_p)) \ - ,IT_LAST_P(M_C(name,_last_p)) \ - ,IT_EQUAL_P(M_C(name,_it_equal_p)) \ - ,IT_NEXT(M_C(name,_next)) \ - ,IT_PREVIOUS(M_C(name,_previous)) \ - ,IT_REF(M_C(name,_ref)) \ - ,IT_CREF(M_C(name,_cref)) \ - ,M_IF_METHOD(INIT_SET, oplist)(IT_INSERT(M_C(name,_insert)) ,) \ - ,M_IF_AT_LEAST_METHOD(SET,INIT_MOVE,oplist)(IT_REMOVE(M_C(name,_remove)),) \ - ,RESET(M_C(name,_reset)) \ + ,SUBTYPE(M_F(name, _subtype_ct)) \ + ,EMPTY_P(M_F(name,_empty_p)) \ + ,IT_TYPE(M_F(name,_it_ct)), \ + ,IT_FIRST(M_F(name,_it)) \ + ,IT_LAST(M_F(name,_it_last)) \ + ,IT_END(M_F(name,_it_end)) \ + ,IT_SET(M_F(name,_it_set)) \ + ,IT_END_P(M_F(name,_end_p)) \ + ,IT_LAST_P(M_F(name,_last_p)) \ + ,IT_EQUAL_P(M_F(name,_it_equal_p)) \ + ,IT_NEXT(M_F(name,_next)) \ + ,IT_PREVIOUS(M_F(name,_previous)) \ + ,IT_REF(M_F(name,_ref)) \ + ,IT_CREF(M_F(name,_cref)) \ + ,M_IF_METHOD(INIT_SET, oplist)(IT_INSERT(M_F(name,_insert)) ,) \ + ,M_IF_AT_LEAST_METHOD(SET,INIT_MOVE,oplist)(IT_REMOVE(M_F(name,_remove)),) \ + ,RESET(M_F(name,_reset)) \ ,KEY_TYPE(size_t) \ - ,VALUE_TYPE(M_C(name, _subtype_ct)) \ + ,VALUE_TYPE(M_F(name, _subtype_ct)) \ ,KEY_OPLIST(M_BASIC_OPLIST) \ ,VALUE_OPLIST(oplist) \ - ,M_IF_METHOD(SET, oplist)(SET_KEY(M_C(name, _set_at)) ,) \ - ,GET_KEY(M_C(name, _get)) \ - ,M_IF_METHOD(INIT, oplist)(SAFE_GET_KEY(M_C(name, _safe_get)) ,) \ - ,M_IF_AT_LEAST_METHOD(SET,INIT_MOVE,oplist)(ERASE_KEY(M_C(name, _erase)),) \ - ,GET_SIZE(M_C(name, _size)) \ - ,M_IF_METHOD(INIT_SET, oplist)(PUSH(M_C(name,_push_back)) ,) \ - ,M_IF_AT_LEAST_METHOD(SET,INIT_MOVE,oplist)(POP(M_C(name,_pop_back)) ,) \ - ,M_IF_AT_LEAST_METHOD(INIT_SET,INIT_MOVE,oplist)(PUSH_MOVE(M_C(name,_push_move)) ,) \ - ,M_IF_AT_LEAST_METHOD(INIT_SET,INIT_MOVE,oplist)(POP_MOVE(M_C(name,_pop_move)) ,) \ + ,M_IF_METHOD(SET, oplist)(SET_KEY(M_F(name, _set_at)) ,) \ + ,GET_KEY(M_F(name, _get)) \ + ,M_IF_METHOD(INIT, oplist)(SAFE_GET_KEY(M_F(name, _safe_get)) ,) \ + ,M_IF_AT_LEAST_METHOD(SET,INIT_MOVE,oplist)(ERASE_KEY(M_F(name, _erase)),) \ + ,GET_SIZE(M_F(name, _size)) \ + ,M_IF_METHOD(INIT_SET, oplist)(PUSH(M_F(name,_push_back)) ,) \ + ,M_IF_AT_LEAST_METHOD(SET,INIT_MOVE,oplist)(POP(M_F(name,_pop_back)) ,) \ + ,M_IF_AT_LEAST_METHOD(INIT_SET,INIT_MOVE,oplist)(PUSH_MOVE(M_F(name,_push_move)) ,) \ + ,M_IF_AT_LEAST_METHOD(INIT_SET,INIT_MOVE,oplist)(POP_MOVE(M_F(name,_pop_move)) ,) \ ,OPLIST(oplist) \ - ,M_IF_METHOD(CMP, oplist)(SORT(M_C(name, _special_sort)),) \ - ,M_IF_METHOD(GET_STR, oplist)(GET_STR(M_C(name, _get_str)),) \ - ,M_IF_METHOD(PARSE_STR, oplist)(PARSE_STR(M_C(name, _parse_str)),) \ - ,M_IF_METHOD(OUT_STR, oplist)(OUT_STR(M_C(name, _out_str)),) \ - ,M_IF_METHOD(IN_STR, oplist)(IN_STR(M_C(name, _in_str)),) \ - ,M_IF_METHOD(OUT_SERIAL, oplist)(OUT_SERIAL(M_C(name, _out_serial)),) \ - ,M_IF_METHOD(IN_SERIAL, oplist)(IN_SERIAL(M_C(name, _in_serial)),) \ - ,M_IF_METHOD(EQUAL, oplist)(EQUAL(M_C(name, _equal_p)),) \ - ,M_IF_METHOD(HASH, oplist)(HASH(M_C(name, _hash)),) \ + ,M_IF_METHOD(CMP, oplist)(SORT(M_F(name, _special_sort)),) \ + ,M_IF_METHOD(GET_STR, oplist)(GET_STR(M_F(name, _get_str)),) \ + ,M_IF_METHOD(PARSE_STR, oplist)(PARSE_STR(M_F(name, _parse_str)),) \ + ,M_IF_METHOD(OUT_STR, oplist)(OUT_STR(M_F(name, _out_str)),) \ + ,M_IF_METHOD(IN_STR, oplist)(IN_STR(M_F(name, _in_str)),) \ + ,M_IF_METHOD(OUT_SERIAL, oplist)(OUT_SERIAL(M_F(name, _out_serial)),) \ + ,M_IF_METHOD(IN_SERIAL, oplist)(IN_SERIAL(M_F(name, _in_serial)),) \ + ,M_IF_METHOD(EQUAL, oplist)(EQUAL(M_F(name, _equal_p)),) \ + ,M_IF_METHOD(HASH, oplist)(HASH(M_F(name, _hash)),) \ ,M_IF_METHOD(NEW, oplist)(NEW(M_GET_NEW oplist),) \ ,M_IF_METHOD(REALLOC, oplist)(REALLOC(M_GET_REALLOC oplist),) \ ,M_IF_METHOD(DEL, oplist)(DEL(M_GET_DEL oplist),) \ @@ -176,36 +176,36 @@ M_CHECK_COMPATIBLE_OPLIST(name, 1, type, oplist) \ M_ARRA4_DEF_CORE(name, type, oplist, array_t, it_t) \ M_ARRA4_DEF_IO(name, type, oplist, array_t, it_t) \ - M_EMPLACE_QUEUE_DEF(name, array_t, M_C(name, _emplace_back), oplist, M_ARRA4_EMPLACE_DEF) + M_EMPLACE_QUEUE_DEF(name, array_t, M_F(name, _emplace_back), oplist, M_ARRA4_EMPLACE_DEF) /* Define the types */ #define M_ARRA4_DEF_TYPE(name, type, oplist, array_t, it_t) \ \ /* Define a dynamic array */ \ - typedef struct M_C(name, _s) { \ + typedef struct M_F(name, _s) { \ size_t size; /* Number of elements in the array */ \ size_t alloc; /* Allocated size for the array base */ \ type *ptr; /* Pointer to the array base */ \ } array_t[1]; \ \ /* Define an iterator over an array */ \ - typedef struct M_C(name, _it_s) { \ + typedef struct M_F(name, _it_s) { \ size_t index; /* Index of the element */ \ - const struct M_C(name, _s) *array; /* Reference of the array */ \ + const struct M_F(name, _s) *array; /* Reference of the array */ \ } it_t[1]; \ \ /* Definition of the synonyms of the type */ \ - typedef struct M_C(name, _s) *M_C(name, _ptr); \ - typedef const struct M_C(name, _s) *M_C(name, _srcptr); \ - typedef array_t M_C(name, _ct); \ - typedef it_t M_C(name, _it_ct); \ - typedef type M_C(name, _subtype_ct); \ + typedef struct M_F(name, _s) *M_F(name, _ptr); \ + typedef const struct M_F(name, _s) *M_F(name, _srcptr); \ + typedef array_t M_F(name, _ct); \ + typedef it_t M_F(name, _it_ct); \ + typedef type M_F(name, _subtype_ct); \ /* Define the core functions */ #define M_ARRA4_DEF_CORE(name, type, oplist, array_t, it_t) \ \ static inline void \ - M_C(name, _init)(array_t v) \ + M_F(name, _init)(array_t v) \ { \ M_ASSERT (v != NULL); \ /* Initially, the array is empty with nothing allocated */ \ @@ -216,7 +216,7 @@ } \ \ static inline void \ - M_C(name, _reset)(array_t v) \ + M_F(name, _reset)(array_t v) \ { \ M_ARRA4_CONTRACT(v); \ for(size_t i = 0; i < v->size; i++) \ @@ -226,10 +226,10 @@ } \ \ static inline void \ - M_C(name, _clear)(array_t v) \ + M_F(name, _clear)(array_t v) \ { \ M_ARRA4_CONTRACT(v); \ - M_C(name, _reset)(v); \ + M_F(name, _reset)(v); \ M_CALL_FREE(oplist, v->ptr); \ /* This is so reusing the object implies an assertion failure */ \ v->alloc = 1; \ @@ -238,7 +238,7 @@ \ M_IF_METHOD2(INIT_SET, SET, oplist)( \ static inline void \ - M_C(name, _set)(array_t d, const array_t s) \ + M_F(name, _set)(array_t d, const array_t s) \ { \ M_ARRA4_CONTRACT(d); \ M_ARRA4_CONTRACT(s); \ @@ -266,16 +266,16 @@ } \ \ static inline void \ - M_C(name, _init_set)(array_t d, const array_t s) \ + M_F(name, _init_set)(array_t d, const array_t s) \ { \ M_ASSERT (d != s); \ - M_C(name, _init)(d); \ - M_C(name, _set)(d, s); \ + M_F(name, _init)(d); \ + M_F(name, _set)(d, s); \ } \ , /* No SET & INIT_SET */) \ \ static inline void \ - M_C(name, _init_move)(array_t d, array_t s) \ + M_F(name, _init_move)(array_t d, array_t s) \ { \ M_ASSERT (d != s); \ M_ARRA4_CONTRACT(s); \ @@ -289,16 +289,16 @@ } \ \ static inline void \ - M_C(name, _move)(array_t d, array_t s) \ + M_F(name, _move)(array_t d, array_t s) \ { \ M_ASSERT (d != s); \ - M_C(name, _clear)(d); \ - M_C(name, _init_move)(d, s); \ + M_F(name, _clear)(d); \ + M_F(name, _init_move)(d, s); \ } \ \ M_IF_METHOD(SET, oplist)( \ static inline void \ - M_C(name, _set_at)(array_t v, size_t i, type const x) \ + M_F(name, _set_at)(array_t v, size_t i, type const x) \ { \ M_ARRA4_CONTRACT(v); \ M_ASSERT(v->size > 0 && v->ptr != NULL); \ @@ -308,7 +308,7 @@ , /* No SET */) \ \ static inline type * \ - M_C(name, _back)(array_t v) \ + M_F(name, _back)(array_t v) \ { \ M_ARRA4_CONTRACT(v); \ M_ASSERT(v->ptr != NULL); \ @@ -317,7 +317,7 @@ } \ \ static inline type * \ - M_C(name, _push_raw)(array_t v) \ + M_F(name, _push_raw)(array_t v) \ { \ M_ARRA4_CONTRACT(v); \ if (M_UNLIKELY (v->size >= v->alloc)) { \ @@ -346,9 +346,9 @@ \ M_IF_METHOD(INIT_SET, oplist)( \ static inline void \ - M_C(name, _push_back)(array_t v, type const x) \ + M_F(name, _push_back)(array_t v, type const x) \ { \ - type *data = M_C(name, _push_raw)(v); \ + type *data = M_F(name, _push_raw)(v); \ if (M_UNLIKELY (data == NULL) ) \ return; \ M_CALL_INIT_SET(oplist, *data, x); \ @@ -357,9 +357,9 @@ \ M_IF_METHOD(INIT, oplist)( \ static inline type * \ - M_C(name, _push_new)(array_t v) \ + M_F(name, _push_new)(array_t v) \ { \ - type *data = M_C(name, _push_raw)(v); \ + type *data = M_F(name, _push_raw)(v); \ if (M_UNLIKELY (data == NULL) ) \ return NULL; \ M_CALL_INIT(oplist, *data); \ @@ -369,10 +369,10 @@ \ M_IF_AT_LEAST_METHOD(INIT_SET, INIT_MOVE, oplist)( \ static inline void \ - M_C(name, _push_move)(array_t v, type *x) \ + M_F(name, _push_move)(array_t v, type *x) \ { \ M_ASSERT (x != NULL); \ - type *data = M_C(name, _push_raw)(v); \ + type *data = M_F(name, _push_raw)(v); \ if (M_UNLIKELY (data == NULL) ) \ return; \ M_DO_INIT_MOVE (oplist, *data, *x); \ @@ -381,7 +381,7 @@ \ M_IF_METHOD(INIT_SET, oplist)( \ static inline void \ - M_C(name, _push_at)(array_t v, size_t key, type const x) \ + M_F(name, _push_at)(array_t v, size_t key, type const x) \ { \ M_ARRA4_CONTRACT(v); \ M_ASSERT_INDEX(key, v->size+1); \ @@ -411,7 +411,7 @@ \ M_IF_METHOD(INIT, oplist)( \ static inline void \ - M_C(name, _resize)(array_t v, size_t size) \ + M_F(name, _resize)(array_t v, size_t size) \ { \ M_ARRA4_CONTRACT(v); \ if (v->size > size) { \ @@ -440,7 +440,7 @@ , /* No INIT */ ) \ \ static inline void \ - M_C(name, _reserve)(array_t v, size_t alloc) \ + M_F(name, _reserve)(array_t v, size_t alloc) \ { \ M_ARRA4_CONTRACT(v); \ /* NOTE: Reserve below needed size to perform a shrink to fit */ \ @@ -465,7 +465,7 @@ \ M_IF_METHOD(INIT, oplist)( \ static inline type * \ - M_C(name, _safe_get)(array_t v, size_t idx) \ + M_F(name, _safe_get)(array_t v, size_t idx) \ { \ M_ARRA4_CONTRACT(v); \ const size_t size = idx + 1; \ @@ -499,7 +499,7 @@ \ M_IF_AT_LEAST_METHOD(SET, INIT_MOVE, oplist)( \ static inline void \ - M_C(name, _pop_back)(type *dest, array_t v) \ + M_F(name, _pop_back)(type *dest, array_t v) \ { \ M_ARRA4_CONTRACT(v); \ M_ASSERT (v->ptr != NULL); \ @@ -516,7 +516,7 @@ \ M_IF_AT_LEAST_METHOD(INIT_SET, INIT_MOVE, oplist)( \ static inline void \ - M_C(name, _pop_move)(type *dest, array_t v) \ + M_F(name, _pop_move)(type *dest, array_t v) \ { \ M_ARRA4_CONTRACT(v); \ M_ASSERT (v->ptr != NULL); \ @@ -530,31 +530,31 @@ \ M_IF_METHOD(INIT, oplist)( \ static inline void \ - M_C(name, _pop_until)(array_t v, it_t pos) \ + M_F(name, _pop_until)(array_t v, it_t pos) \ { \ M_ARRA4_CONTRACT(v); \ M_ASSERT (v == pos->array); \ M_ASSERT_INDEX(pos->index, v->size+1); \ - M_C(name, _resize)(v, pos->index); \ + M_F(name, _resize)(v, pos->index); \ } \ , /* No INIT */ ) \ \ static inline bool \ - M_C(name, _empty_p)(const array_t v) \ + M_F(name, _empty_p)(const array_t v) \ { \ M_ARRA4_CONTRACT(v); \ return v->size == 0; \ } \ \ static inline size_t \ - M_C(name, _size)(const array_t v) \ + M_F(name, _size)(const array_t v) \ { \ M_ARRA4_CONTRACT(v); \ return v->size; \ } \ \ static inline size_t \ - M_C(name, _capacity)(const array_t v) \ + M_F(name, _capacity)(const array_t v) \ { \ M_ARRA4_CONTRACT(v); \ return v->alloc; \ @@ -562,7 +562,7 @@ \ M_IF_AT_LEAST_METHOD(SET, INIT_MOVE, oplist)( \ static inline void \ - M_C(name, _pop_at)(type *dest, array_t v, size_t i) \ + M_F(name, _pop_at)(type *dest, array_t v, size_t i) \ { \ M_ARRA4_CONTRACT(v); \ M_ASSERT (v->size > 0 && v->ptr != NULL); \ @@ -577,18 +577,18 @@ } \ \ static inline bool \ - M_C(name, _erase)(array_t a, size_t i) \ + M_F(name, _erase)(array_t a, size_t i) \ { \ M_ARRA4_CONTRACT(a); \ if (i >= a->size) return false; \ - M_C(name, _pop_at)(NULL, a, i); \ + M_F(name, _pop_at)(NULL, a, i); \ return true; \ } \ , /* SET | INIT_MOVE */ ) \ \ M_IF_METHOD(INIT, oplist)( \ static inline void \ - M_C(name, _insert_v)(array_t v, size_t i, size_t num) \ + M_F(name, _insert_v)(array_t v, size_t i, size_t num) \ { \ M_ARRA4_CONTRACT(v); \ M_ASSERT_INDEX(i, v->size+1); \ @@ -624,7 +624,7 @@ , /* No INIT */) \ \ static inline void \ - M_C(name, _remove_v)(array_t v, size_t i, size_t j) \ + M_F(name, _remove_v)(array_t v, size_t i, size_t j) \ { \ M_ARRA4_CONTRACT(v); \ M_ASSERT(i < j && v->ptr != NULL); \ @@ -638,7 +638,7 @@ } \ \ static inline void \ - M_C(name, _swap)(array_t v1, array_t v2) \ + M_F(name, _swap)(array_t v1, array_t v2) \ { \ M_ARRA4_CONTRACT(v1); \ M_ARRA4_CONTRACT(v2); \ @@ -651,7 +651,7 @@ \ M_IF_AT_LEAST_METHOD(INIT_SET,INIT_MOVE,oplist) ( \ static inline void \ - M_C(name, _swap_at)(array_t v, size_t i, size_t j) \ + M_F(name, _swap_at)(array_t v, size_t i, size_t j) \ { \ M_ARRA4_CONTRACT(v); \ M_ASSERT(v->ptr != NULL); \ @@ -666,7 +666,7 @@ , /* INIT_SET | INIT_MOVE */ ) \ \ static inline type * \ - M_C(name, _get)(const array_t v, size_t i) \ + M_F(name, _get)(const array_t v, size_t i) \ { \ M_ARRA4_CONTRACT(v); \ M_ASSERT (v->ptr != NULL); \ @@ -675,7 +675,7 @@ } \ \ static inline type const * \ - M_C(name, _cget)(const array_t v, size_t i) \ + M_F(name, _cget)(const array_t v, size_t i) \ { \ M_ARRA4_CONTRACT(v); \ M_ASSERT (v->ptr != NULL); \ @@ -684,15 +684,15 @@ } \ \ static inline type * \ - M_C(name, _front)(const array_t v) \ + M_F(name, _front)(const array_t v) \ { \ M_ARRA4_CONTRACT(v); \ M_ASSERT_INDEX(0, v->size); \ - return M_C(name, _get)(v, 0); \ + return M_F(name, _get)(v, 0); \ } \ \ static inline void \ - M_C(name, _it)(it_t it, const array_t v) \ + M_F(name, _it)(it_t it, const array_t v) \ { \ M_ARRA4_CONTRACT(v); \ M_ASSERT (it != NULL); \ @@ -701,7 +701,7 @@ } \ \ static inline void \ - M_C(name, _it_last)(it_t it, const array_t v) \ + M_F(name, _it_last)(it_t it, const array_t v) \ { \ M_ARRA4_CONTRACT(v); \ M_ASSERT (it != NULL); \ @@ -711,7 +711,7 @@ } \ \ static inline void \ - M_C(name, _it_end)(it_t it, const array_t v) \ + M_F(name, _it_end)(it_t it, const array_t v) \ { \ M_ARRA4_CONTRACT(v); \ M_ASSERT (it != NULL); \ @@ -720,7 +720,7 @@ } \ \ static inline void \ - M_C(name, _it_set)(it_t it, const it_t org) \ + M_F(name, _it_set)(it_t it, const it_t org) \ { \ M_ASSERT (it != NULL && org != NULL); \ it->index = org->index; \ @@ -729,14 +729,14 @@ } \ \ static inline bool \ - M_C(name, _end_p)(const it_t it) \ + M_F(name, _end_p)(const it_t it) \ { \ M_ASSERT(it != NULL && it->array != NULL); \ return it->index >= it->array->size; \ } \ \ static inline bool \ - M_C(name, _last_p)(const it_t it) \ + M_F(name, _last_p)(const it_t it) \ { \ M_ASSERT(it != NULL && it->array != NULL); \ /* NOTE: Can not compute 'size-1' due to potential overflow \ @@ -745,7 +745,7 @@ } \ \ static inline bool \ - M_C(name, _it_equal_p)(const it_t it1, \ + M_F(name, _it_equal_p)(const it_t it1, \ const it_t it2) \ { \ M_ASSERT(it1 != NULL && it2 != NULL); \ @@ -753,14 +753,14 @@ } \ \ static inline void \ - M_C(name, _next)(it_t it) \ + M_F(name, _next)(it_t it) \ { \ M_ASSERT(it != NULL && it->array != NULL); \ it->index ++; \ } \ \ static inline void \ - M_C(name, _previous)(it_t it) \ + M_F(name, _previous)(it_t it) \ { \ M_ASSERT(it != NULL && it->array != NULL); \ /* NOTE: In the case index=0, it will be set to (unsigned) -1 \ @@ -769,43 +769,43 @@ } \ \ static inline type * \ - M_C(name, _ref)(const it_t it) \ + M_F(name, _ref)(const it_t it) \ { \ M_ASSERT(it != NULL); \ - return M_C(name, _get)(it->array, it->index); \ + return M_F(name, _get)(it->array, it->index); \ } \ \ static inline type const * \ - M_C(name, _cref)(const it_t it) \ + M_F(name, _cref)(const it_t it) \ { \ M_ASSERT(it != NULL); \ - return M_C(name, _cget)(it->array, it->index); \ + return M_F(name, _cget)(it->array, it->index); \ } \ \ M_IF_METHOD(INIT_SET, oplist)( \ static inline void \ - M_C(name, _insert)(array_t a, it_t it, type const x) \ + M_F(name, _insert)(array_t a, it_t it, type const x) \ { \ M_ASSERT (it != NULL && a == it->array); \ - size_t index = M_C(name, _end_p)(it) ? 0 : it->index+1; \ - M_C(name, _push_at)(a, index, x); \ + size_t index = M_F(name, _end_p)(it) ? 0 : it->index+1; \ + M_F(name, _push_at)(a, index, x); \ it->index = index; \ } \ , /* End of INIT_SET */ ) \ \ M_IF_AT_LEAST_METHOD(SET, INIT_MOVE, oplist)( \ static inline void \ - M_C(name, _remove)(array_t a, it_t it) \ + M_F(name, _remove)(array_t a, it_t it) \ { \ M_ASSERT (it != NULL && a == it->array); \ - M_C(name, _pop_at)(NULL, a, it->index); \ + M_F(name, _pop_at)(NULL, a, it->index); \ /* NOTE: it->index will naturaly point to the next element */ \ } \ , /* End of SET | INIT_SET */ ) \ \ M_IF_METHOD(CMP, oplist) \ ( \ - static inline void M_C(name, _special_sort)(array_t l, \ + static inline void M_F(name, _special_sort)(array_t l, \ int (*func_type) (type const *a, type const *b)) \ { \ /* Using qsort is more compact but slower than a full templated \ @@ -889,7 +889,7 @@ } \ \ static inline void \ - M_C(name, _special_stable_sort)(array_t l) \ + M_F(name, _special_stable_sort)(array_t l) \ { \ if (M_UNLIKELY (l->size < 2)) \ return; \ @@ -908,7 +908,7 @@ \ M_IF_METHOD(EQUAL, oplist)( \ static inline bool \ - M_C(name, _equal_p)(const array_t array1, \ + M_F(name, _equal_p)(const array_t array1, \ const array_t array2) \ { \ M_ARRA4_CONTRACT(array1); \ @@ -916,8 +916,8 @@ if (array1->size != array2->size) return false; \ size_t i; \ for(i = 0; i < array1->size; i++) { \ - type const *item1 = M_C(name, _cget)(array1, i); \ - type const *item2 = M_C(name, _cget)(array2, i); \ + type const *item1 = M_F(name, _cget)(array1, i); \ + type const *item2 = M_F(name, _cget)(array2, i); \ bool b = M_CALL_EQUAL(oplist, *item1, *item2); \ if (!b) return false; \ } \ @@ -927,7 +927,7 @@ \ M_IF_METHOD(HASH, oplist)( \ static inline size_t \ - M_C(name, _hash)(const array_t array) \ + M_F(name, _hash)(const array_t array) \ { \ M_ARRA4_CONTRACT(array); \ M_HASH_DECL(hash); \ @@ -940,7 +940,7 @@ , /* no HASH */ ) \ \ static inline void \ - M_C(name, _splice)(array_t a1, array_t a2) \ + M_F(name, _splice)(array_t a1, array_t a2) \ { \ M_ARRA4_CONTRACT(a1); \ M_ARRA4_CONTRACT(a2); \ @@ -973,18 +973,18 @@ \ M_IF_METHOD(GET_STR, oplist)( \ static inline void \ - M_C(name, _get_str)(m_string_t str, array_t const array, \ + M_F(name, _get_str)(m_string_t str, array_t const array, \ bool append) \ { \ M_ARRA4_CONTRACT(array); \ (append ? m_string_cat_cstr : m_string_set_cstr) (str, "["); \ it_t it; \ - for (M_C(name, _it)(it, array) ; \ - !M_C(name, _end_p)(it); \ - M_C(name, _next)(it)){ \ - type const *item = M_C(name, _cref)(it); \ + for (M_F(name, _it)(it, array) ; \ + !M_F(name, _end_p)(it); \ + M_F(name, _next)(it)){ \ + type const *item = M_F(name, _cref)(it); \ M_CALL_GET_STR(oplist, str, *item, true); \ - if (!M_C(name, _last_p)(it)) \ + if (!M_F(name, _last_p)(it)) \ m_string_push_back (str, M_GET_SEPARATOR oplist); \ } \ m_string_push_back (str, ']'); \ @@ -993,13 +993,13 @@ \ M_IF_METHOD(OUT_STR, oplist)( \ static inline void \ - M_C(name, _out_str)(FILE *file, const array_t array) \ + M_F(name, _out_str)(FILE *file, const array_t array) \ { \ M_ARRA4_CONTRACT(array); \ M_ASSERT (file != NULL); \ fputc ('[', file); \ for (size_t i = 0; i < array->size; i++) { \ - type const *item = M_C(name, _cget)(array, i); \ + type const *item = M_F(name, _cget)(array, i); \ M_CALL_OUT_STR(oplist, file, *item); \ if (i != array->size-1) \ fputc (M_GET_SEPARATOR oplist, file); \ @@ -1010,11 +1010,11 @@ \ M_IF_METHOD2(PARSE_STR, INIT, oplist)( \ static inline bool \ - M_C(name, _parse_str)(array_t array, const char str[], const char**endp) \ + M_F(name, _parse_str)(array_t array, const char str[], const char**endp) \ { \ M_ARRA4_CONTRACT(array); \ M_ASSERT (str != NULL); \ - M_C(name,_reset)(array); \ + M_F(name,_reset)(array); \ bool success = false; \ int c = *str++; \ if (M_UNLIKELY (c != '[')) goto exit; \ @@ -1028,7 +1028,7 @@ bool b = M_CALL_PARSE_STR(oplist, item, str, &str); \ do { c = *str++; } while (isspace(c)); \ if (b == false || c == 0) { goto exit_clear; } \ - M_C(name, _push_back)(array, item); \ + M_F(name, _push_back)(array, item); \ } while (c == M_GET_SEPARATOR oplist); \ M_ARRA4_CONTRACT(array); \ success = (c == ']'); \ @@ -1042,11 +1042,11 @@ \ M_IF_METHOD2(IN_STR, INIT, oplist)( \ static inline bool \ - M_C(name, _in_str)(array_t array, FILE *file) \ + M_F(name, _in_str)(array_t array, FILE *file) \ { \ M_ARRA4_CONTRACT(array); \ M_ASSERT (file != NULL); \ - M_C(name,_reset)(array); \ + M_F(name,_reset)(array); \ int c = fgetc(file); \ if (M_UNLIKELY (c != '[')) return false; \ c = fgetc(file); \ @@ -1059,7 +1059,7 @@ bool b = M_CALL_IN_STR(oplist, item, file); \ do { c = fgetc(file); } while (isspace(c)); \ if (b == false || c == EOF) { break; } \ - M_C(name, _push_back)(array, item); \ + M_F(name, _push_back)(array, item); \ } while (c == M_GET_SEPARATOR oplist); \ M_CALL_CLEAR(oplist, item); \ M_ARRA4_CONTRACT(array); \ @@ -1069,7 +1069,7 @@ \ M_IF_METHOD(OUT_SERIAL, oplist)( \ static inline m_serial_return_code_t \ - M_C(name, _out_serial)(m_serial_write_t f, const array_t array) \ + M_F(name, _out_serial)(m_serial_write_t f, const array_t array) \ { \ M_ARRA4_CONTRACT(array); \ M_ASSERT (f != NULL && f->m_interface != NULL); \ @@ -1077,7 +1077,7 @@ m_serial_local_t local; \ ret = f->m_interface->write_array_start(local, f, array->size); \ for (size_t i = 0; i < array->size; i++) { \ - type const *item = M_C(name, _cget)(array, i); \ + type const *item = M_F(name, _cget)(array, i); \ if (i != 0) { \ ret |= f->m_interface->write_array_next(local, f); \ } \ @@ -1090,28 +1090,28 @@ \ M_IF_METHOD2(IN_SERIAL, INIT, oplist)( \ static inline m_serial_return_code_t \ - M_C(name, _in_serial)(array_t array, m_serial_read_t f) \ + M_F(name, _in_serial)(array_t array, m_serial_read_t f) \ { \ M_ARRA4_CONTRACT(array); \ M_ASSERT (f != NULL && f->m_interface != NULL); \ m_serial_return_code_t ret; \ m_serial_local_t local; \ size_t estimated_size = 0; \ - M_C(name,_reset)(array); \ + M_F(name,_reset)(array); \ ret = f->m_interface->read_array_start(local, f, &estimated_size); \ if (M_UNLIKELY (ret != M_SERIAL_OK_CONTINUE)) { \ return ret; \ } \ if (estimated_size != 0) { \ /* The format has given an estimation of the array size */ \ - M_C(name, _reserve)(array, estimated_size); \ + M_F(name, _reserve)(array, estimated_size); \ } \ type item; \ M_CALL_INIT(oplist, item); \ do { \ ret = M_CALL_IN_SERIAL(oplist, item, f); \ if (ret != M_SERIAL_OK_DONE) { break; } \ - M_C(name, _push_back)(array, item); \ + M_F(name, _push_back)(array, item); \ ret = f->m_interface->read_array_next(local, f); \ } while (ret == M_SERIAL_OK_CONTINUE); \ M_CALL_CLEAR(oplist, item); \ @@ -1126,7 +1126,7 @@ function_name(name_t v \ M_EMPLACE_LIST_TYPE_VAR(a, exp_emplace_type) ) \ { \ - M_C(name, _subtype_ct) *data = M_C(name, _push_raw)(v); \ + M_F(name, _subtype_ct) *data = M_F(name, _push_raw)(v); \ if (M_UNLIKELY (data == NULL) ) \ return; \ M_EMPLACE_CALL_FUNC(a, init_func, oplist, *data, exp_emplace_type); \ diff --git a/m-bptree.h b/m-bptree.h index ca19539c..4377e1f6 100644 --- a/m-bptree.h +++ b/m-bptree.h @@ -35,7 +35,7 @@ BPTREE_DEF2(name, N, key_t, value_t) */ #define M_BPTREE_DEF2(name, N, key_type, ...) \ - M_BPTREE_DEF2_AS(name, M_C(name,_t), M_C(name,_it_t), M_C(name, _itref_t), N, key_type, __VA_ARGS__) + M_BPTREE_DEF2_AS(name, M_F(name,_t), M_F(name,_it_t), M_F(name, _itref_t), N, key_type, __VA_ARGS__) /* Define a B+tree of size 'N' that maps a 'key' to a 'value' @@ -48,8 +48,8 @@ #define M_BPTREE_DEF2_AS(name, name_t, it_t, itref_t, N, key_type, ...) \ M_BEGIN_PROTECTED_CODE \ M_BPTR33_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ - ((name, N, key_type, M_GLOBAL_OPLIST_OR_DEF(key_type)(), __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), 1, 0, name_t, M_C(name, _node_ct), M_C(name, _pit_ct), it_t, itref_t ), \ - (name, N, key_type, __VA_ARGS__, 1, 0, name_t, M_C(name, _node_ct), M_C(name, _pit_ct), it_t, itref_t ))) \ + ((name, N, key_type, M_GLOBAL_OPLIST_OR_DEF(key_type)(), __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), 1, 0, name_t, M_F(name, _node_ct), M_F(name, _pit_ct), it_t, itref_t ), \ + (name, N, key_type, __VA_ARGS__, 1, 0, name_t, M_F(name, _node_ct), M_F(name, _pit_ct), it_t, itref_t ))) \ M_END_PROTECTED_CODE @@ -57,7 +57,7 @@ with its associated functions USAGE: BPTREE_DEF(name, N, type, [, oplist_of_the_type]) */ #define M_BPTREE_DEF(name, N, ...) \ - M_BPTREE_DEF_AS(name, M_C(name,_t), M_C(name,_it_t), N, __VA_ARGS__) + M_BPTREE_DEF_AS(name, M_F(name,_t), M_F(name,_it_t), N, __VA_ARGS__) /* Define a B+tree of a given type, of size N. @@ -66,8 +66,8 @@ #define M_BPTREE_DEF_AS(name, name_t, it_t, N, ...) \ M_BEGIN_PROTECTED_CODE \ M_BPTR33_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ - ((name, N, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), 0, 0, name_t, M_C(name, _node_ct), M_C(name, _pit_ct), it_t, M_C(name, _itref_ct) ), \ - (name, N, __VA_ARGS__, __VA_ARGS__, 0, 0, name_t, M_C(name, _node_ct), M_C(name, _pit_ct), it_t, M_C(name, _itref_ct) ))) \ + ((name, N, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), 0, 0, name_t, M_F(name, _node_ct), M_F(name, _pit_ct), it_t, M_F(name, _itref_ct) ), \ + (name, N, __VA_ARGS__, __VA_ARGS__, 0, 0, name_t, M_F(name, _node_ct), M_F(name, _pit_ct), it_t, M_F(name, _itref_ct) ))) \ M_END_PROTECTED_CODE @@ -80,7 +80,7 @@ BPTREE_MULTI_DEF2(name, N, key_t, value_t) */ #define M_BPTREE_MULTI_DEF2(name, N, key_type, ...) \ - M_BPTREE_MULTI_DEF2_AS(name, M_C(name,_t), M_C(name,_it_t), M_C(name,_itref_t), N, key_type, __VA_ARGS__) + M_BPTREE_MULTI_DEF2_AS(name, M_F(name,_t), M_F(name,_it_t), M_F(name,_itref_t), N, key_type, __VA_ARGS__) /* Define a B+tree of size 'N' that maps a 'key' to a 'value', @@ -94,8 +94,8 @@ #define M_BPTREE_MULTI_DEF2_AS(name, name_t, it_t, itref_t, N, key_type, ...) \ M_BEGIN_PROTECTED_CODE \ M_BPTR33_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ - ((name, N, key_type, M_GLOBAL_OPLIST_OR_DEF(key_type)(), __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), 1, 1, name_t, M_C(name, _node_ct), M_C(name, _pit_ct), it_t, itref_t ), \ - (name, N, key_type, __VA_ARGS__, 1, 1, name_t, M_C(name, _node_ct), M_C(name, _pit_ct), it_t, itref_t ))) \ + ((name, N, key_type, M_GLOBAL_OPLIST_OR_DEF(key_type)(), __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), 1, 1, name_t, M_F(name, _node_ct), M_F(name, _pit_ct), it_t, itref_t ), \ + (name, N, key_type, __VA_ARGS__, 1, 1, name_t, M_F(name, _node_ct), M_F(name, _pit_ct), it_t, itref_t ))) \ M_END_PROTECTED_CODE @@ -104,7 +104,7 @@ with its associated functions USAGE: BPTREE_MULTI_DEF(name, N, type, [, oplist_of_the_type]) */ #define M_BPTREE_MULTI_DEF(name, N, ...) \ - M_BPTREE_MULTI_DEF_AS(name, M_C(name,_t), M_C(name,_it_t), N, __VA_ARGS__) + M_BPTREE_MULTI_DEF_AS(name, M_F(name,_t), M_F(name,_it_t), N, __VA_ARGS__) /* Define a B+tree of a given type, of size N. @@ -114,8 +114,8 @@ #define M_BPTREE_MULTI_DEF_AS(name, name_t, it_t, N, ...) \ M_BEGIN_PROTECTED_CODE \ M_BPTR33_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ - ((name, N, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), 0, 1, name_t, M_C(name, _node_ct), M_C(name, _pit_ct), it_t, M_C(name, _itref_ct) ), \ - (name, N, __VA_ARGS__, __VA_ARGS__, 0, 1, name_t, M_C(name, _node_ct), M_C(name, _pit_ct), it_t, M_C(name, _itref_ct) ))) \ + ((name, N, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), 0, 1, name_t, M_F(name, _node_ct), M_F(name, _pit_ct), it_t, M_F(name, _itref_ct) ), \ + (name, N, __VA_ARGS__, __VA_ARGS__, 0, 1, name_t, M_F(name, _node_ct), M_F(name, _pit_ct), it_t, M_F(name, _itref_ct) ))) \ M_BEGIN_PROTECTED_CODE @@ -157,37 +157,37 @@ /* OPLIST definition of a b+tree (global tree) */ #define M_BPTR33_KEY_OPLIST_P3(name, oplist) \ - (INIT(M_C(name, _init)), \ - INIT_SET(M_C(name, _init_set)), \ + (INIT(M_F(name, _init)), \ + INIT_SET(M_F(name, _init_set)), \ INIT_WITH(API_1(M_INIT_VAI)), \ - SET(M_C(name, _set)), \ - CLEAR(M_C(name, _clear)), \ - INIT_MOVE(M_C(name, _init_move)), \ - MOVE(M_C(name, _move)), \ - SWAP(M_C(name, _swap)), \ + SET(M_F(name, _set)), \ + CLEAR(M_F(name, _clear)), \ + INIT_MOVE(M_F(name, _init_move)), \ + MOVE(M_F(name, _move)), \ + SWAP(M_F(name, _swap)), \ NAME(name), \ - TYPE(M_C(name,_ct)), \ - SUBTYPE(M_C(name, _subtype_ct)), \ - IT_TYPE(M_C(name, _it_ct)), \ - IT_FIRST(M_C(name,_it)), \ - IT_SET(M_C(name,_it_set)), \ - IT_END(M_C(name,_it_end)), \ - IT_END_P(M_C(name,_end_p)), \ - IT_EQUAL_P(M_C(name,_it_equal_p)), \ - IT_NEXT(M_C(name,_next)), \ - IT_CREF(M_C(name,_cref)), \ - RESET(M_C(name,_reset)), \ - PUSH(M_C(name,_push)), \ - GET_MIN(M_C(name,_min)), \ - GET_MAX(M_C(name,_max)), \ - M_IF_METHOD(GET_STR, oplist)(GET_STR(M_C(name, _get_str)),), \ - M_IF_METHOD(PARSE_STR, oplist)(PARSE_STR(M_C(name, _parse_str)),), \ - M_IF_METHOD(OUT_STR, oplist)(OUT_STR(M_C(name, _out_str)),), \ - M_IF_METHOD(IN_STR, oplist)(IN_STR(M_C(name, _in_str)),), \ - M_IF_METHOD(OUT_SERIAL, oplist)(OUT_SERIAL(M_C(name, _out_serial)),), \ - M_IF_METHOD(IN_SERIAL, oplist)(IN_SERIAL(M_C(name, _in_serial)),), \ - M_IF_METHOD(EQUAL, oplist)(EQUAL(M_C(name, _equal_p)),), \ - M_IF_METHOD(HASH, oplist)(HASH(M_C(name, _hash)),) \ + TYPE(M_F(name,_ct)), \ + SUBTYPE(M_F(name, _subtype_ct)), \ + IT_TYPE(M_F(name, _it_ct)), \ + IT_FIRST(M_F(name,_it)), \ + IT_SET(M_F(name,_it_set)), \ + IT_END(M_F(name,_it_end)), \ + IT_END_P(M_F(name,_end_p)), \ + IT_EQUAL_P(M_F(name,_it_equal_p)), \ + IT_NEXT(M_F(name,_next)), \ + IT_CREF(M_F(name,_cref)), \ + RESET(M_F(name,_reset)), \ + PUSH(M_F(name,_push)), \ + GET_MIN(M_F(name,_min)), \ + GET_MAX(M_F(name,_max)), \ + M_IF_METHOD(GET_STR, oplist)(GET_STR(M_F(name, _get_str)),), \ + M_IF_METHOD(PARSE_STR, oplist)(PARSE_STR(M_F(name, _parse_str)),), \ + M_IF_METHOD(OUT_STR, oplist)(OUT_STR(M_F(name, _out_str)),), \ + M_IF_METHOD(IN_STR, oplist)(IN_STR(M_F(name, _in_str)),), \ + M_IF_METHOD(OUT_SERIAL, oplist)(OUT_SERIAL(M_F(name, _out_serial)),), \ + M_IF_METHOD(IN_SERIAL, oplist)(IN_SERIAL(M_F(name, _in_serial)),), \ + M_IF_METHOD(EQUAL, oplist)(EQUAL(M_F(name, _equal_p)),), \ + M_IF_METHOD(HASH, oplist)(HASH(M_F(name, _hash)),) \ ,M_IF_METHOD(NEW, oplist)(NEW(M_GET_NEW oplist),) \ ,M_IF_METHOD(REALLOC, oplist)(REALLOC(M_GET_REALLOC oplist),) \ ,M_IF_METHOD(DEL, oplist)(DEL(M_GET_DEL oplist),) \ @@ -209,44 +209,44 @@ /* Final definition of the oplist (associative array) */ #define M_BPTR33_OPLIST2_P4(name, key_oplist, value_oplist) \ - (INIT(M_C(name, _init)), \ - INIT_SET(M_C(name, _init_set)), \ + (INIT(M_F(name, _init)), \ + INIT_SET(M_F(name, _init_set)), \ INIT_WITH(API_1(M_INIT_KEY_VAI)), \ - SET(M_C(name, _set)), \ - CLEAR(M_C(name, _clear)), \ - INIT_MOVE(M_C(name, _init_move)), \ - MOVE(M_C(name, _move)), \ - SWAP(M_C(name, _swap)), \ + SET(M_F(name, _set)), \ + CLEAR(M_F(name, _clear)), \ + INIT_MOVE(M_F(name, _init_move)), \ + MOVE(M_F(name, _move)), \ + SWAP(M_F(name, _swap)), \ NAME(name), \ - TYPE(M_C(name,_ct)), \ - SUBTYPE(M_C(name, _subtype_ct)), \ - EMPTY_P(M_C(name,_empty_p)), \ - IT_TYPE(M_C(name, _it_ct)), \ - IT_FIRST(M_C(name,_it)), \ - IT_SET(M_C(name,_it_set)), \ - IT_END(M_C(name,_it_end)), \ - IT_END_P(M_C(name,_end_p)), \ - IT_EQUAL_P(M_C(name,_it_equal_p)), \ - IT_NEXT(M_C(name,_next)), \ - IT_CREF(M_C(name,_cref)), \ - RESET(M_C(name,_reset)), \ - GET_MIN(M_C(name,_min)), \ - GET_MAX(M_C(name,_max)), \ - KEY_TYPE(M_C(name, _key_ct)), \ - VALUE_TYPE(M_C(name, _value_ct)), \ - SET_KEY(M_C(name, _set_at)), \ - GET_KEY(M_C(name, _get)), \ - SAFE_GET_KEY(M_C(name, _safe_get)) \ - ERASE_KEY(M_C(name, _erase)), \ + TYPE(M_F(name,_ct)), \ + SUBTYPE(M_F(name, _subtype_ct)), \ + EMPTY_P(M_F(name,_empty_p)), \ + IT_TYPE(M_F(name, _it_ct)), \ + IT_FIRST(M_F(name,_it)), \ + IT_SET(M_F(name,_it_set)), \ + IT_END(M_F(name,_it_end)), \ + IT_END_P(M_F(name,_end_p)), \ + IT_EQUAL_P(M_F(name,_it_equal_p)), \ + IT_NEXT(M_F(name,_next)), \ + IT_CREF(M_F(name,_cref)), \ + RESET(M_F(name,_reset)), \ + GET_MIN(M_F(name,_min)), \ + GET_MAX(M_F(name,_max)), \ + KEY_TYPE(M_F(name, _key_ct)), \ + VALUE_TYPE(M_F(name, _value_ct)), \ + SET_KEY(M_F(name, _set_at)), \ + GET_KEY(M_F(name, _get)), \ + SAFE_GET_KEY(M_F(name, _safe_get)) \ + ERASE_KEY(M_F(name, _erase)), \ KEY_OPLIST(key_oplist), \ VALUE_OPLIST(value_oplist), \ - M_IF_METHOD_BOTH(PARSE_STR, key_oplist, value_oplist)(PARSE_STR(M_C(name, _parse_str)),), \ - M_IF_METHOD_BOTH(OUT_STR, key_oplist, value_oplist)(OUT_STR(M_C(name, _out_str)),), \ - M_IF_METHOD_BOTH(IN_STR, key_oplist, value_oplist)(IN_STR(M_C(name, _in_str)),), \ - M_IF_METHOD_BOTH(OUT_SERIAL, key_oplist, value_oplist)(OUT_SERIAL(M_C(name, _out_serial)),), \ - M_IF_METHOD_BOTH(IN_SERIAL, key_oplist, value_oplist)(IN_SERIAL(M_C(name, _in_serial)),), \ - M_IF_METHOD_BOTH(EQUAL, key_oplist, value_oplist)(EQUAL(M_C(name, _equal_p)),), \ - M_IF_METHOD_BOTH(HASH, key_oplist, value_oplist)(HASH(M_C(name, _hash)),) \ + M_IF_METHOD_BOTH(PARSE_STR, key_oplist, value_oplist)(PARSE_STR(M_F(name, _parse_str)),), \ + M_IF_METHOD_BOTH(OUT_STR, key_oplist, value_oplist)(OUT_STR(M_F(name, _out_str)),), \ + M_IF_METHOD_BOTH(IN_STR, key_oplist, value_oplist)(IN_STR(M_F(name, _in_str)),), \ + M_IF_METHOD_BOTH(OUT_SERIAL, key_oplist, value_oplist)(OUT_SERIAL(M_F(name, _out_serial)),), \ + M_IF_METHOD_BOTH(IN_SERIAL, key_oplist, value_oplist)(IN_SERIAL(M_F(name, _in_serial)),), \ + M_IF_METHOD_BOTH(EQUAL, key_oplist, value_oplist)(EQUAL(M_F(name, _equal_p)),), \ + M_IF_METHOD_BOTH(HASH, key_oplist, value_oplist)(HASH(M_F(name, _hash)),) \ ,M_IF_METHOD(NEW, key_oplist)(NEW(M_GET_NEW oplist),) \ ,M_IF_METHOD(REALLOC, key_oplist)(REALLOC(M_GET_REALLOC oplist),) \ ,M_IF_METHOD(DEL, key_oplist)(DEL(M_GET_DEL oplist),) \ @@ -356,7 +356,7 @@ /* Type returned by the iterator. Due to having key and value \ separated in their own array in the node, it is pointers to \ the objects, not a global pointer to both objects. */ \ - typedef struct M_C(name, _pair_s) { \ + typedef struct M_F(name, _pair_s) { \ key_t *key_ptr; \ value_t *value_ptr; \ } subtype_t; \ @@ -369,54 +369,54 @@ * needed so that the code can push one more element in the node and \ * then split the nodes (simplify the code) \ */ \ - typedef struct M_C(name, _node_s) { \ + typedef struct M_F(name, _node_s) { \ int num; /* Abs=Number of keys. Sign <0 is leaf */ \ key_t key[N+1]; /* We can temporary push one more key */ \ - struct M_C(name, _node_s) *next; /* next node reference */ \ - union M_C(name, _kind_s) { /* either value or pointer to other nodes */ \ + struct M_F(name, _node_s) *next; /* next node reference */ \ + union M_F(name, _kind_s) { /* either value or pointer to other nodes */ \ M_IF(isMap)(value_t value[N+1];,) \ - struct M_C(name, _node_s) *node[N+2]; \ + struct M_F(name, _node_s) *node[N+2]; \ } kind; \ } *node_t; \ \ /* A B+TREE is just a pointer to the root node */ \ - typedef struct M_C(name, _s) { \ + typedef struct M_F(name, _s) { \ node_t root; \ size_t size; \ } tree_t[1]; \ - typedef struct M_C(name, _s) *M_C(name, _ptr); \ - typedef const struct M_C(name, _s) *M_C(name, _srcptr); \ + typedef struct M_F(name, _s) *M_F(name, _ptr); \ + typedef const struct M_F(name, _s) *M_F(name, _srcptr); \ \ /* Definition of the alias used by the oplists */ \ - typedef subtype_t M_C(name, _subtype_ct); \ - typedef key_t M_C(name, _key_ct); \ - typedef value_t M_C(name, _value_ct); \ - typedef tree_t M_C(name, _ct); \ + typedef subtype_t M_F(name, _subtype_ct); \ + typedef key_t M_F(name, _key_ct); \ + typedef value_t M_F(name, _value_ct); \ + typedef tree_t M_F(name, _ct); \ \ /* Define the Parent Tree Iterator */ \ - typedef struct M_C(name, _parent_it_s) { \ + typedef struct M_F(name, _parent_it_s) { \ int num; \ node_t parent[M_BPTR33_MAX_STACK]; \ } pit_t[1]; \ \ /* Define the Iterator */ \ - typedef struct M_C(name, _it_s) { \ - M_IF(isMap)(struct M_C(name, _pair_s) pair;,) \ + typedef struct M_F(name, _it_s) { \ + M_IF(isMap)(struct M_F(name, _pair_s) pair;,) \ node_t node; \ int idx; \ } it_t[1]; \ - typedef it_t M_C(name, _it_ct); \ + typedef it_t M_F(name, _it_ct); \ /* Define the core functions of a B+ Tree */ #define M_BPTR33_DEF_CORE(name, N, key_t, key_oplist, value_t, value_oplist, isMap, isMulti, tree_t, node_t, pit_t, it_t, subtype_t) \ \ /* Allocate a new node */ \ /* TODO: Can be specialized to alloc for leaf or for non leaf */ \ - static inline node_t M_C(name, _new_node)(void) \ + static inline node_t M_F(name, _new_node)(void) \ { \ M_STATIC_ASSERT(N >= 2, M_LIB_ILLEGAL_PARAM, \ "Number of items per node shall be >= 2."); \ - node_t n = M_CALL_NEW(key_oplist, struct M_C(name, _node_s)); \ + node_t n = M_CALL_NEW(key_oplist, struct M_F(name, _node_s)); \ if (M_UNLIKELY_NOMEM (n == NULL)) { \ M_MEMORY_FULL(sizeof (node_t)); \ M_ASSERT (0); \ @@ -426,14 +426,14 @@ return n; \ } \ \ - static inline void M_C(name, _init)(tree_t b) \ + static inline void M_F(name, _init)(tree_t b) \ { \ - b->root = M_C(name, _new_node)(); \ + b->root = M_F(name, _new_node)(); \ b->size = 0; \ M_BPTR33_CONTRACT(N, isMulti, key_oplist, b); \ } \ \ - static inline bool M_C(name, _is_leaf)(const node_t n) \ + static inline bool M_F(name, _is_leaf)(const node_t n) \ { \ /* We consider the empty node as a leaf */ \ /* Only the root node can be empty */ \ @@ -441,7 +441,7 @@ } \ \ /* Return the number of keys of the node */ \ - static inline int M_C(name, _get_num)(const node_t n) \ + static inline int M_F(name, _get_num)(const node_t n) \ { \ int num = n->num; \ num = num < 0 ? -num : num; \ @@ -449,7 +449,7 @@ return num; \ } \ \ - static inline void M_C(name, _reset)(tree_t b) \ + static inline void M_F(name, _reset)(tree_t b) \ { \ M_BPTR33_CONTRACT(N, isMulti, key_oplist, b); \ node_t next, n = b->root; \ @@ -457,7 +457,7 @@ /* np is the heigh of the tree */ \ int np = 0; \ /* Scan down the nodes to the left down node */ \ - while (!M_C(name, _is_leaf)(n)) { \ + while (!M_F(name, _is_leaf)(n)) { \ pit->parent[np++] = n; \ M_ASSERT (np <= M_BPTR33_MAX_STACK); \ n = n->kind.node[0]; \ @@ -469,8 +469,8 @@ n = pit->parent[i]; \ while (n != NULL) { \ /* Clear key (& value for leaf) */ \ - int num = M_C(name, _get_num)(n); \ - M_IF(isMap)(bool is_leaf = M_C(name, _is_leaf)(n);,) \ + int num = M_F(name, _get_num)(n); \ + M_IF(isMap)(bool is_leaf = M_F(name, _is_leaf)(n);,) \ for(int j = 0; j < num; j++) { \ M_CALL_CLEAR(key_oplist, n->key[j]); \ M_IF(isMap)(if (is_leaf) { \ @@ -492,30 +492,30 @@ M_BPTR33_CONTRACT(N, isMulti, key_oplist, b); \ } \ \ - static inline void M_C(name, _clear)(tree_t b) \ + static inline void M_F(name, _clear)(tree_t b) \ { \ M_BPTR33_CONTRACT(N, isMulti, key_oplist, b); \ - M_C(name, _reset)(b); \ + M_F(name, _reset)(b); \ /* Once the tree is clean, only the root remains */ \ M_CALL_DEL(key_oplist, b->root); \ b->root = NULL; \ } \ \ /* Copy recursively the node 'o' of root node 'root' */ \ - static inline node_t M_C(name, _copy_node)(const node_t o, const node_t root) \ + static inline node_t M_F(name, _copy_node)(const node_t o, const node_t root) \ { \ - node_t n = M_C(name, _new_node)(); \ + node_t n = M_F(name, _new_node)(); \ /* Set default number of keys and type to copy */ \ n->num = o->num; \ /* By default it is not linked to its brother. \ Only the parent of this node can do it. It is fixed by it */ \ n->next = NULL; \ /* Get number of keys in the node and copy them */ \ - int num = M_C(name, _get_num)(o); \ + int num = M_F(name, _get_num)(o); \ for(int i = 0; i < num; i++) { \ M_CALL_INIT_SET(key_oplist, n->key[i], o->key[i]); \ } \ - if (M_C(name, _is_leaf)(o)) { \ + if (M_F(name, _is_leaf)(o)) { \ /* Copy the associated values if it is a leaf and a MAP */ \ M_IF(isMap)( \ for(int i = 0; i < num; i++) { \ @@ -526,7 +526,7 @@ /* Copy recursively the associated nodes if it is not a leaf */ \ for(int i = 0; i <= num; i++) { \ 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_F(name, _copy_node)(o->kind.node[i], root); \ } \ /* The copied nodes don't have their next field correct */ \ /* Fix the next field for the copied nodes */ \ @@ -536,8 +536,8 @@ current->next = next; \ /* Go down the tree up to the leaf \ and fix the final 'next' link with the copied node */ \ - while (!M_C(name, _is_leaf)(current)) { \ - M_ASSERT(!M_C(name, _is_leaf)(next)); \ + while (!M_F(name, _is_leaf)(current)) { \ + M_ASSERT(!M_F(name, _is_leaf)(next)); \ current = current->kind.node[current->num]; \ next = next->kind.node[0]; \ current->next = next; \ @@ -548,44 +548,44 @@ return n; \ } \ \ - static inline void M_C(name, _init_set)(tree_t b, const tree_t o) \ + static inline void M_F(name, _init_set)(tree_t b, const tree_t o) \ { \ M_BPTR33_CONTRACT(N, isMulti, key_oplist, o); \ M_ASSERT (b != NULL); \ /* Just copy recursively the root node */ \ - b->root = M_C(name, _copy_node)(o->root, o->root); \ + b->root = M_F(name, _copy_node)(o->root, o->root); \ b->size = o->size; \ M_BPTR33_CONTRACT(N, isMulti, key_oplist, b); \ } \ \ - static inline void M_C(name, _set)(tree_t b, const tree_t o) \ + static inline void M_F(name, _set)(tree_t b, const tree_t o) \ { \ /* NOTE: We could reuse the already allocated nodes of 'b'. \ Not sure if it worth the effort */ \ - M_C(name, _clear)(b); \ - M_C(name, _init_set)(b, o); \ + M_F(name, _clear)(b); \ + M_F(name, _init_set)(b, o); \ } \ \ - static inline bool M_C(name, _empty_p)(const tree_t b) \ + static inline bool M_F(name, _empty_p)(const tree_t b) \ { \ M_BPTR33_CONTRACT(N, isMulti, key_oplist, b); \ /* root shall be an empty leaf */ \ return b->size == 0; \ } \ \ - static inline size_t M_C(name, _size)(const tree_t b) \ + static inline size_t M_F(name, _size)(const tree_t b) \ { \ M_BPTR33_CONTRACT(N, isMulti, key_oplist, b); \ return b->size; \ } \ \ - static inline node_t M_C(name, _search_for_leaf)(pit_t pit, const tree_t b, key_t const key) \ + static inline node_t M_F(name, _search_for_leaf)(pit_t pit, const tree_t b, key_t const key) \ { \ node_t n = b->root; \ int np = 0; \ M_BPTR33_NODE_CONTRACT(N, isMulti, key_oplist, n, b->root); \ /* Go down the tree while searching for key */ \ - while (!M_C(name, _is_leaf)(n)) { \ + while (!M_F(name, _is_leaf)(n)) { \ M_ASSERT (np <= M_BPTR33_MAX_STACK); \ int i, hi = n->num; \ M_ASSERT (hi > 0); \ @@ -608,12 +608,12 @@ return n; \ } \ \ - static inline value_t *M_C(name, _get)(const tree_t b, key_t const key) \ + static inline value_t *M_F(name, _get)(const tree_t b, key_t const key) \ { \ M_BPTR33_CONTRACT(N, isMulti, key_oplist, b); \ pit_t pit; \ /* Get the leaf node where the key can be */ \ - node_t n = M_C(name, _search_for_leaf)(pit, b, key); \ + node_t n = M_F(name, _search_for_leaf)(pit, b, key); \ int cmp = 0; \ M_BPTR33_NODE_CONTRACT(N, isMulti, key_oplist, n, b->root); \ /* Search in the leaf for key */ \ @@ -628,17 +628,17 @@ return NULL; \ } \ \ - static inline value_t const *M_C(name, _cget)(const tree_t b, key_t const key) \ + static inline value_t const *M_F(name, _cget)(const tree_t b, key_t const key) \ { \ - return M_CONST_CAST(value_t, M_C(name, _get)(b, key)); \ + return M_CONST_CAST(value_t, M_F(name, _get)(b, key)); \ } \ \ static inline int \ - M_C(name, _search_and_insert_in_leaf)(node_t n, key_t const key \ + M_F(name, _search_and_insert_in_leaf)(node_t n, key_t const key \ M_IF(isMap)( M_DEFERRED_COMMA value_t const value,) ) \ { \ - M_ASSERT (M_C(name, _is_leaf)(n)); \ - int i, num = M_C(name, _get_num)(n); \ + M_ASSERT (M_F(name, _is_leaf)(n)); \ + int i, num = M_F(name, _get_num)(n); \ M_ASSERT (num <= N); \ /* Search for the key in the node n (a leaf) for insertion */ \ for(i = 0; i < num; i++) { \ @@ -666,10 +666,10 @@ } \ \ static inline int \ - M_C(name, _search_and_insert_in_node)(node_t n, node_t l, key_t key) \ + M_F(name, _search_and_insert_in_node)(node_t n, node_t l, key_t key) \ { \ - M_ASSERT (!M_C(name, _is_leaf)(n)); \ - int i, num = M_C(name, _get_num)(n); \ + M_ASSERT (!M_F(name, _is_leaf)(n)); \ + int i, num = M_F(name, _get_num)(n); \ M_ASSERT (num <= N); \ /* Search for the key in the node n (not a leaf) for insertion */ \ for(i = 0; i < num; i++) { \ @@ -689,15 +689,15 @@ } \ \ static inline void \ - M_IF(isMap)(M_C(name, _set_at),M_C(name,_push))(tree_t b, key_t const key \ + M_IF(isMap)(M_F(name, _set_at),M_F(name,_push))(tree_t b, key_t const key \ M_IF(isMap)(M_DEFERRED_COMMA value_t const value,)) \ { \ pit_t pit; \ M_BPTR33_CONTRACT(N, isMulti, key_oplist, b); \ - node_t leaf = M_C(name, _search_for_leaf)(pit, b, key); \ + node_t leaf = M_F(name, _search_for_leaf)(pit, b, key); \ /* Insert key into the leaf.*/ \ /* NOTE: Even if there is N elements, we can still add one more.*/ \ - int i = M_C(name, _search_and_insert_in_leaf)(leaf, key M_IF (isMap)(M_DEFERRED_COMMA value,)); \ + int i = M_F(name, _search_and_insert_in_leaf)(leaf, key M_IF (isMap)(M_DEFERRED_COMMA value,)); \ if (i < 0) { \ /* Nothing to do anymore. key already exists in the tree. \ value has been updated if needed */ \ @@ -719,7 +719,7 @@ /* leaf is full: need to slip the leaf in two */ \ int nnum = (N + 1) / 2; \ num = N + 1 - nnum; \ - node_t nleaf = M_C(name, _new_node)(); \ + node_t nleaf = M_F(name, _new_node)(); \ /* Move half objects to the new node */ \ memmove(&nleaf->key[0], &leaf->key[num], sizeof(key_t)*(unsigned int)nnum); \ M_IF(isMap)(memmove(&nleaf->kind.value[0], &leaf->kind.value[num], sizeof(value_t)*(unsigned int)nnum);,) \ @@ -734,7 +734,7 @@ while (true) { \ if (pit->num == 0) { \ /* We reach root ==> Need to increase the height of the tree.*/ \ - node_t parent = M_C(name, _new_node)(); \ + node_t parent = M_F(name, _new_node)(); \ parent->num = 1; \ /* TBC: DO_INIT_MOVE instead ? If key was in a node !*/ \ M_CALL_INIT_SET(key_oplist, parent->key[0], *key_ptr); \ @@ -747,7 +747,7 @@ /* Non root node. Get the parent node */ \ node_t parent = pit->parent[--pit->num]; \ /* Insert into parent (It is big enough to receive temporary one more) */ \ - i = M_C(name, _search_and_insert_in_node)(parent, leaf, *key_ptr); \ + i = M_F(name, _search_and_insert_in_node)(parent, leaf, *key_ptr); \ parent->kind.node[i] = leaf; \ parent->kind.node[i+1] = nleaf; \ /* Test if parent node is full? */ \ @@ -760,7 +760,7 @@ int nnp = N / 2; \ int np = N - nnp; \ M_ASSERT (nnp > 0 && np > 0 && nnp+np+1 == N+1); \ - node_t nparent = M_C(name, _new_node)(); \ + node_t nparent = M_F(name, _new_node)(); \ /* Move half items to new node (Like a classic B-TREE) \ and the median key to the grand-parent*/ \ memmove(&nparent->key[0], &parent->key[np+1], sizeof(key_t)*(unsigned int)nnp); \ @@ -778,30 +778,30 @@ } \ } \ \ - static inline value_t *M_C(name, _safe_get)(tree_t b, key_t const key) \ + static inline value_t *M_F(name, _safe_get)(tree_t b, key_t const key) \ { \ M_BPTR33_CONTRACT(N, isMulti, key_oplist, b); \ /* Not optimized implementation */ \ - value_t *ret = M_C(name, _get)(b, key); \ + value_t *ret = M_F(name, _get)(b, key); \ if (ret == NULL) { \ M_IF(isMap)( \ value_t v; \ M_CALL_INIT(value_oplist, v); \ - M_C(name, _set_at)(b, key, v); \ + M_F(name, _set_at)(b, key, v); \ M_CALL_CLEAR(value_oplist, v); \ , \ - M_C(name, _push)(b, key); \ + M_F(name, _push)(b, key); \ ) \ - ret = M_C(name, _get)(b, key); \ + ret = M_F(name, _get)(b, key); \ } \ return ret; \ } \ \ static inline int \ - M_C(name, _search_and_remove_in_leaf)(node_t n, key_t const key) \ + M_F(name, _search_and_remove_in_leaf)(node_t n, key_t const key) \ { \ - M_ASSERT(M_C(name, _is_leaf)(n)); \ - const int num = M_C(name, _get_num)(n); \ + M_ASSERT(M_F(name, _is_leaf)(n)); \ + const int num = M_F(name, _get_num)(n); \ for(int i = 0; i < num; i++) { \ const int cmp = M_CALL_CMP(key_oplist, key, n->key[i]); \ if (cmp == 0) { \ @@ -817,21 +817,21 @@ return -1; /* Not found */ \ } \ \ - static inline void M_C(name, _left_shift)(node_t parent, int k) \ + static inline void M_F(name, _left_shift)(node_t parent, int k) \ { \ - M_ASSERT (parent != NULL && !M_C(name, _is_leaf)(parent)); \ - M_ASSERT (0 <= k && k < M_C(name, _get_num)(parent)); \ + M_ASSERT (parent != NULL && !M_F(name, _is_leaf)(parent)); \ + M_ASSERT (0 <= k && k < M_F(name, _get_num)(parent)); \ node_t left = parent->kind.node[k]; \ node_t right = parent->kind.node[k+1]; \ M_ASSERT (left != NULL && right != NULL); \ - int num_left = M_C(name, _get_num)(left); \ - int num_right = M_C(name, _get_num)(right); \ + int num_left = M_F(name, _get_num)(left); \ + int num_right = M_F(name, _get_num)(right); \ M_ASSERT (num_left > N/2); \ M_ASSERT (num_right < N/2); \ \ /* 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); \ - if (M_C(name, _is_leaf)(left)) { \ + if (M_F(name, _is_leaf)(left)) { \ M_IF(isMap)(memmove (&right->kind.value[1], &right->kind.value[0], sizeof(value_t)*(unsigned int)num_right);,) \ memmove (&right->key[0], &left->key[num_left-1], sizeof (key_t)); \ M_IF(isMap)(memmove (&right->kind.value[0], &left->kind.value[num_left-1], sizeof (value_t));,) \ @@ -852,20 +852,20 @@ M_ASSERT (left->num != 0); \ } \ \ - static inline void M_C(name, _right_shift)(node_t parent, int k) \ + static inline void M_F(name, _right_shift)(node_t parent, int k) \ { \ - M_ASSERT (parent != NULL && !M_C(name, _is_leaf)(parent)); \ - M_ASSERT (0 <= k && k < M_C(name, _get_num)(parent)); \ + M_ASSERT (parent != NULL && !M_F(name, _is_leaf)(parent)); \ + M_ASSERT (0 <= k && k < M_F(name, _get_num)(parent)); \ node_t left = parent->kind.node[k]; \ node_t right = parent->kind.node[k+1]; \ M_ASSERT (left != NULL && right != NULL); \ - int num_left = M_C(name, _get_num)(left); \ - int num_right = M_C(name, _get_num)(right); \ + int num_left = M_F(name, _get_num)(left); \ + int num_right = M_F(name, _get_num)(right); \ M_ASSERT (num_left < N/2); \ M_ASSERT (num_right > N/2); \ \ /* Move one item from the right node to the left node. */ \ - if (M_C(name, _is_leaf)(right)) { \ + if (M_F(name, _is_leaf)(right)) { \ memmove (&left->key[num_left], &right->key[0], sizeof(key_t)); \ memmove (&right->key[0], &right->key[1], sizeof(key_t)*(unsigned int)(num_right-1)); \ M_IF(isMap)(memmove (&left->kind.value[num_left], &right->kind.value[0], sizeof (value_t));,) \ @@ -886,16 +886,16 @@ M_ASSERT (left->num != 0); \ } \ \ - static inline void M_C(name, _merge_node)(node_t parent, int k, bool leaf) \ + static inline void M_F(name, _merge_node)(node_t parent, int k, bool leaf) \ { \ - M_ASSERT (parent != NULL && !M_C(name, _is_leaf)(parent)); \ - M_ASSERT (0 <= k && k < M_C(name, _get_num(parent))); \ + M_ASSERT (parent != NULL && !M_F(name, _is_leaf)(parent)); \ + M_ASSERT (0 <= k && k < M_F(name, _get_num(parent))); \ node_t left = parent->kind.node[k]; \ node_t right = parent->kind.node[k+1]; \ M_ASSERT (left != NULL && right != NULL); \ - int num_parent = M_C(name, _get_num)(parent); \ - int num_left = M_C(name, _get_num)(left); \ - int num_right = M_C(name, _get_num)(right); \ + int num_parent = M_F(name, _get_num)(parent); \ + int num_left = M_F(name, _get_num)(left); \ + int num_right = M_F(name, _get_num)(right); \ \ /* Merge node 'k' and 'k+1' into a single one */ \ if (leaf) { \ @@ -922,62 +922,62 @@ /* We can also cache the index when we descend the tree. \ TODO: Bench if this is worth the effort.*/ \ static inline int \ - M_C(name, _search_for_node)(node_t parent, node_t child) \ + M_F(name, _search_for_node)(node_t parent, node_t child) \ { \ - M_ASSERT (!M_C(name, _is_leaf)(parent)); \ + M_ASSERT (!M_F(name, _is_leaf)(parent)); \ int i = 0; \ while (true) { \ - M_ASSERT(i <= M_C(name, _get_num)(parent)); \ + M_ASSERT(i <= M_F(name, _get_num)(parent)); \ if (parent->kind.node[i] == child) \ return i; \ i++; \ } \ } \ \ - static inline bool M_C(name, _erase)(tree_t b, key_t const key) \ + static inline bool M_F(name, _erase)(tree_t b, key_t const key) \ { \ M_BPTR33_CONTRACT(N, isMulti, key_oplist, b); \ pit_t pit; \ - node_t leaf = M_C(name, _search_for_leaf)(pit, b, key); \ - int k = M_C(name, _search_and_remove_in_leaf)(leaf, key); \ + node_t leaf = M_F(name, _search_for_leaf)(pit, b, key); \ + int k = M_F(name, _search_and_remove_in_leaf)(leaf, key); \ /* If key is not found ==> erase failed */ \ if (k < 0) return false; \ /* Remove one item from the B+TREE */ \ b->size --; \ /* If number of keys greater than N>2 or root ==> Nothing more to do */ \ - if (M_LIKELY (M_C(name, _get_num)(leaf) >= N/2) || pit->num == 0) \ + if (M_LIKELY (M_F(name, _get_num)(leaf) >= N/2) || pit->num == 0) \ return true; \ /* Leaf is too small. Needs rebalancing */ \ - M_ASSERT (M_C(name, _get_num)(leaf) == N/2-1); \ + M_ASSERT (M_F(name, _get_num)(leaf) == N/2-1); \ bool pass1 = true; \ while (true) { \ M_ASSERT (pit->num > 0); \ /* Search for node 'leaf' in parent */ \ node_t parent = pit->parent[--pit->num]; \ M_ASSERT (parent != NULL); \ - k = M_C(name, _search_for_node)(parent, leaf); \ + k = M_F(name, _search_for_node)(parent, leaf); \ /* Look for the neighboor of the removed key. */ \ /* if we can steal one key from them to keep our node balanced */ \ - if (k > 0 && M_C(name, _get_num)(parent->kind.node[k-1]) > N/2) { \ - M_C(name, _left_shift)(parent, k-1); \ + if (k > 0 && M_F(name, _get_num)(parent->kind.node[k-1]) > N/2) { \ + M_F(name, _left_shift)(parent, k-1); \ return true; \ - } else if (k < M_C(name, _get_num)(parent) \ - && M_C(name, _get_num)(parent->kind.node[k+1]) > N/2) { \ - M_C(name, _right_shift)(parent, k); \ + } else if (k < M_F(name, _get_num)(parent) \ + && M_F(name, _get_num)(parent->kind.node[k+1]) > N/2) { \ + M_F(name, _right_shift)(parent, k); \ return true; \ } \ /* Merge both nodes, removing 'k' from parent */ \ - if (k == M_C(name, _get_num)(parent)) \ + if (k == M_F(name, _get_num)(parent)) \ k--; \ - M_ASSERT(k >= 0 && k < M_C(name, _get_num)(parent)); \ + M_ASSERT(k >= 0 && k < M_F(name, _get_num)(parent)); \ /* Merge 'k' & 'k+1' & remove 'k' from parent */ \ - M_C(name, _merge_node)(parent, k, pass1); \ + M_F(name, _merge_node)(parent, k, pass1); \ /* Check if we need to continue */ \ - if (M_C(name, _get_num)(parent) >= N/2) \ + if (M_F(name, _get_num)(parent) >= N/2) \ return true; \ if (pit->num == 0) { \ /* We reach the root */ \ - if (M_C(name, _get_num)(parent) == 0) { \ + if (M_F(name, _get_num)(parent) == 0) { \ /* Update root (deleted) */ \ b->root = parent->kind.node[0]; \ M_CALL_DEL(key_oplist, parent); \ @@ -990,58 +990,58 @@ } \ } \ \ - static inline bool M_C(name, _pop_at)(value_t *ptr, tree_t b, key_t const key) \ + static inline bool M_F(name, _pop_at)(value_t *ptr, tree_t b, key_t const key) \ { \ if (ptr != NULL) { \ - value_t *ref = M_C(name, _get)(b, key); \ + value_t *ref = M_F(name, _get)(b, key); \ if (ref == NULL) { \ return false; \ } \ M_CALL_SET(value_oplist, *ptr, *ref); \ } \ - return M_C(name, _erase)(b, key); \ + return M_F(name, _erase)(b, key); \ } \ \ static inline value_t * \ - M_C(name, _min)(const tree_t b) \ + M_F(name, _min)(const tree_t b) \ { \ M_BPTR33_CONTRACT(N, isMulti, key_oplist, b); \ if (M_UNLIKELY (b->size == 0)) return NULL; \ node_t n = b->root; \ /* Scan down the nodes */ \ - while (!M_C(name, _is_leaf)(n)) { \ + while (!M_F(name, _is_leaf)(n)) { \ n = n->kind.node[0]; \ } \ return &n->M_IF(isMap)(kind.value, key)[0]; \ } \ \ static inline value_t * \ - M_C(name, _max)(const tree_t b) \ + M_F(name, _max)(const tree_t b) \ { \ M_BPTR33_CONTRACT(N, isMulti, key_oplist, b); \ if (M_UNLIKELY (b->size == 0)) return NULL; \ node_t n = b->root; \ /* Scan down the nodes */ \ - while (!M_C(name, _is_leaf)(n)) { \ + while (!M_F(name, _is_leaf)(n)) { \ n = n->kind.node[n->num]; \ } \ return &n->M_IF(isMap)(kind.value, key)[-n->num-1]; \ } \ \ static inline value_t const * \ - M_C(name, _cmin)(const tree_t tree) \ + M_F(name, _cmin)(const tree_t tree) \ { \ - return M_CONST_CAST(value_t, M_C(name, _min)(tree)); \ + return M_CONST_CAST(value_t, M_F(name, _min)(tree)); \ } \ \ static inline value_t const * \ - M_C(name, _cmax)(const tree_t tree) \ + M_F(name, _cmax)(const tree_t tree) \ { \ - return M_CONST_CAST(value_t, M_C(name, _max)(tree)); \ + return M_CONST_CAST(value_t, M_F(name, _max)(tree)); \ } \ \ static inline void \ - M_C(name, _init_move)(tree_t b, tree_t ref) \ + M_F(name, _init_move)(tree_t b, tree_t ref) \ { \ M_BPTR33_CONTRACT(N, isMulti, key_oplist, ref); \ M_ASSERT (b != NULL && b != ref); \ @@ -1052,18 +1052,18 @@ } \ \ static inline void \ - M_C(name, _move)(tree_t b, tree_t ref) \ + M_F(name, _move)(tree_t b, tree_t ref) \ { \ M_BPTR33_CONTRACT(N, isMulti, key_oplist, b); \ M_BPTR33_CONTRACT(N, isMulti, key_oplist, ref); \ M_ASSERT (b != ref); \ - M_C(name,_clear)(b); \ - M_C(name,_init_move)(b, ref); \ + M_F(name,_clear)(b); \ + M_F(name,_init_move)(b, ref); \ M_BPTR33_CONTRACT(N, isMulti, key_oplist, b); \ } \ \ static inline void \ - M_C(name, _swap)(tree_t tree1, tree_t tree2) \ + M_F(name, _swap)(tree_t tree1, tree_t tree2) \ { \ M_BPTR33_CONTRACT(N, isMulti, key_oplist, tree1); \ M_BPTR33_CONTRACT(N, isMulti, key_oplist, tree2); \ @@ -1077,13 +1077,13 @@ #define M_BPTR33_DEF_IT(name, N, key_t, key_oplist, value_t, value_oplist, isMap, isMulti, tree_t, node_t, pit_t, it_t, subtype_t) \ \ static inline void \ - M_C(name, _it)(it_t it, const tree_t b) \ + M_F(name, _it)(it_t it, const tree_t b) \ { \ M_BPTR33_CONTRACT(N, isMulti, key_oplist, b); \ M_ASSERT (it != NULL); \ node_t n = b->root; \ /* Scan down the nodes */ \ - while (!M_C(name, _is_leaf)(n)) { \ + while (!M_F(name, _is_leaf)(n)) { \ n = n->kind.node[0]; \ } \ it->node = n; \ @@ -1091,13 +1091,13 @@ } \ \ static inline void \ - M_C(name, _it_end)(it_t it, const tree_t b) \ + M_F(name, _it_end)(it_t it, const tree_t b) \ { \ M_BPTR33_CONTRACT(N, isMulti, key_oplist, b); \ M_ASSERT (it != NULL); \ node_t n = b->root; \ /* Scan down the nodes */ \ - while (!M_C(name, _is_leaf)(n)) { \ + while (!M_F(name, _is_leaf)(n)) { \ n = n->kind.node[n->num]; \ } \ it->node = n; \ @@ -1105,7 +1105,7 @@ } \ \ static inline void \ - M_C(name, _it_set)(it_t itd, const it_t its) \ + M_F(name, _it_set)(it_t itd, const it_t its) \ { \ M_ASSERT (itd != NULL && its != NULL); \ itd->node = its->node; \ @@ -1113,24 +1113,24 @@ } \ \ static inline bool \ - M_C(name, _end_p)(it_t it) \ + M_F(name, _end_p)(it_t it) \ { \ M_ASSERT (it != NULL && it->node != NULL); \ - M_ASSERT (M_C(name, _is_leaf)(it->node)); \ + M_ASSERT (M_F(name, _is_leaf)(it->node)); \ return it->node->next ==NULL && it->idx >= -it->node->num; \ } \ \ static inline bool \ - M_C(name, _it_equal_p)(const it_t it1, const it_t it2) \ + M_F(name, _it_equal_p)(const it_t it1, const it_t it2) \ { \ return it1->node == it2->node && it1->idx == it2->idx; \ } \ \ static inline void \ - M_C(name, _next)(it_t it) \ + M_F(name, _next)(it_t it) \ { \ M_ASSERT (it != NULL && it->node != NULL); \ - M_ASSERT (M_C(name, _is_leaf)(it->node)); \ + M_ASSERT (M_F(name, _is_leaf)(it->node)); \ it->idx ++; \ if (it->idx >= -it->node->num && it->node->next != NULL) { \ it->node = it->node->next; \ @@ -1139,10 +1139,10 @@ } \ \ static inline subtype_t * \ - M_C(name, _ref)(it_t it) \ + M_F(name, _ref)(it_t it) \ { \ M_ASSERT (it != NULL && it->node != NULL); \ - M_ASSERT (M_C(name, _is_leaf)(it->node)); \ + M_ASSERT (M_F(name, _is_leaf)(it->node)); \ M_ASSERT (it->idx <= -it->node->num); \ M_IF(isMap)( \ it->pair.key_ptr = &it->node->key[it->idx]; \ @@ -1154,19 +1154,19 @@ } \ \ static inline subtype_t const * \ - M_C(name, _cref)(it_t it) \ + M_F(name, _cref)(it_t it) \ { \ - return M_CONST_CAST(subtype_t, M_C(name, _ref)(it)); \ + return M_CONST_CAST(subtype_t, M_F(name, _ref)(it)); \ } \ \ \ static inline void \ - M_C(name, _it_from)(it_t it, const tree_t b, key_t const key) \ + M_F(name, _it_from)(it_t it, const tree_t b, key_t const key) \ { \ M_BPTR33_CONTRACT(N, isMulti, key_oplist, b); \ M_ASSERT (it != NULL); \ pit_t pit; \ - node_t n = M_C(name, _search_for_leaf)(pit, b, key); \ + node_t n = M_F(name, _search_for_leaf)(pit, b, key); \ it->node = n; \ int i; \ M_BPTR33_NODE_CONTRACT(N, isMulti, key_oplist, n, b->root); \ @@ -1182,7 +1182,7 @@ } \ \ static inline bool \ - M_C(name, _it_until_p)(it_t it, key_t const key) \ + M_F(name, _it_until_p)(it_t it, key_t const key) \ { \ M_ASSERT (it != NULL); \ node_t n = it->node; \ @@ -1192,7 +1192,7 @@ } \ \ static inline bool \ - M_C(name, _it_while_p)(it_t it, key_t const key) \ + M_F(name, _it_while_p)(it_t it, key_t const key) \ { \ M_ASSERT (it != NULL); \ node_t n = it->node; \ @@ -1206,7 +1206,7 @@ #define M_BPTR33_DEF_EXT(name, N, key_t, key_oplist, value_t, value_oplist, isMap, isMulti, tree_t, node_t, pit_t, it_t, subtype_t) \ \ M_IF_METHOD_BOTH(EQUAL, key_oplist, value_oplist)( \ - static inline bool M_C(name,_equal_p)(const tree_t t1, const tree_t t2) { \ + static inline bool M_F(name,_equal_p)(const tree_t t1, const tree_t t2) { \ M_BPTR33_CONTRACT(N, isMulti, key_oplist, t1); \ M_BPTR33_CONTRACT(N, isMulti, key_oplist, t2); \ if (t1->size != t2->size) return false; \ @@ -1218,12 +1218,12 @@ structuraly different but functionnaly equal (you get this by \ constructing the tree in a different way). We have to \ compare the ordered value within the tree. */ \ - M_C(name, _it)(it1, t1); \ - M_C(name, _it)(it2, t2); \ - while (!M_C(name, _end_p)(it1) \ - && !M_C(name, _end_p)(it2)) { \ - const subtype_t *ref1 = M_C(name, _cref)(it1); \ - const subtype_t *ref2 = M_C(name, _cref)(it2); \ + M_F(name, _it)(it1, t1); \ + M_F(name, _it)(it2, t2); \ + while (!M_F(name, _end_p)(it1) \ + && !M_F(name, _end_p)(it2)) { \ + const subtype_t *ref1 = M_F(name, _cref)(it1); \ + const subtype_t *ref2 = M_F(name, _cref)(it2); \ M_IF(isMap)( \ if (!M_CALL_EQUAL(key_oplist, *ref1->key_ptr, *ref2->key_ptr)) \ return false; \ @@ -1233,38 +1233,38 @@ if (!M_CALL_EQUAL(key_oplist, *ref1, *ref2)) \ return false; \ ) \ - M_C(name, _next)(it1); \ - M_C(name, _next)(it2); \ + M_F(name, _next)(it1); \ + M_F(name, _next)(it2); \ } \ - return M_C(name, _end_p)(it1) \ - && M_C(name, _end_p)(it2); \ + return M_F(name, _end_p)(it1) \ + && M_F(name, _end_p)(it2); \ } \ , /* NO EQUAL METHOD */ ) \ \ M_IF_METHOD_BOTH(HASH, key_oplist, value_oplist)( \ - static inline size_t M_C(name,_hash)(const tree_t t1) { \ + static inline size_t M_F(name,_hash)(const tree_t t1) { \ M_BPTR33_CONTRACT(N, isMulti, key_oplist, t1); \ M_HASH_DECL(hash); \ /* NOTE: We can't compute the hash directly for the same reason \ than for EQUAL operator. */ \ it_t it1; \ - M_C(name, _it)(it1, t1); \ - while (!M_C(name, _end_p)(it1)) { \ - subtype_t const *ref1 = M_C(name, _cref)(it1); \ + M_F(name, _it)(it1, t1); \ + while (!M_F(name, _end_p)(it1)) { \ + subtype_t const *ref1 = M_F(name, _cref)(it1); \ M_IF(isMap)( \ M_HASH_UP(hash, M_CALL_HASH(key_oplist, *ref1->key_ptr)); \ M_HASH_UP(hash, M_CALL_HASH(value_oplist, *ref1->value_ptr)); \ , \ M_HASH_UP(hash, M_CALL_HASH(key_oplist, *ref1)); \ ) \ - M_C(name, _next)(it1); \ + M_F(name, _next)(it1); \ } \ return M_HASH_FINAL (hash); \ } \ , /* NO HASH METHOD */ ) \ \ M_IF_METHOD_BOTH(GET_STR, key_oplist, value_oplist)( \ - static inline void M_C(name, _get_str)(m_string_t str, \ + static inline void M_F(name, _get_str)(m_string_t str, \ const tree_t t1, bool append) { \ M_BPTR33_CONTRACT(N, isMulti, key_oplist, t1); \ M_ASSERT(str != NULL); \ @@ -1272,13 +1272,13 @@ /* NOTE: The print is really naive, and not really efficient */ \ bool commaToPrint = false; \ it_t it; \ - for (M_C(name, _it)(it, t1) ; \ - !M_C(name, _end_p)(it); \ - M_C(name, _next)(it)) { \ + for (M_F(name, _it)(it, t1) ; \ + !M_F(name, _end_p)(it); \ + M_F(name, _next)(it)) { \ if (commaToPrint) \ m_string_push_back (str, M_GET_SEPARATOR key_oplist); \ commaToPrint = true; \ - subtype_t const *ref1 = M_C(name, _cref)(it); \ + subtype_t const *ref1 = M_F(name, _cref)(it); \ M_IF(isMap)( \ M_CALL_GET_STR(key_oplist, str, *ref1->key_ptr, true); \ m_string_cat_cstr(str, ":"); \ @@ -1293,20 +1293,20 @@ \ M_IF_METHOD_BOTH(OUT_STR, key_oplist, value_oplist)( \ static inline void \ - M_C(name, _out_str)(FILE *file, tree_t const t1) \ + M_F(name, _out_str)(FILE *file, tree_t const t1) \ { \ M_BPTR33_CONTRACT(N, isMulti, key_oplist, t1); \ M_ASSERT (file != NULL); \ fputc ('[', file); \ bool commaToPrint = false; \ it_t it; \ - for (M_C(name, _it)(it, t1) ; \ - !M_C(name, _end_p)(it); \ - M_C(name, _next)(it)){ \ + for (M_F(name, _it)(it, t1) ; \ + !M_F(name, _end_p)(it); \ + M_F(name, _next)(it)){ \ if (commaToPrint) \ fputc (M_GET_SEPARATOR key_oplist, file); \ commaToPrint = true; \ - subtype_t const *ref1 = M_C(name, _cref)(it); \ + subtype_t const *ref1 = M_F(name, _cref)(it); \ M_IF(isMap)( \ M_CALL_OUT_STR(key_oplist, file, *ref1->key_ptr); \ fputc (':', file); \ @@ -1321,11 +1321,11 @@ \ M_IF_METHOD_BOTH(PARSE_STR, key_oplist, value_oplist)( \ static inline bool \ - M_C(name, _parse_str)(tree_t t1, const char str[], const char **endp) \ + M_F(name, _parse_str)(tree_t t1, const char str[], const char **endp) \ { \ M_BPTR33_CONTRACT(N, isMulti, key_oplist, t1); \ M_ASSERT (str != NULL); \ - M_C(name,_reset)(t1); \ + M_F(name,_reset)(t1); \ bool success = false; \ int c = *str++; \ if (M_UNLIKELY (c != '[')) goto exit; \ @@ -1346,9 +1346,9 @@ b = M_CALL_PARSE_STR(value_oplist, value, str, &str); \ do { c = *str++; } while (isspace(c)); \ if (b == false || c == 0) goto exit_clear; \ - M_C(name, _set_at)(t1, key, value); \ + M_F(name, _set_at)(t1, key, value); \ , \ - M_C(name, _push)(t1, key); \ + M_F(name, _push)(t1, key); \ ) \ } while (c == M_GET_SEPARATOR key_oplist); \ success = (c == ']'); \ @@ -1363,11 +1363,11 @@ \ M_IF_METHOD_BOTH(IN_STR, key_oplist, value_oplist)( \ static inline bool \ - M_C(name, _in_str)(tree_t t1, FILE *file) \ + M_F(name, _in_str)(tree_t t1, FILE *file) \ { \ M_BPTR33_CONTRACT(N, isMulti, key_oplist, t1); \ M_ASSERT (file != NULL); \ - M_C(name,_reset)(t1); \ + M_F(name,_reset)(t1); \ int c = fgetc(file); \ if (M_UNLIKELY (c != '[')) return false; \ c = fgetc(file); \ @@ -1387,9 +1387,9 @@ b = M_CALL_IN_STR(value_oplist,value, file); \ do { c = fgetc(file); } while (isspace(c)); \ if (b == false || c == EOF) break; \ - M_C(name, _set_at)(t1, key, value) \ + M_F(name, _set_at)(t1, key, value) \ , \ - M_C(name, _push)(t1, key) \ + M_F(name, _push)(t1, key) \ ); \ } while (c == M_GET_SEPARATOR key_oplist); \ M_CALL_CLEAR(key_oplist, key); \ @@ -1401,7 +1401,7 @@ \ M_IF_METHOD_BOTH(OUT_SERIAL, key_oplist, value_oplist)( \ static inline m_serial_return_code_t \ - M_C(name, _out_serial)(m_serial_write_t f, tree_t const t1) \ + M_F(name, _out_serial)(m_serial_write_t f, tree_t const t1) \ { \ M_BPTR33_CONTRACT(N, isMulti, key_oplist, t1); \ M_ASSERT (f != NULL && f->m_interface != NULL); \ @@ -1414,10 +1414,10 @@ & set container */ \ M_IF(isMap)( \ ret = f->m_interface->write_map_start(local, f, t1->size); \ - for (M_C(name, _it)(it, t1) ; \ - !M_C(name, _end_p)(it); \ - M_C(name, _next)(it)){ \ - item = M_C(name, _cref)(it); \ + for (M_F(name, _it)(it, t1) ; \ + !M_F(name, _end_p)(it); \ + M_F(name, _next)(it)){ \ + item = M_F(name, _cref)(it); \ if (first_done) \ ret |= f->m_interface->write_map_next(local, f); \ ret |= M_CALL_OUT_SERIAL(key_oplist, f, *item->key_ptr); \ @@ -1428,10 +1428,10 @@ ret |= f->m_interface->write_map_end(local, f); \ , \ ret = f->m_interface->write_array_start(local, f, t1->size); \ - for (M_C(name, _it)(it, t1) ; \ - !M_C(name, _end_p)(it); \ - M_C(name, _next)(it)){ \ - item = M_C(name, _cref)(it); \ + for (M_F(name, _it)(it, t1) ; \ + !M_F(name, _end_p)(it); \ + M_F(name, _next)(it)){ \ + item = M_F(name, _cref)(it); \ if (first_done) \ ret |= f->m_interface->write_array_next(local, f); \ ret |= M_CALL_OUT_SERIAL(key_oplist, f, *item); \ @@ -1445,7 +1445,7 @@ \ M_IF_METHOD_BOTH(IN_SERIAL, key_oplist, value_oplist)( \ static inline m_serial_return_code_t \ - M_C(name, _in_serial)(tree_t t1, m_serial_read_t f) \ + M_F(name, _in_serial)(tree_t t1, m_serial_read_t f) \ { \ M_BPTR33_CONTRACT(N, isMulti, key_oplist, t1); \ M_ASSERT (f != NULL && f->m_interface != NULL); \ @@ -1453,7 +1453,7 @@ m_serial_return_code_t ret; \ size_t estimated_size = 0; \ key_t key; \ - M_C(name,_reset)(t1); \ + M_F(name,_reset)(t1); \ M_IF(isMap)( \ value_t value; \ ret = f->m_interface->read_map_start(local, f, &estimated_size); \ @@ -1467,7 +1467,7 @@ if (ret != M_SERIAL_OK_CONTINUE) return M_SERIAL_FAIL; \ ret = M_CALL_IN_SERIAL(value_oplist, value, f); \ if (ret != M_SERIAL_OK_DONE) return M_SERIAL_FAIL; \ - M_C(name, _set_at)(t1, key, value); \ + M_F(name, _set_at)(t1, key, value); \ } while ((ret = f->m_interface->read_map_next(local, f)) == M_SERIAL_OK_CONTINUE); \ M_CALL_CLEAR(key_oplist, key); \ M_CALL_CLEAR(value_oplist, value); \ @@ -1478,7 +1478,7 @@ do { \ ret = M_CALL_IN_SERIAL(key_oplist, key, f); \ if (ret != M_SERIAL_OK_DONE) { break; } \ - M_C(name, _push)(t1, key); \ + M_F(name, _push)(t1, key); \ } while ((ret = f->m_interface->read_array_next(local, f)) == M_SERIAL_OK_CONTINUE); \ M_CALL_CLEAR(key_oplist, key); \ ) /* End of IF isMap */ \ diff --git a/m-buffer.h b/m-buffer.h index c1da7a79..8659a7d1 100644 --- a/m-buffer.h +++ b/m-buffer.h @@ -56,7 +56,7 @@ typedef enum { otherwise the size will be a compile time constant. USAGE: BUFFER_DEF(name, type, size_of_buffer_or_0, policy[, oplist]) */ #define M_BUFFER_DEF(name, type, m_size, ... ) \ - M_BUFFER_DEF_AS(name, M_C(name, _t), type, m_size, __VA_ARGS__) + M_BUFFER_DEF_AS(name, M_F(name, _t), type, m_size, __VA_ARGS__) /* Define a lock based buffer @@ -85,7 +85,7 @@ typedef enum { USAGE: QUEUE_MPMC_DEF(name, type, policy, [oplist of type]) */ #define M_QUEUE_MPMC_DEF(name, type, ...) \ - M_QUEUE_MPMC_DEF_AS(name, M_C(name,_t), type, __VA_ARGS__) + M_QUEUE_MPMC_DEF_AS(name, M_F(name,_t), type, __VA_ARGS__) /* Define a nearly lock-free queue for Many Producer Many Consummer @@ -110,7 +110,7 @@ typedef enum { USAGE: QUEUE_SPSC_DEF(name, type, policy, [oplist of type]) */ #define M_QUEUE_SPSC_DEF(name, type, ...) \ - M_QUEUE_SPSC_DEF_AS(name, M_C(name, _t), type, __VA_ARGS__) + M_QUEUE_SPSC_DEF_AS(name, M_F(name, _t), type, __VA_ARGS__) /* Define a wait-free queue for Single Producer Single Consummer @@ -258,19 +258,19 @@ m_buff3r_number_dec(m_buff3r_number_ct n, unsigned int policy) M_BUFF3R_DEF_TYPE(name, type, m_size, policy, oplist, buffer_t) \ M_CHECK_COMPATIBLE_OPLIST(name, 1, type, oplist) \ M_BUFF3R_DEF_CORE(name, type, m_size, policy, oplist, buffer_t) \ - M_EMPLACE_QUEUE_DEF(name, buffer_t, M_C(name, _emplace), oplist, M_EMPLACE_QUEUE_GENE) + M_EMPLACE_QUEUE_DEF(name, buffer_t, M_F(name, _emplace), oplist, M_EMPLACE_QUEUE_GENE) /* Define the type of a buffer */ #define M_BUFF3R_DEF_TYPE(name, type, m_size, policy, oplist, buffer_t) \ \ /* Put each data in a separate cache line to avoid false sharing \ by multiple writing threads. No need to align if there is no thread */ \ - typedef union M_C(name, _el_s) { \ + typedef union M_F(name, _el_s) { \ type x; \ char align[M_BUFF3R_POLICY_P(policy, M_BUFFER_THREAD_UNSAFE) ? 1 : M_ALIGN_FOR_CACHELINE_EXCLUSION]; \ - } M_C(name, _el_ct); \ + } M_F(name, _el_ct); \ \ - typedef struct M_C(name, _s) { \ + typedef struct M_F(name, _s) { \ /* Data for a producer */ \ m_mutex_t mutexPush; /* MUTEX used for pushing elements */ \ size_t idx_prod; /* Index of the production threads */ \ @@ -286,22 +286,22 @@ m_buff3r_number_dec(m_buff3r_number_ct n, unsigned int policy) /* number[1] := [OPTION] Number of elements being deferred in the buffer */ \ m_buff3r_number_ct number[1 + M_BUFF3R_POLICY_P(policy, M_BUFFER_DEFERRED_POP)]; \ /* If fixed size, array of elements, otherwise pointer to element */ \ - M_C(name, _el_ct) M_BUFF3R_IF_CTE_SIZE(m_size)(data[m_size], *data); \ + M_F(name, _el_ct) M_BUFF3R_IF_CTE_SIZE(m_size)(data[m_size], *data); \ } buffer_t[1]; \ \ - typedef struct M_C(name, _s) *M_C(name, _ptr); \ - typedef const struct M_C(name, _s) *M_C(name, _srcptr); \ + typedef struct M_F(name, _s) *M_F(name, _ptr); \ + typedef const struct M_F(name, _s) *M_F(name, _srcptr); \ /* Internal type used to unconst the buffer */ \ - typedef union { M_C(name, _srcptr) cptr; M_C(name, _ptr) ptr; } M_C(name, _uptr_ct); \ + typedef union { M_F(name, _srcptr) cptr; M_F(name, _ptr) ptr; } M_F(name, _uptr_ct); \ /* Internal types used by the oplist */ \ - typedef type M_C(name, _subtype_ct); \ - typedef buffer_t M_C(name, _ct); \ + typedef type M_F(name, _subtype_ct); \ + typedef buffer_t M_F(name, _ct); \ /* Define the core functionnalities of a buffer */ #define M_BUFF3R_DEF_CORE(name, type, m_size, policy, oplist, buffer_t) \ \ static inline void \ -M_C(name, _init)(buffer_t v, size_t size) \ +M_F(name, _init)(buffer_t v, size_t size) \ { \ M_BUFF3R_IF_CTE_SIZE(m_size)(M_ASSERT(size == m_size), v->size = size); \ M_ASSERT(size <= UINT_MAX); \ @@ -319,9 +319,9 @@ M_C(name, _init)(buffer_t v, size_t size) \ } \ \ M_BUFF3R_IF_CTE_SIZE(m_size)( /* Statically allocated */ , \ - v->data = M_CALL_REALLOC(oplist, M_C(name, _el_ct), NULL, M_BUFF3R_SIZE(m_size)); \ + v->data = M_CALL_REALLOC(oplist, M_F(name, _el_ct), NULL, M_BUFF3R_SIZE(m_size)); \ if (M_UNLIKELY_NOMEM (v->data == NULL)) { \ - M_MEMORY_FULL (M_BUFF3R_SIZE(m_size)*sizeof(M_C(name, _el_ct))); \ + M_MEMORY_FULL (M_BUFF3R_SIZE(m_size)*sizeof(M_F(name, _el_ct))); \ return; \ } \ ) \ @@ -337,7 +337,7 @@ M_C(name, _init)(buffer_t v, size_t size) \ static inline void \ M_C3(m_buff3r_,name,_init)(buffer_t v) \ { \ - M_C(name, _init)(v, m_size); \ + M_F(name, _init)(v, m_size); \ } \ , ) \ \ @@ -366,7 +366,7 @@ M_C(name, _init)(buffer_t v, size_t size) \ } \ \ static inline void \ - M_C(name, _clear)(buffer_t v) \ + M_F(name, _clear)(buffer_t v) \ { \ M_BUFF3R_CONTRACT(v,m_size); \ M_C3(m_buff3r_,name,_clear_obj)(v); \ @@ -384,7 +384,7 @@ M_C(name, _init)(buffer_t v, size_t size) \ } \ \ static inline void \ - M_C(name, _reset)(buffer_t v) \ + M_F(name, _reset)(buffer_t v) \ { \ M_BUFF3R_CONTRACT(v,m_size); \ if (!M_BUFF3R_POLICY_P((policy), M_BUFFER_THREAD_UNSAFE)) { \ @@ -407,21 +407,21 @@ M_C(name, _init)(buffer_t v, size_t size) \ } \ \ static inline void M_ATTR_DEPRECATED \ - M_C(name, _clean)(buffer_t v) \ + M_F(name, _clean)(buffer_t v) \ { \ - M_C(name,_reset)(v); \ + M_F(name,_reset)(v); \ } \ \ static inline void \ - M_C(name, _init_set)(buffer_t dest, const buffer_t src) \ + M_F(name, _init_set)(buffer_t dest, const buffer_t src) \ { \ /* unconst 'src', so that we can lock it (semantically it is const) */ \ - M_C(name, _uptr_ct) vu; \ + M_F(name, _uptr_ct) vu; \ vu.cptr = src; \ - M_C(name, _ptr) v = vu.ptr; \ + M_F(name, _ptr) v = vu.ptr; \ M_ASSERT (dest != v); \ M_BUFF3R_CONTRACT(v,m_size); \ - M_C(name, _init)(dest, M_BUFF3R_SIZE(m_size)); \ + M_F(name, _init)(dest, M_BUFF3R_SIZE(m_size)); \ if (!M_BUFF3R_POLICY_P((policy), M_BUFFER_THREAD_UNSAFE)) { \ m_mutex_lock(v->mutexPush); \ m_mutex_lock(v->mutexPop); \ @@ -457,12 +457,12 @@ M_C(name, _init)(buffer_t v, size_t size) \ } \ \ static inline void \ - M_C(name, _set)(buffer_t dest, const buffer_t src) \ + M_F(name, _set)(buffer_t dest, const buffer_t src) \ { \ /* unconst 'src', so that we can lock it (semantically it is const) */ \ - M_C(name, _uptr_ct) vu; \ + M_F(name, _uptr_ct) vu; \ vu.cptr = src; \ - M_C(name, _ptr) v = vu.ptr; \ + M_F(name, _ptr) v = vu.ptr; \ M_BUFF3R_CONTRACT(dest,m_size); \ M_BUFF3R_CONTRACT(v,m_size); \ \ @@ -527,7 +527,7 @@ M_C(name, _init)(buffer_t v, size_t size) \ } \ \ static inline bool \ - M_C(name, _empty_p)(buffer_t v) \ + M_F(name, _empty_p)(buffer_t v) \ { \ M_BUFF3R_CONTRACT(v,m_size); \ /* If the buffer has been configured with deferred pop \ @@ -541,7 +541,7 @@ M_C(name, _init)(buffer_t v, size_t size) \ } \ \ static inline bool \ - M_C(name, _full_p)(buffer_t v) \ + M_F(name, _full_p)(buffer_t v) \ { \ M_BUFF3R_CONTRACT(v,m_size); \ return m_buff3r_number_load (v->number[0], policy) \ @@ -549,14 +549,14 @@ M_C(name, _init)(buffer_t v, size_t size) \ } \ \ static inline size_t \ - M_C(name, _size)(buffer_t v) \ + M_F(name, _size)(buffer_t v) \ { \ M_BUFF3R_CONTRACT(v,m_size); \ return m_buff3r_number_load (v->number[0], policy); \ } \ \ static inline bool \ - M_C(name, _push_blocking)(buffer_t v, type const data, bool blocking) \ + M_F(name, _push_blocking)(buffer_t v, type const data, bool blocking) \ { \ M_BUFF3R_CONTRACT(v,m_size); \ \ @@ -564,7 +564,7 @@ M_C(name, _init)(buffer_t v, size_t size) \ if (!M_BUFF3R_POLICY_P((policy), M_BUFFER_THREAD_UNSAFE)) { \ m_mutex_lock(v->mutexPush); \ while (!M_BUFF3R_POLICY_P((policy), M_BUFFER_PUSH_OVERWRITE) \ - && M_C(name, _full_p)(v)) { \ + && M_F(name, _full_p)(v)) { \ if (!blocking) { \ m_mutex_unlock(v->mutexPush); \ return false; \ @@ -572,14 +572,14 @@ M_C(name, _init)(buffer_t v, size_t size) \ m_cond_wait(v->there_is_room_for_data, v->mutexPush); \ } \ } else if (!M_BUFF3R_POLICY_P((policy), M_BUFFER_PUSH_OVERWRITE) \ - && M_C(name, _full_p)(v)) \ + && M_F(name, _full_p)(v)) \ return false; \ M_BUFF3R_PROTECTED_CONTRACT(policy, v, m_size); \ \ size_t previousSize, idx = v->idx_prod; \ /* INDEX computation if we have to overwrite the last element */ \ if (M_UNLIKELY (M_BUFF3R_POLICY_P((policy), M_BUFFER_PUSH_OVERWRITE) \ - && M_C(name, _full_p)(v))) { \ + && M_F(name, _full_p)(v))) { \ v->overwrite++; \ /* Let's overwrite the last element */ \ /* Compute the index of the last push element */ \ @@ -636,7 +636,7 @@ M_C(name, _init)(buffer_t v, size_t size) \ } \ \ static inline bool \ - M_C(name, _pop_blocking)(type *data, buffer_t v, bool blocking) \ + M_F(name, _pop_blocking)(type *data, buffer_t v, bool blocking) \ { \ M_BUFF3R_CONTRACT(v,m_size); \ M_ASSERT (data != NULL); \ @@ -644,14 +644,14 @@ M_C(name, _init)(buffer_t v, size_t size) \ /* Consummer lock (mutex lock performs an acquire memory barrier) */ \ if (!M_BUFF3R_POLICY_P((policy), M_BUFFER_THREAD_UNSAFE)) { \ m_mutex_lock(v->mutexPop); \ - while (M_C(name, _empty_p)(v)) { \ + while (M_F(name, _empty_p)(v)) { \ if (!blocking) { \ m_mutex_unlock(v->mutexPop); \ return false; \ } \ m_cond_wait(v->there_is_data, v->mutexPop); \ } \ - } else if (M_C(name, _empty_p)(v)) \ + } else if (M_F(name, _empty_p)(v)) \ return false; \ M_BUFF3R_PROTECTED_CONTRACT(policy, v, m_size); \ \ @@ -707,34 +707,34 @@ M_C(name, _init)(buffer_t v, size_t size) \ \ \ static inline bool \ - M_C(name, _push)(buffer_t v, type const data) \ + M_F(name, _push)(buffer_t v, type const data) \ { \ - return M_C(name, _push_blocking)(v, data, \ + return M_F(name, _push_blocking)(v, data, \ !M_BUFF3R_POLICY_P((policy), M_BUFFER_UNBLOCKING_PUSH)); \ } \ \ static inline bool \ - M_C(name, _pop)(type *data, buffer_t v) \ + M_F(name, _pop)(type *data, buffer_t v) \ { \ - return M_C(name, _pop_blocking)(data, v, \ + return M_F(name, _pop_blocking)(data, v, \ !M_BUFF3R_POLICY_P((policy), M_BUFFER_UNBLOCKING_POP)); \ } \ \ static inline size_t \ - M_C(name, _overwrite)(const buffer_t v) \ + M_F(name, _overwrite)(const buffer_t v) \ { \ return v->overwrite; \ } \ \ static inline size_t \ - M_C(name, _capacity)(const buffer_t v) \ + M_F(name, _capacity)(const buffer_t v) \ { \ (void) v; /* may be unused */ \ return M_BUFF3R_SIZE(m_size); \ } \ \ static inline void \ - M_C(name, _pop_release)(buffer_t v) \ + M_F(name, _pop_release)(buffer_t v) \ { \ /* Decrement the effective number of elements in the buffer */ \ if (M_BUFF3R_POLICY_P((policy), M_BUFFER_DEFERRED_POP)) { \ @@ -798,7 +798,7 @@ M_C(name, _init)(buffer_t v, size_t size) \ M_QU3UE_MPMC_DEF_TYPE(name, type, policy, oplist, buffer_t) \ M_CHECK_COMPATIBLE_OPLIST(name, 1, type, oplist) \ M_QU3UE_MPMC_DEF_CORE(name, type, policy, oplist, buffer_t) \ - M_EMPLACE_QUEUE_DEF(name, buffer_t, M_C(name, _emplace), oplist, M_EMPLACE_QUEUE_GENE) + M_EMPLACE_QUEUE_DEF(name, buffer_t, M_F(name, _emplace), oplist, M_EMPLACE_QUEUE_GENE) /* Define the type of a MPMC queue */ #define M_QU3UE_MPMC_DEF_TYPE(name, type, policy, oplist, buffer_t) \ @@ -811,30 +811,30 @@ M_C(name, _init)(buffer_t v, size_t size) \ Each element is put in a separate cache line to avoid false \ sharing by multiple writing threads. \ */ \ - typedef struct M_C(name, _el_s) { \ + typedef struct M_F(name, _el_s) { \ atomic_uint seq; /* Can only increase until wrapping */ \ type x; \ M_CACHELINE_ALIGN(align, atomic_uint, type); \ - } M_C(name, _el_ct); \ + } M_F(name, _el_ct); \ \ /* If there is only one producer and one consummer, then they won't \ typically use the same cache line, increasing performance. */ \ - typedef struct M_C(name, _s) { \ + typedef struct M_F(name, _s) { \ atomic_uint ProdIdx; /* Can only increase until wrapping */ \ M_CACHELINE_ALIGN(align1, atomic_uint); \ atomic_uint ConsoIdx; /* Can only increase until wrapping */ \ M_CACHELINE_ALIGN(align2, atomic_uint); \ - M_C(name, _el_ct) *Tab; \ + M_F(name, _el_ct) *Tab; \ unsigned int size; \ } buffer_t[1]; \ \ - typedef type M_C(name, _subtype_ct); \ - typedef buffer_t M_C(name, _ct); \ + typedef type M_F(name, _subtype_ct); \ + typedef buffer_t M_F(name, _ct); \ /* Define the core functionnalities of a MPMC queue */ #define M_QU3UE_MPMC_DEF_CORE(name, type, policy, oplist, buffer_t) \ static inline bool \ - M_C(name, _push)(buffer_t table, type const x) \ + M_F(name, _push)(buffer_t table, type const x) \ { \ M_QU3UE_MPMC_CONTRACT(table); \ unsigned int idx = atomic_load_explicit(&table->ProdIdx, \ @@ -868,7 +868,7 @@ M_C(name, _init)(buffer_t v, size_t size) \ } \ \ static inline bool \ - M_C(name, _pop)(type *ptr, buffer_t table) \ + M_F(name, _pop)(type *ptr, buffer_t table) \ { \ M_QU3UE_MPMC_CONTRACT(table); \ M_ASSERT (ptr != NULL); \ @@ -897,7 +897,7 @@ M_C(name, _init)(buffer_t v, size_t size) \ } \ \ static inline void \ - M_C(name, _init)(buffer_t buffer, size_t size) \ + M_F(name, _init)(buffer_t buffer, size_t size) \ { \ M_ASSERT (buffer != NULL); \ M_ASSERT( M_POWEROF2_P(size)); \ @@ -906,9 +906,9 @@ M_C(name, _init)(buffer_t v, size_t size) \ atomic_init(&buffer->ProdIdx, (unsigned int) size); \ atomic_init(&buffer->ConsoIdx, (unsigned int) size); \ buffer->size = (unsigned int) size; \ - buffer->Tab = M_CALL_REALLOC(oplist, M_C(name, _el_ct), NULL, size); \ + buffer->Tab = M_CALL_REALLOC(oplist, M_F(name, _el_ct), NULL, size); \ if (M_UNLIKELY_NOMEM (buffer->Tab == NULL)) { \ - M_MEMORY_FULL (size*sizeof(M_C(name, _el_ct) )); \ + M_MEMORY_FULL (size*sizeof(M_F(name, _el_ct) )); \ return; \ } \ for(unsigned int j = 0; j < (unsigned int) size; j++) { \ @@ -921,7 +921,7 @@ M_C(name, _init)(buffer_t v, size_t size) \ } \ \ static inline void \ - M_C(name, _clear)(buffer_t buffer) \ + M_F(name, _clear)(buffer_t buffer) \ { \ M_QU3UE_MPMC_CONTRACT(buffer); \ if (!M_BUFF3R_POLICY_P((policy), M_BUFFER_PUSH_INIT_POP_MOVE)) { \ @@ -946,7 +946,7 @@ M_C(name, _init)(buffer_t v, size_t size) \ } \ \ static inline size_t \ - M_C(name, _size)(buffer_t table) \ + M_F(name, _size)(buffer_t table) \ { \ M_QU3UE_MPMC_CONTRACT(table); \ const unsigned int iC = atomic_load_explicit(&table->ConsoIdx, memory_order_relaxed); \ @@ -965,22 +965,22 @@ M_C(name, _init)(buffer_t v, size_t size) \ } \ \ static inline size_t \ - M_C(name, _capacity)(buffer_t v) \ + M_F(name, _capacity)(buffer_t v) \ { \ M_QU3UE_MPMC_CONTRACT(v); \ return v->size; \ } \ \ static inline bool \ - M_C(name, _empty_p)(buffer_t v) \ + M_F(name, _empty_p)(buffer_t v) \ { \ - return M_C(name, _size) (v) == 0; \ + return M_F(name, _size) (v) == 0; \ } \ \ static inline bool \ - M_C(name, _full_p)(buffer_t v) \ + M_F(name, _full_p)(buffer_t v) \ { \ - return M_C(name, _size)(v) >= v->size; \ + return M_F(name, _size)(v) >= v->size; \ } \ @@ -1033,7 +1033,7 @@ M_C(name, _init)(buffer_t v, size_t size) \ M_QU3UE_SPSC_DEF_TYPE(name, type, policy, oplist, buffer_t) \ M_CHECK_COMPATIBLE_OPLIST(name, 1, type, oplist) \ M_QU3UE_SPSC_DEF_CORE(name, type, policy, oplist, buffer_t) \ - M_EMPLACE_QUEUE_DEF(name, buffer_t, M_C(name, _emplace), oplist, M_EMPLACE_QUEUE_GENE) + M_EMPLACE_QUEUE_DEF(name, buffer_t, M_F(name, _emplace), oplist, M_EMPLACE_QUEUE_GENE) /* Define the type of a SPSC queue */ #define M_QU3UE_SPSC_DEF_TYPE(name, type, policy, oplist, buffer_t) \ @@ -1042,26 +1042,26 @@ M_C(name, _init)(buffer_t v, size_t size) \ So, only one thread will write in this table. The other thread \ will only read. As such, there is no concurrent write, and no \ need to align the structure for best performance. */ \ - typedef struct M_C(name, _el_s) { \ + typedef struct M_F(name, _el_s) { \ type x; \ - } M_C(name, _el_ct); \ + } M_F(name, _el_ct); \ \ - typedef struct M_C(name, _s) { \ + typedef struct M_F(name, _s) { \ atomic_uint consoIdx; /* Can only increase until overflow */ \ unsigned int size; \ - M_C(name, _el_ct) *Tab; \ - M_CACHELINE_ALIGN(align, atomic_uint, size_t, M_C(name, _el_ct) *); \ + M_F(name, _el_ct) *Tab; \ + M_CACHELINE_ALIGN(align, atomic_uint, size_t, M_F(name, _el_ct) *); \ atomic_uint prodIdx; /* Can only increase until overflow */ \ } buffer_t[1]; \ \ - typedef type M_C(name, _subtype_ct); \ - typedef buffer_t M_C(name, _ct); \ + typedef type M_F(name, _subtype_ct); \ + typedef buffer_t M_F(name, _ct); \ /* Define the core functionnalities of a SPSC queue */ #define M_QU3UE_SPSC_DEF_CORE(name, type, policy, oplist, buffer_t) \ \ static inline bool \ - M_C(name, _push)(buffer_t table, type const x) \ + M_F(name, _push)(buffer_t table, type const x) \ { \ M_QU3UE_SPSC_CONTRACT(table); \ unsigned int r = atomic_load_explicit(&table->consoIdx, \ @@ -1082,7 +1082,7 @@ M_C(name, _init)(buffer_t v, size_t size) \ } \ \ static inline bool \ - M_C(name, _push_move)(buffer_t table, type *x) \ + M_F(name, _push_move)(buffer_t table, type *x) \ { \ M_QU3UE_SPSC_CONTRACT(table); \ unsigned int r = atomic_load_explicit(&table->consoIdx, \ @@ -1103,7 +1103,7 @@ M_C(name, _init)(buffer_t v, size_t size) \ } \ \ static inline bool \ - M_C(name, _pop)(type *ptr, buffer_t table) \ + M_F(name, _pop)(type *ptr, buffer_t table) \ { \ M_QU3UE_SPSC_CONTRACT(table); \ M_ASSERT (ptr != NULL); \ @@ -1125,7 +1125,7 @@ M_C(name, _init)(buffer_t v, size_t size) \ } \ \ static inline unsigned \ - M_C(name, _push_bulk)(buffer_t table, unsigned n, type const x[]) \ + M_F(name, _push_bulk)(buffer_t table, unsigned n, type const x[]) \ { \ M_QU3UE_SPSC_CONTRACT(table); \ M_ASSERT (x != NULL); \ @@ -1151,7 +1151,7 @@ M_C(name, _init)(buffer_t v, size_t size) \ } \ \ static inline unsigned \ - M_C(name, _pop_bulk)(unsigned int n, type ptr[], buffer_t table) \ + M_F(name, _pop_bulk)(unsigned int n, type ptr[], buffer_t table) \ { \ M_QU3UE_SPSC_CONTRACT(table); \ M_ASSERT (ptr != NULL); \ @@ -1177,7 +1177,7 @@ M_C(name, _init)(buffer_t v, size_t size) \ } \ \ static inline void \ - M_C(name, _push_force)(buffer_t table, type const x) \ + M_F(name, _push_force)(buffer_t table, type const x) \ { \ M_QU3UE_SPSC_CONTRACT(table); \ unsigned int r = atomic_load_explicit(&table->consoIdx, \ @@ -1200,7 +1200,7 @@ M_C(name, _init)(buffer_t v, size_t size) \ } \ \ static inline size_t \ - M_C(name, _size)(buffer_t table) \ + M_F(name, _size)(buffer_t table) \ { \ M_QU3UE_SPSC_CONTRACT(table); \ unsigned int r = atomic_load_explicit(&table->consoIdx, \ @@ -1221,25 +1221,25 @@ M_C(name, _init)(buffer_t v, size_t size) \ } \ \ static inline size_t \ - M_C(name, _capacity)(buffer_t v) \ + M_F(name, _capacity)(buffer_t v) \ { \ return v->size; \ } \ \ static inline bool \ - M_C(name, _empty_p)(buffer_t v) \ + M_F(name, _empty_p)(buffer_t v) \ { \ - return M_C(name, _size) (v) == 0; \ + return M_F(name, _size) (v) == 0; \ } \ \ static inline bool \ - M_C(name, _full_p)(buffer_t v) \ + M_F(name, _full_p)(buffer_t v) \ { \ - return M_C(name, _size)(v) >= v->size; \ + return M_F(name, _size)(v) >= v->size; \ } \ \ static inline void \ - M_C(name, _init)(buffer_t buffer, size_t size) \ + M_F(name, _init)(buffer_t buffer, size_t size) \ { \ M_ASSERT (buffer != NULL); \ M_ASSERT( M_POWEROF2_P(size)); \ @@ -1248,9 +1248,9 @@ M_C(name, _init)(buffer_t v, size_t size) \ atomic_init(&buffer->prodIdx, (unsigned int) size); \ atomic_init(&buffer->consoIdx, (unsigned int) size); \ buffer->size = (unsigned int) size; \ - buffer->Tab = M_CALL_REALLOC(oplist, M_C(name, _el_ct), NULL, size); \ + buffer->Tab = M_CALL_REALLOC(oplist, M_F(name, _el_ct), NULL, size); \ if (M_UNLIKELY_NOMEM (buffer->Tab == NULL)) { \ - M_MEMORY_FULL (size*sizeof(M_C(name, _el_ct) )); \ + M_MEMORY_FULL (size*sizeof(M_F(name, _el_ct) )); \ return; \ } \ if (!M_BUFF3R_POLICY_P((policy), M_BUFFER_PUSH_INIT_POP_MOVE)) { \ @@ -1262,7 +1262,7 @@ M_C(name, _init)(buffer_t v, size_t size) \ } \ \ static inline void \ - M_C(name, _clear)(buffer_t buffer) \ + M_F(name, _clear)(buffer_t buffer) \ { \ M_QU3UE_SPSC_CONTRACT(buffer); \ if (!M_BUFF3R_POLICY_P((policy), M_BUFFER_PUSH_INIT_POP_MOVE)) { \ @@ -1304,18 +1304,18 @@ M_C(name, _init)(buffer_t v, size_t size) \ /* OPLIST definition of a buffer */ #define M_BUFF3R_OPLIST_P3(name, oplist) \ (INIT(M_C3(m_buff3r_,name, _init)) \ - ,INIT_SET(M_C(name, _init_set)) \ - ,SET(M_C(name, _set)) \ - ,CLEAR(M_C(name, _clear)) \ + ,INIT_SET(M_F(name, _init_set)) \ + ,SET(M_F(name, _set)) \ + ,CLEAR(M_F(name, _clear)) \ ,NAME(name) \ - ,TYPE(M_C(name,_ct)) \ - ,SUBTYPE(M_C(name, _subtype_ct)) \ - ,RESET(M_C(name,_reset)) \ - ,PUSH(M_C(name,_push)) \ - ,POP(M_C(name,_pop)) \ + ,TYPE(M_F(name,_ct)) \ + ,SUBTYPE(M_F(name, _subtype_ct)) \ + ,RESET(M_F(name,_reset)) \ + ,PUSH(M_F(name,_push)) \ + ,POP(M_F(name,_pop)) \ ,OPLIST(oplist) \ - ,EMPTY_P(M_C(name, _empty_p)), \ - ,GET_SIZE(M_C(name, _size)) \ + ,EMPTY_P(M_F(name, _empty_p)), \ + ,GET_SIZE(M_F(name, _size)) \ ) diff --git a/m-c-mempool.h b/m-c-mempool.h index 18de66f7..c926b243 100644 --- a/m-c-mempool.h +++ b/m-c-mempool.h @@ -46,55 +46,55 @@ M_BEGIN_PROTECTED_CODE /* Classic internal Singly List without allocation */ #define M_CMEMP00L_DEF_SINGLY_LIST(name, type_t) \ \ - typedef struct M_C(name, _slist_node_s) { \ - struct M_C(name, _slist_node_s) *next; \ + typedef struct M_F(name, _slist_node_s) { \ + struct M_F(name, _slist_node_s) *next; \ type_t data; \ - } M_C(name, _slist_node_ct); \ + } M_F(name, _slist_node_ct); \ \ - typedef struct M_C(name, _slist_node_s) *M_C(name, _slist_ct)[1]; \ + typedef struct M_F(name, _slist_node_s) *M_F(name, _slist_ct)[1]; \ \ static inline void \ - M_C(name, _slist_init)(M_C(name, _slist_ct) list) \ + M_F(name, _slist_init)(M_F(name, _slist_ct) list) \ { \ *list = NULL; \ } \ \ static inline void \ - M_C(name, _slist_push)(M_C(name, _slist_ct) list, \ - M_C(name, _slist_node_ct) *node) \ + M_F(name, _slist_push)(M_F(name, _slist_ct) list, \ + M_F(name, _slist_node_ct) *node) \ { \ node->next = *list; \ *list = node; \ } \ \ - static inline M_C(name, _slist_node_ct) * \ - M_C(name, _slist_pop)(M_C(name, _slist_ct) list) \ + static inline M_F(name, _slist_node_ct) * \ + M_F(name, _slist_pop)(M_F(name, _slist_ct) list) \ { \ M_ASSERT (*list != NULL); \ - M_C(name, _slist_node_ct) *node = *list; \ + M_F(name, _slist_node_ct) *node = *list; \ *list = node->next; \ M_IF_DEBUG(node->next = NULL;) \ return node; \ } \ \ static inline bool \ - M_C(name, _slist_empty_p)(M_C(name, _slist_ct) list) \ + M_F(name, _slist_empty_p)(M_F(name, _slist_ct) list) \ { \ return *list == NULL; \ } \ \ static inline void \ - M_C(name, _slist_move)(M_C(name, _slist_ct) list, \ - M_C(name, _slist_ct) src) \ + M_F(name, _slist_move)(M_F(name, _slist_ct) list, \ + M_F(name, _slist_ct) src) \ { \ *list = *src; \ *src = NULL; \ } \ \ static inline void \ - M_C(name, _slist_clear)(M_C(name, _slist_ct) list) \ + M_F(name, _slist_clear)(M_F(name, _slist_ct) list) \ { \ - M_C(name, _slist_node_ct) *it = *list, *next; \ + M_F(name, _slist_node_ct) *it = *list, *next; \ while (it) { \ next = it->next; \ M_MEMORY_DEL(it); \ @@ -125,23 +125,23 @@ M_BEGIN_PROTECTED_CODE to reduce memory consumption too (non compatible with C++ ...) */ #define M_CMEMP00L_DEF_LF_QUEUE(name, type_t) \ \ - typedef struct M_C(name, _lf_node_s) { \ - M_ATTR_EXTENSION _Atomic(struct M_C(name, _lf_node_s) *) next; \ + typedef struct M_F(name, _lf_node_s) { \ + M_ATTR_EXTENSION _Atomic(struct M_F(name, _lf_node_s) *) next; \ m_gc_atomic_ticket_ct cpt; \ - M_C(name, _slist_ct) list; \ - } M_C(name, _lf_node_t); \ + M_F(name, _slist_ct) list; \ + } M_F(name, _lf_node_t); \ \ - typedef struct M_C(name, _lflist_s) { \ - M_ATTR_EXTENSION _Atomic(M_C(name, _lf_node_t) *) head; \ + typedef struct M_F(name, _lflist_s) { \ + M_ATTR_EXTENSION _Atomic(M_F(name, _lf_node_t) *) head; \ char align1[M_ALIGN_FOR_CACHELINE_EXCLUSION]; \ - M_ATTR_EXTENSION _Atomic(M_C(name, _lf_node_t) *) tail; \ + M_ATTR_EXTENSION _Atomic(M_F(name, _lf_node_t) *) tail; \ char align2[M_ALIGN_FOR_CACHELINE_EXCLUSION]; \ - M_C(name, _lf_node_t) nil; \ - } M_C(name, _lflist_ct)[1]; \ + M_F(name, _lf_node_t) nil; \ + } M_F(name, _lflist_ct)[1]; \ \ static inline void \ - M_C(name, _lflist_init)(M_C(name, _lflist_ct) list, \ - M_C(name, _lf_node_t) *node) \ + M_F(name, _lflist_init)(M_F(name, _lflist_ct) list, \ + M_F(name, _lf_node_t) *node) \ { \ atomic_init(&list->head, node); \ atomic_init(&list->tail, node); \ @@ -149,17 +149,17 @@ M_BEGIN_PROTECTED_CODE } \ \ static inline bool \ - M_C(name, _lflist_empty_p)(M_C(name, _lflist_ct) list) \ + M_F(name, _lflist_empty_p)(M_F(name, _lflist_ct) list) \ { \ return atomic_load(&list->tail) == atomic_load(&list->head); \ } \ \ static inline void \ - M_C(name, _lflist_push)(M_C(name, _lflist_ct) list, \ - M_C(name, _lf_node_t) *node, m_core_backoff_ct bkoff) \ + M_F(name, _lflist_push)(M_F(name, _lflist_ct) list, \ + M_F(name, _lf_node_t) *node, m_core_backoff_ct bkoff) \ { \ - M_C(name, _lf_node_t) *tail; \ - M_C(name, _lf_node_t) *next; \ + M_F(name, _lf_node_t) *tail; \ + M_F(name, _lf_node_t) *next; \ \ atomic_store_explicit(&node->next, &list->nil, memory_order_relaxed); \ m_core_backoff_reset(bkoff); \ @@ -190,12 +190,12 @@ M_BEGIN_PROTECTED_CODE memory_order_relaxed); \ } \ \ - static inline M_C(name, _lf_node_t) * \ - M_C(name, _lflist_pop)(M_C(name, _lflist_ct) list, m_core_backoff_ct bkoff) \ + static inline M_F(name, _lf_node_t) * \ + M_F(name, _lflist_pop)(M_F(name, _lflist_ct) list, m_core_backoff_ct bkoff) \ { \ - M_C(name, _lf_node_t) *head; \ - M_C(name, _lf_node_t) *tail; \ - M_C(name, _lf_node_t) *next; \ + M_F(name, _lf_node_t) *head; \ + M_F(name, _lf_node_t) *tail; \ + M_F(name, _lf_node_t) *next; \ \ /* Reinitialize backoff */ \ m_core_backoff_reset(bkoff); \ @@ -236,18 +236,18 @@ M_BEGIN_PROTECTED_CODE provided that the node we return is older than the one we should return, \ Therefore, we return the previous dummy head. \ As such, it is not the original MSqueue algorithm. */ \ - M_IF_DEBUG(atomic_store(&head->next, (M_C(name, _lf_node_t) *) 0);) \ + M_IF_DEBUG(atomic_store(&head->next, (M_F(name, _lf_node_t) *) 0);) \ return head; \ } \ \ /* Dequeue a node if the node is old enough */ \ - static inline M_C(name, _lf_node_t) * \ - M_C(name, _lflist_pop_if)(M_C(name, _lflist_ct) list, \ + static inline M_F(name, _lf_node_t) * \ + M_F(name, _lflist_pop_if)(M_F(name, _lflist_ct) list, \ m_gc_ticket_ct age, m_core_backoff_ct bkoff) \ { \ - M_C(name, _lf_node_t) *head; \ - M_C(name, _lf_node_t) *tail; \ - M_C(name, _lf_node_t) *next; \ + M_F(name, _lf_node_t) *head; \ + M_F(name, _lf_node_t) *tail; \ + M_F(name, _lf_node_t) *next; \ \ m_core_backoff_reset(bkoff); \ while (true) { \ @@ -277,28 +277,28 @@ M_BEGIN_PROTECTED_CODE } \ } \ } \ - M_IF_DEBUG(atomic_store(&head->next, (M_C(name, _lf_node_t) *) 0);) \ + M_IF_DEBUG(atomic_store(&head->next, (M_F(name, _lf_node_t) *) 0);) \ return head; \ } \ \ static inline void \ - M_C(name, _lflist_clear)(M_C(name, _lflist_ct) list) \ + M_F(name, _lflist_clear)(M_F(name, _lflist_ct) list) \ { \ m_core_backoff_ct bkoff; \ m_core_backoff_init(bkoff); \ while (true) { \ - M_C(name, _lf_node_t) *node = M_C(name, _lflist_pop)(list, bkoff); \ + M_F(name, _lf_node_t) *node = M_F(name, _lflist_pop)(list, bkoff); \ if (node == NULL) break; \ - M_C(name, _lf_node_t) *next = atomic_load_explicit(&node->next, \ + M_F(name, _lf_node_t) *next = atomic_load_explicit(&node->next, \ memory_order_relaxed); \ - M_C(name, _slist_clear)(node->list); \ + M_F(name, _slist_clear)(node->list); \ M_MEMORY_DEL(node); \ node = next; \ } \ /* Dummy node to free too */ \ - M_C(name, _lf_node_t) *dummy; \ + M_F(name, _lf_node_t) *dummy; \ dummy = atomic_load_explicit(&list->head, memory_order_relaxed); \ - M_C(name, _slist_clear)(dummy->list); \ + M_F(name, _slist_clear)(dummy->list); \ M_MEMORY_DEL(dummy); \ } \ @@ -306,26 +306,26 @@ M_BEGIN_PROTECTED_CODE As such it is a non Lock-Free path. */ #define M_CMEMP00L_DEF_SYSTEM_ALLOC(name, type_t) \ \ - static inline M_C(name, _lf_node_t) * \ - M_C(name, _alloc_node)(unsigned int initial) \ + static inline M_F(name, _lf_node_t) * \ + M_F(name, _alloc_node)(unsigned int initial) \ { \ - M_C(name, _lf_node_t) * node; \ - node = M_MEMORY_ALLOC(M_C(name, _lf_node_t)); \ + M_F(name, _lf_node_t) * node; \ + node = M_MEMORY_ALLOC(M_F(name, _lf_node_t)); \ if (M_UNLIKELY_NOMEM (node == NULL)) { \ - M_MEMORY_FULL(sizeof(M_C(name, _lf_node_t))); \ + M_MEMORY_FULL(sizeof(M_F(name, _lf_node_t))); \ return NULL; \ } \ - atomic_init(&node->next, (M_C(name, _lf_node_t) *) 0); \ + atomic_init(&node->next, (M_F(name, _lf_node_t) *) 0); \ atomic_init(&node->cpt, 0UL); \ - M_C(name, _slist_init)(node->list); \ + M_F(name, _slist_init)(node->list); \ for(unsigned i = 0; i < initial; i++) { \ - M_C(name, _slist_node_ct) *n; \ - n = M_MEMORY_ALLOC(M_C(name, _slist_node_ct)); \ + M_F(name, _slist_node_ct) *n; \ + n = M_MEMORY_ALLOC(M_F(name, _slist_node_ct)); \ if (M_UNLIKELY_NOMEM (n == NULL)) { \ - M_MEMORY_FULL(sizeof(M_C(name, _lf_node_t))); \ + M_MEMORY_FULL(sizeof(M_F(name, _lf_node_t))); \ return NULL; \ } \ - M_C(name, _slist_push)(node->list, n); \ + M_F(name, _slist_push)(node->list, n); \ } \ return node; \ } \ @@ -388,39 +388,39 @@ M_BEGIN_PROTECTED_CODE */ #define M_CMEMP00L_DEF_LFMP_THREAD_MEMPOOL(name, type_t) \ \ - typedef struct M_C(name, _lfmp_thread_s) { \ - M_C(name, _slist_ct) free; \ - M_C(name, _slist_ct) to_be_reclaimed; \ - M_CACHELINE_ALIGN(align1, M_C(name, _slist_ct), M_C(name, _slist_ct)); \ - } M_C(name, _lfmp_thread_ct); \ + typedef struct M_F(name, _lfmp_thread_s) { \ + M_F(name, _slist_ct) free; \ + M_F(name, _slist_ct) to_be_reclaimed; \ + M_CACHELINE_ALIGN(align1, M_F(name, _slist_ct), M_F(name, _slist_ct)); \ + } M_F(name, _lfmp_thread_ct); \ \ static inline void \ - M_C(name, _lfmp_thread_init)(M_C(name, _lfmp_thread_ct) *t) \ + M_F(name, _lfmp_thread_init)(M_F(name, _lfmp_thread_ct) *t) \ { \ - M_C(name, _slist_init)(t->free); \ - M_C(name, _slist_init)(t->to_be_reclaimed); \ + M_F(name, _slist_init)(t->free); \ + M_F(name, _slist_init)(t->to_be_reclaimed); \ } \ \ static inline void \ - M_C(name, _lfmp_thread_clear)(M_C(name, _lfmp_thread_ct) *t) \ + M_F(name, _lfmp_thread_clear)(M_F(name, _lfmp_thread_ct) *t) \ { \ - 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->to_be_reclaimed); \ + M_ASSERT(M_F(name, _slist_empty_p)(t->to_be_reclaimed)); \ + M_F(name, _slist_clear)(t->free); \ + M_F(name, _slist_clear)(t->to_be_reclaimed); \ } \ /* NOTE: once a node is deleted, its data are kept readable until the future GC */ #define M_CMEMP00L_DEF_LF_MEMPOOL(name, type_t) \ \ - typedef struct M_C(name, _s) { \ + typedef struct M_F(name, _s) { \ unsigned initial; \ - M_C(name, _lfmp_thread_ct) *thread_data; \ - M_C(name, _lflist_ct) free; \ - M_C(name, _lflist_ct) to_be_reclaimed; \ - M_C(name, _lflist_ct) empty; \ + M_F(name, _lfmp_thread_ct) *thread_data; \ + M_F(name, _lflist_ct) free; \ + M_F(name, _lflist_ct) to_be_reclaimed; \ + M_F(name, _lflist_ct) empty; \ m_cmemp00l_list_ct mempool_node; \ struct m_gc_s *gc_mem; \ - } M_C(name, _t)[1]; \ + } M_F(name, _t)[1]; \ \ /* Garbage collect of the nodes of the mempool on sleep */ \ static inline void \ @@ -428,59 +428,59 @@ M_BEGIN_PROTECTED_CODE m_gc_tid_t id, m_gc_ticket_ct ticket, m_gc_ticket_ct min_ticket) \ { \ /* Get back the mempool from the node */ \ - struct M_C(name, _s) *mempool = \ - M_TYPE_FROM_FIELD(struct M_C(name, _s), data, m_cmemp00l_list_ct, mempool_node); \ + struct M_F(name, _s) *mempool = \ + M_TYPE_FROM_FIELD(struct M_F(name, _s), data, m_cmemp00l_list_ct, mempool_node); \ \ /* Move the local nodes of the mempool to be reclaimed to the thread into the global pool */ \ - if (!M_C(name, _slist_empty_p)(mempool->thread_data[id].to_be_reclaimed)) { \ - M_C(name, _lf_node_t) *node; \ + if (!M_F(name, _slist_empty_p)(mempool->thread_data[id].to_be_reclaimed)) { \ + M_F(name, _lf_node_t) *node; \ /* Get a new empty group of nodes */ \ - node = M_C(name, _lflist_pop)(mempool->empty, gc_mem->thread_data[id].bkoff); \ + node = M_F(name, _lflist_pop)(mempool->empty, gc_mem->thread_data[id].bkoff); \ if (M_UNLIKELY (node == NULL)) { \ /* Fail to get an empty group of node. \ Alloc a new one from the system */ \ - node = M_C(name, _alloc_node)(0); \ + node = M_F(name, _alloc_node)(0); \ M_ASSERT(node != NULL); \ } \ - 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_ASSERT(M_F(name, _slist_empty_p)(node->list)); \ + M_F(name, _slist_move)(node->list, mempool->thread_data[id].to_be_reclaimed); \ 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_F(name, _lflist_push)(mempool->to_be_reclaimed, node, gc_mem->thread_data[id].bkoff); \ } \ \ /* Perform a GC of the freelist of nodes */ \ while (true) { \ - M_C(name, _lf_node_t) *node; \ - node = M_C(name, _lflist_pop_if)(mempool->to_be_reclaimed, \ + M_F(name, _lf_node_t) *node; \ + node = M_F(name, _lflist_pop_if)(mempool->to_be_reclaimed, \ min_ticket, gc_mem->thread_data[id].bkoff); \ if (node == NULL) break; \ - M_C(name, _lflist_push)(mempool->free, node, gc_mem->thread_data[id].bkoff); \ + M_F(name, _lflist_push)(mempool->free, node, gc_mem->thread_data[id].bkoff); \ } \ } \ \ static inline void \ - M_C(name, _init)(M_C(name, _t) mem, m_gc_t gc_mem, \ + M_F(name, _init)(M_F(name, _t) mem, m_gc_t gc_mem, \ unsigned init_node_count, unsigned init_group_count) \ { \ const size_t max_thread = gc_mem->max_thread; \ /* Initialize the thread data of the mempool */ \ - mem->thread_data = M_MEMORY_REALLOC(M_C(name, _lfmp_thread_ct), NULL, max_thread); \ + mem->thread_data = M_MEMORY_REALLOC(M_F(name, _lfmp_thread_ct), NULL, max_thread); \ if (M_UNLIKELY_NOMEM (mem->thread_data == NULL)) { \ - M_MEMORY_FULL(max_thread * sizeof(M_C(name, _lfmp_thread_ct))); \ + M_MEMORY_FULL(max_thread * sizeof(M_F(name, _lfmp_thread_ct))); \ return; \ } \ for(unsigned i = 0; i < max_thread;i++) { \ - M_C(name, _lfmp_thread_init)(&mem->thread_data[i]); \ + M_F(name, _lfmp_thread_init)(&mem->thread_data[i]); \ } \ /* Preallocate some group of nodes for the mempool */ \ mem->initial = M_MAX(M_CMEMP00L_MIN_NODE_PER_GROUP, init_node_count); \ - M_C(name, _lflist_init)(mem->free, M_C(name, _alloc_node)(init_node_count)); \ - M_C(name, _lflist_init)(mem->to_be_reclaimed, M_C(name, _alloc_node)(init_node_count)); \ - M_C(name, _lflist_init)(mem->empty, M_C(name, _alloc_node)(0)); \ + M_F(name, _lflist_init)(mem->free, M_F(name, _alloc_node)(init_node_count)); \ + M_F(name, _lflist_init)(mem->to_be_reclaimed, M_F(name, _alloc_node)(init_node_count)); \ + M_F(name, _lflist_init)(mem->empty, M_F(name, _alloc_node)(0)); \ for(unsigned i = 1; i < init_group_count; i++) { \ - M_C(name, _lflist_push)(mem->free, M_C(name, _alloc_node)(init_node_count), \ + M_F(name, _lflist_push)(mem->free, M_F(name, _alloc_node)(init_node_count), \ gc_mem->thread_data[0].bkoff); \ - M_C(name, _lflist_push)(mem->empty, M_C(name, _alloc_node)(0), \ + M_F(name, _lflist_push)(mem->empty, M_F(name, _alloc_node)(0), \ gc_mem->thread_data[0].bkoff); \ } \ /* Register the mempool in the GC */ \ @@ -491,55 +491,55 @@ M_BEGIN_PROTECTED_CODE } \ \ static inline void \ - M_C(name, _clear)(M_C(name, _t) mem) \ + M_F(name, _clear)(M_F(name, _t) mem) \ { \ const unsigned max_thread = mem->gc_mem->max_thread; \ for(unsigned i = 0; i < max_thread;i++) { \ - M_C(name, _lfmp_thread_clear)(&mem->thread_data[i]); \ + M_F(name, _lfmp_thread_clear)(&mem->thread_data[i]); \ } \ M_MEMORY_FREE(mem->thread_data); \ mem->thread_data = NULL; \ - M_C(name, _lflist_clear)(mem->empty); \ - M_C(name, _lflist_clear)(mem->free); \ - M_ASSERT(M_C(name, _lflist_empty_p)(mem->to_be_reclaimed)); \ - M_C(name, _lflist_clear)(mem->to_be_reclaimed); \ + M_F(name, _lflist_clear)(mem->empty); \ + M_F(name, _lflist_clear)(mem->free); \ + M_ASSERT(M_F(name, _lflist_empty_p)(mem->to_be_reclaimed)); \ + M_F(name, _lflist_clear)(mem->to_be_reclaimed); \ /* TODO: Unregister from the GC? */ \ } \ \ static inline type_t * \ - M_C(name, _new)(M_C(name, _t) mem, m_gc_tid_t id) \ + M_F(name, _new)(M_F(name, _t) mem, m_gc_tid_t id) \ { \ - M_C(name, _slist_node_ct) *snode; \ - M_C(name, _lf_node_t) *node; \ + M_F(name, _slist_node_ct) *snode; \ + M_F(name, _lf_node_t) *node; \ while (true) { \ /* Fast & likely path where we access the thread pool of nodes */ \ - if (M_LIKELY(!M_C(name, _slist_empty_p)(mem->thread_data[id].free))) { \ - snode = M_C(name, _slist_pop)(mem->thread_data[id].free); \ + if (M_LIKELY(!M_F(name, _slist_empty_p)(mem->thread_data[id].free))) { \ + snode = M_F(name, _slist_pop)(mem->thread_data[id].free); \ return &snode->data; \ } \ /* Request a group node to the freelist of groups */ \ - node = M_C(name, _lflist_pop)(mem->free, mem->gc_mem->thread_data[id].bkoff); \ + node = M_F(name, _lflist_pop)(mem->free, mem->gc_mem->thread_data[id].bkoff); \ if (M_UNLIKELY (node == NULL)) { \ /* Request a new group to the system. Non Lock Free path */ \ M_ASSERT(mem->initial > 0); \ - node = M_C(name, _alloc_node)(mem->initial); \ + node = M_F(name, _alloc_node)(mem->initial); \ M_ASSERT(node != NULL); \ - M_ASSERT(!M_C(name, _slist_empty_p)(node->list)); \ + M_ASSERT(!M_F(name, _slist_empty_p)(node->list)); \ } \ - M_C(name, _slist_move)(mem->thread_data[id].free, node->list); \ + M_F(name, _slist_move)(mem->thread_data[id].free, node->list); \ /* Push back the empty group */ \ - 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_ASSERT (M_F(name, _slist_empty_p)(node->list)); \ + M_F(name, _lflist_push)(mem->empty, node, mem->gc_mem->thread_data[id].bkoff); \ } \ } \ \ static inline void \ - M_C(name, _del)(M_C(name, _t) mem, type_t *d, m_gc_tid_t id) \ + M_F(name, _del)(M_F(name, _t) mem, type_t *d, m_gc_tid_t id) \ { \ - M_C(name, _slist_node_ct) *snode; \ + M_F(name, _slist_node_ct) *snode; \ M_ASSERT( d != NULL); \ - 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); \ + snode = M_TYPE_FROM_FIELD(M_F(name, _slist_node_ct), d, type_t, data); \ + M_F(name, _slist_push)(mem->thread_data[id].to_be_reclaimed, snode); \ } \ diff --git a/m-concurrent.h b/m-concurrent.h index 5eaecc1d..44175077 100644 --- a/m-concurrent.h +++ b/m-concurrent.h @@ -33,7 +33,7 @@ based on the given container. USAGE: CONCURRENT_DEF(name, type [, oplist_of_the_type]) */ #define M_CONCURRENT_DEF(name, ...) \ - M_CONCURRENT_DEF_AS(name, M_C(name,_t), __VA_ARGS__) + M_CONCURRENT_DEF_AS(name, M_F(name,_t), __VA_ARGS__) /* Define a protected concurrent container and its associated functions @@ -52,7 +52,7 @@ can be done in parallel. USAGE: CONCURRENT_RP_DEF(name, type [, oplist_of_the_type]) */ #define M_CONCURRENT_RP_DEF(name, ...) \ - M_CONCURRENT_RP_DEF_AS(name, M_C(name,_t), __VA_ARGS__) + M_CONCURRENT_RP_DEF_AS(name, M_F(name,_t), __VA_ARGS__) /* Define a protected concurrent container and its associated functions @@ -98,38 +98,38 @@ destroyed by another thread). */ #define M_C0NCURRENT_OPLIST_P3(name, oplist) \ - (M_IF_METHOD(INIT, oplist)(INIT(M_C(name, _init)),) \ - ,M_IF_METHOD(INIT_SET, oplist)(INIT_SET(M_C(name, _init_set)),) \ - ,M_IF_METHOD(SET, oplist)(SET(M_C(name, _set)),) \ - ,M_IF_METHOD(CLEAR, oplist)(CLEAR(M_C(name, _clear)),) \ - ,M_IF_METHOD(INIT_MOVE, oplist)(INIT_MOVE(M_C(name, _init_move)),) \ - ,M_IF_METHOD(MOVE, oplist)(MOVE(M_C(name, _move)),) \ - ,M_IF_METHOD(SWAP,oplist)(SWAP(M_C(name, _swap)),) \ + (M_IF_METHOD(INIT, oplist)(INIT(M_F(name, _init)),) \ + ,M_IF_METHOD(INIT_SET, oplist)(INIT_SET(M_F(name, _init_set)),) \ + ,M_IF_METHOD(SET, oplist)(SET(M_F(name, _set)),) \ + ,M_IF_METHOD(CLEAR, oplist)(CLEAR(M_F(name, _clear)),) \ + ,M_IF_METHOD(INIT_MOVE, oplist)(INIT_MOVE(M_F(name, _init_move)),) \ + ,M_IF_METHOD(MOVE, oplist)(MOVE(M_F(name, _move)),) \ + ,M_IF_METHOD(SWAP,oplist)(SWAP(M_F(name, _swap)),) \ ,NAME(name) \ - ,TYPE(M_C(name,_ct)) \ - ,SUBTYPE(M_C(name, _subtype_ct)) \ + ,TYPE(M_F(name,_ct)) \ + ,SUBTYPE(M_F(name, _subtype_ct)) \ ,OPLIST(oplist) \ - ,M_IF_METHOD(EMPTY_P, oplist)(EMPTY_P(M_C(name,_empty_p)),) \ - ,M_IF_METHOD(GET_SIZE, oplist)(GET_SIZE(M_C(name,_size)),) \ - ,M_IF_METHOD(RESET, oplist)(RESET(M_C(name,_reset)),) \ + ,M_IF_METHOD(EMPTY_P, oplist)(EMPTY_P(M_F(name,_empty_p)),) \ + ,M_IF_METHOD(GET_SIZE, oplist)(GET_SIZE(M_F(name,_size)),) \ + ,M_IF_METHOD(RESET, oplist)(RESET(M_F(name,_reset)),) \ ,M_IF_METHOD(KEY_TYPE, oplist)(KEY_TYPE(M_GET_KEY_TYPE oplist),) \ ,M_IF_METHOD(VALUE_TYPE, oplist)(VALUE_TYPE(M_GET_VALUE_TYPE oplist),) \ ,M_IF_METHOD(KEY_TYPE, oplist)(KEY_OPLIST(M_GET_KEY_OPLIST oplist),) \ ,M_IF_METHOD(VALUE_TYPE, oplist)(VALUE_OPLIST(M_GET_VALUE_OPLIST oplist), ) \ - ,M_IF_METHOD(SET_KEY, oplist)(SET_KEY(M_C(name, _set_at)),) \ - ,M_IF_METHOD(ERASE_KEY, oplist)(ERASE_KEY(M_C(name, _erase)),) \ - ,M_IF_METHOD(PUSH, oplist)(PUSH(M_C(name,_push)),) \ - ,M_IF_METHOD(POP, oplist)(POP(M_C(name,_pop)),) \ - ,M_IF_METHOD(PUSH_MOVE, oplist)(PUSH_MOVE(M_C(name,_push_move)),) \ - ,M_IF_METHOD(POP_MOVE, oplist)(POP_MOVE(M_C(name,_pop_move)),) \ - ,M_IF_METHOD(GET_STR, oplist)(GET_STR(M_C(name, _get_str)),) \ - ,M_IF_METHOD(PARSE_STR, oplist)(PARSE_STR(M_C(name, _parse_str)),) \ - ,M_IF_METHOD(OUT_STR, oplist)(OUT_STR(M_C(name, _out_str)),) \ - ,M_IF_METHOD(IN_STR, oplist)(IN_STR(M_C(name, _in_str)),) \ - ,M_IF_METHOD(OUT_SERIAL, oplist)(OUT_SERIAL(M_C(name, _out_serial)),) \ - ,M_IF_METHOD(IN_SERIAL, oplist)(IN_SERIAL(M_C(name, _in_serial)),) \ - ,M_IF_METHOD(EQUAL, oplist)(EQUAL(M_C(name, _equal_p)),) \ - ,M_IF_METHOD(HASH, oplist)(HASH(M_C(name, _hash)),) \ + ,M_IF_METHOD(SET_KEY, oplist)(SET_KEY(M_F(name, _set_at)),) \ + ,M_IF_METHOD(ERASE_KEY, oplist)(ERASE_KEY(M_F(name, _erase)),) \ + ,M_IF_METHOD(PUSH, oplist)(PUSH(M_F(name,_push)),) \ + ,M_IF_METHOD(POP, oplist)(POP(M_F(name,_pop)),) \ + ,M_IF_METHOD(PUSH_MOVE, oplist)(PUSH_MOVE(M_F(name,_push_move)),) \ + ,M_IF_METHOD(POP_MOVE, oplist)(POP_MOVE(M_F(name,_pop_move)),) \ + ,M_IF_METHOD(GET_STR, oplist)(GET_STR(M_F(name, _get_str)),) \ + ,M_IF_METHOD(PARSE_STR, oplist)(PARSE_STR(M_F(name, _parse_str)),) \ + ,M_IF_METHOD(OUT_STR, oplist)(OUT_STR(M_F(name, _out_str)),) \ + ,M_IF_METHOD(IN_STR, oplist)(IN_STR(M_F(name, _in_str)),) \ + ,M_IF_METHOD(OUT_SERIAL, oplist)(OUT_SERIAL(M_F(name, _out_serial)),) \ + ,M_IF_METHOD(IN_SERIAL, oplist)(IN_SERIAL(M_F(name, _in_serial)),) \ + ,M_IF_METHOD(EQUAL, oplist)(EQUAL(M_F(name, _equal_p)),) \ + ,M_IF_METHOD(HASH, oplist)(HASH(M_F(name, _hash)),) \ ,M_IF_METHOD(NEW, oplist)(NEW(M_GET_NEW oplist),) \ ,M_IF_METHOD(REALLOC, oplist)(REALLOC(M_GET_REALLOC oplist),) \ ,M_IF_METHOD(DEL, oplist)(DEL(M_GET_DEL oplist),) \ @@ -162,7 +162,7 @@ - name: prefix to be used - type: type of the sub container - oplist: oplist of the type of the sub container - - concurrent_t: alias for M_C(name, _t) [ type of the container ] + - concurrent_t: alias for M_F(name, _t) [ type of the container ] */ #define M_C0NCURRENT_DEF_P3(name, type, oplist, concurrent_t) \ M_C0NCURRENT_DEF_TYPE(name, type, oplist, concurrent_t) \ @@ -174,20 +174,20 @@ #define M_C0NCURRENT_DEF_TYPE(name, type, oplist, concurrent_t) \ \ /* Define a concurrent container using a lock */ \ - typedef struct M_C(name, _s) { \ - struct M_C(name, _s) *self; \ + typedef struct M_F(name, _s) { \ + struct M_F(name, _s) *self; \ m_mutex_t lock; \ m_cond_t there_is_data; /* condition raised when there is data */ \ type data; \ } concurrent_t[1]; \ \ /* Define alias for pointer types */ \ - typedef struct M_C(name, _s) *M_C(name, _ptr); \ - typedef const struct M_C(name, _s) *M_C(name, _srcptr); \ + typedef struct M_F(name, _s) *M_F(name, _ptr); \ + typedef const struct M_F(name, _s) *M_F(name, _srcptr); \ \ /* Internal types for oplist */ \ - typedef concurrent_t M_C(name, _ct); \ - typedef type M_C(name, _subtype_ct); \ + typedef concurrent_t M_F(name, _ct); \ + typedef type M_F(name, _subtype_ct); \ \ /* Cannot define iterator as it cannot be reliable in a concurrent type */ \ @@ -197,7 +197,7 @@ /* Initial the fields of the concurrent object not associated to the \ sub-container. */ \ static inline void \ - M_C(name, _internal_init)(concurrent_t out) \ + M_F(name, _internal_init)(concurrent_t out) \ { \ m_mutex_init(out->lock); \ m_cond_init(out->there_is_data); \ @@ -208,7 +208,7 @@ /* Clear the fields of the concurrent object not associated to the \ sub-container. */ \ static inline void \ - M_C(name, _internal_clear)(concurrent_t out) \ + M_F(name, _internal_clear)(concurrent_t out) \ { \ M_C0NCURRENT_CONTRACT(out); \ m_mutex_clear(out->lock); \ @@ -221,7 +221,7 @@ NOTE: This instance doesn't implement the read/write strategy, \ and only get the lock */ \ static inline void \ - M_C(name, _read_lock)(const concurrent_t out) \ + M_F(name, _read_lock)(const concurrent_t out) \ { \ M_C0NCURRENT_CONTRACT(out); \ m_mutex_lock (out->self->lock); \ @@ -231,7 +231,7 @@ NOTE: This instance doesn't implement the read/write strategy, \ and only get the lock */ \ static inline void \ - M_C(name, _read_unlock)(const concurrent_t out) \ + M_F(name, _read_unlock)(const concurrent_t out) \ { \ M_C0NCURRENT_CONTRACT(out); \ m_mutex_unlock (out->self->lock); \ @@ -240,7 +240,7 @@ /* Wait for a thread pushing some data in the container. \ CONSTRAINT: the read lock shall be get before calling this service */ \ static inline void \ - M_C(name, _read_wait)(const concurrent_t out) \ + M_F(name, _read_wait)(const concurrent_t out) \ { \ M_C0NCURRENT_CONTRACT(out); \ m_cond_wait(out->self->there_is_data, out->self->lock); \ @@ -251,7 +251,7 @@ NOTE: This instance doesn't implement the read/write strategy, \ and only get the lock */ \ static inline void \ - M_C(name, _write_lock)(concurrent_t out) \ + M_F(name, _write_lock)(concurrent_t out) \ { \ M_C0NCURRENT_CONTRACT(out); \ m_mutex_lock (out->lock); \ @@ -261,7 +261,7 @@ NOTE: This instance doesn't implement the read/write strategy, \ and only get the lock */ \ static inline void \ - M_C(name, _write_unlock)(concurrent_t out) \ + M_F(name, _write_unlock)(concurrent_t out) \ { \ M_C0NCURRENT_CONTRACT(out); \ m_mutex_unlock (out->lock); \ @@ -270,7 +270,7 @@ /* Wait for a thread pushing some data in the container. \ CONSTRAINT: the write lock shall be get before calling this service */ \ static inline void \ - M_C(name, _write_wait)(const concurrent_t out) \ + M_F(name, _write_wait)(const concurrent_t out) \ { \ M_C0NCURRENT_CONTRACT(out); \ m_cond_wait(out->self->there_is_data, out->self->lock); \ @@ -279,7 +279,7 @@ /* Wait to all threads that some data are available in the container. \ CONSTRAINT: the write lock shall be get before calling this service */ \ static inline void \ - M_C(name, _write_signal)(concurrent_t out) \ + M_F(name, _write_signal)(concurrent_t out) \ { \ M_C0NCURRENT_CONTRACT(out); \ /* We need to signal this to ALL waiting threads as multiple threads \ @@ -291,7 +291,7 @@ - name: prefix to be used - type: type of the sub container - oplist: oplist of the type of the sub container - - concurrent_t: alias for M_C(name, _t) [ type of the container ] + - concurrent_t: alias for M_F(name, _t) [ type of the container ] A function is defined only if the underlying container exports the needed services. It is usually one service declared per service exported. */ @@ -299,9 +299,9 @@ \ M_IF_METHOD(INIT, oplist)( \ static inline void \ - M_C(name, _init)(concurrent_t out) \ + M_F(name, _init)(concurrent_t out) \ { \ - M_C(name, _internal_init)(out); \ + M_F(name, _internal_init)(out); \ M_CALL_INIT(oplist, out->data); \ M_C0NCURRENT_CONTRACT(out); \ } \ @@ -309,21 +309,21 @@ \ M_IF_METHOD(INIT_SET, oplist)( \ static inline void \ - M_C(name, _init_set)(concurrent_t out, concurrent_t const src) \ + M_F(name, _init_set)(concurrent_t out, concurrent_t const src) \ { \ M_C0NCURRENT_CONTRACT(src); \ M_ASSERT (out != src); \ - M_C(name, _internal_init)(out); \ - M_C(name, _read_lock)(src); \ + M_F(name, _internal_init)(out); \ + M_F(name, _read_lock)(src); \ M_CALL_INIT_SET(oplist, out->data, src->data); \ - M_C(name, _read_unlock)(src); \ + M_F(name, _read_unlock)(src); \ M_C0NCURRENT_CONTRACT(out); \ } \ ,) \ \ M_IF_METHOD(SET, oplist)( \ static inline void \ - M_C(name, _set)(concurrent_t out, concurrent_t const src) \ + M_F(name, _set)(concurrent_t out, concurrent_t const src) \ { \ M_C0NCURRENT_CONTRACT(out); \ if (M_UNLIKELY (out == src)) return; \ @@ -338,19 +338,19 @@ To avoid this problem, we **always** lock the mutex which address is \ the lowest. */ \ if (out < src) { \ - M_C(name, _write_lock)(out); \ - M_C(name, _read_lock)(src); \ + M_F(name, _write_lock)(out); \ + M_F(name, _read_lock)(src); \ } else { \ - M_C(name, _read_lock)(src); \ - M_C(name, _write_lock)(out); \ + M_F(name, _read_lock)(src); \ + M_F(name, _write_lock)(out); \ } \ M_CALL_SET(oplist, out->data, src->data); \ if (out < src) { \ - M_C(name, _read_lock)(src); \ - M_C(name, _write_unlock)(out); \ + M_F(name, _read_lock)(src); \ + M_F(name, _write_unlock)(out); \ } else { \ - M_C(name, _write_unlock)(out); \ - M_C(name, _read_unlock)(src); \ + M_F(name, _write_unlock)(out); \ + M_F(name, _read_unlock)(src); \ } \ M_C0NCURRENT_CONTRACT(out); \ } \ @@ -358,307 +358,307 @@ \ M_IF_METHOD(CLEAR, oplist)( \ static inline void \ - M_C(name, _clear)(concurrent_t out) \ + M_F(name, _clear)(concurrent_t out) \ { \ M_C0NCURRENT_CONTRACT(out); \ /* No need to lock. A clear is supposed to be called when all operations \ of the container in other threads are terminated */ \ M_CALL_CLEAR(oplist, out->data); \ - M_C(name, _internal_clear)(out); \ + M_F(name, _internal_clear)(out); \ } \ ,) \ \ M_IF_METHOD(INIT_MOVE, oplist)( \ static inline void \ - M_C(name, _init_move)(concurrent_t out, concurrent_t src) \ + M_F(name, _init_move)(concurrent_t out, concurrent_t src) \ { \ M_C0NCURRENT_CONTRACT(src); \ M_ASSERT (out != src); \ /* No need to lock 'src' ? */ \ - M_C(name, _internal_init)(out); \ + M_F(name, _internal_init)(out); \ M_CALL_INIT_MOVE(oplist, out->data, src->data); \ - M_C(name, _internal_clear)(src); \ + M_F(name, _internal_clear)(src); \ M_C0NCURRENT_CONTRACT(out); \ } \ ,) \ \ M_IF_METHOD(MOVE, oplist)( \ static inline void \ - M_C(name, _move)(concurrent_t out, concurrent_t src) \ + M_F(name, _move)(concurrent_t out, concurrent_t src) \ { \ M_C0NCURRENT_CONTRACT(out); \ M_C0NCURRENT_CONTRACT(src); \ /* No need to lock 'src' ? */ \ - M_C(name, _write_lock)(out); \ + M_F(name, _write_lock)(out); \ M_CALL_MOVE(oplist, out->data, src->data); \ - M_C(name, _write_unlock)(out); \ - M_C(name, _internal_clear)(src); \ + M_F(name, _write_unlock)(out); \ + M_F(name, _internal_clear)(src); \ M_C0NCURRENT_CONTRACT(out); \ } \ ,) \ \ M_IF_METHOD(SWAP, oplist)( \ static inline void \ - M_C(name, _swap)(concurrent_t out, concurrent_t src) \ + M_F(name, _swap)(concurrent_t out, concurrent_t src) \ { \ M_C0NCURRENT_CONTRACT(out); \ M_C0NCURRENT_CONTRACT(src); \ if (M_UNLIKELY (out == src)) return; \ /* See comment above */ \ if (out < src) { \ - M_C(name, _write_lock)(out); \ - M_C(name, _write_lock)(src); \ + M_F(name, _write_lock)(out); \ + M_F(name, _write_lock)(src); \ } else { \ - M_C(name, _write_lock)(src); \ - M_C(name, _write_lock)(out); \ + M_F(name, _write_lock)(src); \ + M_F(name, _write_lock)(out); \ } \ M_CALL_SWAP(oplist, out->data, src->data); \ if (out < src) { \ - M_C(name, _write_unlock)(src); \ - M_C(name, _write_unlock)(out); \ + M_F(name, _write_unlock)(src); \ + M_F(name, _write_unlock)(out); \ } else { \ - M_C(name, _write_unlock)(out); \ - M_C(name, _write_unlock)(src); \ + M_F(name, _write_unlock)(out); \ + M_F(name, _write_unlock)(src); \ } \ } \ ,) \ \ M_IF_METHOD(RESET, oplist)( \ static inline void \ - M_C(name, _reset)(concurrent_t out) \ + M_F(name, _reset)(concurrent_t out) \ { \ M_C0NCURRENT_CONTRACT(out); \ - M_C(name, _write_lock)(out); \ + M_F(name, _write_lock)(out); \ M_CALL_RESET(oplist, out->data); \ - M_C(name, _write_unlock)(out); \ + M_F(name, _write_unlock)(out); \ } \ ,) \ \ M_IF_METHOD(EMPTY_P, oplist)( \ static inline bool \ - M_C(name, _empty_p)(concurrent_t const out) \ + M_F(name, _empty_p)(concurrent_t const out) \ { \ M_C0NCURRENT_CONTRACT(out); \ - M_C(name, _read_lock)(out); \ + M_F(name, _read_lock)(out); \ bool b = M_CALL_EMPTY_P(oplist, out->data); \ - M_C(name, _read_unlock)(out); \ + M_F(name, _read_unlock)(out); \ return b; \ } \ ,) \ \ M_IF_METHOD(GET_SIZE, oplist)( \ static inline size_t \ - M_C(name, _size)(concurrent_t const out) \ + M_F(name, _size)(concurrent_t const out) \ { \ M_C0NCURRENT_CONTRACT(out); \ - M_C(name, _read_lock)(out); \ + M_F(name, _read_lock)(out); \ size_t r = M_CALL_GET_SIZE(oplist, out->data); \ - M_C(name, _read_unlock)(out); \ + M_F(name, _read_unlock)(out); \ return r; \ } \ ,) \ \ M_IF_METHOD(SET_KEY, oplist)( \ static inline void \ - M_C(name, _set_at)(concurrent_t out, M_GET_KEY_TYPE oplist const key, M_GET_VALUE_TYPE oplist const data) \ + M_F(name, _set_at)(concurrent_t out, M_GET_KEY_TYPE oplist const key, M_GET_VALUE_TYPE oplist const data) \ { \ M_C0NCURRENT_CONTRACT(out); \ - M_C(name, _write_lock)(out); \ + M_F(name, _write_lock)(out); \ M_CALL_SET_KEY(oplist, out->data, key, data); \ - M_C(name, _write_signal)(out); \ - M_C(name, _write_unlock)(out); \ + M_F(name, _write_signal)(out); \ + M_F(name, _write_unlock)(out); \ } \ ,) \ \ M_IF_METHOD(GET_KEY, oplist)( \ static inline bool \ - M_C(name, _get_copy)(M_GET_VALUE_TYPE oplist *out_data, const concurrent_t out, M_GET_KEY_TYPE oplist const key) \ + M_F(name, _get_copy)(M_GET_VALUE_TYPE oplist *out_data, const concurrent_t out, M_GET_KEY_TYPE oplist const key) \ { \ M_C0NCURRENT_CONTRACT(out); \ M_ASSERT (out_data != NULL); \ - M_C(name, _read_lock)(out); \ + M_F(name, _read_lock)(out); \ M_GET_VALUE_TYPE oplist *p = M_CALL_GET_KEY(oplist, out->data, key); \ if (p != NULL) { \ M_CALL_SET(M_GET_VALUE_OPLIST oplist, *out_data, *p); \ } \ - M_C(name, _read_unlock)(out); \ + M_F(name, _read_unlock)(out); \ return p != NULL; \ } \ ,) \ \ M_IF_METHOD(SAFE_GET_KEY, oplist)( \ static inline void \ - M_C(name, _safe_get_copy)(M_GET_VALUE_TYPE oplist *out_data, concurrent_t out, M_GET_KEY_TYPE oplist const key) \ + M_F(name, _safe_get_copy)(M_GET_VALUE_TYPE oplist *out_data, concurrent_t out, M_GET_KEY_TYPE oplist const key) \ { \ M_C0NCURRENT_CONTRACT(out); \ M_ASSERT (out_data != NULL); \ - M_C(name, _write_lock)(out); \ + M_F(name, _write_lock)(out); \ M_GET_VALUE_TYPE oplist *p = M_CALL_SAFE_GET_KEY(oplist, out->data, key); \ M_ASSERT (p != NULL); \ M_CALL_SET(M_GET_VALUE_OPLIST oplist, *out_data, *p); \ - M_C(name, _write_unlock)(out); \ + M_F(name, _write_unlock)(out); \ } \ ,) \ \ M_IF_METHOD(ERASE_KEY, oplist)( \ static inline bool \ - M_C(name, _erase)(concurrent_t out, M_GET_KEY_TYPE oplist const key) \ + M_F(name, _erase)(concurrent_t out, M_GET_KEY_TYPE oplist const key) \ { \ M_C0NCURRENT_CONTRACT(out); \ - M_C(name, _write_lock)(out); \ + M_F(name, _write_lock)(out); \ bool b = M_CALL_ERASE_KEY(oplist, out->data, key); \ /* We suppose that the container has 'infinite' capacity, so \ we won't signal that a free space has been created */ \ - M_C(name, _write_unlock)(out); \ + M_F(name, _write_unlock)(out); \ return b; \ } \ ,) \ \ M_IF_METHOD(PUSH, oplist)( \ static inline void \ - M_C(name, _push)(concurrent_t out, M_GET_SUBTYPE oplist const data) \ + M_F(name, _push)(concurrent_t out, M_GET_SUBTYPE oplist const data) \ { \ M_C0NCURRENT_CONTRACT(out); \ - M_C(name, _write_lock)(out); \ + M_F(name, _write_lock)(out); \ M_CALL_PUSH(oplist, out->data, data); \ - M_C(name, _write_signal)(out); \ - M_C(name, _write_unlock)(out); \ + M_F(name, _write_signal)(out); \ + M_F(name, _write_unlock)(out); \ } \ \ - M_EMPLACE_QUEUE_DEF(name, concurrent_t, M_C(name, _emplace), M_GET_OPLIST oplist, M_EMPLACE_QUEUE_GENE) \ + M_EMPLACE_QUEUE_DEF(name, concurrent_t, M_F(name, _emplace), M_GET_OPLIST oplist, M_EMPLACE_QUEUE_GENE) \ ,) \ \ M_IF_METHOD(POP, oplist)( \ static inline void \ - M_C(name, _pop)(M_GET_SUBTYPE oplist *p, concurrent_t out) \ + M_F(name, _pop)(M_GET_SUBTYPE oplist *p, concurrent_t out) \ { \ M_C0NCURRENT_CONTRACT(out); \ - M_C(name, _write_lock)(out); \ + M_F(name, _write_lock)(out); \ M_CALL_POP(oplist, p, out->data); \ /* See comment above */ \ - M_C(name, _write_unlock)(out); \ + M_F(name, _write_unlock)(out); \ } \ ,) \ \ M_IF_METHOD(PUSH_MOVE, oplist)( \ static inline void \ - M_C(name, _push_move)(concurrent_t out, M_GET_SUBTYPE oplist *data) \ + M_F(name, _push_move)(concurrent_t out, M_GET_SUBTYPE oplist *data) \ { \ M_C0NCURRENT_CONTRACT(out); \ - M_C(name, _write_lock)(out); \ + M_F(name, _write_lock)(out); \ M_CALL_PUSH_MOVE(oplist, out->data, data); \ - M_C(name, _write_signal)(out); \ - M_C(name, _write_unlock)(out); \ + M_F(name, _write_signal)(out); \ + M_F(name, _write_unlock)(out); \ } \ ,) \ \ M_IF_METHOD(POP_MOVE, oplist)( \ static inline void \ - M_C(name, _pop_move)(M_GET_SUBTYPE oplist *p, concurrent_t out) \ + M_F(name, _pop_move)(M_GET_SUBTYPE oplist *p, concurrent_t out) \ { \ M_C0NCURRENT_CONTRACT(out); \ - M_C(name, _write_lock)(out); \ + M_F(name, _write_lock)(out); \ M_CALL_POP_MOVE(oplist, p, out->data); \ /* See comment above */ \ - M_C(name, _write_unlock)(out); \ + M_F(name, _write_unlock)(out); \ } \ ,) \ \ M_IF_METHOD(GET_STR, oplist)( \ static inline void \ - M_C(name, _get_str)(m_string_t str, concurrent_t const out, bool a) \ + M_F(name, _get_str)(m_string_t str, concurrent_t const out, bool a) \ { \ M_C0NCURRENT_CONTRACT(out); \ - M_C(name, _read_lock)(out); \ + M_F(name, _read_lock)(out); \ M_CALL_GET_STR(oplist, str, out->data, a); \ - M_C(name, _read_unlock)(out); \ + M_F(name, _read_unlock)(out); \ } \ ,) \ \ M_IF_METHOD(OUT_STR, oplist)( \ static inline void \ - M_C(name, _out_str)(FILE *f, concurrent_t const out) \ + M_F(name, _out_str)(FILE *f, concurrent_t const out) \ { \ M_C0NCURRENT_CONTRACT(out); \ - M_C(name, _read_lock)(out); \ + M_F(name, _read_lock)(out); \ M_CALL_OUT_STR(oplist, f, out->data); \ - M_C(name, _read_unlock)(out); \ + M_F(name, _read_unlock)(out); \ } \ ,) \ \ M_IF_METHOD(PARSE_STR, oplist)( \ static inline bool \ - M_C(name, _parse_str)(concurrent_t out, const char str[], const char **e) \ + M_F(name, _parse_str)(concurrent_t out, const char str[], const char **e) \ { \ M_C0NCURRENT_CONTRACT(out); \ - M_C(name, _write_lock)(out); \ + M_F(name, _write_lock)(out); \ bool b = M_CALL_PARSE_STR(oplist, out->data, str, e); \ - M_C(name, _write_signal)(out); \ - M_C(name, _write_unlock)(out); \ + M_F(name, _write_signal)(out); \ + M_F(name, _write_unlock)(out); \ return b; \ } \ ,) \ \ M_IF_METHOD(IN_STR, oplist)( \ static inline bool \ - M_C(name, _in_str)(concurrent_t out, FILE *f) \ + M_F(name, _in_str)(concurrent_t out, FILE *f) \ { \ M_C0NCURRENT_CONTRACT(out); \ - M_C(name, _write_lock)(out); \ + M_F(name, _write_lock)(out); \ bool b = M_CALL_IN_STR(oplist, out->data, f); \ - M_C(name, _write_signal)(out); \ - M_C(name, _write_unlock)(out); \ + M_F(name, _write_signal)(out); \ + M_F(name, _write_unlock)(out); \ return b; \ } \ ,) \ \ M_IF_METHOD(OUT_SERIAL, oplist)( \ static inline m_serial_return_code_t \ - M_C(name, _out_serial)(m_serial_write_t f, concurrent_t const out) \ + M_F(name, _out_serial)(m_serial_write_t f, concurrent_t const out) \ { \ M_C0NCURRENT_CONTRACT(out); \ - M_C(name, _read_lock)(out); \ + M_F(name, _read_lock)(out); \ m_serial_return_code_t r = M_CALL_OUT_SERIAL(oplist, f, out->data); \ - M_C(name, _read_unlock)(out); \ + M_F(name, _read_unlock)(out); \ return r; \ } \ ,) \ \ M_IF_METHOD(IN_SERIAL, oplist)( \ static inline m_serial_return_code_t \ - M_C(name, _in_serial)(concurrent_t out, m_serial_read_t f) \ + M_F(name, _in_serial)(concurrent_t out, m_serial_read_t f) \ { \ M_C0NCURRENT_CONTRACT(out); \ - M_C(name, _write_lock)(out); \ + M_F(name, _write_lock)(out); \ m_serial_return_code_t r = M_CALL_IN_SERIAL(oplist, out->data, f); \ - M_C(name, _write_signal)(out); \ - M_C(name, _write_unlock)(out); \ + M_F(name, _write_signal)(out); \ + M_F(name, _write_unlock)(out); \ return r; \ } \ ,) \ \ M_IF_METHOD(EQUAL, oplist)( \ static inline bool \ - M_C(name, _equal_p)(concurrent_t const out1, concurrent_t const out2) \ + M_F(name, _equal_p)(concurrent_t const out1, concurrent_t const out2) \ { \ M_C0NCURRENT_CONTRACT(out1); \ M_C0NCURRENT_CONTRACT(out2); \ if (M_UNLIKELY (out1 == out2)) return true; \ /* See comment above on mutal mutexs */ \ if (out1 < out2) { \ - M_C(name, _read_lock)(out1); \ - M_C(name, _read_lock)(out2); \ + M_F(name, _read_lock)(out1); \ + M_F(name, _read_lock)(out2); \ } else { \ - M_C(name, _read_lock)(out2); \ - M_C(name, _read_lock)(out1); \ + M_F(name, _read_lock)(out2); \ + M_F(name, _read_lock)(out1); \ } \ bool b = M_CALL_EQUAL(oplist, out1->data, out2->data); \ if (out1 < out2) { \ - M_C(name, _read_unlock)(out2); \ - M_C(name, _read_unlock)(out1); \ + M_F(name, _read_unlock)(out2); \ + M_F(name, _read_unlock)(out1); \ } else { \ - M_C(name, _read_unlock)(out1); \ - M_C(name, _read_unlock)(out2); \ + M_F(name, _read_unlock)(out1); \ + M_F(name, _read_unlock)(out2); \ } \ return b; \ } \ @@ -666,12 +666,12 @@ \ M_IF_METHOD(GET_KEY, oplist)( \ static inline bool \ - 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_F(name, _get_blocking)(M_GET_VALUE_TYPE oplist *out_data, const concurrent_t out, M_GET_KEY_TYPE oplist const key, bool blocking) \ { \ M_C0NCURRENT_CONTRACT(out); \ M_ASSERT (out_data != NULL); \ bool ret = false; \ - M_C(name, _read_lock)(out); \ + M_F(name, _read_lock)(out); \ while (true) { \ M_GET_VALUE_TYPE oplist *p = M_CALL_GET_KEY(oplist, out->data, key); \ if (p != NULL) { \ @@ -681,21 +681,21 @@ } \ if (blocking == false) break; \ /* No data: wait for a write to signal some data */ \ - M_C(name, _read_wait)(out); \ + M_F(name, _read_wait)(out); \ } \ - M_C(name, _read_unlock)(out); \ + M_F(name, _read_unlock)(out); \ return ret; \ } \ ,) \ \ M_IF_METHOD2(POP, EMPTY_P, oplist)( \ static inline bool \ - M_C(name, _pop_blocking)(M_GET_SUBTYPE oplist *p, concurrent_t out, bool blocking) \ + M_F(name, _pop_blocking)(M_GET_SUBTYPE oplist *p, concurrent_t out, bool blocking) \ { \ M_C0NCURRENT_CONTRACT(out); \ M_ASSERT (p != NULL); \ bool ret = false; \ - M_C(name, _write_lock)(out); \ + M_F(name, _write_lock)(out); \ while (true) { \ if (!M_CALL_EMPTY_P(oplist, out->data)) { \ M_CALL_POP(oplist, p, out->data); \ @@ -704,21 +704,21 @@ } \ if (blocking == false) break; \ /* No data: wait for a write to signal some data */ \ - M_C(name, _write_wait)(out); \ + M_F(name, _write_wait)(out); \ } \ - M_C(name, _write_unlock)(out); \ + M_F(name, _write_unlock)(out); \ return ret; \ } \ ,) \ \ M_IF_METHOD2(POP_MOVE, EMPTY_P, oplist)( \ static inline bool \ - M_C(name, _pop_move_blocking)(M_GET_SUBTYPE oplist *p, concurrent_t out, bool blocking) \ + M_F(name, _pop_move_blocking)(M_GET_SUBTYPE oplist *p, concurrent_t out, bool blocking) \ { \ M_C0NCURRENT_CONTRACT(out); \ M_ASSERT (p != NULL); \ bool ret = false; \ - M_C(name, _write_lock)(out); \ + M_F(name, _write_lock)(out); \ while (true) { \ if (!M_CALL_EMPTY_P(oplist, out->data)) { \ M_CALL_POP_MOVE(oplist, p, out->data); \ @@ -727,21 +727,21 @@ } \ if (blocking == false) break; \ /* No data: wait for a write to signal some data */ \ - M_C(name, _write_wait)(out); \ + M_F(name, _write_wait)(out); \ } \ - M_C(name, _write_unlock)(out); \ + M_F(name, _write_unlock)(out); \ return ret; \ } \ ,) \ \ M_IF_METHOD(HASH, oplist)( \ static inline size_t \ - M_C(name, _hash)(concurrent_t const out) \ + M_F(name, _hash)(concurrent_t const out) \ { \ M_C0NCURRENT_CONTRACT(out); \ - M_C(name, _read_lock)(out); \ + M_F(name, _read_lock)(out); \ size_t h = M_CALL_HASH(oplist, out->data); \ - M_C(name, _read_unlock)(out); \ + M_F(name, _read_unlock)(out); \ /* The hash is unchanged by the concurrent container */ \ return h; \ } \ @@ -766,7 +766,7 @@ - name: prefix to be used - type: type of the sub container - oplist: oplist of the type of the sub container - - concurrent_t: alias for M_C(name, _t) [ type of the container ] + - concurrent_t: alias for M_F(name, _t) [ type of the container ] */ #define M_C0NCURRENT_RP_DEF_P3(name, type, oplist, concurrent_t) \ M_C0NCURRENT_RP_DEF_TYPE(name, type, oplist, concurrent_t) \ @@ -777,8 +777,8 @@ /* Define the type of a RP concurrent container */ #define M_C0NCURRENT_RP_DEF_TYPE(name, type, oplist, concurrent_t) \ \ - typedef struct M_C(name, _s) { \ - struct M_C(name, _s) *self; \ + typedef struct M_F(name, _s) { \ + struct M_F(name, _s) *self; \ m_mutex_t lock; \ m_cond_t rw_done; \ size_t read_count; \ @@ -787,16 +787,16 @@ type data; \ } concurrent_t[1]; \ \ - typedef struct M_C(name, _s) *M_C(name, _ptr); \ - typedef const struct M_C(name, _s) *M_C(name, _srcptr); \ + typedef struct M_F(name, _s) *M_F(name, _ptr); \ + typedef const struct M_F(name, _s) *M_F(name, _srcptr); \ \ - typedef type M_C(name, _subtype_ct); \ + typedef type M_F(name, _subtype_ct); \ /* Define the internal services for the lock strategy of a RP container */ #define M_C0NCURRENT_RP_DEF_CORE(name, type, oplist, concurrent_t) \ \ static inline void \ - M_C(name, _internal_init)(concurrent_t out) \ + M_F(name, _internal_init)(concurrent_t out) \ { \ m_mutex_init(out->lock); \ m_cond_init(out->rw_done); \ @@ -808,7 +808,7 @@ } \ \ static inline void \ - M_C(name, _internal_clear)(concurrent_t out) \ + M_F(name, _internal_clear)(concurrent_t out) \ { \ M_C0NCURRENT_CONTRACT(out); \ m_mutex_clear(out->lock); \ @@ -818,10 +818,10 @@ } \ \ static inline void \ - M_C(name, _read_lock)(const concurrent_t out) \ + M_F(name, _read_lock)(const concurrent_t out) \ { \ M_C0NCURRENT_CONTRACT(out); \ - struct M_C(name, _s) *self = out->self; \ + struct M_F(name, _s) *self = out->self; \ m_mutex_lock (self->lock); \ while (self->writer_waiting == true) { \ m_cond_wait(self->rw_done, self->lock); \ @@ -831,10 +831,10 @@ } \ \ static inline void \ - M_C(name, _read_unlock)(const concurrent_t out) \ + M_F(name, _read_unlock)(const concurrent_t out) \ { \ M_C0NCURRENT_CONTRACT(out); \ - struct M_C(name, _s) *self = out->self; \ + struct M_F(name, _s) *self = out->self; \ m_mutex_lock (self->lock); \ self->read_count --; \ if (self->read_count == 0) { \ @@ -844,7 +844,7 @@ } \ \ static inline void \ - M_C(name, _write_lock)(concurrent_t out) \ + M_F(name, _write_lock)(concurrent_t out) \ { \ M_C0NCURRENT_CONTRACT(out); \ m_mutex_lock (out->lock); \ @@ -859,7 +859,7 @@ } \ \ static inline void \ - M_C(name, _write_unlock)(concurrent_t out) \ + M_F(name, _write_unlock)(concurrent_t out) \ { \ M_C0NCURRENT_CONTRACT(out); \ m_mutex_lock (out->lock); \ @@ -869,10 +869,10 @@ } \ \ static inline void \ - M_C(name, _read_wait)(const concurrent_t out) \ + M_F(name, _read_wait)(const concurrent_t out) \ { \ M_C0NCURRENT_CONTRACT(out); \ - struct M_C(name, _s) *self = out->self; \ + struct M_F(name, _s) *self = out->self; \ M_ASSERT (self == out); \ m_mutex_lock (out->self->lock); \ self->read_count --; \ @@ -888,7 +888,7 @@ } \ \ static inline void \ - M_C(name, _write_wait)(concurrent_t out) \ + M_F(name, _write_wait)(concurrent_t out) \ { \ M_C0NCURRENT_CONTRACT(out); \ m_mutex_lock (out->lock); \ @@ -906,7 +906,7 @@ } \ \ static inline void \ - M_C(name, _write_signal)(concurrent_t out) \ + M_F(name, _write_signal)(concurrent_t out) \ { \ M_C0NCURRENT_CONTRACT(out); \ m_mutex_lock (out->lock); \ diff --git a/m-core.h b/m-core.h index 4d06a3ec..d7577677 100644 --- a/m-core.h +++ b/m-core.h @@ -471,6 +471,23 @@ M_BEGIN_PROTECTED_CODE #define M_C4(a, b, c, ...) M_C4I(a ,b, c, __VA_ARGS__) +/* Generation of function name by concatenation + Can be ovverrided by user +*/ +#ifndef M_F +#define M_F(a, b) M_C2I(a, b) +#endif + +/* Concatenation of function name that enable developer to use customizaton + developer shall provide its own name customization by forcing M_F to it + then provide its own suffix in the namespace M_OVERRIDE_ ## suffix (): + Each generated suffix shall start with a comma. +#define M_F(a,b) M_OVERRIDE_F(a,b) +#define M_OVERRIDE__clear() , _cleanup , +#include "m-core.h" +*/ +#define M_OVERRIDE_F(a, b) M_C(a, M_RET_ARG2( M_C(M_OVERRIDE_, b)() , b)) + /* Inverse 0 into 1 and 1 into 0 */ #define M_INVI_0 1 #define M_INVI_1 0 @@ -3980,11 +3997,11 @@ m_core_parse2_enum (const char str[], const char **endptr) /* Default oplist for complex objects with "classic" names for methods. */ #define M_CLASSIC_OPLIST(name) ( \ - INIT(M_C(name, _init)), \ - INIT_SET(M_C(name, _init_set)), \ - SET(M_C(name, _set)), \ - CLEAR(M_C(name, _clear)), \ - TYPE(M_C(name, _t)) ) + INIT(M_F(name, _init)), \ + INIT_SET(M_F(name, _init_set)), \ + SET(M_F(name, _set)), \ + CLEAR(M_F(name, _clear)), \ + TYPE(M_F(name, _t)) ) /* OPLIST for 'const char *' string (with NO memory allocation). @@ -4698,11 +4715,11 @@ m_core_parse2_enum (const char str[], const char **endptr) #define M_EMPLACE_ASS_ARRAY_OR_QUEUE_DEF(isSet, name, name_t, key_oplist, val_oplist) \ M_ID( M_C(M_EMPLACE_ASS_ARRAY_OR_QUEUE_DEF, isSet)(name, name_t, key_oplist, val_oplist) ) #define M_EMPLACE_ASS_ARRAY_OR_QUEUE_DEF0(name, name_t, key_oplist, val_oplist) \ - M_EMPLACE_ASS_ARRAY_DEF(name, name_t, M_C(name, _emplace), key_oplist, val_oplist, M_EMPLACE_ASS_ARRA1_BOTH_GENE, M_EMPLACE_ASS_ARRA1_KEY_GENE, M_EMPLACE_ASS_ARRA1_VAL_GENE) \ - M_EMPLACE_QUEUE_DEF(name, name_t, M_C(name, _get_emplace), key_oplist, M_EMPLACE_GET_GENE) + M_EMPLACE_ASS_ARRAY_DEF(name, name_t, M_F(name, _emplace), key_oplist, val_oplist, M_EMPLACE_ASS_ARRA1_BOTH_GENE, M_EMPLACE_ASS_ARRA1_KEY_GENE, M_EMPLACE_ASS_ARRA1_VAL_GENE) \ + M_EMPLACE_QUEUE_DEF(name, name_t, M_F(name, _get_emplace), key_oplist, M_EMPLACE_GET_GENE) #define M_EMPLACE_ASS_ARRAY_OR_QUEUE_DEF1(name, name_t, key_oplist, val_oplist) \ - M_EMPLACE_QUEUE_DEF(name, name_t, M_C(name, _emplace), key_oplist, M_EMPLACE_QUEUE_GENE) \ - M_EMPLACE_QUEUE_DEF(name, name_t, M_C(name, _get_emplace), key_oplist, M_EMPLACE_GET_GENE) + M_EMPLACE_QUEUE_DEF(name, name_t, M_F(name, _emplace), key_oplist, M_EMPLACE_QUEUE_GENE) \ + M_EMPLACE_QUEUE_DEF(name, name_t, M_F(name, _get_emplace), key_oplist, M_EMPLACE_GET_GENE) /* Definition of the emplace_back function for associative arrays. @@ -4718,10 +4735,10 @@ m_core_parse2_enum (const char str[], const char **endptr) M_EMPLACE_LIST_TYPE_VAR(akey, key_emplace_type) \ M_EMPLACE_LIST_TYPE_VAR(aval, val_emplace_type) \ ){ \ - M_C(name, _key_ct) key; \ + M_F(name, _key_ct) key; \ M_EMPLACE_CALL_FUNC(akey, key_init_func, key_oplist, key, key_emplace_type); \ - M_C(name, _value_ct) *val; \ - val = M_C(name, _safe_get)(v, key); \ + M_F(name, _value_ct) *val; \ + val = M_F(name, _safe_get)(v, key); \ M_CALL_CLEAR(val_oplist, *val); \ M_EMPLACE_CALL_FUNC(aval, val_init_func, val_oplist, *val, val_emplace_type); \ M_CALL_CLEAR(key_oplist, key); \ @@ -4731,21 +4748,21 @@ m_core_parse2_enum (const char str[], const char **endptr) static inline void \ function_name(name_t v \ M_EMPLACE_LIST_TYPE_VAR(akey, key_emplace_type) \ - , M_C(name, _value_ct) const val \ + , M_F(name, _value_ct) const val \ ){ \ - M_C(name, _key_ct) key; \ + M_F(name, _key_ct) key; \ M_EMPLACE_CALL_FUNC(akey, key_init_func, key_oplist, key, key_emplace_type); \ - M_C(name, _set_at)(v, key, val); \ + M_F(name, _set_at)(v, key, val); \ M_CALL_CLEAR(key_oplist, key); \ } \ #define M_EMPLACE_ASS_ARRA1_VAL_GENE(name, name_t, function_name, key_oplist, val_oplist, key_init_func, val_init_func, key_emplace_type, val_emplace_type) \ static inline void \ - function_name(name_t v, M_C(name, _key_ct) const key \ + function_name(name_t v, M_F(name, _key_ct) const key \ M_EMPLACE_LIST_TYPE_VAR(aval, val_emplace_type) \ ){ \ - M_C(name, _value_ct) *val; \ - val = M_C(name, _safe_get)(v, key); \ + M_F(name, _value_ct) *val; \ + val = M_F(name, _safe_get)(v, key); \ M_CALL_CLEAR(val_oplist, *val); \ M_EMPLACE_CALL_FUNC(aval, val_init_func, val_oplist, *val, val_emplace_type); \ } \ @@ -4762,7 +4779,7 @@ m_core_parse2_enum (const char str[], const char **endptr) { \ M_GET_TYPE oplist data; \ M_EMPLACE_CALL_FUNC(a, init_func, oplist, data, exp_emplace_type); \ - M_C(name, _push)(v, data); \ + M_F(name, _push)(v, data); \ M_CALL_CLEAR(oplist, data); \ } @@ -4772,13 +4789,13 @@ m_core_parse2_enum (const char str[], const char **endptr) This definition is far from being efficient but works for the current interface. */ #define M_EMPLACE_GET_GENE(name, name_t, function_name, oplist, init_func, exp_emplace_type) \ - static inline M_C(name, _value_ct) * \ + static inline M_F(name, _value_ct) * \ function_name(name_t const v \ M_EMPLACE_LIST_TYPE_VAR(a, exp_emplace_type) ) \ { \ M_GET_TYPE oplist data; \ M_EMPLACE_CALL_FUNC(a, init_func, oplist, data, exp_emplace_type); \ - M_C(name, _value_ct) *ret = M_C(name, _get)(v, data); \ + M_F(name, _value_ct) *ret = M_F(name, _get)(v, data); \ M_CALL_CLEAR(oplist, data); \ return ret; \ } diff --git a/m-deque.h b/m-deque.h index dd100c65..7f73eaf3 100644 --- a/m-deque.h +++ b/m-deque.h @@ -30,7 +30,7 @@ /* Define a deque of a given type and its associated functions. USAGE: DEQUE_DEF(name, type [, oplist_of_the_type]) */ #define M_DEQUE_DEF(name, ...) \ - M_DEQUE_DEF_AS(name, M_C(name,_t), M_C(name,_it_t), __VA_ARGS__) + M_DEQUE_DEF_AS(name, M_F(name,_t), M_F(name,_it_t), __VA_ARGS__) /* Define a deque of a given type and its associated functions. @@ -39,8 +39,8 @@ #define M_DEQUE_DEF_AS(name, name_t, it_t, ...) \ M_BEGIN_PROTECTED_CODE \ M_D3QU3_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ - ((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t, it_t, M_C(name, _node_ct) ), \ - (name, __VA_ARGS__, name_t, it_t, M_C(name, _node_ct)))) \ + ((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t, it_t, M_F(name, _node_ct) ), \ + (name, __VA_ARGS__, name_t, it_t, M_F(name, _node_ct)))) \ M_END_PROTECTED_CODE @@ -91,16 +91,16 @@ - name: prefix to be used - type: type of the elements of the deque - oplist: oplist of the type of the elements of the container - - deque_t: alias for M_C(name, _t) [ type of the container ] - - it_t: alias for M_C(name, _it_t) [ iterator of the container ] + - deque_t: alias for M_F(name, _t) [ type of the container ] + - it_t: alias for M_F(name, _it_t) [ iterator of the container ] - node_t: alias for node_t [ node ] */ #define M_D3QU3_DEF_P3(name, type, oplist, deque_t, it_t, node_t) \ M_D3QU3_DEF_TYPE(name, type, oplist, deque_t, it_t, node_t) \ M_CHECK_COMPATIBLE_OPLIST(name, 1, type, oplist) \ M_D3QU3_DEF_CORE(name, type, oplist, deque_t, it_t, node_t) \ - M_EMPLACE_QUEUE_DEF(name, deque_t, M_C(name, _emplace_back), oplist, M_D3QUE_EMPLACE_BACK_DEF) \ - M_EMPLACE_QUEUE_DEF(name, deque_t, M_C(name, _emplace_front), oplist, M_D3QUE_EMPLACE_FRONT_DEF) + M_EMPLACE_QUEUE_DEF(name, deque_t, M_F(name, _emplace_back), oplist, M_D3QUE_EMPLACE_BACK_DEF) \ + M_EMPLACE_QUEUE_DEF(name, deque_t, M_F(name, _emplace_front), oplist, M_D3QUE_EMPLACE_FRONT_DEF) /* Define the types. It is a linked list of buckets of the types, @@ -114,8 +114,8 @@ */ #define M_D3QU3_DEF_TYPE(name, type, oplist, deque_t, it_t, node_t) \ \ - typedef struct M_C(name, _node_s) { \ - ILIST_INTERFACE(M_C(name, _node_list), struct M_C(name, _node_s)); \ + typedef struct M_F(name, _node_s) { \ + ILIST_INTERFACE(M_F(name, _node_list), struct M_F(name, _node_s)); \ size_t size; \ type data[M_MIN_FLEX_ARRAY_SIZE]; \ } node_t; \ @@ -127,13 +127,13 @@ The interfaces are compatible. \ */ \ /* FIXME: How can I separate public types and private implementation? */ \ - ILIST_DEF(M_C(name, _node_list), node_t, (DEL(M_GET_FREE oplist)) ) \ + ILIST_DEF(M_F(name, _node_list), node_t, (DEL(M_GET_FREE oplist)) ) \ \ /* Define an internal iterator */ \ - typedef struct M_C(name, _it2_s) { \ + typedef struct M_F(name, _it2_s) { \ node_t *node; \ size_t index; \ - } M_C(name, _it2_ct)[1]; \ + } M_F(name, _it2_ct)[1]; \ \ /* Define the deque type: \ - 'list' if the list of buckets containing the objects. \ @@ -142,29 +142,29 @@ - 'default_size' is the size used for the creation of a new bucket \ - 'count' is the number of elements in the container. \ */ \ - typedef struct M_C(name, _s) { \ - M_C(name, _node_list_t) list; \ - M_C(name, _it2_ct) front; \ - M_C(name, _it2_ct) back; \ + typedef struct M_F(name, _s) { \ + M_F(name, _node_list_t) list; \ + M_F(name, _it2_ct) front; \ + M_F(name, _it2_ct) back; \ size_t default_size; \ size_t count; \ } deque_t[1]; \ \ /* Define pointer alias */ \ - typedef struct M_C(name, _s) *M_C(name, _ptr); \ - typedef const struct M_C(name, _s) *M_C(name, _srcptr); \ + typedef struct M_F(name, _s) *M_F(name, _ptr); \ + typedef const struct M_F(name, _s) *M_F(name, _srcptr); \ \ /* Define the iterator object */ \ - typedef struct M_C(name, _it_s) { \ + typedef struct M_F(name, _it_s) { \ node_t *node; \ size_t index; \ - const struct M_C(name, _s) *deque; \ + const struct M_F(name, _s) *deque; \ } it_t[1]; \ \ /* Define internal types for oplist */ \ - typedef deque_t M_C(name, _ct); \ - typedef type M_C(name, _subtype_ct); \ - typedef it_t M_C(name, _it_ct); \ + typedef deque_t M_F(name, _ct); \ + typedef type M_F(name, _subtype_ct); \ + typedef it_t M_F(name, _it_ct); \ /* Define the core functions */ #define M_D3QU3_DEF_CORE(name, type, oplist, deque_t, it_t, node_t) \ @@ -189,7 +189,7 @@ } \ /* Initialize the node */ \ n->size = def; \ - M_C(name, _node_list_init_field)(n); \ + M_F(name, _node_list_init_field)(n); \ /* Increase the next bucket allocation */ \ /* Do not increase it too much if there are few items */ \ def = M_MIN(def, d->count); \ @@ -199,14 +199,14 @@ } \ \ static inline void \ - M_C(name, _init)(deque_t d) \ + M_F(name, _init)(deque_t d) \ { \ - M_C(name, _node_list_init)(d->list); \ + M_F(name, _node_list_init)(d->list); \ d->default_size = M_USE_DEQUE_DEFAULT_SIZE; \ d->count = 0; \ node_t *n = M_C3(m_d3qu3_,name,_new_node)(d); \ if (n == NULL) return; \ - M_C(name, _node_list_push_back)(d->list, n); \ + M_F(name, _node_list_push_back)(d->list, n); \ d->front->node = n; \ d->front->index = M_USE_DEQUE_DEFAULT_SIZE/2; \ d->back->node = n; \ @@ -215,14 +215,14 @@ } \ \ static inline void \ - M_C(name, _reset)(deque_t d) \ + M_F(name, _reset)(deque_t d) \ { \ M_D3QU3_CONTRACT(d); \ node_t *min_node = NULL; \ for(node_t *n = d->front->node; \ n != NULL ; \ n = (n == d->back->node) ? NULL : \ - M_C(name, _node_list_next_obj)(d->list, n) ){ \ + M_F(name, _node_list_next_obj)(d->list, n) ){ \ size_t min = n == d->front->node ? d->front->index : 0; \ size_t max = n == d->back->node ? d->back->index : n->size; \ for(size_t i = min; i < max; i++) { \ @@ -240,12 +240,12 @@ } \ \ static inline void \ - M_C(name, _clear)(deque_t d) \ + M_F(name, _clear)(deque_t d) \ { \ M_D3QU3_CONTRACT(d); \ - M_C(name, _reset)(d); \ + M_F(name, _reset)(d); \ /* We have registered the delete operator to clear all objects */ \ - M_C(name, _node_list_clear)(d->list); \ + M_F(name, _node_list_clear)(d->list); \ /* It is safer to clean some variables */ \ d->front->node = NULL; \ d->back->node = NULL; \ @@ -253,19 +253,19 @@ } \ \ static inline type * \ - M_C(name, _push_back_raw)(deque_t d) \ + M_F(name, _push_back_raw)(deque_t d) \ { \ M_D3QU3_CONTRACT(d); \ node_t *n = d->back->node; \ size_t index = d->back->index; \ if (M_UNLIKELY (n->size <= index)) { \ /* try to get an already allocated node */ \ - n = M_C(name, _node_list_next_obj)(d->list, n); \ + n = M_F(name, _node_list_next_obj)(d->list, n); \ if (n == NULL) { \ /* No node exists, allocate a new one */ \ n = M_C3(m_d3qu3_,name,_new_node)(d); \ if (M_UNLIKELY (n == NULL)) return NULL; \ - M_C(name, _node_list_push_back)(d->list, n); \ + M_F(name, _node_list_push_back)(d->list, n); \ } \ d->back->node = n; \ index = 0; \ @@ -280,15 +280,15 @@ \ /* Internal, for INIT_WITH */ \ static inline type * \ - M_C(name, _push_raw)(deque_t d) \ + M_F(name, _push_raw)(deque_t d) \ { \ - return M_C(name, _push_back_raw)(d); \ + return M_F(name, _push_back_raw)(d); \ } \ \ static inline void \ - M_C(name, _push_back)(deque_t d, type const x) \ + M_F(name, _push_back)(deque_t d, type const x) \ { \ - type *p = M_C(name, _push_back_raw)(d); \ + type *p = M_F(name, _push_back_raw)(d); \ if (M_LIKELY(p != NULL)) { \ M_CALL_INIT_SET(oplist, *p, x); \ } \ @@ -296,9 +296,9 @@ \ M_IF_METHOD(INIT, oplist)( \ static inline type * \ - M_C(name, _push_back_new)(deque_t d) \ + M_F(name, _push_back_new)(deque_t d) \ { \ - type *p = M_C(name, _push_back_raw)(d); \ + type *p = M_F(name, _push_back_raw)(d); \ if (M_LIKELY(p != NULL)) { \ M_CALL_INIT(oplist, *p); \ } \ @@ -307,17 +307,17 @@ , ) \ \ static inline void \ - M_C(name, _push_back_move)(deque_t d, type *x) \ + M_F(name, _push_back_move)(deque_t d, type *x) \ { \ M_ASSERT (x != NULL); \ - type *p = M_C(name, _push_back_raw)(d); \ + type *p = M_F(name, _push_back_raw)(d); \ if (M_UNLIKELY(p == NULL)) \ return; \ M_DO_INIT_MOVE (oplist, *p, *x); \ } \ \ static inline type* \ - M_C(name, _push_front_raw)(deque_t d) \ + M_F(name, _push_front_raw)(deque_t d) \ { \ M_D3QU3_CONTRACT(d); \ node_t *n = d->front->node; \ @@ -325,11 +325,11 @@ index --; \ /* If overflow */ \ if (M_UNLIKELY (n->size <= index)) { \ - n = M_C(name, _node_list_previous_obj)(d->list, n); \ + n = M_F(name, _node_list_previous_obj)(d->list, n); \ if (n == NULL) { \ n = M_C3(m_d3qu3_,name,_new_node)(d); \ if (M_UNLIKELY (n == NULL)) return NULL; \ - M_C(name, _node_list_push_front)(d->list, n); \ + M_F(name, _node_list_push_front)(d->list, n); \ } \ d->front->node = n; \ index = n->size -1; \ @@ -342,9 +342,9 @@ } \ \ static inline void \ - M_C(name, _push_front)(deque_t d, type const x) \ + M_F(name, _push_front)(deque_t d, type const x) \ { \ - type *p = M_C(name, _push_front_raw)(d); \ + type *p = M_F(name, _push_front_raw)(d); \ if (M_LIKELY(p != NULL)) { \ M_CALL_INIT_SET(oplist, *p, x); \ } \ @@ -352,9 +352,9 @@ \ M_IF_METHOD(INIT, oplist)( \ static inline type * \ - M_C(name, _push_front_new)(deque_t d) \ + M_F(name, _push_front_new)(deque_t d) \ { \ - type *p = M_C(name, _push_front_raw)(d); \ + type *p = M_F(name, _push_front_raw)(d); \ if (M_LIKELY(p != NULL)) { \ M_CALL_INIT(oplist, *p); \ } \ @@ -363,17 +363,17 @@ ,) \ \ static inline void \ - M_C(name, _push_front_move)(deque_t d, type *x) \ + M_F(name, _push_front_move)(deque_t d, type *x) \ { \ M_ASSERT (x != NULL); \ - type *p = M_C(name, _push_front_raw)(d); \ + type *p = M_F(name, _push_front_raw)(d); \ if (M_UNLIKELY(p == NULL)) \ return; \ M_DO_INIT_MOVE (oplist, *p, *x); \ } \ \ static inline void \ - M_C(name, _pop_back)(type *ptr, deque_t d) \ + M_F(name, _pop_back)(type *ptr, deque_t d) \ { \ M_D3QU3_CONTRACT(d); \ M_ASSERT(d->count > 0); \ @@ -384,13 +384,13 @@ /* If there is a next node, \ pop the back node and push it back to the front. This \ reduce the used memory if the deque is used as a FIFO queue.*/ \ - node_t *next = M_C(name, _node_list_next_obj)(d->list, n); \ + node_t *next = M_F(name, _node_list_next_obj)(d->list, n); \ if (next != NULL) { \ - next = M_C(name, _node_list_pop_back)(d->list); \ + next = M_F(name, _node_list_pop_back)(d->list); \ M_ASSERT (next != n); \ - M_C(name, _node_list_push_front)(d->list, next); \ + M_F(name, _node_list_push_front)(d->list, next); \ } \ - n = M_C(name, _node_list_previous_obj)(d->list, n); \ + n = M_F(name, _node_list_previous_obj)(d->list, n); \ M_ASSERT (n != NULL && n->size > 1); \ d->back->node = n; \ index = n->size-1; \ @@ -409,17 +409,17 @@ \ M_IF_METHOD(INIT, oplist)( \ static inline void \ - M_C(name, _pop_back_move)(type *ptr, deque_t d) \ + M_F(name, _pop_back_move)(type *ptr, deque_t d) \ { \ M_ASSERT(ptr != NULL); \ /* Note: Lazy implementation. Can be improved if needed */ \ M_CALL_INIT(oplist, *ptr); \ - M_C(name, _pop_back)(ptr, d); \ + M_F(name, _pop_back)(ptr, d); \ } \ , ) \ \ static inline void \ - M_C(name, _pop_front)(type *ptr, deque_t d) \ + M_F(name, _pop_front)(type *ptr, deque_t d) \ { \ M_D3QU3_CONTRACT(d); \ M_ASSERT(d->count > 0); \ @@ -437,14 +437,14 @@ /* If there is a previous node, \ pop the front node and push it back to the back. This \ recycles the used memory if the deque is used as a FIFO queue.*/ \ - node_t *prev = M_C(name, _node_list_previous_obj)(d->list, n); \ + node_t *prev = M_F(name, _node_list_previous_obj)(d->list, n); \ if (prev != NULL) { \ - prev = M_C(name, _node_list_pop_front)(d->list); \ + prev = M_F(name, _node_list_pop_front)(d->list); \ M_ASSERT (prev != n); \ - M_C(name, _node_list_push_back)(d->list, prev); \ + M_F(name, _node_list_push_back)(d->list, prev); \ } \ /* Update front iterator to point to the next object */ \ - n = M_C(name, _node_list_next_obj)(d->list, n); \ + n = M_F(name, _node_list_next_obj)(d->list, n); \ if (M_UNLIKELY(n == NULL)) { \ /* No next obj. \ It is only possible if there was only 1 element */ \ @@ -465,24 +465,24 @@ \ M_IF_METHOD(INIT, oplist)( \ static inline void \ - M_C(name, _pop_front_move)(type *ptr, deque_t d) \ + M_F(name, _pop_front_move)(type *ptr, deque_t d) \ { \ M_ASSERT(ptr != NULL); \ /* Note: Lazy implementation */ \ M_CALL_INIT(oplist, *ptr); \ - M_C(name, _pop_front)(ptr, d); \ + M_F(name, _pop_front)(ptr, d); \ } \ ,) \ \ static inline type * \ - M_C(name, _back)(const deque_t d) \ + M_F(name, _back)(const deque_t d) \ { \ M_D3QU3_CONTRACT(d); \ M_ASSERT (d->count > 0); \ size_t i = d->back->index; \ node_t *n = d->back->node; \ if (M_UNLIKELY (i == 0)) { \ - n = M_C(name, _node_list_previous_obj)(d->list, n); \ + n = M_F(name, _node_list_previous_obj)(d->list, n); \ M_ASSERT (n != NULL); \ i = n->size; \ } \ @@ -490,7 +490,7 @@ } \ \ static inline type * \ - M_C(name, _front)(const deque_t d) \ + M_F(name, _front)(const deque_t d) \ { \ M_D3QU3_CONTRACT(d); \ M_ASSERT (d->count > 0); \ @@ -500,55 +500,55 @@ } \ \ static inline size_t \ - M_C(name, _size)(const deque_t d) \ + M_F(name, _size)(const deque_t d) \ { \ M_D3QU3_CONTRACT(d); \ return d->count; \ } \ \ static inline size_t \ - M_C(name, _capacity_back)(const deque_t v) \ + M_F(name, _capacity_back)(const deque_t v) \ { \ M_D3QU3_CONTRACT(v); \ size_t s = 0; \ - for(node_t *n = M_C(name, _node_list_back)(v->list); \ + for(node_t *n = M_F(name, _node_list_back)(v->list); \ n != NULL ; \ n = (n == v->back->node) ? NULL : \ - M_C(name, _node_list_previous_obj)(v->list, n) ){ \ + M_F(name, _node_list_previous_obj)(v->list, n) ){ \ s += (n == v->back->node ? v->back->index : n->size); \ } \ return s; \ } \ \ static inline size_t \ - M_C(name, _capacity_front)(const deque_t v) \ + M_F(name, _capacity_front)(const deque_t v) \ { \ M_D3QU3_CONTRACT(v); \ size_t s = 0; \ - for(node_t *n = M_C(name, _node_list_front)(v->list); \ + for(node_t *n = M_F(name, _node_list_front)(v->list); \ n != NULL ; \ n = (n == v->front->node) ? NULL : \ - M_C(name, _node_list_next_obj)(v->list, n) ){ \ + M_F(name, _node_list_next_obj)(v->list, n) ){ \ s += n->size - (n == v->front->node ? v->front->index : 0); \ } \ return s; \ } \ \ static inline size_t \ - M_C(name, _capacity)(const deque_t v) \ + M_F(name, _capacity)(const deque_t v) \ { \ - return M_C(name, _capacity_back)(v)+M_C(name, _capacity_front)(v); \ + return M_F(name, _capacity_back)(v)+M_F(name, _capacity_front)(v); \ } \ \ static inline bool \ - M_C(name, _empty_p)(const deque_t d) \ + M_F(name, _empty_p)(const deque_t d) \ { \ M_D3QU3_CONTRACT(d); \ return d->count == 0; \ } \ \ static inline void \ - M_C(name, _it)(it_t it, const deque_t d) \ + M_F(name, _it)(it_t it, const deque_t d) \ { \ M_D3QU3_CONTRACT(d); \ M_ASSERT (it != NULL); \ @@ -558,7 +558,7 @@ } \ \ static inline void \ - M_C(name, _it_last)(it_t it, const deque_t d) \ + M_F(name, _it_last)(it_t it, const deque_t d) \ { \ M_D3QU3_CONTRACT(d); \ M_ASSERT (it != NULL); \ @@ -566,14 +566,14 @@ it->index = d->back->index - 1; \ it->deque = d; \ if (M_UNLIKELY (it->index >= it->node->size)) { \ - it->node = M_C(name, _node_list_previous_obj)(d->list, it->node); \ + it->node = M_F(name, _node_list_previous_obj)(d->list, it->node); \ M_ASSERT (it->node != NULL && it->node->size > 1); \ it->index = it->node->size-1; \ } \ } \ \ static inline void \ - M_C(name, _it_end)(it_t it, const deque_t d) \ + M_F(name, _it_end)(it_t it, const deque_t d) \ { \ M_D3QU3_CONTRACT(d); \ M_ASSERT (it != NULL); \ @@ -583,7 +583,7 @@ } \ \ static inline void \ - M_C(name, _it_set)(it_t it1, const it_t it2) \ + M_F(name, _it_set)(it_t it1, const it_t it2) \ { \ M_ASSERT (it1 != NULL); \ M_ASSERT (it2 != NULL); \ @@ -593,7 +593,7 @@ } \ \ static inline bool \ - M_C(name, _end_p)(it_t it) \ + M_F(name, _end_p)(it_t it) \ { \ M_ASSERT (it != NULL); \ return (it->node == it->deque->back->node \ @@ -603,13 +603,13 @@ } \ \ static inline void \ - M_C(name, _next)(it_t it) \ + M_F(name, _next)(it_t it) \ { \ M_ASSERT (it != NULL); \ node_t *n = it->node; \ it->index ++; \ if (M_UNLIKELY (it->index >= n->size)) { \ - n = M_C(name, _node_list_next_obj)(it->deque->list, n); \ + n = M_F(name, _node_list_next_obj)(it->deque->list, n); \ if (M_UNLIKELY (n == NULL || it->node == it->deque->back->node)) { \ /* Point to 'end' (can't undo it) */ \ it->node = it->deque->back->node; \ @@ -622,13 +622,13 @@ } \ \ static inline void \ - M_C(name, _previous)(it_t it) \ + M_F(name, _previous)(it_t it) \ { \ M_ASSERT (it != NULL); \ node_t *n = it->node; \ it->index --; \ if (M_UNLIKELY (it->index >= n->size)) { \ - n = M_C(name, _node_list_previous_obj)(it->deque->list, n); \ + n = M_F(name, _node_list_previous_obj)(it->deque->list, n); \ if (M_UNLIKELY (n == NULL || it->node == it->deque->front->node)) { \ /* Point to 'end' (can't undo it) */ \ it->node = it->deque->back->node; \ @@ -641,17 +641,17 @@ } \ \ static inline bool \ - M_C(name, _last_p)(it_t it) \ + M_F(name, _last_p)(it_t it) \ { \ M_ASSERT (it != NULL); \ it_t it2; \ - M_C(name, _it_set)(it2, it); \ - M_C(name, _next)(it2); \ - return M_C(name, _end_p)(it2); \ + M_F(name, _it_set)(it2, it); \ + M_F(name, _next)(it2); \ + return M_F(name, _end_p)(it2); \ } \ \ static inline bool \ - M_C(name, _it_equal_p)(it_t it1, const it_t it2) \ + M_F(name, _it_equal_p)(it_t it1, const it_t it2) \ { \ M_ASSERT (it1 != NULL); \ M_ASSERT (it2 != NULL); \ @@ -661,7 +661,7 @@ } \ \ static inline type * \ - M_C(name, _ref)(it_t it) \ + M_F(name, _ref)(it_t it) \ { \ M_ASSERT (it != NULL); \ M_ASSERT (it->index < it->node->size); \ @@ -669,7 +669,7 @@ } \ \ static inline type const * \ - M_C(name, _cref)(it_t it) \ + M_F(name, _cref)(it_t it) \ { \ M_ASSERT (it != NULL); \ M_ASSERT (it->index < it->node->size); \ @@ -677,7 +677,7 @@ } \ \ static inline void \ - M_C(name, _remove)(deque_t d, it_t it) \ + M_F(name, _remove)(deque_t d, it_t it) \ { \ M_D3QU3_CONTRACT(d); \ M_ASSERT (it != NULL && it->node != NULL); \ @@ -700,7 +700,7 @@ if (M_UNLIKELY (d->front->index == n->size -1)) { \ /* Node 'smart' deletion (single element) */ \ /* Update front iterator to point to the next object */ \ - n = M_C(name, _node_list_next_obj)(d->list, n); \ + n = M_F(name, _node_list_next_obj)(d->list, n); \ /* We must have a next element, as we have a different back node \ than the front node. */ \ M_ASSERT (n != NULL); \ @@ -714,16 +714,16 @@ sizeof(type) * (it->index - d->front->index)); \ d->front->index ++; \ /* The iterator shall reference the next element */ \ - M_C(name, _next)(it); \ + M_F(name, _next)(it); \ } \ } else { \ /* Nether front or end node */ \ if (M_UNLIKELY(n->size == 1)) { \ /* The iterator shall reference the next element */ \ - M_C(name, _next)(it); \ + M_F(name, _next)(it); \ /* Node deletion */ \ M_ASSERT(d->count > 1); \ - M_C(name, _node_list_unlink)(n); \ + M_F(name, _node_list_unlink)(n); \ M_CALL_FREE(oplist, n); \ } else { \ memmove(&n->data[it->index], &n->data[it->index+1], \ @@ -732,7 +732,7 @@ n->size --; \ /* The iterator points to the next element \ except if it was the last one*/ \ - if (M_UNLIKELY(it->index >= n->size)) M_C(name, _next)(it); \ + if (M_UNLIKELY(it->index >= n->size)) M_F(name, _next)(it); \ } \ } \ d->count--; \ @@ -740,25 +740,25 @@ } \ \ static inline void \ - M_C(name, _init_set)(deque_t d, const deque_t src) \ + M_F(name, _init_set)(deque_t d, const deque_t src) \ { \ M_D3QU3_CONTRACT(src); \ M_ASSERT (d != NULL); \ - M_C(name, _node_list_init)(d->list); \ + M_F(name, _node_list_init)(d->list); \ d->default_size = M_USE_DEQUE_DEFAULT_SIZE + src->count; \ d->count = src->count; \ node_t *n = M_C3(m_d3qu3_,name,_new_node)(d); \ if (n == NULL) return; \ d->default_size /= 2; \ - M_C(name, _node_list_push_back)(d->list, n); \ + M_F(name, _node_list_push_back)(d->list, n); \ d->front->node = n; \ d->front->index = M_USE_DEQUE_DEFAULT_SIZE/2; \ d->back->node = n; \ d->back->index = M_USE_DEQUE_DEFAULT_SIZE/2 + src->count; \ it_t it; \ size_t i = M_USE_DEQUE_DEFAULT_SIZE/2; \ - for(M_C(name, _it)(it, src); !M_C(name, _end_p)(it) ; M_C(name, _next)(it)) { \ - type const *obj = M_C(name, _cref)(it); \ + for(M_F(name, _it)(it, src); !M_F(name, _end_p)(it) ; M_F(name, _next)(it)) { \ + type const *obj = M_F(name, _cref)(it); \ M_CALL_INIT_SET(oplist, n->data[i], *obj); \ i++; \ M_ASSERT (i <= d->back->index); \ @@ -767,21 +767,21 @@ } \ \ static inline void \ - M_C(name, _set)(deque_t d, deque_t const src) \ + M_F(name, _set)(deque_t d, deque_t const src) \ { \ if (M_UNLIKELY (src == d)) \ return; \ /* TODO: Reuse memory of d! */ \ - M_C(name, _clear)(d); \ - M_C(name, _init_set)(d, src); \ + M_F(name, _clear)(d); \ + M_F(name, _init_set)(d, src); \ } \ \ static inline void \ - M_C(name, _init_move)(deque_t d, deque_t src) \ + M_F(name, _init_move)(deque_t d, deque_t src) \ { \ M_D3QU3_CONTRACT(src); \ M_ASSERT (d!= NULL); \ - M_C(name,_node_list_init_move)(d->list, src->list); \ + M_F(name,_node_list_init_move)(d->list, src->list); \ d->front->node = src->front->node; \ d->front->index = src->front->index; \ d->back->node = src->back->node; \ @@ -793,21 +793,21 @@ } \ \ static inline void \ - M_C(name, _move)(deque_t d, deque_t src) \ + M_F(name, _move)(deque_t d, deque_t src) \ { \ M_D3QU3_CONTRACT(d); \ M_D3QU3_CONTRACT(src); \ - M_C(name, _clear)(d); \ - M_C(name, _init_move)(d, src); \ + M_F(name, _clear)(d); \ + M_F(name, _init_move)(d, src); \ M_D3QU3_CONTRACT(d); \ } \ \ static inline void \ - M_C(name, _swap)(deque_t d, deque_t e) \ + M_F(name, _swap)(deque_t d, deque_t e) \ { \ M_D3QU3_CONTRACT(d); \ M_D3QU3_CONTRACT(e); \ - M_C(name, _node_list_swap) (d->list, e->list); \ + M_F(name, _node_list_swap) (d->list, e->list); \ M_SWAP(node_t *, d->front->node, e->front->node); \ M_SWAP(node_t *, d->back->node, e->back->node); \ M_SWAP(size_t, d->front->index, e->front->index); \ @@ -819,7 +819,7 @@ } \ \ static inline type* \ - M_C(name, _get)(deque_t d, size_t key) \ + M_F(name, _get)(deque_t d, size_t key) \ { \ M_D3QU3_CONTRACT(d); \ M_ASSERT_INDEX (key, d->count); \ @@ -828,7 +828,7 @@ /* This loop is in log(N) since the size increase exponentially.*/ \ for(node_t *n = d->front->node; true ; \ n = (n == d->back->node) ? NULL : \ - M_C(name, _node_list_next_obj)(d->list, n) ){ \ + M_F(name, _node_list_next_obj)(d->list, n) ){ \ M_ASSERT(n != NULL); \ if (index0 + key < count + n->size) { \ return &n->data[index0 + key - count]; \ @@ -838,24 +838,24 @@ } \ \ static inline type const * \ - M_C(name, _cget)(deque_t d, size_t key) \ + M_F(name, _cget)(deque_t d, size_t key) \ { \ - return M_CONST_CAST(type, M_C(name, _get)(d, key)); \ + return M_CONST_CAST(type, M_F(name, _get)(d, key)); \ } \ \ static inline void \ - M_C(name, _set_at)(deque_t d, size_t key, type const x) \ + M_F(name, _set_at)(deque_t d, size_t key, type const x) \ { \ M_D3QU3_CONTRACT(d); \ M_ASSERT_INDEX (key, d->count); \ - type *p = M_C(name, _get)(d, key); \ + type *p = M_F(name, _get)(d, key); \ M_CALL_SET(oplist, *p, x); \ M_D3QU3_CONTRACT(d); \ } \ \ M_IF_METHOD(EQUAL, oplist)( \ static inline bool \ - M_C(name, _equal_p)(const deque_t d1, const deque_t d2) \ + M_F(name, _equal_p)(const deque_t d1, const deque_t d2) \ { \ M_D3QU3_CONTRACT(d1); \ M_D3QU3_CONTRACT(d2); \ @@ -863,28 +863,28 @@ return false; \ it_t it1; \ it_t it2; \ - for(M_C(name, _it)(it1, d1), M_C(name,_it)(it2, d2); \ - !M_C(name, _end_p)(it1) ; \ - M_C(name, _next)(it1), M_C(name, _next)(it2)) { \ - type const *obj1 = M_C(name, _cref)(it1); \ - type const *obj2 = M_C(name, _cref)(it2); \ + for(M_F(name, _it)(it1, d1), M_F(name,_it)(it2, d2); \ + !M_F(name, _end_p)(it1) ; \ + M_F(name, _next)(it1), M_F(name, _next)(it2)) { \ + type const *obj1 = M_F(name, _cref)(it1); \ + type const *obj2 = M_F(name, _cref)(it2); \ if (M_CALL_EQUAL(oplist, *obj1, *obj2) == false) \ return false; \ } \ - M_ASSERT (M_C(name, _end_p)(it2)); \ + M_ASSERT (M_F(name, _end_p)(it2)); \ return true; \ } \ , /* NO EQUAL */) \ \ M_IF_METHOD(HASH, oplist)( \ static inline size_t \ - M_C(name, _hash)(const deque_t d) \ + M_F(name, _hash)(const deque_t d) \ { \ M_D3QU3_CONTRACT(d); \ M_HASH_DECL(hash); \ it_t it; \ - for(M_C(name, _it)(it, d); !M_C(name, _end_p)(it); M_C(name, _next)(it)) { \ - type const *obj = M_C(name, _cref)(it); \ + for(M_F(name, _it)(it, d); !M_F(name, _end_p)(it); M_F(name, _next)(it)) { \ + type const *obj = M_F(name, _cref)(it); \ M_HASH_UP (hash, M_CALL_HASH(oplist, *obj)); \ } \ return M_HASH_FINAL(hash); \ @@ -893,13 +893,13 @@ \ M_IF_METHOD(SWAP, oplist)( \ static inline void \ - M_C(name, _swap_at)(deque_t d, size_t i, size_t j) \ + M_F(name, _swap_at)(deque_t d, size_t i, size_t j) \ { \ M_D3QU3_CONTRACT(d); \ M_ASSERT_INDEX (i, d->count); \ M_ASSERT_INDEX (j, d->count); \ - type *obj1 = M_C(name, _get)(d, i); \ - type *obj2 = M_C(name, _get)(d, j); \ + type *obj1 = M_F(name, _get)(d, i); \ + type *obj2 = M_F(name, _get)(d, j); \ M_CALL_SWAP(oplist, *obj1, *obj2); \ M_D3QU3_CONTRACT(d); \ } \ @@ -907,17 +907,17 @@ \ M_IF_METHOD(GET_STR, oplist)( \ static inline void \ - M_C(name, _get_str)(m_string_t str, deque_t const deque, bool append) \ + M_F(name, _get_str)(m_string_t str, deque_t const deque, bool append) \ { \ M_D3QU3_CONTRACT(deque); \ (append ? m_string_cat_cstr : m_string_set_cstr) (str, "["); \ it_t it; \ - for (M_C(name, _it)(it, deque) ; \ - !M_C(name, _end_p)(it); \ - M_C(name, _next)(it)){ \ - type const *item = M_C(name, _cref)(it); \ + for (M_F(name, _it)(it, deque) ; \ + !M_F(name, _end_p)(it); \ + M_F(name, _next)(it)){ \ + type const *item = M_F(name, _cref)(it); \ M_CALL_GET_STR(oplist, str, *item, true); \ - if (!M_C(name, _last_p)(it)) \ + if (!M_F(name, _last_p)(it)) \ m_string_push_back (str, M_GET_SEPARATOR oplist); \ } \ m_string_push_back (str, ']'); \ @@ -926,18 +926,18 @@ \ M_IF_METHOD(OUT_STR, oplist)( \ static inline void \ - M_C(name, _out_str)(FILE *file, const deque_t deque) \ + M_F(name, _out_str)(FILE *file, const deque_t deque) \ { \ M_D3QU3_CONTRACT(deque); \ M_ASSERT (file != NULL); \ fputc ('[', file); \ it_t it; \ - for (M_C(name, _it)(it, deque) ; \ - !M_C(name, _end_p)(it); \ - M_C(name, _next)(it)) { \ - type const *item = M_C(name, _cref)(it); \ + for (M_F(name, _it)(it, deque) ; \ + !M_F(name, _end_p)(it); \ + M_F(name, _next)(it)) { \ + type const *item = M_F(name, _cref)(it); \ M_CALL_OUT_STR(oplist, file, *item); \ - if (!M_C(name, _last_p)(it)) \ + if (!M_F(name, _last_p)(it)) \ fputc (M_GET_SEPARATOR oplist, file); \ } \ fputc (']', file); \ @@ -946,11 +946,11 @@ \ M_IF_METHOD2(PARSE_STR, INIT, oplist)( \ static inline bool \ - M_C(name, _parse_str)(deque_t deque, const char str[], const char **endp) \ + M_F(name, _parse_str)(deque_t deque, const char str[], const char **endp) \ { \ M_D3QU3_CONTRACT(deque); \ M_ASSERT (str != NULL); \ - M_C(name,_reset)(deque); \ + M_F(name,_reset)(deque); \ bool success = false; \ int c = *str++; \ if (M_UNLIKELY (c != '[')) goto exit; \ @@ -964,7 +964,7 @@ bool b = M_CALL_PARSE_STR(oplist, item, str, &str); \ do { c = *str++; } while (isspace(c)); \ if (b == false || c == 0) { goto exit_clear; } \ - M_C(name, _push_back)(deque, item); \ + M_F(name, _push_back)(deque, item); \ } while (c == M_GET_SEPARATOR oplist); \ M_D3QU3_CONTRACT(deque); \ success = (c == ']'); \ @@ -978,11 +978,11 @@ \ M_IF_METHOD2(IN_STR, INIT, oplist)( \ static inline bool \ - M_C(name, _in_str)(deque_t deque, FILE *file) \ + M_F(name, _in_str)(deque_t deque, FILE *file) \ { \ M_D3QU3_CONTRACT(deque); \ M_ASSERT (file != NULL); \ - M_C(name,_reset)(deque); \ + M_F(name,_reset)(deque); \ int c = fgetc(file); \ if (M_UNLIKELY (c != '[')) return false; \ c = fgetc(file); \ @@ -995,7 +995,7 @@ bool b = M_CALL_IN_STR(oplist, item, file); \ do { c = fgetc(file); } while (isspace(c)); \ if (b == false || c == EOF) { break; } \ - M_C(name, _push_back)(deque, item); \ + M_F(name, _push_back)(deque, item); \ } while (c == M_GET_SEPARATOR oplist); \ M_CALL_CLEAR(oplist, item); \ M_D3QU3_CONTRACT(deque); \ @@ -1005,7 +1005,7 @@ \ M_IF_METHOD(OUT_SERIAL, oplist)( \ static inline m_serial_return_code_t \ - M_C(name, _out_serial)(m_serial_write_t f, const deque_t deque) \ + M_F(name, _out_serial)(m_serial_write_t f, const deque_t deque) \ { \ M_D3QU3_CONTRACT(deque); \ M_ASSERT (f != NULL && f->m_interface != NULL); \ @@ -1013,11 +1013,11 @@ m_serial_return_code_t ret; \ bool first_done = false; \ ret = f->m_interface->write_array_start(local, f, deque->count); \ - M_C(name, _it_ct) it; \ - for (M_C(name, _it)(it, deque) ; \ - !M_C(name, _end_p)(it); \ - M_C(name, _next)(it)){ \ - type const *item = M_C(name, _cref)(it); \ + M_F(name, _it_ct) it; \ + for (M_F(name, _it)(it, deque) ; \ + !M_F(name, _end_p)(it); \ + M_F(name, _next)(it)){ \ + type const *item = M_F(name, _cref)(it); \ if (first_done) \ ret |= f->m_interface->write_array_next(local, f); \ ret |= M_CALL_OUT_SERIAL(oplist, f, *item); \ @@ -1030,14 +1030,14 @@ \ M_IF_METHOD2(IN_SERIAL, INIT, oplist)( \ static inline m_serial_return_code_t \ - M_C(name, _in_serial)(deque_t deque, m_serial_read_t f) \ + M_F(name, _in_serial)(deque_t deque, m_serial_read_t f) \ { \ M_D3QU3_CONTRACT(deque); \ M_ASSERT (f != NULL && f->m_interface != NULL); \ m_serial_local_t local; \ m_serial_return_code_t ret; \ size_t estimated_size = 0; \ - M_C(name,_reset)(deque); \ + M_F(name,_reset)(deque); \ ret = f->m_interface->read_array_start(local, f, &estimated_size); \ if (M_UNLIKELY (ret != M_SERIAL_OK_CONTINUE)) return ret; \ type item; \ @@ -1045,7 +1045,7 @@ do { \ ret = M_CALL_IN_SERIAL(oplist, item, f); \ if (ret != M_SERIAL_OK_DONE) { break; } \ - M_C(name, _push_back)(deque, item); \ + M_F(name, _push_back)(deque, item); \ ret = f->m_interface->read_array_next(local, f); \ } while (ret == M_SERIAL_OK_CONTINUE); \ M_CALL_CLEAR(oplist, item); \ @@ -1059,7 +1059,7 @@ function_name(name_t v \ M_EMPLACE_LIST_TYPE_VAR(a, exp_emplace_type) ) \ { \ - M_C(name, _subtype_ct) *data = M_C(name, _push_back_raw)(v); \ + M_F(name, _subtype_ct) *data = M_F(name, _push_back_raw)(v); \ if (M_UNLIKELY (data == NULL) ) \ return; \ M_EMPLACE_CALL_FUNC(a, init_func, oplist, *data, exp_emplace_type); \ @@ -1072,7 +1072,7 @@ function_name(name_t v \ M_EMPLACE_LIST_TYPE_VAR(a, exp_emplace_type) ) \ { \ - M_C(name, _subtype_ct) *data = M_C(name, _push_front_raw)(v); \ + M_F(name, _subtype_ct) *data = M_F(name, _push_front_raw)(v); \ if (M_UNLIKELY (data == NULL) ) \ return; \ M_EMPLACE_CALL_FUNC(a, init_func, oplist, *data, exp_emplace_type); \ @@ -1095,44 +1095,44 @@ /* OPLIST definition of a deque */ #define M_D3QU3_OPLIST_P3(name, oplist) \ - (INIT(M_C(name, _init)) \ - ,INIT_SET(M_C(name, _init_set)) \ + (INIT(M_F(name, _init)) \ + ,INIT_SET(M_F(name, _init_set)) \ ,INIT_WITH(API_1(M_INIT_WITH_VAI)) \ - ,SET(M_C(name, _set)) \ - ,CLEAR(M_C(name, _clear)) \ - ,INIT_MOVE(M_C(name, _init_move)) \ - ,MOVE(M_C(name, _move)) \ - ,SWAP(M_C(name, _swap)) \ + ,SET(M_F(name, _set)) \ + ,CLEAR(M_F(name, _clear)) \ + ,INIT_MOVE(M_F(name, _init_move)) \ + ,MOVE(M_F(name, _move)) \ + ,SWAP(M_F(name, _swap)) \ ,NAME(name) \ - ,TYPE(M_C(name,_ct)) \ - ,SUBTYPE(M_C(name, _subtype_ct)) \ - ,EMPTY_P(M_C(name,_empty_p)) \ - ,IT_TYPE(M_C(name,_it_ct)) \ - ,IT_FIRST(M_C(name,_it)) \ - ,IT_LAST(M_C(name,_it_last)) \ - ,IT_END(M_C(name,_it_end)) \ - ,IT_SET(M_C(name,_it_set)) \ - ,IT_END_P(M_C(name,_end_p)) \ - ,IT_LAST_P(M_C(name,_last_p)) \ - ,IT_EQUAL_P(M_C(name,_it_equal_p)) \ - ,IT_NEXT(M_C(name,_next)) \ - ,IT_PREVIOUS(M_C(name,_previous)) \ - ,IT_REF(M_C(name,_ref)) \ - ,IT_CREF(M_C(name,_cref)) \ - ,IT_REMOVE(M_C(name,_remove)) \ - ,RESET(M_C(name,_reset)) \ - ,GET_SIZE(M_C(name, _size)) \ - ,PUSH(M_C(name,_push_back)) \ - ,POP(M_C(name,_pop_back)) \ + ,TYPE(M_F(name,_ct)) \ + ,SUBTYPE(M_F(name, _subtype_ct)) \ + ,EMPTY_P(M_F(name,_empty_p)) \ + ,IT_TYPE(M_F(name,_it_ct)) \ + ,IT_FIRST(M_F(name,_it)) \ + ,IT_LAST(M_F(name,_it_last)) \ + ,IT_END(M_F(name,_it_end)) \ + ,IT_SET(M_F(name,_it_set)) \ + ,IT_END_P(M_F(name,_end_p)) \ + ,IT_LAST_P(M_F(name,_last_p)) \ + ,IT_EQUAL_P(M_F(name,_it_equal_p)) \ + ,IT_NEXT(M_F(name,_next)) \ + ,IT_PREVIOUS(M_F(name,_previous)) \ + ,IT_REF(M_F(name,_ref)) \ + ,IT_CREF(M_F(name,_cref)) \ + ,IT_REMOVE(M_F(name,_remove)) \ + ,RESET(M_F(name,_reset)) \ + ,GET_SIZE(M_F(name, _size)) \ + ,PUSH(M_F(name,_push_back)) \ + ,POP(M_F(name,_pop_back)) \ ,OPLIST(oplist) \ - ,M_IF_METHOD(GET_STR, oplist)(GET_STR(M_C(name, _get_str)),) \ - ,M_IF_METHOD(PARSE_STR, oplist)(PARSE_STR(M_C(name, _parse_str)),) \ - ,M_IF_METHOD(OUT_STR, oplist)(OUT_STR(M_C(name, _out_str)),) \ - ,M_IF_METHOD(IN_STR, oplist)(IN_STR(M_C(name, _in_str)),) \ - ,M_IF_METHOD(OUT_SERIAL, oplist)(OUT_SERIAL(M_C(name, _out_serial)),) \ - ,M_IF_METHOD(IN_SERIAL, oplist)(IN_SERIAL(M_C(name, _in_serial)),) \ - ,M_IF_METHOD(EQUAL, oplist)(EQUAL(M_C(name, _equal_p)),) \ - ,M_IF_METHOD(HASH, oplist)(HASH(M_C(name, _hash)),) \ + ,M_IF_METHOD(GET_STR, oplist)(GET_STR(M_F(name, _get_str)),) \ + ,M_IF_METHOD(PARSE_STR, oplist)(PARSE_STR(M_F(name, _parse_str)),) \ + ,M_IF_METHOD(OUT_STR, oplist)(OUT_STR(M_F(name, _out_str)),) \ + ,M_IF_METHOD(IN_STR, oplist)(IN_STR(M_F(name, _in_str)),) \ + ,M_IF_METHOD(OUT_SERIAL, oplist)(OUT_SERIAL(M_F(name, _out_serial)),) \ + ,M_IF_METHOD(IN_SERIAL, oplist)(IN_SERIAL(M_F(name, _in_serial)),) \ + ,M_IF_METHOD(EQUAL, oplist)(EQUAL(M_F(name, _equal_p)),) \ + ,M_IF_METHOD(HASH, oplist)(HASH(M_F(name, _hash)),) \ ,M_IF_METHOD(NEW, oplist)(NEW(M_GET_NEW oplist),) \ ,M_IF_METHOD(REALLOC, oplist)(REALLOC(M_GET_REALLOC oplist),) \ ,M_IF_METHOD(DEL, oplist)(DEL(M_GET_DEL oplist),) \ diff --git a/m-dict.h b/m-dict.h index ac688e08..45090626 100644 --- a/m-dict.h +++ b/m-dict.h @@ -37,7 +37,7 @@ DICT_DEF2(name, key_type, value_type) */ #define M_DICT_DEF2(name, key_type, ...) \ - M_DICT_DEF2_AS(name, M_C(name,_t), M_C(name,_it_t), M_C(name,_itref_t), key_type, __VA_ARGS__) + M_DICT_DEF2_AS(name, M_F(name,_t), M_F(name,_it_t), M_F(name,_itref_t), key_type, __VA_ARGS__) /* Define a dictionary associating the key key_type to the value value_type and its associated functions. @@ -64,7 +64,7 @@ DICT_STOREHASH_DEF2(name, key_type[, key_oplist], value_type[, value_oplist]) */ #define M_DICT_STOREHASH_DEF2(name, key_type, ...) \ - M_DICT_STOREHASH_DEF2_AS(name, M_C(name,_t), M_C(name,_it_t), M_C(name,_itref_t), key_type, __VA_ARGS__) + M_DICT_STOREHASH_DEF2_AS(name, M_F(name,_t), M_F(name,_it_t), M_F(name,_itref_t), key_type, __VA_ARGS__) /* Define a dictionary asssociating the key key_type to the value value_type and its associated functions. @@ -93,7 +93,7 @@ DICT_OA_DEF2(name, key_type, value_type) */ #define M_DICT_OA_DEF2(name, key_type, ...) \ - M_DICT_OA_DEF2_AS(name, M_C(name,_t), M_C(name,_it_t), M_C(name,_itref_t), key_type, __VA_ARGS__) + M_DICT_OA_DEF2_AS(name, M_F(name,_t), M_F(name,_it_t), M_F(name,_itref_t), key_type, __VA_ARGS__) /* Define a dictionary associating the key key_type to the value value_type @@ -118,7 +118,7 @@ USAGE: DICT_SET_DEF(name, key_type[, key_oplist]) */ #define M_DICT_SET_DEF(name, ...) \ - M_DICT_SET_DEF_AS(name, M_C(name,_t), M_C(name,_it_t), __VA_ARGS__) + M_DICT_SET_DEF_AS(name, M_F(name,_t), M_F(name,_it_t), __VA_ARGS__) /* Define a set of the key key_type and its associated functions. @@ -129,8 +129,8 @@ #define M_DICT_SET_DEF_AS(name, name_t, it_t, ...) \ M_BEGIN_PROTECTED_CODE \ M_D1CT_SET_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ - ((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t, it_t, M_C(name, _itref_ct) ), \ - (name, __VA_ARGS__, name_t, it_t, M_C(name, _itref_ct) ))) \ + ((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t, it_t, M_F(name, _itref_ct) ), \ + (name, __VA_ARGS__, name_t, it_t, M_F(name, _itref_ct) ))) \ M_END_PROTECTED_CODE @@ -140,7 +140,7 @@ USAGE: DICT_OASET_DEF(name, key_type[, key_oplist]) */ #define M_DICT_OASET_DEF(name, ...) \ - M_DICT_OASET_DEF_AS(name, M_C(name,_t), M_C(name,_it_t), __VA_ARGS__) + M_DICT_OASET_DEF_AS(name, M_F(name,_t), M_F(name,_it_t), __VA_ARGS__) /* Define a set of the key key_type @@ -152,8 +152,8 @@ #define M_DICT_OASET_DEF_AS(name, name_t, it_t, ...) \ M_BEGIN_PROTECTED_CODE \ M_D1CT_OASET_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ - ((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t, it_t, M_C(name, _itref_ct) ), \ - (name, __VA_ARGS__, name_t, it_t, M_C(name, _itref_ct) ))) \ + ((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t, it_t, M_F(name, _itref_ct) ), \ + (name, __VA_ARGS__, name_t, it_t, M_F(name, _itref_ct) ))) \ M_END_PROTECTED_CODE @@ -206,10 +206,10 @@ M_CHECK_COMPATIBLE_OPLIST(name, 1, key_type, key_oplist) \ M_CHECK_COMPATIBLE_OPLIST(name, 2, value_type, value_oplist) \ \ - TUPLE_DEF2(M_C(name, _pair), (key, key_type, key_oplist), (value, value_type, value_oplist)) \ + TUPLE_DEF2(M_F(name, _pair), (key, key_type, key_oplist), (value, value_type, value_oplist)) \ \ M_D1CT_FUNC_DEF2_P5(name, key_type, key_oplist, value_type, value_oplist, \ - M_C(name, _pair_ct), TUPLE_OPLIST(M_C(name, _pair), key_oplist, value_oplist), 0, 0, \ + M_F(name, _pair_ct), TUPLE_OPLIST(M_F(name, _pair), key_oplist, value_oplist), 0, 0, \ dict_t, dict_it_t, it_deref_t ) @@ -238,10 +238,10 @@ M_CHECK_COMPATIBLE_OPLIST(name, 1, key_type, key_oplist) \ M_CHECK_COMPATIBLE_OPLIST(name, 2, value_type, value_oplist) \ \ - TUPLE_DEF2(M_C(name, _pair), (hash, size_t, M_BASIC_OPLIST), (key, key_type, key_oplist), (value, value_type, value_oplist)) \ + TUPLE_DEF2(M_F(name, _pair), (hash, size_t, M_BASIC_OPLIST), (key, key_type, key_oplist), (value, value_type, value_oplist)) \ \ M_D1CT_FUNC_DEF2_P5(name, key_type, key_oplist, value_type, value_oplist, \ - M_C(name, _pair_ct), TUPLE_OPLIST(M_C(name, _pair), M_BASIC_OPLIST, key_oplist, value_oplist), 0, 1, \ + M_F(name, _pair_ct), TUPLE_OPLIST(M_F(name, _pair), M_BASIC_OPLIST, key_oplist, value_oplist), 0, 1, \ dict_t, dict_it_t, it_deref_t ) @@ -263,10 +263,10 @@ \ M_CHECK_COMPATIBLE_OPLIST(name, 1, key_type, key_oplist) \ \ - TUPLE_DEF2(M_C(name, _pair), (key, key_type, key_oplist)) \ + TUPLE_DEF2(M_F(name, _pair), (key, key_type, key_oplist)) \ \ M_D1CT_FUNC_DEF2_P5(name, key_type, key_oplist, key_type, M_EMPTY_OPLIST, \ - M_C(name, _pair_ct), TUPLE_OPLIST(M_C(name, _pair), key_oplist), 1, 0, \ + M_F(name, _pair_ct), TUPLE_OPLIST(M_F(name, _pair), key_oplist), 1, 0, \ dict_t, dict_it_t, it_deref_t) @@ -294,128 +294,128 @@ /* Use memory allocator for bucket if needed */ \ M_IF_METHOD(MEMPOOL, key_oplist) \ ( \ - LIST_DEF(M_C(name, _list_pair), pair_type, \ + LIST_DEF(M_F(name, _list_pair), pair_type, \ M_OPEXTEND(pair_oplist, MEMPOOL(M_GET_MEMPOOL key_oplist), MEMPOOL_LINKAGE(M_GET_MEMPOOL_LINKAGE key_oplist))) \ , \ - LIST_DEF(M_C(name, _list_pair), pair_type, pair_oplist) \ + LIST_DEF(M_F(name, _list_pair), pair_type, pair_oplist) \ ) \ \ /* Define the array of list of buckets */ \ - ARRAY_DEF(M_C(name, _array_list_pair), M_C(name, _list_pair_ct), \ - LIST_OPLIST(M_C(name, _list_pair), pair_oplist)) \ + ARRAY_DEF(M_F(name, _array_list_pair), M_F(name, _list_pair_ct), \ + LIST_OPLIST(M_F(name, _list_pair), pair_oplist)) \ \ /* Define chained dict type */ \ - typedef struct M_C(name, _s) { \ + typedef struct M_F(name, _s) { \ size_t count, lower_limit, upper_limit; \ - M_C(name, _array_list_pair_ct) table; \ + M_F(name, _array_list_pair_ct) table; \ } dict_t[1]; \ \ - typedef struct M_C(name, _s) *M_C(name, _ptr); \ - typedef const struct M_C(name, _s) *M_C(name, _srcptr); \ + typedef struct M_F(name, _s) *M_F(name, _ptr); \ + typedef const struct M_F(name, _s) *M_F(name, _srcptr); \ \ /* Define iterator type */ \ - typedef struct M_C(name, _it_s) { \ - M_C(name, _array_list_pair_it_ct) array_it; \ - M_C(name, _list_pair_it_ct) list_it; \ + typedef struct M_F(name, _it_s) { \ + M_F(name, _array_list_pair_it_ct) array_it; \ + M_F(name, _list_pair_it_ct) list_it; \ } dict_it_t[1]; \ \ /* Define type returned by the _ref method of an iterator */ \ M_IF(isSet)( \ typedef key_type it_deref_t; \ , \ - typedef struct M_C(name, _pair_s) it_deref_t; \ + typedef struct M_F(name, _pair_s) it_deref_t; \ ) \ \ /* Define internal types for oplist */ \ - typedef dict_t M_C(name, _ct); \ - typedef it_deref_t M_C(name, _subtype_ct); \ - typedef key_type M_C(name, _key_ct); \ - typedef value_type M_C(name, _value_ct); \ - typedef dict_it_t M_C(name, _it_ct); \ + typedef dict_t M_F(name, _ct); \ + typedef it_deref_t M_F(name, _subtype_ct); \ + typedef key_type M_F(name, _key_ct); \ + typedef value_type M_F(name, _value_ct); \ + typedef dict_it_t M_F(name, _it_ct); \ \ static inline void \ - M_C(name, _init)(dict_t map) \ + M_F(name, _init)(dict_t map) \ { \ M_ASSERT (map != NULL); \ map->count = 0; \ - M_C(name, _array_list_pair_init)(map->table); \ - M_C(name, _array_list_pair_resize)(map->table, M_D1CT_INITIAL_SIZE); \ + M_F(name, _array_list_pair_init)(map->table); \ + M_F(name, _array_list_pair_resize)(map->table, M_D1CT_INITIAL_SIZE); \ map->lower_limit = M_D1CT_LOWER_BOUND(M_D1CT_INITIAL_SIZE); \ map->upper_limit = M_D1CT_UPPER_BOUND(M_D1CT_INITIAL_SIZE); \ M_D1CT_CONTRACT(name, map); \ } \ \ static inline void \ - M_C(name, _init_set)(dict_t map, const dict_t org) \ + M_F(name, _init_set)(dict_t map, const dict_t org) \ { \ M_D1CT_CONTRACT(name, org); \ M_ASSERT (map != org); \ map->count = org->count; \ map->lower_limit = org->lower_limit; \ map->upper_limit = org->upper_limit; \ - M_C(name, _array_list_pair_init_set)(map->table, org->table); \ + M_F(name, _array_list_pair_init_set)(map->table, org->table); \ M_D1CT_CONTRACT(name, map); \ } \ \ static inline void \ - M_C(name, _set)(dict_t map, const dict_t org) \ + M_F(name, _set)(dict_t map, const dict_t org) \ { \ M_D1CT_CONTRACT(name, map); \ M_D1CT_CONTRACT(name, org); \ map->count = org->count; \ map->lower_limit = org->lower_limit; \ map->upper_limit = org->upper_limit; \ - M_C(name, _array_list_pair_set)(map->table, org->table); \ + M_F(name, _array_list_pair_set)(map->table, org->table); \ M_D1CT_CONTRACT(name, map); \ } \ \ static inline void \ - M_C(name,_clear)(dict_t map) \ + M_F(name,_clear)(dict_t map) \ { \ M_D1CT_CONTRACT(name, map); \ - M_C(name, _array_list_pair_clear)(map->table); \ + M_F(name, _array_list_pair_clear)(map->table); \ } \ \ static inline void \ - M_C(name, _init_move)(dict_t map, dict_t org) \ + M_F(name, _init_move)(dict_t map, dict_t org) \ { \ M_D1CT_CONTRACT(name, org); \ map->count = org->count; \ map->lower_limit = org->lower_limit; \ map->upper_limit = org->upper_limit; \ - M_C(name, _array_list_pair_init_move)(map->table, org->table); \ + M_F(name, _array_list_pair_init_move)(map->table, org->table); \ M_D1CT_CONTRACT(name, map); \ } \ \ static inline void \ - M_C(name, _swap)(dict_t d1, dict_t d2) \ + M_F(name, _swap)(dict_t d1, dict_t d2) \ { \ M_D1CT_CONTRACT(name, d1); \ M_D1CT_CONTRACT(name, d2); \ M_SWAP (size_t, d1->count, d2->count); \ M_SWAP (size_t, d1->lower_limit, d2->lower_limit); \ M_SWAP (size_t, d1->upper_limit, d2->upper_limit); \ - M_C(name, _array_list_pair_swap)(d1->table, d2->table); \ + M_F(name, _array_list_pair_swap)(d1->table, d2->table); \ M_D1CT_CONTRACT(name, d1); \ M_D1CT_CONTRACT(name, d2); \ } \ \ static inline void \ - M_C(name, _move)(dict_t map, dict_t org) \ + M_F(name, _move)(dict_t map, dict_t org) \ { \ M_D1CT_CONTRACT(name, map); \ M_D1CT_CONTRACT(name, org); \ M_ASSERT (map != org); \ - M_C(name,_clear)(map); \ - M_C(name,_init_move)(map, org); \ + M_F(name,_clear)(map); \ + M_F(name,_init_move)(map, org); \ M_D1CT_CONTRACT(name, map); \ } \ \ static inline void \ - M_C(name,_reset)(dict_t map) \ + M_F(name,_reset)(dict_t map) \ { \ - M_C(name, _array_list_pair_reset)(map->table); \ - M_C(name, _array_list_pair_resize)(map->table, M_D1CT_INITIAL_SIZE); \ + M_F(name, _array_list_pair_reset)(map->table); \ + M_F(name, _array_list_pair_resize)(map->table, M_D1CT_INITIAL_SIZE); \ map->lower_limit = M_D1CT_LOWER_BOUND(M_D1CT_INITIAL_SIZE); \ map->upper_limit = M_D1CT_UPPER_BOUND(M_D1CT_INITIAL_SIZE); \ map->count = 0; \ @@ -423,18 +423,18 @@ } \ \ static inline value_type * \ - M_C(name, _get)(const dict_t map, key_type const key) \ + M_F(name, _get)(const dict_t map, key_type const key) \ { \ M_D1CT_CONTRACT(name, map); \ size_t hash = M_CALL_HASH(key_oplist, key); \ - size_t i = hash & (M_C(name, _array_list_pair_size)(map->table) - 1); \ - const M_C(name, _list_pair_ct) *list_ptr = \ - M_C(name, _array_list_pair_cget)(map->table, i); \ - M_C(name, _list_pair_it_ct) it; \ - for(M_C(name, _list_pair_it)(it, *list_ptr); \ - !M_C(name, _list_pair_end_p)(it); \ - M_C(name, _list_pair_next)(it)) { \ - pair_type *ref = M_C(name, _list_pair_ref)(it); \ + size_t i = hash & (M_F(name, _array_list_pair_size)(map->table) - 1); \ + const M_F(name, _list_pair_ct) *list_ptr = \ + M_F(name, _array_list_pair_cget)(map->table, i); \ + M_F(name, _list_pair_it_ct) it; \ + for(M_F(name, _list_pair_it)(it, *list_ptr); \ + !M_F(name, _list_pair_end_p)(it); \ + M_F(name, _list_pair_next)(it)) { \ + pair_type *ref = M_F(name, _list_pair_ref)(it); \ M_IF(isStoreHash)(if ((*ref)->hash != hash) { continue; }, ) \ if (M_CALL_EQUAL(key_oplist, (*ref)->key, key)) \ return &(*ref)->M_IF(isSet)(key, value); \ @@ -443,44 +443,44 @@ } \ \ static inline value_type const * \ - M_C(name, _cget)(const dict_t map, key_type const key) \ + M_F(name, _cget)(const dict_t map, key_type const key) \ { \ - return M_CONST_CAST(value_type, M_C(name,_get)(map,key)); \ + return M_CONST_CAST(value_type, M_F(name,_get)(map,key)); \ } \ \ static inline void \ M_C3(m_d1ct_,name,_resize_up)(dict_t map) \ { \ /* NOTE: Contract may not be fulfilled here */ \ - size_t old_size = M_C(name, _array_list_pair_size)(map->table); \ + size_t old_size = M_F(name, _array_list_pair_size)(map->table); \ size_t new_size = old_size * 2; \ if (M_UNLIKELY_NOMEM (new_size <= old_size)) { \ M_MEMORY_FULL((size_t)-1); \ } \ M_ASSERT (old_size > 1 && new_size > 1); \ /* Resize the table of the dictionnary */ \ - M_C(name, _array_list_pair_resize)(map->table, new_size); \ + M_F(name, _array_list_pair_resize)(map->table, new_size); \ /* Move the items to the new upper part */ \ for(size_t i = 0; i < old_size; i++) { \ - M_C(name, _list_pair_ct) *list = \ - M_C(name, _array_list_pair_get)(map->table, i); \ - if (M_C(name, _list_pair_empty_p)(*list)) \ + M_F(name, _list_pair_ct) *list = \ + M_F(name, _array_list_pair_get)(map->table, i); \ + if (M_F(name, _list_pair_empty_p)(*list)) \ continue; \ /* We need to scan each item and recompute its hash to know \ if it remains inplace or shall be moved to the upper part.*/ \ - M_C(name, _list_pair_it_ct) it; \ - M_C(name, _list_pair_it)(it, *list); \ - while (!M_C(name, _list_pair_end_p)(it)) { \ - M_C(name, _pair_ptr) pair = *M_C(name, _list_pair_ref)(it); \ + M_F(name, _list_pair_it_ct) it; \ + M_F(name, _list_pair_it)(it, *list); \ + while (!M_F(name, _list_pair_end_p)(it)) { \ + M_F(name, _pair_ptr) pair = *M_F(name, _list_pair_ref)(it); \ size_t hash = M_IF(isStoreHash)(pair->hash, M_CALL_HASH(key_oplist, pair->key)); \ if ((hash & (new_size-1)) >= old_size) { \ M_ASSERT( (hash & (new_size-1)) == (i + old_size)); \ - M_C(name, _list_pair_ct) *new_list = \ - M_C(name, _array_list_pair_get)(map->table, i + old_size); \ - M_C(name, _list_pair_splice_back)(*new_list, *list, it); \ + M_F(name, _list_pair_ct) *new_list = \ + M_F(name, _array_list_pair_get)(map->table, i + old_size); \ + M_F(name, _list_pair_splice_back)(*new_list, *list, it); \ /* Splice_back has updated the iterator to the next one */ \ } else { \ - M_C(name, _list_pair_next)(it); \ + M_F(name, _list_pair_next)(it); \ } \ } \ } \ @@ -492,50 +492,50 @@ M_C3(m_d1ct_,name,_resize_down)(dict_t map) \ { \ /* NOTE: Contract may not be fulfilled here */ \ - size_t old_size = M_C(name, _array_list_pair_size)(map->table); \ + size_t old_size = M_F(name, _array_list_pair_size)(map->table); \ M_ASSERT ((old_size % 2) == 0); \ size_t new_size = old_size / 2; \ M_ASSERT (new_size >= M_D1CT_INITIAL_SIZE); \ /* 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! */ \ for(size_t i = new_size; i < old_size; i++) { \ - M_C(name, _list_pair_ct) *list = \ - M_C(name, _array_list_pair_get)(map->table, i); \ - if (M_C(name, _list_pair_empty_p)(*list)) \ + M_F(name, _list_pair_ct) *list = \ + M_F(name, _array_list_pair_get)(map->table, i); \ + if (M_F(name, _list_pair_empty_p)(*list)) \ continue; \ - M_C(name, _list_pair_ct) *new_list = \ - M_C(name, _array_list_pair_get)(map->table, i - new_size); \ - M_C(name, _list_pair_splice)(*new_list, *list); \ + M_F(name, _list_pair_ct) *new_list = \ + M_F(name, _array_list_pair_get)(map->table, i - new_size); \ + M_F(name, _list_pair_splice)(*new_list, *list); \ } \ /* Resize the table of the dictionary */ \ - M_C(name, _array_list_pair_resize)(map->table, new_size); \ + M_F(name, _array_list_pair_resize)(map->table, new_size); \ map->upper_limit = M_D1CT_UPPER_BOUND(new_size); \ map->lower_limit = M_D1CT_LOWER_BOUND(new_size); \ } \ \ static inline void \ - M_IF(isSet)(M_C(name, _push), M_C(name, _set_at)) \ + M_IF(isSet)(M_F(name, _push), M_F(name, _set_at)) \ (dict_t map, key_type const key \ M_IF(isSet)(, M_DEFERRED_COMMA value_type const value)) \ { \ M_D1CT_CONTRACT(name, map); \ \ size_t hash = M_CALL_HASH(key_oplist, key); \ - size_t i = hash & (M_C(name, _array_list_pair_size)(map->table) - 1); \ - M_C(name, _list_pair_ct) *list_ptr = \ - M_C(name, _array_list_pair_get)(map->table, i); \ - M_C(name, _list_pair_it_ct) it; \ - for(M_C(name, _list_pair_it)(it, *list_ptr); \ - !M_C(name, _list_pair_end_p)(it); \ - M_C(name, _list_pair_next)(it)) { \ - M_C(name, _pair_ptr) ref = *M_C(name, _list_pair_ref)(it); \ + size_t i = hash & (M_F(name, _array_list_pair_size)(map->table) - 1); \ + M_F(name, _list_pair_ct) *list_ptr = \ + M_F(name, _array_list_pair_get)(map->table, i); \ + M_F(name, _list_pair_it_ct) it; \ + for(M_F(name, _list_pair_it)(it, *list_ptr); \ + !M_F(name, _list_pair_end_p)(it); \ + M_F(name, _list_pair_next)(it)) { \ + M_F(name, _pair_ptr) ref = *M_F(name, _list_pair_ref)(it); \ M_IF(isStoreHash)(if (ref->hash != hash) continue;, ) \ if (M_CALL_EQUAL(key_oplist,ref->key, key)) { \ M_CALL_SET(value_oplist, ref->value, value); \ return; \ } \ } \ - M_C(name, _pair_init_emplace)(*M_C(name, _list_pair_push_raw)(*list_ptr), \ + M_F(name, _pair_init_emplace)(*M_F(name, _list_pair_push_raw)(*list_ptr), \ M_IF(isStoreHash)(hash M_DEFERRED_COMMA,) \ key \ M_IF(isSet)(, M_DEFERRED_COMMA value)); \ @@ -546,27 +546,27 @@ } \ \ static inline value_type * \ - M_C(name, _safe_get)(dict_t map, key_type const key) \ + M_F(name, _safe_get)(dict_t map, key_type const key) \ { \ M_D1CT_CONTRACT(name, map); \ \ size_t hash = M_CALL_HASH(key_oplist, key); \ - size_t i = hash & (M_C(name, _array_list_pair_size)(map->table) - 1); \ - M_C(name, _list_pair_ct) *list_ptr = \ - M_C(name, _array_list_pair_get)(map->table, i); \ - M_C(name, _list_pair_it_ct) it; \ - for(M_C(name, _list_pair_it)(it, *list_ptr); \ - !M_C(name, _list_pair_end_p)(it); \ - M_C(name, _list_pair_next)(it)) { \ - M_C(name, _pair_ptr) ref = *M_C(name, _list_pair_ref)(it); \ + size_t i = hash & (M_F(name, _array_list_pair_size)(map->table) - 1); \ + M_F(name, _list_pair_ct) *list_ptr = \ + M_F(name, _array_list_pair_get)(map->table, i); \ + M_F(name, _list_pair_it_ct) it; \ + for(M_F(name, _list_pair_it)(it, *list_ptr); \ + !M_F(name, _list_pair_end_p)(it); \ + M_F(name, _list_pair_next)(it)) { \ + M_F(name, _pair_ptr) ref = *M_F(name, _list_pair_ref)(it); \ M_IF(isStoreHash)(if (ref->hash != hash) continue;, ) \ if (M_CALL_EQUAL(key_oplist, ref->key, key)) { \ return &ref->M_IF(isSet)(key, value); \ } \ } \ - pair_type *ref = M_C(name, _list_pair_push_new)(*list_ptr); \ - M_IF(isStoreHash)(M_C(name, _pair_set_hash)(*ref, hash);,) \ - M_C(name, _pair_set_key)(*ref, key); \ + pair_type *ref = M_F(name, _list_pair_push_new)(*list_ptr); \ + M_IF(isStoreHash)(M_F(name, _pair_set_hash)(*ref, hash);,) \ + M_F(name, _pair_set_key)(*ref, key); \ map->count ++; \ if (M_UNLIKELY (map->count > map->upper_limit) ) { \ M_C3(m_d1ct_,name,_resize_up)(map); \ @@ -579,23 +579,23 @@ } \ \ static inline bool \ - M_C(name, _erase)(dict_t map, key_type const key) \ + M_F(name, _erase)(dict_t map, key_type const key) \ { \ M_D1CT_CONTRACT(name, map); \ \ bool ret = false; \ size_t hash = M_CALL_HASH(key_oplist, key); \ - size_t i = hash & (M_C(name, _array_list_pair_size)(map->table) - 1); \ - M_C(name, _list_pair_ct) *list_ptr = \ - M_C(name, _array_list_pair_get)(map->table, i); \ - M_C(name, _list_pair_it_ct) it; \ - for(M_C(name, _list_pair_it)(it, *list_ptr); \ - !M_C(name, _list_pair_end_p)(it); \ - M_C(name, _list_pair_next)(it)) { \ - M_C(name, _pair_ptr) ref = *M_C(name, _list_pair_ref)(it); \ + size_t i = hash & (M_F(name, _array_list_pair_size)(map->table) - 1); \ + M_F(name, _list_pair_ct) *list_ptr = \ + M_F(name, _array_list_pair_get)(map->table, i); \ + M_F(name, _list_pair_it_ct) it; \ + for(M_F(name, _list_pair_it)(it, *list_ptr); \ + !M_F(name, _list_pair_end_p)(it); \ + M_F(name, _list_pair_next)(it)) { \ + M_F(name, _pair_ptr) ref = *M_F(name, _list_pair_ref)(it); \ M_IF(isStoreHash)(if (ref->hash != hash) continue;, ) \ if (M_CALL_EQUAL(key_oplist, ref->key, key)) { \ - M_C(name, _list_pair_remove)(*list_ptr, it); \ + M_F(name, _list_pair_remove)(*list_ptr, it); \ map->count --; \ ret = true; \ break; \ @@ -607,99 +607,99 @@ } \ \ static inline void \ - M_C(name, _it)(dict_it_t it, const dict_t d) \ + M_F(name, _it)(dict_it_t it, const dict_t d) \ { \ M_D1CT_CONTRACT(name, d); \ - M_C(name, _array_list_pair_it)(it->array_it, d->table); \ - M_C(name, _list_pair_ct) *ref = \ - M_C(name, _array_list_pair_ref)(it->array_it); \ - M_C(name, _list_pair_it)(it->list_it, *ref); \ - while (M_C(name, _list_pair_end_p)(it->list_it)) { \ - M_C(name, _array_list_pair_next)(it->array_it); \ - if (M_UNLIKELY (M_C(name, _array_list_pair_end_p)(it->array_it))) \ + M_F(name, _array_list_pair_it)(it->array_it, d->table); \ + M_F(name, _list_pair_ct) *ref = \ + M_F(name, _array_list_pair_ref)(it->array_it); \ + M_F(name, _list_pair_it)(it->list_it, *ref); \ + while (M_F(name, _list_pair_end_p)(it->list_it)) { \ + M_F(name, _array_list_pair_next)(it->array_it); \ + if (M_UNLIKELY (M_F(name, _array_list_pair_end_p)(it->array_it))) \ break; \ - ref = M_C(name, _array_list_pair_ref)(it->array_it); \ - M_C(name, _list_pair_it)(it->list_it, *ref); \ + ref = M_F(name, _array_list_pair_ref)(it->array_it); \ + M_F(name, _list_pair_it)(it->list_it, *ref); \ } \ } \ \ static inline void \ - M_C(name, _it_set)(dict_it_t it, const dict_it_t ref) \ + M_F(name, _it_set)(dict_it_t it, const dict_it_t ref) \ { \ M_ASSERT (it != NULL && ref != NULL); \ - M_C(name, _array_list_pair_it_set)(it->array_it, \ + M_F(name, _array_list_pair_it_set)(it->array_it, \ ref->array_it); \ - M_C(name, _list_pair_it_set)(it->list_it, ref->list_it); \ + M_F(name, _list_pair_it_set)(it->list_it, ref->list_it); \ } \ \ static inline void \ - M_C(name, _it_end)(dict_it_t it, const dict_t d) \ + M_F(name, _it_end)(dict_it_t it, const dict_t d) \ { \ M_D1CT_CONTRACT(name, d); \ - M_C(name, _array_list_pair_it_end)(it->array_it, d->table); \ + M_F(name, _array_list_pair_it_end)(it->array_it, d->table); \ } \ \ static inline bool \ - M_C(name, _end_p)(const dict_it_t it) \ + M_F(name, _end_p)(const dict_it_t it) \ { \ M_ASSERT (it != NULL); \ - return M_C(name, _list_pair_end_p)(it->list_it); \ + return M_F(name, _list_pair_end_p)(it->list_it); \ } \ \ static inline void \ - M_C(name, _next)(dict_it_t it) \ + M_F(name, _next)(dict_it_t it) \ { \ M_ASSERT(it != NULL); \ - M_C(name, _list_pair_next)(it->list_it); \ - M_C(name, _list_pair_ct) *ref; \ - while (M_C(name, _list_pair_end_p)(it->list_it)) { \ - M_C(name, _array_list_pair_next)(it->array_it); \ - if (M_C(name, _array_list_pair_end_p)(it->array_it)) \ + M_F(name, _list_pair_next)(it->list_it); \ + M_F(name, _list_pair_ct) *ref; \ + while (M_F(name, _list_pair_end_p)(it->list_it)) { \ + M_F(name, _array_list_pair_next)(it->array_it); \ + if (M_F(name, _array_list_pair_end_p)(it->array_it)) \ break; \ - ref = M_C(name, _array_list_pair_ref)(it->array_it); \ - M_C(name, _list_pair_it)(it->list_it, *ref); \ + ref = M_F(name, _array_list_pair_ref)(it->array_it); \ + M_F(name, _list_pair_it)(it->list_it, *ref); \ } \ } \ \ static inline bool \ - M_C(name, _last_p)(const dict_it_t it) \ + M_F(name, _last_p)(const dict_it_t it) \ { \ M_ASSERT (it != NULL); \ dict_it_t it2; \ - M_C(name,_it_set)(it2, it); \ - M_C(name, _next)(it2); \ - return M_C(name, _end_p)(it2); \ + M_F(name,_it_set)(it2, it); \ + M_F(name, _next)(it2); \ + return M_F(name, _end_p)(it2); \ } \ \ static inline bool \ - M_C(name, _it_equal_p)(const dict_it_t it1, const dict_it_t it2) \ + M_F(name, _it_equal_p)(const dict_it_t it1, const dict_it_t it2) \ { \ M_ASSERT (it1 != NULL && it2 != NULL); \ - return M_C(name, _list_pair_it_equal_p)(it1->list_it, \ + return M_F(name, _list_pair_it_equal_p)(it1->list_it, \ it2->list_it); \ } \ \ static inline it_deref_t * \ - M_C(name, _ref)(const dict_it_t it) \ + M_F(name, _ref)(const dict_it_t it) \ { \ M_ASSERT(it != NULL); \ /* NOTE: partially unsafe if the user modify the 'key' \ in a non equivalent way */ \ M_IF(isSet)( \ - return &(*M_C(name, _list_pair_ref)(it->list_it))->key; \ + return &(*M_F(name, _list_pair_ref)(it->list_it))->key; \ , \ - return *M_C(name, _list_pair_ref)(it->list_it); \ + return *M_F(name, _list_pair_ref)(it->list_it); \ ) \ } \ \ static inline const it_deref_t * \ - M_C(name, _cref)(const dict_it_t it) \ + M_F(name, _cref)(const dict_it_t it) \ { \ M_ASSERT(it != NULL); \ M_IF(isSet)( \ - return &(*M_C(name, _list_pair_cref)(it->list_it))->key; \ + return &(*M_F(name, _list_pair_cref)(it->list_it))->key; \ , \ - return *M_C(name, _list_pair_cref)(it->list_it); \ + return *M_F(name, _list_pair_cref)(it->list_it); \ ) \ } \ \ @@ -734,14 +734,14 @@ #define M_D1CT_FUNC_ADDITIONAL_DEF2(name, key_type, key_oplist, value_type, value_oplist, isSet, dict_t, dict_it_t, it_deref_t) \ \ static inline bool \ - M_C(name,_empty_p)(const dict_t map) \ + M_F(name,_empty_p)(const dict_t map) \ { \ M_ASSERT(map != NULL); \ return map->count == 0; \ } \ \ static inline size_t \ - M_C(name,_size)(const dict_t map) \ + M_F(name,_size)(const dict_t map) \ { \ M_ASSERT(map != NULL); \ return map->count; \ @@ -749,7 +749,7 @@ \ M_IF_METHOD(EQUAL, value_oplist)( \ static inline bool \ - M_C(name, _equal_p)(const dict_t dict1, const dict_t dict2) \ + M_F(name, _equal_p)(const dict_t dict1, const dict_t dict2) \ { \ M_ASSERT (dict1 != NULL && dict2 != NULL); \ /* NOTE: Key type has mandatory equal operator */ \ @@ -763,11 +763,11 @@ still the dictionaries shall be equal as they contain the same \ items. */ \ dict_it_t it; \ - for(M_C(name, _it)(it, dict1) ; \ - !M_C(name, _end_p)(it); \ - M_C(name, _next)(it)) { \ - const it_deref_t *item = M_C(name, _cref)(it); \ - value_type *ptr = M_C(name, _get)(dict2, M_IF(isSet)(*item, item->key)); \ + for(M_F(name, _it)(it, dict1) ; \ + !M_F(name, _end_p)(it); \ + M_F(name, _next)(it)) { \ + const it_deref_t *item = M_F(name, _cref)(it); \ + value_type *ptr = M_F(name, _get)(dict2, M_IF(isSet)(*item, item->key)); \ if (ptr == NULL) \ return false; \ if (M_CALL_EQUAL(value_oplist, item->value, *ptr) == false) \ @@ -779,17 +779,17 @@ \ M_IF_METHOD_BOTH(GET_STR, key_oplist, value_oplist)( \ static inline void \ - M_C(name, _get_str)(m_string_t str, const dict_t dict, const bool append) \ + M_F(name, _get_str)(m_string_t str, const dict_t dict, const bool append) \ { \ (append ? m_string_cat_cstr : m_string_set_cstr) (str, "{"); \ dict_it_t it; \ bool print_comma = false; \ - for (M_C(name, _it)(it, dict) ; \ - !M_C(name, _end_p)(it); \ - M_C(name, _next)(it)){ \ + for (M_F(name, _it)(it, dict) ; \ + !M_F(name, _end_p)(it); \ + M_F(name, _next)(it)){ \ if (print_comma) \ m_string_push_back (str, ','); \ - const it_deref_t *item = M_C(name, _cref)(it); \ + const it_deref_t *item = M_F(name, _cref)(it); \ M_IF(isSet)( \ M_CALL_GET_STR(key_oplist, str, *item, true); \ , \ @@ -805,18 +805,18 @@ \ M_IF_METHOD_BOTH(OUT_STR, key_oplist, value_oplist)( \ static inline void \ - M_C(name, _out_str)(FILE *file, const dict_t dict) \ + M_F(name, _out_str)(FILE *file, const dict_t dict) \ { \ M_ASSERT (file != NULL); \ fputc ('{', file); \ dict_it_t it; \ bool print_comma = false; \ - for (M_C(name, _it)(it, dict) ; \ - !M_C(name, _end_p)(it); \ - M_C(name, _next)(it)){ \ + for (M_F(name, _it)(it, dict) ; \ + !M_F(name, _end_p)(it); \ + M_F(name, _next)(it)){ \ if (print_comma) \ fputc (',', file); \ - const it_deref_t *item = M_C(name, _cref)(it); \ + const it_deref_t *item = M_F(name, _cref)(it); \ M_IF(isSet)( \ M_CALL_OUT_STR(key_oplist, file, *item); \ , \ @@ -832,10 +832,10 @@ \ M_IF_METHOD_BOTH(PARSE_STR, key_oplist, value_oplist)( \ static inline bool \ - M_C(name, _parse_str)(dict_t dict, const char str[], const char **endp) \ + M_F(name, _parse_str)(dict_t dict, const char str[], const char **endp) \ { \ M_ASSERT (str != NULL); \ - M_C(name, _reset)(dict); \ + M_F(name, _reset)(dict); \ bool success = false; \ int c = m_core_str_nospace(&str); \ if (M_UNLIKELY (c != '{')) { goto exit; } \ @@ -853,7 +853,7 @@ bool b = M_CALL_PARSE_STR(key_oplist, key, str, &str); \ M_IF(isSet)( \ if (b == false) { goto exit_clear; } \ - M_C(name, _push)(dict, key); \ + M_F(name, _push)(dict, key); \ , \ c = m_core_str_nospace(&str); \ if (b == false || c != ':') { goto exit_clear; } \ @@ -861,7 +861,7 @@ str--; \ b = M_CALL_PARSE_STR(value_oplist, value, str, &str); \ if (b == false) { goto exit_clear; } \ - M_C(name, _set_at)(dict, key, value); \ + M_F(name, _set_at)(dict, key, value); \ ) \ c = m_core_str_nospace(&str); \ } while (c == ','); \ @@ -877,10 +877,10 @@ \ M_IF_METHOD_BOTH(IN_STR, key_oplist, value_oplist)( \ static inline bool \ - M_C(name, _in_str)(dict_t dict, FILE *file) \ + M_F(name, _in_str)(dict_t dict, FILE *file) \ { \ M_ASSERT (file != NULL); \ - M_C(name, _reset)(dict); \ + M_F(name, _reset)(dict); \ int c = m_core_fgetc_nospace(file); \ if (M_UNLIKELY (c != '{')) return false; \ c = m_core_fgetc_nospace(file); \ @@ -898,7 +898,7 @@ bool b = M_CALL_IN_STR(key_oplist, key, file); \ M_IF(isSet)( \ if (M_UNLIKELY (b == false)) { break; } \ - M_C(name, _push)(dict, key); \ + M_F(name, _push)(dict, key); \ , \ c = m_core_fgetc_nospace(file); \ if (M_UNLIKELY (b == false || c != ':')) { c = 0; break; } \ @@ -907,7 +907,7 @@ ungetc(c, file); \ b = M_CALL_IN_STR(value_oplist, value, file); \ if (M_UNLIKELY (b == false)) { c = 0; break; } \ - M_C(name, _set_at)(dict, key, value); \ + M_F(name, _set_at)(dict, key, value); \ ) \ c = m_core_fgetc_nospace(file); \ } while (c == ','); \ @@ -919,7 +919,7 @@ \ M_IF_METHOD_BOTH(OUT_SERIAL, key_oplist, value_oplist)( \ static inline m_serial_return_code_t \ - M_C(name, _out_serial)(m_serial_write_t f, dict_t const t1) \ + M_F(name, _out_serial)(m_serial_write_t f, dict_t const t1) \ { \ M_ASSERT (f != NULL && f->m_interface != NULL); \ m_serial_local_t local; \ @@ -930,11 +930,11 @@ /* Format is different between associative container \ & set container */ \ M_IF(isSet)( \ - ret = f->m_interface->write_array_start(local, f, M_C(name, _size)(t1)); \ - for (M_C(name, _it)(it, t1) ; \ - !M_C(name, _end_p)(it); \ - M_C(name, _next)(it)){ \ - item = M_C(name, _cref)(it); \ + ret = f->m_interface->write_array_start(local, f, M_F(name, _size)(t1)); \ + for (M_F(name, _it)(it, t1) ; \ + !M_F(name, _end_p)(it); \ + M_F(name, _next)(it)){ \ + item = M_F(name, _cref)(it); \ if (first_done) \ ret |= f->m_interface->write_array_next(local, f); \ ret |= M_CALL_OUT_SERIAL(key_oplist, f, *item); \ @@ -942,11 +942,11 @@ } \ ret |= f->m_interface->write_array_end(local, f); \ , \ - ret = f->m_interface->write_map_start(local, f, M_C(name, _size)(t1)); \ - for (M_C(name, _it)(it, t1) ; \ - !M_C(name, _end_p)(it); \ - M_C(name, _next)(it)){ \ - item = M_C(name, _cref)(it); \ + ret = f->m_interface->write_map_start(local, f, M_F(name, _size)(t1)); \ + for (M_F(name, _it)(it, t1) ; \ + !M_F(name, _end_p)(it); \ + M_F(name, _next)(it)){ \ + item = M_F(name, _cref)(it); \ if (first_done) \ ret |= f->m_interface->write_map_next(local, f); \ ret |= M_CALL_OUT_SERIAL(key_oplist, f, item->key); \ @@ -962,14 +962,14 @@ \ M_IF_METHOD_BOTH(IN_SERIAL, key_oplist, value_oplist)( \ static inline m_serial_return_code_t \ - M_C(name, _in_serial)(dict_t t1, m_serial_read_t f) \ + M_F(name, _in_serial)(dict_t t1, m_serial_read_t f) \ { \ M_ASSERT (f != NULL && f->m_interface != NULL); \ m_serial_local_t local; \ m_serial_return_code_t ret; \ size_t estimated_size = 0; \ key_type key; \ - M_C(name,_reset)(t1); \ + M_F(name,_reset)(t1); \ M_IF(isSet)( \ ret = f->m_interface->read_array_start(local, f, &estimated_size); \ if (M_UNLIKELY (ret != M_SERIAL_OK_CONTINUE)) return ret; \ @@ -977,7 +977,7 @@ do { \ ret = M_CALL_IN_SERIAL(key_oplist, key, f); \ if (ret != M_SERIAL_OK_DONE) { break; } \ - M_C(name, _push)(t1, key); \ + M_F(name, _push)(t1, key); \ } while ((ret = f->m_interface->read_array_next(local, f)) == M_SERIAL_OK_CONTINUE); \ M_CALL_CLEAR(key_oplist, key); \ , \ @@ -993,7 +993,7 @@ if (ret != M_SERIAL_OK_CONTINUE) return M_SERIAL_FAIL; \ ret = M_CALL_IN_SERIAL(value_oplist, value, f); \ if (ret != M_SERIAL_OK_DONE) return M_SERIAL_FAIL; \ - M_C(name, _set_at)(t1, key, value); \ + M_F(name, _set_at)(t1, key, value); \ } while ((ret = f->m_interface->read_map_next(local, f)) == M_SERIAL_OK_CONTINUE); \ M_CALL_CLEAR(key_oplist, key); \ M_CALL_CLEAR(value_oplist, value); \ @@ -1004,37 +1004,37 @@ \ M_IF(isSet)( \ static inline void \ - M_C(name, _splice)(dict_t d1, dict_t d2) \ + M_F(name, _splice)(dict_t d1, dict_t d2) \ { \ dict_it_t it; \ /* NOTE: Despite using set_at, the accessing of the item in d1 \ is not as random as other uses of the HASH table as d2 \ uses the same order than d1 */ \ - for (M_C(name, _it)(it, d2); !M_C(name, _end_p)(it); M_C(name, _next)(it)){ \ - const it_deref_t *item = M_C(name, _cref)(it); \ - M_C(name, _push)(d1, *item); \ + for (M_F(name, _it)(it, d2); !M_F(name, _end_p)(it); M_F(name, _next)(it)){ \ + const it_deref_t *item = M_F(name, _cref)(it); \ + M_F(name, _push)(d1, *item); \ } \ - M_C(name, _reset)(d2); \ + M_F(name, _reset)(d2); \ } \ , \ M_IF_METHOD(ADD, value_oplist)( \ static inline void \ - M_C(name, _splice)(dict_t d1, dict_t d2) \ + M_F(name, _splice)(dict_t d1, dict_t d2) \ { \ dict_it_t it; \ /* NOTE: Despite using set_at, the accessing of the item in d1 \ is not as random as other uses of the HASH table as d2 \ uses the same order than d1 */ \ - for (M_C(name, _it)(it, d2); !M_C(name, _end_p)(it); M_C(name, _next)(it)){ \ - const struct M_C(name, _pair_s) *item = M_C(name, _cref)(it); \ - value_type *ptr = M_C(name, _get)(d1, item->key); \ + for (M_F(name, _it)(it, d2); !M_F(name, _end_p)(it); M_F(name, _next)(it)){ \ + const struct M_F(name, _pair_s) *item = M_F(name, _cref)(it); \ + value_type *ptr = M_F(name, _get)(d1, item->key); \ if (ptr == NULL) { \ - M_C(name, _set_at)(d1, item->key, item->value); \ + M_F(name, _set_at)(d1, item->key, item->value); \ } else { \ M_CALL_ADD(value_oplist, *ptr, *ptr, item->value); \ } \ } \ - M_C(name, _reset)(d2); \ + M_F(name, _reset)(d2); \ } \ , /* NO UPDATE */) ) \ \ @@ -1061,43 +1061,43 @@ NOTE: IT_REF is not exported so that the contained appears as not modifiable by algorithm.*/ #define M_D1CT_OPLIST_P4(name, key_oplist, value_oplist) \ - (INIT(M_C(name, _init)), \ - INIT_SET(M_C(name, _init_set)), \ + (INIT(M_F(name, _init)), \ + INIT_SET(M_F(name, _init_set)), \ INIT_WITH(API_1(M_INIT_KEY_VAI)), \ - SET(M_C(name, _set)), \ - CLEAR(M_C(name, _clear)), \ - INIT_MOVE(M_C(name, _init_move)), \ - MOVE(M_C(name, _move)), \ - SWAP(M_C(name, _swap)), \ - RESET(M_C(name, _reset)), \ + SET(M_F(name, _set)), \ + CLEAR(M_F(name, _clear)), \ + INIT_MOVE(M_F(name, _init_move)), \ + MOVE(M_F(name, _move)), \ + SWAP(M_F(name, _swap)), \ + RESET(M_F(name, _reset)), \ NAME(name), \ - TYPE(M_C(name, _ct)), \ - SUBTYPE(M_C(name, _subtype_ct)), \ - EMPTY_P(M_C(name,_empty_p)), \ - IT_TYPE(M_C(name, _it_ct)), \ - IT_FIRST(M_C(name,_it)), \ - IT_SET(M_C(name, _it_set)), \ - IT_END(M_C(name,_it_end)), \ - IT_END_P(M_C(name,_end_p)), \ - IT_LAST_P(M_C(name,_last_p)), \ - IT_NEXT(M_C(name,_next)), \ - IT_CREF(M_C(name,_cref)) \ - ,KEY_TYPE(M_C(name, _key_ct)) \ - ,VALUE_TYPE(M_C(name, _value_ct)) \ - ,SET_KEY(M_C(name, _set_at)) \ - ,GET_KEY(M_C(name, _get)) \ - ,SAFE_GET_KEY(M_C(name, _safe_get)) \ - ,ERASE_KEY(M_C(name, _erase)) \ + TYPE(M_F(name, _ct)), \ + SUBTYPE(M_F(name, _subtype_ct)), \ + EMPTY_P(M_F(name,_empty_p)), \ + IT_TYPE(M_F(name, _it_ct)), \ + IT_FIRST(M_F(name,_it)), \ + IT_SET(M_F(name, _it_set)), \ + IT_END(M_F(name,_it_end)), \ + IT_END_P(M_F(name,_end_p)), \ + IT_LAST_P(M_F(name,_last_p)), \ + IT_NEXT(M_F(name,_next)), \ + IT_CREF(M_F(name,_cref)) \ + ,KEY_TYPE(M_F(name, _key_ct)) \ + ,VALUE_TYPE(M_F(name, _value_ct)) \ + ,SET_KEY(M_F(name, _set_at)) \ + ,GET_KEY(M_F(name, _get)) \ + ,SAFE_GET_KEY(M_F(name, _safe_get)) \ + ,ERASE_KEY(M_F(name, _erase)) \ ,KEY_OPLIST(key_oplist) \ ,VALUE_OPLIST(value_oplist) \ - ,GET_SIZE(M_C(name, _size)) \ - ,M_IF_METHOD_BOTH(GET_STR, key_oplist, value_oplist)(GET_STR(M_C(name, _get_str)),) \ - ,M_IF_METHOD_BOTH(PARSE_STR, key_oplist, value_oplist)(PARSE_STR(M_C(name, _parse_str)),) \ - ,M_IF_METHOD_BOTH(OUT_STR, key_oplist, value_oplist)(OUT_STR(M_C(name, _out_str)),) \ - ,M_IF_METHOD_BOTH(IN_STR, key_oplist, value_oplist)(IN_STR(M_C(name, _in_str)),) \ - ,M_IF_METHOD_BOTH(OUT_SERIAL, key_oplist, value_oplist)(OUT_SERIAL(M_C(name, _out_serial)),) \ - ,M_IF_METHOD_BOTH(IN_SERIAL, key_oplist, value_oplist)(IN_SERIAL(M_C(name, _in_serial)),) \ - ,M_IF_METHOD(EQUAL, value_oplist)(EQUAL(M_C(name, _equal_p)),) \ + ,GET_SIZE(M_F(name, _size)) \ + ,M_IF_METHOD_BOTH(GET_STR, key_oplist, value_oplist)(GET_STR(M_F(name, _get_str)),) \ + ,M_IF_METHOD_BOTH(PARSE_STR, key_oplist, value_oplist)(PARSE_STR(M_F(name, _parse_str)),) \ + ,M_IF_METHOD_BOTH(OUT_STR, key_oplist, value_oplist)(OUT_STR(M_F(name, _out_str)),) \ + ,M_IF_METHOD_BOTH(IN_STR, key_oplist, value_oplist)(IN_STR(M_F(name, _in_str)),) \ + ,M_IF_METHOD_BOTH(OUT_SERIAL, key_oplist, value_oplist)(OUT_SERIAL(M_F(name, _out_serial)),) \ + ,M_IF_METHOD_BOTH(IN_SERIAL, key_oplist, value_oplist)(IN_SERIAL(M_F(name, _in_serial)),) \ + ,M_IF_METHOD(EQUAL, value_oplist)(EQUAL(M_F(name, _equal_p)),) \ ,M_IF_METHOD(NEW, oplist)(NEW(M_GET_NEW key_oplist),) \ ,M_IF_METHOD(REALLOC, oplist)(REALLOC(M_GET_REALLOC key_oplist),) \ ,M_IF_METHOD(DEL, oplist)(DEL(M_GET_DEL key_oplist),) \ @@ -1119,44 +1119,44 @@ Note: IT_REF is not exported so that the contained appears as not modifiable */ #define M_D1CT_SET_OPLIST_P3(name, oplist) \ - (INIT(M_C(name, _init)), \ - INIT_SET(M_C(name, _init_set)), \ + (INIT(M_F(name, _init)), \ + INIT_SET(M_F(name, _init_set)), \ INIT_WITH(API_1(M_INIT_VAI)), \ - SET(M_C(name, _set)), \ - CLEAR(M_C(name, _clear)), \ - INIT_MOVE(M_C(name, _init_move)), \ - MOVE(M_C(name, _move)), \ - SWAP(M_C(name, _swap)), \ - RESET(M_C(name, _reset)), \ + SET(M_F(name, _set)), \ + CLEAR(M_F(name, _clear)), \ + INIT_MOVE(M_F(name, _init_move)), \ + MOVE(M_F(name, _move)), \ + SWAP(M_F(name, _swap)), \ + RESET(M_F(name, _reset)), \ NAME(name), \ - TYPE(M_C(name, _ct)), \ - SUBTYPE(M_C(name, _subtype_ct)), \ - EMPTY_P(M_C(name,_empty_p)), \ - PUSH(M_C(name,_push)), \ - KEY_TYPE(M_C(name, _key_ct)), \ - VALUE_TYPE(M_C(name, _key_ct)), \ - GET_KEY(M_C(name, _get)), \ - SAFE_GET_KEY(M_C(name, _safe_get)), \ - ERASE_KEY(M_C(name, _erase)), \ + TYPE(M_F(name, _ct)), \ + SUBTYPE(M_F(name, _subtype_ct)), \ + EMPTY_P(M_F(name,_empty_p)), \ + PUSH(M_F(name,_push)), \ + KEY_TYPE(M_F(name, _key_ct)), \ + VALUE_TYPE(M_F(name, _key_ct)), \ + GET_KEY(M_F(name, _get)), \ + SAFE_GET_KEY(M_F(name, _safe_get)), \ + ERASE_KEY(M_F(name, _erase)), \ KEY_OPLIST(oplist), \ VALUE_OPLIST(oplist), \ - GET_SIZE(M_C(name, _size)), \ - IT_TYPE(M_C(name, _it_ct)), \ - IT_FIRST(M_C(name,_it)), \ - IT_SET(M_C(name, _it_set)), \ - IT_END(M_C(name,_it_end)), \ - IT_END_P(M_C(name,_end_p)), \ - IT_LAST_P(M_C(name,_last_p)), \ - IT_NEXT(M_C(name,_next)), \ - IT_CREF(M_C(name,_cref)) \ + GET_SIZE(M_F(name, _size)), \ + IT_TYPE(M_F(name, _it_ct)), \ + IT_FIRST(M_F(name,_it)), \ + IT_SET(M_F(name, _it_set)), \ + IT_END(M_F(name,_it_end)), \ + IT_END_P(M_F(name,_end_p)), \ + IT_LAST_P(M_F(name,_last_p)), \ + IT_NEXT(M_F(name,_next)), \ + IT_CREF(M_F(name,_cref)) \ ,OPLIST(oplist) \ - ,M_IF_METHOD(GET_STR, oplist)(GET_STR(M_C(name, _get_str)),) \ - ,M_IF_METHOD(PARSE_STR, oplist)(PARSE_STR(M_C(name, _parse_str)),) \ - ,M_IF_METHOD(OUT_STR, oplist)(OUT_STR(M_C(name, _out_str)),) \ - ,M_IF_METHOD(IN_STR, oplist)(IN_STR(M_C(name, _in_str)),) \ - ,M_IF_METHOD(OUT_SERIAL, oplist)(OUT_SERIAL(M_C(name, _out_serial)),) \ - ,M_IF_METHOD(IN_SERIAL, oplist)(IN_SERIAL(M_C(name, _in_serial)),) \ - ,EQUAL(M_C(name, _equal_p)), \ + ,M_IF_METHOD(GET_STR, oplist)(GET_STR(M_F(name, _get_str)),) \ + ,M_IF_METHOD(PARSE_STR, oplist)(PARSE_STR(M_F(name, _parse_str)),) \ + ,M_IF_METHOD(OUT_STR, oplist)(OUT_STR(M_F(name, _out_str)),) \ + ,M_IF_METHOD(IN_STR, oplist)(IN_STR(M_F(name, _in_str)),) \ + ,M_IF_METHOD(OUT_SERIAL, oplist)(OUT_SERIAL(M_F(name, _out_serial)),) \ + ,M_IF_METHOD(IN_SERIAL, oplist)(IN_SERIAL(M_F(name, _in_serial)),) \ + ,EQUAL(M_F(name, _equal_p)), \ ,M_IF_METHOD(NEW, oplist)(NEW(M_GET_NEW oplist),) \ ,M_IF_METHOD(REALLOC, oplist)(REALLOC(M_GET_REALLOC oplist),) \ ,M_IF_METHOD(DEL, oplist)(DEL(M_GET_DEL oplist),) \ @@ -1182,7 +1182,7 @@ M_ASSERT(map->count <= map->upper_limit); \ M_ASSERT(map->upper_limit >= M_D1CT_UPPER_BOUND(M_D1CT_INITIAL_SIZE)); \ M_ASSERT(map->count >= map->lower_limit); \ - M_ASSERT(M_POWEROF2_P(M_C(name, _array_list_pair_size)(map->table))); \ + M_ASSERT(M_POWEROF2_P(M_F(name, _array_list_pair_size)(map->table))); \ } while (0) @@ -1257,45 +1257,45 @@ enum m_d1ct_oa_element_e { /* NOTE: \ if isSet is true, all methods of value_oplist are NOP methods */ \ \ - typedef struct M_C(name, _pair_s) { \ + typedef struct M_F(name, _pair_s) { \ key_type key; \ M_IF(isSet)( , value_type value;) \ - } M_C(name, _pair_ct); \ + } M_F(name, _pair_ct); \ \ /* Define type returned by the _ref method of an iterator */ \ M_IF(isSet)( \ typedef key_type it_deref_t; \ , \ - typedef struct M_C(name, _pair_s) it_deref_t; \ + typedef struct M_F(name, _pair_s) it_deref_t; \ ) \ \ M_CHECK_COMPATIBLE_OPLIST(name, 1, key_type, key_oplist) \ M_CHECK_COMPATIBLE_OPLIST(name, 2, value_type, value_oplist) \ \ /* NOTE: We don't want a real oplist for this sub type */ \ - ARRAY_DEF(M_C(name, _array_pair), M_C(name, _pair_ct), \ + ARRAY_DEF(M_F(name, _array_pair), M_F(name, _pair_ct), \ (INIT(M_NOTHING_DEFAULT), SET(M_MEMCPY_DEFAULT), \ INIT_SET(M_MEMCPY_DEFAULT), CLEAR(M_NOTHING_DEFAULT))) \ \ - typedef struct M_C(name,_s) { \ + typedef struct M_F(name,_s) { \ size_t mask, count, count_delete; \ size_t upper_limit, lower_limit; \ - struct M_C(name, _pair_s) *data; \ + struct M_F(name, _pair_s) *data; \ } dict_t[1]; \ - typedef struct M_C(name, _s) *M_C(name, _ptr); \ - typedef const struct M_C(name, _s) *M_C(name, _srcptr); \ + typedef struct M_F(name, _s) *M_F(name, _ptr); \ + typedef const struct M_F(name, _s) *M_F(name, _srcptr); \ \ - typedef struct M_C(name, _it_s) { \ - const struct M_C(name,_s) *dict; \ + typedef struct M_F(name, _it_s) { \ + const struct M_F(name,_s) *dict; \ size_t index; \ } dict_it_t[1]; \ \ /* Define internal types for oplist */ \ - typedef dict_t M_C(name, _ct); \ - typedef it_deref_t M_C(name, _subtype_ct); \ - typedef key_type M_C(name, _key_ct); \ - typedef value_type M_C(name, _value_ct); \ - typedef dict_it_t M_C(name, _it_ct); \ + typedef dict_t M_F(name, _ct); \ + typedef it_deref_t M_F(name, _subtype_ct); \ + typedef key_type M_F(name, _key_ct); \ + typedef value_type M_F(name, _value_ct); \ + typedef dict_it_t M_F(name, _it_ct); \ \ static inline void \ M_C3(m_d1ct_,name,_update_limit)(dict_t dict, size_t size) \ @@ -1306,16 +1306,16 @@ enum m_d1ct_oa_element_e { } \ \ static inline void \ - M_C(name, _init)(dict_t dict) \ + M_F(name, _init)(dict_t dict) \ { \ M_ASSERT(0 <= (coeff_down) && (coeff_down)*2 < (coeff_up) && (coeff_up) < 1); \ dict->mask = M_D1CT_INITIAL_SIZE-1; \ dict->count = 0; \ dict->count_delete = 0; \ M_C3(m_d1ct_,name,_update_limit)(dict, M_D1CT_INITIAL_SIZE); \ - dict->data = M_CALL_REALLOC(key_oplist, M_C(name, _pair_ct), NULL, M_D1CT_INITIAL_SIZE); \ + dict->data = M_CALL_REALLOC(key_oplist, M_F(name, _pair_ct), NULL, M_D1CT_INITIAL_SIZE); \ if (M_UNLIKELY_NOMEM (dict->data == NULL)) { \ - M_MEMORY_FULL(sizeof (M_C(name, _pair_ct)) * M_D1CT_INITIAL_SIZE); \ + M_MEMORY_FULL(sizeof (M_F(name, _pair_ct)) * M_D1CT_INITIAL_SIZE); \ return ; \ } \ /* Populate the initial table with the 'empty' representation */ \ @@ -1327,7 +1327,7 @@ enum m_d1ct_oa_element_e { } \ \ static inline void \ - M_C(name, _clear)(dict_t dict) \ + M_F(name, _clear)(dict_t dict) \ { \ M_D1CT_OA_CONTRACT(dict); \ for(size_t i = 0; i <= dict->mask; i++) { \ @@ -1344,14 +1344,14 @@ enum m_d1ct_oa_element_e { } \ \ static inline value_type * \ - M_C(name, _get)(const dict_t dict, key_type const key) \ + M_F(name, _get)(const dict_t dict, key_type const key) \ { \ M_D1CT_OA_CONTRACT(dict); \ /* NOTE: Key can not be the representation of empty or deleted */ \ M_ASSERT (!M_CALL_OOR_EQUAL(key_oplist, key, M_D1CT_OA_EMPTY)); \ M_ASSERT (!M_CALL_OOR_EQUAL(key_oplist, key, M_D1CT_OA_DELETED)); \ \ - M_C(name, _pair_ct) *const data = dict->data; \ + M_F(name, _pair_ct) *const data = dict->data; \ const size_t mask = dict->mask; \ size_t p = M_CALL_HASH(key_oplist, key) & mask; \ \ @@ -1375,9 +1375,9 @@ enum m_d1ct_oa_element_e { } \ \ static inline value_type const * \ - M_C(name, _cget)(const dict_t map, key_type const key) \ + M_F(name, _cget)(const dict_t map, key_type const key) \ { \ - return M_CONST_CAST(value_type, M_C(name,_get)(map,key)); \ + return M_CONST_CAST(value_type, M_F(name,_get)(map,key)); \ } \ \ M_IF_DEBUG( \ @@ -1385,7 +1385,7 @@ enum m_d1ct_oa_element_e { M_C3(m_d1ct_,name,_control_after_resize)(const dict_t h) \ { \ /* This function checks if the reshashing of the dict is ok */ \ - M_C(name, _pair_ct) *data = h->data; \ + M_F(name, _pair_ct) *data = h->data; \ size_t empty = 0; \ size_t del = 0; \ /* Count the number of empty elements and the number of deleted */ \ @@ -1405,12 +1405,12 @@ enum m_d1ct_oa_element_e { size_t oldSize = h->mask+1; \ M_ASSERT (newSize >= oldSize); \ M_ASSERT (M_POWEROF2_P(newSize)); \ - M_C(name, _pair_ct) *data = h->data; \ + M_F(name, _pair_ct) *data = h->data; \ /* resize can be called just to delete the items */ \ if (newSize > oldSize) { \ - data = M_CALL_REALLOC(key_oplist, M_C(name, _pair_ct), data, newSize); \ + data = M_CALL_REALLOC(key_oplist, M_F(name, _pair_ct), data, newSize); \ if (M_UNLIKELY_NOMEM (data == NULL) ) { \ - M_MEMORY_FULL(sizeof (M_C(name, _pair_ct)) * newSize); \ + M_MEMORY_FULL(sizeof (M_F(name, _pair_ct)) * newSize); \ return ; \ } \ \ @@ -1424,8 +1424,8 @@ enum m_d1ct_oa_element_e { It has been measured that the size of this 'tmp' array is \ around 6% of the size of updated dictionnary. \ NOTE: This should be much cache friendly than typical hash code */ \ - M_C(name, _array_pair_ct) tmp; \ - M_C(name, _array_pair_init)(tmp); \ + M_F(name, _array_pair_ct) tmp; \ + M_F(name, _array_pair_init)(tmp); \ const size_t mask = (newSize -1); \ \ for(size_t i = 0 ; i < oldSize; i++) { \ @@ -1438,7 +1438,7 @@ enum m_d1ct_oa_element_e { M_DO_INIT_MOVE(key_oplist, data[p].key, data[i].key); \ M_DO_INIT_MOVE(value_oplist, data[p].value, data[i].value); \ } else { \ - M_C(name, _pair_ct) *ptr = M_C(name, _array_pair_push_raw) (tmp); \ + M_F(name, _pair_ct) *ptr = M_F(name, _array_pair_push_raw) (tmp); \ M_DO_INIT_MOVE(key_oplist, ptr->key, data[i].key); \ M_DO_INIT_MOVE(value_oplist, ptr->value, data[i].value); \ } \ @@ -1452,8 +1452,8 @@ enum m_d1ct_oa_element_e { /* Let's put back the entries in the tmp array in their right place */ \ /* NOTE: There should be very few entries in this array \ which contains what we weren't be able to fit in the first pass */ \ - while (M_C(name, _array_pair_size)(tmp) > 0) { \ - M_C(name, _pair_ct) const *item = M_C(name, _array_pair_back)(tmp); \ + while (M_F(name, _array_pair_size)(tmp) > 0) { \ + M_F(name, _pair_ct) const *item = M_F(name, _array_pair_back)(tmp); \ size_t p = M_CALL_HASH(key_oplist, item->key) & mask; \ /* NOTE: since the first pass, the bucket might be free now */ \ if (!M_CALL_OOR_EQUAL(key_oplist, data[p].key, M_D1CT_OA_EMPTY)) { \ @@ -1463,10 +1463,10 @@ enum m_d1ct_oa_element_e { M_ASSERT (s <= h->mask); \ } while (!M_CALL_OOR_EQUAL(key_oplist, data[p].key, M_D1CT_OA_EMPTY) ); \ } \ - M_C(name, _array_pair_pop_move)(&data[p], tmp); \ + M_F(name, _array_pair_pop_move)(&data[p], tmp); \ } \ \ - M_C(name, _array_pair_clear) (tmp); \ + M_F(name, _array_pair_clear) (tmp); \ h->mask = newSize-1; \ h->count_delete = h->count; \ if (updateLimit == true) { \ @@ -1478,7 +1478,7 @@ enum m_d1ct_oa_element_e { } \ \ static inline void \ - M_IF(isSet)(M_C(name, _push), M_C(name,_set_at)) \ + M_IF(isSet)(M_F(name, _push), M_F(name,_set_at)) \ (dict_t dict, key_type const key \ M_IF(isSet)(, M_DEFERRED_COMMA value_type const value) ) \ { \ @@ -1487,7 +1487,7 @@ enum m_d1ct_oa_element_e { M_ASSERT (!M_CALL_OOR_EQUAL(key_oplist, key, M_D1CT_OA_EMPTY)); \ M_ASSERT (!M_CALL_OOR_EQUAL(key_oplist, key, M_D1CT_OA_DELETED)); \ \ - M_C(name, _pair_ct) *const data = dict->data; \ + M_F(name, _pair_ct) *const data = dict->data; \ const size_t mask = dict->mask; \ size_t p = M_CALL_HASH(key_oplist, key) & mask; \ \ @@ -1538,14 +1538,14 @@ enum m_d1ct_oa_element_e { } \ \ static inline value_type * \ - M_C(name,_safe_get)(dict_t dict, key_type const key) \ + M_F(name,_safe_get)(dict_t dict, key_type const key) \ { \ M_D1CT_OA_CONTRACT(dict); \ /* NOTE: key can not be the representation of empty or deleted */ \ M_ASSERT (!M_CALL_OOR_EQUAL(key_oplist, key, M_D1CT_OA_EMPTY)); \ M_ASSERT (!M_CALL_OOR_EQUAL(key_oplist, key, M_D1CT_OA_DELETED)); \ \ - M_C(name, _pair_ct) *const data = dict->data; \ + M_F(name, _pair_ct) *const data = dict->data; \ const size_t mask = dict->mask; \ size_t p = M_CALL_HASH(key_oplist, key) & mask; \ \ @@ -1588,15 +1588,15 @@ enum m_d1ct_oa_element_e { } \ M_C3(m_d1ct_,name,_resize_up)(dict, newSize, true); \ /* data is now invalid */ \ - return M_C(name, _get)(dict, key); \ + return M_F(name, _get)(dict, key); \ } \ M_D1CT_OA_CONTRACT(dict); \ return &data[p].M_IF(isSet)(key, value); \ } \ static inline M_ATTR_DEPRECATED value_type * \ - M_C(name,_get_at)(dict_t dict, key_type const key) \ + M_F(name,_get_at)(dict_t dict, key_type const key) \ { \ - return M_C(name,_safe_get)(dict, key); \ + return M_F(name,_safe_get)(dict, key); \ } \ \ static inline void \ @@ -1607,9 +1607,9 @@ enum m_d1ct_oa_element_e { if (M_UNLIKELY (newSize < M_D1CT_INITIAL_SIZE)) \ newSize = M_D1CT_INITIAL_SIZE; \ const size_t mask = newSize -1; \ - M_C(name, _pair_ct) *data = h->data; \ - M_C(name, _array_pair_ct) tmp; \ - M_C(name, _array_pair_init)(tmp); \ + M_F(name, _pair_ct) *data = h->data; \ + M_F(name, _array_pair_ct) tmp; \ + M_F(name, _array_pair_init)(tmp); \ \ /* Pass 1: scan lower entries, and move them if needed */ \ for(size_t i = 0; i < newSize; i++) { \ @@ -1626,7 +1626,7 @@ enum m_d1ct_oa_element_e { M_DO_INIT_MOVE(key_oplist, data[p].key, data[i].key); \ M_DO_INIT_MOVE(value_oplist, data[p].value, data[i].value); \ } else { \ - M_C(name, _pair_ct) *ptr = M_C(name, _array_pair_push_raw) (tmp); \ + M_F(name, _pair_ct) *ptr = M_F(name, _array_pair_push_raw) (tmp); \ M_DO_INIT_MOVE(key_oplist, ptr->key, data[i].key); \ M_DO_INIT_MOVE(value_oplist, ptr->value, data[i].value); \ } \ @@ -1651,8 +1651,8 @@ enum m_d1ct_oa_element_e { } \ } \ /* Pass 3: scan moved entries and move them back */ \ - while (M_C(name, _array_pair_size)(tmp) > 0) { \ - M_C(name, _pair_ct) const *item = M_C(name, _array_pair_back)(tmp); \ + while (M_F(name, _array_pair_size)(tmp) > 0) { \ + M_F(name, _pair_ct) const *item = M_F(name, _array_pair_back)(tmp); \ size_t p = M_CALL_HASH(key_oplist, item->key) & mask; \ if (!M_CALL_OOR_EQUAL(key_oplist, data[p].key, M_D1CT_OA_EMPTY)) { \ size_t s = 1; \ @@ -1661,15 +1661,15 @@ enum m_d1ct_oa_element_e { M_ASSERT (s <= h->mask); \ } while (!M_CALL_OOR_EQUAL(key_oplist, data[p].key, M_D1CT_OA_EMPTY) ); \ } \ - M_C(name, _array_pair_pop_move)(&data[p], tmp); \ + M_F(name, _array_pair_pop_move)(&data[p], tmp); \ } \ \ - M_C(name, _array_pair_clear) (tmp); \ + M_F(name, _array_pair_clear) (tmp); \ h->count_delete = h->count; \ if (newSize != oldSize) { \ h->mask = newSize-1; \ M_C3(m_d1ct_,name,_update_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_F(name, _pair_ct), data, newSize); \ M_ASSERT (h->data != NULL); \ } \ M_IF_DEBUG (M_ASSERT (M_C3(m_d1ct_,name,_control_after_resize)(h));) \ @@ -1678,14 +1678,14 @@ enum m_d1ct_oa_element_e { } \ \ static inline bool \ - M_C(name,_erase)(dict_t dict, key_type const key) \ + M_F(name,_erase)(dict_t dict, key_type const key) \ { \ M_D1CT_OA_CONTRACT(dict); \ /* NOTE: key can't be the representation of empty or deleted */ \ M_ASSERT (!M_CALL_OOR_EQUAL(key_oplist, key, M_D1CT_OA_EMPTY)); \ M_ASSERT (!M_CALL_OOR_EQUAL(key_oplist, key, M_D1CT_OA_DELETED)); \ \ - M_C(name, _pair_ct) *const data = dict->data; \ + M_F(name, _pair_ct) *const data = dict->data; \ const size_t mask = dict->mask; \ size_t p = M_CALL_HASH(key_oplist, key) & mask; \ \ @@ -1714,7 +1714,7 @@ enum m_d1ct_oa_element_e { } \ \ static inline void \ - M_C(name, _init_set)(dict_t map, const dict_t org) \ + M_F(name, _init_set)(dict_t map, const dict_t org) \ { \ M_D1CT_OA_CONTRACT(org); \ M_ASSERT (map != org); \ @@ -1723,9 +1723,9 @@ enum m_d1ct_oa_element_e { map->count_delete = org->count_delete; \ map->upper_limit = org->upper_limit; \ map->lower_limit = org->lower_limit; \ - map->data = M_CALL_REALLOC(key_oplist, M_C(name, _pair_ct), NULL, map->mask+1); \ + map->data = M_CALL_REALLOC(key_oplist, M_F(name, _pair_ct), NULL, map->mask+1); \ if (M_UNLIKELY_NOMEM (map->data == NULL)) { \ - M_MEMORY_FULL(sizeof (M_C(name, _pair_ct)) * (map->mask+1)); \ + M_MEMORY_FULL(sizeof (M_F(name, _pair_ct)) * (map->mask+1)); \ return ; \ } \ for(size_t i = 0; i <= org->mask; i++) { \ @@ -1742,19 +1742,19 @@ enum m_d1ct_oa_element_e { } \ \ static inline void \ - M_C(name, _set)(dict_t map, const dict_t org) \ + M_F(name, _set)(dict_t map, const dict_t org) \ { \ M_D1CT_OA_CONTRACT(map); \ M_D1CT_OA_CONTRACT(org); \ if (M_LIKELY (map != org)) { \ - M_C(name, _clear)(map); \ - M_C(name, _init_set)(map, org); \ + M_F(name, _clear)(map); \ + M_F(name, _init_set)(map, org); \ } \ M_D1CT_OA_CONTRACT(map); \ } \ \ static inline void \ - M_C(name, _init_move)(dict_t map, dict_t org) \ + M_F(name, _init_move)(dict_t map, dict_t org) \ { \ M_D1CT_OA_CONTRACT(org); \ M_ASSERT (map != org); \ @@ -1771,19 +1771,19 @@ enum m_d1ct_oa_element_e { } \ \ static inline void \ - M_C(name, _move)(dict_t map, dict_t org) \ + M_F(name, _move)(dict_t map, dict_t org) \ { \ M_D1CT_OA_CONTRACT(map); \ M_D1CT_OA_CONTRACT(org); \ if (M_LIKELY (map != org)) { \ - M_C(name, _clear)(map); \ - M_C(name, _init_move)(map, org); \ + M_F(name, _clear)(map); \ + M_F(name, _init_move)(map, org); \ } \ M_D1CT_OA_CONTRACT(map); \ } \ \ static inline void \ - M_C(name, _swap)(dict_t d1, dict_t d2) \ + M_F(name, _swap)(dict_t d1, dict_t d2) \ { \ M_D1CT_OA_CONTRACT(d1); \ M_D1CT_OA_CONTRACT(d2); \ @@ -1792,13 +1792,13 @@ enum m_d1ct_oa_element_e { M_SWAP (size_t, d1->count_delete, d2->count_delete); \ M_SWAP (size_t, d1->upper_limit, d2->upper_limit); \ M_SWAP (size_t, d1->lower_limit, d2->lower_limit); \ - M_SWAP (M_C(name, _pair_ct) *, d1->data, d2->data); \ + M_SWAP (M_F(name, _pair_ct) *, d1->data, d2->data); \ M_D1CT_OA_CONTRACT(d1); \ M_D1CT_OA_CONTRACT(d2); \ } \ \ static inline void \ - M_C(name, _reset)(dict_t d) \ + M_F(name, _reset)(dict_t d) \ { \ M_D1CT_OA_CONTRACT(d); \ for(size_t i = 0; i <= d->mask; i++) { \ @@ -1812,7 +1812,7 @@ enum m_d1ct_oa_element_e { d->count_delete = 0; \ d->mask = M_D1CT_INITIAL_SIZE-1; \ M_C3(m_d1ct_,name,_update_limit)(d, M_D1CT_INITIAL_SIZE); \ - d->data = M_CALL_REALLOC(key_oplist, M_C(name, _pair_ct), \ + d->data = M_CALL_REALLOC(key_oplist, M_F(name, _pair_ct), \ d->data, M_D1CT_INITIAL_SIZE); \ M_ASSERT(d->data != NULL); \ for(size_t i = 0; i <= d->mask; i++) { \ @@ -1822,13 +1822,13 @@ enum m_d1ct_oa_element_e { } \ \ static inline void M_ATTR_DEPRECATED \ - M_C(name, _clean)(dict_t d) \ + M_F(name, _clean)(dict_t d) \ { \ - M_C(name, _reset)(d); \ + M_F(name, _reset)(d); \ } \ \ static inline void \ - M_C(name, _it)(dict_it_t it, const dict_t d) \ + M_F(name, _it)(dict_it_t it, const dict_t d) \ { \ M_D1CT_OA_CONTRACT(d); \ M_ASSERT (it != NULL); \ @@ -1843,7 +1843,7 @@ enum m_d1ct_oa_element_e { } \ \ static inline void \ - M_C(name, _it_set)(dict_it_t it, const dict_it_t ref) \ + M_F(name, _it_set)(dict_it_t it, const dict_it_t ref) \ { \ M_ASSERT (it != NULL); \ M_ASSERT (ref != NULL); \ @@ -1853,7 +1853,7 @@ enum m_d1ct_oa_element_e { } \ \ static inline void \ - M_C(name, _it_last)(dict_it_t it, const dict_t d) \ + M_F(name, _it_last)(dict_it_t it, const dict_t d) \ { \ M_D1CT_OA_CONTRACT(d); \ M_ASSERT (it != NULL); \ @@ -1868,7 +1868,7 @@ enum m_d1ct_oa_element_e { } \ \ static inline void \ - M_C(name, _it_end)(dict_it_t it, const dict_t d) \ + M_F(name, _it_end)(dict_it_t it, const dict_t d) \ { \ M_D1CT_OA_CONTRACT(d); \ M_ASSERT (it != NULL); \ @@ -1877,7 +1877,7 @@ enum m_d1ct_oa_element_e { } \ \ static inline bool \ - M_C(name, _end_p)(const dict_it_t it) \ + M_F(name, _end_p)(const dict_it_t it) \ { \ M_ASSERT (it != NULL); \ M_D1CT_OA_CONTRACT (it->dict); \ @@ -1885,7 +1885,7 @@ enum m_d1ct_oa_element_e { } \ \ static inline void \ - M_C(name, _next)(dict_it_t it) \ + M_F(name, _next)(dict_it_t it) \ { \ M_ASSERT (it != NULL); \ M_D1CT_OA_CONTRACT (it->dict); \ @@ -1899,7 +1899,7 @@ enum m_d1ct_oa_element_e { } \ \ static inline void \ - M_C(name, _previous)(dict_it_t it) \ + M_F(name, _previous)(dict_it_t it) \ { \ M_ASSERT (it != NULL); \ M_D1CT_OA_CONTRACT (it->dict); \ @@ -1914,17 +1914,17 @@ enum m_d1ct_oa_element_e { } \ \ static inline bool \ - M_C(name, _last_p)(const dict_it_t it) \ + M_F(name, _last_p)(const dict_it_t it) \ { \ M_ASSERT (it != NULL); \ dict_it_t it2; \ - M_C(name,_it_set)(it2, it); \ - M_C(name, _next)(it2); \ - return M_C(name, _end_p)(it2); \ + M_F(name,_it_set)(it2, it); \ + M_F(name, _next)(it2); \ + return M_F(name, _end_p)(it2); \ } \ \ static inline bool \ - M_C(name, _it_equal_p)(const dict_it_t it1,const dict_it_t it2) \ + M_F(name, _it_equal_p)(const dict_it_t it1,const dict_it_t it2) \ { \ M_ASSERT (it1 != NULL && it2 != NULL); \ M_D1CT_OA_CONTRACT (it1->dict); \ @@ -1933,7 +1933,7 @@ enum m_d1ct_oa_element_e { } \ \ static inline it_deref_t * \ - M_C(name, _ref)(const dict_it_t it) \ + M_F(name, _ref)(const dict_it_t it) \ { \ M_ASSERT (it != NULL); \ M_D1CT_OA_CONTRACT (it -> dict); \ @@ -1945,13 +1945,13 @@ enum m_d1ct_oa_element_e { } \ \ static inline const it_deref_t * \ - M_C(name, _cref)(const dict_it_t it) \ + M_F(name, _cref)(const dict_it_t it) \ { \ - return M_CONST_CAST(it_deref_t, M_C(name, _ref)(it)); \ + return M_CONST_CAST(it_deref_t, M_F(name, _ref)(it)); \ } \ \ static inline void \ - M_C(name,_reserve)(dict_t dict, size_t capacity) \ + M_F(name,_reserve)(dict_t dict, size_t capacity) \ { \ M_D1CT_OA_CONTRACT(dict); \ size_t size; \ diff --git a/m-funcobj.h b/m-funcobj.h index 9a7d88e9..2ed38f8a 100644 --- a/m-funcobj.h +++ b/m-funcobj.h @@ -33,7 +33,7 @@ * FUNC_OBJ_ITF_DEF(name, retcode type, type of param1, type of param 2, ...) */ #define M_FUNC_OBJ_ITF_DEF(name, ...) \ - M_FUNC_OBJ_ITF_DEF_AS(name, M_C(name,_t), __VA_ARGS__) + M_FUNC_OBJ_ITF_DEF_AS(name, M_F(name,_t), __VA_ARGS__) /* Define a function object interface of name 'name' @@ -66,7 +66,7 @@ * FUNC_OBJ_INS_DEF(name, base_name, (param1, ...), { return param1 * self->member1 }, (member1, int), ...) */ #define M_FUNC_OBJ_INS_DEF(name, base_name, param_list, ...) \ - M_FUNC_OBJ_INS_DEF_AS(name, M_C(name,_t), base_name, param_list, __VA_ARGS__) + M_FUNC_OBJ_INS_DEF_AS(name, M_F(name,_t), base_name, param_list, __VA_ARGS__) /* Define a function object instance of name 'name' based on the interface 'base_name' @@ -111,9 +111,9 @@ /* Specialization of the OPLIST in function if there is at least one member or not */ #define M_FUNC0BJ_INS_NO_ATTR_OPLIST(name) ( \ NAME(name), \ - TYPE(M_C(name, _ct)), \ - CLEAR(M_C(name, _clear)), \ - INIT(M_C(name,_init)) \ + TYPE(M_F(name, _ct)), \ + CLEAR(M_F(name, _clear)), \ + INIT(M_F(name,_init)) \ ) /* Validate the oplist before going further */ @@ -127,10 +127,10 @@ /* Define the oplist of the instance */ #define M_FUNC0BJ_INS_ATTR_OPLIST_P3(name, ...) ( \ NAME(name), \ - TYPE(M_C(name, _ct)), \ - INIT_WITH(M_C(name, _init_with)), \ - CLEAR(M_C(name, _clear)), \ - M_IF_METHOD_ALL(INIT, __VA_ARGS__)(INIT(M_C(name,_init)),), \ + TYPE(M_F(name, _ct)), \ + INIT_WITH(M_F(name, _init_with)), \ + CLEAR(M_F(name, _clear)), \ + M_IF_METHOD_ALL(INIT, __VA_ARGS__)(INIT(M_F(name,_init)),), \ PROPERTIES(( LET_AS_INIT_WITH(1) )) \ ) @@ -140,29 +140,29 @@ /* Specialization of the definition a function object interface of name 'name' * with a function like "retcode (void)" that doesn't have any input parameters. * Define the following types to be used by instance: - * - M_C(name, _retcode_ct): internal type of the return code - * - M_C(name, _callback_ct): internal type of the callback. - * - M_C(name, _ct): synonym of main type used by oplist. + * - M_F(name, _retcode_ct): internal type of the return code + * - M_F(name, _callback_ct): internal type of the callback. + * - M_F(name, _ct): synonym of main type used by oplist. */ #define M_FUNC0BJ_ITF_NO_PARAM_DEF(name, interface_t, retcode) \ \ /* Forward declaration */ \ - struct M_C(name, _s); \ + struct M_F(name, _s); \ \ /* Internal type for instance */ \ - typedef retcode M_C(name, _retcode_ct); \ + typedef retcode M_F(name, _retcode_ct); \ /* No parameters to the callback */ \ - typedef retcode(*M_C(name, _callback_ct))(struct M_C(name, _s) *); \ + typedef retcode(*M_F(name, _callback_ct))(struct M_F(name, _s) *); \ \ - typedef struct M_C(name, _s) { \ - M_C(name, _callback_ct) callback; \ + typedef struct M_F(name, _s) { \ + M_F(name, _callback_ct) callback; \ } interface_t[1]; \ \ /* Internal type for oplist & instance */ \ - typedef interface_t M_C(name, _ct); \ + typedef interface_t M_F(name, _ct); \ \ static inline retcode \ - M_C(name, _call)(interface_t funcobj) \ + M_F(name, _call)(interface_t funcobj) \ { \ M_IF(M_KEYWORD_P(void, retcode)) ( /* nothing */,return) \ funcobj->callback(funcobj); \ @@ -173,32 +173,32 @@ * with a function like retcode, type of param1, type of param 2, ... * with mandatory input parameters. * Define the following types to be used by instance: - * - M_C(name, _retcode_ct): internal type of the return code - * - M_C(name, _callback_ct): internal type of the callback. + * - M_F(name, _retcode_ct): internal type of the return code + * - M_F(name, _callback_ct): internal type of the callback. * - M_C4(name, _param_, num, _ct) for each parameter defined - * - M_C(name, _ct): synonym of main type used by oplist. + * - M_F(name, _ct): synonym of main type used by oplist. */ #define M_FUNC0BJ_ITF_PARAM_DEF(name, interface_t, retcode, ...) \ \ /* Forward declaration */ \ - struct M_C(name, _s); \ + struct M_F(name, _s); \ \ /* Internal types for instance */ \ - typedef retcode M_C(name, _retcode_ct); \ + typedef retcode M_F(name, _retcode_ct); \ /* Define types for all parameters */ \ M_MAP3(M_FUNC0BJ_BASE_TYPE, name, __VA_ARGS__) \ /* Define callback type with all parameters */ \ - typedef retcode(*M_C(name, _callback_ct))(struct M_C(name, _s) *, __VA_ARGS__); \ + typedef retcode(*M_F(name, _callback_ct))(struct M_F(name, _s) *, __VA_ARGS__); \ \ - typedef struct M_C(name, _s) { \ - M_C(name, _callback_ct) callback; \ + typedef struct M_F(name, _s) { \ + M_F(name, _callback_ct) callback; \ } interface_t[1]; \ \ /* Internal type for oplist & instance */ \ - typedef interface_t M_C(name, _ct); \ + typedef interface_t M_F(name, _ct); \ \ static inline retcode \ - M_C(name, _call)(interface_t funcobj \ + M_F(name, _call)(interface_t funcobj \ M_MAP3(M_FUNC0BJ_BASE_ARGLIST, name, __VA_ARGS__) ) \ { \ /* If the retcode is 'void', don't return the value of the callback */ \ @@ -213,48 +213,48 @@ * with no member attribute. */ #define M_FUNC0BJ_INS_NO_ATTR_DEF(name, instance_t, base_name, param_list, callback_core) \ - typedef struct M_C(name, _s) { \ + typedef struct M_F(name, _s) { \ M_C(base_name, _callback_ct) callback; \ } instance_t[1]; \ \ /* Internal type for oplist */ \ - typedef instance_t M_C(name, _ct); \ + typedef instance_t M_F(name, _ct); \ \ static inline M_C(base_name, _retcode_ct) \ - M_C(name, _callback)(M_C(base_name, _ct) _self \ + M_F(name, _callback)(M_C(base_name, _ct) _self \ M_IF_EMPTY(M_OPFLAT param_list)( \ /* No param */, \ M_MAP3(M_FUNC0BJ_INS_ARGLIST, base_name, M_OPFLAT param_list) \ ) \ ) \ { \ - struct M_C(name, _s) *self = (struct M_C(name, _s) *)_self; \ + struct M_F(name, _s) *self = (struct M_F(name, _s) *)_self; \ (void) self; /* maybe unused */ \ callback_core; \ } \ \ static inline void \ - M_C(name, _init_with)(instance_t obj) \ + M_F(name, _init_with)(instance_t obj) \ { \ - obj->callback = M_C(name, _callback); \ + obj->callback = M_F(name, _callback); \ } \ \ static inline void \ - M_C(name, _clear)(instance_t obj) \ + M_F(name, _clear)(instance_t obj) \ { \ (void) obj; /* nothing to do */ \ } \ \ static inline struct M_C(base_name, _s) * \ - M_C(name, _as_interface)(instance_t obj) \ + M_F(name, _as_interface)(instance_t obj) \ { \ return (struct M_C(base_name, _s) *) obj; \ } \ \ static inline void \ - M_C(name, _init)(instance_t obj) \ + M_F(name, _init)(instance_t obj) \ { \ - obj->callback = M_C(name, _callback); \ + obj->callback = M_F(name, _callback); \ } \ @@ -294,7 +294,7 @@ /* Expand the Function Object with members */ #define M_FUNC0BJ_INS_ATTR_DEF_P3(name, instance_t, base_name, param_list, callback_core, ...) \ - typedef struct M_C(name, _s) { \ + typedef struct M_F(name, _s) { \ /* Callback is the mandatory first argument */ \ M_C(base_name, _callback_ct) callback; \ /* All the member attribute of the Function Object */ \ @@ -302,12 +302,12 @@ } instance_t[1]; \ \ /* Internal type for oplist */ \ - typedef instance_t M_C(name, _ct); \ + typedef instance_t M_F(name, _ct); \ \ M_FUNC0BJ_CONTROL_ALL_OPLIST(name, __VA_ARGS__) \ \ static inline M_C(base_name, _retcode_ct) \ - M_C(name, _callback)(M_C(base_name, _ct) _self \ + M_F(name, _callback)(M_C(base_name, _ct) _self \ M_IF_EMPTY(M_OPFLAT param_list)( \ /* No param */, \ M_MAP3(M_FUNC0BJ_INS_ARGLIST, base_name, M_OPFLAT param_list) \ @@ -316,26 +316,26 @@ { \ /* Let's go through an uintptr_t to avoid [broken] aliasing detection by compiler */ \ uintptr_t __self = (uintptr_t) _self; \ - struct M_C(name, _s) *self = (struct M_C(name, _s) *)(void*)__self; \ + struct M_F(name, _s) *self = (struct M_F(name, _s) *)(void*)__self; \ (void) self; /* maybe unused */ \ callback_core; \ } \ \ static inline void \ - M_C(name, _init_with)(instance_t obj M_MAP(M_FUNC0BJ_INS_ATTR_LIST, __VA_ARGS__)) \ + M_F(name, _init_with)(instance_t obj M_MAP(M_FUNC0BJ_INS_ATTR_LIST, __VA_ARGS__)) \ { \ - obj->callback = M_C(name, _callback); \ + obj->callback = M_F(name, _callback); \ M_MAP(M_FUNC0BJ_INS_ATTR_INIT_SET, __VA_ARGS__); \ } \ \ static inline void \ - M_C(name, _clear)(instance_t obj) \ + M_F(name, _clear)(instance_t obj) \ { \ M_MAP(M_FUNC0BJ_INS_ATTR_CLEAR, __VA_ARGS__); \ } \ \ static inline struct M_C(base_name, _s) * \ - M_C(name, _as_interface)(instance_t obj) \ + M_F(name, _as_interface)(instance_t obj) \ { \ return (struct M_C(base_name, _s) *) obj; \ } \ @@ -343,9 +343,9 @@ M_IF(M_FUNC0BJ_TEST_METHOD_P(INIT, __VA_ARGS)) \ ( \ static inline void \ - M_C(name, _init)(instance_t obj) \ + M_F(name, _init)(instance_t obj) \ { \ - obj->callback = M_C(name, _callback); \ + obj->callback = M_F(name, _callback); \ M_MAP(M_FUNC0BJ_INS_ATTR_INIT, __VA_ARGS__); \ } \ , /* END OF INIT METHOD */ ) \ diff --git a/m-i-list.h b/m-i-list.h index 5cc2ebed..d45bc608 100644 --- a/m-i-list.h +++ b/m-i-list.h @@ -47,7 +47,7 @@ USAGE: ILIST_DEF(name, type [, oplist_of_the_type]) */ #define M_ILIST_DEF(name, ...) \ - M_ILIST_DEF_AS(name, M_C(name,_t), M_C(name,_it_t), __VA_ARGS__) + M_ILIST_DEF_AS(name, M_F(name,_t), M_F(name,_it_t), __VA_ARGS__) /* Define a doubly-linked intrusive list of a given type @@ -95,31 +95,31 @@ typedef struct m_il1st_head_s { /* Define the oplist of an ilist of type */ #define M_IL1ST_OPLIST_P3(name, oplist) \ - (INIT(M_C(name, _init)), \ - CLEAR(M_C(name, _clear)), \ - INIT_MOVE(M_C(name, _init_move)), \ - MOVE(M_C(name, _move)), \ + (INIT(M_F(name, _init)), \ + CLEAR(M_F(name, _clear)), \ + INIT_MOVE(M_F(name, _init_move)), \ + MOVE(M_F(name, _move)), \ NAME(name), \ - TYPE(M_C(name,_ct)), \ - RESET(M_C(name,_reset)), \ - SUBTYPE(M_C(name,_subtype_ct)), \ - EMPTY_P(M_C(name,_empty_p)), \ - IT_TYPE(M_C(name,_it_ct)), \ - IT_FIRST(M_C(name,_it)), \ - IT_SET(M_C(name,_it_set)), \ - IT_LAST(M_C(name,_it_last)), \ - IT_END(M_C(name,_it_end)), \ - IT_END_P(M_C(name,_end_p)), \ - IT_LAST_P(M_C(name,_last_p)), \ - IT_EQUAL_P(M_C(name,_it_equal_p)), \ - IT_NEXT(M_C(name,_next)), \ - IT_PREVIOUS(M_C(name,_previous)), \ - IT_REF(M_C(name,_ref)), \ - IT_CREF(M_C(name,_cref)), \ - IT_REMOVE(M_C(name,_remove)), \ - M_IF_METHOD(NEW, oplist)(IT_INSERT(M_C(name,_insert)),), \ + TYPE(M_F(name,_ct)), \ + RESET(M_F(name,_reset)), \ + SUBTYPE(M_F(name,_subtype_ct)), \ + EMPTY_P(M_F(name,_empty_p)), \ + IT_TYPE(M_F(name,_it_ct)), \ + IT_FIRST(M_F(name,_it)), \ + IT_SET(M_F(name,_it_set)), \ + IT_LAST(M_F(name,_it_last)), \ + IT_END(M_F(name,_it_end)), \ + IT_END_P(M_F(name,_end_p)), \ + IT_LAST_P(M_F(name,_last_p)), \ + IT_EQUAL_P(M_F(name,_it_equal_p)), \ + IT_NEXT(M_F(name,_next)), \ + IT_PREVIOUS(M_F(name,_previous)), \ + IT_REF(M_F(name,_ref)), \ + IT_CREF(M_F(name,_cref)), \ + IT_REMOVE(M_F(name,_remove)), \ + M_IF_METHOD(NEW, oplist)(IT_INSERT(M_F(name,_insert)),), \ OPLIST(oplist), \ - SPLICE_BACK(M_C(name,_splice_back)) \ + SPLICE_BACK(M_F(name,_splice_back)) \ ,M_IF_METHOD(NEW, oplist)(NEW(M_GET_NEW oplist),) \ ,M_IF_METHOD(DEL, oplist)(DEL(M_GET_DEL oplist),) \ ) @@ -176,16 +176,16 @@ typedef struct m_il1st_head_s { \ /* Define the list as a structure containing pointers \ * to the front & back nodes */ \ - typedef struct M_C(name, _s) { \ + typedef struct M_F(name, _s) { \ struct m_il1st_head_s name; \ } list_t[1]; \ \ /* Define internal types pointers to such a list */ \ - typedef struct M_C(name, _s) *M_C(name, _ptr); \ - typedef const struct M_C(name, _s) *M_C(name, _srcptr); \ + typedef struct M_F(name, _s) *M_F(name, _ptr); \ + typedef const struct M_F(name, _s) *M_F(name, _srcptr); \ \ /* Define iterator of such a list */ \ - typedef struct M_C(name, _it_s) { \ + typedef struct M_F(name, _it_s) { \ struct m_il1st_head_s *head; \ struct m_il1st_head_s *previous; \ struct m_il1st_head_s *current; \ @@ -193,15 +193,15 @@ typedef struct m_il1st_head_s { } it_t[1]; \ \ /* Define types used by oplist */ \ - typedef type M_C(name, _subtype_ct); \ - typedef list_t M_C(name, _ct); \ - typedef it_t M_C(name, _it_ct); \ + typedef type M_F(name, _subtype_ct); \ + typedef list_t M_F(name, _ct); \ + typedef it_t M_F(name, _it_ct); \ /* Define core functions for intrusive lists */ #define M_IL1ST_DEF_CORE(name, type, oplist, list_t, it_t) \ \ static inline void \ - M_C(name, _init)(list_t list) \ + M_F(name, _init)(list_t list) \ { \ M_ASSERT (list != NULL); \ list->name.next = &list->name; \ @@ -210,7 +210,7 @@ typedef struct m_il1st_head_s { } \ \ static inline void \ - M_C(name, _reset)(list_t list) \ + M_F(name, _reset)(list_t list) \ { \ M_IL1ST_CONTRACT(name, list); \ for(struct m_il1st_head_s *it = list->name.next, *next ; \ @@ -232,17 +232,17 @@ typedef struct m_il1st_head_s { } \ \ static inline void \ - M_C(name, _clear)(list_t list) \ + M_F(name, _clear)(list_t list) \ { \ /* Nothing to do more than clean the list itself */ \ - M_C(name, _reset)(list); \ + M_F(name, _reset)(list); \ /* For safety purpose (create invalid represenation of object) */ \ list->name.next = NULL; \ list->name.prev = NULL; \ } \ \ static inline bool \ - M_C(name, _empty_p)(const list_t list) \ + M_F(name, _empty_p)(const list_t list) \ { \ M_IL1ST_CONTRACT(name, list); \ return list->name.next == &list->name; \ @@ -250,12 +250,12 @@ typedef struct m_il1st_head_s { \ \ static inline void \ - M_C(name, _init_move)(list_t list, list_t ref) \ + M_F(name, _init_move)(list_t list, list_t ref) \ { \ M_IL1ST_CONTRACT(name, ref); \ M_ASSERT (list != ref); \ - M_C(name,_init)(list); \ - if (!M_C(name,_empty_p)(ref)) { \ + M_F(name,_init)(list); \ + if (!M_F(name,_empty_p)(ref)) { \ list->name.next = ref->name.next; \ list->name.prev = ref->name.prev; \ list->name.next->prev = &list->name; \ @@ -267,14 +267,14 @@ typedef struct m_il1st_head_s { } \ \ static inline void \ - M_C(name, _move)(list_t list, list_t ref) \ + M_F(name, _move)(list_t list, list_t ref) \ { \ - M_C(name, _clear)(list); \ - M_C(name, _init_move)(list, ref); \ + M_F(name, _clear)(list); \ + M_F(name, _init_move)(list, ref); \ } \ \ static inline size_t \ - M_C(name, _size)(const list_t list) \ + M_F(name, _size)(const list_t list) \ { \ M_IL1ST_CONTRACT(name, list); \ size_t s = 0; \ @@ -288,7 +288,7 @@ typedef struct m_il1st_head_s { } \ \ static inline void \ - M_C(name, _push_back)(list_t list, type *obj) \ + M_F(name, _push_back)(list_t list, type *obj) \ { \ M_IL1ST_CONTRACT(name, list); \ M_ASSERT (obj != NULL); \ @@ -301,7 +301,7 @@ typedef struct m_il1st_head_s { } \ \ static inline void \ - M_C(name, _push_front)(list_t list, type *obj) \ + M_F(name, _push_front)(list_t list, type *obj) \ { \ M_IL1ST_CONTRACT(name, list); \ M_ASSERT (obj != NULL); \ @@ -314,7 +314,7 @@ typedef struct m_il1st_head_s { } \ \ static inline void \ - M_C(name, _push_after)(type *obj_pos, type *obj) \ + M_F(name, _push_after)(type *obj_pos, type *obj) \ { \ M_ASSERT (obj_pos != NULL && obj != NULL); \ /* We don't have the list, so we have no contract at list level */ \ @@ -327,7 +327,7 @@ typedef struct m_il1st_head_s { } \ \ static inline void \ - M_C(name, _init_field)(type *obj) \ + M_F(name, _init_field)(type *obj) \ { \ M_ASSERT (obj != NULL); \ /* Init the fields of the node. To be used in object constructor */ \ @@ -336,7 +336,7 @@ typedef struct m_il1st_head_s { } \ \ static inline void \ - M_C(name, _unlink)(type *obj) \ + M_F(name, _unlink)(type *obj) \ { \ M_ASSERT (obj != NULL); \ /* We don't have the list, so we have no contract at list level */ \ @@ -351,25 +351,25 @@ typedef struct m_il1st_head_s { } \ \ static inline type * \ - M_C(name, _back)(const list_t list) \ + M_F(name, _back)(const list_t list) \ { \ M_IL1ST_CONTRACT(name, list); \ - M_ASSERT(!M_C(name, _empty_p)(list)); \ + M_ASSERT(!M_F(name, _empty_p)(list)); \ return M_TYPE_FROM_FIELD(type, list->name.prev, \ struct m_il1st_head_s, name); \ } \ \ static inline type * \ - M_C(name, _front)(const list_t list) \ + M_F(name, _front)(const list_t list) \ { \ M_IL1ST_CONTRACT(name, list); \ - M_ASSERT(!M_C(name, _empty_p)(list)); \ + M_ASSERT(!M_F(name, _empty_p)(list)); \ return M_TYPE_FROM_FIELD(type, list->name.next, \ struct m_il1st_head_s, name); \ } \ \ static inline type * \ - M_C(name, _next_obj)(const list_t list, type const *obj) \ + M_F(name, _next_obj)(const list_t list, type const *obj) \ { \ M_IL1ST_CONTRACT(name, list); \ M_ASSERT (obj != NULL); \ @@ -380,7 +380,7 @@ typedef struct m_il1st_head_s { } \ \ static inline type * \ - M_C(name, _previous_obj)(const list_t list, type const *obj) \ + M_F(name, _previous_obj)(const list_t list, type const *obj) \ { \ M_IL1ST_CONTRACT(name, list); \ M_ASSERT (obj != NULL); \ @@ -391,7 +391,7 @@ typedef struct m_il1st_head_s { } \ \ static inline void \ - M_C(name, _it)(it_t it, const list_t list) \ + M_F(name, _it)(it_t it, const list_t list) \ { \ M_IL1ST_CONTRACT(name, list); \ M_ASSERT (it != NULL); \ @@ -403,7 +403,7 @@ typedef struct m_il1st_head_s { } \ \ static inline void \ - M_C(name, _it_set)(it_t it, const it_t cit) \ + M_F(name, _it_set)(it_t it, const it_t cit) \ { \ M_ASSERT (it != NULL && cit != NULL); \ it->head = cit->head; \ @@ -414,7 +414,7 @@ typedef struct m_il1st_head_s { } \ \ static inline void \ - M_C(name, _it_last)(it_t it, list_t const list) \ + M_F(name, _it_last)(it_t it, list_t const list) \ { \ M_IL1ST_CONTRACT(name, list); \ M_ASSERT (it != NULL); \ @@ -426,7 +426,7 @@ typedef struct m_il1st_head_s { } \ \ static inline void \ - M_C(name, _it_end)(it_t it, list_t const list) \ + M_F(name, _it_end)(it_t it, list_t const list) \ { \ M_ASSERT (it != NULL && list != NULL); \ it->head = list->name.next->prev; \ @@ -437,7 +437,7 @@ typedef struct m_il1st_head_s { } \ \ static inline bool \ - M_C(name, _end_p)(const it_t it) \ + M_F(name, _end_p)(const it_t it) \ { \ M_ASSERT (it != NULL); \ M_IL1ST_NODE_CONTRACT(it->current); \ @@ -445,7 +445,7 @@ typedef struct m_il1st_head_s { } \ \ static inline bool \ - M_C(name, _last_p)(const it_t it) \ + M_F(name, _last_p)(const it_t it) \ { \ M_ASSERT (it != NULL); \ M_IL1ST_NODE_CONTRACT(it->current); \ @@ -453,7 +453,7 @@ typedef struct m_il1st_head_s { } \ \ static inline void \ - M_C(name, _next)(it_t it) \ + M_F(name, _next)(it_t it) \ { \ M_ASSERT (it != NULL); \ /* Cannot check node for it->current: it may have been deleted! */ \ @@ -468,7 +468,7 @@ typedef struct m_il1st_head_s { } \ \ static inline void \ - M_C(name, _previous)(it_t it) \ + M_F(name, _previous)(it_t it) \ { \ M_ASSERT (it != NULL); \ /* Cannot check node for it->current: it may have been deleted! */ \ @@ -483,7 +483,7 @@ typedef struct m_il1st_head_s { } \ \ static inline bool \ - M_C(name, _it_equal_p)(const it_t it1, const it_t it2 ) \ + M_F(name, _it_equal_p)(const it_t it1, const it_t it2 ) \ { \ M_ASSERT (it1 != NULL && it2 != NULL); \ /* No need to check for next & previous */ \ @@ -491,42 +491,42 @@ typedef struct m_il1st_head_s { } \ \ static inline type * \ - M_C(name, _ref)(const it_t it) \ + M_F(name, _ref)(const it_t it) \ { \ M_ASSERT (it != NULL && it->current != NULL); \ M_IL1ST_NODE_CONTRACT(it->current); \ /* check if 'it' was not deleted */ \ M_ASSERT (it->current->next == it->next); \ M_ASSERT (it->current->prev == it->previous); \ - M_ASSERT (!M_C(name, _end_p)(it)); \ + M_ASSERT (!M_F(name, _end_p)(it)); \ return M_TYPE_FROM_FIELD(type, it->current, \ struct m_il1st_head_s, name); \ } \ \ static inline type const * \ - M_C(name, _cref)(const it_t it) \ + M_F(name, _cref)(const it_t it) \ { \ - type *ptr = M_C(name, _ref)(it); \ + type *ptr = M_F(name, _ref)(it); \ return M_CONST_CAST(type, ptr); \ } \ \ static inline void \ - M_C(name, _remove)(list_t list, it_t it) \ + M_F(name, _remove)(list_t list, it_t it) \ { \ M_IL1ST_CONTRACT(name, list); \ M_IL1ST_NODE_CONTRACT(it->current); \ (void)list; /* list param is not used */ \ type *obj = M_TYPE_FROM_FIELD(type, it->current, \ struct m_il1st_head_s, name); \ - M_C(name, _unlink)(obj); \ + M_F(name, _unlink)(obj); \ M_CALL_CLEAR(oplist, obj); \ M_IF_METHOD(DEL, oplist)(M_CALL_DEL(oplist, obj), (void) 0); \ - M_C(name, _next)(it); \ + M_F(name, _next)(it); \ } \ \ M_IF_METHOD2(NEW, INIT_SET, oplist)( \ static inline void \ - M_C(name, _insert)(list_t list, it_t it, type x) \ + M_F(name, _insert)(list_t list, it_t it, type x) \ { \ M_IL1ST_CONTRACT(name, list); \ M_IL1ST_NODE_CONTRACT(it->current); \ @@ -536,8 +536,8 @@ typedef struct m_il1st_head_s { return ; \ } \ M_CALL_INIT_SET(oplist, *p, x); \ - type *obj = M_C(name, _ref)(it); \ - M_C(name, _push_after)(obj, p); \ + type *obj = M_F(name, _ref)(it); \ + M_F(name, _push_after)(obj, p); \ it->current = p; \ (void) list; \ M_IL1ST_CONTRACT(name, list); \ @@ -545,29 +545,29 @@ typedef struct m_il1st_head_s { , /* NEW & INIT_SET not defined */) \ \ static inline type * \ - M_C(name, _pop_back)(list_t list) \ + M_F(name, _pop_back)(list_t list) \ { \ M_IL1ST_CONTRACT(name, list); \ - M_ASSERT (!M_C(name, _empty_p)(list)); \ - type *obj = M_C(name, _back)(list); \ + M_ASSERT (!M_F(name, _empty_p)(list)); \ + type *obj = M_F(name, _back)(list); \ list->name.prev = list->name.prev->prev; \ list->name.prev->next = &list->name; \ return obj; \ } \ \ static inline type * \ - M_C(name, _pop_front)(list_t list) \ + M_F(name, _pop_front)(list_t list) \ { \ M_IL1ST_CONTRACT(name, list); \ - M_ASSERT (!M_C(name, _empty_p)(list)); \ - type *obj = M_C(name, _front)(list); \ + M_ASSERT (!M_F(name, _empty_p)(list)); \ + type *obj = M_F(name, _front)(list); \ list->name.next = list->name.next->next; \ list->name.next->prev = &list->name; \ return obj; \ } \ \ static inline void \ - M_C(name, _splice)(list_t list1, list_t list2) \ + M_F(name, _splice)(list_t list1, list_t list2) \ { \ M_IL1ST_CONTRACT(name, list1); \ M_IL1ST_CONTRACT(name, list2); \ @@ -584,35 +584,35 @@ typedef struct m_il1st_head_s { } \ \ static inline void \ - M_C(name, _splice_back)(list_t nv, list_t ov, it_t it) \ + M_F(name, _splice_back)(list_t nv, list_t ov, it_t it) \ { \ M_IL1ST_CONTRACT(name, nv); \ M_IL1ST_CONTRACT(name, ov); \ M_IL1ST_NODE_CONTRACT(it->current); \ M_ASSERT (it != NULL); \ (void) ov; \ - type *obj = M_C(name, _ref)(it); \ - M_C(name, _unlink)(obj); \ - M_C(name, _push_back)(nv, obj); \ - M_C(name, _next)(it); \ + type *obj = M_F(name, _ref)(it); \ + M_F(name, _unlink)(obj); \ + M_F(name, _push_back)(nv, obj); \ + M_F(name, _next)(it); \ M_IL1ST_CONTRACT(name, nv); \ M_IL1ST_CONTRACT(name, ov); \ } \ \ static inline void \ - M_C(name, _splice_at)(list_t nlist, it_t npos, \ + M_F(name, _splice_at)(list_t nlist, it_t npos, \ list_t olist, it_t opos) \ { \ M_IL1ST_CONTRACT(name, nlist); \ M_IL1ST_CONTRACT(name, olist); \ M_ASSERT (npos != NULL && opos != NULL); \ - M_ASSERT (!M_C(name, _end_p)(opos)); \ + M_ASSERT (!M_F(name, _end_p)(opos)); \ /* npos may be end */ \ (void) olist, (void) nlist; \ - type *obj = M_C(name, _ref)(opos); \ + type *obj = M_F(name, _ref)(opos); \ struct m_il1st_head_s *ref = npos->current; \ /* Remove object */ \ - M_C(name, _unlink)(obj); \ + M_F(name, _unlink)(obj); \ /* Push 'obj' after 'ref' */ \ struct m_il1st_head_s *next = ref->next; \ ref->next = &obj->name; \ @@ -620,7 +620,7 @@ typedef struct m_il1st_head_s { obj->name.prev = ref; \ next->prev = &obj->name; \ /* Move iterator in old list */ \ - M_C(name, _next)(opos); \ + M_F(name, _next)(opos); \ /* Set npos iterator to new position of object */ \ npos->previous = ref; \ npos->current = &obj->name; \ @@ -630,7 +630,7 @@ typedef struct m_il1st_head_s { } \ \ static inline void \ - M_C(name, _swap)(list_t d, list_t e) \ + M_F(name, _swap)(list_t d, list_t e) \ { \ M_IL1ST_CONTRACT(name, d); \ M_IL1ST_CONTRACT(name, e); \ @@ -653,7 +653,7 @@ typedef struct m_il1st_head_s { } \ \ static inline void \ - M_C(name, _reverse)(list_t list) \ + M_F(name, _reverse)(list_t list) \ { \ M_IL1ST_CONTRACT(name, list); \ struct m_il1st_head_s *next, *it; \ diff --git a/m-i-shared.h b/m-i-shared.h index 27b2d810..0907e2af 100644 --- a/m-i-shared.h +++ b/m-i-shared.h @@ -43,12 +43,12 @@ M_BEGIN_PROTECTED_CODE type: name of the type of the structure (aka. struct test_s) - not used currently. NOTE: There can be only one interface of this kind in a type! */ #define M_ISHARED_PTR_INTERFACE(name, type) \ - atomic_int M_C(name, _cpt) + atomic_int M_F(name, _cpt) /* Value of the interface field for static intialization (Uses C99 designated element). */ #define M_ISHARED_PTR_STATIC_DESIGNATED_INIT(name, type) \ - .M_C(name, _cpt) = ATOMIC_VAR_INIT(0) + .M_F(name, _cpt) = ATOMIC_VAR_INIT(0) /* Value of the interface field for static intialization (Uses C89 designated element). */ #define M_ISHARED_PTR_STATIC_INIT(name, type) \ @@ -58,7 +58,7 @@ M_BEGIN_PROTECTED_CODE /* Define the intrusive shared pointer type and its static inline functions. USAGE: ISHARED_PTR_DEF(name, type, [, oplist]) */ #define M_ISHARED_PTR_DEF(name, ...) \ - M_ISHARED_PTR_DEF_AS(name, M_C(name,_t), __VA_ARGS__) + M_ISHARED_PTR_DEF_AS(name, M_F(name,_t), __VA_ARGS__) /* Define the intrusive shared pointer type and its static inline functions @@ -90,14 +90,14 @@ M_BEGIN_PROTECTED_CODE // Define the oplist #define M_ISHAR3D_PTR_OPLIST_P3(name, oplist) ( \ INIT(M_INIT_DEFAULT), \ - INIT_SET(API_4(M_C(name, _init_set))), \ - SET(M_C(name, _set) M_IPTR), \ - CLEAR(M_C(name, _clear)), \ - RESET(M_C(name, _reset) M_IPTR), \ + INIT_SET(API_4(M_F(name, _init_set))), \ + SET(M_F(name, _set) M_IPTR), \ + CLEAR(M_F(name, _clear)), \ + RESET(M_F(name, _reset) M_IPTR), \ NAME(name), \ - TYPE(M_C(name, _ct)), \ + TYPE(M_F(name, _ct)), \ OPLIST(oplist), \ - SUBTYPE(M_C(name, _subtype_ct)) \ + SUBTYPE(M_F(name, _subtype_ct)) \ ,M_IF_METHOD(NEW, oplist)(NEW(M_GET_NEW oplist),) \ ,M_IF_METHOD(REALLOC, oplist)(REALLOC(M_GET_REALLOC oplist),) \ ,M_IF_METHOD(DEL, oplist)(DEL(M_GET_DEL oplist),) \ @@ -129,27 +129,27 @@ M_BEGIN_PROTECTED_CODE typedef type *shared_t; \ \ /* Define internal types for oplist */ \ - typedef shared_t M_C(name, _ct); \ - typedef type M_C(name, _subtype_ct); \ + typedef shared_t M_F(name, _ct); \ + typedef type M_F(name, _subtype_ct); \ /* Define the core functions */ #define M_ISHAR3D_PTR_DEF_CORE(name, type, oplist, shared_t) \ \ static inline shared_t \ - M_C(name, _init)(type *ptr) \ + M_F(name, _init)(type *ptr) \ { \ /* Initialize the type referenced by the pointer */ \ if (M_LIKELY (ptr != NULL)) { \ - atomic_init(&ptr->M_C(name, _cpt), 2); \ + atomic_init(&ptr->M_F(name, _cpt), 2); \ } \ return ptr; \ } \ \ static inline shared_t \ - M_C(name, _init_set)(shared_t shared) \ + M_F(name, _init_set)(shared_t shared) \ { \ if (M_LIKELY (shared != NULL)) { \ - int n = atomic_fetch_add(&(shared->M_C(name, _cpt)), 2); \ + int n = atomic_fetch_add(&(shared->M_F(name, _cpt)), 2); \ (void) n; \ } \ return shared; \ @@ -160,38 +160,38 @@ M_BEGIN_PROTECTED_CODE ( \ /* This function is only for static object */ \ static inline shared_t \ - M_C(name, _init_once)(type *shared) \ + M_F(name, _init_once)(type *shared) \ { \ if (M_LIKELY (shared != NULL)) { \ /* Pretty much like atomic_add, except the first one increment by 1, others by 2 */ \ - int o = atomic_load(&(shared->M_C(name, _cpt))); \ + int o = atomic_load(&(shared->M_F(name, _cpt))); \ int n; \ do { \ n = o + 1 + (o != 0); \ - } while (!atomic_compare_exchange_strong(&(shared->M_C(name, _cpt)), &o, n)); \ + } while (!atomic_compare_exchange_strong(&(shared->M_F(name, _cpt)), &o, n)); \ if (o == 0) { \ /* Partial initialization: _cpt is odd */ \ /* Call the INIT function once */ \ M_CALL_INIT(oplist, *shared); \ /* Finish initialization: _cpt is even */ \ - atomic_fetch_add(&(shared->M_C(name, _cpt)), 1); \ + atomic_fetch_add(&(shared->M_F(name, _cpt)), 1); \ } else if ( (o&1) != 0) { \ /* Not fully initialized yet: wait for initialization */ \ m_core_backoff_ct bkoff; \ m_core_backoff_init(bkoff); \ /* Wait for _cpt to be _even */ \ - while ((atomic_load(&(shared->M_C(name, _cpt)))&1) != 0 ) { \ + while ((atomic_load(&(shared->M_F(name, _cpt)))&1) != 0 ) { \ m_core_backoff_wait(bkoff); \ } \ } \ - M_ASSERT( (atomic_load(&(shared->M_C(name, _cpt)))&1) == 0); \ + M_ASSERT( (atomic_load(&(shared->M_F(name, _cpt)))&1) == 0); \ } \ return shared; \ } \ , \ /* This function is only for dynamic object */ \ static inline shared_t \ - M_C(name, _init_new)(void) \ + M_F(name, _init_new)(void) \ { \ type *ptr = M_CALL_NEW(oplist, type); \ if (M_UNLIKELY_NOMEM (ptr == NULL)) { \ @@ -199,17 +199,17 @@ M_BEGIN_PROTECTED_CODE return NULL; \ } \ M_CALL_INIT(oplist, *ptr); \ - atomic_init (&ptr->M_C(name, _cpt), 2); \ + atomic_init (&ptr->M_F(name, _cpt), 2); \ return ptr; \ } \ /* End of NEW */) \ , /* End of INIT */) \ \ static inline void \ - M_C(name, _clear)(shared_t shared) \ + M_F(name, _clear)(shared_t shared) \ { \ if (shared != NULL) { \ - if (atomic_fetch_sub(&(shared->M_C(name, _cpt)), 2) == 2) { \ + if (atomic_fetch_sub(&(shared->M_F(name, _cpt)), 2) == 2) { \ M_CALL_CLEAR(oplist, *shared); \ M_IF_DISABLED_METHOD(DEL, oplist)(, M_CALL_DEL(oplist, shared);) \ } \ @@ -217,27 +217,27 @@ M_BEGIN_PROTECTED_CODE } \ \ static inline void \ - M_C(name, _clear_ptr)(shared_t *shared) \ + M_F(name, _clear_ptr)(shared_t *shared) \ { \ M_ASSERT(shared != NULL); \ - M_C(name, _clear)(*shared); \ + M_F(name, _clear)(*shared); \ *shared = NULL; \ } \ \ static inline void \ - M_C(name, _reset)(shared_t *shared) \ + M_F(name, _reset)(shared_t *shared) \ { \ - M_C(name, _clear)(*shared); \ + M_F(name, _clear)(*shared); \ *shared = NULL; \ } \ \ static inline void \ - M_C(name, _set)(shared_t *ptr, shared_t shared) \ + M_F(name, _set)(shared_t *ptr, shared_t shared) \ { \ M_ASSERT (ptr != NULL); \ if (M_LIKELY (*ptr != shared)) { \ - M_C(name, _clear)(*ptr); \ - *ptr = M_C(name, _init_set)(shared); \ + M_F(name, _clear)(*ptr); \ + *ptr = M_F(name, _init_set)(shared); \ } \ } \ \ diff --git a/m-list.h b/m-list.h index 7bb68412..26fdcc84 100644 --- a/m-list.h +++ b/m-list.h @@ -30,7 +30,7 @@ /* Define a singly linked list of a given type. USAGE: LIST_DEF(name, type [, oplist_of_the_type]) */ #define M_LIST_DEF(name, ...) \ - M_LIST_DEF_AS(name, M_C(name, _t), M_C(name, _it_t), __VA_ARGS__) + M_LIST_DEF_AS(name, M_F(name, _t), M_F(name, _it_t), __VA_ARGS__) /* Define a singly linked list of a given type @@ -47,7 +47,7 @@ /* Define a singly linked list of a given type allowing both push. USAGE: LIST_DUAL_PUSH_DEF_AS(name, name_t, type [, oplist_of_the_type]) */ #define M_LIST_DUAL_PUSH_DEF(name, ...) \ - M_LIST_DUAL_PUSH_DEF_AS(name, M_C(name,_t), M_C(name, _it_t), __VA_ARGS__) + M_LIST_DUAL_PUSH_DEF_AS(name, M_F(name,_t), M_F(name, _it_t), __VA_ARGS__) /* Define a singly linked list of a given type allowing both push. @@ -100,47 +100,47 @@ /* OPLIST definition of a list and list_dual_push */ #define M_L1ST_OPLIST_P3(name, oplist) \ - (INIT(M_C(name, _init)), \ - INIT_SET(M_C(name, _init_set)), \ + (INIT(M_F(name, _init)), \ + INIT_SET(M_F(name, _init_set)), \ INIT_WITH(API_1(M_INIT_WITH_VAI)), \ - SET(M_C(name, _set)), \ - CLEAR(M_C(name, _clear)), \ - MOVE(M_C(name, _move)), \ - INIT_MOVE(M_C(name, _init_move)), \ - SWAP(M_C(name, _swap)), \ + SET(M_F(name, _set)), \ + CLEAR(M_F(name, _clear)), \ + MOVE(M_F(name, _move)), \ + INIT_MOVE(M_F(name, _init_move)), \ + SWAP(M_F(name, _swap)), \ NAME(name), \ - TYPE(M_C(name,_ct)), \ - SUBTYPE(M_C(name,_subtype_ct)), \ - EMPTY_P(M_C(name,_empty_p)), \ - IT_TYPE(M_C(name, _it_ct)), \ - IT_FIRST(M_C(name,_it)), \ - IT_END(M_C(name,_it_end)), \ - IT_SET(M_C(name,_it_set)), \ - IT_END_P(M_C(name,_end_p)), \ - IT_EQUAL_P(M_C(name,_it_equal_p)), \ - IT_LAST_P(M_C(name,_last_p)), \ - IT_NEXT(M_C(name,_next)), \ - IT_REF(M_C(name,_ref)), \ - IT_CREF(M_C(name,_cref)), \ - IT_INSERT(M_C(name, _insert)), \ - IT_REMOVE(M_C(name,_remove)), \ - RESET(M_C(name,_reset)), \ - PUSH(M_C(name,_push_back)), \ - POP(M_C(name,_pop_back)), \ - PUSH_MOVE(M_C(name,_push_move)), \ - POP_MOVE(M_C(name,_pop_move)) \ - ,SPLICE_BACK(M_C(name,_splice_back)) \ - ,SPLICE_AT(M_C(name,_splice_at)) \ - ,REVERSE(M_C(name,_reverse)) \ + TYPE(M_F(name,_ct)), \ + SUBTYPE(M_F(name,_subtype_ct)), \ + EMPTY_P(M_F(name,_empty_p)), \ + IT_TYPE(M_F(name, _it_ct)), \ + IT_FIRST(M_F(name,_it)), \ + IT_END(M_F(name,_it_end)), \ + IT_SET(M_F(name,_it_set)), \ + IT_END_P(M_F(name,_end_p)), \ + IT_EQUAL_P(M_F(name,_it_equal_p)), \ + IT_LAST_P(M_F(name,_last_p)), \ + IT_NEXT(M_F(name,_next)), \ + IT_REF(M_F(name,_ref)), \ + IT_CREF(M_F(name,_cref)), \ + IT_INSERT(M_F(name, _insert)), \ + IT_REMOVE(M_F(name,_remove)), \ + RESET(M_F(name,_reset)), \ + PUSH(M_F(name,_push_back)), \ + POP(M_F(name,_pop_back)), \ + PUSH_MOVE(M_F(name,_push_move)), \ + POP_MOVE(M_F(name,_pop_move)) \ + ,SPLICE_BACK(M_F(name,_splice_back)) \ + ,SPLICE_AT(M_F(name,_splice_at)) \ + ,REVERSE(M_F(name,_reverse)) \ ,OPLIST(oplist) \ - ,M_IF_METHOD(GET_STR, oplist)(GET_STR(M_C(name, _get_str)),) \ - ,M_IF_METHOD(OUT_STR, oplist)(OUT_STR(M_C(name, _out_str)),) \ - ,M_IF_METHOD(PARSE_STR, oplist)(PARSE_STR(M_C(name, _parse_str)),) \ - ,M_IF_METHOD(IN_STR, oplist)(IN_STR(M_C(name, _in_str)),) \ - ,M_IF_METHOD(OUT_SERIAL, oplist)(OUT_SERIAL(M_C(name, _out_serial)),) \ - ,M_IF_METHOD(IN_SERIAL, oplist)(IN_SERIAL(M_C(name, _in_serial)),) \ - ,M_IF_METHOD(EQUAL, oplist)(EQUAL(M_C(name, _equal_p)),) \ - ,M_IF_METHOD(HASH, oplist)(HASH(M_C(name, _hash)),) \ + ,M_IF_METHOD(GET_STR, oplist)(GET_STR(M_F(name, _get_str)),) \ + ,M_IF_METHOD(OUT_STR, oplist)(OUT_STR(M_F(name, _out_str)),) \ + ,M_IF_METHOD(PARSE_STR, oplist)(PARSE_STR(M_F(name, _parse_str)),) \ + ,M_IF_METHOD(IN_STR, oplist)(IN_STR(M_F(name, _in_str)),) \ + ,M_IF_METHOD(OUT_SERIAL, oplist)(OUT_SERIAL(M_F(name, _out_serial)),) \ + ,M_IF_METHOD(IN_SERIAL, oplist)(IN_SERIAL(M_F(name, _in_serial)),) \ + ,M_IF_METHOD(EQUAL, oplist)(EQUAL(M_F(name, _equal_p)),) \ + ,M_IF_METHOD(HASH, oplist)(HASH(M_F(name, _hash)),) \ ,M_IF_METHOD(NEW, oplist)(NEW(M_GET_NEW oplist),) \ ,M_IF_METHOD(REALLOC, oplist)(REALLOC(M_GET_REALLOC oplist),) \ ,M_IF_METHOD(DEL, oplist)(DEL(M_GET_DEL oplist),) \ @@ -162,21 +162,21 @@ #define M_L1ST_MEMPOOL_DEF(name, type, oplist, list_t, list_it_t) \ M_IF_METHOD(MEMPOOL, oplist)( \ \ - MEMPOOL_DEF(M_C(name, _mempool), struct M_C(name, _s)) \ - M_GET_MEMPOOL_LINKAGE oplist M_C(name, _mempool_t) M_GET_MEMPOOL oplist; \ - static inline struct M_C(name, _s) *M_C3(m_l1st_,name,_new)(void) { \ - return M_C(name, _mempool_alloc)(M_GET_MEMPOOL oplist); \ + MEMPOOL_DEF(M_F(name, _mempool), struct M_F(name, _s)) \ + M_GET_MEMPOOL_LINKAGE oplist M_F(name, _mempool_t) M_GET_MEMPOOL oplist; \ + static inline struct M_F(name, _s) *M_C3(m_l1st_,name,_new)(void) { \ + return M_F(name, _mempool_alloc)(M_GET_MEMPOOL oplist); \ } \ - static inline void M_C3(m_l1st_,name,_del)(struct M_C(name, _s) *ptr) { \ - M_C(name, _mempool_free)(M_GET_MEMPOOL oplist, ptr); \ + static inline void M_C3(m_l1st_,name,_del)(struct M_F(name, _s) *ptr) { \ + M_F(name, _mempool_free)(M_GET_MEMPOOL oplist, ptr); \ } \ \ , /* No mempool allocation */ \ \ - static inline struct M_C(name, _s) *M_C3(m_l1st_,name,_new)(void) { \ - return M_CALL_NEW(oplist, struct M_C(name, _s)); \ + static inline struct M_F(name, _s) *M_C3(m_l1st_,name,_new)(void) { \ + return M_CALL_NEW(oplist, struct M_F(name, _s)); \ } \ - static inline void M_C3(m_l1st_,name,_del)(struct M_C(name, _s) *ptr) { \ + static inline void M_C3(m_l1st_,name,_del)(struct M_F(name, _s) *ptr) { \ M_CALL_DEL(oplist, ptr); \ } \ ) \ @@ -186,30 +186,30 @@ - name: prefix to be used - type: type of the elements of the list - oplist: oplist of the type of the elements of the container - - list_t: alias for M_C(name, _t) [ type of the container ] - - it_t: alias for M_C(name, _it_t) [ iterator of the container ] - - node_t: alias for M_C(name, _node_t) [ node ] + - list_t: alias for M_F(name, _t) [ type of the container ] + - it_t: alias for M_F(name, _it_t) [ iterator of the container ] + - node_t: alias for M_F(name, _node_t) [ node ] */ #define M_L1ST_DEF_P3(name, type, oplist, list_t, it_t) \ \ /* Define the node of a list, and the list as a pointer to a node */ \ - typedef struct M_C(name, _s) { \ - struct M_C(name, _s) *next; /* Next node or NULL if final node */ \ + typedef struct M_F(name, _s) { \ + struct M_F(name, _s) *next; /* Next node or NULL if final node */ \ type data; /* The data itself */ \ } *list_t[1]; \ \ /* Define an iterator of a list */ \ - typedef struct M_C(name, _it_s) { \ - struct M_C(name, _s) *previous; /* Previous node or NULL */ \ - struct M_C(name, _s) *current; /* Current node or NULL */ \ + typedef struct M_F(name, _it_s) { \ + struct M_F(name, _s) *previous; /* Previous node or NULL */ \ + struct M_F(name, _s) *current; /* Current node or NULL */ \ } it_t[1]; \ \ /* Definition of the synonyms of the type */ \ - typedef struct M_C(name, _s) *M_C(name, _ptr); \ - typedef const struct M_C(name, _s) *M_C(name, _srcptr); \ - typedef list_t M_C(name, _ct); \ - typedef it_t M_C(name, _it_ct); \ - typedef type M_C(name, _subtype_ct); \ + typedef struct M_F(name, _s) *M_F(name, _ptr); \ + typedef const struct M_F(name, _s) *M_F(name, _srcptr); \ + typedef list_t M_F(name, _ct); \ + typedef it_t M_F(name, _it_ct); \ + typedef type M_F(name, _subtype_ct); \ \ M_CHECK_COMPATIBLE_OPLIST(name, 1, type, oplist) \ \ @@ -235,20 +235,20 @@ #define M_L1ST_DEF_P4(name, type, oplist, list_t, it_t) \ \ static inline void \ - M_C(name, _init)(list_t v) \ + M_F(name, _init)(list_t v) \ { \ M_ASSERT (v != NULL); \ *v = NULL; \ } \ \ static inline void \ - M_C(name, _reset)(list_t v) \ + M_F(name, _reset)(list_t v) \ { \ M_L1ST_CONTRACT(v); \ - struct M_C(name, _s) *it = *v; \ + struct M_F(name, _s) *it = *v; \ *v = NULL; \ while (it != NULL) { \ - struct M_C(name, _s) *next = it->next; \ + struct M_F(name, _s) *next = it->next; \ M_CALL_CLEAR(oplist, it->data); \ M_C3(m_l1st_,name,_del)(it); \ it = next; \ @@ -257,13 +257,13 @@ } \ \ static inline void \ - M_C(name, _clear)(list_t v) \ + M_F(name, _clear)(list_t v) \ { \ - M_C(name, _reset)(v); \ + M_F(name, _reset)(v); \ } \ \ static inline type * \ - M_C(name, _back)(const list_t v) \ + M_F(name, _back)(const list_t v) \ { \ M_L1ST_CONTRACT(v); \ M_ASSERT(*v != NULL); \ @@ -271,13 +271,13 @@ } \ \ static inline type * \ - M_C(name, _push_raw)(list_t v) \ + M_F(name, _push_raw)(list_t v) \ { \ M_L1ST_CONTRACT(v); \ - struct M_C(name, _s) *next; \ + struct M_F(name, _s) *next; \ next = M_C3(m_l1st_,name,_new)(); \ if (M_UNLIKELY_NOMEM (next == NULL)) { \ - M_MEMORY_FULL(sizeof (struct M_C(name, _s))); \ + M_MEMORY_FULL(sizeof (struct M_F(name, _s))); \ return NULL; \ } \ type *ret = &next->data; \ @@ -288,9 +288,9 @@ } \ \ static inline void \ - M_C(name, _push_back)(list_t v, type const x) \ + M_F(name, _push_back)(list_t v, type const x) \ { \ - type *data = M_C(name, _push_raw)(v); \ + type *data = M_F(name, _push_raw)(v); \ if (M_UNLIKELY (data == NULL)) \ return; \ M_CALL_INIT_SET(oplist, *data, x); \ @@ -298,9 +298,9 @@ \ M_IF_METHOD(INIT, oplist)( \ static inline type * \ - M_C(name, _push_new)(list_t v) \ + M_F(name, _push_new)(list_t v) \ { \ - type *data = M_C(name, _push_raw)(v); \ + type *data = M_F(name, _push_raw)(v); \ if (M_UNLIKELY (data == NULL)) \ return NULL; \ M_CALL_INIT(oplist, *data); \ @@ -309,7 +309,7 @@ , /* No INIT */) \ \ static inline void \ - M_C(name, _pop_back)(type *data, list_t v) \ + M_F(name, _pop_back)(type *data, list_t v) \ { \ M_L1ST_CONTRACT(v); \ M_ASSERT(*v != NULL); \ @@ -318,53 +318,53 @@ } else { \ M_CALL_CLEAR(oplist, (*v)->data); \ } \ - struct M_C(name, _s) *tofree = *v; \ + struct M_F(name, _s) *tofree = *v; \ *v = (*v)->next; \ M_C3(m_l1st_,name,_del)(tofree); \ M_L1ST_CONTRACT(v); \ } \ \ static inline void \ - M_C(name, _push_move)(list_t v, type *x) \ + M_F(name, _push_move)(list_t v, type *x) \ { \ M_ASSERT (x != NULL); \ - type *data = M_C(name, _push_raw)(v); \ + type *data = M_F(name, _push_raw)(v); \ if (M_UNLIKELY (data == NULL)) \ return; \ M_DO_INIT_MOVE (oplist, *data, *x); \ } \ \ static inline void \ - M_C(name, _pop_move)(type *data, list_t v) \ + M_F(name, _pop_move)(type *data, list_t v) \ { \ M_L1ST_CONTRACT(v); \ M_ASSERT(*v != NULL && data != NULL); \ M_DO_INIT_MOVE (oplist, *data, (*v)->data); \ - struct M_C(name, _s) *tofree = *v; \ + struct M_F(name, _s) *tofree = *v; \ *v = (*v)->next; \ M_C3(m_l1st_,name,_del)(tofree); \ M_L1ST_CONTRACT(v); \ } \ \ static inline bool \ - M_C(name, _empty_p)(const list_t v) \ + M_F(name, _empty_p)(const list_t v) \ { \ M_L1ST_CONTRACT(v); \ return *v == NULL; \ } \ \ static inline void \ - M_C(name, _swap)(list_t l, list_t v) \ + M_F(name, _swap)(list_t l, list_t v) \ { \ M_L1ST_CONTRACT(l); \ M_L1ST_CONTRACT(v); \ - M_SWAP(struct M_C(name, _s) *, *l, *v); \ + M_SWAP(struct M_F(name, _s) *, *l, *v); \ M_L1ST_CONTRACT(l); \ M_L1ST_CONTRACT(v); \ } \ \ static inline void \ - M_C(name, _it)(it_t it, const list_t v) \ + M_F(name, _it)(it_t it, const list_t v) \ { \ M_L1ST_CONTRACT(v); \ M_ASSERT (it != NULL); \ @@ -373,7 +373,7 @@ } \ \ static inline void \ - M_C(name, _it_set)(it_t it1, const it_t it2) \ + M_F(name, _it_set)(it_t it1, const it_t it2) \ { \ M_ASSERT (it1 != NULL && it2 != NULL); \ it1->current = it2->current; \ @@ -381,7 +381,7 @@ } \ \ static inline void \ - M_C(name, _it_end)(it_t it1, const list_t v) \ + M_F(name, _it_end)(it_t it1, const list_t v) \ { \ M_L1ST_CONTRACT(v); \ M_ASSERT (it1 != NULL); \ @@ -391,21 +391,21 @@ } \ \ static inline bool \ - M_C(name, _end_p)(const it_t it) \ + M_F(name, _end_p)(const it_t it) \ { \ M_ASSERT (it != NULL); \ return it->current == NULL; \ } \ \ static inline bool \ - M_C(name, _last_p)(const it_t it) \ + M_F(name, _last_p)(const it_t it) \ { \ M_ASSERT (it != NULL); \ return it->current == NULL || it->current->next == NULL; \ } \ \ static inline void \ - M_C(name, _next)(it_t it) \ + M_F(name, _next)(it_t it) \ { \ M_ASSERT(it != NULL && it->current != NULL); \ it->previous = it->current; \ @@ -413,32 +413,32 @@ } \ \ static inline bool \ - M_C(name, _it_equal_p)(const it_t it1, const it_t it2) \ + M_F(name, _it_equal_p)(const it_t it1, const it_t it2) \ { \ M_ASSERT(it1 != NULL && it2 != NULL); \ return it1->current == it2->current; \ } \ \ static inline type * \ - M_C(name, _ref)(const it_t it) \ + M_F(name, _ref)(const it_t it) \ { \ M_ASSERT(it != NULL && it->current != NULL); \ return &(it->current->data); \ } \ \ static inline type const * \ - M_C(name, _cref)(const it_t it) \ + M_F(name, _cref)(const it_t it) \ { \ M_ASSERT(it != NULL && it->current != NULL); \ return M_CONST_CAST(type, &(it->current->data)); \ } \ \ static inline size_t \ - M_C(name, _size)(const list_t list) \ + M_F(name, _size)(const list_t list) \ { \ M_L1ST_CONTRACT(list); \ size_t size = 0; \ - struct M_C(name, _s) *it = *list; \ + struct M_F(name, _s) *it = *list; \ while (it != NULL) { \ size ++; \ it = it->next; \ @@ -447,11 +447,11 @@ } \ \ static inline bool \ - M_C(name, _sublist_p)(const list_t list, const it_t itsub) \ + M_F(name, _sublist_p)(const list_t list, const it_t itsub) \ { \ M_L1ST_CONTRACT(list); \ M_ASSERT (itsub != NULL); \ - struct M_C(name, _s) *it = *list; \ + struct M_F(name, _s) *it = *list; \ while (it != NULL) { \ if (it == itsub->current) return true; \ it = it->next; \ @@ -461,12 +461,12 @@ } \ \ static inline type * \ - M_C(name, _get)(const list_t list, size_t i) \ + M_F(name, _get)(const list_t list, size_t i) \ { \ M_L1ST_CONTRACT(list); \ - struct M_C(name, _s) *it = *list; \ + struct M_F(name, _s) *it = *list; \ /* FIXME: How to avoid the double iteration over the list? */ \ - size_t len = M_C(name,_size)(list); \ + size_t len = M_F(name,_size)(list); \ M_ASSERT_INDEX (i, len); \ size_t j = len-1; \ while (true) { \ @@ -478,25 +478,25 @@ } \ \ static inline type const * \ - M_C(name, _cget)(const list_t l, size_t i) \ + M_F(name, _cget)(const list_t l, size_t i) \ { \ - return M_CONST_CAST(type, M_C(name, _get)(l,i)); \ + return M_CONST_CAST(type, M_F(name, _get)(l,i)); \ } \ \ static inline void \ - M_C(name, _insert)(list_t list, it_t insertion_point, \ + M_F(name, _insert)(list_t list, it_t insertion_point, \ type const x) \ { \ M_L1ST_CONTRACT(list); \ M_ASSERT (insertion_point != NULL); \ - M_ASSERT(M_C(name, _sublist_p)(list, insertion_point)); \ - struct M_C(name, _s) *next = M_C3(m_l1st_,name,_new)(); \ + M_ASSERT(M_F(name, _sublist_p)(list, insertion_point)); \ + struct M_F(name, _s) *next = M_C3(m_l1st_,name,_new)(); \ if (M_UNLIKELY_NOMEM (next == NULL)) { \ - M_MEMORY_FULL(sizeof (struct M_C(name, _s))); \ + M_MEMORY_FULL(sizeof (struct M_F(name, _s))); \ return; \ } \ M_CALL_INIT_SET(oplist, next->data, x); \ - struct M_C(name, _s) *current = insertion_point->current; \ + struct M_F(name, _s) *current = insertion_point->current; \ if (M_UNLIKELY (current == NULL)) { \ next->next = *list; \ *list = next; \ @@ -510,13 +510,13 @@ } \ \ static inline void \ - M_C(name, _remove)(list_t list, it_t removing_point) \ + M_F(name, _remove)(list_t list, it_t removing_point) \ { \ M_L1ST_CONTRACT(list); \ M_ASSERT (removing_point != NULL); \ M_ASSERT (removing_point->current != NULL); \ - M_ASSERT(M_C(name, _sublist_p)(list, removing_point)); \ - struct M_C(name, _s) *next = removing_point->current->next; \ + M_ASSERT(M_F(name, _sublist_p)(list, removing_point)); \ + struct M_F(name, _s) *next = removing_point->current->next; \ if (M_UNLIKELY (removing_point->previous == NULL)) { \ *list = next; \ } else { \ @@ -529,18 +529,18 @@ } \ \ static inline void \ - M_C(name, _init_set)(list_t list, const list_t org) \ + M_F(name, _init_set)(list_t list, const list_t org) \ { \ M_L1ST_CONTRACT(org); \ - struct M_C(name, _s) *next, *it_org; \ - struct M_C(name, _s) **update_list; \ + struct M_F(name, _s) *next, *it_org; \ + struct M_F(name, _s) **update_list; \ update_list = list; \ it_org = *org; \ while (it_org != NULL) { \ next = M_C3(m_l1st_,name,_new)(); \ *update_list = next; \ if (M_UNLIKELY_NOMEM (next == NULL)) { \ - M_MEMORY_FULL(sizeof (struct M_C(name, _s))); \ + M_MEMORY_FULL(sizeof (struct M_F(name, _s))); \ /* FIXME: Partialy initialized list. What to do? */ \ return; \ } \ @@ -553,15 +553,15 @@ } \ \ static inline void \ - M_C(name, _set)(list_t list, const list_t org) \ + M_F(name, _set)(list_t list, const list_t org) \ { \ if (M_UNLIKELY (list == org)) return; \ - M_C(name, _clear)(list); \ - M_C(name, _init_set)(list, org); \ + M_F(name, _clear)(list); \ + M_F(name, _init_set)(list, org); \ } \ \ static inline void \ - M_C(name, _init_move)(list_t list, list_t org) \ + M_F(name, _init_move)(list_t list, list_t org) \ { \ M_L1ST_CONTRACT(org); \ M_ASSERT (list != NULL && list != org); \ @@ -570,24 +570,24 @@ } \ \ static inline void \ - M_C(name, _move)(list_t list, list_t org) \ + M_F(name, _move)(list_t list, list_t org) \ { \ M_ASSERT (list != org); \ - M_C(name, _clear)(list); \ - M_C(name, _init_move)(list, org); \ + M_F(name, _clear)(list); \ + M_F(name, _init_move)(list, org); \ } \ \ static inline void \ - M_C(name, _splice_back)(list_t nv, list_t ov, it_t it) \ + M_F(name, _splice_back)(list_t nv, list_t ov, it_t it) \ { \ M_L1ST_CONTRACT(nv); \ M_L1ST_CONTRACT(ov); \ M_ASSERT (it != NULL); \ M_ASSERT (it->current != NULL); \ - M_ASSERT (M_C(name, _sublist_p)(ov, it)); \ + M_ASSERT (M_F(name, _sublist_p)(ov, it)); \ /* Remove the item 'it' from the list 'ov' */ \ - struct M_C(name, _s) *current = it->current; \ - struct M_C(name, _s) *next = current->next; \ + struct M_F(name, _s) *current = it->current; \ + struct M_F(name, _s) *next = current->next; \ if (it->previous == NULL) { \ *ov = next; \ } else { \ @@ -602,20 +602,20 @@ } \ \ static inline void \ - M_C(name, _splice_at)(list_t nlist, it_t npos, \ + M_F(name, _splice_at)(list_t nlist, it_t npos, \ list_t olist, it_t opos) \ { \ M_L1ST_CONTRACT(nlist); \ M_L1ST_CONTRACT(olist); \ M_ASSERT (npos != NULL); \ M_ASSERT (opos != NULL); \ - M_ASSERT (M_C(name, _sublist_p)(nlist, npos)); \ - M_ASSERT (M_C(name, _sublist_p)(olist, opos)); \ + M_ASSERT (M_F(name, _sublist_p)(nlist, npos)); \ + M_ASSERT (M_F(name, _sublist_p)(olist, opos)); \ /* Remove the item 'opos' from the list 'olist' */ \ - struct M_C(name, _s) *current = opos->current; \ + struct M_F(name, _s) *current = opos->current; \ /* current shall reference a valid element of the list */ \ M_ASSERT (current != NULL); \ - struct M_C(name, _s) *next = current->next; \ + struct M_F(name, _s) *next = current->next; \ if (opos->previous == NULL) { \ *olist = next; \ } else { \ @@ -624,7 +624,7 @@ /* Update 'opos' to point to the next element */ \ opos->current = next; \ /* Insert 'current' into 'nlist' just after 'npos' */ \ - struct M_C(name, _s) *previous = npos->current; \ + struct M_F(name, _s) *previous = npos->current; \ if (M_UNLIKELY (previous == NULL)) { \ current->next = *nlist; \ *nlist = current; \ @@ -640,13 +640,13 @@ } \ \ static inline void \ - M_C(name, _splice)(list_t list1, list_t list2) \ + M_F(name, _splice)(list_t list1, list_t list2) \ { \ M_L1ST_CONTRACT(list1); \ M_L1ST_CONTRACT(list2); \ M_ASSERT (list1 != list2); \ - struct M_C(name, _s) **update_list = list1; \ - struct M_C(name, _s) *it = *list1; \ + struct M_F(name, _s) **update_list = list1; \ + struct M_F(name, _s) *it = *list1; \ while (it != NULL) { \ update_list = &it->next; \ it = it->next; \ @@ -656,10 +656,10 @@ } \ \ static inline void \ - M_C(name, _reverse)(list_t list) \ + M_F(name, _reverse)(list_t list) \ { \ M_L1ST_CONTRACT(list); \ - struct M_C(name, _s) *previous = NULL, *it = *list, *next; \ + struct M_F(name, _s) *previous = NULL, *it = *list, *next; \ while (it != NULL) { \ next = it->next; \ it->next = previous; \ @@ -669,7 +669,7 @@ *list = previous; \ } \ \ - M_EMPLACE_QUEUE_DEF(name, list_t, M_C(name, _emplace_back), oplist, M_L1ST_EMPLACE_DEF) + M_EMPLACE_QUEUE_DEF(name, list_t, M_F(name, _emplace_back), oplist, M_L1ST_EMPLACE_DEF) /* Internal list function definition using only iterator functions @@ -679,25 +679,25 @@ - name: prefix to be used - type: type of the elements of the list - oplist: oplist of the type of the elements of the container - - list_t: alias for M_C(name, _t) [ type of the container ] - - it_t: alias for M_C(name, _it_t) [ iterator of the container ] + - list_t: alias for M_F(name, _t) [ type of the container ] + - it_t: alias for M_F(name, _it_t) [ iterator of the container ] */ #define M_L1ST_ITBASE_DEF(name, type, oplist, list_t, it_t) \ \ M_IF_METHOD(GET_STR, oplist)( \ static inline void \ - M_C(name, _get_str)(m_string_t str, const list_t list, \ + M_F(name, _get_str)(m_string_t str, const list_t list, \ bool append) \ { \ M_ASSERT (str != NULL && list != NULL); \ (append ? m_string_cat_cstr : m_string_set_cstr) (str, "["); \ it_t it; \ - for (M_C(name, _it)(it, list) ; \ - !M_C(name, _end_p)(it); \ - M_C(name, _next)(it)){ \ - type const *item = M_C(name, _cref)(it); \ + for (M_F(name, _it)(it, list) ; \ + !M_F(name, _end_p)(it); \ + M_F(name, _next)(it)){ \ + type const *item = M_F(name, _cref)(it); \ M_CALL_GET_STR(oplist, str, *item, true); \ - if (!M_C(name, _last_p)(it)) \ + if (!M_F(name, _last_p)(it)) \ m_string_push_back (str, M_GET_SEPARATOR oplist); \ } \ m_string_push_back (str, ']'); \ @@ -706,17 +706,17 @@ \ M_IF_METHOD(OUT_STR, oplist)( \ static inline void \ - M_C(name, _out_str)(FILE *file, const list_t list) \ + M_F(name, _out_str)(FILE *file, const list_t list) \ { \ M_ASSERT (file != NULL && list != NULL); \ fputc ('[', file); \ it_t it; \ - for (M_C(name, _it)(it, list) ; \ - !M_C(name, _end_p)(it); \ - M_C(name, _next)(it)){ \ - type const *item = M_C(name, _cref)(it); \ + for (M_F(name, _it)(it, list) ; \ + !M_F(name, _end_p)(it); \ + M_F(name, _next)(it)){ \ + type const *item = M_F(name, _cref)(it); \ M_CALL_OUT_STR(oplist, file, *item); \ - if (!M_C(name, _last_p)(it)) \ + if (!M_F(name, _last_p)(it)) \ fputc (M_GET_SEPARATOR oplist, file); \ } \ fputc (']', file); \ @@ -725,10 +725,10 @@ \ M_IF_METHOD2(PARSE_STR, INIT, oplist)( \ static inline bool \ - M_C(name, _parse_str)(list_t list, const char str[], const char **endp) \ + M_F(name, _parse_str)(list_t list, const char str[], const char **endp) \ { \ M_ASSERT (str != NULL && list != NULL); \ - M_C(name,_reset)(list); \ + M_F(name,_reset)(list); \ bool success = false; \ int c = *str++; \ if (M_UNLIKELY (c != '[')) goto exit; \ @@ -742,9 +742,9 @@ bool b = M_CALL_PARSE_STR(oplist, item, str, &str); \ do { c = *str++; } while (isspace(c)); \ if (b == false || c == 0) { goto exit_clear; } \ - M_C(name, _push_back)(list, item); \ + M_F(name, _push_back)(list, item); \ } while (c == M_GET_SEPARATOR oplist); \ - M_C(name, _reverse)(list); \ + M_F(name, _reverse)(list); \ success = (c == ']'); \ exit_clear: \ M_CALL_CLEAR(oplist, item); \ @@ -756,10 +756,10 @@ \ M_IF_METHOD2(IN_STR, INIT, oplist)( \ static inline bool \ - M_C(name, _in_str)(list_t list, FILE *file) \ + M_F(name, _in_str)(list_t list, FILE *file) \ { \ M_ASSERT (file != NULL && list != NULL); \ - M_C(name,_reset)(list); \ + M_F(name,_reset)(list); \ int c = fgetc(file); \ if (M_UNLIKELY (c != '[')) return false; \ c = fgetc(file); \ @@ -772,17 +772,17 @@ bool b = M_CALL_IN_STR(oplist, item, file); \ do { c = fgetc(file); } while (isspace(c)); \ if (b == false || c == EOF) { break; } \ - M_C(name, _push_back)(list, item); \ + M_F(name, _push_back)(list, item); \ } while (c == M_GET_SEPARATOR oplist); \ M_CALL_CLEAR(oplist, item); \ - M_C(name, _reverse)(list); \ + M_F(name, _reverse)(list); \ return c == ']'; \ } \ , /* no IN_STR & INIT */ ) \ \ M_IF_METHOD(OUT_SERIAL, oplist)( \ static inline m_serial_return_code_t \ - M_C(name, _out_serial)(m_serial_write_t f, const list_t list) \ + M_F(name, _out_serial)(m_serial_write_t f, const list_t list) \ { \ M_ASSERT (list != NULL); \ M_ASSERT (f != NULL && f->m_interface != NULL); \ @@ -791,10 +791,10 @@ bool first_done = false; \ ret = f->m_interface->write_array_start(local, f, 0); \ it_t it; \ - for (M_C(name, _it)(it, list) ; \ - !M_C(name, _end_p)(it); \ - M_C(name, _next)(it)){ \ - type const *item = M_C(name, _cref)(it); \ + for (M_F(name, _it)(it, list) ; \ + !M_F(name, _end_p)(it); \ + M_F(name, _next)(it)){ \ + type const *item = M_F(name, _cref)(it); \ if (first_done) \ ret |= f->m_interface->write_array_next(local, f); \ ret |= M_CALL_OUT_SERIAL(oplist, f, *item); \ @@ -807,14 +807,14 @@ \ M_IF_METHOD2(IN_SERIAL, INIT, oplist)( \ static inline m_serial_return_code_t \ - M_C(name, _in_serial)(list_t list, m_serial_read_t f) \ + M_F(name, _in_serial)(list_t list, m_serial_read_t f) \ { \ M_ASSERT (list != NULL); \ M_ASSERT (f != NULL && f->m_interface != NULL); \ m_serial_return_code_t ret; \ m_serial_local_t local; \ size_t estimated_size = 0; \ - M_C(name,_reset)(list); \ + M_F(name,_reset)(list); \ ret = f->m_interface->read_array_start(local, f, &estimated_size); \ if (M_UNLIKELY (ret != M_SERIAL_OK_CONTINUE)) return ret; \ type item; \ @@ -822,50 +822,50 @@ do { \ ret = M_CALL_IN_SERIAL(oplist, item, f); \ if (ret != M_SERIAL_OK_DONE) { break; } \ - M_C(name, _push_back)(list, item); \ + M_F(name, _push_back)(list, item); \ ret = f->m_interface->read_array_next(local, f); \ } while (ret == M_SERIAL_OK_CONTINUE); \ M_CALL_CLEAR(oplist, item); \ - M_C(name, _reverse)(list); \ + M_F(name, _reverse)(list); \ return ret; \ } \ , /* no IN_SERIAL & INIT */ ) \ \ M_IF_METHOD(EQUAL, oplist)( \ static inline bool \ - M_C(name, _equal_p)(const list_t list1, const list_t list2) \ + M_F(name, _equal_p)(const list_t list1, const list_t list2) \ { \ M_ASSERT (list1 != NULL && list2 != NULL); \ it_t it1; \ it_t it2; \ if (list1 == list2) return true; \ - M_C(name, _it)(it1, list1); \ - M_C(name, _it)(it2, list2); \ - while (!M_C(name, _end_p)(it1) \ - &&!M_C(name, _end_p)(it2)) { \ - type const *item1 = M_C(name, _cref)(it1); \ - type const *item2 = M_C(name, _cref)(it2); \ + M_F(name, _it)(it1, list1); \ + M_F(name, _it)(it2, list2); \ + while (!M_F(name, _end_p)(it1) \ + &&!M_F(name, _end_p)(it2)) { \ + type const *item1 = M_F(name, _cref)(it1); \ + type const *item2 = M_F(name, _cref)(it2); \ bool b = M_CALL_EQUAL(oplist, *item1, *item2); \ if (!b) return false; \ - M_C(name, _next)(it1); \ - M_C(name, _next)(it2); \ + M_F(name, _next)(it1); \ + M_F(name, _next)(it2); \ } \ - return M_C(name, _end_p)(it1) \ - && M_C(name, _end_p)(it2); \ + return M_F(name, _end_p)(it1) \ + && M_F(name, _end_p)(it2); \ } \ , /* no equal */ ) \ \ M_IF_METHOD(HASH, oplist)( \ static inline size_t \ - M_C(name, _hash)(const list_t list) \ + M_F(name, _hash)(const list_t list) \ { \ M_ASSERT (list != NULL); \ M_HASH_DECL(hash); \ it_t it; \ - for(M_C(name, _it)(it, list) ; \ - !M_C(name, _end_p)(it); \ - M_C(name, _next)(it)) { \ - type const *item = M_C(name, _cref)(it); \ + for(M_F(name, _it)(it, list) ; \ + !M_F(name, _end_p)(it); \ + M_F(name, _next)(it)) { \ + type const *item = M_F(name, _cref)(it); \ size_t hi = M_CALL_HASH(oplist, *item); \ M_HASH_UP(hash, hi); \ } \ @@ -880,7 +880,7 @@ function_name(name_t v \ M_EMPLACE_LIST_TYPE_VAR(a, exp_emplace_type) ) \ { \ - M_C(name, _subtype_ct) *data = M_C(name, _push_raw)(v); \ + M_F(name, _subtype_ct) *data = M_F(name, _push_raw)(v); \ if (M_UNLIKELY (data == NULL) ) \ return; \ M_EMPLACE_CALL_FUNC(a, init_func, oplist, *data, exp_emplace_type); \ @@ -893,7 +893,7 @@ function_name(name_t v \ M_EMPLACE_LIST_TYPE_VAR(a, exp_emplace_type) ) \ { \ - M_C(name, _subtype_ct) *data = M_C(name, _push_back_raw)(v); \ + M_F(name, _subtype_ct) *data = M_F(name, _push_back_raw)(v); \ if (M_UNLIKELY (data == NULL) ) \ return; \ M_EMPLACE_CALL_FUNC(a, init_func, oplist, *data, exp_emplace_type); \ @@ -906,7 +906,7 @@ function_name(name_t v \ M_EMPLACE_LIST_TYPE_VAR(a, exp_emplace_type) ) \ { \ - M_C(name, _subtype_ct) *data = M_C(name, _push_front_raw)(v); \ + M_F(name, _subtype_ct) *data = M_F(name, _push_front_raw)(v); \ if (M_UNLIKELY (data == NULL) ) \ return; \ M_EMPLACE_CALL_FUNC(a, init_func, oplist, *data, exp_emplace_type); \ @@ -929,14 +929,14 @@ - name: prefix to be used - type: type of the elements of the array - oplist: oplist of the type of the elements of the container - - list_t: alias for M_C(name, _t) [ type of the container ] - - it_t: alias for M_C(name, _it_t) [ iterator of the container ] + - list_t: alias for M_F(name, _t) [ type of the container ] + - it_t: alias for M_F(name, _it_t) [ iterator of the container ] */ #define M_L1ST_DUAL_PUSH_DEF_P3(name, type, oplist, list_t, it_t) \ \ /* Node of a list (it is liked the singly linked list) */ \ - struct M_C(name, _s) { \ - struct M_C(name, _s) *next; \ + struct M_F(name, _s) { \ + struct M_F(name, _s) *next; \ type data; \ }; \ \ @@ -945,23 +945,23 @@ Doesn't support Pop front. \ This is done by keeping a pointer to both back & front \ */ \ - typedef struct M_C(name, _head_s) { \ - struct M_C(name,_s) *front; /* Pointer to the front node or NULL */ \ - struct M_C(name,_s) *back; /* Pointer to the back node or NULL */ \ + typedef struct M_F(name, _head_s) { \ + struct M_F(name,_s) *front; /* Pointer to the front node or NULL */ \ + struct M_F(name,_s) *back; /* Pointer to the back node or NULL */ \ } list_t[1]; \ \ /* Define the iterator over a dual push singly linked list */ \ - typedef struct M_C(name, _it_s) { \ - struct M_C(name, _s) *previous; \ - struct M_C(name, _s) *current; \ + typedef struct M_F(name, _it_s) { \ + struct M_F(name, _s) *previous; \ + struct M_F(name, _s) *current; \ } it_t[1]; \ \ /* Definition of the synonyms of the type */ \ - typedef struct M_C(name, _head_s) *M_C(name, _ptr); \ - typedef const struct M_C(name, _head_s) *M_C(name, _srcptr); \ - typedef list_t M_C(name, _ct); \ - typedef it_t M_C(name, _it_ct); \ - typedef type M_C(name, _subtype_ct); \ + typedef struct M_F(name, _head_s) *M_F(name, _ptr); \ + typedef const struct M_F(name, _head_s) *M_F(name, _srcptr); \ + typedef list_t M_F(name, _ct); \ + typedef it_t M_F(name, _it_ct); \ + typedef type M_F(name, _subtype_ct); \ \ M_CHECK_COMPATIBLE_OPLIST(name, 1, type, oplist) \ \ @@ -987,7 +987,7 @@ #define M_L1ST_DUAL_PUSH_DEF_P4(name, type, oplist, list_t, it_t) \ \ static inline void \ - M_C(name, _init)(list_t v) \ + M_F(name, _init)(list_t v) \ { \ M_ASSERT( v != NULL); \ v->front = NULL; \ @@ -996,12 +996,12 @@ } \ \ static inline void \ - M_C(name, _reset)(list_t v) \ + M_F(name, _reset)(list_t v) \ { \ M_L1ST_DUAL_PUSH_CONTRACT(v); \ - struct M_C(name, _s) *it = v->back; \ + struct M_F(name, _s) *it = v->back; \ while (it != NULL) { \ - struct M_C(name, _s) *next = it->next; \ + struct M_F(name, _s) *next = it->next; \ M_CALL_CLEAR(oplist, it->data); \ M_C3(m_l1st_,name,_del)(it); \ it = next; \ @@ -1012,13 +1012,13 @@ } \ \ static inline void \ - M_C(name, _clear)(list_t v) \ + M_F(name, _clear)(list_t v) \ { \ - M_C(name, _reset)(v); \ + M_F(name, _reset)(v); \ } \ \ static inline type * \ - M_C(name, _back)(const list_t v) \ + M_F(name, _back)(const list_t v) \ { \ M_L1ST_DUAL_PUSH_CONTRACT(v); \ M_ASSERT (v->back != NULL); \ @@ -1026,12 +1026,12 @@ } \ \ static inline type * \ - M_C(name, _push_back_raw)(list_t v) \ + M_F(name, _push_back_raw)(list_t v) \ { \ M_L1ST_DUAL_PUSH_CONTRACT(v); \ - struct M_C(name, _s) *next = M_C3(m_l1st_,name,_new)(); \ + struct M_F(name, _s) *next = M_C3(m_l1st_,name,_new)(); \ if (M_UNLIKELY_NOMEM (next == NULL)) { \ - M_MEMORY_FULL(sizeof (struct M_C(name, _s))); \ + M_MEMORY_FULL(sizeof (struct M_F(name, _s))); \ return NULL; \ } \ type *ret = &next->data; \ @@ -1039,7 +1039,7 @@ v->back = next; \ /* Update front too if the list was empty */ \ /* This C code shall generate branchless code */ \ - struct M_C(name, _s) *front = v->front; \ + struct M_F(name, _s) *front = v->front; \ front = (front == NULL) ? next : front; \ v->front = front; \ M_L1ST_DUAL_PUSH_CONTRACT(v); \ @@ -1048,15 +1048,15 @@ \ /* Internal, for INIT_WITH */ \ static inline type * \ - M_C(name, _push_raw)(list_t d) \ + M_F(name, _push_raw)(list_t d) \ { \ - return M_C(name, _push_back_raw)(d); \ + return M_F(name, _push_back_raw)(d); \ } \ \ static inline void \ - M_C(name, _push_back)(list_t v, type const x) \ + M_F(name, _push_back)(list_t v, type const x) \ { \ - type *data = M_C(name, _push_back_raw)(v); \ + type *data = M_F(name, _push_back_raw)(v); \ if (M_UNLIKELY (data == NULL)) \ return; \ M_CALL_INIT_SET(oplist, *data, x); \ @@ -1064,9 +1064,9 @@ \ M_IF_METHOD(INIT, oplist)( \ static inline type * \ - M_C(name, _push_back_new)(list_t v) \ + M_F(name, _push_back_new)(list_t v) \ { \ - type *data = M_C(name, _push_back_raw)(v); \ + type *data = M_F(name, _push_back_raw)(v); \ if (M_UNLIKELY (data == NULL)) \ return NULL; \ M_CALL_INIT(oplist, *data); \ @@ -1075,27 +1075,27 @@ , /* No INIT */ ) \ \ static inline void \ - M_C(name, _push_back_move)(list_t v, type *x) \ + M_F(name, _push_back_move)(list_t v, type *x) \ { \ M_ASSERT (x != NULL); \ - type *data = M_C(name, _push_back_raw)(v); \ + type *data = M_F(name, _push_back_raw)(v); \ if (M_UNLIKELY (data == NULL)) \ return; \ M_DO_INIT_MOVE (oplist, *data, *x); \ } \ \ static inline void \ - M_C(name, _push_move)(list_t v, type *x) \ + M_F(name, _push_move)(list_t v, type *x) \ { \ - M_C(name, _push_back_move)(v, x); \ + M_F(name, _push_back_move)(v, x); \ } \ \ static inline void \ - M_C(name, _pop_back)(type *data, list_t v) \ + M_F(name, _pop_back)(type *data, list_t v) \ { \ M_L1ST_DUAL_PUSH_CONTRACT(v); \ M_ASSERT (v->back != NULL); \ - struct M_C(name, _s) *tofree = v->back; \ + struct M_F(name, _s) *tofree = v->back; \ if (data != NULL) { \ M_DO_MOVE(oplist, *data, tofree->data); \ } else { \ @@ -1105,32 +1105,32 @@ M_C3(m_l1st_,name,_del)(tofree); \ /* Update front too if the list became empty */ \ /* This C code shall generate branchless code */ \ - struct M_C(name, _s) *front = v->front; \ + struct M_F(name, _s) *front = v->front; \ front = (front == tofree) ? NULL : front; \ v->front = front; \ M_L1ST_DUAL_PUSH_CONTRACT(v); \ } \ \ static inline void \ - M_C(name, _pop_move)(type *data, list_t v) \ + M_F(name, _pop_move)(type *data, list_t v) \ { \ M_L1ST_DUAL_PUSH_CONTRACT(v); \ M_ASSERT (v->back != NULL); \ M_ASSERT (data != NULL); \ - struct M_C(name, _s) *tofree = v->back; \ + struct M_F(name, _s) *tofree = v->back; \ M_DO_INIT_MOVE (oplist, *data, tofree->data); \ v->back = tofree->next; \ M_C3(m_l1st_,name,_del)(tofree); \ /* Update front too if the list became empty */ \ /* This C code shall generate branchless code */ \ - struct M_C(name, _s) *front = v->front; \ + struct M_F(name, _s) *front = v->front; \ front = (front == tofree) ? NULL : front; \ v->front = front; \ M_L1ST_DUAL_PUSH_CONTRACT(v); \ } \ \ static inline type * \ - M_C(name, _front)(list_t v) \ + M_F(name, _front)(list_t v) \ { \ M_L1ST_DUAL_PUSH_CONTRACT(v); \ M_ASSERT (v->front != NULL); \ @@ -1138,12 +1138,12 @@ } \ \ static inline type * \ - M_C(name, _push_front_raw)(list_t v) \ + M_F(name, _push_front_raw)(list_t v) \ { \ M_L1ST_DUAL_PUSH_CONTRACT(v); \ - struct M_C(name, _s) *next = M_C3(m_l1st_,name,_new)(); \ + struct M_F(name, _s) *next = M_C3(m_l1st_,name,_new)(); \ if (M_UNLIKELY_NOMEM (next == NULL)) { \ - M_MEMORY_FULL(sizeof (struct M_C(name, _s))); \ + M_MEMORY_FULL(sizeof (struct M_F(name, _s))); \ return NULL; \ } \ type *ret = &next->data; \ @@ -1160,19 +1160,19 @@ } \ \ static inline void \ - M_C(name, _push_front)(list_t v, type const x) \ + M_F(name, _push_front)(list_t v, type const x) \ { \ - type *data = M_C(name, _push_front_raw)(v); \ + type *data = M_F(name, _push_front_raw)(v); \ if (M_UNLIKELY (data == NULL)) \ return; \ M_CALL_INIT_SET(oplist, *data, x); \ } \ \ static inline void \ - M_C(name, _push_front_move)(list_t v, type *x) \ + M_F(name, _push_front_move)(list_t v, type *x) \ { \ M_ASSERT (x != NULL); \ - type *data = M_C(name, _push_front_raw)(v); \ + type *data = M_F(name, _push_front_raw)(v); \ if (M_UNLIKELY (data == NULL)) \ return; \ M_DO_INIT_MOVE (oplist, *data, *x); \ @@ -1180,9 +1180,9 @@ \ M_IF_METHOD(INIT, oplist)( \ static inline type * \ - M_C(name, _push_front_new)(list_t v) \ + M_F(name, _push_front_new)(list_t v) \ { \ - type *data = M_C(name, _push_back_raw)(v); \ + type *data = M_F(name, _push_back_raw)(v); \ if (M_UNLIKELY (data == NULL)) \ return NULL; \ M_CALL_INIT(oplist, *data); \ @@ -1191,23 +1191,23 @@ , /* No INIT */) \ \ static inline bool \ - M_C(name, _empty_p)(const list_t v) \ + M_F(name, _empty_p)(const list_t v) \ { \ M_L1ST_DUAL_PUSH_CONTRACT(v); \ return v->back == NULL; \ } \ \ static inline void \ - M_C(name, _swap)(list_t l, list_t v) \ + M_F(name, _swap)(list_t l, list_t v) \ { \ M_L1ST_DUAL_PUSH_CONTRACT(l); \ M_L1ST_DUAL_PUSH_CONTRACT(v); \ - M_SWAP(struct M_C(name, _s) *, l->front, v->front); \ - M_SWAP(struct M_C(name, _s) *, l->back, v->back); \ + M_SWAP(struct M_F(name, _s) *, l->front, v->front); \ + M_SWAP(struct M_F(name, _s) *, l->back, v->back); \ } \ \ static inline void \ - M_C(name, _it)(it_t it, const list_t v) \ + M_F(name, _it)(it_t it, const list_t v) \ { \ M_L1ST_DUAL_PUSH_CONTRACT(v); \ M_ASSERT (it != NULL); \ @@ -1216,7 +1216,7 @@ } \ \ static inline void \ - M_C(name, _it_set)(it_t it1, const it_t it2) \ + M_F(name, _it_set)(it_t it1, const it_t it2) \ { \ M_ASSERT (it1 != NULL && it2 != NULL); \ it1->current = it2->current; \ @@ -1224,7 +1224,7 @@ } \ \ static inline void \ - M_C(name, _it_end)(it_t it1, const list_t v) \ + M_F(name, _it_end)(it_t it1, const list_t v) \ { \ M_ASSERT (it1 != NULL); \ M_L1ST_DUAL_PUSH_CONTRACT(v); \ @@ -1234,21 +1234,21 @@ } \ \ static inline bool \ - M_C(name, _end_p)(const it_t it) \ + M_F(name, _end_p)(const it_t it) \ { \ M_ASSERT (it != NULL); \ return it->current == NULL; \ } \ \ static inline bool \ - M_C(name, _last_p)(const it_t it) \ + M_F(name, _last_p)(const it_t it) \ { \ M_ASSERT (it != NULL); \ return it->current == NULL || it->current->next == NULL; \ } \ \ static inline void \ - M_C(name, _next)(it_t it) \ + M_F(name, _next)(it_t it) \ { \ M_ASSERT(it != NULL && it->current != NULL); \ it->previous = it->current; \ @@ -1256,32 +1256,32 @@ } \ \ static inline bool \ - M_C(name, _it_equal_p)(const it_t it1, const it_t it2) \ + M_F(name, _it_equal_p)(const it_t it1, const it_t it2) \ { \ M_ASSERT(it1 != NULL && it2 != NULL); \ return it1->current == it2->current; \ } \ \ static inline type * \ - M_C(name, _ref)(const it_t it) \ + M_F(name, _ref)(const it_t it) \ { \ M_ASSERT(it != NULL && it->current != NULL); \ return &(it->current->data); \ } \ \ static inline type const * \ - M_C(name, _cref)(const it_t it) \ + M_F(name, _cref)(const it_t it) \ { \ M_ASSERT(it != NULL && it->current != NULL); \ return M_CONST_CAST(type, &(it->current->data)); \ } \ \ static inline size_t \ - M_C(name, _size)(const list_t v) \ + M_F(name, _size)(const list_t v) \ { \ M_L1ST_DUAL_PUSH_CONTRACT(v); \ size_t size = 0; \ - struct M_C(name, _s) *it = v->back; \ + struct M_F(name, _s) *it = v->back; \ while (it != NULL) { \ size ++; \ it = it->next; \ @@ -1290,14 +1290,14 @@ } \ \ static inline void \ - M_C(name, _insert)(list_t list, it_t insertion_point, \ + M_F(name, _insert)(list_t list, it_t insertion_point, \ type const x) \ { \ M_L1ST_DUAL_PUSH_CONTRACT(list); \ M_ASSERT (insertion_point != NULL); \ - struct M_C(name, _s) *next = M_C3(m_l1st_,name,_new)(); \ + struct M_F(name, _s) *next = M_C3(m_l1st_,name,_new)(); \ if (M_UNLIKELY_NOMEM (next == NULL)) { \ - M_MEMORY_FULL(sizeof (struct M_C(name, _s))); \ + M_MEMORY_FULL(sizeof (struct M_F(name, _s))); \ return; \ } \ M_CALL_INIT_SET(oplist, next->data, x); \ @@ -1305,34 +1305,34 @@ next->next = list->back; \ list->back = next; \ /* update front if list is empty */ \ - struct M_C(name, _s) *front = list->front; \ + struct M_F(name, _s) *front = list->front; \ front = (front == NULL) ? next : front; \ list->front = front; \ } else { \ next->next = insertion_point->current->next; \ insertion_point->current->next = next; \ /* update front if current == front */ \ - struct M_C(name, _s) *front = list->front; \ + struct M_F(name, _s) *front = list->front; \ front = (front == insertion_point->current) ? next : front; \ list->front = front; \ } \ } \ \ static inline void \ - M_C(name, _remove)(list_t list, it_t removing_point) \ + M_F(name, _remove)(list_t list, it_t removing_point) \ { \ M_L1ST_DUAL_PUSH_CONTRACT(list); \ M_ASSERT (removing_point != NULL); \ M_ASSERT(removing_point->current != NULL); \ - struct M_C(name, _s) *next = removing_point->current->next; \ - struct M_C(name, _s) *previous = removing_point->previous; \ + struct M_F(name, _s) *next = removing_point->current->next; \ + struct M_F(name, _s) *previous = removing_point->previous; \ if (M_UNLIKELY (previous == NULL)) { \ list->back = next; \ } else { \ previous->next = next; \ } \ /* Update front */ \ - struct M_C(name, _s) *front = list->front; \ + struct M_F(name, _s) *front = list->front; \ front = (next == NULL) ? previous : front; \ list->front = front; \ /* Remove node */ \ @@ -1342,22 +1342,22 @@ } \ \ static inline void \ - M_C(name, _set)(list_t list, const list_t org) \ + M_F(name, _set)(list_t list, const list_t org) \ { \ M_L1ST_DUAL_PUSH_CONTRACT(list); \ M_L1ST_DUAL_PUSH_CONTRACT(org); \ - struct M_C(name, _s) *next = NULL; \ - struct M_C(name, _s) *it_org; \ - struct M_C(name, _s) **update_list; \ + struct M_F(name, _s) *next = NULL; \ + struct M_F(name, _s) *it_org; \ + struct M_F(name, _s) **update_list; \ if (M_UNLIKELY (list == org)) return; \ - M_C(name, _reset)(list); \ + M_F(name, _reset)(list); \ update_list = &list->back; \ it_org = org->back; \ while (it_org != NULL) { \ next = M_C3(m_l1st_,name,_new)(); \ *update_list = next; \ if (M_UNLIKELY_NOMEM (next == NULL)) { \ - M_MEMORY_FULL(sizeof (struct M_C(name, _s))); \ + M_MEMORY_FULL(sizeof (struct M_F(name, _s))); \ return; \ } \ update_list = &next->next; \ @@ -1369,15 +1369,15 @@ } \ \ static inline void \ - M_C(name, _init_set)(list_t list, const list_t org) \ + M_F(name, _init_set)(list_t list, const list_t org) \ { \ M_ASSERT (list != org); \ - M_C(name, _init)(list); \ - M_C(name, _set)(list, org); \ + M_F(name, _init)(list); \ + M_F(name, _set)(list, org); \ } \ \ static inline void \ - M_C(name, _init_move)(list_t list, list_t org) \ + M_F(name, _init_move)(list_t list, list_t org) \ { \ M_ASSERT (list != org); \ list->back = org->back; \ @@ -1387,28 +1387,28 @@ } \ \ static inline void \ - M_C(name, _move)(list_t list, list_t org) \ + M_F(name, _move)(list_t list, list_t org) \ { \ - M_C(name, _clear)(list); \ - M_C(name, _init_move)(list, org); \ + M_F(name, _clear)(list); \ + M_F(name, _init_move)(list, org); \ } \ \ static inline void \ - M_C(name, _splice_back)(list_t list1, list_t list2, it_t it) \ + M_F(name, _splice_back)(list_t list1, list_t list2, it_t it) \ { \ M_L1ST_DUAL_PUSH_CONTRACT(list1); \ M_L1ST_DUAL_PUSH_CONTRACT(list2); \ M_ASSERT (it->current != NULL); \ /* First remove the item 'it' from the list 'list2' */ \ - struct M_C(name, _s) *current = it->current; \ - struct M_C(name, _s) *next = current->next; \ + struct M_F(name, _s) *current = it->current; \ + struct M_F(name, _s) *next = current->next; \ if (it->previous == NULL) { \ list2->back = next; \ } else { \ it->previous->next = next; \ } \ /* Update the front of 'list2' if it was the last element */ \ - struct M_C(name, _s) *front = list2->front; \ + struct M_F(name, _s) *front = list2->front; \ front = (next == NULL) ? it->previous : front; \ list2->front = front; \ /* Update 'it' to point to the next element */ \ @@ -1426,31 +1426,31 @@ } \ \ static inline void \ - M_C(name, _splice_at)(list_t nlist, it_t npos, \ + M_F(name, _splice_at)(list_t nlist, it_t npos, \ list_t olist, it_t opos) \ { \ M_L1ST_DUAL_PUSH_CONTRACT(nlist); \ M_L1ST_DUAL_PUSH_CONTRACT(olist); \ M_ASSERT (npos != NULL && opos != NULL); \ /* First remove the item 'opos' from the list 'olist' */ \ - struct M_C(name, _s) *current = opos->current; \ + struct M_F(name, _s) *current = opos->current; \ /* It shall refer a valid argument in the list */ \ M_ASSERT(current != NULL); \ - struct M_C(name, _s) *next = current->next; \ + struct M_F(name, _s) *next = current->next; \ if (opos->previous == NULL) { \ olist->back = next; \ } else { \ opos->previous->next = next; \ } \ /* Update the front of 'olist' if it was the last element */ \ - struct M_C(name, _s) *front = olist->front; \ + struct M_F(name, _s) *front = olist->front; \ front = (next == NULL) ? opos->previous : front; \ olist->front = front; \ /* Update 'opos' to point to the next element */ \ opos->current = next; \ /* opos->previous is still valid & doesn't need to be updated */ \ /* Insert into 'nlist' */ \ - struct M_C(name, _s) *npos_current = npos->current; \ + struct M_F(name, _s) *npos_current = npos->current; \ if (M_UNLIKELY (npos_current == NULL)) { \ current->next = nlist->back; \ nlist->back = current; \ @@ -1474,7 +1474,7 @@ } \ \ static inline void \ - M_C(name, _splice)(list_t list1, list_t list2) \ + M_F(name, _splice)(list_t list1, list_t list2) \ { \ M_L1ST_DUAL_PUSH_CONTRACT(list1); \ M_L1ST_DUAL_PUSH_CONTRACT(list2); \ @@ -1494,11 +1494,11 @@ } \ \ static inline void \ - M_C(name, _reverse)(list_t list) \ + M_F(name, _reverse)(list_t list) \ { \ M_L1ST_DUAL_PUSH_CONTRACT(list); \ list->front = list->back; \ - struct M_C(name, _s) *previous = NULL, *it = list->back, *next; \ + struct M_F(name, _s) *previous = NULL, *it = list->back, *next; \ while (it != NULL) { \ next = it->next; \ it->next = previous; \ @@ -1509,8 +1509,8 @@ M_L1ST_DUAL_PUSH_CONTRACT(list); \ } \ \ - M_EMPLACE_QUEUE_DEF(name, list_t, M_C(name, _emplace_back), oplist, M_L1ST_EMPLACE_BACK_DEF) \ - M_EMPLACE_QUEUE_DEF(name, list_t, M_C(name, _emplace_front), oplist, M_L1ST_EMPLACE_FRONT_DEF) + M_EMPLACE_QUEUE_DEF(name, list_t, M_F(name, _emplace_back), oplist, M_L1ST_EMPLACE_BACK_DEF) \ + M_EMPLACE_QUEUE_DEF(name, list_t, M_F(name, _emplace_front), oplist, M_L1ST_EMPLACE_FRONT_DEF) #if M_USE_SMALL_NAME #define LIST_DEF M_LIST_DEF diff --git a/m-mempool.h b/m-mempool.h index 36b89c6a..4be19ab0 100644 --- a/m-mempool.h +++ b/m-mempool.h @@ -42,7 +42,7 @@ mempool_uint_clear(m); // Give back memory to system */ #define M_MEMPOOL_DEF(name, type) \ - M_MEMPOOL_DEF_AS(name, M_C(name,_t), type) + M_MEMPOOL_DEF_AS(name, M_F(name,_t), type) /* Fast, fixed Size, thread unsafe allocator based on memory region. @@ -84,25 +84,25 @@ \ /* Define the type of element in a segment of the mempool. \ Either it is the basic type or a pointer to another one. */ \ - typedef union M_C(name,_union_s) { \ + typedef union M_F(name,_union_s) { \ type t; \ - union M_C(name,_union_s) *next; \ - } M_C(name,_union_ct); \ + union M_F(name,_union_s) *next; \ + } M_F(name,_union_ct); \ \ /* Define a segment of a mempool. \ It is an array of basic type, each segment is in a linked list */ \ - typedef struct M_C(name,_segment_s) { \ + typedef struct M_F(name,_segment_s) { \ unsigned int count; \ - struct M_C(name,_segment_s) *next; \ - M_C(name,_union_ct) tab[M_USE_MEMPOOL_MAX_PER_SEGMENT(type)]; \ - } M_C(name,_segment_ct); \ + struct M_F(name,_segment_s) *next; \ + M_F(name,_union_ct) tab[M_USE_MEMPOOL_MAX_PER_SEGMENT(type)]; \ + } M_F(name,_segment_ct); \ \ /* Define a mempool. \ It is a pointer to the first free object within the segments \ and the segments themselves */ \ - typedef struct M_C(name, _s) { \ - M_C(name,_union_ct) *free_list; \ - M_C(name,_segment_ct) *current_segment; \ + typedef struct M_F(name, _s) { \ + M_F(name,_union_ct) *free_list; \ + M_F(name,_segment_ct) *current_segment; \ } name_t[1]; \ @@ -110,12 +110,12 @@ #define M_M3MPOOL_DEF_CORE(name, type, name_t) \ \ static inline void \ - M_C(name,_init)(name_t mem) \ + M_F(name,_init)(name_t mem) \ { \ mem->free_list = NULL; \ - mem->current_segment = M_MEMORY_ALLOC(M_C(name,_segment_ct)); \ + mem->current_segment = M_MEMORY_ALLOC(M_F(name,_segment_ct)); \ if (M_UNLIKELY_NOMEM(mem->current_segment == NULL)) { \ - M_MEMORY_FULL(sizeof (M_C(name,_segment_ct))); \ + M_MEMORY_FULL(sizeof (M_F(name,_segment_ct))); \ return; \ } \ mem->current_segment->next = NULL; \ @@ -124,12 +124,12 @@ } \ \ static inline void \ - M_C(name,_clear)(name_t mem) \ + M_F(name,_clear)(name_t mem) \ { \ M_M3MPOOL_CONTRACT(mem, type); \ - M_C(name,_segment_ct) *segment = mem->current_segment; \ + M_F(name,_segment_ct) *segment = mem->current_segment; \ while (segment != NULL) { \ - M_C(name,_segment_ct) *next = segment->next; \ + M_F(name,_segment_ct) *next = segment->next; \ M_MEMORY_DEL (segment); \ segment = next; \ } \ @@ -139,25 +139,25 @@ } \ \ static inline type * \ - M_C(name,_alloc)(name_t mem) \ + M_F(name,_alloc)(name_t mem) \ { \ M_M3MPOOL_CONTRACT(mem, type); \ /* Test if one object is in the free list */ \ - M_C(name,_union_ct) *ret = mem->free_list; \ + M_F(name,_union_ct) *ret = mem->free_list; \ if (ret != NULL) { \ /* Yes, so return it, and pop it from the free list */ \ mem->free_list = ret->next; \ return &ret->t; \ } \ /* No cheap free object exist. Test within a segment */ \ - M_C(name,_segment_ct) *segment = mem->current_segment; \ + M_F(name,_segment_ct) *segment = mem->current_segment; \ M_ASSERT(segment != NULL); \ unsigned int count = segment->count; \ /* If segment is full, allocate a new one from the system */ \ if (M_UNLIKELY (count >= M_USE_MEMPOOL_MAX_PER_SEGMENT(type))) { \ - M_C(name,_segment_ct) *new_segment = M_MEMORY_ALLOC (M_C(name,_segment_ct)); \ + M_F(name,_segment_ct) *new_segment = M_MEMORY_ALLOC (M_F(name,_segment_ct)); \ if (M_UNLIKELY_NOMEM (new_segment == NULL)) { \ - M_MEMORY_FULL(sizeof (M_C(name,_segment_ct))); \ + M_MEMORY_FULL(sizeof (M_F(name,_segment_ct))); \ return NULL; \ } \ new_segment->next = segment; \ @@ -174,12 +174,12 @@ } \ \ static inline void \ - M_C(name,_free)(name_t mem, type *ptr) \ + M_F(name,_free)(name_t mem, type *ptr) \ { \ M_M3MPOOL_CONTRACT(mem, type); \ /* NOTE: Unsafe cast: suppose that the given pointer \ was allocated by the previous alloc function. */ \ - M_C(name,_union_ct) *ret = (M_C(name,_union_ct) *)(uintptr_t)ptr; \ + M_F(name,_union_ct) *ret = (M_F(name,_union_ct) *)(uintptr_t)ptr; \ /* Add the object back in the free list */ \ ret->next = mem->free_list; \ mem->free_list = ret; \ diff --git a/m-prioqueue.h b/m-prioqueue.h index 888593d6..61877e51 100644 --- a/m-prioqueue.h +++ b/m-prioqueue.h @@ -33,7 +33,7 @@ /* Define a prioqueue of a given type and its associated functions. USAGE: PRIOQUEUE_DEF(name, type [, oplist_of_the_type]) */ #define M_PRIOQUEUE_DEF(name, ...) \ - M_PRIOQUEUE_DEF_AS(name, M_C(name,_t), M_C(name,_it_t), __VA_ARGS__) + M_PRIOQUEUE_DEF_AS(name, M_F(name,_t), M_F(name,_it_t), __VA_ARGS__) /* Define a prioqueue of a given type and its associated functions. @@ -73,38 +73,38 @@ /* Define oplist of a priority queue */ #define M_PR1OQUEUE_OPLIST_P3(name, oplist) \ - (INIT(M_C(name, _init)) \ - ,INIT_SET(M_C(name, _init_set)) \ + (INIT(M_F(name, _init)) \ + ,INIT_SET(M_F(name, _init_set)) \ ,INIT_WITH(API_1(M_INIT_VAI)) \ - ,SET(M_C(name, _set)) \ - ,CLEAR(M_C(name, _clear)) \ - ,INIT_MOVE(M_C(name, _init_move)) \ - ,MOVE(M_C(name, _move)) \ - ,SWAP(M_C(name, _swap)) \ + ,SET(M_F(name, _set)) \ + ,CLEAR(M_F(name, _clear)) \ + ,INIT_MOVE(M_F(name, _init_move)) \ + ,MOVE(M_F(name, _move)) \ + ,SWAP(M_F(name, _swap)) \ ,NAME(name) \ - ,TYPE(M_C(name,_ct)) \ - ,SUBTYPE(M_C(name, _subtype_ct)) \ - ,RESET(M_C(name,_reset)) \ - ,PUSH(M_C(name,_push)) \ - ,POP(M_C(name,_pop)) \ + ,TYPE(M_F(name,_ct)) \ + ,SUBTYPE(M_F(name, _subtype_ct)) \ + ,RESET(M_F(name,_reset)) \ + ,PUSH(M_F(name,_push)) \ + ,POP(M_F(name,_pop)) \ ,OPLIST(oplist) \ - ,EMPTY_P(M_C(name, _empty_p)) \ - ,GET_SIZE(M_C(name, _size)) \ - ,IT_TYPE(M_C(name, _it_ct)) \ - ,IT_FIRST(M_C(name,_it)) \ - ,IT_END(M_C(name,_it_end)) \ - ,IT_SET(M_C(name,_it_set)) \ - ,IT_END_P(M_C(name,_end_p)) \ - ,IT_EQUAL_P(M_C(name,_it_equal_p)) \ - ,IT_LAST_P(M_C(name,_last_p)) \ - ,IT_NEXT(M_C(name,_next)) \ - ,IT_CREF(M_C(name,_cref)) \ - ,M_IF_METHOD(GET_STR, oplist)(GET_STR(M_C(name, _get_str)),) \ - ,M_IF_METHOD(PARSE_STR, oplist)(PARSE_STR(M_C(name, _parse_str)),) \ - ,M_IF_METHOD(OUT_STR, oplist)(OUT_STR(M_C(name, _out_str)),) \ - ,M_IF_METHOD(IN_STR, oplist)(IN_STR(M_C(name, _in_str)),) \ - ,M_IF_METHOD(OUT_SERIAL, oplist)(OUT_SERIAL(M_C(name, _out_serial)),) \ - ,M_IF_METHOD(IN_SERIAL, oplist)(IN_SERIAL(M_C(name, _in_serial)),) \ + ,EMPTY_P(M_F(name, _empty_p)) \ + ,GET_SIZE(M_F(name, _size)) \ + ,IT_TYPE(M_F(name, _it_ct)) \ + ,IT_FIRST(M_F(name,_it)) \ + ,IT_END(M_F(name,_it_end)) \ + ,IT_SET(M_F(name,_it_set)) \ + ,IT_END_P(M_F(name,_end_p)) \ + ,IT_EQUAL_P(M_F(name,_it_equal_p)) \ + ,IT_LAST_P(M_F(name,_last_p)) \ + ,IT_NEXT(M_F(name,_next)) \ + ,IT_CREF(M_F(name,_cref)) \ + ,M_IF_METHOD(GET_STR, oplist)(GET_STR(M_F(name, _get_str)),) \ + ,M_IF_METHOD(PARSE_STR, oplist)(PARSE_STR(M_F(name, _parse_str)),) \ + ,M_IF_METHOD(OUT_STR, oplist)(OUT_STR(M_F(name, _out_str)),) \ + ,M_IF_METHOD(IN_STR, oplist)(IN_STR(M_F(name, _in_str)),) \ + ,M_IF_METHOD(OUT_SERIAL, oplist)(OUT_SERIAL(M_F(name, _out_serial)),) \ + ,M_IF_METHOD(IN_SERIAL, oplist)(IN_SERIAL(M_F(name, _in_serial)),) \ ) @@ -131,171 +131,171 @@ */ #define M_PR1OQUEUE_DEF_P3(name, type, oplist, prioqueue_t, it_t) \ /* Definition of the internal array used to construct the priority queue */ \ - ARRAY_DEF(M_C(name, _array), type, oplist) \ + ARRAY_DEF(M_F(name, _array), type, oplist) \ M_PR1OQUEUE_DEF_TYPE(name, type, oplist, prioqueue_t, it_t) \ M_CHECK_COMPATIBLE_OPLIST(name, 1, type, oplist) \ M_PR1OQUEUE_DEF_CORE(name, type, oplist, prioqueue_t, it_t) \ M_PR1OQUEUE_DEF_IT(name, type, oplist, prioqueue_t, it_t) \ M_PR1OQUEUE_DEF_IO(name, type, oplist, prioqueue_t, it_t) \ - M_EMPLACE_QUEUE_DEF(name, prioqueue_t, M_C(name, _emplace), oplist, M_EMPLACE_QUEUE_GENE) + M_EMPLACE_QUEUE_DEF(name, prioqueue_t, M_F(name, _emplace), oplist, M_EMPLACE_QUEUE_GENE) /* Define the types */ #define M_PR1OQUEUE_DEF_TYPE(name, type, oplist, prioqueue_t, it_t) \ \ /* Define the priority queue over the defined array */ \ - typedef struct M_C(name, _s) { \ - M_C(name, _array_t) array; \ + typedef struct M_F(name, _s) { \ + M_F(name, _array_t) array; \ } prioqueue_t[1]; \ /* Define the pointer references to the priority queue */ \ - typedef struct M_C(name, _s) *M_C(name, _ptr); \ - typedef const struct M_C(name, _s) *M_C(name, _srcptr); \ + typedef struct M_F(name, _s) *M_F(name, _ptr); \ + typedef const struct M_F(name, _s) *M_F(name, _srcptr); \ \ /* The iterator is the same one as the one of the internal array */ \ - typedef M_C(name, _array_it_t) it_t; \ + typedef M_F(name, _array_it_t) it_t; \ \ /* Definition of the internal types used by the oplist */ \ - typedef prioqueue_t M_C(name, _ct); \ - typedef type M_C(name, _subtype_ct); \ - typedef it_t M_C(name, _it_ct); \ + typedef prioqueue_t M_F(name, _ct); \ + typedef type M_F(name, _subtype_ct); \ + typedef it_t M_F(name, _it_ct); \ /* Define the core functions */ #define M_PR1OQUEUE_DEF_CORE(name, type, oplist, prioqueue_t, it_t) \ \ static inline void \ - M_C(name, _init)(prioqueue_t p) \ + M_F(name, _init)(prioqueue_t p) \ { \ - M_C(name, _array_init)(p->array); \ + M_F(name, _array_init)(p->array); \ } \ \ static inline void \ - M_C(name, _init_set)(prioqueue_t p, prioqueue_t const o) \ + M_F(name, _init_set)(prioqueue_t p, prioqueue_t const o) \ { \ - M_C(name, _array_init_set)(p->array, o->array); \ + M_F(name, _array_init_set)(p->array, o->array); \ } \ \ static inline void \ - M_C(name, _set)(prioqueue_t p, prioqueue_t const o) \ + M_F(name, _set)(prioqueue_t p, prioqueue_t const o) \ { \ - M_C(name, _array_set)(p->array, o->array); \ + M_F(name, _array_set)(p->array, o->array); \ } \ \ static inline void \ - M_C(name, _clear)(prioqueue_t p) \ + M_F(name, _clear)(prioqueue_t p) \ { \ - M_C(name, _array_clear)(p->array); \ + M_F(name, _array_clear)(p->array); \ } \ \ static inline void \ - M_C(name, _init_move)(prioqueue_t p, prioqueue_t o) \ + M_F(name, _init_move)(prioqueue_t p, prioqueue_t o) \ { \ - M_C(name, _array_init_move)(p->array, o->array); \ + M_F(name, _array_init_move)(p->array, o->array); \ } \ \ static inline void \ - M_C(name, _move)(prioqueue_t p, prioqueue_t o) \ + M_F(name, _move)(prioqueue_t p, prioqueue_t o) \ { \ - M_C(name, _array_move)(p->array, o->array); \ + M_F(name, _array_move)(p->array, o->array); \ } \ \ static inline void \ - M_C(name, _swap)(prioqueue_t p, prioqueue_t o) \ + M_F(name, _swap)(prioqueue_t p, prioqueue_t o) \ { \ - M_C(name, _array_swap)(p->array, o->array); \ + M_F(name, _array_swap)(p->array, o->array); \ } \ \ static inline void \ - M_C(name, _reset)(prioqueue_t p) \ + M_F(name, _reset)(prioqueue_t p) \ { \ - M_C(name, _array_reset)(p->array); \ + M_F(name, _array_reset)(p->array); \ } \ \ static inline size_t \ - M_C(name, _i_parent)(size_t i) \ + M_F(name, _i_parent)(size_t i) \ { \ M_ASSERT (i > 0); \ return (i - 1) / 2; \ } \ \ static inline size_t \ - M_C(name, _i_lchild)(size_t i) \ + M_F(name, _i_lchild)(size_t i) \ { \ M_ASSERT(i <= ((SIZE_MAX)-2)/2); \ return 2*i + 1; \ } \ \ static inline size_t \ - M_C(name, _i_rchild)(size_t i) \ + M_F(name, _i_rchild)(size_t i) \ { \ M_ASSERT(i <= ((SIZE_MAX)-2)/2); \ return 2*i + 2; \ } \ \ static inline int \ - M_C(name, _i_cmp)(const prioqueue_t p, size_t i, size_t j) \ + M_F(name, _i_cmp)(const prioqueue_t p, size_t i, size_t j) \ { \ - return M_CALL_CMP(oplist, *M_C(name, _array_cget)(p->array, i), \ - *M_C(name, _array_cget)(p->array, j)); \ + return M_CALL_CMP(oplist, *M_F(name, _array_cget)(p->array, i), \ + *M_F(name, _array_cget)(p->array, j)); \ } \ \ static inline bool \ - M_C(name, _empty_p)(prioqueue_t const p) \ + M_F(name, _empty_p)(prioqueue_t const p) \ { \ - return M_C(name, _array_empty_p)(p->array); \ + return M_F(name, _array_empty_p)(p->array); \ } \ \ static inline size_t \ - M_C(name, _size)(prioqueue_t const p) \ + M_F(name, _size)(prioqueue_t const p) \ { \ - return M_C(name, _array_size)(p->array); \ + return M_F(name, _array_size)(p->array); \ } \ \ static inline void \ - M_C(name, _push)(prioqueue_t p, type const x) \ + M_F(name, _push)(prioqueue_t p, type const x) \ { \ /* Push back the new element at the end of the array */ \ - M_C(name, _array_push_back)(p->array, x); \ + M_F(name, _array_push_back)(p->array, x); \ \ /* Reorder the array by swapping with its parent \ * until it reaches the right position */ \ - size_t i = M_C(name, _array_size)(p->array)-1; \ + size_t i = M_F(name, _array_size)(p->array)-1; \ while (i > 0) { \ - size_t j = M_C(name, _i_parent)(i); \ - if (M_C(name, _i_cmp)(p, j, i) <= 0) \ + size_t j = M_F(name, _i_parent)(i); \ + if (M_F(name, _i_cmp)(p, j, i) <= 0) \ break; \ - M_C(name, _array_swap_at) (p->array, i, j); \ + M_F(name, _array_swap_at) (p->array, i, j); \ i = j; \ } \ } \ \ static inline type const * \ - M_C(name, _front)(prioqueue_t const p) \ + M_F(name, _front)(prioqueue_t const p) \ { \ - return M_C(name, _array_cget)(p->array, 0); \ + return M_F(name, _array_cget)(p->array, 0); \ } \ \ static inline void \ - M_C(name, _pop)(type *x, prioqueue_t p) \ + M_F(name, _pop)(type *x, prioqueue_t p) \ { \ /* Swap the front element with the last element */ \ - size_t size = M_C(name, _array_size)(p->array)-1; \ - M_C(name, _array_swap_at) (p->array, 0, size); \ + size_t size = M_F(name, _array_size)(p->array)-1; \ + M_F(name, _array_swap_at) (p->array, 0, size); \ /* Swap the new last element */ \ - M_C(name, _array_pop_back)(x, p->array); \ + M_F(name, _array_pop_back)(x, p->array); \ \ /* Reorder the heap */ \ size_t i = 0; \ while (true) { \ - size_t child = M_C(name, _i_lchild)(i); \ + size_t child = M_F(name, _i_lchild)(i); \ if (child >= size) \ break; \ - size_t otherChild = M_C(name, _i_rchild)(i); \ + size_t otherChild = M_F(name, _i_rchild)(i); \ if (otherChild < size \ - && M_C(name, _i_cmp)(p, otherChild, child) < 0 ) { \ + && M_F(name, _i_cmp)(p, otherChild, child) < 0 ) { \ child = otherChild; \ } \ - if (M_C(name, _i_cmp)(p, i, child) <= 0) \ + if (M_F(name, _i_cmp)(p, i, child) <= 0) \ break; \ - M_C(name, _array_swap_at) (p->array, i, child); \ + M_F(name, _array_swap_at) (p->array, i, child); \ i = child; \ } \ } \ @@ -304,86 +304,86 @@ ( \ /* EQUAL & CMP may be uncorrelated */ \ static inline bool \ - M_C(name, _equal_p)(prioqueue_t const p, prioqueue_t const q) \ + M_F(name, _equal_p)(prioqueue_t const p, prioqueue_t const q) \ { \ - return M_C(name, _array_equal_p)(p->array, q->array); \ + return M_F(name, _array_equal_p)(p->array, q->array); \ } \ \ static inline size_t \ - M_C(name, _i_find)(prioqueue_t p, type const x) \ + M_F(name, _i_find)(prioqueue_t p, type const x) \ { \ - size_t size = M_C(name, _array_size)(p->array); \ + size_t size = M_F(name, _array_size)(p->array); \ size_t i = 0; \ for(i = 0; i < size; i++) { \ /* FIXME: Can we use CMP and the partial order to go faster? */ \ - if (M_CALL_EQUAL(oplist, *M_C(name, _array_cget)(p->array, i), x)) \ + if (M_CALL_EQUAL(oplist, *M_F(name, _array_cget)(p->array, i), x)) \ break; \ } \ return i; \ } \ \ static inline bool \ - M_C(name, _erase)(prioqueue_t p, type const x) \ + M_F(name, _erase)(prioqueue_t p, type const x) \ { \ /* First pass: search for an item EQUAL to x */ \ - size_t size = M_C(name, _array_size)(p->array); \ - size_t i = M_C(name, _i_find)(p, x); \ + size_t size = M_F(name, _array_size)(p->array); \ + size_t i = M_F(name, _i_find)(p, x); \ /* If x is not found, then stop */ \ if (i >= size) \ return false; \ /* Swap the found item and the last element */ \ size--; \ - M_C(name, _array_swap_at) (p->array, i, size); \ - M_C(name, _array_pop_back)(NULL, p->array); \ + M_F(name, _array_swap_at) (p->array, i, size); \ + M_F(name, _array_pop_back)(NULL, p->array); \ /* Move back the last swapped element to its right position in the heap */ \ while (true) { \ - size_t child = M_C(name, _i_lchild)(i); \ + size_t child = M_F(name, _i_lchild)(i); \ if (child >= size) break; \ - size_t otherChild = M_C(name, _i_rchild)(i); \ + size_t otherChild = M_F(name, _i_rchild)(i); \ if (otherChild < size \ - && M_C(name, _i_cmp)(p, otherChild, child) < 0 ) { \ + && M_F(name, _i_cmp)(p, otherChild, child) < 0 ) { \ child = otherChild; \ } \ - if (M_C(name, _i_cmp)(p, i, child) <= 0) break; \ - M_C(name, _array_swap_at) (p->array, i, child); \ + if (M_F(name, _i_cmp)(p, i, child) <= 0) break; \ + M_F(name, _array_swap_at) (p->array, i, child); \ i = child; \ } \ return true; \ } \ \ static inline void \ - M_C(name, _update)(prioqueue_t p, type const xold, type const xnew) \ + M_F(name, _update)(prioqueue_t p, type const xold, type const xnew) \ { \ /* NOTE: xold can be the same pointer than xnew */ \ /* First pass: search for an item EQUAL to x */ \ - size_t size = M_C(name, _array_size)(p->array); \ - size_t i = M_C(name, _i_find)(p, xold); \ + size_t size = M_F(name, _array_size)(p->array); \ + size_t i = M_F(name, _i_find)(p, xold); \ /* We shall have found the item */ \ M_ASSERT (i < size); \ /* Test if the position of the old data is further or nearer than the new */ \ - int cmp = M_CALL_CMP(oplist, *M_C(name, _array_cget)(p->array, i), xnew); \ + int cmp = M_CALL_CMP(oplist, *M_F(name, _array_cget)(p->array, i), xnew); \ /* Set the found item to the new element */ \ - M_C(name, _array_set_at) (p->array, i, xnew); \ + M_F(name, _array_set_at) (p->array, i, xnew); \ if (cmp < 0) { \ /* Move back the updated element to its new position, further in the heap */ \ while (true) { \ - size_t child = M_C(name, _i_lchild)(i); \ + size_t child = M_F(name, _i_lchild)(i); \ if (child >= size) break; \ - size_t otherChild = M_C(name, _i_rchild)(i); \ + size_t otherChild = M_F(name, _i_rchild)(i); \ if (otherChild < size \ - && M_C(name, _i_cmp)(p, otherChild, child) < 0 ) { \ + && M_F(name, _i_cmp)(p, otherChild, child) < 0 ) { \ child = otherChild; \ } \ - if (M_C(name, _i_cmp)(p, i, child) <= 0) break; \ - M_C(name, _array_swap_at) (p->array, i, child); \ + if (M_F(name, _i_cmp)(p, i, child) <= 0) break; \ + M_F(name, _array_swap_at) (p->array, i, child); \ i = child; \ } \ } else { \ /* Move back the updated element to its new position, nearest in the heap */ \ while (i > 0) { \ - size_t parent = M_C(name, _i_parent)(i); \ - if (M_C(name, _i_cmp)(p, parent, i) <= 0) break; \ - M_C(name, _array_swap_at) (p->array, i, parent); \ + size_t parent = M_F(name, _i_parent)(i); \ + if (M_F(name, _i_cmp)(p, parent, i) <= 0) break; \ + M_F(name, _array_swap_at) (p->array, i, parent); \ i = parent; \ } \ } \ @@ -395,113 +395,113 @@ \ /* Define iterators over the array iterator */ \ static inline void \ - M_C(name, _it)(it_t it, prioqueue_t const v) \ + M_F(name, _it)(it_t it, prioqueue_t const v) \ { \ - M_C(name, _array_it)(it, v->array); \ + M_F(name, _array_it)(it, v->array); \ } \ \ static inline void \ - M_C(name, _it_last)(it_t it, prioqueue_t const v) \ + M_F(name, _it_last)(it_t it, prioqueue_t const v) \ { \ - M_C(name, _array_it_last)(it, v->array); \ + M_F(name, _array_it_last)(it, v->array); \ } \ \ static inline void \ - M_C(name, _it_end)(it_t it, prioqueue_t const v) \ + M_F(name, _it_end)(it_t it, prioqueue_t const v) \ { \ - M_C(name, _array_it_end)(it, v->array); \ + M_F(name, _array_it_end)(it, v->array); \ } \ \ static inline void \ - M_C(name, _it_set)(it_t it, const it_t org) \ + M_F(name, _it_set)(it_t it, const it_t org) \ { \ - M_C(name, _array_it_set)(it, org); \ + M_F(name, _array_it_set)(it, org); \ } \ \ static inline bool \ - M_C(name, _end_p)(const it_t it) \ + M_F(name, _end_p)(const it_t it) \ { \ - return M_C(name, _array_end_p)(it); \ + return M_F(name, _array_end_p)(it); \ } \ \ static inline bool \ - M_C(name, _last_p)(const it_t it) \ + M_F(name, _last_p)(const it_t it) \ { \ - return M_C(name, _array_last_p)(it); \ + return M_F(name, _array_last_p)(it); \ } \ \ static inline bool \ - M_C(name, _it_equal_p)(const it_t it1, \ + M_F(name, _it_equal_p)(const it_t it1, \ const it_t it2) \ { \ - return M_C(name, _array_it_equal_p)(it1, it2); \ + return M_F(name, _array_it_equal_p)(it1, it2); \ } \ \ static inline void \ - M_C(name, _next)(it_t it) \ + M_F(name, _next)(it_t it) \ { \ - M_C(name, _array_next)(it); \ + M_F(name, _array_next)(it); \ } \ \ static inline void \ - M_C(name, _previous)(it_t it) \ + M_F(name, _previous)(it_t it) \ { \ - M_C(name, _array_previous)(it); \ + M_F(name, _array_previous)(it); \ } \ \ static inline type const * \ - M_C(name, _cref)(const it_t it) \ + M_F(name, _cref)(const it_t it) \ { \ - return M_C(name, _array_cref)(it); \ + return M_F(name, _array_cref)(it); \ } \ /* Define the IO functions */ #define M_PR1OQUEUE_DEF_IO(name, type, oplist, prioqueue_t, it_t) \ M_IF_METHOD(OUT_STR, oplist)( \ static inline void \ - M_C(name, _out_str)(FILE *file, const prioqueue_t p) \ + M_F(name, _out_str)(FILE *file, const prioqueue_t p) \ { \ - M_C(name, _array_out_str)(file, p->array); \ + M_F(name, _array_out_str)(file, p->array); \ } \ ,/* No OUT_STR */) \ \ M_IF_METHOD(IN_STR, oplist)( \ static inline bool \ - M_C(name, _in_str)(prioqueue_t p, FILE *file) \ + M_F(name, _in_str)(prioqueue_t p, FILE *file) \ { \ - return M_C(name, _array_in_str)(p->array, file); \ + return M_F(name, _array_in_str)(p->array, file); \ } \ ,/* No IN_STR */) \ \ M_IF_METHOD(GET_STR, oplist)( \ static inline void \ - M_C(name, _get_str)(string_t str, const prioqueue_t p, bool append) \ + M_F(name, _get_str)(string_t str, const prioqueue_t p, bool append) \ { \ - M_C(name, _array_get_str)(str, p->array, append); \ + M_F(name, _array_get_str)(str, p->array, append); \ } \ ,/* No GET_STR */) \ \ M_IF_METHOD(PARSE_STR, oplist)( \ static inline bool \ - M_C(name, _parse_str)(prioqueue_t p, const char str[], const char **endp) \ + M_F(name, _parse_str)(prioqueue_t p, const char str[], const char **endp) \ { \ - return M_C(name, _array_parse_str)(p->array, str, endp); \ + return M_F(name, _array_parse_str)(p->array, str, endp); \ } \ ,/* No PARSE_STR */) \ \ M_IF_METHOD(OUT_SERIAL, oplist)( \ static inline m_serial_return_code_t \ - M_C(name, _out_serial)(m_serial_write_t f, const prioqueue_t p) \ + M_F(name, _out_serial)(m_serial_write_t f, const prioqueue_t p) \ { \ - return M_C(name, _array_out_serial)(f, p->array); \ + return M_F(name, _array_out_serial)(f, p->array); \ } \ ,/* No OUT_SERIAL */) \ \ M_IF_METHOD2(IN_SERIAL, INIT, oplist)( \ static inline m_serial_return_code_t \ - M_C(name, _in_serial)(prioqueue_t p, m_serial_read_t f) \ + M_F(name, _in_serial)(prioqueue_t p, m_serial_read_t f) \ { \ - return M_C(name, _array_in_serial)(p->array, f); \ + return M_F(name, _array_in_serial)(p->array, f); \ } \ ,/* No in_SERIAL */) \ diff --git a/m-rbtree.h b/m-rbtree.h index 663bfce9..62ba39da 100644 --- a/m-rbtree.h +++ b/m-rbtree.h @@ -30,7 +30,7 @@ /* Define a Red/Black binary tree of a given type. USAGE: RBTREE_DEF(name, type [, oplist_of_the_type]) */ #define M_RBTREE_DEF(name, ...) \ - M_RBTREE_DEF_AS(name, M_C(name,_t), M_C(name,_it_t), __VA_ARGS__) + M_RBTREE_DEF_AS(name, M_F(name,_t), M_F(name,_it_t), __VA_ARGS__) /* Define a Red/Black binary tree of a given type @@ -39,8 +39,8 @@ #define M_RBTREE_DEF_AS(name, name_t, it_t, ...) \ M_BEGIN_PROTECTED_CODE \ M_RBTR33_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \ - ((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t, M_C(name, _node_ct), it_t ), \ - (name, __VA_ARGS__, name_t, M_C(name, _node_ct), it_t ))) \ + ((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t, M_F(name, _node_ct), it_t ), \ + (name, __VA_ARGS__, name_t, M_F(name, _node_ct), it_t ))) \ M_END_PROTECTED_CODE @@ -72,43 +72,43 @@ NOTE: IT_REF is not exported so that the container appears as not modifiable by algorithm.*/ #define M_RBTR33_OPLIST_P3(name, oplist) \ - (INIT(M_C(name, _init)), \ - INIT_SET(M_C(name, _init_set)), \ + (INIT(M_F(name, _init)), \ + INIT_SET(M_F(name, _init_set)), \ INIT_WITH(API_1(M_INIT_EMPLACE_VAI)), \ - SET(M_C(name, _set)), \ - CLEAR(M_C(name, _clear)), \ - INIT_MOVE(M_C(name, _init_move)), \ - MOVE(M_C(name, _move)), \ - SWAP(M_C(name, _swap)), \ + SET(M_F(name, _set)), \ + CLEAR(M_F(name, _clear)), \ + INIT_MOVE(M_F(name, _init_move)), \ + MOVE(M_F(name, _move)), \ + SWAP(M_F(name, _swap)), \ NAME(name), \ - TYPE(M_C(name,_ct)), \ - SUBTYPE(M_C(name, _subtype_ct)), \ - EMPTY_P(M_C(name,_empty_p)), \ - GET_SIZE(M_C(name, _size)), \ - IT_TYPE(M_C(name, _it_ct)), \ - IT_FIRST(M_C(name,_it)), \ - IT_SET(M_C(name,_it_set)), \ - IT_LAST(M_C(name,_it_last)), \ - IT_END(M_C(name,_it_end)), \ - IT_END_P(M_C(name,_end_p)), \ - IT_LAST_P(M_C(name,_last_p)), \ - IT_EQUAL_P(M_C(name,_it_equal_p)), \ - IT_NEXT(M_C(name,_next)), \ - IT_PREVIOUS(M_C(name,_previous)), \ - IT_CREF(M_C(name,_cref)), \ - IT_REMOVE(M_C(name,_remove)), \ - RESET(M_C(name,_reset)), \ - PUSH(M_C(name,_push)), \ - GET_MIN(M_C(name,_min)), \ - GET_MAX(M_C(name,_max)), \ - M_IF_METHOD(GET_STR, oplist)(GET_STR(M_C(name, _get_str)),), \ - M_IF_METHOD(PARSE_STR, oplist)(PARSE_STR(M_C(name, _parse_str)),), \ - M_IF_METHOD(OUT_STR, oplist)(OUT_STR(M_C(name, _out_str)),), \ - M_IF_METHOD(IN_STR, oplist)(IN_STR(M_C(name, _in_str)),), \ - M_IF_METHOD(OUT_SERIAL, oplist)(OUT_SERIAL(M_C(name, _out_serial)),), \ - M_IF_METHOD(IN_SERIAL, oplist)(IN_SERIAL(M_C(name, _in_serial)),), \ - M_IF_METHOD(EQUAL, oplist)(EQUAL(M_C(name, _equal_p)),), \ - M_IF_METHOD(HASH, oplist)(HASH(M_C(name, _hash)),) \ + TYPE(M_F(name,_ct)), \ + SUBTYPE(M_F(name, _subtype_ct)), \ + EMPTY_P(M_F(name,_empty_p)), \ + GET_SIZE(M_F(name, _size)), \ + IT_TYPE(M_F(name, _it_ct)), \ + IT_FIRST(M_F(name,_it)), \ + IT_SET(M_F(name,_it_set)), \ + IT_LAST(M_F(name,_it_last)), \ + IT_END(M_F(name,_it_end)), \ + IT_END_P(M_F(name,_end_p)), \ + IT_LAST_P(M_F(name,_last_p)), \ + IT_EQUAL_P(M_F(name,_it_equal_p)), \ + IT_NEXT(M_F(name,_next)), \ + IT_PREVIOUS(M_F(name,_previous)), \ + IT_CREF(M_F(name,_cref)), \ + IT_REMOVE(M_F(name,_remove)), \ + RESET(M_F(name,_reset)), \ + PUSH(M_F(name,_push)), \ + GET_MIN(M_F(name,_min)), \ + GET_MAX(M_F(name,_max)), \ + M_IF_METHOD(GET_STR, oplist)(GET_STR(M_F(name, _get_str)),), \ + M_IF_METHOD(PARSE_STR, oplist)(PARSE_STR(M_F(name, _parse_str)),), \ + M_IF_METHOD(OUT_STR, oplist)(OUT_STR(M_F(name, _out_str)),), \ + M_IF_METHOD(IN_STR, oplist)(IN_STR(M_F(name, _in_str)),), \ + M_IF_METHOD(OUT_SERIAL, oplist)(OUT_SERIAL(M_F(name, _out_serial)),), \ + M_IF_METHOD(IN_SERIAL, oplist)(IN_SERIAL(M_F(name, _in_serial)),), \ + M_IF_METHOD(EQUAL, oplist)(EQUAL(M_F(name, _equal_p)),), \ + M_IF_METHOD(HASH, oplist)(HASH(M_F(name, _hash)),) \ ,M_IF_METHOD(NEW, oplist)(NEW(M_GET_NEW oplist),) \ ,M_IF_METHOD(REALLOC, oplist)(REALLOC(M_GET_REALLOC oplist),) \ ,M_IF_METHOD(DEL, oplist)(DEL(M_GET_DEL oplist),) \ @@ -183,7 +183,7 @@ typedef enum { M_CHECK_COMPATIBLE_OPLIST(name, 1, type, oplist) \ M_RBTR33_DEF_CORE(name, type, oplist, tree_t, node_t, it_t) \ M_RBTR33_DEF_IO(name, type, oplist, tree_t, node_t, it_t) \ - M_EMPLACE_QUEUE_DEF(name, tree_t, M_C(name, _emplace), oplist, M_EMPLACE_QUEUE_GENE) + M_EMPLACE_QUEUE_DEF(name, tree_t, M_F(name, _emplace), oplist, M_EMPLACE_QUEUE_GENE) /* Define the types associated to a R/B Tree */ #define M_RBTR33_DEF_TYPE(name, type, oplist, tree_t, node_t, it_t) \ @@ -191,48 +191,48 @@ typedef enum { /* Node of Red/Black tree. \ Each node has up to two child, a color (Red or black) \ and the data stored in it */ \ - typedef struct M_C(name, _node_s) { \ - struct M_C(name, _node_s) *child[2]; \ + typedef struct M_F(name, _node_s) { \ + struct M_F(name, _node_s) *child[2]; \ type data; \ m_rbtr33_color_e color; \ } node_t; \ \ /* Define the Red/Black tree */ \ - typedef struct M_C(name, _s) { \ + typedef struct M_F(name, _s) { \ size_t size; /* Number of elements in the tree */ \ node_t *node; /* Root node of the tree */ \ } tree_t[1]; \ - typedef struct M_C(name, _s) *M_C(name, _ptr); \ - typedef const struct M_C(name, _s) *M_C(name, _srcptr); \ + typedef struct M_F(name, _s) *M_F(name, _ptr); \ + typedef const struct M_F(name, _s) *M_F(name, _srcptr); \ \ /* Iterator on a tree. The iterator stores the full path to the \ current node through all its parents and its depth */ \ - typedef struct M_C(name, _it_s) { \ + typedef struct M_F(name, _it_s) { \ node_t *stack[M_RBTR33_MAX_STACK]; \ int8_t which[M_RBTR33_MAX_STACK]; \ unsigned int cpt; \ } it_t[1]; \ \ /* Definition of the alias used by the oplists */ \ - typedef type M_C(name, _subtype_ct); \ - typedef tree_t M_C(name, _ct); \ - typedef it_t M_C(name, _it_ct); \ + typedef type M_F(name, _subtype_ct); \ + typedef tree_t M_F(name, _ct); \ + typedef it_t M_F(name, _it_ct); \ /* Define the mempool encapsulation */ #define M_RBTR33_DEF_MEMPOOL(name, type, oplist, tree_t, node_t, it_t) \ /* Link with fast memory allocator if requested */ \ M_IF_METHOD(MEMPOOL, oplist)( \ /* Definition of the memory pool of this kind of node */ \ - MEMPOOL_DEF(M_C(name, _mempool), node_t) \ + MEMPOOL_DEF(M_F(name, _mempool), node_t) \ /* Definition of the global variable used to reference this pool */ \ - M_GET_MEMPOOL_LINKAGE oplist M_C(name, _mempool_t) M_GET_MEMPOOL oplist; \ + M_GET_MEMPOOL_LINKAGE oplist M_F(name, _mempool_t) M_GET_MEMPOOL oplist; \ /* Allocator function */ \ static inline node_t *M_C3(m_rbtr33_,name,_new)(void) { \ - return M_C(name, _mempool_alloc)(M_GET_MEMPOOL oplist); \ + return M_F(name, _mempool_alloc)(M_GET_MEMPOOL oplist); \ } \ /* Deallocator function */ \ static inline void M_C3(m_rbtr33_,name,_del)(node_t *ptr) { \ - M_C(name, _mempool_free)(M_GET_MEMPOOL oplist, ptr); \ + M_F(name, _mempool_free)(M_GET_MEMPOOL oplist, ptr); \ } \ \ , /* No mempool allocation */ \ @@ -249,7 +249,7 @@ typedef enum { #define M_RBTR33_DEF_CORE(name, type, oplist, tree_t, node_t, it_t) \ \ static inline void \ - M_C(name, _init)(tree_t tree) \ + M_F(name, _init)(tree_t tree) \ { \ M_ASSERT (tree != NULL); \ tree->size = 0; \ @@ -258,7 +258,7 @@ typedef enum { } \ \ static inline void \ - M_C(name, _reset)(tree_t tree) \ + M_F(name, _reset)(tree_t tree) \ { \ M_RBTR33_CONTRACT(tree); \ node_t *stack[M_RBTR33_MAX_STACK]; \ @@ -303,14 +303,14 @@ typedef enum { } \ \ static inline void \ - M_C(name, _clear)(tree_t tree) \ + M_F(name, _clear)(tree_t tree) \ { \ /* Nothing more than clean the tree as everything is cleared */ \ - M_C(name, _reset)(tree); \ + M_F(name, _reset)(tree); \ } \ \ static inline void \ - M_C(name, _push)(tree_t tree, type const data) \ + M_F(name, _push)(tree_t tree, type const data) \ { \ M_RBTR33_CONTRACT(tree); \ node_t *tab[M_RBTR33_MAX_STACK]; \ @@ -436,7 +436,7 @@ typedef enum { } \ \ static inline size_t \ - M_C(name, _size)(const tree_t tree) \ + M_F(name, _size)(const tree_t tree) \ { \ M_RBTR33_CONTRACT (tree); \ return tree->size; \ @@ -466,19 +466,19 @@ typedef enum { } \ \ static inline void \ - M_C(name, _it)(it_t it, const tree_t tree) \ + M_F(name, _it)(it_t it, const tree_t tree) \ { \ M_C3(m_rbtr33_,name,_it)(it, tree, 0); \ } \ \ static inline void \ - M_C(name, _it_last)(it_t it, const tree_t tree) \ + M_F(name, _it_last)(it_t it, const tree_t tree) \ { \ M_C3(m_rbtr33_,name,_it)(it, tree, 1); \ } \ \ static inline void \ - M_C(name, _it_end)(it_t it, const tree_t tree) \ + M_F(name, _it_end)(it_t it, const tree_t tree) \ { \ M_RBTR33_CONTRACT (tree); \ M_ASSERT (it != NULL); \ @@ -487,14 +487,14 @@ typedef enum { } \ \ static inline void \ - M_C(name, _it_set)(it_t it, const it_t ref) \ + M_F(name, _it_set)(it_t it, const it_t ref) \ { \ M_ASSERT (it != NULL && ref != NULL); \ *it = *ref; \ } \ \ static inline bool \ - M_C(name, _end_p)(const it_t it) \ + M_F(name, _end_p)(const it_t it) \ { \ M_ASSERT (it != NULL); \ return it->cpt == 0; \ @@ -534,19 +534,19 @@ typedef enum { } \ \ static inline void \ - M_C(name, _next)(it_t it) \ + M_F(name, _next)(it_t it) \ { \ M_C3(m_rbtr33_,name,_next)(it, 0); \ } \ \ static inline void \ - M_C(name, _previous)(it_t it) \ + M_F(name, _previous)(it_t it) \ { \ M_C3(m_rbtr33_,name,_next)(it, 1); \ } \ \ static inline type * \ - M_C(name, _ref)(const it_t it) \ + M_F(name, _ref)(const it_t it) \ { \ M_ASSERT(it != NULL); \ /* There shall be at least one element */ \ @@ -556,13 +556,13 @@ typedef enum { } \ \ static inline type const * \ - M_C(name, _cref)(const it_t it) \ + M_F(name, _cref)(const it_t it) \ { \ - return M_CONST_CAST(type, M_C(name, _ref)(it)); \ + return M_CONST_CAST(type, M_F(name, _ref)(it)); \ } \ \ static inline bool \ - M_C(name, _it_equal_p)(const it_t it1, const it_t it2) \ + M_F(name, _it_equal_p)(const it_t it1, const it_t it2) \ { \ M_ASSERT(it1 != NULL && it2 != NULL); \ /* There can be no element */ \ @@ -573,7 +573,7 @@ typedef enum { } \ \ static inline void \ - M_C(name, _it_from)(it_t it, const tree_t tree, type const data) \ + M_F(name, _it_from)(it_t it, const tree_t tree, type const data) \ { \ M_RBTR33_CONTRACT (tree); \ M_ASSERT (it != NULL); \ @@ -597,12 +597,12 @@ typedef enum { /* The iterator found may be strictly lower than data. \ In this case, go to the next element */ \ if (cmp < 0) { \ - M_C(name, _next)(it); \ + M_F(name, _next)(it); \ } \ } \ \ static inline bool \ - M_C(name, _it_until_p)(it_t it, type const data) \ + M_F(name, _it_until_p)(it_t it, type const data) \ { \ M_ASSERT (it != NULL); \ if (M_UNLIKELY(it->cpt == 0)) return true; \ @@ -613,7 +613,7 @@ typedef enum { } \ \ static inline bool \ - M_C(name, _it_while_p)(it_t it, type const data) \ + M_F(name, _it_while_p)(it_t it, type const data) \ { \ M_ASSERT (it != NULL); \ if (M_UNLIKELY(it->cpt == 0)) return false; \ @@ -624,7 +624,7 @@ typedef enum { } \ \ static inline type * \ - M_C(name, _min)(const tree_t tree) \ + M_F(name, _min)(const tree_t tree) \ { \ M_RBTR33_CONTRACT (tree); \ node_t *n = tree->node; \ @@ -637,7 +637,7 @@ typedef enum { } \ \ static inline type * \ - M_C(name, _max)(const tree_t tree) \ + M_F(name, _max)(const tree_t tree) \ { \ M_RBTR33_CONTRACT (tree); \ node_t *n = tree->node; \ @@ -650,19 +650,19 @@ typedef enum { } \ \ static inline type const * \ - M_C(name, _cmin)(const tree_t tree) \ + M_F(name, _cmin)(const tree_t tree) \ { \ - return M_CONST_CAST(type, M_C(name, _min)(tree)); \ + return M_CONST_CAST(type, M_F(name, _min)(tree)); \ } \ \ static inline type const * \ - M_C(name, _cmax)(const tree_t tree) \ + M_F(name, _cmax)(const tree_t tree) \ { \ - return M_CONST_CAST(type, M_C(name, _max)(tree)); \ + return M_CONST_CAST(type, M_F(name, _max)(tree)); \ } \ \ static inline type * \ - M_C(name, _get)(const tree_t tree, type const data) \ + M_F(name, _get)(const tree_t tree, type const data) \ { \ M_RBTR33_CONTRACT (tree); \ node_t *n = tree->node; \ @@ -681,9 +681,9 @@ typedef enum { } \ \ static inline type const * \ - M_C(name, _cget)(const tree_t tree, type const data) \ + M_F(name, _cget)(const tree_t tree, type const data) \ { \ - return M_CONST_CAST(type, M_C(name, _get)(tree, data)); \ + return M_CONST_CAST(type, M_F(name, _get)(tree, data)); \ } \ \ /* Create a copy of the given node (recursively) */ \ @@ -704,7 +704,7 @@ typedef enum { } \ \ static inline void \ - M_C(name, _init_set)(tree_t tree, const tree_t ref) \ + M_F(name, _init_set)(tree_t tree, const tree_t ref) \ { \ M_RBTR33_CONTRACT (ref); \ M_ASSERT (tree != NULL && tree != ref); \ @@ -715,17 +715,17 @@ typedef enum { } \ \ static inline void \ - M_C(name, _set)(tree_t tree, const tree_t ref) \ + M_F(name, _set)(tree_t tree, const tree_t ref) \ { \ M_RBTR33_CONTRACT (tree); \ M_RBTR33_CONTRACT (ref); \ if (tree == ref) return; \ - M_C(name,_clear)(tree); \ - M_C(name,_init_set)(tree, ref); \ + M_F(name,_clear)(tree); \ + M_F(name,_init_set)(tree, ref); \ } \ \ static inline void \ - M_C(name, _init_move)(tree_t tree, tree_t ref) \ + M_F(name, _init_move)(tree_t tree, tree_t ref) \ { \ M_RBTR33_CONTRACT (ref); \ M_ASSERT (tree != NULL && tree != ref); \ @@ -737,18 +737,18 @@ typedef enum { } \ \ static inline void \ - M_C(name, _move)(tree_t tree, tree_t ref) \ + M_F(name, _move)(tree_t tree, tree_t ref) \ { \ M_RBTR33_CONTRACT (tree); \ M_RBTR33_CONTRACT (ref); \ M_ASSERT (tree != ref); \ - M_C(name,_clear)(tree); \ - M_C(name,_init_move)(tree, ref); \ + M_F(name,_clear)(tree); \ + M_F(name,_init_move)(tree, ref); \ M_RBTR33_CONTRACT (tree); \ } \ \ static inline void \ - M_C(name, _swap)(tree_t tree1, tree_t tree2) \ + M_F(name, _swap)(tree_t tree1, tree_t tree2) \ { \ M_RBTR33_CONTRACT (tree1); \ M_RBTR33_CONTRACT (tree2); \ @@ -759,7 +759,7 @@ typedef enum { } \ \ static inline bool \ - M_C(name, _empty_p)(const tree_t tree) \ + M_F(name, _empty_p)(const tree_t tree) \ { \ M_RBTR33_CONTRACT (tree); \ return tree->size == 0; \ @@ -805,7 +805,7 @@ typedef enum { ) \ \ static inline bool \ - M_C(name, _pop_at)(type *data_ptr, tree_t tree, type const key) \ + M_F(name, _pop_at)(type *data_ptr, tree_t tree, type const key) \ { \ M_RBTR33_CONTRACT (tree); \ node_t *tab[M_RBTR33_MAX_STACK]; \ @@ -964,22 +964,22 @@ typedef enum { return true; \ } \ \ - static inline void M_C(name,_remove)(tree_t t, it_t it) \ + static inline void M_F(name,_remove)(tree_t t, it_t it) \ { \ /* Not optimum: another search in the tree is performed */ \ type data; \ - M_CALL_INIT_SET(oplist, data, *M_C(name,_cref)(it)); \ - M_C(name,_next)(it); \ - M_C(name, _pop_at)(NULL, t, data); \ + M_CALL_INIT_SET(oplist, data, *M_F(name,_cref)(it)); \ + M_F(name,_next)(it); \ + M_F(name, _pop_at)(NULL, t, data); \ /* We have changed the tree: the iterator is partialy invalid */ \ - if (!M_C(name, _end_p)(it)) { \ - M_C(name, _it_from)(it, t, *M_C(name,_cref)(it)); \ + if (!M_F(name, _end_p)(it)) { \ + M_F(name, _it_from)(it, t, *M_F(name,_cref)(it)); \ } \ M_CALL_CLEAR(oplist, data); \ } \ \ M_IF_METHOD(EQUAL, oplist)( \ - static inline bool M_C(name,_equal_p)(const tree_t t1, const tree_t t2) { \ + static inline bool M_F(name,_equal_p)(const tree_t t1, const tree_t t2) { \ M_RBTR33_CONTRACT(t1); \ M_RBTR33_CONTRACT(t2); \ if (t1->size != t2->size) return false; \ @@ -989,34 +989,34 @@ typedef enum { structuraly different but functionnaly equal (you get this by \ constructing the tree in a different way). We have to \ compare the ordered value within the tree. */ \ - M_C(name, _it)(it1, t1); \ - M_C(name, _it)(it2, t2); \ - while (!M_C(name, _end_p)(it1) \ - && !M_C(name, _end_p)(it2)) { \ - type const *ref1 = M_C(name, _cref)(it1); \ - type const *ref2 = M_C(name, _cref)(it2); \ + M_F(name, _it)(it1, t1); \ + M_F(name, _it)(it2, t2); \ + while (!M_F(name, _end_p)(it1) \ + && !M_F(name, _end_p)(it2)) { \ + type const *ref1 = M_F(name, _cref)(it1); \ + type const *ref2 = M_F(name, _cref)(it2); \ if (M_CALL_EQUAL(oplist, *ref1, *ref2) == false) \ return false; \ - M_C(name, _next)(it1); \ - M_C(name, _next)(it2); \ + M_F(name, _next)(it1); \ + M_F(name, _next)(it2); \ } \ - return M_C(name, _end_p)(it1) \ - && M_C(name, _end_p)(it2); \ + return M_F(name, _end_p)(it1) \ + && M_F(name, _end_p)(it2); \ } \ , /* NO EQUAL METHOD */ ) \ \ M_IF_METHOD(HASH, oplist)( \ - static inline size_t M_C(name,_hash)(const tree_t t1) { \ + static inline size_t M_F(name,_hash)(const tree_t t1) { \ M_RBTR33_CONTRACT(t1); \ M_HASH_DECL(hash); \ /* NOTE: We can't compute the hash directly for the same reason \ than for EQUAL operator. */ \ it_t it1; \ - M_C(name, _it)(it1, t1); \ - while (!M_C(name, _end_p)(it1)) { \ - type const *ref1 = M_C(name, _cref)(it1); \ + M_F(name, _it)(it1, t1); \ + while (!M_F(name, _end_p)(it1)) { \ + type const *ref1 = M_F(name, _cref)(it1); \ M_HASH_UP(hash, M_CALL_HASH(oplist, *ref1)); \ - M_C(name, _next)(it1); \ + M_F(name, _next)(it1); \ } \ return M_HASH_FINAL (hash); \ } \ @@ -1025,7 +1025,7 @@ typedef enum { /* Define the I/O functions */ #define M_RBTR33_DEF_IO(name, type, oplist, tree_t, node_t, it_t) \ M_IF_METHOD(GET_STR, oplist)( \ - static inline void M_C(name, _get_str)(m_string_t str, \ + static inline void M_F(name, _get_str)(m_string_t str, \ tree_t const t1, bool append) { \ M_RBTR33_CONTRACT(t1); \ M_ASSERT(str != NULL); \ @@ -1033,14 +1033,14 @@ typedef enum { /* NOTE: The print is really naive, and not really efficient */ \ bool commaToPrint = false; \ it_t it1; \ - M_C(name, _it)(it1, t1); \ - while (!M_C(name, _end_p)(it1)) { \ + M_F(name, _it)(it1, t1); \ + while (!M_F(name, _end_p)(it1)) { \ if (commaToPrint) \ m_string_push_back (str, M_GET_SEPARATOR oplist); \ commaToPrint = true; \ - type const *ref1 = M_C(name, _cref)(it1); \ + type const *ref1 = M_F(name, _cref)(it1); \ M_CALL_GET_STR(oplist, str, *ref1, true); \ - M_C(name, _next)(it1); \ + M_F(name, _next)(it1); \ } \ m_string_push_back (str, ']'); \ } \ @@ -1048,20 +1048,20 @@ typedef enum { \ M_IF_METHOD(OUT_STR, oplist)( \ static inline void \ - M_C(name, _out_str)(FILE *file, tree_t const rbtree) \ + M_F(name, _out_str)(FILE *file, tree_t const rbtree) \ { \ M_RBTR33_CONTRACT(rbtree); \ M_ASSERT (file != NULL); \ fputc ('[', file); \ it_t it; \ bool commaToPrint = false; \ - for (M_C(name, _it)(it, rbtree) ; \ - !M_C(name, _end_p)(it); \ - M_C(name, _next)(it)){ \ + for (M_F(name, _it)(it, rbtree) ; \ + !M_F(name, _end_p)(it); \ + M_F(name, _next)(it)){ \ if (commaToPrint) \ fputc (M_GET_SEPARATOR oplist, file); \ commaToPrint = true; \ - type const *item = M_C(name, _cref)(it); \ + type const *item = M_F(name, _cref)(it); \ M_CALL_OUT_STR(oplist, file, *item); \ } \ fputc (']', file); \ @@ -1070,11 +1070,11 @@ typedef enum { \ M_IF_METHOD(PARSE_STR, oplist)( \ static inline bool \ - M_C(name, _parse_str)(tree_t rbtree, const char str[], const char **endp) \ + M_F(name, _parse_str)(tree_t rbtree, const char str[], const char **endp) \ { \ M_RBTR33_CONTRACT(rbtree); \ M_ASSERT (str != NULL); \ - M_C(name,_reset)(rbtree); \ + M_F(name,_reset)(rbtree); \ bool success = false; \ int c = *str++; \ if (M_UNLIKELY (c != '[')) goto exit; \ @@ -1088,7 +1088,7 @@ typedef enum { bool b = M_CALL_PARSE_STR(oplist, item, str, &str); \ do { c = *str++; } while (isspace(c)); \ if (b == false || c == 0) goto exit_clear; \ - M_C(name, _push)(rbtree, item); \ + M_F(name, _push)(rbtree, item); \ } while (c == M_GET_SEPARATOR oplist); \ success = (c == ']'); \ exit_clear: \ @@ -1101,11 +1101,11 @@ typedef enum { \ M_IF_METHOD(IN_STR, oplist)( \ static inline bool \ - M_C(name, _in_str)(tree_t rbtree, FILE *file) \ + M_F(name, _in_str)(tree_t rbtree, FILE *file) \ { \ M_RBTR33_CONTRACT(rbtree); \ M_ASSERT (file != NULL); \ - M_C(name,_reset)(rbtree); \ + M_F(name,_reset)(rbtree); \ int c = fgetc(file); \ if (M_UNLIKELY (c != '[')) return false; \ c = fgetc(file); \ @@ -1118,7 +1118,7 @@ typedef enum { bool b = M_CALL_IN_STR(oplist, item, file); \ do { c = fgetc(file); } while (isspace(c)); \ if (b == false || c == EOF) break; \ - M_C(name, _push)(rbtree, item); \ + M_F(name, _push)(rbtree, item); \ } while (c == M_GET_SEPARATOR oplist); \ M_CALL_CLEAR(oplist, item); \ return c == ']'; \ @@ -1127,20 +1127,20 @@ typedef enum { \ M_IF_METHOD(OUT_SERIAL, oplist)( \ static inline m_serial_return_code_t \ - M_C(name, _out_serial)(m_serial_write_t f, tree_t const t1) \ + M_F(name, _out_serial)(m_serial_write_t f, tree_t const t1) \ { \ M_RBTR33_CONTRACT(t1); \ M_ASSERT (f != NULL && f->m_interface != NULL); \ m_serial_local_t local; \ m_serial_return_code_t ret; \ - M_C(name, _subtype_ct) const *item; \ + M_F(name, _subtype_ct) const *item; \ bool first_done = false; \ it_t it; \ ret = f->m_interface->write_array_start(local, f, t1->size); \ - for (M_C(name, _it)(it, t1) ; \ - !M_C(name, _end_p)(it); \ - M_C(name, _next)(it)){ \ - item = M_C(name, _cref)(it); \ + for (M_F(name, _it)(it, t1) ; \ + !M_F(name, _end_p)(it); \ + M_F(name, _next)(it)){ \ + item = M_F(name, _cref)(it); \ if (first_done) \ ret |= f->m_interface->write_array_next(local, f); \ ret |= M_CALL_OUT_SERIAL(oplist, f, *item); \ @@ -1153,7 +1153,7 @@ typedef enum { \ M_IF_METHOD(IN_SERIAL, oplist)( \ static inline m_serial_return_code_t \ - M_C(name, _in_serial)(tree_t t1, m_serial_read_t f) \ + M_F(name, _in_serial)(tree_t t1, m_serial_read_t f) \ { \ M_RBTR33_CONTRACT(t1); \ M_ASSERT (f != NULL && f->m_interface != NULL); \ @@ -1161,14 +1161,14 @@ typedef enum { m_serial_return_code_t ret; \ size_t estimated_size = 0; \ type key; \ - M_C(name,_reset)(t1); \ + M_F(name,_reset)(t1); \ ret = f->m_interface->read_array_start(local, f, &estimated_size); \ if (M_UNLIKELY (ret != M_SERIAL_OK_CONTINUE)) return ret; \ M_CALL_INIT(oplist, key); \ do { \ ret = M_CALL_IN_SERIAL(oplist, key, f); \ if (ret != M_SERIAL_OK_DONE) { break; } \ - M_C(name, _push)(t1, key); \ + M_F(name, _push)(t1, key); \ } while ((ret = f->m_interface->read_array_next(local, f)) == M_SERIAL_OK_CONTINUE); \ M_CALL_CLEAR(oplist, key); \ return ret; \ diff --git a/m-shared.h b/m-shared.h index 67855c91..59dbda98 100644 --- a/m-shared.h +++ b/m-shared.h @@ -34,7 +34,7 @@ M_BEGIN_PROTECTED_CODE /* Define shared pointer and its function. USAGE: SHARED_PTR_DEF(name, type, [, oplist]) */ #define M_SHARED_PTR_DEF(name, ...) \ - M_SHARED_PTR_DEF_AS(name, M_C(name,_t), __VA_ARGS__) + M_SHARED_PTR_DEF_AS(name, M_F(name,_t), __VA_ARGS__) /* Define shared pointer and its function @@ -59,7 +59,7 @@ M_BEGIN_PROTECTED_CODE /* Define relaxed shared pointer and its function (thread unsafe). USAGE: SHARED_PTR_RELAXED_DEF(name, type, [, oplist]) */ #define M_SHARED_PTR_RELAXED_DEF(name, ...) \ - M_SHARED_PTR_RELAXED_DEF_AS(name, M_C(name,_t), __VA_ARGS__) + M_SHARED_PTR_RELAXED_DEF_AS(name, M_F(name,_t), __VA_ARGS__) /* Define relaxed shared pointer and its function (thread unsafe) @@ -77,7 +77,7 @@ M_BEGIN_PROTECTED_CODE This is a bounded pool of resource shared by multiple owners. USAGE: SHARED_RESOURCE_DEF(name, type, [, oplist]) */ #define M_SHARED_RESOURCE_DEF(name, ...) \ - M_SHARED_RESOURCE_DEF_AS(name, M_C(name,_t), M_C(name,_it_t), __VA_ARGS__) + M_SHARED_RESOURCE_DEF_AS(name, M_F(name,_t), M_F(name,_it_t), __VA_ARGS__) /* Define shared resource and its function @@ -109,16 +109,16 @@ M_BEGIN_PROTECTED_CODE ((M_LIB_ERROR(ARGUMENT_OF_SHARED_PTR_OPLIST_IS_NOT_AN_OPLIST, name, oplist))) #define M_SHAR3D_PTR_OPLIST_P3(name, oplist) ( \ - INIT(M_C(name, _init)), \ - CLEAR(M_C(name, _clear)), \ - INIT_SET(M_C(name, _init_set)), \ - SET(M_C(name, _set)) \ - INIT_MOVE(M_C(name, _init_move)), \ - RESET(M_C(name, _reset)), \ - MOVE(M_C(name, _move)), \ - SWAP(M_C(name, _swap)) \ + INIT(M_F(name, _init)), \ + CLEAR(M_F(name, _clear)), \ + INIT_SET(M_F(name, _init_set)), \ + SET(M_F(name, _set)) \ + INIT_MOVE(M_F(name, _init_move)), \ + RESET(M_F(name, _reset)), \ + MOVE(M_F(name, _move)), \ + SWAP(M_F(name, _swap)) \ ,NAME(name) \ - ,TYPE(M_C(name, _ct)) \ + ,TYPE(M_F(name, _ct)) \ ,M_IF_METHOD(NEW, oplist)(NEW(M_GET_NEW oplist),) \ ,M_IF_METHOD(REALLOC, oplist)(REALLOC(M_GET_REALLOC oplist),) \ ,M_IF_METHOD(DEL, oplist)(DEL(M_GET_DEL oplist),) \ @@ -173,44 +173,44 @@ static inline int m_shar3d_integer_cref(int *p) { return *p; } /* Define the types */ #define M_SHAR3D_PTR_DEF_TYPE(name, type, oplist, cpt_oplist, shared_t) \ \ - typedef struct M_C(name, _s){ \ + typedef struct M_F(name, _s){ \ type *data; /* Pointer to the data */ \ M_GET_TYPE cpt_oplist cpt; /* Counter of how many refs the data */ \ bool combineAlloc; /* Does the data and the ptr share the slot? */ \ } *shared_t[1]; \ - typedef struct M_C(name, _s) *M_C(name, _ptr); \ - typedef const struct M_C(name, _s) *M_C(name, _srcptr); \ + typedef struct M_F(name, _s) *M_F(name, _ptr); \ + typedef const struct M_F(name, _s) *M_F(name, _srcptr); \ \ /* Internal type for oplist */ \ - typedef shared_t M_C(name, _ct); \ + typedef shared_t M_F(name, _ct); \ \ - typedef struct M_C(name, combine_s) { \ + typedef struct M_F(name, combine_s) { \ type data; \ - struct M_C(name, _s) ptr; \ - } M_C(name, combine_ct)[1]; \ + struct M_F(name, _s) ptr; \ + } M_F(name, combine_ct)[1]; \ /* Define the core functions */ #define M_SHAR3D_PTR_DEF_CORE(name, type, oplist, cpt_oplist, shared_t) \ \ static inline void \ - M_C(name, _init)(shared_t shared) \ + M_F(name, _init)(shared_t shared) \ { \ *shared = NULL; \ } \ \ static inline void \ - M_C(name, _init2)(shared_t shared, type *data) \ + M_F(name, _init2)(shared_t shared, type *data) \ { \ M_ASSERT (shared != NULL); \ /* The shared ptr get exclusive access to data */ \ - struct M_C(name, _s) *ptr; \ + struct M_F(name, _s) *ptr; \ if (M_UNLIKELY (data == NULL)) { \ *shared = NULL; \ return; \ } \ - ptr = M_CALL_NEW(oplist, struct M_C(name, _s)); \ + ptr = M_CALL_NEW(oplist, struct M_F(name, _s)); \ if (M_UNLIKELY_NOMEM (ptr == NULL)) { \ - M_MEMORY_FULL(sizeof(struct M_C(name, _s))); \ + M_MEMORY_FULL(sizeof(struct M_F(name, _s))); \ return; \ } \ ptr->data = data; \ @@ -222,16 +222,16 @@ static inline int m_shar3d_integer_cref(int *p) { return *p; } \ M_IF_METHOD(INIT, oplist)( \ static inline void \ - M_C(name, _init_new)(shared_t shared) \ + M_F(name, _init_new)(shared_t shared) \ { \ /* NOTE: Alloc 1 struct with both structures. */ \ - struct M_C(name, combine_s) *p = \ - M_CALL_NEW(oplist, struct M_C(name, combine_s)); \ + struct M_F(name, combine_s) *p = \ + M_CALL_NEW(oplist, struct M_F(name, combine_s)); \ if (M_UNLIKELY_NOMEM (p == NULL)) { \ - M_MEMORY_FULL(sizeof(struct M_C(name, combine_s))); \ + M_MEMORY_FULL(sizeof(struct M_F(name, combine_s))); \ return; \ } \ - struct M_C(name, _s) *ptr = &p->ptr; \ + struct M_F(name, _s) *ptr = &p->ptr; \ type *data = &p->data; \ M_CALL_INIT( oplist, *data); \ ptr->data = data; \ @@ -243,14 +243,14 @@ static inline int m_shar3d_integer_cref(int *p) { return *p; } , /* No INIT */ ) \ \ static inline bool \ - M_C(name, _NULL_p)(const shared_t shared) \ + M_F(name, _NULL_p)(const shared_t shared) \ { \ M_SHAR3D_CONTRACT(shared, cpt_oplist); \ return *shared == NULL; \ } \ \ static inline void \ - M_C(name, _init_set)(shared_t dest, \ + M_F(name, _init_set)(shared_t dest, \ const shared_t shared) \ { \ M_SHAR3D_CONTRACT(shared, cpt_oplist); \ @@ -264,7 +264,7 @@ static inline int m_shar3d_integer_cref(int *p) { return *p; } } \ \ static inline void \ - M_C(name, _clear)(shared_t dest) \ + M_F(name, _clear)(shared_t dest) \ { \ M_SHAR3D_CONTRACT(dest, cpt_oplist); \ if (*dest != NULL) { \ @@ -285,24 +285,24 @@ static inline int m_shar3d_integer_cref(int *p) { return *p; } } \ \ static inline void \ - M_C(name, _reset)(shared_t dest) \ + M_F(name, _reset)(shared_t dest) \ { \ /* NOTE: Clear will also set dest to NULL */ \ - M_C(name, _clear)(dest); \ + M_F(name, _clear)(dest); \ } \ \ static inline void \ - M_C(name, _set)(shared_t dest, \ + M_F(name, _set)(shared_t dest, \ const shared_t shared) \ { \ M_SHAR3D_CONTRACT(dest, cpt_oplist); \ M_SHAR3D_CONTRACT(shared, cpt_oplist); \ - M_C(name, _clear)(dest); \ - M_C(name, _init_set)(dest, shared); \ + M_F(name, _clear)(dest); \ + M_F(name, _init_set)(dest, shared); \ } \ \ static inline void \ - M_C(name, _init_move)(shared_t dest, \ + M_F(name, _init_move)(shared_t dest, \ shared_t shared) \ { \ M_SHAR3D_CONTRACT(shared, cpt_oplist); \ @@ -313,30 +313,30 @@ static inline int m_shar3d_integer_cref(int *p) { return *p; } } \ \ static inline void \ - M_C(name, _move)(shared_t dest, \ + M_F(name, _move)(shared_t dest, \ shared_t shared) \ { \ M_SHAR3D_CONTRACT(dest, cpt_oplist); \ M_SHAR3D_CONTRACT(shared, cpt_oplist); \ M_ASSERT (dest != shared); \ - M_C(name, _clear)(dest); \ - M_C(name, _init_move)(dest, shared); \ + M_F(name, _clear)(dest); \ + M_F(name, _init_move)(dest, shared); \ } \ \ static inline void \ - M_C(name, _swap)(shared_t p1, \ + M_F(name, _swap)(shared_t p1, \ shared_t p2) \ { \ M_SHAR3D_CONTRACT(p1, cpt_oplist); \ M_SHAR3D_CONTRACT(p2, cpt_oplist); \ /* NOTE: SWAP is not atomic */ \ - M_SWAP (struct M_C(name, _s)*, *p1, *p2); \ + M_SWAP (struct M_F(name, _s)*, *p1, *p2); \ M_SHAR3D_CONTRACT(p1, cpt_oplist); \ M_SHAR3D_CONTRACT(p2, cpt_oplist); \ } \ \ static inline bool \ - M_C(name, _equal_p)(const shared_t p1, \ + M_F(name, _equal_p)(const shared_t p1, \ const shared_t p2) \ { \ M_SHAR3D_CONTRACT(p1, cpt_oplist); \ @@ -345,7 +345,7 @@ static inline int m_shar3d_integer_cref(int *p) { return *p; } } \ \ static inline type const * \ - M_C(name, _cref)(const shared_t shared) \ + M_F(name, _cref)(const shared_t shared) \ { \ M_SHAR3D_CONTRACT(shared, cpt_oplist); \ M_ASSERT(*shared != NULL); \ @@ -355,7 +355,7 @@ static inline int m_shar3d_integer_cref(int *p) { return *p; } } \ \ static inline type * \ - M_C(name, _ref)(shared_t shared) \ + M_F(name, _ref)(shared_t shared) \ { \ M_SHAR3D_CONTRACT(shared, cpt_oplist); \ M_ASSERT(*shared != NULL); \ @@ -392,35 +392,35 @@ static inline int m_shar3d_integer_cref(int *p) { return *p; } #define M_SHAR3D_RESOURCE_DEF_TYPE(name, type, oplist, shared_t, it_t) \ \ /* Create an aligned type to avoid false sharing between threads */ \ - typedef struct M_C(name, _atype_s) { \ + typedef struct M_F(name, _atype_s) { \ atomic_uint cpt; \ type x; \ M_CACHELINE_ALIGN(align, type, atomic_uint); \ - } M_C(name, _atype_ct); \ + } M_F(name, _atype_ct); \ \ - typedef struct M_C(name, _s) { \ + typedef struct M_F(name, _s) { \ m_genint_t core; \ - M_C(name, _atype_ct) *buffer; \ + M_F(name, _atype_ct) *buffer; \ } shared_t[1]; \ \ - typedef struct M_C(name, _it_s) { \ + typedef struct M_F(name, _it_s) { \ unsigned int idx; \ - struct M_C(name, _s) *ref; \ + struct M_F(name, _s) *ref; \ } it_t[1]; \ \ /* Internal Types for oplist */ \ - typedef shared_t M_C(name, _ct); \ + typedef shared_t M_F(name, _ct); \ /* Define the core functions */ #define M_SHAR3D_RESOURCE_DEF_CORE(name, type, oplist, shared_t, it_t) \ static inline void \ - M_C(name, _init)(shared_t s, size_t n) \ + M_F(name, _init)(shared_t s, size_t n) \ { \ M_ASSERT(s != NULL); \ 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_F(name, _atype_ct), NULL, n); \ if (M_UNLIKELY_NOMEM (s->buffer == NULL)) { \ - M_MEMORY_FULL(sizeof(M_C(name, _atype_ct)) * n); \ + M_MEMORY_FULL(sizeof(M_F(name, _atype_ct)) * n); \ return; \ } \ for(size_t i = 0; i < n; i++) { \ @@ -432,7 +432,7 @@ static inline int m_shar3d_integer_cref(int *p) { return *p; } } \ \ static inline void \ - M_C(name, _clear)(shared_t s) \ + M_F(name, _clear)(shared_t s) \ { \ M_SHAR3D_RESOURCE_CONTRACT(s); \ size_t n = m_genint_size(s->core); \ @@ -445,7 +445,7 @@ static inline int m_shar3d_integer_cref(int *p) { return *p; } } \ \ static inline void \ - M_C(name, _it)(it_t it, shared_t s) \ + M_F(name, _it)(it_t it, shared_t s) \ { \ M_SHAR3D_RESOURCE_CONTRACT(s); \ M_ASSERT (it != NULL); \ @@ -459,14 +459,14 @@ static inline int m_shar3d_integer_cref(int *p) { return *p; } } \ \ static inline bool \ - M_C(name, _end_p)(it_t it) \ + M_F(name, _end_p)(it_t it) \ { \ M_ASSERT (it != NULL); \ return it->idx == M_GENINT_ERROR; \ } \ \ static inline type * \ - M_C(name, _ref)(it_t it) \ + M_F(name, _ref)(it_t it) \ { \ M_ASSERT (it != NULL && it->ref != NULL && it->idx != M_GENINT_ERROR); \ M_SHAR3D_RESOURCE_CONTRACT(it->ref); \ @@ -474,7 +474,7 @@ static inline int m_shar3d_integer_cref(int *p) { return *p; } } \ \ static inline type const * \ - M_C(name, _cref)(it_t it) \ + M_F(name, _cref)(it_t it) \ { \ M_ASSERT (it != NULL && it->ref != NULL && it->idx != M_GENINT_ERROR); \ M_SHAR3D_RESOURCE_CONTRACT(it->ref); \ @@ -482,7 +482,7 @@ static inline int m_shar3d_integer_cref(int *p) { return *p; } } \ \ static inline void \ - M_C(name, _end)(it_t it, shared_t s) \ + M_F(name, _end)(it_t it, shared_t s) \ { \ M_SHAR3D_RESOURCE_CONTRACT(s); \ M_ASSERT (it != NULL); \ @@ -498,7 +498,7 @@ static inline int m_shar3d_integer_cref(int *p) { return *p; } } \ \ static inline void \ - M_C(name, _it_set)(it_t itd, it_t its) \ + M_F(name, _it_set)(it_t itd, it_t its) \ { \ M_ASSERT (itd != NULL && its != NULL); \ M_SHAR3D_RESOURCE_CONTRACT(its->ref); \ diff --git a/m-snapshot.h b/m-snapshot.h index 8aba859a..4e92a51c 100644 --- a/m-snapshot.h +++ b/m-snapshot.h @@ -34,7 +34,7 @@ M_BEGIN_PROTECTED_CODE /* Define a Single Producer Single Consummer snapshot and its functions USAGE: SNAPSHOT_SPSC_DEF(name, type[, oplist]) */ #define M_SNAPSHOT_SPSC_DEF(name, ...) \ - M_SNAPSHOT_SPSC_DEF_AS(name, M_C(name,_t), __VA_ARGS__) + M_SNAPSHOT_SPSC_DEF_AS(name, M_F(name,_t), __VA_ARGS__) /* Define a Single Producer Single Consummer snapshot and its functions @@ -51,7 +51,7 @@ M_BEGIN_PROTECTED_CODE /* Define a Single Producer Multiple Consummer snapshot and its functions USAGE: SNAPSHOT_SPMC_DEF(name, type[, oplist]) */ #define M_SNAPSHOT_SPMC_DEF(name, ...) \ - M_SNAPSHOT_SPMC_DEF_AS(name, M_C(name,_t), __VA_ARGS__) + M_SNAPSHOT_SPMC_DEF_AS(name, M_F(name,_t), __VA_ARGS__) /* Define a Single Producer Multiple Consummer snapshot and its functions @@ -68,7 +68,7 @@ M_BEGIN_PROTECTED_CODE /* Define a Multiple Producer Multiple Consummer snapshot and its functions USAGE: SNAPSHOT_MPMC_DEF(name, type[, oplist]) */ #define M_SNAPSHOT_MPMC_DEF(name, ...) \ - M_SNAPSHOT_MPMC_DEF_AS(name, M_C(name,_t), __VA_ARGS__) + M_SNAPSHOT_MPMC_DEF_AS(name, M_F(name,_t), __VA_ARGS__) /* Define a Multiple Producer Multiple Consummer snapshot and its functions @@ -107,16 +107,16 @@ M_BEGIN_PROTECTED_CODE /* Define the oplist of a snapshot */ #define M_SNAPSH0T_OPLIST_P3(name, oplist) \ - (INIT(M_C(name, _init)) \ - ,INIT_SET(M_C(name, _init_set)) \ - ,SET(M_C(name, _set)) \ - ,CLEAR(M_C(name, _clear)) \ + (INIT(M_F(name, _init)) \ + ,INIT_SET(M_F(name, _init_set)) \ + ,SET(M_F(name, _set)) \ + ,CLEAR(M_F(name, _clear)) \ ,NAME(name) \ - ,TYPE(M_C(name, _ct)) \ - ,SUBTYPE(M_C(name, _subtype_ct)) \ + ,TYPE(M_F(name, _ct)) \ + ,SUBTYPE(M_F(name, _subtype_ct)) \ ,OPLIST(oplist) \ - ,M_IF_METHOD(INIT_MOVE, oplist)(INIT_MOVE(M_C(name, _init_move)),) \ - ,M_IF_METHOD(MOVE, oplist)(MOVE(M_C(name, _move)),) \ + ,M_IF_METHOD(INIT_MOVE, oplist)(INIT_MOVE(M_F(name, _init_move)),) \ + ,M_IF_METHOD(MOVE, oplist)(MOVE(M_F(name, _move)),) \ ) @@ -178,27 +178,27 @@ M_BEGIN_PROTECTED_CODE #define M_SNAPSH0T_SPSC_DEF_TYPE(name, type, oplist, snapshot_t) \ \ /* Create an aligned type to avoid false sharing between threads */ \ - typedef struct M_C(name, _aligned_type_s) { \ + typedef struct M_F(name, _aligned_type_s) { \ type x; \ M_CACHELINE_ALIGN(align, type); \ - } M_C(name, _aligned_type_ct); \ + } M_F(name, _aligned_type_ct); \ \ - typedef struct M_C(name, _s) { \ - M_C(name, _aligned_type_ct) data[M_SNAPSH0T_SPSC_MAX_BUFFER]; \ + typedef struct M_F(name, _s) { \ + M_F(name, _aligned_type_ct) data[M_SNAPSH0T_SPSC_MAX_BUFFER]; \ atomic_uchar flags; \ } snapshot_t[1]; \ - typedef struct M_C(name, _s) *M_C(name, _ptr); \ - typedef const struct M_C(name, _s) *M_C(name, _srcptr); \ + typedef struct M_F(name, _s) *M_F(name, _ptr); \ + typedef const struct M_F(name, _s) *M_F(name, _srcptr); \ \ /* Define internal types for oplist */ \ - typedef snapshot_t M_C(name, _ct); \ - typedef type M_C(name, _subtype_ct); \ + typedef snapshot_t M_F(name, _ct); \ + typedef type M_F(name, _subtype_ct); \ /* Define the core functions */ #define M_SNAPSH0T_SPSC_DEF_CORE(name, type, oplist, snapshot_t) \ \ static inline void \ - M_C(name, _init)(snapshot_t snap) \ + M_F(name, _init)(snapshot_t snap) \ { \ M_ASSERT(snap != NULL); \ for(int i = 0; i < M_SNAPSH0T_SPSC_MAX_BUFFER; i++) { \ @@ -209,7 +209,7 @@ M_BEGIN_PROTECTED_CODE } \ \ static inline void \ - M_C(name, _clear)(snapshot_t snap) \ + M_F(name, _clear)(snapshot_t snap) \ { \ M_SNAPSH0T_SPSC_CONTRACT(snap); \ for(int i = 0; i < M_SNAPSH0T_SPSC_MAX_BUFFER; i++) { \ @@ -219,7 +219,7 @@ M_BEGIN_PROTECTED_CODE \ /* const is missing for org due to use of atomic_load of org */ \ static inline void \ - M_C(name, _init_set)(snapshot_t snap, snapshot_t org) \ + M_F(name, _init_set)(snapshot_t snap, snapshot_t org) \ { \ M_SNAPSH0T_SPSC_CONTRACT(org); \ M_ASSERT(snap != NULL && snap != org); \ @@ -232,7 +232,7 @@ M_BEGIN_PROTECTED_CODE \ /* const is missing for org due to use of atomic_load of org */ \ static inline void \ - M_C(name, _set)(snapshot_t snap, snapshot_t org) \ + M_F(name, _set)(snapshot_t snap, snapshot_t org) \ { \ M_SNAPSH0T_SPSC_CONTRACT(snap); \ M_SNAPSH0T_SPSC_CONTRACT(org); \ @@ -245,7 +245,7 @@ M_BEGIN_PROTECTED_CODE \ M_IF_METHOD(INIT_MOVE, oplist)( \ static inline void \ - M_C(name, _init_move)(snapshot_t snap, snapshot_t org) \ + M_F(name, _init_move)(snapshot_t snap, snapshot_t org) \ { \ M_SNAPSH0T_SPSC_CONTRACT(org); \ M_ASSERT(snap != NULL && snap != org); \ @@ -260,7 +260,7 @@ M_BEGIN_PROTECTED_CODE \ M_IF_METHOD(MOVE, oplist)( \ static inline void \ - M_C(name, _move)(snapshot_t snap, \ + M_F(name, _move)(snapshot_t snap, \ snapshot_t org) \ { \ M_SNAPSH0T_SPSC_CONTRACT(snap); \ @@ -276,7 +276,7 @@ M_BEGIN_PROTECTED_CODE ,) /* IF_METHOD (MOVE) */ \ \ static inline type * \ - M_C(name, _write)(snapshot_t snap) \ + M_F(name, _write)(snapshot_t snap) \ { \ M_SNAPSH0T_SPSC_CONTRACT(snap); \ unsigned char nextFlags, origFlags = atomic_load (&snap->flags); \ @@ -295,7 +295,7 @@ M_BEGIN_PROTECTED_CODE } \ \ static inline type const * \ - M_C(name, _read)(snapshot_t snap) \ + M_F(name, _read)(snapshot_t snap) \ { \ M_SNAPSH0T_SPSC_CONTRACT(snap); \ unsigned char nextFlags, origFlags = atomic_load (&snap->flags); \ @@ -320,7 +320,7 @@ M_BEGIN_PROTECTED_CODE \ /* Non const due to use of atomic_load */ \ static inline bool \ - M_C(name, _updated_p)(snapshot_t snap) \ + M_F(name, _updated_p)(snapshot_t snap) \ { \ M_SNAPSH0T_SPSC_CONTRACT(snap); \ unsigned char flags = atomic_load (&snap->flags); \ @@ -329,7 +329,7 @@ M_BEGIN_PROTECTED_CODE \ /* Non const due to use of atomic_load */ \ static inline type * \ - M_C(name, _get_write_buffer)(snapshot_t snap) \ + M_F(name, _get_write_buffer)(snapshot_t snap) \ { \ M_SNAPSH0T_SPSC_CONTRACT(snap); \ unsigned char flags = atomic_load(&snap->flags); \ @@ -338,7 +338,7 @@ M_BEGIN_PROTECTED_CODE \ /* Non const due to use of atomic_load */ \ static inline type const * \ - M_C(name, _get_read_buffer)(snapshot_t snap) \ + M_F(name, _get_read_buffer)(snapshot_t snap) \ { \ M_SNAPSH0T_SPSC_CONTRACT(snap); \ unsigned char flags = atomic_load(&snap->flags); \ @@ -622,32 +622,32 @@ m_snapsh0t_mrsw_read_end(m_snapsh0t_mrsw_ct s, unsigned int idx) #define M_SNAPSH0T_SPMC_DEF_TYPE(name, type, oplist, snapshot_t) \ \ /* Create an aligned type to avoid false sharing between threads */ \ - typedef struct M_C(name, _aligned_type_s) { \ + typedef struct M_F(name, _aligned_type_s) { \ type x; \ M_CACHELINE_ALIGN(align, type); \ - } M_C(name, _aligned_type_ct); \ + } M_F(name, _aligned_type_ct); \ \ - typedef struct M_C(name, _s) { \ - M_C(name, _aligned_type_ct) *data; \ + typedef struct M_F(name, _s) { \ + M_F(name, _aligned_type_ct) *data; \ m_snapsh0t_mrsw_ct core; \ } snapshot_t[1]; \ \ /* Define internal types for oplist */ \ - typedef snapshot_t M_C(name, _ct); \ - typedef type M_C(name, _subtype_ct); \ + typedef snapshot_t M_F(name, _ct); \ + typedef type M_F(name, _subtype_ct); \ /* Define the core functions */ #define M_SNAPSH0T_SPMC_DEF_CORE(name, type, oplist, snapshot_t) \ \ static inline void \ - M_C(name, _init)(snapshot_t snap, size_t nReader) \ + M_F(name, _init)(snapshot_t snap, size_t nReader) \ { \ M_ASSERT (snap != NULL); \ M_ASSERT (nReader > 0 && nReader <= M_SNAPSH0T_SPMC_MAX_READER); \ - snap->data = M_CALL_REALLOC(oplist, M_C(name, _aligned_type_ct), \ + snap->data = M_CALL_REALLOC(oplist, M_F(name, _aligned_type_ct), \ NULL, nReader+M_SNAPSH0T_SPMC_EXTRA_BUFFER); \ if (M_UNLIKELY_NOMEM (snap->data == NULL)) { \ - M_MEMORY_FULL(sizeof(M_C(name, _aligned_type_ct)) * \ + M_MEMORY_FULL(sizeof(M_F(name, _aligned_type_ct)) * \ (nReader+M_SNAPSH0T_SPMC_EXTRA_BUFFER)); \ return; \ } \ @@ -659,7 +659,7 @@ m_snapsh0t_mrsw_read_end(m_snapsh0t_mrsw_ct s, unsigned int idx) } \ \ static inline void \ - M_C(name, _clear)(snapshot_t snap) \ + M_F(name, _clear)(snapshot_t snap) \ { \ M_SNAPSH0T_SPMC_CONTRACT(snap); \ size_t nReader = m_snapsh0t_mrsw_size(snap->core); \ @@ -671,7 +671,7 @@ m_snapsh0t_mrsw_read_end(m_snapsh0t_mrsw_ct s, unsigned int idx) } \ \ static inline type * \ - M_C(name, _write)(snapshot_t snap) \ + M_F(name, _write)(snapshot_t snap) \ { \ M_SNAPSH0T_SPMC_CONTRACT(snap); \ const unsigned int idx = m_snapsh0t_mrsw_write(snap->core); \ @@ -679,7 +679,7 @@ m_snapsh0t_mrsw_read_end(m_snapsh0t_mrsw_ct s, unsigned int idx) } \ \ static inline type const * \ - M_C(name, _read_start)(snapshot_t snap) \ + M_F(name, _read_start)(snapshot_t snap) \ { \ M_SNAPSH0T_SPMC_CONTRACT(snap); \ const unsigned int idx = m_snapsh0t_mrsw_read_start(snap->core); \ @@ -687,12 +687,12 @@ m_snapsh0t_mrsw_read_end(m_snapsh0t_mrsw_ct s, unsigned int idx) } \ \ static inline void \ - M_C(name, _read_end)(snapshot_t snap, type const *old) \ + M_F(name, _read_end)(snapshot_t snap, type const *old) \ { \ M_SNAPSH0T_SPMC_CONTRACT(snap); \ M_ASSERT (old != NULL); \ - const M_C(name, _aligned_type_ct) *oldx; \ - oldx = M_CTYPE_FROM_FIELD(M_C(name, _aligned_type_ct), old, type, x); \ + const M_F(name, _aligned_type_ct) *oldx; \ + oldx = M_CTYPE_FROM_FIELD(M_F(name, _aligned_type_ct), old, type, x); \ M_ASSERT (oldx >= snap->data); \ M_ASSERT (oldx < snap->data + snap->core->n_reader + M_SNAPSH0T_SPMC_EXTRA_BUFFER); \ M_ASSERT(snap->core->n_reader +M_SNAPSH0T_SPMC_EXTRA_BUFFER < UINT_MAX); \ @@ -701,7 +701,7 @@ m_snapsh0t_mrsw_read_end(m_snapsh0t_mrsw_ct s, unsigned int idx) } \ \ static inline type * \ - M_C(name, _get_write_buffer)(snapshot_t snap) \ + M_F(name, _get_write_buffer)(snapshot_t snap) \ { \ M_SNAPSH0T_SPMC_CONTRACT(snap); \ const unsigned int idx = m_snapsh0t_mrsw_get_write_idx(snap->core); \ @@ -727,7 +727,7 @@ m_snapsh0t_mrsw_read_end(m_snapsh0t_mrsw_ct s, unsigned int idx) /* Expand the type and the functions of a MPMC snapshot */ #define M_SNAPSH0T_MPMC_DEF_P3(name, type, oplist, snapshot_t) \ - M_SNAPSH0T_SPMC_DEF_P1((M_C(name, _mrsw), type, oplist, M_C(name, _mrsw_pct))) \ + M_SNAPSH0T_SPMC_DEF_P1((M_F(name, _mrsw), type, oplist, M_F(name, _mrsw_pct))) \ M_SNAPSH0T_MPMC_DEF_TYPE(name, type, oplist, snapshot_t) \ M_CHECK_COMPATIBLE_OPLIST(name, 1, type, oplist) \ M_SNAPSH0T_MPMC_DEF_CORE(name, type, oplist, snapshot_t) \ @@ -735,34 +735,34 @@ m_snapsh0t_mrsw_read_end(m_snapsh0t_mrsw_ct s, unsigned int idx) /* Define the types */ #define M_SNAPSH0T_MPMC_DEF_TYPE(name, type, oplist, snapshot_t) \ \ - typedef struct M_C(name, _s) { \ - M_C(name, _mrsw_pct) core; \ + typedef struct M_F(name, _s) { \ + M_F(name, _mrsw_pct) core; \ } snapshot_t[1]; \ \ /* Define internal types for oplist */ \ - typedef snapshot_t M_C(name, _ct); \ - typedef type M_C(name, _subtype_ct); \ + typedef snapshot_t M_F(name, _ct); \ + typedef type M_F(name, _subtype_ct); \ /* Define the core functions */ #define M_SNAPSH0T_MPMC_DEF_CORE(name, type, oplist, snapshot_t) \ \ static inline void \ - M_C(name, _init)(snapshot_t snap, size_t nReader, size_t nWriter) \ + M_F(name, _init)(snapshot_t snap, size_t nReader, size_t nWriter) \ { \ - M_C(name, _mrsw_init)(snap->core, nReader + nWriter -1 ); \ + M_F(name, _mrsw_init)(snap->core, nReader + nWriter -1 ); \ unsigned int idx = snap->core->core->currentWrite; \ snap->core->core->currentWrite = M_GENINT_ERROR; \ m_snapsh0t_mrsw_write_end(snap->core->core, idx); \ } \ \ static inline void \ - M_C(name, _clear)(snapshot_t snap) \ + M_F(name, _clear)(snapshot_t snap) \ { \ - M_C(name, _mrsw_clear)(snap->core); \ + M_F(name, _mrsw_clear)(snap->core); \ } \ \ static inline type * \ - M_C(name, _write_start)(snapshot_t snap) \ + M_F(name, _write_start)(snapshot_t snap) \ { \ M_SNAPSH0T_SPMC_CONTRACT(snap->core); \ const unsigned int idx = m_snapsh0t_mrsw_write_start(snap->core->core); \ @@ -770,11 +770,11 @@ m_snapsh0t_mrsw_read_end(m_snapsh0t_mrsw_ct s, unsigned int idx) } \ \ static inline void \ - M_C(name, _write_end)(snapshot_t snap, type *old) \ + M_F(name, _write_end)(snapshot_t snap, type *old) \ { \ M_SNAPSH0T_SPMC_CONTRACT(snap->core); \ - const M_C(name, _mrsw_aligned_type_ct) *oldx; \ - oldx = M_CTYPE_FROM_FIELD(M_C(name, _mrsw_aligned_type_ct), old, type, x); \ + const M_F(name, _mrsw_aligned_type_ct) *oldx; \ + oldx = M_CTYPE_FROM_FIELD(M_F(name, _mrsw_aligned_type_ct), old, type, x); \ M_ASSERT (oldx >= snap->core->data); \ M_ASSERT (oldx < snap->core->data + snap->core->core->n_reader + M_SNAPSH0T_SPMC_EXTRA_BUFFER); \ M_ASSERT(snap->core->core->n_reader + M_SNAPSH0T_SPMC_EXTRA_BUFFER < UINT_MAX); \ @@ -783,15 +783,15 @@ m_snapsh0t_mrsw_read_end(m_snapsh0t_mrsw_ct s, unsigned int idx) } \ \ static inline type const * \ - M_C(name, _read_start)(snapshot_t snap) \ + M_F(name, _read_start)(snapshot_t snap) \ { \ - return M_C(name, _mrsw_read_start)(snap->core); \ + return M_F(name, _mrsw_read_start)(snap->core); \ } \ \ static inline void \ - M_C(name, _read_end)(snapshot_t snap, type const *old) \ + M_F(name, _read_end)(snapshot_t snap, type const *old) \ { \ - M_C(name, _mrsw_read_end)(snap->core, old); \ + M_F(name, _mrsw_read_end)(snap->core, old); \ } \ \ diff --git a/m-string.h b/m-string.h index 26323422..1d8a5a98 100644 --- a/m-string.h +++ b/m-string.h @@ -1882,7 +1882,7 @@ m_string_utf8_p(m_string_t str) /* Define the split & the join functions in case of usage with the algorithm module */ #define M_STR1NG_SPLIT(name, oplist, type_oplist) \ - static inline void M_C(name, _split)(M_GET_TYPE oplist cont, \ + static inline void M_F(name, _split)(M_GET_TYPE oplist cont, \ const m_string_t str, const char sep) \ { \ size_t begin = 0; \ @@ -1912,7 +1912,7 @@ m_string_utf8_p(m_string_t str) m_string_clear(tmp); \ } \ \ - static inline void M_C(name, _join)(m_string_t dst, M_GET_TYPE oplist cont, \ + static inline void M_F(name, _join)(m_string_t dst, M_GET_TYPE oplist cont, \ const m_string_t str) \ { \ bool init_done = false; \ @@ -2163,29 +2163,29 @@ namespace m_lib { */ #define M_BOUNDED_STRING_DEF(name, max_size) \ M_BEGIN_PROTECTED_CODE \ - M_BOUNDED_STR1NG_DEF_P2(name, max_size, M_C(name, _t) ) \ + M_BOUNDED_STR1NG_DEF_P2(name, max_size, M_F(name, _t) ) \ M_END_PROTECTED_CODE /* Define the OPLIST of a BOUNDED_STRING */ #define M_BOUNDED_STRING_OPLIST(name) \ - (INIT(M_C(name,_init)), \ - INIT_SET(M_C(name,_init_set)), \ - SET(M_C(name,_set)), \ - CLEAR(M_C(name,_clear)), \ + (INIT(M_F(name,_init)), \ + INIT_SET(M_F(name,_init_set)), \ + SET(M_F(name,_set)), \ + CLEAR(M_F(name,_clear)), \ NAME(name), \ INIT_WITH( API_1(M_BOUNDED_STR1NG_INIT_WITH)), \ - HASH(M_C(name,_hash)), \ - EQUAL(M_C(name,_equal_p)), \ - CMP(M_C(name,_cmp)), \ - TYPE(M_C(name,_ct)), \ - OOR_EQUAL(M_C(name,_oor_equal_p)), \ - OOR_SET(M_C(name, _oor_set)), \ - PARSE_STR(M_C(name,_parse_str)), \ - GET_STR(M_C(name,_get_str)), \ - OUT_STR(M_C(name,_out_str)), \ - IN_STR(M_C(name,_in_str)), \ - OUT_SERIAL(M_C(name,_out_serial)), \ - IN_SERIAL(M_C(name,_in_serial)), \ + HASH(M_F(name,_hash)), \ + EQUAL(M_F(name,_equal_p)), \ + CMP(M_F(name,_cmp)), \ + TYPE(M_F(name,_ct)), \ + OOR_EQUAL(M_F(name,_oor_equal_p)), \ + OOR_SET(M_F(name, _oor_set)), \ + PARSE_STR(M_F(name,_parse_str)), \ + GET_STR(M_F(name,_get_str)), \ + OUT_STR(M_F(name,_out_str)), \ + IN_STR(M_F(name,_in_str)), \ + OUT_SERIAL(M_F(name,_out_serial)), \ + IN_SERIAL(M_F(name,_in_serial)), \ ) /************************** INTERNAL ***********************************/ @@ -2201,17 +2201,17 @@ namespace m_lib { #define M_BOUNDED_STR1NG_DEF_P2(name, max_size, bounded_t) \ \ /* Define of an array with one more to store the final nul char */ \ - typedef char M_C(name, _array_t)[max_size+1]; \ + typedef char M_F(name, _array_t)[max_size+1]; \ \ - typedef struct M_C(name, _s) { \ + typedef struct M_F(name, _s) { \ char s[max_size+1]; \ } bounded_t[1]; \ \ /* Internal types for oplist */ \ - typedef bounded_t M_C(name, _ct); \ + typedef bounded_t M_F(name, _ct); \ \ static inline void \ - M_C(name, _init)(bounded_t s) \ + M_F(name, _init)(bounded_t s) \ { \ M_ASSERT(s != NULL); \ M_STATIC_ASSERT(max_size >= 1, M_LIB_INTERNAL, "M*LIB: max_size parameter shall be greater than 0."); \ @@ -2221,7 +2221,7 @@ namespace m_lib { } \ \ static inline void \ - M_C(name, _clear)(bounded_t s) \ + M_F(name, _clear)(bounded_t s) \ { \ M_BOUNDED_STR1NG_CONTRACT(s, max_size); \ /* Make the object illegal to be able to detect use after free */ \ @@ -2229,7 +2229,7 @@ namespace m_lib { } \ \ static inline void \ - M_C(name, _reset)(bounded_t s) \ + M_F(name, _reset)(bounded_t s) \ { \ M_BOUNDED_STR1NG_CONTRACT(s, max_size); \ s->s[0] = 0; \ @@ -2237,14 +2237,14 @@ namespace m_lib { } \ \ static inline size_t \ - M_C(name, _size)(const bounded_t s) \ + M_F(name, _size)(const bounded_t s) \ { \ M_BOUNDED_STR1NG_CONTRACT(s, max_size); \ return strlen(s->s); \ } \ \ static inline size_t \ - M_C(name, _capacity)(const bounded_t s) \ + M_F(name, _capacity)(const bounded_t s) \ { \ M_BOUNDED_STR1NG_CONTRACT(s, max_size); \ (void)s; /* unused */ \ @@ -2252,7 +2252,7 @@ namespace m_lib { } \ \ static inline char \ - M_C(name, _get_char)(const bounded_t s, size_t index) \ + M_F(name, _get_char)(const bounded_t s, size_t index) \ { \ M_BOUNDED_STR1NG_CONTRACT(s, max_size); \ M_ASSERT_INDEX(index, max_size); \ @@ -2260,14 +2260,14 @@ namespace m_lib { } \ \ static inline bool \ - M_C(name, _empty_p)(const bounded_t s) \ + M_F(name, _empty_p)(const bounded_t s) \ { \ M_BOUNDED_STR1NG_CONTRACT(s, max_size); \ return s->s[0] == 0; \ } \ \ static inline void \ - M_C(name, _set_cstr)(bounded_t s, const char str[]) \ + M_F(name, _set_cstr)(bounded_t s, const char str[]) \ { \ M_BOUNDED_STR1NG_CONTRACT(s, max_size); \ m_core_strncpy(s->s, max_size+1, str, max_size); \ @@ -2276,7 +2276,7 @@ namespace m_lib { } \ \ static inline void \ - M_C(name, _set_cstrn)(bounded_t s, const char str[], size_t n) \ + M_F(name, _set_cstrn)(bounded_t s, const char str[], size_t n) \ { \ M_BOUNDED_STR1NG_CONTRACT(s, max_size); \ M_ASSERT(str != NULL); \ @@ -2287,46 +2287,46 @@ namespace m_lib { } \ \ static inline const char * \ - M_C(name, _get_cstr)(const bounded_t s) \ + M_F(name, _get_cstr)(const bounded_t s) \ { \ M_BOUNDED_STR1NG_CONTRACT(s, max_size); \ return s->s; \ } \ \ static inline void \ - M_C(name, _set)(bounded_t s, const bounded_t str) \ + M_F(name, _set)(bounded_t s, const bounded_t str) \ { \ M_BOUNDED_STR1NG_CONTRACT(s, max_size); \ M_BOUNDED_STR1NG_CONTRACT(str, max_size); \ - M_C(name, _set_cstr)(s, str->s); \ + M_F(name, _set_cstr)(s, str->s); \ } \ \ static inline void \ - M_C(name, _set_n)(bounded_t s, const bounded_t str, \ + M_F(name, _set_n)(bounded_t s, const bounded_t str, \ size_t offset, size_t length) \ { \ M_BOUNDED_STR1NG_CONTRACT(s, max_size); \ M_BOUNDED_STR1NG_CONTRACT(str, max_size); \ M_ASSERT_INDEX (offset, max_size+1); \ - M_C(name, _set_cstrn)(s, str->s+offset, length); \ + M_F(name, _set_cstrn)(s, str->s+offset, length); \ } \ \ static inline void \ - M_C(name, _init_set)(bounded_t s, const bounded_t str) \ + M_F(name, _init_set)(bounded_t s, const bounded_t str) \ { \ - M_C(name,_init)(s); \ - M_C(name,_set)(s, str); \ + M_F(name,_init)(s); \ + M_F(name,_set)(s, str); \ } \ \ static inline void \ - M_C(name, _init_set_cstr)(bounded_t s, const char str[]) \ + M_F(name, _init_set_cstr)(bounded_t s, const char str[]) \ { \ - M_C(name,_init)(s); \ - M_C(name,_set_cstr)(s, str); \ + M_F(name,_init)(s); \ + M_F(name,_set_cstr)(s, str); \ } \ \ static inline void \ - M_C(name, _cat_cstr)(bounded_t s, const char str[]) \ + M_F(name, _cat_cstr)(bounded_t s, const char str[]) \ { \ M_BOUNDED_STR1NG_CONTRACT(s, max_size); \ M_ASSERT (str != NULL); \ @@ -2335,14 +2335,14 @@ namespace m_lib { } \ \ static inline void \ - M_C(name, _cat)(bounded_t s, const bounded_t str) \ + M_F(name, _cat)(bounded_t s, const bounded_t str) \ { \ M_BOUNDED_STR1NG_CONTRACT(str, max_size); \ - M_C(name, _cat_cstr)(s, str->s); \ + M_F(name, _cat_cstr)(s, str->s); \ } \ \ static inline int \ - M_C(name, _cmp_cstr)(const bounded_t s, const char str[]) \ + M_F(name, _cmp_cstr)(const bounded_t s, const char str[]) \ { \ M_BOUNDED_STR1NG_CONTRACT(s, max_size); \ M_ASSERT(str != NULL); \ @@ -2350,7 +2350,7 @@ namespace m_lib { } \ \ static inline int \ - M_C(name, _cmp)(const bounded_t s, const bounded_t str) \ + M_F(name, _cmp)(const bounded_t s, const bounded_t str) \ { \ M_BOUNDED_STR1NG_CONTRACT(s, max_size); \ M_BOUNDED_STR1NG_CONTRACT(str, max_size); \ @@ -2358,7 +2358,7 @@ namespace m_lib { } \ \ static inline bool \ - M_C(name, _equal_cstr_p)(const bounded_t s, const char str[]) \ + M_F(name, _equal_cstr_p)(const bounded_t s, const char str[]) \ { \ M_BOUNDED_STR1NG_CONTRACT(s, max_size); \ M_ASSERT(str != NULL); \ @@ -2366,14 +2366,14 @@ namespace m_lib { } \ \ static inline bool \ - M_C(name, _equal_p)(const bounded_t s, const bounded_t str) \ + M_F(name, _equal_p)(const bounded_t s, const bounded_t str) \ { \ /* _equal_p may be called in context OOR. So contract cannot be verified */ \ return (s->s[max_size] == str->s[max_size]) & (strcmp(s->s, str->s) == 0); \ } \ \ static inline int \ - M_C(name, _printf)(bounded_t s, const char format[], ...) \ + M_F(name, _printf)(bounded_t s, const char format[], ...) \ { \ M_BOUNDED_STR1NG_CONTRACT(s, max_size); \ M_ASSERT(format != NULL); \ @@ -2386,7 +2386,7 @@ namespace m_lib { } \ \ static inline int \ - M_C(name, _cat_printf)(bounded_t s, const char format[], ...) \ + M_F(name, _cat_printf)(bounded_t s, const char format[], ...) \ { \ M_BOUNDED_STR1NG_CONTRACT(s, max_size); \ M_ASSERT(format != NULL); \ @@ -2401,7 +2401,7 @@ namespace m_lib { } \ \ static inline bool \ - M_C(name, _fgets)(bounded_t s, FILE *f, m_string_fgets_t arg) \ + M_F(name, _fgets)(bounded_t s, FILE *f, m_string_fgets_t arg) \ { \ M_BOUNDED_STR1NG_CONTRACT(s, max_size); \ M_ASSERT(f != NULL); \ @@ -2417,7 +2417,7 @@ namespace m_lib { } \ \ static inline bool \ - M_C(name, _fputs)(FILE *f, const bounded_t s) \ + M_F(name, _fputs)(FILE *f, const bounded_t s) \ { \ M_BOUNDED_STR1NG_CONTRACT(s, max_size); \ M_ASSERT(f != NULL); \ @@ -2425,7 +2425,7 @@ namespace m_lib { } \ \ static inline size_t \ - M_C(name, _hash)(const bounded_t s) \ + M_F(name, _hash)(const bounded_t s) \ { \ M_BOUNDED_STR1NG_CONTRACT(s, max_size); \ /* Cannot use m_core_hash: alignment not sufficent */ \ @@ -2433,7 +2433,7 @@ namespace m_lib { } \ \ static inline bool \ - M_C(name, _oor_equal_p)(const bounded_t s, unsigned char n) \ + M_F(name, _oor_equal_p)(const bounded_t s, unsigned char n) \ { \ /* s may be invalid contract */ \ M_ASSERT (s != NULL); \ @@ -2442,7 +2442,7 @@ namespace m_lib { } \ \ static inline void \ - M_C(name, _oor_set)(bounded_t s, unsigned char n) \ + M_F(name, _oor_set)(bounded_t s, unsigned char n) \ { \ /* s may be invalid contract */ \ M_ASSERT (s != NULL); \ @@ -2451,7 +2451,7 @@ namespace m_lib { } \ \ static inline void \ - M_C(name, _get_str)(m_string_t v, const bounded_t s, bool append) \ + M_F(name, _get_str)(m_string_t v, const bounded_t s, bool append) \ { \ M_STR1NG_CONTRACT(v); \ M_BOUNDED_STR1NG_CONTRACT(s, max_size); \ @@ -2465,7 +2465,7 @@ namespace m_lib { } \ \ static inline void \ - M_C(name, _out_str)(FILE *f, const bounded_t s) \ + M_F(name, _out_str)(FILE *f, const bounded_t s) \ { \ M_BOUNDED_STR1NG_CONTRACT(s, max_size); \ M_ASSERT(f != NULL); \ @@ -2479,7 +2479,7 @@ namespace m_lib { } \ \ static inline bool \ - M_C(name, _in_str)(bounded_t v, FILE *f) \ + M_F(name, _in_str)(bounded_t v, FILE *f) \ { \ M_BOUNDED_STR1NG_CONTRACT(v, max_size); \ M_ASSERT(f != NULL); \ @@ -2492,7 +2492,7 @@ namespace m_lib { } \ \ static inline bool \ - M_C(name, _parse_str)(bounded_t v, const char str[], const char **endptr) \ + M_F(name, _parse_str)(bounded_t v, const char str[], const char **endptr) \ { \ M_BOUNDED_STR1NG_CONTRACT(v, max_size); \ M_ASSERT(str != NULL); \ @@ -2505,7 +2505,7 @@ namespace m_lib { } \ \ static inline m_serial_return_code_t \ - M_C(name, _out_serial)(m_serial_write_t serial, const bounded_t v) \ + M_F(name, _out_serial)(m_serial_write_t serial, const bounded_t v) \ { \ M_BOUNDED_STR1NG_CONTRACT(v, max_size); \ M_ASSERT (serial != NULL && serial->m_interface != NULL); \ @@ -2513,7 +2513,7 @@ namespace m_lib { } \ \ static inline m_serial_return_code_t \ - M_C(name, _in_serial)(bounded_t v, m_serial_read_t serial) \ + M_F(name, _in_serial)(bounded_t v, m_serial_read_t serial) \ { \ M_BOUNDED_STR1NG_CONTRACT(v, max_size); \ M_ASSERT (serial != NULL && serial->m_interface != NULL); \ @@ -2535,7 +2535,7 @@ namespace m_lib { See above */ #ifndef __cplusplus #define M_BOUNDED_STRING_CTE(name, string) \ - ((const struct M_C(name, _s) *)((M_C(name, _array_t)){string})) + ((const struct M_F(name, _s) *)((M_F(name, _array_t)){string})) #else namespace m_lib { template @@ -2549,7 +2549,7 @@ namespace m_lib { }; } #define M_BOUNDED_STRING_CTE(name, string) \ - ((const struct M_C(name, _s) *)(m_lib::m_bounded_string(string).s)) + ((const struct M_F(name, _s) *)(m_lib::m_bounded_string(string).s)) #endif diff --git a/m-tree.h b/m-tree.h index f226ceda..5e0c5290 100644 --- a/m-tree.h +++ b/m-tree.h @@ -33,7 +33,7 @@ TREE_DEF(name, type_t[, type_oplist]) */ #define M_TREE_DEF(name, ...) \ - M_TREE_DEF_AS(name, M_C(name, _t), M_C(name, _it_t), __VA_ARGS__) + M_TREE_DEF_AS(name, M_F(name, _t), M_F(name, _it_t), __VA_ARGS__) /* Define a complete tree of 'type' as the given name name_t with its associated functions. @@ -159,13 +159,13 @@ typedef int32_t m_tr33_index_t; + 'right' is the right sibling or M_TR33_NO_NODE if there is none \ + 'data' if the data field of the node containing the given type \ */ \ - typedef struct M_C(name, _node_s) { \ + typedef struct M_F(name, _node_s) { \ m_tr33_index_t parent; \ m_tr33_index_t child; \ m_tr33_index_t left; \ m_tr33_index_t right; \ type data; \ - } M_C(name, _node_ct); \ + } M_F(name, _node_ct); \ \ /* Define a tree: \ + size is the number of nodes in the tree, \ @@ -175,13 +175,13 @@ typedef int32_t m_tr33_index_t; + allow_realloc is a bool encoded as true=0 and false=INT32_MAX \ + tab is a pointer to the allocated nodes. \ */ \ - typedef struct M_C(name, _s) { \ + typedef struct M_F(name, _s) { \ m_tr33_index_t size; \ m_tr33_index_t capacity; \ m_tr33_index_t root_index; \ m_tr33_index_t free_index; \ uint32_t allow_realloc; \ - M_C(name, _node_ct) *tab; \ + M_F(name, _node_ct) *tab; \ } tree_t[1]; \ \ /* Define an iterator that references a node. \ @@ -194,18 +194,18 @@ typedef int32_t m_tr33_index_t; NOTE: we don't define then using [1] as we want to pass then by value \ so that we can return iterator on the inserted elements. \ */ \ - typedef struct M_C(name, _it_s) { \ - struct M_C(name, _s) *tree; \ + typedef struct M_F(name, _it_s) { \ + struct M_F(name, _s) *tree; \ m_tr33_index_t index; \ } it_t; \ \ - typedef it_t M_C(name, _it_ct); + typedef it_t M_F(name, _it_ct); /* Define the core & unique methods of a tree */ #define M_TR33_DEF_P4_CORE(name, type, oplist, tree_t, it_t) \ /* Initialize a generic tree (empty) */ \ static inline void \ - M_C(name, _init)(tree_t tree) { \ + M_F(name, _init)(tree_t tree) { \ tree->size = 0; \ tree->capacity = 0; \ tree->root_index = M_TR33_NO_NODE; \ @@ -216,7 +216,7 @@ typedef int32_t m_tr33_index_t; } \ \ static inline void \ - M_C(name, _reset)(tree_t tree) { \ + M_F(name, _reset)(tree_t tree) { \ M_TR33_CONTRACT(tree); \ if (tree->size > 0) { \ /* We don't scan recursively the node tree, but sequentially */ \ @@ -242,9 +242,9 @@ typedef int32_t m_tr33_index_t; } \ \ static inline void \ - M_C(name, _clear)(tree_t tree) { \ - M_C(name, _reset)(tree); \ - struct M_C(name,_node_s)*ptr = tree->tab == NULL ? NULL : tree->tab-1;\ + M_F(name, _clear)(tree_t tree) { \ + M_F(name, _reset)(tree); \ + struct M_F(name,_node_s)*ptr = tree->tab == NULL ? NULL : tree->tab-1;\ M_CALL_FREE(oplist, ptr); \ /* This is so reusing the object implies an assertion failure */ \ tree->size = 1; \ @@ -252,7 +252,7 @@ typedef int32_t m_tr33_index_t; } \ \ static inline void \ - M_C(name, _reserve)(tree_t tree, size_t alloc) { \ + M_F(name, _reserve)(tree_t tree, size_t alloc) { \ M_TR33_CONTRACT(tree); \ /* Nothing to do if the request is lower than the current capacity. */ \ if (alloc <= (size_t) tree->capacity) { \ @@ -260,17 +260,17 @@ typedef int32_t m_tr33_index_t; } \ /* Realloc the array */ \ if (M_UNLIKELY_NOMEM (alloc >= INT32_MAX)) { \ - M_MEMORY_FULL(sizeof (struct M_C(name, _node_s)) * alloc); \ + M_MEMORY_FULL(sizeof (struct M_F(name, _node_s)) * alloc); \ return; \ } \ /* Allocate one more term in the array so that tab[-1] exists. \ This enables performing latter tab[M_TR33_NO_NODE].x = something; \ as M_TR33_NO_NODE is -1. This enables avoiding testing for \ M_TR33_NO_NODE in some cases, performing branchless code. */ \ - struct M_C(name,_node_s)*ptr = tree->tab == NULL ? NULL : tree->tab-1;\ - ptr = M_CALL_REALLOC(oplist, struct M_C(name, _node_s), ptr, alloc+1);\ + struct M_F(name,_node_s)*ptr = tree->tab == NULL ? NULL : tree->tab-1;\ + ptr = M_CALL_REALLOC(oplist, struct M_F(name, _node_s), ptr, alloc+1);\ if (M_UNLIKELY_NOMEM (ptr == NULL) ) { \ - M_MEMORY_FULL(sizeof (struct M_C(name, _node_s)) * alloc); \ + M_MEMORY_FULL(sizeof (struct M_F(name, _node_s)) * alloc); \ return; \ } \ /* Skip the first term to keep it as empty & unused */ \ @@ -299,7 +299,7 @@ typedef int32_t m_tr33_index_t; } \ \ static inline void \ - M_C(name, _lock)(tree_t tree, bool lock) { \ + M_F(name, _lock)(tree_t tree, bool lock) { \ M_TR33_CONTRACT(tree); \ tree->allow_realloc = lock ? INT32_MAX : 0; \ M_TR33_CONTRACT(tree); \ @@ -314,17 +314,17 @@ typedef int32_t m_tr33_index_t; /* Take into account if realloc is allowed */ \ alloc += tree->allow_realloc; \ if (M_UNLIKELY_NOMEM (alloc >= INT32_MAX)) { \ - M_MEMORY_FULL(sizeof (struct M_C(name, _node_s)) * alloc); \ + M_MEMORY_FULL(sizeof (struct M_F(name, _node_s)) * alloc); \ return M_TR33_NO_NODE; \ } \ /* Allocate one more term in the array so that tab[-1] exists. \ This enables performing latter tab[M_TR33_NO_NODE].x = something; \ as M_TR33_NO_NODE is -1. This enables avoiding testing for \ M_TR33_NO_NODE in some cases, performing branchless code. */ \ - struct M_C(name,_node_s)*ptr = tree->tab == NULL ? NULL : tree->tab-1; \ - ptr = M_CALL_REALLOC(oplist, struct M_C(name, _node_s), ptr, alloc+1); \ + struct M_F(name,_node_s)*ptr = tree->tab == NULL ? NULL : tree->tab-1; \ + ptr = M_CALL_REALLOC(oplist, struct M_F(name, _node_s), ptr, alloc+1); \ if (M_UNLIKELY_NOMEM (ptr == NULL) ) { \ - M_MEMORY_FULL(sizeof (struct M_C(name, _node_s)) * alloc); \ + M_MEMORY_FULL(sizeof (struct M_F(name, _node_s)) * alloc); \ return M_TR33_NO_NODE; \ } \ /* Skip the first term to keep it as empty & unused */ \ @@ -361,9 +361,9 @@ typedef int32_t m_tr33_index_t; } \ \ static inline it_t \ - M_C(name, _set_root)(tree_t tree, type const data) { \ + M_F(name, _set_root)(tree_t tree, type const data) { \ M_TR33_CONTRACT(tree); \ - M_C(name, _reset)(tree); \ + M_F(name, _reset)(tree); \ m_tr33_index_t i = M_C3(m_tr33_, name, _alloc_node)(tree); \ tree->tab[i].parent = M_TR33_ROOT_NODE; \ tree->tab[i].left = M_TR33_NO_NODE; \ @@ -381,7 +381,7 @@ typedef int32_t m_tr33_index_t; /* The iterator references the first root node */ \ /* usually for pre-order walk */ \ static inline it_t \ - M_C(name, _it)(tree_t tree) { \ + M_F(name, _it)(tree_t tree) { \ M_TR33_CONTRACT(tree); \ it_t it; \ it.tree = tree; \ @@ -391,7 +391,7 @@ typedef int32_t m_tr33_index_t; } \ \ static inline it_t \ - M_C(name, _it_end)(tree_t tree) { \ + M_F(name, _it_end)(tree_t tree) { \ M_TR33_CONTRACT(tree); \ it_t it; \ it.tree = tree; \ @@ -401,53 +401,53 @@ typedef int32_t m_tr33_index_t; } \ \ static inline bool \ - M_C(name, _end_p)(it_t it) { \ + M_F(name, _end_p)(it_t it) { \ M_TR33_IT_CONTRACT(it, false); \ return it.index < 0; \ } \ \ static inline type * \ - M_C(name, _ref)(it_t it) { \ + M_F(name, _ref)(it_t it) { \ M_TR33_IT_CONTRACT(it, true); \ return &it.tree->tab[it.index].data; \ } \ \ static inline type const * \ - M_C(name, _cref)(it_t it) { \ + M_F(name, _cref)(it_t it) { \ M_TR33_IT_CONTRACT(it, true); \ return M_CONST_CAST(type, &it.tree->tab[it.index].data); \ } \ \ static inline type * \ - M_C(name, _up_ref)(it_t it) { \ + M_F(name, _up_ref)(it_t it) { \ M_TR33_IT_CONTRACT(it, true); \ m_tr33_index_t i = it.tree->tab[it.index].parent; \ return i < 0 ? NULL : &it.tree->tab[i].data; \ } \ \ static inline type * \ - M_C(name, _down_ref)(it_t it) { \ + M_F(name, _down_ref)(it_t it) { \ M_TR33_IT_CONTRACT(it, true); \ m_tr33_index_t i = it.tree->tab[it.index].child; \ return i < 0 ? NULL : &it.tree->tab[i].data; \ } \ \ static inline type * \ - M_C(name, _left_ref)(it_t it) { \ + M_F(name, _left_ref)(it_t it) { \ M_TR33_IT_CONTRACT(it, true); \ m_tr33_index_t i = it.tree->tab[it.index].left; \ return i < 0 ? NULL : &it.tree->tab[i].data; \ } \ \ static inline type * \ - M_C(name, _right_ref)(it_t it) { \ + M_F(name, _right_ref)(it_t it) { \ M_TR33_IT_CONTRACT(it, true); \ m_tr33_index_t i = it.tree->tab[it.index].right; \ return i < 0 ? NULL : &it.tree->tab[i].data; \ } \ \ static inline it_t \ - M_C(name, _insert_up_raw)(it_t it) { \ + M_F(name, _insert_up_raw)(it_t it) { \ M_TR33_IT_CONTRACT(it, true); \ m_tr33_index_t i = M_C3(m_tr33_, name, _alloc_node)(it.tree); \ m_tr33_index_t parent = it.tree->tab[it.index].parent; \ @@ -477,23 +477,23 @@ typedef int32_t m_tr33_index_t; } \ \ static inline it_t \ - M_C(name, _insert_up)(it_t pos, type const data) { \ - it_t it = M_C(name, _insert_up_raw)(pos); \ + M_F(name, _insert_up)(it_t pos, type const data) { \ + it_t it = M_F(name, _insert_up_raw)(pos); \ M_CALL_INIT_SET(oplist, it.tree->tab[it.index].data, data); \ M_TR33_IT_CONTRACT(it, true); \ return it; \ } \ \ static inline it_t \ - M_C(name, _move_up)(it_t pos, type *data) { \ - it_t it = M_C(name, _insert_up_raw)(pos); \ + M_F(name, _move_up)(it_t pos, type *data) { \ + it_t it = M_F(name, _insert_up_raw)(pos); \ M_DO_INIT_MOVE(oplist, it.tree->tab[it.index].data, *data); \ M_TR33_IT_CONTRACT(it, true); \ return it; \ } \ \ static inline it_t \ - M_C(name, _insert_down_raw)(it_t it) { \ + M_F(name, _insert_down_raw)(it_t it) { \ M_TR33_IT_CONTRACT(it, true); \ m_tr33_index_t i = M_C3(m_tr33_, name, _alloc_node)(it.tree); \ m_tr33_index_t child = it.tree->tab[it.index].child; \ @@ -514,23 +514,23 @@ typedef int32_t m_tr33_index_t; } \ \ static inline it_t \ - M_C(name, _insert_down)(it_t pos, type const data) { \ - it_t it = M_C(name, _insert_down_raw)(pos); \ + M_F(name, _insert_down)(it_t pos, type const data) { \ + it_t it = M_F(name, _insert_down_raw)(pos); \ M_CALL_INIT_SET(oplist, it.tree->tab[it.index].data, data); \ M_TR33_IT_CONTRACT(it, true); \ return it; \ } \ \ static inline it_t \ - M_C(name, _move_down)(it_t pos, type *data) { \ - it_t it = M_C(name, _insert_down_raw)(pos); \ + M_F(name, _move_down)(it_t pos, type *data) { \ + it_t it = M_F(name, _insert_down_raw)(pos); \ M_DO_INIT_MOVE(oplist, it.tree->tab[it.index].data, *data); \ M_TR33_IT_CONTRACT(it, true); \ return it; \ } \ \ static inline it_t \ - M_C(name, _insert_child_raw)(it_t it) { \ + M_F(name, _insert_child_raw)(it_t it) { \ M_TR33_IT_CONTRACT(it, true); \ /* Insert a node as a child of another, making the current childreen \ of the nodes their siblings */ \ @@ -551,23 +551,23 @@ typedef int32_t m_tr33_index_t; } \ \ static inline it_t \ - M_C(name, _insert_child)(it_t pos, type const data) { \ - it_t it = M_C(name, _insert_child_raw)(pos); \ + M_F(name, _insert_child)(it_t pos, type const data) { \ + it_t it = M_F(name, _insert_child_raw)(pos); \ M_CALL_INIT_SET(oplist, it.tree->tab[it.index].data, data); \ M_TR33_IT_CONTRACT(it, true); \ return it; \ } \ \ static inline it_t \ - M_C(name, _move_child)(it_t pos, type *data) { \ - it_t it = M_C(name, _insert_child_raw)(pos); \ + M_F(name, _move_child)(it_t pos, type *data) { \ + it_t it = M_F(name, _insert_child_raw)(pos); \ M_DO_INIT_MOVE(oplist, it.tree->tab[it.index].data, *data); \ M_TR33_IT_CONTRACT(it, true); \ return it; \ } \ \ static inline it_t \ - M_C(name, _insert_left_raw)(it_t it) { \ + M_F(name, _insert_left_raw)(it_t it) { \ M_TR33_IT_CONTRACT(it, true); \ M_ASSERT(it.index != it.tree->root_index); \ m_tr33_index_t i = M_C3(m_tr33_, name, _alloc_node)(it.tree); \ @@ -591,23 +591,23 @@ typedef int32_t m_tr33_index_t; } \ \ static inline it_t \ - M_C(name, _insert_left)(it_t pos, type const data) { \ - it_t it = M_C(name, _insert_left_raw)(pos); \ + M_F(name, _insert_left)(it_t pos, type const data) { \ + it_t it = M_F(name, _insert_left_raw)(pos); \ M_CALL_INIT_SET(oplist, it.tree->tab[it.index].data, data); \ M_TR33_IT_CONTRACT(it, true); \ return it; \ } \ \ static inline it_t \ - M_C(name, _move_left)(it_t pos, type *data) { \ - it_t it = M_C(name, _insert_left_raw)(pos); \ + M_F(name, _move_left)(it_t pos, type *data) { \ + it_t it = M_F(name, _insert_left_raw)(pos); \ M_DO_INIT_MOVE(oplist, it.tree->tab[it.index].data, *data); \ M_TR33_IT_CONTRACT(it, true); \ return it; \ } \ \ static inline it_t \ - M_C(name, _insert_right_raw)(it_t it) { \ + M_F(name, _insert_right_raw)(it_t it) { \ M_TR33_IT_CONTRACT(it, true); \ M_ASSERT(it.index != it.tree->root_index); \ m_tr33_index_t i = M_C3(m_tr33_, name, _alloc_node)(it.tree); \ @@ -625,23 +625,23 @@ typedef int32_t m_tr33_index_t; } \ \ static inline it_t \ - M_C(name, _insert_right)(it_t pos, type const data) { \ - it_t it = M_C(name, _insert_right_raw)(pos); \ + M_F(name, _insert_right)(it_t pos, type const data) { \ + it_t it = M_F(name, _insert_right_raw)(pos); \ M_CALL_INIT_SET(oplist, it.tree->tab[it.index].data, data); \ M_TR33_IT_CONTRACT(it, true); \ return it; \ } \ \ static inline it_t \ - M_C(name, _move_right)(it_t pos, type *data) { \ - it_t it = M_C(name, _insert_right_raw)(pos); \ + M_F(name, _move_right)(it_t pos, type *data) { \ + it_t it = M_F(name, _insert_right_raw)(pos); \ M_DO_INIT_MOVE(oplist, it.tree->tab[it.index].data, *data); \ M_TR33_IT_CONTRACT(it, true); \ return it; \ } \ \ static inline bool \ - M_C(name, _it_up)(it_t *it) { \ + M_F(name, _it_up)(it_t *it) { \ M_ASSERT(it != NULL); \ M_TR33_IT_CONTRACT(*it, true); \ m_tr33_index_t i = it->tree->tab[it->index].parent; \ @@ -654,7 +654,7 @@ typedef int32_t m_tr33_index_t; } \ \ static inline bool \ - M_C(name, _it_down)(it_t *it) { \ + M_F(name, _it_down)(it_t *it) { \ M_ASSERT(it != NULL); \ M_TR33_IT_CONTRACT(*it, true); \ m_tr33_index_t i = it->tree->tab[it->index].child; \ @@ -667,7 +667,7 @@ typedef int32_t m_tr33_index_t; } \ \ static inline bool \ - M_C(name, _it_left)(it_t *it) { \ + M_F(name, _it_left)(it_t *it) { \ M_ASSERT(it != NULL); \ M_TR33_IT_CONTRACT(*it, true); \ m_tr33_index_t i = it->tree->tab[it->index].left; \ @@ -680,7 +680,7 @@ typedef int32_t m_tr33_index_t; } \ \ static inline bool \ - M_C(name, _it_right)(it_t *it) { \ + M_F(name, _it_right)(it_t *it) { \ M_ASSERT(it != NULL); \ M_TR33_IT_CONTRACT(*it, true); \ m_tr33_index_t i = it->tree->tab[it->index].right; \ @@ -693,26 +693,26 @@ typedef int32_t m_tr33_index_t; } \ \ static inline bool \ - M_C(name, _root_p)(const it_t it) { \ + M_F(name, _root_p)(const it_t it) { \ M_TR33_IT_CONTRACT(it, true); \ return it.tree->tab[it.index].parent == M_TR33_ROOT_NODE; \ } \ \ static inline bool \ - M_C(name, _node_p)(const it_t it) { \ + M_F(name, _node_p)(const it_t it) { \ M_TR33_IT_CONTRACT(it, true); \ return it.tree->tab[it.index].child != M_TR33_NO_NODE; \ } \ \ static inline bool \ - M_C(name, _leaf_p)(const it_t it) { \ + M_F(name, _leaf_p)(const it_t it) { \ M_TR33_IT_CONTRACT(it, true); \ return it.tree->tab[it.index].child == M_TR33_NO_NODE; \ } \ \ /* Compute the degree of a node in linear time */ \ static inline int32_t \ - M_C(name, _degree)(const it_t it) { \ + M_F(name, _degree)(const it_t it) { \ M_TR33_IT_CONTRACT(it, true); \ int32_t ret = 0; \ m_tr33_index_t i = it.tree->tab[it.index].child; \ @@ -725,7 +725,7 @@ typedef int32_t m_tr33_index_t; \ /* Compute the depth of a node in linear time */ \ static inline int32_t \ - M_C(name, _depth)(it_t it) { \ + M_F(name, _depth)(it_t it) { \ M_TR33_IT_CONTRACT(it, true); \ int32_t ret = 0; \ m_tr33_index_t i = it.tree->tab[it.index].parent; \ @@ -736,14 +736,14 @@ typedef int32_t m_tr33_index_t; return ret; \ } \ \ - static inline struct M_C(name, _s) * \ - M_C(name, _tree)(it_t it) { \ + static inline struct M_F(name, _s) * \ + M_F(name, _tree)(it_t it) { \ M_TR33_IT_CONTRACT(it, false); \ return it.tree; \ } \ \ static inline void \ - M_C(name, _swap_at)(it_t it1, it_t it2, bool swapChild) { \ + M_F(name, _swap_at)(it_t it1, it_t it2, bool swapChild) { \ M_ASSUME(it1.tree == it2.tree); \ M_TR33_IT_CONTRACT(it1, true); \ M_TR33_IT_CONTRACT(it2, true); \ @@ -824,7 +824,7 @@ typedef int32_t m_tr33_index_t; } \ \ static inline type * \ - M_C(name, _unlink)(it_t it) { \ + M_F(name, _unlink)(it_t it) { \ M_TR33_IT_CONTRACT(it, true); \ m_tr33_index_t parent, child, left, right, child_r; \ parent = it.tree->tab[it.index].parent; \ @@ -848,7 +848,7 @@ typedef int32_t m_tr33_index_t; if (M_UNLIKELY(it.index == it.tree->root_index)) { \ /* complex case. Swap root with its first child */ \ it_t it_child = { it.tree, child }; \ - M_C(name, _swap_at)(it, it_child, false); \ + M_F(name, _swap_at)(it, it_child, false); \ parent = it.tree->tab[it.index].parent; \ child = it.tree->tab[it.index].child; \ left = it.tree->tab[it.index].left; \ @@ -885,10 +885,10 @@ typedef int32_t m_tr33_index_t; } \ \ static inline bool \ - M_C(name, _remove)(it_t it) { \ + M_F(name, _remove)(it_t it) { \ M_TR33_IT_CONTRACT(it, false); \ if (M_UNLIKELY(it.index < 0)) { return false; } \ - type *ptr = M_C(name, _unlink)(it); \ + type *ptr = M_F(name, _unlink)(it); \ M_CALL_CLEAR(oplist, *ptr); \ return true; \ } \ @@ -896,15 +896,15 @@ typedef int32_t m_tr33_index_t; /* Scan all nodes, first the parent then the children (uses with _it) */ \ /* pre-order walk */ \ static inline void \ - M_C(name, _next)(it_t *it) { \ + M_F(name, _next)(it_t *it) { \ M_TR33_IT_CONTRACT(*it, true); \ /* First go down, if impossible go right */ \ - if (M_C(name, _it_down)(it) || M_C(name, _it_right)(it)) { \ + if (M_F(name, _it_down)(it) || M_F(name, _it_right)(it)) { \ return; \ } \ /* If impossible to go right, move up and then right until impossible */ \ - while (M_C(name, _it_up)(it)) { \ - if (M_C(name, _it_right)(it)) { \ + while (M_F(name, _it_up)(it)) { \ + if (M_F(name, _it_right)(it)) { \ return; \ } \ } \ @@ -916,13 +916,13 @@ typedef int32_t m_tr33_index_t; /* Scan all nodes, first the children then the parent */ \ /* post-order walk */ \ static inline it_t \ - M_C(name, _it_post)(tree_t tree) { \ + M_F(name, _it_post)(tree_t tree) { \ M_TR33_CONTRACT(tree); \ it_t it; \ it.tree = tree; \ it.index = tree->root_index; \ /* Evaluate child first, so go down to the lowest child */ \ - while (M_C(name, _it_down)(&it)) {} \ + while (M_F(name, _it_down)(&it)) {} \ M_TR33_IT_CONTRACT(it, false); \ return it; \ } \ @@ -930,16 +930,16 @@ typedef int32_t m_tr33_index_t; /* Scan all nodes, first the children then the parent (uses with _it_post) */ \ /* post-order walk */ \ static inline void \ - M_C(name, _next_post)(it_t *it) { \ + M_F(name, _next_post)(it_t *it) { \ M_TR33_IT_CONTRACT(*it, true); \ /* First go right */ \ - if (M_C(name, _it_right)(it)) { \ + if (M_F(name, _it_right)(it)) { \ /* then go down */ \ - while (M_C(name, _it_down)(it)) {} \ + while (M_F(name, _it_down)(it)) {} \ return; \ } \ /* If impossible to go right, move up */ \ - if (M_C(name, _it_up)(it)) { \ + if (M_F(name, _it_up)(it)) { \ return; \ } \ /* Reach end of tree */ \ @@ -948,7 +948,7 @@ typedef int32_t m_tr33_index_t; } \ \ static inline bool \ - M_C(name, _it_equal_p)(it_t it1, it_t it2) { \ + M_F(name, _it_equal_p)(it_t it1, it_t it2) { \ M_TR33_IT_CONTRACT(it1, false); \ M_TR33_IT_CONTRACT(it2, false); \ return it1.tree == it2.tree && it1.index == it2.index; \ @@ -957,7 +957,7 @@ typedef int32_t m_tr33_index_t; /* Scan all nodes, first the parent, then the children */ \ /* post-order walk */ \ static inline it_t \ - M_C(name, _it_subpre)(it_t it) { \ + M_F(name, _it_subpre)(it_t it) { \ /* Nothing to do as it is already on the parent! */ \ return it; \ } \ @@ -965,16 +965,16 @@ typedef int32_t m_tr33_index_t; /* Scan the nodes of it_ref, first the parent then the children */ \ /* pre-order walk */ \ static inline void \ - M_C(name, _next_subpre)(it_t *it, it_t it_ref) { \ + M_F(name, _next_subpre)(it_t *it, it_t it_ref) { \ M_TR33_IT_CONTRACT(*it, true); \ M_TR33_IT_CONTRACT(it_ref, true); \ M_ASSERT(it->tree == it_ref.tree); \ /* First go down, if impossible go right */ \ - if (M_C(name, _it_down)(it)) { return; } \ - if (M_C(name, _it_right)(it)) { return;} \ + if (M_F(name, _it_down)(it)) { return; } \ + if (M_F(name, _it_right)(it)) { return;} \ /* If impossible to go right, move up and then right for the all section */ \ - while (M_C(name, _it_up)(it) && it->index != it_ref.index) { \ - if (M_C(name, _it_right)(it)) { \ + while (M_F(name, _it_up)(it) && it->index != it_ref.index) { \ + if (M_F(name, _it_right)(it)) { \ return; \ } \ } \ @@ -986,10 +986,10 @@ typedef int32_t m_tr33_index_t; /* Scan all nodes, first the children then the parent */ \ /* post-order walk */ \ static inline it_t \ - M_C(name, _it_subpost)(it_t it) { \ + M_F(name, _it_subpost)(it_t it) { \ M_TR33_IT_CONTRACT(it, true); \ /* Evaluate child first, so go down to the lowest child */ \ - while (M_C(name, _it_down)(&it)) {} \ + while (M_F(name, _it_down)(&it)) {} \ M_TR33_IT_CONTRACT(it, false); \ return it; \ } \ @@ -997,7 +997,7 @@ typedef int32_t m_tr33_index_t; /* Scan all nodes, first the children then the parent (uses with _it_subpost) */ \ /* post-order walk */ \ static inline void \ - M_C(name, _next_subpost)(it_t *it, it_t ref) { \ + M_F(name, _next_subpost)(it_t *it, it_t ref) { \ M_TR33_IT_CONTRACT(*it, true); \ M_TR33_IT_CONTRACT(ref, true); \ M_ASSERT(it->tree == ref.tree); \ @@ -1007,26 +1007,26 @@ typedef int32_t m_tr33_index_t; return; \ } \ /* First go right */ \ - if (M_C(name, _it_right)(it)) { \ + if (M_F(name, _it_right)(it)) { \ /* then go down */ \ - while (M_C(name, _it_down)(it)) {} \ + while (M_F(name, _it_down)(it)) {} \ return; \ } \ /* If impossible to go right, move up */ \ - bool b = M_C(name, _it_up)(it); \ + bool b = M_F(name, _it_up)(it); \ (void) b; /* parameter not used */ \ assert(b); \ } \ \ static inline void \ - M_C(name, _prune)(it_t it) { \ + M_F(name, _prune)(it_t it) { \ M_TR33_IT_CONTRACT(it, true); \ /* remove the node, including its childs */ \ - it_t child = M_C(name, _it_subpost)(it); \ - while (!M_C(name, _end_p)(child)) { \ + it_t child = M_F(name, _it_subpost)(it); \ + while (!M_F(name, _end_p)(child)) { \ it_t next = child; \ - M_C(name, _next_subpost)(&next, it); \ - bool b = M_C(name, _remove)(child); \ + M_F(name, _next_subpost)(&next, it); \ + bool b = M_F(name, _remove)(child); \ (void) b; /* parameter not used */ \ M_ASSERT(b); \ child = next; \ @@ -1034,13 +1034,13 @@ typedef int32_t m_tr33_index_t; } \ \ static inline it_t \ - M_C(name, _lca)(it_t it1, it_t it2) { \ + M_F(name, _lca)(it_t it1, it_t it2) { \ M_TR33_IT_CONTRACT(it1, true); \ M_TR33_IT_CONTRACT(it2, true); \ M_ASSERT(it1.tree == it2.tree); \ /* Compute the Lowest Common Ancestor in linear time */ \ - int32_t d1 = M_C(name, _depth)(it1); \ - int32_t d2 = M_C(name, _depth)(it2); \ + int32_t d1 = M_F(name, _depth)(it1); \ + int32_t d2 = M_F(name, _depth)(it2); \ bool b = true; \ if (d1 > d2) { \ M_SWAP(int32_t, d1, d2); \ @@ -1048,14 +1048,14 @@ typedef int32_t m_tr33_index_t; } \ /* it2 is deeper than it1 */ \ while (d1 < d2) { \ - b = M_C(name, _it_up)(&it2); \ + b = M_F(name, _it_up)(&it2); \ d2--; \ assert(b); \ } \ /* Move up both iterators until we found the common node */ \ while (b && it1.index != it2.index) { \ - b = M_C(name, _it_up)(&it1); \ - b = M_C(name, _it_up)(&it2); \ + b = M_F(name, _it_up)(&it1); \ + b = M_F(name, _it_up)(&it2); \ } \ /* If we went back to the root node, we must have found a common node*/ \ M_ASSERT(b); \ @@ -1063,7 +1063,7 @@ typedef int32_t m_tr33_index_t; } \ \ static inline void \ - M_C(name, _graft_child)(it_t it1, const it_t it2) { \ + M_F(name, _graft_child)(it_t it1, const it_t it2) { \ M_ASSERT(it1.tree == it2.tree); \ M_TR33_IT_CONTRACT(it1, true); \ M_TR33_IT_CONTRACT(it2, true); \ @@ -1095,26 +1095,26 @@ typedef int32_t m_tr33_index_t; \ M_IF_METHOD(CMP,oplist)( \ static inline void \ - M_C(name, _sort_child)(it_t it0) { \ + M_F(name, _sort_child)(it_t it0) { \ M_TR33_IT_CONTRACT(it0, true); \ it_t it1 = it0; \ /* Go to the child, if it doesn't exist, nothing to sort */ \ - if (!M_C(name, _it_down)(&it1) ) return ; \ + if (!M_F(name, _it_down)(&it1) ) return ; \ /* Selection sort */ \ do { \ it_t it_min = it1; \ it_t it2 = it1; \ - while (M_C(name, _it_right)(&it2)) { \ - if (M_CALL_CMP(oplist, *M_C(name, _cref)(it2), *M_C(name, _cref)(it_min)) < 0) { \ + while (M_F(name, _it_right)(&it2)) { \ + if (M_CALL_CMP(oplist, *M_F(name, _cref)(it2), *M_F(name, _cref)(it_min)) < 0) { \ it_min = it2; \ } \ } \ - if (M_C(name, _it_equal_p)(it_min, it1) == false) { \ - M_C(name, _swap_at)(it1, it_min, true); \ + if (M_F(name, _it_equal_p)(it_min, it1) == false) { \ + M_F(name, _swap_at)(it1, it_min, true); \ /* The iterator it1 is no longer the min */ \ it1 = it_min; \ } \ - } while (M_C(name, _it_right)(&it1)); \ + } while (M_F(name, _it_right)(&it1)); \ M_TR33_IT_CONTRACT(it0, true); \ } \ , /* No CMP */ ) \ @@ -1123,7 +1123,7 @@ typedef int32_t m_tr33_index_t; /* Define the classic extended missing methods of a tree */ #define M_TR33_DEF_P4_EXT(name, type, oplist, tree_t, it_t) \ static inline void \ - M_C(name, _init_set)(tree_t tree, const tree_t ref) { \ + M_F(name, _init_set)(tree_t tree, const tree_t ref) { \ tree->size = ref->size; \ tree->capacity = ref->capacity; \ tree->root_index = ref->root_index; \ @@ -1133,10 +1133,10 @@ typedef int32_t m_tr33_index_t; if (ref->tab == NULL) { \ tree->tab = NULL; \ } else { \ - struct M_C(name, _node_s) *ptr = \ - M_CALL_REALLOC(oplist, struct M_C(name, _node_s), NULL, alloc+1); \ + struct M_F(name, _node_s) *ptr = \ + M_CALL_REALLOC(oplist, struct M_F(name, _node_s), NULL, alloc+1); \ if (M_UNLIKELY_NOMEM (ptr == NULL) ) { \ - M_MEMORY_FULL(sizeof(struct M_C(name, _node_s)) * alloc); \ + M_MEMORY_FULL(sizeof(struct M_F(name, _node_s)) * alloc); \ return; \ } \ tree->tab = ++ptr; \ @@ -1156,14 +1156,14 @@ typedef int32_t m_tr33_index_t; } \ \ static inline void \ - M_C(name, _set)(tree_t tree, const tree_t ref) { \ + M_F(name, _set)(tree_t tree, const tree_t ref) { \ /* No optimum, but good enought for present time */ \ - M_C(name, _clear)(tree); \ - M_C(name, _init_set)(tree, ref); \ + M_F(name, _clear)(tree); \ + M_F(name, _init_set)(tree, ref); \ } \ \ static inline void \ - M_C(name, _init_move)(tree_t tree, tree_t ref) { \ + M_F(name, _init_move)(tree_t tree, tree_t ref) { \ tree->size = ref->size; \ tree->capacity = ref->capacity; \ tree->root_index = ref->root_index; \ @@ -1176,13 +1176,13 @@ typedef int32_t m_tr33_index_t; } \ \ static inline void \ - M_C(name, _move)(tree_t tree, tree_t ref) { \ - M_C(name, _clear)(tree); \ - M_C(name, _init_move)(tree, ref); \ + M_F(name, _move)(tree_t tree, tree_t ref) { \ + M_F(name, _clear)(tree); \ + M_F(name, _init_move)(tree, ref); \ } \ \ static inline void \ - M_C(name, _swap)(tree_t tree1, tree_t tree2) { \ + M_F(name, _swap)(tree_t tree1, tree_t tree2) { \ M_TR33_CONTRACT(tree1); \ M_TR33_CONTRACT(tree2); \ M_SWAP(m_tr33_index_t, tree1->size, tree2->size); \ @@ -1190,38 +1190,38 @@ typedef int32_t m_tr33_index_t; M_SWAP(m_tr33_index_t, tree1->root_index, tree2->root_index); \ M_SWAP(m_tr33_index_t, tree1->free_index, tree2->free_index); \ M_SWAP(unsigned, tree1->allow_realloc, tree2->allow_realloc); \ - M_SWAP(M_C(name, _node_ct) *, tree1->tab, tree2->tab); \ + M_SWAP(M_F(name, _node_ct) *, tree1->tab, tree2->tab); \ M_TR33_CONTRACT(tree1); \ M_TR33_CONTRACT(tree2); \ } \ \ static inline size_t \ - M_C(name, _size)(const tree_t tree) { \ + M_F(name, _size)(const tree_t tree) { \ M_TR33_CONTRACT(tree); \ return (size_t) tree->size; \ } \ \ static inline bool \ - M_C(name, _empty_p)(const tree_t tree) { \ + M_F(name, _empty_p)(const tree_t tree) { \ M_TR33_CONTRACT(tree); \ return tree->size == 0; \ } \ \ static inline size_t \ - M_C(name, _capacity)(const tree_t tree) { \ + M_F(name, _capacity)(const tree_t tree) { \ M_TR33_CONTRACT(tree); \ return (size_t) tree->capacity; \ } \ \ /* Service not really usefull as the affectation operator works with it */\ static inline void \ - M_C(name, _it_set)(it_t *dst, it_t src ){ \ + M_F(name, _it_set)(it_t *dst, it_t src ){ \ *dst = src; \ } \ \ M_IF_METHOD(EQUAL, oplist)( \ static inline bool \ - M_C(name, _equal_p)(/*const*/ tree_t t1, /*const*/ tree_t t2) { \ + M_F(name, _equal_p)(/*const*/ tree_t t1, /*const*/ tree_t t2) { \ M_TR33_CONTRACT(t1); \ M_TR33_CONTRACT(t2); \ /* Fast case if the sizes don't match */ \ @@ -1232,35 +1232,35 @@ typedef int32_t m_tr33_index_t; and check if we move in the same way \ while checking also the data \ */ \ - it_t it1 = M_C(name, _it)(t1); \ - it_t it2 = M_C(name, _it)(t2); \ - while (!M_C(name, _end_p)(it1)) { \ + it_t it1 = M_F(name, _it)(t1); \ + it_t it2 = M_F(name, _it)(t2); \ + while (!M_F(name, _end_p)(it1)) { \ /* Since both trees have the same size, \ both iterators shall end at the same time. */ \ - M_ASSERT(!M_C(name, _end_p)(it2)); \ - bool b = M_CALL_EQUAL(oplist, *M_C(name, _cref)(it1), *M_C(name, _cref)(it2)); \ + M_ASSERT(!M_F(name, _end_p)(it2)); \ + bool b = M_CALL_EQUAL(oplist, *M_F(name, _cref)(it1), *M_F(name, _cref)(it2)); \ if (!b) return false; \ /* First go down, if impossible go right */ \ - if (M_C(name, _it_down)(&it1) ) { \ - b = M_C(name, _it_down)(&it2); \ + if (M_F(name, _it_down)(&it1) ) { \ + b = M_F(name, _it_down)(&it2); \ if (!b) return false; \ continue; \ } \ - if (M_C(name, _it_right)(&it1)) { \ - b = M_C(name, _it_right)(&it2); \ + if (M_F(name, _it_right)(&it1)) { \ + b = M_F(name, _it_right)(&it2); \ if (!b) return false; \ continue; \ } \ /* If impossible, move up and then right until impossible */ \ - while (M_C(name, _it_up)(&it1)) { \ + while (M_F(name, _it_up)(&it1)) { \ /* Both iterators have move down the same tree by the same \ amount. Therefore if we can move up one iterator, we can \ move the other one up too*/ \ - b = M_C(name, _it_up)(&it2); \ + b = M_F(name, _it_up)(&it2); \ M_ASSERT (b); \ - if (M_C(name, _it_right)(&it1)) { \ + if (M_F(name, _it_right)(&it1)) { \ /* it2 right child may not exist */ \ - b = M_C(name, _it_right)(&it2); \ + b = M_F(name, _it_right)(&it2); \ if (!b) return false; \ goto do_continue; \ } \ @@ -1270,25 +1270,25 @@ typedef int32_t m_tr33_index_t; there shall not be any node for iterator it2 (same size \ same depth) \ */ \ - M_ASSERT( M_C(name, _it_up)(&it2) == false); \ + M_ASSERT( M_F(name, _it_up)(&it2) == false); \ return true; \ /* Reach end of tree */ \ do_continue: \ continue; \ } \ - M_ASSERT(M_C(name, _end_p)(it2)); \ + M_ASSERT(M_F(name, _end_p)(it2)); \ return true; \ } \ , /* No EQUAL */ ) \ \ M_IF_METHOD(HASH, oplist)( \ static inline size_t \ - M_C(name, _hash)(/* const */ tree_t t1) { \ + M_F(name, _hash)(/* const */ tree_t t1) { \ M_HASH_DECL(hash); \ - for(it_t it = M_C(name, _it)(t1); \ - !M_C(name, _end_p)(it) ; \ - M_C(name, _next)(&it)) { \ - size_t h = M_CALL_HASH(oplist, *M_C(name, _cref)(it)); \ + for(it_t it = M_F(name, _it)(t1); \ + !M_F(name, _end_p)(it) ; \ + M_F(name, _next)(&it)) { \ + size_t h = M_CALL_HASH(oplist, *M_F(name, _cref)(it)); \ M_HASH_UP(hash, h); \ } \ return M_HASH_FINAL(hash); \ @@ -1300,33 +1300,33 @@ typedef int32_t m_tr33_index_t; #define M_TR33_DEF_P4_IO(name, type, oplist, tree_t, it_t) \ M_IF_METHOD(GET_STR, oplist)( \ static inline void \ -M_C(name, _get_str)(string_t str, /*const*/ tree_t tree, bool append) { \ +M_F(name, _get_str)(string_t str, /*const*/ tree_t tree, bool append) { \ (append ? m_string_cat_cstr : m_string_set_cstr) (str, "["); \ - it_t it = M_C(name, _it)(tree); \ - while (!M_C(name, _end_p)(it)) { \ + it_t it = M_F(name, _it)(tree); \ + while (!M_F(name, _end_p)(it)) { \ m_string_push_back (str, '{'); \ - type const *item = M_C(name, _cref)(it); \ + type const *item = M_F(name, _cref)(it); \ M_CALL_GET_STR(oplist, str, *item, true); \ /* Go down the tree */ \ - if (M_C(name, _it_down)(&it)) { \ + if (M_F(name, _it_down)(&it)) { \ m_string_push_back (str, M_GET_SEPARATOR oplist); \ m_string_push_back (str, '['); \ continue; \ } \ m_string_push_back (str, '}'); \ - if (M_C(name, _it_right)(&it)) { \ + if (M_F(name, _it_right)(&it)) { \ m_string_push_back (str, M_GET_SEPARATOR oplist); \ continue; \ } \ - while (M_C(name, _it_up)(&it)) { \ + while (M_F(name, _it_up)(&it)) { \ m_string_push_back (str, ']'); \ m_string_push_back (str, '}'); \ - if (M_C(name, _it_right)(&it)) { \ + if (M_F(name, _it_right)(&it)) { \ m_string_push_back (str, M_GET_SEPARATOR oplist); \ goto continue_tree; \ } \ } \ - it = M_C(name, _it_end)(tree); \ + it = M_F(name, _it_end)(tree); \ continue_tree: \ (void) 0; \ } \ @@ -1336,12 +1336,12 @@ M_C(name, _get_str)(string_t str, /*const*/ tree_t tree, bool append) { \ \ M_IF_METHOD(PARSE_STR, oplist)( \ static inline bool \ -M_C(name, _parse_str)(tree_t tree, const char str[], const char **endp) { \ +M_F(name, _parse_str)(tree_t tree, const char str[], const char **endp) { \ M_TR33_CONTRACT(tree); \ int cmd = 0; \ type item; \ it_t it; \ - M_C(name, _reset)(tree); \ + M_F(name, _reset)(tree); \ bool success = false; \ int c = *str; \ if (M_UNLIKELY (c != '[')) goto exit; \ @@ -1349,7 +1349,7 @@ M_C(name, _parse_str)(tree_t tree, const char str[], const char **endp) { \ if (M_UNLIKELY (c == ']')) { success = true; str++; goto exit; } \ if (M_UNLIKELY (c == 0)) goto exit; \ M_CALL_INIT(oplist, item); \ - it = M_C(name, _it_end)(tree); \ + it = M_F(name, _it_end)(tree); \ while (true) { \ c = *str++; \ if (c != '{') goto exit_clear; \ @@ -1358,9 +1358,9 @@ M_C(name, _parse_str)(tree_t tree, const char str[], const char **endp) { \ if (b == false || c == 0) { goto exit_clear; } \ /* Insert the item as the root or as a right sibling or as a child */ \ switch (cmd) { \ - case 0: it = M_C(name, _set_root)(tree, item); break; \ - case 1: it = M_C(name, _insert_right)(it, item); break; \ - case 2: it = M_C(name, _insert_child)(it, item); break; \ + case 0: it = M_F(name, _set_root)(tree, item); break; \ + case 1: it = M_F(name, _insert_right)(it, item); break; \ + case 2: it = M_F(name, _insert_child)(it, item); break; \ default: M_ASSERT(0); \ } \ if (c == ',') { \ @@ -1378,7 +1378,7 @@ M_C(name, _parse_str)(tree_t tree, const char str[], const char **endp) { \ if (c == ']') { \ do { \ /* move up. It we cannot, we have reached the end */ \ - if (!M_C(name, _it_up)(&it)) { goto exit_success; } \ + if (!M_F(name, _it_up)(&it)) { goto exit_success; } \ c = *str++; \ if (c != '}') { goto exit_clear; } \ c = *str++; \ @@ -1401,33 +1401,33 @@ exit: \ \ M_IF_METHOD(OUT_STR, oplist)( \ static inline void \ -M_C(name, _out_str)(FILE *f, /*const*/ tree_t tree) { \ +M_F(name, _out_str)(FILE *f, /*const*/ tree_t tree) { \ fputc('[', f); \ - it_t it = M_C(name, _it)(tree); \ - while (!M_C(name, _end_p)(it)) { \ + it_t it = M_F(name, _it)(tree); \ + while (!M_F(name, _end_p)(it)) { \ fputc('{', f); \ - type const *item = M_C(name, _cref)(it); \ + type const *item = M_F(name, _cref)(it); \ M_CALL_OUT_STR(oplist, f, *item); \ /* Go down the tree */ \ - if (M_C(name, _it_down)(&it)) { \ + if (M_F(name, _it_down)(&it)) { \ fputc (M_GET_SEPARATOR oplist, f); \ fputc ('[', f); \ continue; \ } \ fputc ('}', f); \ - if (M_C(name, _it_right)(&it)) { \ + if (M_F(name, _it_right)(&it)) { \ fputc (M_GET_SEPARATOR oplist, f); \ continue; \ } \ - while (M_C(name, _it_up)(&it)) { \ + while (M_F(name, _it_up)(&it)) { \ fputc (']', f); \ fputc ('}', f); \ - if (M_C(name, _it_right)(&it)) { \ + if (M_F(name, _it_right)(&it)) { \ fputc (M_GET_SEPARATOR oplist, f); \ goto continue_tree; \ } \ } \ - it = M_C(name, _it_end)(tree); \ + it = M_F(name, _it_end)(tree); \ continue_tree: \ (void) 0; \ } \ @@ -1437,12 +1437,12 @@ M_C(name, _out_str)(FILE *f, /*const*/ tree_t tree) { \ \ M_IF_METHOD(IN_STR, oplist)( \ static inline bool \ -M_C(name, _in_str)(tree_t tree, FILE *f) { \ +M_F(name, _in_str)(tree_t tree, FILE *f) { \ M_TR33_CONTRACT(tree); \ int cmd = 0; \ type item; \ it_t it; \ - M_C(name, _reset)(tree); \ + M_F(name, _reset)(tree); \ bool success = false; \ int c = fgetc(f); \ if (M_UNLIKELY (c != '[')) goto exit; \ @@ -1451,7 +1451,7 @@ M_C(name, _in_str)(tree_t tree, FILE *f) { \ ungetc(c, f); \ if (M_UNLIKELY (c == 0)) goto exit; \ M_CALL_INIT(oplist, item); \ - it = M_C(name, _it_end)(tree); \ + it = M_F(name, _it_end)(tree); \ while (true) { \ c = fgetc(f); \ if (c != '{') goto exit_clear; \ @@ -1460,9 +1460,9 @@ M_C(name, _in_str)(tree_t tree, FILE *f) { \ if (b == false || c == 0) { goto exit_clear; } \ /* Insert the item as the root or as a right sibling or as a child */ \ switch (cmd) { \ - case 0: it = M_C(name, _set_root)(tree, item); break; \ - case 1: it = M_C(name, _insert_right)(it, item); break; \ - case 2: it = M_C(name, _insert_child)(it, item); break; \ + case 0: it = M_F(name, _set_root)(tree, item); break; \ + case 1: it = M_F(name, _insert_right)(it, item); break; \ + case 2: it = M_F(name, _insert_child)(it, item); break; \ default: M_ASSERT(0); \ } \ if (c == ',') { \ @@ -1480,7 +1480,7 @@ M_C(name, _in_str)(tree_t tree, FILE *f) { \ if (c == ']') { \ do { \ /* move up. It we cannot, we have reached the end */ \ - if (!M_C(name, _it_up)(&it)) { goto exit_success; } \ + if (!M_F(name, _it_up)(&it)) { goto exit_success; } \ c = fgetc(f); \ if (c != '}') { goto exit_clear; } \ c = fgetc(f); \ @@ -1502,21 +1502,21 @@ exit: \ /* Define the emplace methods of a tree */ #define M_TR33_DEF_P4_EMPLACE(name, type, oplist, tree_t, it_t) \ - M_EMPLACE_QUEUE_DEF(name, tree_t, M_C(name, _emplace_root), oplist, M_TR33_EMPLACE_ROOT_DEF) \ - M_EMPLACE_QUEUE_DEF(name, it_t, M_C(name, _emplace_up), oplist, M_TR33_EMPLACE_UP_DEF) \ - M_EMPLACE_QUEUE_DEF(name, it_t, M_C(name, _emplace_down), oplist, M_TR33_EMPLACE_DOWN_DEF) \ - M_EMPLACE_QUEUE_DEF(name, it_t, M_C(name, _emplace_child), oplist, M_TR33_EMPLACE_CHILD_DEF) \ - M_EMPLACE_QUEUE_DEF(name, it_t, M_C(name, _emplace_left), oplist, M_TR33_EMPLACE_LEFT_DEF) \ - M_EMPLACE_QUEUE_DEF(name, it_t, M_C(name, _emplace_right), oplist, M_TR33_EMPLACE_RIGHT_DEF) + M_EMPLACE_QUEUE_DEF(name, tree_t, M_F(name, _emplace_root), oplist, M_TR33_EMPLACE_ROOT_DEF) \ + M_EMPLACE_QUEUE_DEF(name, it_t, M_F(name, _emplace_up), oplist, M_TR33_EMPLACE_UP_DEF) \ + M_EMPLACE_QUEUE_DEF(name, it_t, M_F(name, _emplace_down), oplist, M_TR33_EMPLACE_DOWN_DEF) \ + M_EMPLACE_QUEUE_DEF(name, it_t, M_F(name, _emplace_child), oplist, M_TR33_EMPLACE_CHILD_DEF) \ + M_EMPLACE_QUEUE_DEF(name, it_t, M_F(name, _emplace_left), oplist, M_TR33_EMPLACE_LEFT_DEF) \ + M_EMPLACE_QUEUE_DEF(name, it_t, M_F(name, _emplace_right), oplist, M_TR33_EMPLACE_RIGHT_DEF) /* Definition of the emplace_back functions */ #define M_TR33_EMPLACE_ROOT_DEF(name, name_t, function_name, oplist, init_func, exp_emplace_type) \ - static inline M_C(name, _it_ct) \ + static inline M_F(name, _it_ct) \ function_name(name_t tree \ M_EMPLACE_LIST_TYPE_VAR(a, exp_emplace_type) ) \ { \ M_TR33_CONTRACT(tree); \ - M_C(name, _reset)(tree); \ + M_F(name, _reset)(tree); \ m_tr33_index_t i = M_C3(m_tr33_, name, _alloc_node)(tree); \ tree->tab[i].parent = M_TR33_ROOT_NODE; \ tree->tab[i].left = M_TR33_NO_NODE; \ @@ -1525,7 +1525,7 @@ exit: \ tree->root_index = i; \ M_EMPLACE_CALL_FUNC(a, init_func, oplist, tree->tab[i].data, \ exp_emplace_type); \ - M_C(name, _it_ct) it; \ + M_F(name, _it_ct) it; \ it.tree = tree; \ it.index = tree->root_index; \ M_TR33_CONTRACT(tree); \ @@ -1537,7 +1537,7 @@ exit: \ function_name(name_t pos \ M_EMPLACE_LIST_TYPE_VAR(a, exp_emplace_type) ) \ { \ - name_t it = M_C(name, _insert_up_raw)(pos); \ + name_t it = M_F(name, _insert_up_raw)(pos); \ M_EMPLACE_CALL_FUNC(a, init_func, oplist, it.tree->tab[it.index].data, \ exp_emplace_type); \ return it; \ @@ -1548,7 +1548,7 @@ exit: \ function_name(name_t pos \ M_EMPLACE_LIST_TYPE_VAR(a, exp_emplace_type) ) \ { \ - name_t it = M_C(name, _insert_down_raw)(pos); \ + name_t it = M_F(name, _insert_down_raw)(pos); \ M_EMPLACE_CALL_FUNC(a, init_func, oplist, it.tree->tab[it.index].data, \ exp_emplace_type); \ return it; \ @@ -1559,7 +1559,7 @@ exit: \ function_name(name_t pos \ M_EMPLACE_LIST_TYPE_VAR(a, exp_emplace_type) ) \ { \ - name_t it = M_C(name, _insert_child_raw)(pos); \ + name_t it = M_F(name, _insert_child_raw)(pos); \ M_EMPLACE_CALL_FUNC(a, init_func, oplist, it.tree->tab[it.index].data, \ exp_emplace_type); \ return it; \ @@ -1570,7 +1570,7 @@ exit: \ function_name(name_t pos \ M_EMPLACE_LIST_TYPE_VAR(a, exp_emplace_type) ) \ { \ - name_t it = M_C(name, _insert_left_raw)(pos); \ + name_t it = M_F(name, _insert_left_raw)(pos); \ M_EMPLACE_CALL_FUNC(a, init_func, oplist, it.tree->tab[it.index].data, \ exp_emplace_type); \ return it; \ @@ -1581,7 +1581,7 @@ exit: \ function_name(name_t pos \ M_EMPLACE_LIST_TYPE_VAR(a, exp_emplace_type) ) \ { \ - name_t it = M_C(name, _insert_right_raw)(pos); \ + name_t it = M_F(name, _insert_right_raw)(pos); \ M_EMPLACE_CALL_FUNC(a, init_func, oplist, it.tree->tab[it.index].data, \ exp_emplace_type); \ return it; \ diff --git a/m-tuple.h b/m-tuple.h index 84a62f73..b1badb6e 100644 --- a/m-tuple.h +++ b/m-tuple.h @@ -31,7 +31,7 @@ USAGE: TUPLE_DEF2(name, [(field1, type1[, oplist1]), (field2, type2[, oplist2]), ...] ) */ #define M_TUPLE_DEF2(name, ...) \ - M_TUPLE_DEF2_AS(name, M_C(name,_t), __VA_ARGS__) + M_TUPLE_DEF2_AS(name, M_F(name,_t), __VA_ARGS__) /* Define the tuple type and functions @@ -151,7 +151,7 @@ namespace m_lib { M_TUPL3_IF_ALL(RESET, __VA_ARGS__)(M_TUPL3_DEFINE_RESET(name, __VA_ARGS__),) /* Provide order for _cmp_order */ -#define M_TUPL3_ORDER_CONVERT(name, x) M_C(name, M_C(M_TUPL3_ORDER_CONVERT_, x)) +#define M_TUPL3_ORDER_CONVERT(name, x) M_F(name, M_C(M_TUPL3_ORDER_CONVERT_, x)) #define M_TUPL3_ORDER_CONVERT_ASC(x) M_C3(_,x,_value) #define M_TUPL3_ORDER_CONVERT_DSC(x) M_C3(_,x,_value)*-1 @@ -201,14 +201,14 @@ namespace m_lib { /* Define the type of a tuple */ #define M_TUPL3_DEFINE_TYPE(name, name_t, ...) \ - typedef struct M_C(name, _s) { \ + typedef struct M_F(name, _s) { \ M_MAP(M_TUPL3_DEFINE_RECUR_TYPE_ELE , __VA_ARGS__) \ } name_t[1]; \ \ - typedef struct M_C(name, _s) *M_C(name, _ptr); \ - typedef const struct M_C(name, _s) *M_C(name, _srcptr); \ + typedef struct M_F(name, _s) *M_F(name, _ptr); \ + typedef const struct M_F(name, _s) *M_F(name, _srcptr); \ /* Define internal type for oplist */ \ - typedef name_t M_C(name, _ct); \ + typedef name_t M_F(name, _ct); \ /* Save constant as the number of arguments (internal) */ \ typedef enum { \ M_C3(m_tupl3_, name, _num_args) = M_NARGS(__VA_ARGS__) \ @@ -225,9 +225,9 @@ namespace m_lib { /* Define the basic enumerate, identifying a parameter */ #define M_TUPL3_DEFINE_ENUM(name, ...) \ typedef enum { \ - M_C(name, _first_one_val), \ + M_F(name, _first_one_val), \ M_MAP2_C(M_TUPL3_DEFINE_ENUM_ELE , name, __VA_ARGS__) \ - } M_C(name,_field_e); + } M_F(name,_field_e); #define M_TUPL3_DEFINE_ENUM_ELE(name, a) \ M_C4(name, _, M_TUPL3_GET_FIELD a, _value) @@ -242,7 +242,7 @@ namespace m_lib { /* Define the INIT method calling the INIT method for all params */ #define M_TUPL3_DEFINE_INIT(name, ...) \ - static inline void M_C(name, _init)(M_C(name,_ct) my) { \ + static inline void M_F(name, _init)(M_F(name,_ct) my) { \ M_MAP(M_TUPL3_DEFINE_INIT_FUNC , __VA_ARGS__) \ } @@ -251,7 +251,7 @@ namespace m_lib { /* Define the INIT_SET method calling the INIT_SET method for all params */ #define M_TUPL3_DEFINE_INIT_SET(name, ...) \ - static inline void M_C(name, _init_set)(M_C(name,_ct) my , M_C(name,_ct) const org) { \ + static inline void M_F(name, _init_set)(M_F(name,_ct) my , M_F(name,_ct) const org) { \ M_TUPL3_CONTRACT(org); \ M_MAP(M_TUPL3_DEFINE_INIT_SET_FUNC , __VA_ARGS__) \ } @@ -260,7 +260,7 @@ namespace m_lib { /* Define the INIT_WITH method calling the INIT_SET method for all params. */ #define M_TUPL3_DEFINE_INIT_SET2(name, ...) \ - static inline void M_C(name, _init_emplace)(M_C(name,_ct) my \ + static inline void M_F(name, _init_emplace)(M_F(name,_ct) my \ M_MAP(M_TUPL3_DEFINE_INIT_SET2_PROTO, __VA_ARGS__) \ ) { \ M_MAP(M_TUPL3_DEFINE_INIT_SET2_FUNC , __VA_ARGS__) \ @@ -275,8 +275,8 @@ namespace m_lib { /* Define the SET method calling the SET method for all params. */ #define M_TUPL3_DEFINE_SET(name, ...) \ - static inline void M_C(name, _set)(M_C(name,_ct) my , \ - M_C(name,_ct) const org) { \ + static inline void M_F(name, _set)(M_F(name,_ct) my , \ + M_F(name,_ct) const org) { \ M_TUPL3_CONTRACT(my); \ M_TUPL3_CONTRACT(org); \ M_MAP(M_TUPL3_DEFINE_SET_FUNC , __VA_ARGS__) \ @@ -288,7 +288,7 @@ namespace m_lib { /* Define the SET_WITH method calling the SET method for all params. */ #define M_TUPL3_DEFINE_SET2(name, ...) \ - static inline void M_C(name, _emplace)(M_C(name,_ct) my \ + static inline void M_F(name, _emplace)(M_F(name,_ct) my \ M_MAP(M_TUPL3_DEFINE_SET2_PROTO, __VA_ARGS__) \ ) { \ M_TUPL3_CONTRACT(my); \ @@ -303,7 +303,7 @@ namespace m_lib { /* Define the CLEAR method calling the CLEAR method for all params. */ #define M_TUPL3_DEFINE_CLEAR(name, ...) \ - static inline void M_C(name, _clear)(M_C(name,_ct) my) { \ + static inline void M_F(name, _clear)(M_F(name,_ct) my) { \ M_TUPL3_CONTRACT(my); \ M_MAP(M_TUPL3_DEFINE_CLEAR_FUNC , __VA_ARGS__) \ } @@ -318,18 +318,18 @@ namespace m_lib { #define M_TUPL3_DEFINE_GETTER_FIELD_PROTO(name, num, a) \ static inline M_TUPL3_GET_TYPE a * M_C3(name, _get_at_, M_TUPL3_GET_FIELD a) \ - (M_C(name,_ct) my) { \ + (M_F(name,_ct) my) { \ M_TUPL3_CONTRACT(my); \ return &(my->M_TUPL3_GET_FIELD a); \ } \ static inline M_TUPL3_GET_TYPE a const * M_C3(name, _cget_at_, M_TUPL3_GET_FIELD a) \ - (M_C(name,_ct) const my) { \ + (M_F(name,_ct) const my) { \ M_TUPL3_CONTRACT(my); \ return &(my->M_TUPL3_GET_FIELD a); \ } \ /* Same but uses numerical index for accessing the field (internal) */ \ static inline M_TUPL3_GET_TYPE a * M_C4(m_tupl3_, name, _get_at_, num) \ - (M_C(name,_ct) my) { \ + (M_F(name,_ct) my) { \ return &(my->M_TUPL3_GET_FIELD a); \ } \ @@ -340,7 +340,7 @@ namespace m_lib { #define M_TUPL3_DEFINE_SETTER_FIELD_PROTO(name, a) \ static inline void M_C3(name, _set_, M_TUPL3_GET_FIELD a) \ - (M_C(name,_ct) my, M_TUPL3_GET_TYPE a const M_TUPL3_GET_FIELD a) { \ + (M_F(name,_ct) my, M_TUPL3_GET_TYPE a const M_TUPL3_GET_FIELD a) { \ M_TUPL3_CONTRACT(my); \ M_TUPL3_CALL_SET(a, my ->M_TUPL3_GET_FIELD a, M_TUPL3_GET_FIELD a); \ } @@ -348,8 +348,8 @@ namespace m_lib { /* Define the CMP method by calling CMP methods for all params. */ #define M_TUPL3_DEFINE_CMP(name, ...) \ - static inline int M_C(name, _cmp)(M_C(name,_ct) const e1 , \ - M_C(name,_ct) const e2) { \ + static inline int M_F(name, _cmp)(M_F(name,_ct) const e1 , \ + M_F(name,_ct) const e2) { \ int i; \ M_TUPL3_CONTRACT(e1); \ M_TUPL3_CONTRACT(e2); \ @@ -369,8 +369,8 @@ namespace m_lib { FIXME: All oplists shall define the CMP operator or at least one? */ #define M_TUPL3_DEFINE_CMP_ORDER(name, ...) \ - static inline int M_C(name, _cmp_order)(M_C(name,_ct) const e1 , \ - M_C(name,_ct) const e2, \ + static inline int M_F(name, _cmp_order)(M_F(name,_ct) const e1 , \ + M_F(name,_ct) const e2, \ const int order[]) { \ int i, r; \ M_TUPL3_CONTRACT(e1); \ @@ -403,8 +403,8 @@ namespace m_lib { ) #define M_TUPL3_DEFINE_CMP_FIELD_FUNC(name, field, func_cmp, oplist) \ - static inline int M_C3(name, _cmp_, field)(M_C(name,_ct) const e1 , \ - M_C(name,_ct) const e2) { \ + static inline int M_C3(name, _cmp_, field)(M_F(name,_ct) const e1 , \ + M_F(name,_ct) const e2) { \ M_TUPL3_CONTRACT(e1); \ M_TUPL3_CONTRACT(e2); \ return M_APPLY_API(func_cmp, oplist, e1 -> field , e2 -> field ); \ @@ -413,8 +413,8 @@ namespace m_lib { /* Define a EQUAL method by calling the EQUAL methods for all params */ #define M_TUPL3_DEFINE_EQUAL(name, ...) \ - static inline bool M_C(name, _equal_p)(M_C(name,_ct) const e1 , \ - M_C(name,_ct) const e2) { \ + static inline bool M_F(name, _equal_p)(M_F(name,_ct) const e1 , \ + M_F(name,_ct) const e2) { \ bool b; \ M_TUPL3_CONTRACT(e1); \ M_TUPL3_CONTRACT(e2); \ @@ -431,7 +431,7 @@ namespace m_lib { /* Define a HASH method by calling the HASH methods for all params */ #define M_TUPL3_DEFINE_HASH(name, ...) \ - static inline size_t M_C(name, _hash)(M_C(name,_ct) const e1) { \ + static inline size_t M_F(name, _hash)(M_F(name,_ct) const e1) { \ M_TUPL3_CONTRACT(e1); \ M_HASH_DECL(hash); \ M_MAP(M_TUPL3_DEFINE_HASH_FUNC_P0, __VA_ARGS__) \ @@ -446,8 +446,8 @@ namespace m_lib { /* Define a GET_STR method by calling the GET_STR methods for all params */ #define M_TUPL3_DEFINE_GET_STR(name, ...) \ - static inline void M_C(name, _get_str)(m_string_t str, \ - M_C(name,_ct) const el, \ + static inline void M_F(name, _get_str)(m_string_t str, \ + M_F(name,_ct) const el, \ bool append) { \ bool comma = false; \ M_TUPL3_CONTRACT(el); \ @@ -465,8 +465,8 @@ namespace m_lib { /* Define a OUT_STR method by calling the OUT_STR methods for all params */ #define M_TUPL3_DEFINE_OUT_STR(name, ...) \ - static inline void M_C(name, _out_str)(FILE *f, \ - M_C(name,_ct) const el) { \ + static inline void M_F(name, _out_str)(FILE *f, \ + M_F(name,_ct) const el) { \ bool comma = false; \ M_TUPL3_CONTRACT(el); \ M_ASSERT (f != NULL); \ @@ -483,7 +483,7 @@ namespace m_lib { /* Define a IN_STR method by calling the IN_STR methods for all params */ #define M_TUPL3_DEFINE_IN_STR(name, ...) \ - static inline bool M_C(name, _in_str)(M_C(name,_ct) el, FILE *f) { \ + static inline bool M_F(name, _in_str)(M_F(name,_ct) el, FILE *f) { \ bool comma = false; \ M_TUPL3_CONTRACT(el); \ M_ASSERT (f != NULL); \ @@ -506,7 +506,7 @@ namespace m_lib { /* Define a PARSE_STR method by calling the PARSE_STR methods for all params */ #define M_TUPL3_DEFINE_PARSE_STR(name, ...) \ - static inline bool M_C(name, _parse_str)(M_C(name,_ct) el, \ + static inline bool M_F(name, _parse_str)(M_F(name,_ct) el, \ const char str[], \ const char **endptr) { \ M_TUPL3_CONTRACT(el); \ @@ -541,8 +541,8 @@ namespace m_lib { /* Define a OUT_SERIAL method by calling the OUT_SERIAL methods for all params */ #define M_TUPL3_DEFINE_OUT_SERIAL(name, ...) \ static inline m_serial_return_code_t \ - M_C(name, _out_serial)(m_serial_write_t f, \ - M_C(name,_ct) const el) { \ + M_F(name, _out_serial)(m_serial_write_t f, \ + M_F(name,_ct) const el) { \ M_TUPL3_CONTRACT(el); \ M_ASSERT (f != NULL && f->m_interface != NULL); \ const int field_max = M_NARGS(__VA_ARGS__); \ @@ -568,7 +568,7 @@ namespace m_lib { /* Define a IN_SERIAL method by calling the IN_SERIAL methods for all params */ #define M_TUPL3_DEFINE_IN_SERIAL(name, ...) \ static inline m_serial_return_code_t \ - M_C(name, _in_serial)(M_C(name,_ct) el, m_serial_read_t f) { \ + M_F(name, _in_serial)(M_F(name,_ct) el, m_serial_read_t f) { \ M_TUPL3_CONTRACT(el); \ M_ASSERT (f != NULL && f->m_interface != NULL); \ int index = -1; \ @@ -600,7 +600,7 @@ namespace m_lib { /* Define a INIT_MOVE method by calling the INIT_MOVE methods for all params */ #define M_TUPL3_DEFINE_INIT_MOVE(name, ...) \ - static inline void M_C(name, _init_move)(M_C(name,_ct) el, M_C(name,_ct) org) { \ + static inline void M_F(name, _init_move)(M_F(name,_ct) el, M_F(name,_ct) org) { \ M_TUPL3_CONTRACT(el); \ M_MAP(M_TUPL3_DEFINE_INIT_MOVE_FUNC , __VA_ARGS__) \ } @@ -611,7 +611,7 @@ namespace m_lib { /* Define a MOVE method by calling the MOVE methods for all params */ #define M_TUPL3_DEFINE_MOVE(name, ...) \ - static inline void M_C(name, _move)(M_C(name,_ct) el, M_C(name,_ct) org) { \ + static inline void M_F(name, _move)(M_F(name,_ct) el, M_F(name,_ct) org) { \ M_TUPL3_CONTRACT(el); \ M_MAP(M_TUPL3_DEFINE_MOVE_FUNC , __VA_ARGS__) \ } @@ -622,7 +622,7 @@ namespace m_lib { /* Define a SWAP method by calling the SWAP methods for all params */ #define M_TUPL3_DEFINE_SWAP(name, ...) \ - static inline void M_C(name, _swap)(M_C(name,_ct) el1, M_C(name,_ct) el2) { \ + static inline void M_F(name, _swap)(M_F(name,_ct) el1, M_F(name,_ct) el2) { \ M_TUPL3_CONTRACT(el1); \ M_TUPL3_CONTRACT(el2); \ M_MAP(M_TUPL3_DEFINE_SWAP_FUNC , __VA_ARGS__) \ @@ -634,7 +634,7 @@ namespace m_lib { /* Define a RESET method by calling the RESET methods for all params */ #define M_TUPL3_DEFINE_RESET(name, ...) \ - static inline void M_C(name, _reset)(M_C(name,_ct) el1) { \ + static inline void M_F(name, _reset)(M_F(name,_ct) el1) { \ M_TUPL3_CONTRACT(el1); \ M_MAP(M_TUPL3_DEFINE_RESET_FUNC , __VA_ARGS__) \ } \ @@ -671,7 +671,7 @@ namespace m_lib { M_IF(M_NOTEQUAL( M_NARGS oplist_arglist, M_NARGS (__VA_ARGS__))) \ (M_TUPL3_INIT_WITH_P1_FUNC, M_TUPL3_INIT_WITH_P1_MACRO)(name, oplist_arglist, dest, __VA_ARGS__) #define M_TUPL3_INIT_WITH_P1_FUNC(name, oplist_arglist, dest, ...) \ - M_C(name, _init_emplace)(dest, __VA_ARGS__) + M_F(name, _init_emplace)(dest, __VA_ARGS__) #define M_TUPL3_INIT_WITH_P1_MACRO(name, oplist_arglist, dest, ...) \ ( M_STATIC_ASSERT( M_NARGS oplist_arglist == M_C3(m_tupl3_, name, _num_args), M_LIB_DIMENSION_ERROR, "The number of oplists given to TUPLE_OPLIST don't match the number of oplists used to create the tuple." ), \ M_STATIC_ASSERT( M_NARGS(__VA_ARGS__) == M_C3(m_tupl3_, name, _num_args), M_LIB_DIMENSION_ERROR, "Missing / Too many arguments for tuple"), \ @@ -721,27 +721,27 @@ namespace m_lib { /* Define the TUPLE oplist */ #define M_TUPL3_OPLIST_P3(name, ...) \ - (M_IF_METHOD_ALL(INIT, __VA_ARGS__)(INIT(M_C(name,_init)),), \ - INIT_SET(M_C(name, _init_set)), \ + (M_IF_METHOD_ALL(INIT, __VA_ARGS__)(INIT(M_F(name,_init)),), \ + INIT_SET(M_F(name, _init_set)), \ INIT_WITH(API_1(M_TUPL3_INIT_WITH)), \ - SET(M_C(name,_set)), \ - CLEAR(M_C(name, _clear)), \ + SET(M_F(name,_set)), \ + CLEAR(M_F(name, _clear)), \ NAME(name), \ - TYPE(M_C(name,_ct)), \ + TYPE(M_F(name,_ct)), \ OPLIST( (__VA_ARGS__) ), \ - M_IF_METHOD_ALL(CMP, __VA_ARGS__)(CMP(M_C(name, _cmp)),), \ - M_IF_METHOD_ALL(HASH, __VA_ARGS__)(HASH(M_C(name, _hash)),), \ - M_IF_METHOD_ALL(EQUAL, __VA_ARGS__)(EQUAL(M_C(name, _equal_p)),), \ - M_IF_METHOD_ALL(GET_STR, __VA_ARGS__)(GET_STR(M_C(name, _get_str)),), \ - M_IF_METHOD_ALL(PARSE_STR, __VA_ARGS__)(PARSE_STR(M_C(name, _parse_str)),), \ - M_IF_METHOD_ALL(IN_STR, __VA_ARGS__)(IN_STR(M_C(name, _in_str)),), \ - M_IF_METHOD_ALL(OUT_STR, __VA_ARGS__)(OUT_STR(M_C(name, _out_str)),), \ - M_IF_METHOD_ALL(IN_SERIAL, __VA_ARGS__)(IN_SERIAL(M_C(name, _in_serial)),), \ - M_IF_METHOD_ALL(OUT_SERIAL, __VA_ARGS__)(OUT_SERIAL(M_C(name, _out_serial)),), \ - M_IF_METHOD_ALL(INIT_MOVE, __VA_ARGS__)(INIT_MOVE(M_C(name, _init_move)),), \ - M_IF_METHOD_ALL(MOVE, __VA_ARGS__)(MOVE(M_C(name, _move)),), \ - M_IF_METHOD_ALL(SWAP, __VA_ARGS__)(SWAP(M_C(name, _swap)),), \ - M_IF_METHOD_ALL(RESET, __VA_ARGS__)(RESET(M_C(name, _reset)),), \ + M_IF_METHOD_ALL(CMP, __VA_ARGS__)(CMP(M_F(name, _cmp)),), \ + M_IF_METHOD_ALL(HASH, __VA_ARGS__)(HASH(M_F(name, _hash)),), \ + M_IF_METHOD_ALL(EQUAL, __VA_ARGS__)(EQUAL(M_F(name, _equal_p)),), \ + M_IF_METHOD_ALL(GET_STR, __VA_ARGS__)(GET_STR(M_F(name, _get_str)),), \ + M_IF_METHOD_ALL(PARSE_STR, __VA_ARGS__)(PARSE_STR(M_F(name, _parse_str)),), \ + M_IF_METHOD_ALL(IN_STR, __VA_ARGS__)(IN_STR(M_F(name, _in_str)),), \ + M_IF_METHOD_ALL(OUT_STR, __VA_ARGS__)(OUT_STR(M_F(name, _out_str)),), \ + M_IF_METHOD_ALL(IN_SERIAL, __VA_ARGS__)(IN_SERIAL(M_F(name, _in_serial)),), \ + M_IF_METHOD_ALL(OUT_SERIAL, __VA_ARGS__)(OUT_SERIAL(M_F(name, _out_serial)),), \ + M_IF_METHOD_ALL(INIT_MOVE, __VA_ARGS__)(INIT_MOVE(M_F(name, _init_move)),), \ + M_IF_METHOD_ALL(MOVE, __VA_ARGS__)(MOVE(M_F(name, _move)),), \ + M_IF_METHOD_ALL(SWAP, __VA_ARGS__)(SWAP(M_F(name, _swap)),), \ + M_IF_METHOD_ALL(RESET, __VA_ARGS__)(RESET(M_F(name, _reset)),), \ M_IF_METHOD(NEW, M_RET_ARG1(__VA_ARGS__,))(NEW(M_DELAY2(M_GET_NEW) M_RET_ARG1(__VA_ARGS__,)),), \ M_IF_METHOD(REALLOC, M_RET_ARG1(__VA_ARGS__,))(REALLOC(M_DELAY2(M_GET_REALLOC) M_RET_ARG1(__VA_ARGS__,)),), \ M_IF_METHOD(DEL, M_RET_ARG1(__VA_ARGS__,))(DEL(M_DELAY2(M_GET_DEL) M_RET_ARG1(__VA_ARGS__,)),), \ diff --git a/m-variant.h b/m-variant.h index baa02c48..e072ab0b 100644 --- a/m-variant.h +++ b/m-variant.h @@ -31,7 +31,7 @@ USAGE: VARIANT_DEF2(name, [(field1, type1, oplist1), (field2, type2, oplist2), ...] ) */ #define M_VARIANT_DEF2(name, ...) \ - M_VARIANT_DEF2_AS(name, M_C(name,_t), __VA_ARGS__) + M_VARIANT_DEF2_AS(name, M_F(name,_t), __VA_ARGS__) /* Define the variant type and functions @@ -59,8 +59,8 @@ /* Contract of a variant. */ #define M_VAR1ANT_CONTRACT(name, my) do { \ M_ASSERT(my != NULL); \ - M_ASSERT(my->type >= M_C(name, _EMPTY)); \ - M_ASSERT(my->type <= (enum M_C(name, _enum)) M_C(name, _MAX_TYPE)); \ + M_ASSERT(my->type >= M_F(name, _EMPTY)); \ + M_ASSERT(my->type <= (enum M_F(name, _enum)) M_F(name, _MAX_TYPE)); \ } while (0) /* Inject the oplist within the list of arguments */ @@ -181,25 +181,25 @@ /* Define the type */ #define M_VAR1ANT_DEFINE_TYPE(name, name_t, ...) \ /* Define enum of all types of the variant */ \ - enum M_C(name, _enum) { M_C(name, _EMPTY) \ + enum M_F(name, _enum) { M_F(name, _EMPTY) \ M_MAP2(M_VAR1ANT_DEFINE_UNION_ELE, name, __VA_ARGS__) \ }; \ /* Define enum equal to the number of types of the variant */ \ - enum M_C(name, _enum_max) { \ - M_C(name, _MAX_TYPE) = M_NARGS(__VA_ARGS__) \ + enum M_F(name, _enum_max) { \ + M_F(name, _MAX_TYPE) = M_NARGS(__VA_ARGS__) \ }; \ /* Define the variant */ \ - typedef struct M_C(name, _s) { \ - enum M_C(name, _enum) type; \ + typedef struct M_F(name, _s) { \ + enum M_F(name, _enum) type; \ union { \ M_MAP(M_VAR1ANT_DEFINE_TYPE_ELE , __VA_ARGS__) \ } value; \ } name_t[1]; \ \ - typedef struct M_C(name, _s) *M_C(name, _ptr); \ - typedef const struct M_C(name, _s) *M_C(name, _srcptr); \ + typedef struct M_F(name, _s) *M_F(name, _ptr); \ + typedef const struct M_F(name, _s) *M_F(name, _srcptr); \ /* Define internal type for oplist */ \ - typedef name_t M_C(name, _ct); + typedef name_t M_F(name, _ct); #define M_VAR1ANT_DEFINE_UNION_ELE(name, a) \ , M_C4(name, _, M_VAR1ANT_GET_FIELD a, _value) @@ -219,21 +219,21 @@ /* Define the INIT function. Init the variant to empty */ #define M_VAR1ANT_DEFINE_INIT(name, ...) \ - static inline void M_C(name, _init)(M_C(name,_ct) my) { \ - my->type = M_C(name, _EMPTY); \ + static inline void M_F(name, _init)(M_F(name,_ct) my) { \ + my->type = M_F(name, _EMPTY); \ } /* Define the INIT_SET function. */ #define M_VAR1ANT_DEFINE_INIT_SET(name, ...) \ - static inline void M_C(name, _init_set)(M_C(name,_ct) my , \ - M_C(name,_ct) const org) { \ + static inline void M_F(name, _init_set)(M_F(name,_ct) my , \ + M_F(name,_ct) const org) { \ M_VAR1ANT_CONTRACT(name, org); \ my->type = org->type; \ switch (org->type) { \ M_MAP2(M_VAR1ANT_DEFINE_INIT_SET_FUNC, name, __VA_ARGS__) \ - case M_C(name, _EMPTY): /* fallthrough */ \ - default: M_ASSUME(org->type == M_C(name, _EMPTY)); break; \ + case M_F(name, _EMPTY): /* fallthrough */ \ + default: M_ASSUME(org->type == M_F(name, _EMPTY)); break; \ } \ } @@ -246,20 +246,20 @@ /* Define the SET function. */ #define M_VAR1ANT_DEFINE_SET(name, ...) \ - static inline void M_C(name, _set)(M_C(name,_ct) my , \ - M_C(name,_ct) const org) { \ + static inline void M_F(name, _set)(M_F(name,_ct) my , \ + M_F(name,_ct) const org) { \ M_VAR1ANT_CONTRACT(name, my); \ M_VAR1ANT_CONTRACT(name, org); \ if (my->type != org->type) { \ /* Different types: clear previous one and create new */ \ - M_C(name, _clear)(my); \ - M_C(name, _init_set)(my, org); \ + M_F(name, _clear)(my); \ + M_F(name, _init_set)(my, org); \ } else { \ /* Same type: optimize the set */ \ switch (org->type) { \ M_MAP2(M_VAR1ANT_DEFINE_SET_FUNC, name, __VA_ARGS__) \ - case M_C(name, _EMPTY): /* fallthrough */ \ - default: M_ASSUME(org->type == M_C(name, _EMPTY)); break; \ + case M_F(name, _EMPTY): /* fallthrough */ \ + default: M_ASSUME(org->type == M_F(name, _EMPTY)); break; \ } \ } \ } @@ -273,14 +273,14 @@ /* Define the CLEAR function. */ #define M_VAR1ANT_DEFINE_CLEAR(name, ...) \ - static inline void M_C(name, _clear)(M_C(name,_ct) my) { \ + static inline void M_F(name, _clear)(M_F(name,_ct) my) { \ M_VAR1ANT_CONTRACT(name, my); \ switch (my->type) { \ M_MAP2(M_VAR1ANT_DEFINE_CLEAR_FUNC, name, __VA_ARGS__) \ - case M_C(name, _EMPTY): /* fallthrough */ \ - default: M_ASSUME(my->type == M_C(name, _EMPTY)); break; \ + case M_F(name, _EMPTY): /* fallthrough */ \ + default: M_ASSUME(my->type == M_F(name, _EMPTY)); break; \ } \ - my->type = M_C(name, _EMPTY); \ + my->type = M_F(name, _EMPTY); \ } #define M_VAR1ANT_DEFINE_CLEAR_FUNC(name, a) \ @@ -291,12 +291,12 @@ /* Define the TEST_P function. */ #define M_VAR1ANT_DEFINE_TEST_P(name, ...) \ - static inline bool M_C(name, _empty_p)(M_C(name,_ct) const my) { \ + static inline bool M_F(name, _empty_p)(M_F(name,_ct) const my) { \ M_VAR1ANT_CONTRACT(name, my); \ - return my->type == M_C(name, _EMPTY); \ + return my->type == M_F(name, _EMPTY); \ } \ - static inline enum M_C(name, _enum) \ - M_C(name, _type)(M_C(name,_ct) my) { \ + static inline enum M_F(name, _enum) \ + M_F(name, _type)(M_F(name,_ct) my) { \ M_VAR1ANT_CONTRACT(name, my); \ return my->type; \ } \ @@ -304,7 +304,7 @@ #define M_VAR1ANT_DEFINE_TEST_FUNC(name, a) \ static inline bool \ - M_C4(name, _, M_VAR1ANT_GET_FIELD a, _p)(M_C(name,_ct) const my) { \ + M_C4(name, _, M_VAR1ANT_GET_FIELD a, _p)(M_F(name,_ct) const my) { \ M_VAR1ANT_CONTRACT(name, my); \ return my->type == M_C4(name, _, M_VAR1ANT_GET_FIELD a, _value); \ } @@ -316,7 +316,7 @@ #define M_VAR1ANT_DEFINE_INIT_FIELD_FUNC(name, a) \ static inline void \ - M_C3(name, _init_, M_VAR1ANT_GET_FIELD a)(M_C(name,_ct) my) { \ + M_C3(name, _init_, M_VAR1ANT_GET_FIELD a)(M_F(name,_ct) my) { \ /* Reinit variable with the given value */ \ my->type = M_C4(name, _, M_VAR1ANT_GET_FIELD a, _value); \ M_VAR1ANT_CALL_INIT(a, my -> value. M_VAR1ANT_GET_FIELD a); \ @@ -329,7 +329,7 @@ #define M_VAR1ANT_DEFINE_INIT_SETTER_FIELD_FUNC(name, a) \ static inline void \ - M_C3(name, _init_set_, M_VAR1ANT_GET_FIELD a)(M_C(name,_ct) my, \ + M_C3(name, _init_set_, M_VAR1ANT_GET_FIELD a)(M_F(name,_ct) my, \ M_VAR1ANT_GET_TYPE a const M_VAR1ANT_GET_FIELD a ) { \ my->type = M_C4(name, _, M_VAR1ANT_GET_FIELD a, _value); \ M_VAR1ANT_CALL_INIT_SET(a, my -> value. M_VAR1ANT_GET_FIELD a, \ @@ -343,14 +343,14 @@ #define M_VAR1ANT_DEFINE_SETTER_FIELD_FUNC(name, a) \ static inline void \ - M_C3(name, _set_, M_VAR1ANT_GET_FIELD a)(M_C(name,_ct) my, \ + M_C3(name, _set_, M_VAR1ANT_GET_FIELD a)(M_F(name,_ct) my, \ M_VAR1ANT_GET_TYPE a const M_VAR1ANT_GET_FIELD a ) { \ M_VAR1ANT_CONTRACT(name, my); \ if (my->type == M_C4(name, _, M_VAR1ANT_GET_FIELD a, _value) ) { \ M_VAR1ANT_CALL_SET(a, my -> value. M_VAR1ANT_GET_FIELD a, \ M_VAR1ANT_GET_FIELD a); \ } else { \ - M_C(name, _clear)(my); \ + M_F(name, _clear)(my); \ /* Reinit variable with the given value */ \ my->type = M_C4(name, _, M_VAR1ANT_GET_FIELD a, _value); \ M_VAR1ANT_CALL_INIT_SET(a, my -> value. M_VAR1ANT_GET_FIELD a, \ @@ -365,7 +365,7 @@ #define M_VAR1ANT_DEFINE_GETTER_FIELD_FUNC(name, a) \ static inline M_VAR1ANT_GET_TYPE a * \ - M_C3(name, _get_, M_VAR1ANT_GET_FIELD a)(M_C(name,_ct) my) { \ + M_C3(name, _get_, M_VAR1ANT_GET_FIELD a)(M_F(name,_ct) my) { \ M_VAR1ANT_CONTRACT(name, my); \ if (my->type != M_C4(name, _, M_VAR1ANT_GET_FIELD a, _value) ) { \ return NULL; \ @@ -374,7 +374,7 @@ } \ \ static inline M_VAR1ANT_GET_TYPE a const * \ - M_C3(name, _cget_, M_VAR1ANT_GET_FIELD a)(M_C(name,_ct) const my) { \ + M_C3(name, _cget_, M_VAR1ANT_GET_FIELD a)(M_F(name,_ct) const my) { \ M_VAR1ANT_CONTRACT(name, my); \ if (my->type != M_C4(name, _, M_VAR1ANT_GET_FIELD a, _value) ) { \ return NULL; \ @@ -393,8 +393,8 @@ #define M_VAR1ANT_MAP3_ALT_ID(a, b) a b #define M_VAR1ANT_DEFINE_EMPLACE_FUNC(name, num, a) \ - M_EMPLACE_QUEUE_DEF( (name, M_VAR1ANT_GET_FIELD a), M_C(name,_ct), M_C3(name, _init_emplace_, M_VAR1ANT_GET_FIELD a), M_VAR1ANT_GET_OPLIST a, M_VAR1ANT_DEFINE_INIT_EMPLACE_DEF) \ - M_EMPLACE_QUEUE_DEF( (name, M_VAR1ANT_GET_FIELD a), M_C(name,_ct), M_C3(name, _emplace_, M_VAR1ANT_GET_FIELD a), M_VAR1ANT_GET_OPLIST a, M_VAR1ANT_DEFINE_EMPLACE_DEF) + M_EMPLACE_QUEUE_DEF( (name, M_VAR1ANT_GET_FIELD a), M_F(name,_ct), M_C3(name, _init_emplace_, M_VAR1ANT_GET_FIELD a), M_VAR1ANT_GET_OPLIST a, M_VAR1ANT_DEFINE_INIT_EMPLACE_DEF) \ + M_EMPLACE_QUEUE_DEF( (name, M_VAR1ANT_GET_FIELD a), M_F(name,_ct), M_C3(name, _emplace_, M_VAR1ANT_GET_FIELD a), M_VAR1ANT_GET_OPLIST a, M_VAR1ANT_DEFINE_EMPLACE_DEF) #define M_VAR1ANT_DEFINE_INIT_EMPLACE_DEF(name, name_t, function_name, oplist, init_func, exp_emplace_type) \ static inline void \ @@ -418,14 +418,14 @@ static inline void \ /* Define the EQUAL_P function. */ #define M_VAR1ANT_DEFINE_EQUAL(name, ...) \ - static inline bool M_C(name, _equal_p)(M_C(name,_ct) const e1 , \ - M_C(name,_ct) const e2) { \ + static inline bool M_F(name, _equal_p)(M_F(name,_ct) const e1 , \ + M_F(name,_ct) const e2) { \ bool b; \ M_VAR1ANT_CONTRACT(name, e1); \ M_VAR1ANT_CONTRACT(name, e2); \ if (e1->type != e2->type) return false; \ switch (e1->type) { \ - case M_C(name, _EMPTY): break; \ + case M_F(name, _EMPTY): break; \ M_MAP2(M_VAR1ANT_DEFINE_EQUAL_FUNC , name, __VA_ARGS__) \ default: M_ASSUME(false); break; \ } \ @@ -442,12 +442,12 @@ static inline void \ /* Define the HASH function. */ #define M_VAR1ANT_DEFINE_HASH(name, ...) \ - static inline size_t M_C(name, _hash)(M_C(name,_ct) const e1) { \ + static inline size_t M_F(name, _hash)(M_F(name,_ct) const e1) { \ M_VAR1ANT_CONTRACT(name, e1); \ M_HASH_DECL(hash); \ M_HASH_UP (hash, (unsigned int) (e1 -> type)); \ switch (e1->type) { \ - case M_C(name, _EMPTY): break; \ + case M_F(name, _EMPTY): break; \ M_MAP2(M_VAR1ANT_DEFINE_HASH_FUNC , name, __VA_ARGS__) \ default: M_ASSUME(false); break; \ } \ @@ -463,15 +463,15 @@ static inline void \ /* Define the INIT_MOVE function. */ #define M_VAR1ANT_DEFINE_INIT_MOVE(name, ...) \ static inline void \ - M_C(name, _init_move)(M_C(name,_ct) el, M_C(name,_ct) org) { \ + M_F(name, _init_move)(M_F(name,_ct) el, M_F(name,_ct) org) { \ M_VAR1ANT_CONTRACT(name, org); \ el -> type = org -> type; \ switch (el->type) { \ - case M_C(name, _EMPTY): break; \ + case M_F(name, _EMPTY): break; \ M_MAP2(M_VAR1ANT_DEFINE_INIT_MOVE_FUNC , name, __VA_ARGS__) \ default: M_ASSUME(false); break; \ } \ - org -> type = M_C(name, _EMPTY); \ + org -> type = M_F(name, _EMPTY); \ } #define M_VAR1ANT_DEFINE_INIT_MOVE_FUNC(name, a) \ @@ -487,11 +487,11 @@ static inline void \ */ #define M_VAR1ANT_DEFINE_MOVE(name, ...) \ static inline void \ - M_C(name, _move)(M_C(name,_ct) el, M_C(name,_ct) org) { \ + M_F(name, _move)(M_F(name,_ct) el, M_F(name,_ct) org) { \ M_VAR1ANT_CONTRACT(name, el); \ M_VAR1ANT_CONTRACT(name, org); \ - M_C(name, _clear)(el); \ - M_C(name, _init_move)(el , org); \ + M_F(name, _clear)(el); \ + M_F(name, _init_move)(el , org); \ } @@ -501,10 +501,10 @@ static inline void \ #define M_VAR1ANT_DEFINE_MOVER_FUNC(name, a) \ static inline void \ - M_C3(name, _move_, M_VAR1ANT_GET_FIELD a)(M_C(name,_ct) my, \ + M_C3(name, _move_, M_VAR1ANT_GET_FIELD a)(M_F(name,_ct) my, \ M_VAR1ANT_GET_TYPE a M_VAR1ANT_GET_FIELD a ) { \ M_VAR1ANT_CONTRACT(name, my); \ - M_C(name, _clear)(my); \ + M_F(name, _clear)(my); \ /* Reinit variable with the given value */ \ my->type = M_C4(name, _, M_VAR1ANT_GET_FIELD a, _value); \ M_VAR1ANT_CALL_INIT_MOVE(a, my -> value. M_VAR1ANT_GET_FIELD a, \ @@ -515,28 +515,28 @@ static inline void \ /* Define the SWAP function */ #define M_VAR1ANT_DEFINE_SWAP(name, ...) \ static inline void \ - M_C(name, _swap)(M_C(name,_ct) el1, M_C(name,_ct) el2) { \ + M_F(name, _swap)(M_F(name,_ct) el1, M_F(name,_ct) el2) { \ M_VAR1ANT_CONTRACT(name, el1); \ M_VAR1ANT_CONTRACT(name, el2); \ if (el1->type == el2->type) { \ switch (el1->type) { \ - case M_C(name, _EMPTY): break; \ + case M_F(name, _EMPTY): break; \ M_MAP2(M_VAR1ANT_DEFINE_INIT_SWAP_FUNC , name, __VA_ARGS__) \ default: M_ASSUME(false); break; \ } \ } else { \ - M_C(name,_ct) tmp; \ + M_F(name,_ct) tmp; \ M_VAR1ANT_IF_ALL(INIT_MOVE, __VA_ARGS__) \ ( /* NOTE: Slow implementation */ \ - M_C(name, _init_move)(tmp, el1); \ - M_C(name, _init_move)(el1, el2); \ - M_C(name, _init_move)(el2, tmp); \ + M_F(name, _init_move)(tmp, el1); \ + M_F(name, _init_move)(el1, el2); \ + M_F(name, _init_move)(el2, tmp); \ , \ /* NOTE: Very slow implementation */ \ - M_C(name, _init_set)(tmp, el1); \ - M_C(name, _set)(el1, el2); \ - M_C(name, _set)(el2, tmp); \ - M_C(name, _clear)(tmp); \ + M_F(name, _init_set)(tmp, el1); \ + M_F(name, _set)(el1, el2); \ + M_F(name, _set)(el2, tmp); \ + M_F(name, _clear)(tmp); \ ) \ } \ } @@ -550,15 +550,15 @@ static inline void \ /* Define the GET_STR function */ #define M_VAR1ANT_DEFINE_GET_STR(name, ...) \ - static inline void M_C(name, _get_str)(m_string_t str, \ - M_C(name,_ct) const el, \ + static inline void M_F(name, _get_str)(m_string_t str, \ + M_F(name,_ct) const el, \ bool append) { \ M_VAR1ANT_CONTRACT(name, el); \ M_ASSERT (str != NULL); \ void (*func)(m_string_t, const char *); \ func = append ? m_string_cat_cstr : m_string_set_cstr; \ switch (el->type) { \ - case M_C(name, _EMPTY): func(str, "@EMPTY@"); break; \ + case M_F(name, _EMPTY): func(str, "@EMPTY@"); break; \ M_MAP2(M_VAR1ANT_DEFINE_GET_STR_FUNC , name, __VA_ARGS__) \ default: M_ASSUME(false); break; \ } \ @@ -574,7 +574,7 @@ static inline void \ /* Define the PARSE_STR function */ #define M_VAR1ANT_DEFINE_PARSE_STR(name, ...) \ - static inline bool M_C(name, _parse_str)(M_C(name,_ct) el, \ + static inline bool M_F(name, _parse_str)(M_F(name,_ct) el, \ const char str[], \ const char **endp) { \ M_VAR1ANT_CONTRACT(name, el); \ @@ -583,7 +583,7 @@ static inline void \ char variantTypeBuf[M_USE_IDENTIFIER_ALLOC+1]; \ int c = *str++; \ unsigned int i = 0; \ - M_C(name, _reset)(el); \ + M_F(name, _reset)(el); \ if (c != '@') goto exit; \ /* First read the name of the type */ \ c = *str++; \ @@ -596,7 +596,7 @@ static inline void \ M_ASSERT(i < sizeof(variantTypeBuf)); \ /* In function of the type */ \ if (strcmp(variantTypeBuf, "EMPTY") == 0) { \ - el->type = M_C(name, _EMPTY); \ + el->type = M_F(name, _EMPTY); \ } \ M_MAP2(M_VAR1ANT_DEFINE_PARSE_STR_FUNC , name, __VA_ARGS__) \ else goto exit; \ @@ -617,12 +617,12 @@ static inline void \ /* Define the OUT_STR function */ #define M_VAR1ANT_DEFINE_OUT_STR(name, ...) \ - static inline void M_C(name, _out_str)(FILE *f, \ - M_C(name,_ct) const el) { \ + static inline void M_F(name, _out_str)(FILE *f, \ + M_F(name,_ct) const el) { \ M_VAR1ANT_CONTRACT(name, el); \ M_ASSERT (f != NULL); \ switch (el->type) { \ - case M_C(name, _EMPTY): fprintf(f, "@EMPTY@"); break; \ + case M_F(name, _EMPTY): fprintf(f, "@EMPTY@"); break; \ M_MAP2(M_VAR1ANT_DEFINE_OUT_STR_FUNC , name, __VA_ARGS__) \ default: M_ASSUME(false); break; \ } \ @@ -638,12 +638,12 @@ static inline void \ /* Define the IN_STR function */ #define M_VAR1ANT_DEFINE_IN_STR(name, ...) \ - static inline bool M_C(name, _in_str)(M_C(name,_ct) el, \ + static inline bool M_F(name, _in_str)(M_F(name,_ct) el, \ FILE *f) { \ M_VAR1ANT_CONTRACT(name, el); \ M_ASSERT (f != NULL); \ char variantTypeBuf[M_USE_IDENTIFIER_ALLOC+1]; \ - M_C(name, _reset)(el); \ + M_F(name, _reset)(el); \ if (fgetc(f) != '@') return false; \ /* First read the name of the type */ \ bool b = true; \ @@ -658,7 +658,7 @@ static inline void \ M_ASSERT(i < sizeof(variantTypeBuf)); \ /* In function of the type */ \ if (strcmp(variantTypeBuf, "EMPTY") == 0) { \ - el->type = M_C(name, _EMPTY); \ + el->type = M_F(name, _EMPTY); \ } \ M_MAP2(M_VAR1ANT_DEFINE_IN_STR_FUNC , name, __VA_ARGS__) \ else { b = false; } \ @@ -681,8 +681,8 @@ static inline void \ /* Define the OUT_SERIAL function */ #define M_VAR1ANT_DEFINE_OUT_SERIAL(name, ...) \ static inline m_serial_return_code_t \ - M_C(name, _out_serial)(m_serial_write_t f, \ - M_C(name,_ct) const el) { \ + M_F(name, _out_serial)(m_serial_write_t f, \ + M_F(name,_ct) const el) { \ M_VAR1ANT_CONTRACT(name, el); \ const int field_max = M_NARGS(__VA_ARGS__); \ static const char *const field_name[] = \ @@ -691,7 +691,7 @@ static inline void \ m_serial_local_t local; \ m_serial_return_code_t ret; \ switch (el->type) { \ - case M_C(name, _EMPTY): \ + case M_F(name, _EMPTY): \ return f->m_interface->write_variant_start(local, f, field_name, field_max, -1); \ break; \ M_MAP2(M_VAR1ANT_DEFINE_OUT_SERIAL_FUNC , name, __VA_ARGS__) \ @@ -712,7 +712,7 @@ static inline void \ /* Define the IN_SERIAL function */ #define M_VAR1ANT_DEFINE_IN_SERIAL(name, ...) \ static inline m_serial_return_code_t \ - M_C(name, _in_serial)(M_C(name,_ct) el, \ + M_F(name, _in_serial)(M_F(name,_ct) el, \ m_serial_read_t f) { \ M_VAR1ANT_CONTRACT(name, el); \ const int field_max = M_NARGS(__VA_ARGS__); \ @@ -722,11 +722,11 @@ static inline void \ m_serial_local_t local; \ m_serial_return_code_t ret; \ int id = -1; \ - M_C(name, _reset)(el); \ + M_F(name, _reset)(el); \ ret = f->m_interface->read_variant_start(local, f, field_name, field_max, &id); \ if (ret != M_SERIAL_OK_CONTINUE) return ret; \ M_ASSERT (id >= 0 && id < field_max); \ - el->type = (enum M_C(name, _enum))(id+1); \ + el->type = (enum M_F(name, _enum))(id+1); \ switch (id+1) { \ M_MAP2(M_VAR1ANT_DEFINE_IN_SERIAL_FUNC , name, __VA_ARGS__) \ default: M_ASSUME(false); break; \ @@ -745,11 +745,11 @@ static inline void \ /* Define the RESET function */ #define M_VAR1ANT_DEFINE_RESET_FUNC(name, ...) \ - static inline void M_C(name, _reset)(M_C(name,_ct) my) \ + static inline void M_F(name, _reset)(M_F(name,_ct) my) \ { \ M_VAR1ANT_CONTRACT(name, my); \ - M_C(name, _clear)(my); \ - M_C(name, _init)(my); \ + M_F(name, _clear)(my); \ + M_F(name, _init)(my); \ } \ @@ -768,25 +768,25 @@ static inline void \ /* Define the oplist */ #define M_VAR1ANT_OPLIST_P3(name, ...) \ - (INIT(M_C(name,_init)), \ - INIT_SET(M_C(name, _init_set)), \ - SET(M_C(name,_set)), \ - CLEAR(M_C(name, _clear)), \ - RESET(M_C(name, _reset)), \ + (INIT(M_F(name,_init)), \ + INIT_SET(M_F(name, _init_set)), \ + SET(M_F(name,_set)), \ + CLEAR(M_F(name, _clear)), \ + RESET(M_F(name, _reset)), \ NAME(name), \ - TYPE(M_C(name,_ct)), \ - EMPTY_P(M_C(name,_empty_p)), \ - M_IF_METHOD_ALL(HASH, __VA_ARGS__)(HASH(M_C(name, _hash)),), \ - M_IF_METHOD_ALL(EQUAL, __VA_ARGS__)(EQUAL(M_C(name, _equal_p)),), \ - M_IF_METHOD_ALL(GET_STR, __VA_ARGS__)(GET_STR(M_C(name, _get_str)),), \ - M_IF_METHOD2_ALL(PARSE_STR, INIT, __VA_ARGS__)(PARSE_STR(M_C(name, _parse_str)),), \ - M_IF_METHOD2_ALL(IN_STR, INIT, __VA_ARGS__)(IN_STR(M_C(name, _in_str)),), \ - M_IF_METHOD_ALL(OUT_STR, __VA_ARGS__)(OUT_STR(M_C(name, _out_str)),), \ - M_IF_METHOD2_ALL(IN_SERIAL, INIT, __VA_ARGS__)(IN_SERIAL(M_C(name, _in_serial)),), \ - M_IF_METHOD_ALL(OUT_SERIAL, __VA_ARGS__)(OUT_SERIAL(M_C(name, _out_serial)),), \ - M_IF_METHOD_ALL(INIT_MOVE, __VA_ARGS__)(INIT_MOVE(M_C(name, _init_move)),), \ - M_IF_METHOD_ALL(INIT_MOVE, __VA_ARGS__)(MOVE(M_C(name, _move)),), \ - M_IF_METHOD_ALL(SWAP, __VA_ARGS__)(SWAP(M_C(name, _swap)),), \ + TYPE(M_F(name,_ct)), \ + EMPTY_P(M_F(name,_empty_p)), \ + M_IF_METHOD_ALL(HASH, __VA_ARGS__)(HASH(M_F(name, _hash)),), \ + M_IF_METHOD_ALL(EQUAL, __VA_ARGS__)(EQUAL(M_F(name, _equal_p)),), \ + M_IF_METHOD_ALL(GET_STR, __VA_ARGS__)(GET_STR(M_F(name, _get_str)),), \ + M_IF_METHOD2_ALL(PARSE_STR, INIT, __VA_ARGS__)(PARSE_STR(M_F(name, _parse_str)),), \ + M_IF_METHOD2_ALL(IN_STR, INIT, __VA_ARGS__)(IN_STR(M_F(name, _in_str)),), \ + M_IF_METHOD_ALL(OUT_STR, __VA_ARGS__)(OUT_STR(M_F(name, _out_str)),), \ + M_IF_METHOD2_ALL(IN_SERIAL, INIT, __VA_ARGS__)(IN_SERIAL(M_F(name, _in_serial)),), \ + M_IF_METHOD_ALL(OUT_SERIAL, __VA_ARGS__)(OUT_SERIAL(M_F(name, _out_serial)),), \ + M_IF_METHOD_ALL(INIT_MOVE, __VA_ARGS__)(INIT_MOVE(M_F(name, _init_move)),), \ + M_IF_METHOD_ALL(INIT_MOVE, __VA_ARGS__)(MOVE(M_F(name, _move)),), \ + M_IF_METHOD_ALL(SWAP, __VA_ARGS__)(SWAP(M_F(name, _swap)),), \ M_IF_METHOD(NEW, M_RET_ARG1(__VA_ARGS__,))(NEW(M_DELAY2(M_GET_NEW) M_RET_ARG1(__VA_ARGS__,)),), \ M_IF_METHOD(REALLOC, M_RET_ARG1(__VA_ARGS__,))(REALLOC(M_DELAY2(M_GET_REALLOC) M_RET_ARG1(__VA_ARGS__,)),), \ M_IF_METHOD(DEL, M_RET_ARG1(__VA_ARGS__,))(DEL(M_DELAY2(M_GET_DEL) M_RET_ARG1(__VA_ARGS__,)),), \ diff --git a/tests/test-mcore.c b/tests/test-mcore.c index cbf66613..887fc1d2 100644 --- a/tests/test-mcore.c +++ b/tests/test-mcore.c @@ -24,9 +24,19 @@ #include #include #include "coverage.h" + +// Override M_F for testing purpose +#define M_F(a,b) M_OVERRIDE_F(a,b) +#define M_OVERRIDE__method() , _get_method , +#define M_OVERRIDE__method2() , _get_method2 +#include "m-core.h" + #include "test-obj.h" -#include "m-core.h" +static bool tmp_init(void) { return true; } +static bool tmp_get_method(void) { return true; } +static bool tmp_get_method2(void) { return true; } +static bool tmp_clear(void) { return true; } static void test_cat(void) { @@ -42,6 +52,10 @@ static void test_cat(void) assert (M_C5_EMPTY(A,a,n,d,B)); assert (M_C5_EMPTY(Aand,,,,B)); + assert( M_F(tmp, _init)()); + assert( M_F(tmp, _method)()); + assert( M_F(tmp, _method2)()); + assert( M_F(tmp, _clear)()); } static void test_power2(void)