From e10c3586a3a1beb1137fe9c6195528af2dbc8259 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Thu, 28 Oct 2021 18:13:00 +0200 Subject: [PATCH] Rename BITSET & CONCURRENT _clean in _reset to avoid confusing _clean & _clear functions. See #97 --- README.md | 12 ++++++------ m-bitset.h | 16 +++++++++++----- m-concurrent.h | 9 +++++++-- tests/test-mbitset.c | 8 ++++---- tests/test-mconcurrent.c | 2 ++ 5 files changed, 30 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 7202f055..47489e45 100644 --- a/README.md +++ b/README.md @@ -4566,9 +4566,9 @@ Clear the list 'list (aka destructor). The list can't be used anymore, except wi If the DEL operator is available in the oplist of the type, the cleared object will also be deleted. -##### void name\_clean(name\_t list) +##### void name\_reset(name\_t list) -Clean the list (the list becomes empty). The list remains initialized but is empty. +Reset the list (the list becomes empty). The list remains initialized but is empty. If the DEL operator is available in the oplist of the type, the cleared object will also be deleted. @@ -4784,9 +4784,9 @@ Set the container with the value of 'src' by stealing as much resources from 'sr Afterwards 'src' is cleared. This method is only defined if the base container exports the MOVE operator. -##### void name\_clean(name\_t concurrent) +##### void name\_reset(name\_t concurrent) -Clean the concurrent container. +Reset the concurrent container. Afterwards the container is empty, but remains initialized. This method is only defined if the base container exports the CLEAN operator. @@ -4975,9 +4975,9 @@ Afterwards 'ref' is cleared. Clear the bitset 'array (aka destructor). -##### void bitset\_clean(bitset\_t array) +##### void bitset\_reset(bitset\_t array) -Clean the bitset (the bitset becomes empty but remains initialized). +Reset the bitset (the bitset becomes empty but remains initialized). ##### void bitset\_push\_back(bitset\_t array, const bool value) diff --git a/m-bitset.h b/m-bitset.h index 68b784ad..a957824b 100644 --- a/m-bitset.h +++ b/m-bitset.h @@ -94,17 +94,23 @@ bitset_init(bitset_t t) /* Clean a bitset */ static inline void -bitset_clean(bitset_t t) +bitset_reset(bitset_t t) { M_B1TSET_CONTRACT(t); t->size = 0; } +static inline void M_ATTR_DEPRECATED +bitset_clean(bitset_t t) +{ + bitset_reset(t); +} + /* Clear a bitset (DESTRUCTOR) */ static inline void bitset_clear(bitset_t t) { - bitset_clean(t); + bitset_reset(t); M_MEMORY_FREE(t->ptr); // This is not really needed, but is safer // This representation is invalid and will be detected by the contract. @@ -629,7 +635,7 @@ bitset_in_str(bitset_t set, FILE *file) { M_B1TSET_CONTRACT (set); M_ASSERT(file != NULL); - bitset_clean(set); + bitset_reset(set); int c = fgetc(file); if (M_UNLIKELY (c != '[')) return false; c = fgetc(file); @@ -649,7 +655,7 @@ bitset_parse_str(bitset_t set, const char str[], const char **endptr) M_B1TSET_CONTRACT (set); M_ASSERT(str != NULL); bool success = false; - bitset_clean(set); + bitset_reset(set); char c = *str++; if (M_UNLIKELY(c != '[')) goto exit; c = *str++; @@ -841,7 +847,7 @@ bitset_popcount(const bitset_t set) ,IT_NEXT(bitset_next) \ ,IT_PREVIOUS(bitset_previous) \ ,IT_CREF(bitset_cref) \ - ,CLEAN(bitset_clean) \ + ,CLEAN(bitset_reset) \ ,PUSH(bitset_push_back) \ ,POP(bitset_pop_back) \ ,HASH(bitset_hash) \ diff --git a/m-concurrent.h b/m-concurrent.h index 7cd0237b..c7685ed2 100644 --- a/m-concurrent.h +++ b/m-concurrent.h @@ -109,7 +109,7 @@ ,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(CLEAN, oplist)(CLEAN(M_C(name,_clean)),) \ + ,M_IF_METHOD(CLEAN, oplist)(CLEAN(M_C(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),) \ @@ -416,13 +416,18 @@ \ M_IF_METHOD(CLEAN, oplist)( \ static inline void \ - M_C(name, _clean)(concurrent_t out) \ + M_C(name, _reset)(concurrent_t out) \ { \ M_C0NCURRENT_CONTRACT(out); \ M_C(name, _write_lock)(out); \ M_CALL_CLEAN(oplist, out->data); \ M_C(name, _write_unlock)(out); \ } \ + static inline void M_ATTR_DEPRECATED \ + M_C(name, _clean)(concurrent_t out) \ + { \ + M_C(name,_reset)(out); \ + } \ ,) \ \ M_IF_METHOD(EMPTY_P, oplist)( \ diff --git a/tests/test-mbitset.c b/tests/test-mbitset.c index c65f43d3..a0c0b6d2 100644 --- a/tests/test-mbitset.c +++ b/tests/test-mbitset.c @@ -46,7 +46,7 @@ static void test1(void) bitset_t set2; bitset_init_set(set2, set); - bitset_clean(set); + bitset_reset(set); assert(bitset_size(set) == 0); assert(bitset_empty_p(set) == true); @@ -135,7 +135,7 @@ static void test1(void) assert (*sp == 0); bitset_clear(set3); - bitset_clean(set); + bitset_reset(set); for(int i = 0; i < 200; i++) bitset_push_back(set, ((size_t) i*17547854547UL)&1) ; bitset_it_t it; @@ -164,7 +164,7 @@ static void test1(void) bitset_reserve(set, 0); assert(bitset_capacity (set) > 0); - bitset_clean(set); + bitset_reset(set); bitset_reserve(set, 0); assert(bitset_capacity (set) == 0); @@ -217,7 +217,7 @@ static void test1(void) assert (bitset_hash(set) != 0); - bitset_clean(set); + bitset_reset(set); bitset_it(it, set); assert(bitset_end_p(it)); assert(bitset_last_p(it)); diff --git a/tests/test-mconcurrent.c b/tests/test-mconcurrent.c index 3723d83a..7d839d8c 100644 --- a/tests/test-mconcurrent.c +++ b/tests/test-mconcurrent.c @@ -217,10 +217,12 @@ static void test_double(void) { ConcurrentDouble d; ConcurrentDouble_init(d); + ConcurrentDouble_reset(d); ConcurrentDouble_clear(d); ConcurrentRpDouble r; ConcurrentRpDouble_init(r); + ConcurrentRpDouble_reset(r); ConcurrentRpDouble_clear(r); }