From 34f70a031fdf3fc4d71336edd205a8c24650cd85 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Sat, 9 May 2020 10:56:05 +0200 Subject: [PATCH] Use M_STATIC_FAILURE to stop expanding methods in case of detected failure --- m-array.h | 10 +++++++++- m-deque.h | 12 ++++++++++-- m-i-list.h | 10 +++++++++- m-list.h | 20 ++++++++++++++------ 4 files changed, 42 insertions(+), 10 deletions(-) diff --git a/m-array.h b/m-array.h index 9046c65e..7adf316e 100644 --- a/m-array.h +++ b/m-array.h @@ -121,6 +121,14 @@ so that all arguments are evaluated before further expansion */ #define ARRAYI_DEF_P1(arg) ARRAYI_DEF_P2 arg +/* Validate the oplist before going further */ +#define ARRAYI_DEF_P2(name, type, oplist, array_t, it_t) \ + M_IF_OPLIST(oplist)(ARRAYI_DEF_P3, ARRAYI_DEF_FAILURE)(name, type, oplist, array_t, it_t) + +/* Stop processing with a compilation failure */ +#define ARRAYI_DEF_FAILURE(name, type, oplist, array_t, it_t) \ + M_STATIC_FAILURE(M_LIB_NOT_AN_OPLIST, "(ARRAY_DEF): the given argument is not a valid oplist: " #oplist) + /* Internal definition: - name: prefix to be used - type: type of the elements of the array @@ -128,7 +136,7 @@ - array_t: alias for M_C(name, _t) [ type of the array ] - it_t: alias for M_C(name, _it_t) [ iterator of the array ] */ -#define ARRAYI_DEF_P2(name, type, oplist, array_t, it_t) \ +#define ARRAYI_DEF_P3(name, type, oplist, array_t, it_t) \ \ typedef struct M_C(name, _s) { \ size_t size; /* Number of elements in the array */ \ diff --git a/m-deque.h b/m-deque.h index 4aebf89e..23bd1476 100644 --- a/m-deque.h +++ b/m-deque.h @@ -67,15 +67,23 @@ so that all arguments are evaluated before further expansion */ #define DEQUEI_DEF_P1(arg) DEQUEI_DEF_P2 arg +/* Validate the oplist before going further */ +#define DEQUEI_DEF_P2(name, type, oplist, deque_t, it_t, node_t) \ + M_IF_OPLIST(oplist)(DEQUEI_DEF_P3, DEQUEI_DEF_FAILURE)(name, type, oplist, deque_t, it_t, node_t) + +/* Stop processing with a compilation failure */ +#define DEQUEI_DEF_FAILURE(name, type, oplist, deque_t, it_t, node_t) \ + M_STATIC_FAILURE(M_LIB_NOT_AN_OPLIST, "(DEQUE_DEF): the given argument is not a valid oplist: " #oplist) + /* Internal deque definition - name: prefix to be used - - type: type of the elements of the array + - type: type of the elements of the deque - oplist: oplist of the type of the elements of the container - deque_t: alias for M_C(name, _t) [ type of the container ] - it_t: alias for M_C(name, _it_t) [ iterator of the container ] - node_t: alias for M_C(name, _node_t) [ node ] */ -#define DEQUEI_DEF_P2(name, type, oplist, deque_t, it_t, node_t) \ +#define DEQUEI_DEF_P3(name, type, oplist, deque_t, it_t, node_t) \ \ /* It is a linked list of buckets of the types, \ each new created bucket size grows compared to the previous one \ diff --git a/m-i-list.h b/m-i-list.h index 328ae531..54ec41d7 100644 --- a/m-i-list.h +++ b/m-i-list.h @@ -120,6 +120,14 @@ typedef struct ilist_head_s { /* Indirection call to allow expanding all arguments (TBC) */ #define ILISTI_DEF_P1(arg) ILISTI_DEF_P2 arg +/* Validate the oplist before going further */ +#define ILISTI_DEF_P2(name, type, oplist, list_t, it_t) \ + M_IF_OPLIST(oplist)(ILISTI_DEF_P3, ILISTI_DEF_FAILURE)(name, type, oplist, list_t, it_t) + +/* Stop processing with a compilation failure */ +#define ILISTI_DEF_FAILURE(name, type, oplist, list_t, it_t) \ + M_STATIC_FAILURE(M_LIB_NOT_AN_OPLIST, "(ILIST_DEF): the given argument is not a valid oplist: " #oplist) + /* Definition of the type and function for an intrusive doubly-linked list. USAGE: name: name of the intrusive list @@ -128,7 +136,7 @@ typedef struct ilist_head_s { list_t: type of the intrusive list (name##_t) it_t: iterator of the intrusive list (name##_it_t) */ -#define ILISTI_DEF_P2(name, type, oplist, list_t, it_t) \ +#define ILISTI_DEF_P3(name, type, oplist, list_t, it_t) \ \ typedef struct M_C(name, _s) { \ struct ilist_head_s name; \ diff --git a/m-list.h b/m-list.h index a879d254..ef78da08 100644 --- a/m-list.h +++ b/m-list.h @@ -106,6 +106,14 @@ so that all arguments are evaluated before further expansion */ #define LISTI_DEF_P1(arg) LISTI_DEF_P2 arg +/* Validate the oplist before going further */ +#define LISTI_DEF_P2(name, type, oplist, list_t, it_t) \ + M_IF_OPLIST(oplist)(LISTI_DEF_P3, LISTI_DEF_FAILURE)(name, type, oplist, list_t, it_t) + +/* Stop processing with a compilation failure */ +#define LISTI_DEF_FAILURE(name, type, oplist, list_t, it_t) \ + M_STATIC_FAILURE(M_LIB_NOT_AN_OPLIST, "(LIST_DEF): the given argument is not a valid oplist: " #oplist) + /* Define allocation functions. If MEMPOOL, we need to define it */ #define LISTI_MEMPOOL_DEF(name, type, oplist, list_t, list_it_t) \ M_IF_METHOD(MEMPOOL, oplist)( \ @@ -132,13 +140,13 @@ /* Internal list definition - name: prefix to be used - - type: type of the elements of the array + - type: type of the elements of the list - oplist: oplist of the type of the elements of the container - list_t: alias for M_C(name, _t) [ type of the container ] - it_t: alias for M_C(name, _it_t) [ iterator of the container ] - node_t: alias for M_C(name, _node_t) [ node ] */ -#define LISTI_DEF_P2(name, type, oplist, list_t, it_t) \ +#define LISTI_DEF_P3(name, type, oplist, list_t, it_t) \ \ typedef struct M_C(name, _s) { \ struct M_C(name, _s) *next; \ @@ -155,7 +163,7 @@ } it_t[1]; \ \ LISTI_MEMPOOL_DEF(name, type, oplist, list_t, it_t) \ - LISTI_DEF_P3(name, type, oplist, list_t, it_t) \ + LISTI_DEF_P4(name, type, oplist, list_t, it_t) \ LISTI_ITBASE_DEF(name, type, oplist, list_t, it_t) @@ -168,13 +176,13 @@ /* Internal list function definition - name: prefix to be used - - type: type of the elements of the array + - type: type of the elements of the list - oplist: oplist of the type of the elements of the container - list_t: alias for M_C(name, _t) [ type of the container ] - it_t: alias for M_C(name, _it_t) [ iterator of the container ] - node_t: alias for M_C(name, _node_t) [ node ] */ -#define LISTI_DEF_P3(name, type, oplist, list_t, it_t) \ +#define LISTI_DEF_P4(name, type, oplist, list_t, it_t) \ \ static inline void \ M_C(name, _init)(list_t v) \ @@ -612,7 +620,7 @@ /* Internal list function definition based on iterator functions (common for all kind of lists) - name: prefix to be used - - type: type of the elements of the array + - type: type of the elements of the list - oplist: oplist of the type of the elements of the container - list_t: alias for M_C(name, _t) [ type of the container ] - it_t: alias for M_C(name, _it_t) [ iterator of the container ]