GCC Wikia
Advertisement

目次

  1. contents

このページを編集する際は,編集に関する方針に従ってください.[]

概要[]

引数[]

  • T
  • A

実装[]

671 #define DEF_VEC_ALLOC_FUNC_P(T,A)                                         \

&aname(alloc);
== *alloc  ==

672 static inline VEC(T,A) *VEC_OP (T,A,alloc)                                \
673      (int alloc_ MEM_STAT_DECL)                                           \
674 {                                                                         \
 675   /* We must request exact size allocation, hence the negation.  */       \

*関数を呼び出す
**Aがgcならばvec_gc_p_reserve、heapならばvec_heap_p_reserveが呼ばれる
**上記の二つは定義されている
**その他は自分で用意する必要がありそう

676   return (VEC(T,A) *) vec_##A##_p_reserve (NULL, -alloc_ PASS_MEM_STAT);  \
677 }                                                                         \
678                                                                           \

&aname(free);
== *free  ==

679 static inline void VEC_OP (T,A,free)                                      \
680      (VEC(T,A) **vec_)                                                    \
681 {                                                                         \
682   if (*vec_)                                                              \
683     vec_##A##_free (*vec_);                                               \
684   *vec_ = NULL;                                                           \
685 }                                                                         \
686                                                                           \

&aname(copy);
== *copy  ==

687 static inline VEC(T,A) *VEC_OP (T,A,copy) (VEC(T,base) *vec_ MEM_STAT_DECL) \
688 {                                                                         \
689   size_t len_ = vec_ ? vec_->num : 0;                                     \
690   VEC (T,A) *new_vec_ = NULL;                                             \
691                                                                           \
692   if (len_)                                                               \
693     {                                                                     \
 694       /* We must request exact size allocation, hence the negation. */    \
695       new_vec_ = (VEC (T,A) *)(vec_##A##_p_reserve                        \
696                                (NULL, -len_ PASS_MEM_STAT));              \
697                                                                           \
698       new_vec_->base.num = len_;                                          \
699       memcpy (new_vec_->base.vec, vec_->vec, sizeof (T) * len_);          \
700     }                                                                     \
701   return new_vec_;                                                        \
702 }                                                                         \
703                                                                           \

&aname(reserve);
== *reserve  ==

704 static inline int VEC_OP (T,A,reserve)                                    \
705      (VEC(T,A) **vec_, int alloc_ VEC_CHECK_DECL MEM_STAT_DECL)           \
706 {                                                                         \
707   int extend = !VEC_OP (T,base,space) (VEC_BASE(*vec_),                   \
708                                        alloc_ < 0 ? -alloc_ : alloc_      \
709                                        VEC_CHECK_PASS);                   \
710                                                                           \
711   if (extend)                                                             \
712     *vec_ = (VEC(T,A) *) vec_##A##_p_reserve (*vec_, alloc_ PASS_MEM_STAT); \
713                                                                           \
714   return extend;                                                          \
715 }                                                                         \
716                                                                           \

&aname(safe_grow);
== *safe_grow  ==

717 static inline void VEC_OP (T,A,safe_grow)                                 \
718      (VEC(T,A) **vec_, int size_ VEC_CHECK_DECL MEM_STAT_DECL)            \
719 {                                                                         \
720   VEC_ASSERT (size_ >= 0                                                  \
721               && VEC_OP(T,base,length) VEC_BASE(*vec_) <= (unsigned)size_, \
722                                                  "grow", T, A);           \
723   VEC_OP (T,A,reserve) (vec_, (int)(*vec_ ? VEC_BASE(*vec_)->num : 0) - size_ \
724                         VEC_CHECK_PASS PASS_MEM_STAT);                    \
725   VEC_BASE (*vec_)->num = size_;                                          \
726 }                                                                         \

&aname(safe_push);
== *safe_push  ==

727                                                                           \
728 static inline T *VEC_OP (T,A,safe_push)                                   \
729      (VEC(T,A) **vec_, T obj_ VEC_CHECK_DECL MEM_STAT_DECL)               \
730 {                                                                         \
731   VEC_OP (T,A,reserve) (vec_, 1 VEC_CHECK_PASS PASS_MEM_STAT);            \
732                                                                           \
733   return VEC_OP (T,base,quick_push) (VEC_BASE(*vec_), obj_ VEC_CHECK_PASS); \
734 }                                                                         \

&aname(safe_insert);
== *safe_insert  ==

735                                                                           \
736 static inline T *VEC_OP (T,A,safe_insert)                                 \
737      (VEC(T,A) **vec_, unsigned ix_, T obj_ VEC_CHECK_DECL MEM_STAT_DECL)  \
738 {                                                                         \
739   VEC_OP (T,A,reserve) (vec_, 1 VEC_CHECK_PASS PASS_MEM_STAT);            \
740                                                                           \
741   return VEC_OP (T,base,quick_insert) (VEC_BASE(*vec_), ix_, obj_         \
742                                        VEC_CHECK_PASS);                   \
743 }


リンク元

Advertisement