Commit 89f5a4ce authored by Christoph Mallon's avatar Christoph Mallon
Browse files

array: Remove the attribute eltsize from struct ir_arr_descr.

It is hardly able to catch problems, because most arrays contain pointers.
parent c1aac698
......@@ -236,7 +236,6 @@ typedef union {
*/
typedef struct {
int magic; /**< array magic. */
size_t eltsize; /**< size of array elements. */
size_t allocated; /**< number of allocated elements. */
size_t nelts; /**< current length of the array. */
aligned_type elts[1]; /**< start of the array data. */
......
......@@ -46,7 +46,7 @@
/**
* An empty dynamic array descriptor.
*/
ir_arr_descr arr_mt_descr = { ARR_D_MAGIC, 0, 0, 0, { { 0 } } };
ir_arr_descr arr_mt_descr = { ARR_D_MAGIC, 0, 0, { { 0 } } };
void ir_verify_arr(const void *arr)
{
......@@ -79,7 +79,7 @@ void *ir_new_arr_d(struct obstack *obstack, size_t nelts, size_t elts_size)
assert(obstack);
dp = (ir_arr_descr*)obstack_alloc(obstack, ARR_ELTS_OFFS + elts_size);
ARR_SET_DBGINF(dp, ARR_D_MAGIC, elts_size/nelts);
ARR_SET_DBGINF(dp, ARR_D_MAGIC);
dp->allocated = dp->nelts = nelts;
return dp->elts;
}
......@@ -100,7 +100,7 @@ void *ir_new_arr_f(size_t nelts, size_t elts_size)
ir_arr_descr *newa;
newa = (ir_arr_descr*)xmalloc(ARR_ELTS_OFFS+elts_size);
ARR_SET_DBGINF(newa, ARR_F_MAGIC, nelts ? elts_size/nelts : 0);
ARR_SET_DBGINF(newa, ARR_F_MAGIC);
newa->allocated = newa->nelts = nelts;
return newa->elts;
}
......@@ -143,7 +143,6 @@ void *ir_arr_setlen (void *elts, size_t nelts, size_t elts_size)
assert(dp->magic == ARR_F_MAGIC);
ARR_VRFY(elts);
assert(!dp->eltsize || !nelts || (dp->eltsize == elts_size/nelts));
dp = (ir_arr_descr*) xrealloc(dp, ARR_ELTS_OFFS+elts_size);
dp->allocated = dp->nelts = nelts;
......@@ -171,7 +170,6 @@ void *ir_arr_resize(void *elts, size_t nelts, size_t eltsize)
assert(dp->magic == ARR_F_MAGIC);
ARR_VRFY(elts);
assert(dp->eltsize ? dp->eltsize == eltsize : (dp->eltsize = eltsize, 1));
/* @@@ lots of resizes for small nelts */
n = MAX(1, dp->allocated);
......
......@@ -32,10 +32,10 @@
#define ARR_F_MAGIC FOURCC('A','R','R','F')
#ifdef NDEBUG
# define ARR_SET_DBGINF(descr, co, es)
# define ARR_SET_DBGINF(descr, co)
#else
# define ARR_SET_DBGINF(descr, co, es) \
( (descr)->magic = (co), (descr)->eltsize = (es) )
# define ARR_SET_DBGINF(descr, co) \
((descr)->magic = (co))
#endif
/**
......@@ -53,7 +53,7 @@
do { \
size_t nelts = (n); \
(var) = (type *)((ir_arr_descr *)alloca(ARR_ELTS_OFFS + sizeof(type) * nelts))->elts; \
ARR_SET_DBGINF(ARR_DESCR ((var)), ARR_A_MAGIC, sizeof (type)); \
ARR_SET_DBGINF(ARR_DESCR ((var)), ARR_A_MAGIC); \
(void)(ARR_DESCR((var))->nelts = nelts); \
} while (0)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment