diff --git a/README.md b/README.md index fe36167a..fefee98f 100644 --- a/README.md +++ b/README.md @@ -2428,9 +2428,9 @@ from 'ref' and clear 'ref'. Set the dictionary 'dict' by stealing as resource as possible from 'ref' and clear 'ref'. -##### void name\_clean(name\_t dict) +##### void name\_reset(name\_t dict) -Clean the dictionary 'dict'. 'dict' remains initialized. +Reset the dictionary 'dict'. 'dict' becomes empty but remains initialized. ##### size\_t name\_size(const name\_t dict) @@ -2643,6 +2643,10 @@ This method is created only if all Oplist of the tuple define MOVE method. Clear the tuple 'tuple (aka destructor). +##### void name\_reset(name\_t tuple) + +Reset the tuple 'tuple' (applying the _reset method to all fields of the tuple). + ##### const type1 *name\_cget\_at\_element1(const name\_t tuple) Return a constant pointer to the element 'element1' of the tuple. @@ -2820,9 +2824,9 @@ This method is created only if all Oplist of the variant define MOVE method. Clear the variant 'variant (aka destructor). -##### void name\_clean(name\_t variant) +##### void name\_reset(name\_t variant) -Clean the variant 'variant and make it empty. +Reset the variant 'variant and make it empty. ##### void name\_init\_elementN(name\_t variant) diff --git a/m-dict.h b/m-dict.h index 2fc1ec6e..e0ac2c3d 100644 --- a/m-dict.h +++ b/m-dict.h @@ -411,9 +411,9 @@ } \ \ static inline void \ - M_C(name,_clean)(dict_t map) \ + M_C(name,_reset)(dict_t map) \ { \ - M_C(name, _array_list_pair_clean)(map->table); \ + M_C(name, _array_list_pair_reset)(map->table); \ M_C(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); \ @@ -421,6 +421,12 @@ M_D1CT_CONTRACT(name, map); \ } \ \ + static inline void M_ATTR_DEPRECATED \ + M_C(name,_clean)(dict_t map) \ + { \ + M_C(name, _reset)(map); \ + } \ + \ static inline bool \ M_C(name,_empty_p)(const dict_t map) \ { \ @@ -811,7 +817,7 @@ M_C(name, _parse_str)(dict_t dict, const char str[], const char **endp) \ { \ M_ASSERT (str != NULL); \ - M_C(name, _clean)(dict); \ + M_C(name, _reset)(dict); \ bool success = false; \ int c = *str++; \ if (M_UNLIKELY (c != '{')) goto exit; \ @@ -853,7 +859,7 @@ M_C(name, _in_str)(dict_t dict, FILE *file) \ { \ M_ASSERT (file != NULL); \ - M_C(name, _clean)(dict); \ + M_C(name, _reset)(dict); \ int c = fgetc(file); \ if (M_UNLIKELY (c != '{')) return false; \ c = fgetc(file); \ @@ -943,7 +949,7 @@ m_serial_return_code_t ret; \ size_t estimated_size = 0; \ key_type key; \ - M_C(name,_clean)(t1); \ + M_C(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; \ @@ -988,7 +994,7 @@ const it_deref_t *item = M_C(name, _cref)(it); \ M_C(name, _push)(d1, *item); \ } \ - M_C(name, _clean)(d2); \ + M_C(name, _reset)(d2); \ } \ , \ M_IF_METHOD(ADD, value_oplist)( \ @@ -1008,7 +1014,7 @@ M_CALL_ADD(value_oplist, *ptr, *ptr, item->value); \ } \ } \ - M_C(name, _clean)(d2); \ + M_C(name, _reset)(d2); \ } \ , /* NO UPDATE */) ) \ \ @@ -1051,7 +1057,7 @@ INIT_MOVE(M_C(name, _init_move)), \ MOVE(M_C(name, _move)), \ SWAP(M_C(name, _swap)), \ - CLEAN(M_C(name, _clean)), \ + CLEAN(M_C(name, _reset)), \ NAME(name), \ TYPE(M_C(name, _ct)), \ SUBTYPE(M_C(name, _subtype_ct)), \ @@ -1109,7 +1115,7 @@ INIT_MOVE(M_C(name, _init_move)), \ MOVE(M_C(name, _move)), \ SWAP(M_C(name, _swap)), \ - CLEAN(M_C(name, _clean)), \ + CLEAN(M_C(name, _reset)), \ NAME(name), \ TYPE(M_C(name, _ct)), \ SUBTYPE(M_C(name, _subtype_ct)), \ @@ -1781,7 +1787,7 @@ enum m_d1ct_oa_element_e { } \ \ static inline void \ - M_C(name, _clean)(dict_t d) \ + M_C(name, _reset)(dict_t d) \ { \ M_D1CT_OA_CONTRACT(d); \ for(size_t i = 0; i <= d->mask; i++) { \ @@ -1804,6 +1810,12 @@ enum m_d1ct_oa_element_e { M_D1CT_OA_CONTRACT(d); \ } \ \ + static inline void M_ATTR_DEPRECATED \ + M_C(name, _clean)(dict_t d) \ + { \ + M_C(name, _reset)(d); \ + } \ + \ static inline void \ M_C(name, _it)(dict_it_t it, const dict_t d) \ { \ diff --git a/m-tuple.h b/m-tuple.h index 703d6906..d678aa79 100644 --- a/m-tuple.h +++ b/m-tuple.h @@ -629,9 +629,13 @@ namespace m_lib { /* Define a CLEAN method by calling the CLEAN methods for all params */ #define M_TUPL3_DEFINE_CLEAN(name, ...) \ - static inline void M_C(name, _clean)(M_C(name,_ct) el1) { \ + static inline void M_C(name, _reset)(M_C(name,_ct) el1) { \ M_TUPL3_CONTRACT(el1); \ M_MAP(M_TUPL3_DEFINE_CLEAN_FUNC , __VA_ARGS__) \ + } \ + static inline void M_ATTR_DEPRECATED \ + M_C(name, _clean)(M_C(name,_ct) el1) { \ + M_C(name, _reset)(el1); \ } #define M_TUPL3_DEFINE_CLEAN_FUNC(a) \ @@ -732,7 +736,7 @@ namespace m_lib { 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(CLEAN, __VA_ARGS__)(CLEAN(M_C(name, _clean)),), \ + M_IF_METHOD_ALL(CLEAN, __VA_ARGS__)(CLEAN(M_C(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 bc61053c..94e60b2e 100644 --- a/m-variant.h +++ b/m-variant.h @@ -550,7 +550,7 @@ char variantTypeBuf[M_USE_IDENTIFIER_ALLOC+1]; \ int c = *str++; \ unsigned int i = 0; \ - M_C(name, _clean)(el); \ + M_C(name, _reset)(el); \ if (c != '@') goto exit; \ /* First read the name of the type */ \ c = *str++; \ @@ -610,7 +610,7 @@ M_VAR1ANT_CONTRACT(name, el); \ M_ASSERT (f != NULL); \ char variantTypeBuf[M_USE_IDENTIFIER_ALLOC+1]; \ - M_C(name, _clean)(el); \ + M_C(name, _reset)(el); \ if (fgetc(f) != '@') return false; \ /* First read the name of the type */ \ bool b = true; \ @@ -689,7 +689,7 @@ m_serial_local_t local; \ m_serial_return_code_t ret; \ int id = -1; \ - M_C(name, _clean)(el); \ + M_C(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); \ @@ -712,13 +712,17 @@ /* Define the CLEAN function */ #define M_VAR1ANT_DEFINE_CLEAN_FUNC(name, ...) \ - static inline void M_C(name, _clean)(M_C(name,_ct) my) \ + static inline void M_C(name, _reset)(M_C(name,_ct) my) \ { \ M_VAR1ANT_CONTRACT(name, my); \ M_C(name, _clear)(my); \ M_C(name, _init)(my); \ } \ - + static inline void M_ATTR_DEPRECATED \ + M_C(name, _clean)(M_C(name,_ct) my) \ + { \ + M_C(name, _reset)(my); \ + } /* deferred evaluation of the oplist */ #define M_VAR1ANT_OPLIST_P1(arg) M_VAR1ANT_OPLIST_P2 arg @@ -737,7 +741,7 @@ INIT_SET(M_C(name, _init_set)), \ SET(M_C(name,_set)), \ CLEAR(M_C(name, _clear)), \ - CLEAN(M_C(name, _clean)), \ + CLEAN(M_C(name, _reset)), \ NAME(name), \ TYPE(M_C(name,_ct)), \ EMPTY_P(M_C(name,_empty_p)), \ diff --git a/tests/test-mdict.c b/tests/test-mdict.c index 5e30c7d7..9c0e8e7b 100644 --- a/tests/test-mdict.c +++ b/tests/test-mdict.c @@ -223,7 +223,7 @@ static void test_init(void) assert (dict_str_size (d1) == 100); dict_str_move (d2, d3); assert (dict_str_size (d2) == 100); - dict_str_clean (d2); + dict_str_reset (d2); assert (dict_str_size (d2) == 0); assert (dict_str_size (d1) == 100); @@ -425,7 +425,7 @@ static void test_init_oa(void) assert (dict_oa_int_size (d1) == 100); dict_oa_int_move (d2, d3); assert (dict_oa_int_size (d2) == 100); - dict_oa_int_clean (d2); + dict_oa_int_reset (d2); assert (dict_oa_int_size (d2) == 0); //assert (dict_oa_int_hash (d2) != 0); diff --git a/tests/test-mtuple.c b/tests/test-mtuple.c index 3e66fa73..f186acd6 100644 --- a/tests/test-mtuple.c +++ b/tests/test-mtuple.c @@ -104,27 +104,27 @@ static void check_swap(void) pair_str_clear(p2); } -static void check_clean(void) +static void check_reset(void) { single_str_t p1; single_str_init (p1); string_set_str(p1->vala, "Hello"); - single_str_clean(p1); + single_str_reset(p1); assert(string_equal_str_p (p1->vala, "")); single_str_clear(p1); M_LET(r, rtuple_t) { string_set_str(r->name, "Hello"); - rtuple_clean(r); + rtuple_reset(r); assert(string_equal_str_p (r->name, "")); } M_LET( (r, ("Hello"), 4), TUPLE_OPLIST(pair2_str, STRING_OPLIST, M_DEFAULT_OPLIST) ) { assert(string_equal_str_p (r->str, "Hello")); assert(r->value == 4); - pair2_str_clean(r); + pair2_str_reset(r); assert(string_equal_str_p (r->str, "")); } @@ -133,7 +133,7 @@ static void check_clean(void) M_LET( (q, r), TUPLE_OPLIST(pair2_str, STRING_OPLIST, M_DEFAULT_OPLIST) ) { assert(string_equal_str_p (q->str, "Goldy")); assert(q->value == 46); - pair2_str_clean(q); + pair2_str_reset(q); assert(string_equal_str_p (q->str, "")); } @@ -142,7 +142,7 @@ static void check_clean(void) M_LET((r, s, 460), TUPLE_OPLIST(pair2_str, STRING_OPLIST) ) { assert(string_equal_str_p (r->str, "Goldy McDuck")); assert(r->value == 460); - pair2_str_clean(r); + pair2_str_reset(r); assert(string_equal_str_p (r->str, "")); } @@ -151,14 +151,14 @@ static void check_clean(void) // another level to emplace the string_t M_LET( (r, (("Two emplace"))), TUPLE_OPLIST(single_str, STRING_OPLIST) ) { assert(string_equal_str_p (r->vala, "Two emplace")); - single_str_clean(r); + single_str_reset(r); assert(string_equal_str_p (r->vala, "")); } M_LET( (s, ("Goldy McDuck") ), STRING_OPLIST) M_LET( (r, (s)), TUPLE_OPLIST(single_str, STRING_OPLIST) ) { assert(string_equal_str_p (r->vala, "Goldy McDuck")); - single_str_clean(r); + single_str_reset(r); assert(string_equal_str_p (r->vala, "")); } @@ -285,7 +285,7 @@ int main(void) test1(); check_io(); check_swap(); - check_clean(); + check_reset(); check_chaining_tuple(); test_double(); exit(0); diff --git a/tests/test-mvariant.c b/tests/test-mvariant.c index 9db1a2a6..e7facb97 100644 --- a/tests/test-mvariant.c +++ b/tests/test-mvariant.c @@ -90,7 +90,7 @@ static void test_pair(void) assert(f != NULL); assert (*f == 42.0); - pair_clean(p); + pair_reset(p); assert (pair_empty_p(p)); assert (!pair_key_p(p)); assert (!pair_value_p(p)); @@ -126,7 +126,7 @@ static void test_pair(void) assert(i != NULL); assert (*i == 42); - pair_clean(p); + pair_reset(p); assert (pair_empty_p(p)); pair_clear(p2); @@ -140,8 +140,8 @@ static void test_pair(void) f = pair_get_value(p2); assert(f != NULL); assert (*f == 435.0); - pair_clean(p); - pair_clean(p2); + pair_reset(p); + pair_reset(p2); pair_set(p2, p); assert (pair_empty_p(p2));