Commit 40005366 by Nathan Sidwell Committed by Nathan Sidwell

vec.h (VEC_T_truncate): Allow truncation of an empty vector.

	* vec.h (VEC_T_truncate): Allow truncation of an empty vector.
	(VEC_T_quick_insert, VEC_T_ordered_remove): Fix sizeof(T) thinko.

From-SVN: r84746
parent ad5dc4b3
2004-07-15 Nathan Sidwell <nathan@codesourcery.com>
* vec.h (VEC_T_truncate): Allow truncation of an empty vector.
(VEC_T_quick_insert, VEC_T_ordered_remove): Fix sizeof(T) thinko.
2004-07-14 Richard Henderson <rth@redhat.com> 2004-07-14 Richard Henderson <rth@redhat.com>
* print-tree.c (print_node): Fix casts last change. * print-tree.c (print_node): Fix casts last change.
......
...@@ -382,8 +382,9 @@ static inline TDEF VEC_OP (TDEF,pop) \ ...@@ -382,8 +382,9 @@ static inline TDEF VEC_OP (TDEF,pop) \
static inline void VEC_OP (TDEF,truncate) \ static inline void VEC_OP (TDEF,truncate) \
(VEC (TDEF) *vec_, size_t size_) \ (VEC (TDEF) *vec_, size_t size_) \
{ \ { \
VEC_ASSERT (vec_->num >= size_, "truncate", TDEF); \ VEC_ASSERT (vec_ ? vec_->num >= size_ : !size_, "truncate", TDEF); \
vec_->num = size_; \ if (vec_) \
vec_->num = size_; \
} \ } \
\ \
static inline TDEF VEC_OP (TDEF,replace) \ static inline TDEF VEC_OP (TDEF,replace) \
...@@ -406,7 +407,7 @@ static inline TDEF *VEC_OP (TDEF,quick_insert) \ ...@@ -406,7 +407,7 @@ static inline TDEF *VEC_OP (TDEF,quick_insert) \
VEC_ASSERT (vec_->num < vec_->alloc, "insert", TDEF); \ VEC_ASSERT (vec_->num < vec_->alloc, "insert", TDEF); \
VEC_ASSERT (ix_ <= vec_->num, "insert", TDEF); \ VEC_ASSERT (ix_ <= vec_->num, "insert", TDEF); \
slot_ = &vec_->vec[ix_]; \ slot_ = &vec_->vec[ix_]; \
memmove (slot_ + 1, slot_, vec_->num++ - ix_); \ memmove (slot_ + 1, slot_, (vec_->num++ - ix_) * sizeof (TDEF)); \
*slot_ = obj_; \ *slot_ = obj_; \
\ \
return slot_; \ return slot_; \
...@@ -429,7 +430,7 @@ static inline TDEF VEC_OP (TDEF,ordered_remove) \ ...@@ -429,7 +430,7 @@ static inline TDEF VEC_OP (TDEF,ordered_remove) \
VEC_ASSERT (ix_ < vec_->num, "remove", TDEF); \ VEC_ASSERT (ix_ < vec_->num, "remove", TDEF); \
slot_ = &vec_->vec[ix_]; \ slot_ = &vec_->vec[ix_]; \
obj_ = *slot_; \ obj_ = *slot_; \
memmove (slot_, slot_ + 1, --vec_->num - ix_); \ memmove (slot_, slot_ + 1, (--vec_->num - ix_) * sizeof (TDEF)); \
\ \
return obj_; \ return obj_; \
} \ } \
...@@ -553,8 +554,9 @@ static inline void VEC_OP (TDEF,pop) \ ...@@ -553,8 +554,9 @@ static inline void VEC_OP (TDEF,pop) \
static inline void VEC_OP (TDEF,truncate) \ static inline void VEC_OP (TDEF,truncate) \
(VEC (TDEF) *vec_, size_t size_) \ (VEC (TDEF) *vec_, size_t size_) \
{ \ { \
VEC_ASSERT (vec_->num >= size_, "truncate", TDEF); \ VEC_ASSERT (vec_ ? vec_->num >= size_ : !size_, "truncate", TDEF); \
vec_->num = size_; \ if (vec_) \
vec_->num = size_; \
} \ } \
\ \
static inline TDEF *VEC_OP (TDEF,replace) \ static inline TDEF *VEC_OP (TDEF,replace) \
...@@ -578,7 +580,7 @@ static inline TDEF *VEC_OP (TDEF,quick_insert) \ ...@@ -578,7 +580,7 @@ static inline TDEF *VEC_OP (TDEF,quick_insert) \
VEC_ASSERT (vec_->num < vec_->alloc, "insert", TDEF); \ VEC_ASSERT (vec_->num < vec_->alloc, "insert", TDEF); \
VEC_ASSERT (ix_ <= vec_->num, "insert", TDEF); \ VEC_ASSERT (ix_ <= vec_->num, "insert", TDEF); \
slot_ = &vec_->vec[ix_]; \ slot_ = &vec_->vec[ix_]; \
memmove (slot_ + 1, slot_, vec_->num++ - ix_); \ memmove (slot_ + 1, slot_, (vec_->num++ - ix_) * sizeof (TDEF)); \
if (obj_) \ if (obj_) \
*slot_ = *obj_; \ *slot_ = *obj_; \
\ \
...@@ -600,7 +602,7 @@ static inline void VEC_OP (TDEF,ordered_remove) \ ...@@ -600,7 +602,7 @@ static inline void VEC_OP (TDEF,ordered_remove) \
\ \
VEC_ASSERT (ix_ < vec_->num, "remove", TDEF); \ VEC_ASSERT (ix_ < vec_->num, "remove", TDEF); \
slot_ = &vec_->vec[ix_]; \ slot_ = &vec_->vec[ix_]; \
memmove (slot_, slot_ + 1, --vec_->num - ix_); \ memmove (slot_, slot_ + 1, (--vec_->num - ix_) * sizeof (TDEF)); \
} \ } \
\ \
static inline void VEC_OP (TDEF,unordered_remove) \ static inline void VEC_OP (TDEF,unordered_remove) \
......
Markdown is supported
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