Fix issue if given type is a T * = TYPE:

token pasting created const T *, which is not the same as
const TYPE = T * const
This commit is contained in:
Patrick Pelissier committed 2018-08-03 20:20:57 +02:00
1 parent 030510613c
commit 143a5fdf4f
9 files changed
+54 -54

No files matched your search

+9 -9
View File
@@ -212,7 +212,7 @@
M_GET_SET oplist(v->ptr[i], x); \
} \
\
static inline const type * \
static inline type const * \
M_C(name, _back)(array_t v) \
{ \
ARRAYI_CONTRACT(v); \
@@ -542,7 +542,7 @@
return &v->ptr[i]; \
} \
\
static inline const type * \
static inline type const * \
M_C(name, _cget)(const array_t v, size_t i) \
{ \
ARRAYI_CONTRACT(v); \
@@ -550,7 +550,7 @@
return M_CONST_CAST(type, &v->ptr[i]); \
} \
\
static inline const type * \
static inline type const * \
M_C(name, _front)(const array_t v) \
{ \
ARRAYI_CONTRACT(v); \
@@ -641,7 +641,7 @@
return M_C(name, _get)(it->array, it->index); \
} \
\
static inline const type * \
static inline type const * \
M_C(name, _cref)(const array_it_t it) \
{ \
assert(it != NULL); \
@@ -666,7 +666,7 @@
M_IF_METHOD(CMP, oplist) \
( \
static inline void M_C(name, _special_sort)(array_t l, \
int (*func_type) (const type *a, const type *b)) \
int (*func_type) (type const *a, type const *b)) \
{ \
/* Using qsort is more compact but slower than a full templated \
version which can be twice faster */ \
@@ -778,7 +778,7 @@
for (M_C(name, _it)(it, array) ; \
!M_C(name, _end_p)(it); \
M_C(name, _next)(it)){ \
const type *item = M_C(name, _cref)(it); \
type const *item = M_C(name, _cref)(it); \
M_GET_GET_STR oplist (str, *item, true); \
if (!M_C(name, _last_p)(it)) \
string_push_back (str, M_GET_SEPARATOR oplist); \
@@ -796,7 +796,7 @@
assert (file != NULL); \
fputc ('[', file); \
for (size_t i = 0; i < array->size; i++) { \
const type *item = M_C(name, _cget)(array, i); \
type const *item = M_C(name, _cget)(array, i); \
M_GET_OUT_STR oplist (file, *item); \
if (i != array->size-1) \
fputc (M_GET_SEPARATOR oplist, file); \
@@ -873,8 +873,8 @@
if (array1->size != array2->size) return false; \
size_t i; \
for(i = 0; i < array1->size; i++) { \
const type *item1 = M_C(name, _cget)(array1, i); \
const type *item2 = M_C(name, _cget)(array2, i); \
type const *item1 = M_C(name, _cget)(array1, i); \
type const *item2 = M_C(name, _cget)(array2, i); \
bool b = M_GET_EQUAL oplist (*item1, *item2); \
if (!b) return false; \
} \
+4 -4
View File
@@ -1325,8 +1325,8 @@
# define M_ASSIGN_CAST(type, n) static_cast<type>(n)
#endif
/* Cast 'n' of type 'type*' into 'const type*'.
This is like (const type*)p but safer as the type of 'n' is checked,
/* Cast 'n' of type 'type*' into 'type const*'.
This is like (type const*)p but safer as the type of 'n' is checked,
and more robust for double arrays type.
NOTE: Seems to be compliant with the C standard as in §6.2.5 Types:
"Similarly, pointers to qualified or unqualified versions
@@ -1337,7 +1337,7 @@
# define M_CONST_CAST(type, n) \
(((union { type *ptr; type const *cptr; }){n}).cptr)
#else
# define M_CONST_CAST(type, n) const_cast<const type*>(n)
# define M_CONST_CAST(type, n) const_cast<type*>(n)
#endif
/*
@@ -1349,7 +1349,7 @@
((type *)(void*)( (char *)M_ASSIGN_CAST(field_type*, (ptr)) - offsetof(type, field) ))
#define M_CTYPE_FROM_FIELD(type, ptr, field_type, field) \
((const type *)(const void*)( (const char *)M_ASSIGN_CAST(const field_type*, (ptr)) - offsetof(const type, field) ))
((type const *)(const void*)( (const char *)M_ASSIGN_CAST(field_type const *, (ptr)) - offsetof(type const, field) ))
/************************************************************/
+8 -8
View File
@@ -541,7 +541,7 @@
return &it->node->data[it->index]; \
} \
\
static inline const type * \
static inline type const * \
M_C(name, _cref)(it_t it) \
{ \
assert (it != NULL); \
@@ -568,7 +568,7 @@
it_t it; \
size_t i = DEQUEUI_DEFAULT_SIZE/2; \
for(M_C(name, _it)(it, src); !M_C(name, _end_p)(it) ; M_C(name, _next)(it)) { \
const type *obj = M_C(name, _cref)(it); \
type const *obj = M_C(name, _cref)(it); \
M_GET_INIT_SET oplist (n->data[i], *obj); \
i++; \
assert (i <= d->back->index); \
@@ -650,7 +650,7 @@
return NULL; \
} \
\
static inline const type * \
static inline type const * \
M_C(name, _cget)(deque_t d, size_t key) \
{ \
return M_CONST_CAST(type, M_C(name, _get)(d, key)); \
@@ -678,8 +678,8 @@
for(M_C(name, _it)(it1, d1), M_C(name,_it)(it2, d2); \
!M_C(name, _end_p)(it1) ; \
M_C(name, _next)(it1), M_C(name, _next)(it2)) { \
const type *obj1 = M_C(name, _cref)(it1); \
const type *obj2 = M_C(name, _cref)(it2); \
type const *obj1 = M_C(name, _cref)(it1); \
type const *obj2 = M_C(name, _cref)(it2); \
if (M_GET_EQUAL oplist (*obj1, *obj2) == false) \
return false; \
} \
@@ -696,7 +696,7 @@
M_HASH_DECL(hash); \
it_t it; \
for(M_C(name, _it)(it, d); !M_C(name, _end_p)(it); M_C(name, _next)(it)) { \
const type *obj = M_C(name, _cref)(it); \
type const *obj = M_C(name, _cref)(it); \
M_HASH_UP (hash, M_GET_HASH oplist (*obj)); \
} \
return M_HASH_FINAL(hash); \
@@ -728,7 +728,7 @@
for (M_C(name, _it)(it, deque) ; \
!M_C(name, _end_p)(it); \
M_C(name, _next)(it)){ \
const type *item = M_C(name, _cref)(it); \
type const *item = M_C(name, _cref)(it); \
M_GET_GET_STR oplist (str, *item, true); \
if (!M_C(name, _last_p)(it)) \
string_push_back (str, M_GET_SEPARATOR oplist); \
@@ -749,7 +749,7 @@
for (M_C(name, _it)(it, deque) ; \
!M_C(name, _end_p)(it); \
M_C(name, _next)(it)) { \
const type *item = M_C(name, _cref)(it); \
type const *item = M_C(name, _cref)(it); \
M_GET_OUT_STR oplist (file, *item); \
if (!M_C(name, _last_p)(it)) \
fputc (M_GET_SEPARATOR oplist, file); \
+3 -3
View File
@@ -288,7 +288,7 @@ typedef struct ilist_head_s {
} \
\
static inline type * \
M_C(name, _next_obj)(const list_t list, const type *obj) \
M_C(name, _next_obj)(const list_t list, type const *obj) \
{ \
ILISTI_CONTRACT(name, list); \
assert (obj != NULL); \
@@ -299,7 +299,7 @@ typedef struct ilist_head_s {
} \
\
static inline type * \
M_C(name, _previous_obj)(const list_t list, const type *obj) \
M_C(name, _previous_obj)(const list_t list, type const *obj) \
{ \
ILISTI_CONTRACT(name, list); \
assert (obj != NULL); \
@@ -422,7 +422,7 @@ typedef struct ilist_head_s {
struct ilist_head_s, name); \
} \
\
static inline const type * \
static inline type const * \
M_C(name, _cref)(const list_it_t it) \
{ \
type *ptr = M_C(name, _ref)(it); \
+11 -11
View File
@@ -171,7 +171,7 @@
M_C(name, _clean)(v); \
} \
\
static inline const type * \
static inline type const * \
M_C(name, _back)(const list_t v) \
{ \
LISTI_CONTRACT(v); \
@@ -335,7 +335,7 @@
return &(it->current->data); \
} \
\
static inline const type * \
static inline type const * \
M_C(name, _cref)(const list_it_t it) \
{ \
assert(it != NULL && it->current != NULL); \
@@ -385,7 +385,7 @@
} \
} \
\
static inline const type * \
static inline type const * \
M_C(name, _cget)(const list_t l, size_t i) \
{ \
return M_CONST_CAST(type, M_C(name, _get)(l,i)); \
@@ -586,7 +586,7 @@
for (M_C(name, _it)(it, list) ; \
!M_C(name, _end_p)(it); \
M_C(name, _next)(it)){ \
const type *item = M_C(name, _cref)(it); \
type const *item = M_C(name, _cref)(it); \
M_GET_GET_STR oplist (str, *item, true); \
if (!M_C(name, _last_p)(it)) \
string_push_back (str, M_GET_SEPARATOR oplist); \
@@ -605,7 +605,7 @@
for (M_C(name, _it)(it, list) ; \
!M_C(name, _end_p)(it); \
M_C(name, _next)(it)){ \
const type *item = M_C(name, _cref)(it); \
type const *item = M_C(name, _cref)(it); \
M_GET_OUT_STR oplist (file, *item); \
if (!M_C(name, _last_p)(it)) \
fputc (M_GET_SEPARATOR oplist, file); \
@@ -682,8 +682,8 @@
M_C(name, _it)(it2, list2); \
while (!M_C(name, _end_p)(it1) \
&&!M_C(name, _end_p)(it2)) { \
const type *item1 = M_C(name, _cref)(it1); \
const type *item2 = M_C(name, _cref)(it2); \
type const *item1 = M_C(name, _cref)(it1); \
type const *item2 = M_C(name, _cref)(it2); \
bool b = M_GET_EQUAL oplist (*item1, *item2); \
if (!b) return false; \
M_C(name, _next)(it1); \
@@ -704,7 +704,7 @@
for(M_C(name, _it)(it, list) ; \
!M_C(name, _end_p)(it); \
M_C(name, _next)(it)) { \
const type *item = M_C(name, _cref)(it); \
type const *item = M_C(name, _cref)(it); \
size_t hi = M_GET_HASH oplist (*item); \
M_HASH_UP(hash, hi); \
} \
@@ -781,7 +781,7 @@
M_C(name, _clean)(v); \
} \
\
static inline const type * \
static inline type const * \
M_C(name, _back)(const list_t v) \
{ \
LISTI_DUAL_PUSH_CONTRACT(v); \
@@ -883,7 +883,7 @@
LISTI_DUAL_PUSH_CONTRACT(v); \
} \
\
static inline const type * \
static inline type const * \
M_C(name, _front)(list_t v) \
{ \
LISTI_DUAL_PUSH_CONTRACT(v); \
@@ -1021,7 +1021,7 @@
return &(it->current->data); \
} \
\
static inline const type * \
static inline type const * \
M_C(name, _cref)(const list_it_t it) \
{ \
assert(it != NULL && it->current != NULL); \
+2 -2
View File
@@ -180,7 +180,7 @@
} \
} \
\
static inline const type * \
static inline type const * \
M_C(name, _front)(prioqueue_t p) \
{ \
return M_C(name, _array_cget)(p->array, 0); \
@@ -263,7 +263,7 @@
M_C(name, _array_previous)(it); \
} \
\
static inline const type * \
static inline type const * \
M_C(name, _cref)(const it_t it) \
{ \
return M_C(name, _array_cref)(it); \
+9 -9
View File
@@ -457,7 +457,7 @@ typedef enum {
return &(it->stack[it->cpt-1]->data); \
} \
\
static inline const type * \
static inline type const * \
M_C(name, _cref)(const tree_it_t it) \
{ \
return M_CONST_CAST(type, M_C(name, _ref)(it)); \
@@ -531,13 +531,13 @@ typedef enum {
return &n->data; \
} \
\
static inline const type * \
static inline type const * \
M_C(name, _cmin)(const tree_t tree) \
{ \
return M_CONST_CAST(type, M_C(name, _min)(tree)); \
} \
\
static inline const type * \
static inline type const * \
M_C(name, _cmax)(const tree_t tree) \
{ \
return M_CONST_CAST(type, M_C(name, _max)(tree)); \
@@ -562,7 +562,7 @@ typedef enum {
return NULL; \
} \
\
static inline const type * \
static inline type const * \
M_C(name, _cget)(const tree_t tree, type const data) \
{ \
return M_CONST_CAST(type, M_C(name, _get)(tree, data)); \
@@ -854,8 +854,8 @@ typedef enum {
M_C(name, _it)(it2, t2); \
while (!M_C(name, _end_p)(it1) \
&& !M_C(name, _end_p)(it2)) { \
const type *ref1 = M_C(name, _cref)(it1); \
const type *ref2 = M_C(name, _cref)(it2); \
type const *ref1 = M_C(name, _cref)(it1); \
type const *ref2 = M_C(name, _cref)(it2); \
if (M_GET_EQUAL oplist (*ref1, *ref2) == false) \
return false; \
M_C(name, _next)(it1); \
@@ -875,7 +875,7 @@ typedef enum {
tree_it_t it1; \
M_C(name, _it)(it1, t1); \
while (!M_C(name, _end_p)(it1)) { \
const type *ref1 = M_C(name, _cref)(it1); \
type const *ref1 = M_C(name, _cref)(it1); \
M_HASH_UP(hash, M_GET_HASH oplist (*ref1)); \
M_C(name, _next)(it1); \
} \
@@ -897,7 +897,7 @@ typedef enum {
if (commaToPrint) \
string_push_back (str, M_GET_SEPARATOR oplist); \
commaToPrint = true; \
const type *ref1 = M_C(name, _cref)(it1); \
type const *ref1 = M_C(name, _cref)(it1); \
M_GET_GET_STR oplist(str, *ref1, true); \
M_C(name, _next)(it1); \
} \
@@ -920,7 +920,7 @@ typedef enum {
if (commaToPrint) \
fputc (M_GET_SEPARATOR oplist, file); \
commaToPrint = true; \
const type *item = M_C(name, _cref)(it); \
type const *item = M_C(name, _cref)(it); \
M_GET_OUT_STR oplist (file, *item); \
} \
fputc (']', file); \
+2 -2
View File
@@ -267,7 +267,7 @@ static inline int sharedi_integer_cref(int *p) { return *p; }
return *p1 == *p2; \
} \
\
static inline const type * \
static inline type const * \
M_C(name, _cref)(const M_C(name, _t) shared) \
{ \
SHAREDI_CONTRACT(shared, cpt_oplist); \
@@ -376,7 +376,7 @@ static inline int sharedi_integer_cref(int *p) { return *p; }
return &it->ref->buffer[it->idx].x; \
} \
\
static inline const type * \
static inline type const * \
M_C(name, _cref)(M_C(name, _it_t) it) \
{ \
assert (it != NULL && it->ref != NULL && it->idx != GENINT_ERROR); \
+6 -6
View File
@@ -222,7 +222,7 @@
return &snap->data[SNAPSHOTI_SPSC_W(nextFlags)].x; \
} \
\
static inline const type *M_C(name, _read)(M_C(name, _t) snap) \
static inline type const *M_C(name, _read)(M_C(name, _t) snap) \
{ \
SNAPSHOTI_SPSC_CONTRACT(snap); \
unsigned char nextFlags, origFlags = atomic_load (&snap->flags); \
@@ -259,7 +259,7 @@
return &snap->data[SNAPSHOTI_SPSC_W(flags)].x; \
} \
\
static inline const type *M_C(name, _get_read_buffer)(M_C(name, _t) snap) \
static inline type const *M_C(name, _get_read_buffer)(M_C(name, _t) snap) \
{ \
SNAPSHOTI_SPSC_CONTRACT(snap); \
unsigned char flags = atomic_load(&snap->flags); \
@@ -532,14 +532,14 @@ static inline void snapshot_mrsw_int_read_end(snapshot_mrsw_int_t s, unsigned in
return &snap->data[idx].x; \
} \
\
static inline const type *M_C(name, _read_start)(M_C(name, _t) snap) \
static inline type const *M_C(name, _read_start)(M_C(name, _t) snap) \
{ \
SNAPSHOTI_SPMC_CONTRACT(snap); \
const unsigned int idx = snapshot_mrsw_int_read_start(snap->core); \
return M_CONST_CAST(type, &snap->data[idx].x); \
} \
\
static inline void M_C(name, _read_end)(M_C(name, _t) snap, const type *old) \
static inline void M_C(name, _read_end)(M_C(name, _t) snap, type const *old) \
{ \
SNAPSHOTI_SPMC_CONTRACT(snap); \
assert (old != NULL); \
@@ -610,12 +610,12 @@ static inline void snapshot_mrsw_int_read_end(snapshot_mrsw_int_t s, unsigned in
snapshot_mrsw_int_write_end(snap->core->core, idx); \
} \
\
static inline const type *M_C(name, _read_start)(M_C(name, _t) snap) \
static inline type const *M_C(name, _read_start)(M_C(name, _t) snap) \
{ \
return M_C(name, _mrsw_read_start)(snap->core); \
} \
\
static inline void M_C(name, _read_end)(M_C(name, _t) snap, const type *old) \
static inline void M_C(name, _read_end)(M_C(name, _t) snap, type const *old) \
{ \
M_C(name, _mrsw_read_end)(snap->core, old); \
} \