Remove ilist_ prefix from Intrusive List

See commit on Shared Pointer
Additional Fix:* the iterator name is also impacted
and shall be converted in the sources (_it_ change from being a prefix to a suffix).
This commit is contained in:
Patrick Pelissier committed 2017-07-25 22:27:48 +02:00
1 parent ad27d331a1
commit da9d87bf4b
2 files changed
+66 -63

No files matched your search

+60 -57
View File
@@ -44,8 +44,8 @@
LIST_DEF(name, type [, oplist_of_the_type]) */ LIST_DEF(name, type [, oplist_of_the_type]) */
#define ILIST_DEF(name, ...) \ #define ILIST_DEF(name, ...) \
M_IF_NARGS_EQ1(__VA_ARGS__) \ M_IF_NARGS_EQ1(__VA_ARGS__) \
(ILISTI_DEF2(name, __VA_ARGS__, M_DEFAULT_OPLIST, M_C3(ilist_, name, _t), M_C3(ilist_it_, name, _t) ), \ (ILISTI_DEF2(name, __VA_ARGS__, M_DEFAULT_OPLIST, M_C(name, _t), M_C(name, _it_t) ), \
ILISTI_DEF2(name, __VA_ARGS__, M_C3(ilist_, name, _t), M_C3(ilist_it_, name, _t) )) ILISTI_DEF2(name, __VA_ARGS__, M_C(name, _t), M_C(name, _it_t) ))
/* Define the oplist of a ilist of type. /* Define the oplist of a ilist of type.
USAGE: LIST_OPLIST(name [, oplist_of_the_type]) */ USAGE: LIST_OPLIST(name [, oplist_of_the_type]) */
@@ -65,69 +65,70 @@ typedef struct ilist_head_s {
/* Define the oplist of an ilist of type */ /* Define the oplist of an ilist of type */
#define ILISTI_OPLIST(name,oplist) \ #define ILISTI_OPLIST(name,oplist) \
(INIT(M_C3(ilist_, name, _init)), \ (INIT(M_C(name, _init)), \
CLEAR(M_C3(ilist_, name, _clear)), \ CLEAR(M_C(name, _clear)), \
TYPE(M_C3(ilist_,name,_t)), \ TYPE(M_C(name,_t)), \
SUBTYPE(M_C3(ilist_type_,name,_t)), \ SUBTYPE(M_C(name,_type_t)), \
IT_TYPE(M_C3(ilist_it_,name,_t)), \ IT_TYPE(M_C(name,_it_t)), \
IT_FIRST(M_C3(ilist_,name,_it)), \ IT_FIRST(M_C(name,_it)), \
IT_SET(M_C3(ilist_,name,_it_set)), \ IT_SET(M_C(name,_it_set)), \
IT_LAST(M_C3(ilist_,name,_it_last)), \ IT_LAST(M_C(name,_it_last)), \
IT_END(M_C3(ilist_,name,_it_end)), \ IT_END(M_C(name,_it_end)), \
IT_END_P(M_C3(ilist_,name,_end_p)), \ IT_END_P(M_C(name,_end_p)), \
IT_LAST_P(M_C3(ilist_,name,_last_p)), \ IT_LAST_P(M_C(name,_last_p)), \
IT_EQUAL_P(M_C3(ilist_,name,_it_equal_p)), \ IT_EQUAL_P(M_C(name,_it_equal_p)), \
IT_NEXT(M_C3(ilist_,name,_next)), \ IT_NEXT(M_C(name,_next)), \
IT_PREVIOUS(M_C3(ilist_,name,_previous)), \ IT_PREVIOUS(M_C(name,_previous)), \
IT_REF(M_C3(ilist_,name,_ref)), \ IT_REF(M_C(name,_ref)), \
IT_CREF(M_C3(ilist_,name,_cref)), \ IT_CREF(M_C(name,_cref)), \
OPLIST(oplist), \ OPLIST(oplist), \
PUSH(M_C3(ilist_,name,_push_back)), \ PUSH(M_C(name,_push_back)), \
POP(M_C3(ilist_,name,_pop_back)) \ POP(M_C(name,_pop_back)) \
,M_IF_METHOD(NEW, oplist)(NEW(M_GET_NEW oplist),) \ ,M_IF_METHOD(NEW, oplist)(NEW(M_GET_NEW oplist),) \
,M_IF_METHOD(REALLOC, oplist)(REALLOC(M_GET_REALLOC oplist),) \ ,M_IF_METHOD(REALLOC, oplist)(REALLOC(M_GET_REALLOC oplist),) \
,M_IF_METHOD(DEL, oplist)(DEL(M_GET_DEL oplist),) \ ,M_IF_METHOD(DEL, oplist)(DEL(M_GET_DEL oplist),) \
) )
#define ILISTI_DEF2(name, type, oplist, list_t, list_it_t) \ #define ILISTI_DEF2(name, type, oplist, list_t, list_it_t) \
typedef struct M_C3(ilist_, name, _s) { \ \
typedef struct M_C(name, _s) { \
struct ilist_head_s name; \ struct ilist_head_s name; \
} list_t[1]; \ } list_t[1]; \
\ \
typedef type M_C3(ilist_type_,name, _t); \ typedef type M_C(name, _type_t); \
\ \
typedef struct M_C3(ilist_it_, name, _s) { \ typedef struct M_C(name, _it_s) { \
struct ilist_head_s *head; \ struct ilist_head_s *head; \
struct ilist_head_s *previous; \ struct ilist_head_s *previous; \
struct ilist_head_s *current; \ struct ilist_head_s *current; \
struct ilist_head_s *next; \ struct ilist_head_s *next; \
} list_it_t[1]; \ } list_it_t[1]; \
\ \
static inline void M_C3(ilist_, name, _init)(list_t list) \ static inline void M_C(name, _init)(list_t list) \
{ \ { \
assert (list != NULL); \ assert (list != NULL); \
list->name.next = &list->name; \ list->name.next = &list->name; \
list->name.prev = &list->name; \ list->name.prev = &list->name; \
} \ } \
\ \
static inline void M_C3(ilist_, name, _clean)(list_t list) \ static inline void M_C(name, _clean)(list_t list) \
{ \ { \
assert (list != NULL); \ assert (list != NULL); \
list->name.next = &list->name; \ list->name.next = &list->name; \
list->name.prev = &list->name; \ list->name.prev = &list->name; \
} \ } \
\ \
static inline void M_C3(ilist_, name, _clear)(list_t list) \ static inline void M_C(name, _clear)(list_t list) \
{ \ { \
M_C3(ilist_, name, _clean)(list); \ M_C(name, _clean)(list); \
} \ } \
\ \
static inline bool M_C3(ilist_, name, _empty_p)(const list_t list) \ static inline bool M_C(name, _empty_p)(const list_t list) \
{ \ { \
return list->name.next == &list->name; \ return list->name.next == &list->name; \
} \ } \
\ \
static inline size_t M_C3(ilist_, name, _size)(const list_t list) \ static inline size_t M_C(name, _size)(const list_t list) \
{ \ { \
size_t s = 0; \ size_t s = 0; \
for(const struct ilist_head_s *it = list->name.next ; \ for(const struct ilist_head_s *it = list->name.next ; \
@@ -136,7 +137,7 @@ typedef struct ilist_head_s {
return s; \ return s; \
} \ } \
\ \
static inline void M_C3(ilist_, name, _push_back)(list_t list, \ static inline void M_C(name, _push_back)(list_t list, \
type *obj) \ type *obj) \
{ \ { \
assert (list != NULL && obj != NULL); \ assert (list != NULL && obj != NULL); \
@@ -147,7 +148,7 @@ typedef struct ilist_head_s {
prev->next = &obj->name; \ prev->next = &obj->name; \
} \ } \
\ \
static inline void M_C3(ilist_, name, _push_front)(list_t list, \ static inline void M_C(name, _push_front)(list_t list, \
type *obj) \ type *obj) \
{ \ { \
assert (list != NULL && obj != NULL); \ assert (list != NULL && obj != NULL); \
@@ -158,7 +159,7 @@ typedef struct ilist_head_s {
next->prev = &obj->name; \ next->prev = &obj->name; \
} \ } \
\ \
static inline void M_C3(ilist_, name, _push_after)(type *obj_it, \ static inline void M_C(name, _push_after)(type *obj_it, \
type *obj_ins) \ type *obj_ins) \
{ \ { \
assert (obj_it != NULL && obj_ins != NULL); \ assert (obj_it != NULL && obj_ins != NULL); \
@@ -169,14 +170,14 @@ typedef struct ilist_head_s {
next->prev = &obj_ins->name; \ next->prev = &obj_ins->name; \
} \ } \
\ \
static inline void M_C3(ilist_, name, _init_field)(type *obj) \ static inline void M_C(name, _init_field)(type *obj) \
{ \ { \
assert (obj != NULL); \ assert (obj != NULL); \
obj->name.next = NULL; \ obj->name.next = NULL; \
obj->name.prev = NULL; \ obj->name.prev = NULL; \
} \ } \
\ \
static inline void M_C3(ilist_, name, _unlink)(type *obj) \ static inline void M_C(name, _unlink)(type *obj) \
{ \ { \
assert (obj != NULL); \ assert (obj != NULL); \
struct ilist_head_s *next = obj->name.next; \ struct ilist_head_s *next = obj->name.next; \
@@ -189,23 +190,23 @@ typedef struct ilist_head_s {
} \ } \
\ \
static inline type * \ static inline type * \
M_C3(ilist_, name, _back)(const list_t list) \ M_C(name, _back)(const list_t list) \
{ \ { \
assert(list != NULL && !M_C3(ilist_, name, _empty_p)(list)); \ assert(list != NULL && !M_C(name, _empty_p)(list)); \
return M_TYPE_FROM_FIELD(type, list->name.prev, \ return M_TYPE_FROM_FIELD(type, list->name.prev, \
struct ilist_head_s, name); \ struct ilist_head_s, name); \
} \ } \
\ \
static inline type * \ static inline type * \
M_C3(ilist_, name, _front)(const list_t list) \ M_C(name, _front)(const list_t list) \
{ \ { \
assert(list != NULL && !M_C3(ilist_, name, _empty_p)(list)); \ assert(list != NULL && !M_C(name, _empty_p)(list)); \
return M_TYPE_FROM_FIELD(type, list->name.next, \ return M_TYPE_FROM_FIELD(type, list->name.next, \
struct ilist_head_s, name); \ struct ilist_head_s, name); \
} \ } \
\ \
static inline void \ static inline void \
M_C3(ilist_, name, _it)(list_it_t it, list_t list) \ M_C(name, _it)(list_it_t it, list_t list) \
{ \ { \
assert (it != NULL && list != NULL); \ assert (it != NULL && list != NULL); \
assert (list->name.next != NULL && list->name.next->next != NULL); \ assert (list->name.next != NULL && list->name.next->next != NULL); \
@@ -216,7 +217,7 @@ typedef struct ilist_head_s {
} \ } \
\ \
static inline void \ static inline void \
M_C3(ilist_, name, _it_set)(list_it_t it, const list_it_t cit) \ M_C(name, _it_set)(list_it_t it, const list_it_t cit) \
{ \ { \
assert (it != NULL && cit != NULL); \ assert (it != NULL && cit != NULL); \
it->head = cit->head; \ it->head = cit->head; \
@@ -226,7 +227,7 @@ typedef struct ilist_head_s {
} \ } \
\ \
static inline void \ static inline void \
M_C3(ilist_, name, _it_last)(list_it_t it, list_t list) \ M_C(name, _it_last)(list_it_t it, list_t list) \
{ \ { \
assert (it != NULL && list != NULL); \ assert (it != NULL && list != NULL); \
assert (list->name.next != NULL && list->name.next->next != NULL); \ assert (list->name.next != NULL && list->name.next->next != NULL); \
@@ -237,7 +238,7 @@ typedef struct ilist_head_s {
} \ } \
\ \
static inline void \ static inline void \
M_C3(ilist_, name, _it_end)(list_it_t it, list_t list) \ M_C(name, _it_end)(list_it_t it, list_t list) \
{ \ { \
assert (it != NULL && list != NULL); \ assert (it != NULL && list != NULL); \
it->head = &list->name; \ it->head = &list->name; \
@@ -247,21 +248,21 @@ typedef struct ilist_head_s {
} \ } \
\ \
static inline bool \ static inline bool \
M_C3(ilist_, name, _end_p)(const list_it_t it) \ M_C(name, _end_p)(const list_it_t it) \
{ \ { \
assert (it != NULL); \ assert (it != NULL); \
return it->current == it->head; \ return it->current == it->head; \
} \ } \
\ \
static inline bool \ static inline bool \
M_C3(ilist_, name, _last_p)(const list_it_t it) \ M_C(name, _last_p)(const list_it_t it) \
{ \ { \
assert (it != NULL); \ assert (it != NULL); \
return it->next == it->head || it->current == it->head; \ return it->next == it->head || it->current == it->head; \
} \ } \
\ \
static inline void \ static inline void \
M_C3(ilist_, name, _next)(list_it_t it) \ M_C(name, _next)(list_it_t it) \
{ \ { \
assert (it != NULL); \ assert (it != NULL); \
/* Note: Can't set it->previous to it->current. \ /* Note: Can't set it->previous to it->current. \
@@ -274,7 +275,7 @@ typedef struct ilist_head_s {
} \ } \
\ \
static inline void \ static inline void \
M_C3(ilist_, name, _previous)(list_it_t it) \ M_C(name, _previous)(list_it_t it) \
{ \ { \
assert (it != NULL); \ assert (it != NULL); \
/* Note: Can't set it->next to it->current. \ /* Note: Can't set it->next to it->current. \
@@ -287,7 +288,7 @@ typedef struct ilist_head_s {
} \ } \
\ \
static inline bool \ static inline bool \
M_C3(ilist_, name, _it_equal_p)(const list_it_t it1, const list_it_t it2 ) \ M_C(name, _it_equal_p)(const list_it_t it1, const list_it_t it2 ) \
{ \ { \
assert (it1 != NULL && it2 != NULL); \ assert (it1 != NULL && it2 != NULL); \
/* No need to check for next & previous */ \ /* No need to check for next & previous */ \
@@ -295,42 +296,44 @@ typedef struct ilist_head_s {
} \ } \
\ \
static inline type * \ static inline type * \
M_C3(ilist_, name, _ref)(const list_it_t it) \ M_C(name, _ref)(const list_it_t it) \
{ \ { \
assert (it != NULL && it->current != NULL); \ assert (it != NULL && it->current != NULL); \
/* check if 'it' was not deleted */ \ /* check if 'it' was not deleted */ \
assert (it->current->next == it->next); \ assert (it->current->next == it->next); \
assert (it->current->prev == it->previous); \ assert (it->current->prev == it->previous); \
assert (!M_C3(ilist_, name, _end_p)(it)); \ assert (!M_C(name, _end_p)(it)); \
return M_TYPE_FROM_FIELD(type, it->current, \ return M_TYPE_FROM_FIELD(type, it->current, \
struct ilist_head_s, name); \ struct ilist_head_s, name); \
} \ } \
\ \
static inline const type * \ static inline const type * \
M_C3(ilist_, name, _cref)(const list_it_t it) \ M_C(name, _cref)(const list_it_t it) \
{ \ { \
type *ptr = M_C3(ilist_, name, _ref)(it); \ type *ptr = M_C(name, _ref)(it); \
return M_CONST_CAST(type, ptr); \ return M_CONST_CAST(type, ptr); \
} \ } \
\ \
static inline type * \ static inline type * \
M_C3(ilist_, name, _pop_back)(list_t list) \ M_C(name, _pop_back)(list_t list) \
{ \ { \
assert (!M_C3(ilist_, name, _empty_p)(list)); \ assert (!M_C(name, _empty_p)(list)); \
type *obj = M_C3(ilist_, name, _back)(list); \ type *obj = M_C(name, _back)(list); \
list->name.prev = list->name.prev->prev; \ list->name.prev = list->name.prev->prev; \
list->name.prev->next = &list->name; \ list->name.prev->next = &list->name; \
return obj; \ return obj; \
} \ } \
\ \
static inline type * \ static inline type * \
M_C3(ilist_, name, _pop_front)(list_t list) \ M_C(name, _pop_front)(list_t list) \
{ \ { \
assert (!M_C3(ilist_, name, _empty_p)(list)); \ assert (!M_C(name, _empty_p)(list)); \
type *obj = M_C3(ilist_, name, _front)(list); \ type *obj = M_C(name, _front)(list); \
list->name.next = list->name.next->next; \ list->name.next = list->name.next->next; \
list->name.next->prev = &list->name; \ list->name.next->prev = &list->name; \
return obj; \ return obj; \
} \ } \
// TODO: splice & splice_back
#endif #endif
+6 -6
View File
@@ -28,12 +28,12 @@
typedef struct test_s { typedef struct test_s {
int n; int n;
ILIST_INTERFACE (tname, struct test_s); ILIST_INTERFACE (ilist_tname, struct test_s);
} test_t; } test_t;
#include "coverage.h" #include "coverage.h"
START_COVERAGE START_COVERAGE
ILIST_DEF(tname, test_t) ILIST_DEF(ilist_tname, test_t)
END_COVERAGE END_COVERAGE
static void test(void) static void test(void)
@@ -58,12 +58,12 @@ static void test(void)
assert (ilist_tname_back (list)->n == 3); assert (ilist_tname_back (list)->n == 3);
int n = 1; int n = 1;
for M_EACH(item, list, ILIST_OPLIST(tname)) { for M_EACH(item, list, ILIST_OPLIST(ilist_tname)) {
assert (n == item->n); assert (n == item->n);
n++; n++;
} }
assert (n == 4); assert (n == 4);
ilist_it_tname_t it1, it2; ilist_tname_it_t it1, it2;
ilist_tname_it_last(it1, list); ilist_tname_it_last(it1, list);
assert (!ilist_tname_end_p(it1)); assert (!ilist_tname_end_p(it1));
assert (ilist_tname_last_p(it1)); assert (ilist_tname_last_p(it1));
@@ -80,7 +80,7 @@ static void test(void)
ilist_tname_it_set(it2, it1); ilist_tname_it_set(it2, it1);
assert (ilist_tname_it_equal_p(it1, it2)); assert (ilist_tname_it_equal_p(it1, it2));
for M_EACH(item, list, ILIST_OPLIST(tname)) { for M_EACH(item, list, ILIST_OPLIST(ilist_tname)) {
if (item->n == 2) if (item->n == 2)
ilist_tname_unlink(item); ilist_tname_unlink(item);
} }
@@ -91,7 +91,7 @@ static void test(void)
assert (ilist_tname_size(list) == 0); assert (ilist_tname_size(list) == 0);
assert (ilist_tname_empty_p(list)); assert (ilist_tname_empty_p(list));
for M_EACH(item, list, ILIST_OPLIST(tname)) { for M_EACH(item, list, ILIST_OPLIST(ilist_tname)) {
(void)item; (void)item;
assert(false); assert(false);
} }