From 2ef7f5b8f02d4a4b20c113ae0f5251ba1b58561d Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Sat, 26 Jul 2025 10:44:21 +0200 Subject: [PATCH] Fix issue of M_LET with LIST_BIF containers. --- m-list.h | 15 ++++++++++----- tests/test-mlist.c | 13 ++++++------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/m-list.h b/m-list.h index aa4e63cc..b5536d95 100644 --- a/m-list.h +++ b/m-list.h @@ -84,6 +84,10 @@ ((__VA_ARGS__, M_BASIC_OPLIST ), \ (__VA_ARGS__ ))) +/* Define the oplist of a list of the given type. + USAGE: LIST_BIF_OPLIST(name [, oplist_of_the_type]) */ +#define M_LIST_BIF_OPLIST(...) M_OPEXTEND(M_LIST_OPLIST(__VA_ARGS__), REVERSE(0)) + /* Define an init value to init global variables of type list. USAGE: list_t global_variable = LIST_INIT_VALUE(); @@ -144,8 +148,8 @@ IT_INSERT(M_F(name, _insert)), \ IT_REMOVE(M_F(name,_remove)), \ RESET(M_F(name,_reset)), \ - PUSH(M_F(name,_push)), \ - POP(M_F(name,_pop)), \ + PUSH(M_F(name,_push)), \ + POP(M_F(name,_pop)), \ PUSH_MOVE(M_F(name,_push_move)), \ POP_MOVE(M_F(name,_pop_move)) \ ,SPLICE_BACK(M_F(name,_splice_back)) \ @@ -188,8 +192,8 @@ IT_INSERT(API_0P(M_F(name, _insert))), \ IT_REMOVE(API_0P(M_F(name,_remove))), \ RESET(API_0P(M_F(name,_reset))), \ - PUSH(API_0P(M_F(name,_push))), \ - POP(API_0P(M_F(name,_pop))), \ + PUSH(API_0P(M_F(name,_push))), \ + POP(API_0P(M_F(name,_pop))), \ PUSH_MOVE(API_0P(M_F(name,_push_move))), \ POP_MOVE(API_0P(M_F(name,_pop_move))) \ ,SPLICE_BACK(M_F(name,_splice_back)) \ @@ -1451,7 +1455,7 @@ M_INLINE void \ M_F(name, _splice_back)(list_t list1, list_t list2, it_t it) \ { \ - /* FIXME back ==> strong */ \ + /* FIXME back ==> strong */ \ M_L1ST_DUAL_PUSH_CONTRACT(list1); \ M_L1ST_DUAL_PUSH_CONTRACT(list2); \ M_ASSERT (it->current != NULL); \ @@ -1601,6 +1605,7 @@ #define LIST_BIF_DEF M_LIST_BIF_DEF #define LIST_BIF_DEF_AS M_LIST_BIF_DEF_AS #define LIST_OPLIST M_LIST_OPLIST +#define LIST_BIF_OPLIST M_LIST_BIF_OPLIST #define LIST_INIT_VALUE M_LIST_INIT_VALUE #define LIST_DUAL_PUSH_INIT_VALUE M_LIST_DUAL_PUSH_INIT_VALUE #endif diff --git a/tests/test-mlist.c b/tests/test-mlist.c index 05225936..02a4df03 100644 --- a/tests/test-mlist.c +++ b/tests/test-mlist.c @@ -603,16 +603,15 @@ static void test_bif(void) assert(d == 2.0); assert(list2f_double_empty_p(x)); list2f_double_clear(x); - // BUG: M_INIT_WITH_VAI23_FUNC uses _back instead of _strong... - // How to fix? Create common functions also for array... - M_LET( (y, (1.0, 2.0, 3.0, 4.0)), LIST_OPLIST(list2f_double, M_BASIC_OPLIST)) { + M_LET( (y, (1.0, 2.0, 3.0, 4.0)), LIST_BIF_OPLIST(list2f_double, M_BASIC_OPLIST)) { assert(list2f_double_size(y) == 4); - for(list2f_double_it(it, y); !list2f_double_end_p(it); list2f_double_next(it)){ - printf("%f ", *list2f_double_cref(it) ); - } printf("\n"); - printf("Front=%f\n", *list2f_double_front(y) ); assert(*list2f_double_front(y) == 1.0); assert(*list2f_double_back(y) == 4.0); + d = 1.0; + for(list2f_double_it(it, y); !list2f_double_end_p(it); list2f_double_next(it)){ + assert( *list2f_double_cref(it) == d); + d += 1.0; + } } }