From 4bf045e3d6964b477486f4a668476d1a6f60030d Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Sun, 21 Oct 2018 22:31:22 +0200 Subject: [PATCH] Make INIT conditional for DEQUE containers. --- m-deque.h | 18 ++++++++++++++---- tests/test-mdeque.c | 3 +++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/m-deque.h b/m-deque.h index d7df406b..ff6b2993 100644 --- a/m-deque.h +++ b/m-deque.h @@ -218,6 +218,7 @@ } \ } \ \ + M_IF_METHOD(INIT, oplist)( \ static inline type * \ M_C(name, _push_back_new)(deque_t d) \ { \ @@ -227,6 +228,7 @@ } \ return p; \ } \ + , ) \ \ static inline void \ M_C(name, _push_back_move)(deque_t d, type *x) \ @@ -272,6 +274,7 @@ } \ } \ \ + M_IF_METHOD(INIT, oplist)( \ static inline type * \ M_C(name, _push_front_new)(deque_t d) \ { \ @@ -281,6 +284,7 @@ } \ return p; \ } \ + ,) \ \ static inline void \ M_C(name, _push_front_move)(deque_t d, type *x) \ @@ -327,13 +331,16 @@ DEQUEI_CONTRACT(d); \ } \ \ + M_IF_METHOD(INIT, oplist)( \ static inline void \ M_C(name, _pop_back_move)(type *ptr, deque_t d) \ { \ assert(ptr != NULL); \ - M_CALL_INIT(oplist, *ptr); \ + /* Note: Lazy implementation. Can be improved if needed */ \ + M_CALL_INIT(oplist, *ptr); \ M_C(name, _pop_back)(ptr, d); \ } \ + , ) \ \ static inline void \ M_C(name, _pop_front)(type *ptr, deque_t d) \ @@ -369,13 +376,16 @@ d->front->index = index; \ } \ \ + M_IF_METHOD(INIT, oplist)( \ static inline void \ M_C(name, _pop_front_move)(type *ptr, deque_t d) \ { \ assert(ptr != NULL); \ - M_CALL_INIT(oplist, *ptr); \ + /* Note: Lazy implementation */ \ + M_CALL_INIT(oplist, *ptr); \ M_C(name, _pop_front)(ptr, d); \ } \ + ,) \ \ static inline type * \ M_C(name, _back)(const deque_t d) \ @@ -793,7 +803,7 @@ } \ , /* no OUT_STR */ ) \ \ - M_IF_METHOD(PARSE_STR, oplist)( \ + M_IF_METHOD2(PARSE_STR, INIT, oplist)( \ static inline bool \ M_C(name, _parse_str)(deque_t deque, const char str[], const char **endp) \ { \ @@ -824,7 +834,7 @@ } \ , /* no PARSE_STR */ ) \ \ - M_IF_METHOD(IN_STR, oplist)( \ + M_IF_METHOD2(IN_STR, INIT, oplist)( \ static inline bool \ M_C(name, _in_str)(deque_t deque, FILE *file) \ { \ diff --git a/tests/test-mdeque.c b/tests/test-mdeque.c index bca914cf..9d39b766 100644 --- a/tests/test-mdeque.c +++ b/tests/test-mdeque.c @@ -33,6 +33,9 @@ DEQUE_DEF(deque, int) END_COVERAGE DEQUE_DEF(deque_mpz, testobj_t, TESTOBJ_OPLIST) +// Deque with the minimum number of methods. +DEQUE_DEF(deque_min_z, testobj_t, (INIT_SET(testobj_init_set), SET(testobj_set), CLEAR(testobj_clear))) + #define OPL DEQUE_OPLIST(deque) static void test_ti1(int n)