Rename DICT, TUPLE & VARIANT _clean in _reset to avoid confusing _clean & _clear functions. See #97

This commit is contained in:
Patrick Pelissier committed 2021-10-28 17:51:17 +02:00
1 parent 2695cd6f3e
commit 510cd062ba
7 files changed
+61 -37

No files matched your search

+8 -4
View File
@@ -2428,9 +2428,9 @@ from 'ref' and clear 'ref'.
Set the dictionary 'dict' by stealing as resource as possible Set the dictionary 'dict' by stealing as resource as possible
from 'ref' and clear 'ref'. 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) ##### 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). 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) ##### const type1 *name\_cget\_at\_element1(const name\_t tuple)
Return a constant pointer to the element 'element1' of the 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). 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) ##### void name\_init\_elementN(name\_t variant)
+22 -10
View File
@@ -411,9 +411,9 @@
} \ } \
\ \
static inline void \ 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); \ 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->lower_limit = M_D1CT_LOWER_BOUND(M_D1CT_INITIAL_SIZE); \
map->upper_limit = M_D1CT_UPPER_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); \ 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 \ static inline bool \
M_C(name,_empty_p)(const dict_t map) \ 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_C(name, _parse_str)(dict_t dict, const char str[], const char **endp) \
{ \ { \
M_ASSERT (str != NULL); \ M_ASSERT (str != NULL); \
M_C(name, _clean)(dict); \ M_C(name, _reset)(dict); \
bool success = false; \ bool success = false; \
int c = *str++; \ int c = *str++; \
if (M_UNLIKELY (c != '{')) goto exit; \ if (M_UNLIKELY (c != '{')) goto exit; \
@@ -853,7 +859,7 @@
M_C(name, _in_str)(dict_t dict, FILE *file) \ M_C(name, _in_str)(dict_t dict, FILE *file) \
{ \ { \
M_ASSERT (file != NULL); \ M_ASSERT (file != NULL); \
M_C(name, _clean)(dict); \ M_C(name, _reset)(dict); \
int c = fgetc(file); \ int c = fgetc(file); \
if (M_UNLIKELY (c != '{')) return false; \ if (M_UNLIKELY (c != '{')) return false; \
c = fgetc(file); \ c = fgetc(file); \
@@ -943,7 +949,7 @@
m_serial_return_code_t ret; \ m_serial_return_code_t ret; \
size_t estimated_size = 0; \ size_t estimated_size = 0; \
key_type key; \ key_type key; \
M_C(name,_clean)(t1); \ M_C(name,_reset)(t1); \
M_IF(isSet)( \ M_IF(isSet)( \
ret = f->m_interface->read_array_start(local, f, &estimated_size); \ ret = f->m_interface->read_array_start(local, f, &estimated_size); \
if (M_UNLIKELY (ret != M_SERIAL_OK_CONTINUE)) return ret; \ if (M_UNLIKELY (ret != M_SERIAL_OK_CONTINUE)) return ret; \
@@ -988,7 +994,7 @@
const it_deref_t *item = M_C(name, _cref)(it); \ const it_deref_t *item = M_C(name, _cref)(it); \
M_C(name, _push)(d1, *item); \ M_C(name, _push)(d1, *item); \
} \ } \
M_C(name, _clean)(d2); \ M_C(name, _reset)(d2); \
} \ } \
, \ , \
M_IF_METHOD(ADD, value_oplist)( \ M_IF_METHOD(ADD, value_oplist)( \
@@ -1008,7 +1014,7 @@
M_CALL_ADD(value_oplist, *ptr, *ptr, item->value); \ M_CALL_ADD(value_oplist, *ptr, *ptr, item->value); \
} \ } \
} \ } \
M_C(name, _clean)(d2); \ M_C(name, _reset)(d2); \
} \ } \
, /* NO UPDATE */) ) \ , /* NO UPDATE */) ) \
\ \
@@ -1051,7 +1057,7 @@
INIT_MOVE(M_C(name, _init_move)), \ INIT_MOVE(M_C(name, _init_move)), \
MOVE(M_C(name, _move)), \ MOVE(M_C(name, _move)), \
SWAP(M_C(name, _swap)), \ SWAP(M_C(name, _swap)), \
CLEAN(M_C(name, _clean)), \ CLEAN(M_C(name, _reset)), \
NAME(name), \ NAME(name), \
TYPE(M_C(name, _ct)), \ TYPE(M_C(name, _ct)), \
SUBTYPE(M_C(name, _subtype_ct)), \ SUBTYPE(M_C(name, _subtype_ct)), \
@@ -1109,7 +1115,7 @@
INIT_MOVE(M_C(name, _init_move)), \ INIT_MOVE(M_C(name, _init_move)), \
MOVE(M_C(name, _move)), \ MOVE(M_C(name, _move)), \
SWAP(M_C(name, _swap)), \ SWAP(M_C(name, _swap)), \
CLEAN(M_C(name, _clean)), \ CLEAN(M_C(name, _reset)), \
NAME(name), \ NAME(name), \
TYPE(M_C(name, _ct)), \ TYPE(M_C(name, _ct)), \
SUBTYPE(M_C(name, _subtype_ct)), \ SUBTYPE(M_C(name, _subtype_ct)), \
@@ -1781,7 +1787,7 @@ enum m_d1ct_oa_element_e {
} \ } \
\ \
static inline void \ static inline void \
M_C(name, _clean)(dict_t d) \ M_C(name, _reset)(dict_t d) \
{ \ { \
M_D1CT_OA_CONTRACT(d); \ M_D1CT_OA_CONTRACT(d); \
for(size_t i = 0; i <= d->mask; i++) { \ for(size_t i = 0; i <= d->mask; i++) { \
@@ -1804,6 +1810,12 @@ enum m_d1ct_oa_element_e {
M_D1CT_OA_CONTRACT(d); \ 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 \ static inline void \
M_C(name, _it)(dict_it_t it, const dict_t d) \ M_C(name, _it)(dict_it_t it, const dict_t d) \
{ \ { \
+6 -2
View File
@@ -629,9 +629,13 @@ namespace m_lib {
/* Define a CLEAN method by calling the CLEAN methods for all params */ /* Define a CLEAN method by calling the CLEAN methods for all params */
#define M_TUPL3_DEFINE_CLEAN(name, ...) \ #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_TUPL3_CONTRACT(el1); \
M_MAP(M_TUPL3_DEFINE_CLEAN_FUNC , __VA_ARGS__) \ 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) \ #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(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(MOVE, __VA_ARGS__)(MOVE(M_C(name, _move)),), \
M_IF_METHOD_ALL(SWAP, __VA_ARGS__)(SWAP(M_C(name, _swap)),), \ 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(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(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__,)),), \ M_IF_METHOD(DEL, M_RET_ARG1(__VA_ARGS__,))(DEL(M_DELAY2(M_GET_DEL) M_RET_ARG1(__VA_ARGS__,)),), \
+10 -6
View File
@@ -550,7 +550,7 @@
char variantTypeBuf[M_USE_IDENTIFIER_ALLOC+1]; \ char variantTypeBuf[M_USE_IDENTIFIER_ALLOC+1]; \
int c = *str++; \ int c = *str++; \
unsigned int i = 0; \ unsigned int i = 0; \
M_C(name, _clean)(el); \ M_C(name, _reset)(el); \
if (c != '@') goto exit; \ if (c != '@') goto exit; \
/* First read the name of the type */ \ /* First read the name of the type */ \
c = *str++; \ c = *str++; \
@@ -610,7 +610,7 @@
M_VAR1ANT_CONTRACT(name, el); \ M_VAR1ANT_CONTRACT(name, el); \
M_ASSERT (f != NULL); \ M_ASSERT (f != NULL); \
char variantTypeBuf[M_USE_IDENTIFIER_ALLOC+1]; \ char variantTypeBuf[M_USE_IDENTIFIER_ALLOC+1]; \
M_C(name, _clean)(el); \ M_C(name, _reset)(el); \
if (fgetc(f) != '@') return false; \ if (fgetc(f) != '@') return false; \
/* First read the name of the type */ \ /* First read the name of the type */ \
bool b = true; \ bool b = true; \
@@ -689,7 +689,7 @@
m_serial_local_t local; \ m_serial_local_t local; \
m_serial_return_code_t ret; \ m_serial_return_code_t ret; \
int id = -1; \ int id = -1; \
M_C(name, _clean)(el); \ M_C(name, _reset)(el); \
ret = f->m_interface->read_variant_start(local, f, field_name, field_max, &id); \ ret = f->m_interface->read_variant_start(local, f, field_name, field_max, &id); \
if (ret != M_SERIAL_OK_CONTINUE) return ret; \ if (ret != M_SERIAL_OK_CONTINUE) return ret; \
M_ASSERT (id >= 0 && id < field_max); \ M_ASSERT (id >= 0 && id < field_max); \
@@ -712,13 +712,17 @@
/* Define the CLEAN function */ /* Define the CLEAN function */
#define M_VAR1ANT_DEFINE_CLEAN_FUNC(name, ...) \ #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_VAR1ANT_CONTRACT(name, my); \
M_C(name, _clear)(my); \ M_C(name, _clear)(my); \
M_C(name, _init)(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 */ /* deferred evaluation of the oplist */
#define M_VAR1ANT_OPLIST_P1(arg) M_VAR1ANT_OPLIST_P2 arg #define M_VAR1ANT_OPLIST_P1(arg) M_VAR1ANT_OPLIST_P2 arg
@@ -737,7 +741,7 @@
INIT_SET(M_C(name, _init_set)), \ INIT_SET(M_C(name, _init_set)), \
SET(M_C(name,_set)), \ SET(M_C(name,_set)), \
CLEAR(M_C(name, _clear)), \ CLEAR(M_C(name, _clear)), \
CLEAN(M_C(name, _clean)), \ CLEAN(M_C(name, _reset)), \
NAME(name), \ NAME(name), \
TYPE(M_C(name,_ct)), \ TYPE(M_C(name,_ct)), \
EMPTY_P(M_C(name,_empty_p)), \ EMPTY_P(M_C(name,_empty_p)), \
+2 -2
View File
@@ -223,7 +223,7 @@ static void test_init(void)
assert (dict_str_size (d1) == 100); assert (dict_str_size (d1) == 100);
dict_str_move (d2, d3); dict_str_move (d2, d3);
assert (dict_str_size (d2) == 100); assert (dict_str_size (d2) == 100);
dict_str_clean (d2); dict_str_reset (d2);
assert (dict_str_size (d2) == 0); assert (dict_str_size (d2) == 0);
assert (dict_str_size (d1) == 100); assert (dict_str_size (d1) == 100);
@@ -425,7 +425,7 @@ static void test_init_oa(void)
assert (dict_oa_int_size (d1) == 100); assert (dict_oa_int_size (d1) == 100);
dict_oa_int_move (d2, d3); dict_oa_int_move (d2, d3);
assert (dict_oa_int_size (d2) == 100); 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_size (d2) == 0);
//assert (dict_oa_int_hash (d2) != 0); //assert (dict_oa_int_hash (d2) != 0);
+9 -9
View File
@@ -104,27 +104,27 @@ static void check_swap(void)
pair_str_clear(p2); pair_str_clear(p2);
} }
static void check_clean(void) static void check_reset(void)
{ {
single_str_t p1; single_str_t p1;
single_str_init (p1); single_str_init (p1);
string_set_str(p1->vala, "Hello"); string_set_str(p1->vala, "Hello");
single_str_clean(p1); single_str_reset(p1);
assert(string_equal_str_p (p1->vala, "")); assert(string_equal_str_p (p1->vala, ""));
single_str_clear(p1); single_str_clear(p1);
M_LET(r, rtuple_t) { M_LET(r, rtuple_t) {
string_set_str(r->name, "Hello"); string_set_str(r->name, "Hello");
rtuple_clean(r); rtuple_reset(r);
assert(string_equal_str_p (r->name, "")); assert(string_equal_str_p (r->name, ""));
} }
M_LET( (r, ("Hello"), 4), TUPLE_OPLIST(pair2_str, STRING_OPLIST, M_DEFAULT_OPLIST) ) { M_LET( (r, ("Hello"), 4), TUPLE_OPLIST(pair2_str, STRING_OPLIST, M_DEFAULT_OPLIST) ) {
assert(string_equal_str_p (r->str, "Hello")); assert(string_equal_str_p (r->str, "Hello"));
assert(r->value == 4); assert(r->value == 4);
pair2_str_clean(r); pair2_str_reset(r);
assert(string_equal_str_p (r->str, "")); 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) ) { M_LET( (q, r), TUPLE_OPLIST(pair2_str, STRING_OPLIST, M_DEFAULT_OPLIST) ) {
assert(string_equal_str_p (q->str, "Goldy")); assert(string_equal_str_p (q->str, "Goldy"));
assert(q->value == 46); assert(q->value == 46);
pair2_str_clean(q); pair2_str_reset(q);
assert(string_equal_str_p (q->str, "")); 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) ) { M_LET((r, s, 460), TUPLE_OPLIST(pair2_str, STRING_OPLIST) ) {
assert(string_equal_str_p (r->str, "Goldy McDuck")); assert(string_equal_str_p (r->str, "Goldy McDuck"));
assert(r->value == 460); assert(r->value == 460);
pair2_str_clean(r); pair2_str_reset(r);
assert(string_equal_str_p (r->str, "")); assert(string_equal_str_p (r->str, ""));
} }
@@ -151,14 +151,14 @@ static void check_clean(void)
// another level to emplace the string_t // another level to emplace the string_t
M_LET( (r, (("Two emplace"))), TUPLE_OPLIST(single_str, STRING_OPLIST) ) { M_LET( (r, (("Two emplace"))), TUPLE_OPLIST(single_str, STRING_OPLIST) ) {
assert(string_equal_str_p (r->vala, "Two emplace")); assert(string_equal_str_p (r->vala, "Two emplace"));
single_str_clean(r); single_str_reset(r);
assert(string_equal_str_p (r->vala, "")); assert(string_equal_str_p (r->vala, ""));
} }
M_LET( (s, ("Goldy McDuck") ), STRING_OPLIST) M_LET( (s, ("Goldy McDuck") ), STRING_OPLIST)
M_LET( (r, (s)), TUPLE_OPLIST(single_str, STRING_OPLIST) ) { M_LET( (r, (s)), TUPLE_OPLIST(single_str, STRING_OPLIST) ) {
assert(string_equal_str_p (r->vala, "Goldy McDuck")); assert(string_equal_str_p (r->vala, "Goldy McDuck"));
single_str_clean(r); single_str_reset(r);
assert(string_equal_str_p (r->vala, "")); assert(string_equal_str_p (r->vala, ""));
} }
@@ -285,7 +285,7 @@ int main(void)
test1(); test1();
check_io(); check_io();
check_swap(); check_swap();
check_clean(); check_reset();
check_chaining_tuple(); check_chaining_tuple();
test_double(); test_double();
exit(0); exit(0);
+4 -4
View File
@@ -90,7 +90,7 @@ static void test_pair(void)
assert(f != NULL); assert(f != NULL);
assert (*f == 42.0); assert (*f == 42.0);
pair_clean(p); pair_reset(p);
assert (pair_empty_p(p)); assert (pair_empty_p(p));
assert (!pair_key_p(p)); assert (!pair_key_p(p));
assert (!pair_value_p(p)); assert (!pair_value_p(p));
@@ -126,7 +126,7 @@ static void test_pair(void)
assert(i != NULL); assert(i != NULL);
assert (*i == 42); assert (*i == 42);
pair_clean(p); pair_reset(p);
assert (pair_empty_p(p)); assert (pair_empty_p(p));
pair_clear(p2); pair_clear(p2);
@@ -140,8 +140,8 @@ static void test_pair(void)
f = pair_get_value(p2); f = pair_get_value(p2);
assert(f != NULL); assert(f != NULL);
assert (*f == 435.0); assert (*f == 435.0);
pair_clean(p); pair_reset(p);
pair_clean(p2); pair_reset(p2);
pair_set(p2, p); pair_set(p2, p);
assert (pair_empty_p(p2)); assert (pair_empty_p(p2));