1280ddee8SMarshall Clow //===-------------------------- cxa_vector.cpp ---------------------------===//
2280ddee8SMarshall Clow //
3280ddee8SMarshall Clow //                     The LLVM Compiler Infrastructure
4280ddee8SMarshall Clow //
5280ddee8SMarshall Clow // This file is dual licensed under the MIT and the University of Illinois Open
6280ddee8SMarshall Clow // Source Licenses. See LICENSE.TXT for details.
7280ddee8SMarshall Clow //
8280ddee8SMarshall Clow //
9280ddee8SMarshall Clow //  This file implements the "Array Construction and Destruction APIs"
10c5f7e6feSJonathan Roelofs //  http://mentorembedded.github.io/cxx-abi/abi.html#array-ctor
11280ddee8SMarshall Clow //
12280ddee8SMarshall Clow //===----------------------------------------------------------------------===//
13280ddee8SMarshall Clow 
14280ddee8SMarshall Clow #include "cxxabi.h"
15280ddee8SMarshall Clow 
16280ddee8SMarshall Clow #include <exception>        // for std::terminate
17280ddee8SMarshall Clow 
18280ddee8SMarshall Clow namespace __cxxabiv1 {
19280ddee8SMarshall Clow 
20*5b2d125cSNick Lewycky #if 0
21280ddee8SMarshall Clow #pragma mark --Helper routines and classes --
22*5b2d125cSNick Lewycky #endif
23280ddee8SMarshall Clow 
24280ddee8SMarshall Clow namespace {
25280ddee8SMarshall Clow     inline static size_t __get_element_count ( void *p ) {
26280ddee8SMarshall Clow         return static_cast <size_t *> (p)[-1];
27280ddee8SMarshall Clow         }
28280ddee8SMarshall Clow 
29280ddee8SMarshall Clow     inline static void __set_element_count ( void *p, size_t element_count ) {
30280ddee8SMarshall Clow         static_cast <size_t *> (p)[-1] = element_count;
31280ddee8SMarshall Clow         }
32280ddee8SMarshall Clow 
33280ddee8SMarshall Clow 
34280ddee8SMarshall Clow //  A pair of classes to simplify exception handling and control flow.
35280ddee8SMarshall Clow //  They get passed a block of memory in the constructor, and unless the
36280ddee8SMarshall Clow //  'release' method is called, they deallocate the memory in the destructor.
37be2eced4SHoward Hinnant //  Preferred usage is to allocate some memory, attach it to one of these objects,
38280ddee8SMarshall Clow //  and then, when all the operations to set up the memory block have succeeded,
39280ddee8SMarshall Clow //  call 'release'. If any of the setup operations fail, or an exception is
40280ddee8SMarshall Clow //  thrown, then the block is automatically deallocated.
41280ddee8SMarshall Clow //
42280ddee8SMarshall Clow //  The only difference between these two classes is the signature for the
43280ddee8SMarshall Clow //  deallocation function (to match new2/new3 and delete2/delete3.
44280ddee8SMarshall Clow     class st_heap_block2 {
45280ddee8SMarshall Clow     public:
46280ddee8SMarshall Clow         typedef void (*dealloc_f)(void *);
47280ddee8SMarshall Clow 
48280ddee8SMarshall Clow         st_heap_block2 ( dealloc_f dealloc, void *ptr )
49280ddee8SMarshall Clow             : dealloc_ ( dealloc ), ptr_ ( ptr ), enabled_ ( true ) {}
50280ddee8SMarshall Clow         ~st_heap_block2 () { if ( enabled_ ) dealloc_ ( ptr_ ) ; }
51280ddee8SMarshall Clow         void release () { enabled_ = false; }
52280ddee8SMarshall Clow 
53280ddee8SMarshall Clow     private:
54280ddee8SMarshall Clow         dealloc_f dealloc_;
55280ddee8SMarshall Clow         void *ptr_;
56280ddee8SMarshall Clow         bool enabled_;
57280ddee8SMarshall Clow     };
58280ddee8SMarshall Clow 
59280ddee8SMarshall Clow     class st_heap_block3 {
60280ddee8SMarshall Clow     public:
61280ddee8SMarshall Clow         typedef void (*dealloc_f)(void *, size_t);
62280ddee8SMarshall Clow 
63280ddee8SMarshall Clow         st_heap_block3 ( dealloc_f dealloc, void *ptr, size_t size )
64280ddee8SMarshall Clow             : dealloc_ ( dealloc ), ptr_ ( ptr ), size_ ( size ), enabled_ ( true ) {}
65280ddee8SMarshall Clow         ~st_heap_block3 () { if ( enabled_ ) dealloc_ ( ptr_, size_ ) ; }
66280ddee8SMarshall Clow         void release () { enabled_ = false; }
67280ddee8SMarshall Clow 
68280ddee8SMarshall Clow     private:
69280ddee8SMarshall Clow         dealloc_f dealloc_;
70280ddee8SMarshall Clow         void *ptr_;
71280ddee8SMarshall Clow         size_t size_;
72280ddee8SMarshall Clow         bool enabled_;
73280ddee8SMarshall Clow     };
74280ddee8SMarshall Clow 
75280ddee8SMarshall Clow     class st_cxa_cleanup {
76280ddee8SMarshall Clow     public:
77280ddee8SMarshall Clow         typedef void (*destruct_f)(void *);
78280ddee8SMarshall Clow 
79280ddee8SMarshall Clow         st_cxa_cleanup ( void *ptr, size_t &idx, size_t element_size, destruct_f destructor )
80280ddee8SMarshall Clow             : ptr_ ( ptr ), idx_ ( idx ), element_size_ ( element_size ),
81280ddee8SMarshall Clow                 destructor_ ( destructor ), enabled_ ( true ) {}
82280ddee8SMarshall Clow         ~st_cxa_cleanup () {
83280ddee8SMarshall Clow             if ( enabled_ )
84280ddee8SMarshall Clow                 __cxa_vec_cleanup ( ptr_, idx_, element_size_, destructor_ );
85280ddee8SMarshall Clow             }
86280ddee8SMarshall Clow 
87280ddee8SMarshall Clow         void release () { enabled_ = false; }
88280ddee8SMarshall Clow 
89280ddee8SMarshall Clow     private:
90280ddee8SMarshall Clow         void *ptr_;
91280ddee8SMarshall Clow         size_t &idx_;
92280ddee8SMarshall Clow         size_t element_size_;
93280ddee8SMarshall Clow         destruct_f destructor_;
94280ddee8SMarshall Clow         bool enabled_;
95280ddee8SMarshall Clow     };
96280ddee8SMarshall Clow 
97280ddee8SMarshall Clow     class st_terminate {
98280ddee8SMarshall Clow     public:
99280ddee8SMarshall Clow         st_terminate ( bool enabled = true ) : enabled_ ( enabled ) {}
100280ddee8SMarshall Clow         ~st_terminate () { if ( enabled_ ) std::terminate (); }
101280ddee8SMarshall Clow         void release () { enabled_ = false; }
102280ddee8SMarshall Clow     private:
103280ddee8SMarshall Clow         bool enabled_ ;
104280ddee8SMarshall Clow     };
105280ddee8SMarshall Clow }
106280ddee8SMarshall Clow 
107*5b2d125cSNick Lewycky #if 0
108280ddee8SMarshall Clow #pragma mark --Externally visible routines--
109*5b2d125cSNick Lewycky #endif
110280ddee8SMarshall Clow 
111280ddee8SMarshall Clow extern "C" {
112280ddee8SMarshall Clow 
113280ddee8SMarshall Clow // Equivalent to
114280ddee8SMarshall Clow //
115280ddee8SMarshall Clow //   __cxa_vec_new2(element_count, element_size, padding_size, constructor,
116280ddee8SMarshall Clow //                  destructor, &::operator new[], &::operator delete[])
117280ddee8SMarshall Clow void* __cxa_vec_new(
118280ddee8SMarshall Clow     size_t element_count, size_t element_size, size_t padding_size,
119280ddee8SMarshall Clow         void (*constructor)(void*), void (*destructor)(void*) ) {
120280ddee8SMarshall Clow 
121280ddee8SMarshall Clow     return __cxa_vec_new2 ( element_count, element_size, padding_size,
122280ddee8SMarshall Clow         constructor, destructor, &::operator new [], &::operator delete [] );
123280ddee8SMarshall Clow }
124280ddee8SMarshall Clow 
125280ddee8SMarshall Clow 
126280ddee8SMarshall Clow 
127280ddee8SMarshall Clow // Given the number and size of elements for an array and the non-negative
128280ddee8SMarshall Clow // size of prefix padding for a cookie, allocate space (using alloc) for
129280ddee8SMarshall Clow // the array preceded by the specified padding, initialize the cookie if
130280ddee8SMarshall Clow // the padding is non-zero, and call the given constructor on each element.
131280ddee8SMarshall Clow // Return the address of the array proper, after the padding.
132280ddee8SMarshall Clow //
133280ddee8SMarshall Clow // If alloc throws an exception, rethrow the exception. If alloc returns
134280ddee8SMarshall Clow // NULL, return NULL. If the constructor throws an exception, call
135280ddee8SMarshall Clow // destructor for any already constructed elements, and rethrow the
136280ddee8SMarshall Clow // exception. If the destructor throws an exception, call std::terminate.
137280ddee8SMarshall Clow //
138280ddee8SMarshall Clow // The constructor may be NULL, in which case it must not be called. If the
139280ddee8SMarshall Clow // padding_size is zero, the destructor may be NULL; in that case it must
140280ddee8SMarshall Clow // not be called.
141280ddee8SMarshall Clow //
142280ddee8SMarshall Clow // Neither alloc nor dealloc may be NULL.
143280ddee8SMarshall Clow void* __cxa_vec_new2(
144280ddee8SMarshall Clow     size_t element_count, size_t element_size, size_t padding_size,
145280ddee8SMarshall Clow         void  (*constructor)(void*), void  (*destructor)(void*),
146280ddee8SMarshall Clow         void* (*alloc)(size_t), void  (*dealloc)(void*) ) {
147280ddee8SMarshall Clow 
148280ddee8SMarshall Clow     const size_t heap_size = element_count * element_size + padding_size;
149280ddee8SMarshall Clow     char * const heap_block = static_cast<char *> ( alloc ( heap_size ));
150280ddee8SMarshall Clow     char *vec_base = heap_block;
151280ddee8SMarshall Clow 
152280ddee8SMarshall Clow     if ( NULL != vec_base ) {
153280ddee8SMarshall Clow         st_heap_block2 heap ( dealloc, heap_block );
154280ddee8SMarshall Clow 
155280ddee8SMarshall Clow     //  put the padding before the array elements
156280ddee8SMarshall Clow         if ( 0 != padding_size ) {
157280ddee8SMarshall Clow             vec_base += padding_size;
158280ddee8SMarshall Clow             __set_element_count ( vec_base, element_count );
159280ddee8SMarshall Clow         }
160280ddee8SMarshall Clow 
161280ddee8SMarshall Clow     //  Construct the elements
162280ddee8SMarshall Clow         __cxa_vec_ctor ( vec_base, element_count, element_size, constructor, destructor );
163280ddee8SMarshall Clow         heap.release ();    // We're good!
164280ddee8SMarshall Clow     }
165280ddee8SMarshall Clow 
166280ddee8SMarshall Clow     return vec_base;
167280ddee8SMarshall Clow }
168280ddee8SMarshall Clow 
169280ddee8SMarshall Clow 
170280ddee8SMarshall Clow // Same as __cxa_vec_new2 except that the deallocation function takes both
171280ddee8SMarshall Clow // the object address and its size.
172280ddee8SMarshall Clow void* __cxa_vec_new3(
173280ddee8SMarshall Clow     size_t element_count, size_t element_size, size_t padding_size,
174280ddee8SMarshall Clow         void  (*constructor)(void*), void  (*destructor)(void*),
175280ddee8SMarshall Clow         void* (*alloc)(size_t), void  (*dealloc)(void*, size_t) ) {
176280ddee8SMarshall Clow 
177280ddee8SMarshall Clow     const size_t heap_size = element_count * element_size + padding_size;
178280ddee8SMarshall Clow     char * const heap_block = static_cast<char *> ( alloc ( heap_size ));
179280ddee8SMarshall Clow     char *vec_base = heap_block;
180280ddee8SMarshall Clow 
181280ddee8SMarshall Clow     if ( NULL != vec_base ) {
182280ddee8SMarshall Clow         st_heap_block3 heap ( dealloc, heap_block, heap_size );
183280ddee8SMarshall Clow 
184280ddee8SMarshall Clow     //  put the padding before the array elements
185280ddee8SMarshall Clow         if ( 0 != padding_size ) {
186280ddee8SMarshall Clow             vec_base += padding_size;
187280ddee8SMarshall Clow             __set_element_count ( vec_base, element_count );
188280ddee8SMarshall Clow         }
189280ddee8SMarshall Clow 
190280ddee8SMarshall Clow     //  Construct the elements
191280ddee8SMarshall Clow         __cxa_vec_ctor ( vec_base, element_count, element_size, constructor, destructor );
192280ddee8SMarshall Clow         heap.release ();    // We're good!
193280ddee8SMarshall Clow     }
194280ddee8SMarshall Clow 
195280ddee8SMarshall Clow     return vec_base;
196280ddee8SMarshall Clow }
197280ddee8SMarshall Clow 
198280ddee8SMarshall Clow 
199280ddee8SMarshall Clow // Given the (data) addresses of a destination and a source array, an
200280ddee8SMarshall Clow // element count and an element size, call the given copy constructor to
201280ddee8SMarshall Clow // copy each element from the source array to the destination array. The
202280ddee8SMarshall Clow // copy constructor's arguments are the destination address and source
203280ddee8SMarshall Clow // address, respectively. If an exception occurs, call the given destructor
204280ddee8SMarshall Clow // (if non-NULL) on each copied element and rethrow. If the destructor
205280ddee8SMarshall Clow // throws an exception, call terminate(). The constructor and or destructor
206280ddee8SMarshall Clow // pointers may be NULL. If either is NULL, no action is taken when it
207280ddee8SMarshall Clow // would have been called.
208280ddee8SMarshall Clow 
209280ddee8SMarshall Clow void __cxa_vec_cctor( void*  dest_array, void*  src_array,
210280ddee8SMarshall Clow     size_t element_count, size_t element_size,
211280ddee8SMarshall Clow         void  (*constructor) (void*, void*), void  (*destructor)(void*) ) {
212280ddee8SMarshall Clow 
213280ddee8SMarshall Clow     if ( NULL != constructor ) {
214280ddee8SMarshall Clow         size_t idx = 0;
215280ddee8SMarshall Clow         char *src_ptr  = static_cast<char *>(src_array);
216280ddee8SMarshall Clow         char *dest_ptr = static_cast<char *>(dest_array);
217280ddee8SMarshall Clow         st_cxa_cleanup cleanup ( dest_array, idx, element_size, destructor );
218280ddee8SMarshall Clow 
219280ddee8SMarshall Clow         for ( idx = 0; idx < element_count;
220280ddee8SMarshall Clow                     ++idx, src_ptr += element_size, dest_ptr += element_size )
221280ddee8SMarshall Clow             constructor ( dest_ptr, src_ptr );
222280ddee8SMarshall Clow         cleanup.release ();     // We're good!
223280ddee8SMarshall Clow     }
224280ddee8SMarshall Clow }
225280ddee8SMarshall Clow 
226280ddee8SMarshall Clow 
227280ddee8SMarshall Clow // Given the (data) address of an array, not including any cookie padding,
228280ddee8SMarshall Clow // and the number and size of its elements, call the given constructor on
229280ddee8SMarshall Clow // each element. If the constructor throws an exception, call the given
230280ddee8SMarshall Clow // destructor for any already-constructed elements, and rethrow the
231280ddee8SMarshall Clow // exception. If the destructor throws an exception, call terminate(). The
232280ddee8SMarshall Clow // constructor and/or destructor pointers may be NULL. If either is NULL,
233280ddee8SMarshall Clow // no action is taken when it would have been called.
234280ddee8SMarshall Clow void __cxa_vec_ctor(
235280ddee8SMarshall Clow     void*  array_address, size_t element_count, size_t element_size,
236280ddee8SMarshall Clow        void (*constructor)(void*), void (*destructor)(void*) ) {
237280ddee8SMarshall Clow 
238280ddee8SMarshall Clow     if ( NULL != constructor ) {
239280ddee8SMarshall Clow         size_t idx;
240280ddee8SMarshall Clow         char *ptr = static_cast <char *> ( array_address );
241280ddee8SMarshall Clow         st_cxa_cleanup cleanup ( array_address, idx, element_size, destructor );
242280ddee8SMarshall Clow 
243280ddee8SMarshall Clow     //  Construct the elements
244280ddee8SMarshall Clow         for ( idx = 0; idx < element_count; ++idx, ptr += element_size )
245280ddee8SMarshall Clow             constructor ( ptr );
246280ddee8SMarshall Clow         cleanup.release ();     // We're good!
247280ddee8SMarshall Clow     }
248280ddee8SMarshall Clow }
249280ddee8SMarshall Clow 
250280ddee8SMarshall Clow // Given the (data) address of an array, the number of elements, and the
251280ddee8SMarshall Clow // size of its elements, call the given destructor on each element. If the
252280ddee8SMarshall Clow // destructor throws an exception, rethrow after destroying the remaining
253280ddee8SMarshall Clow // elements if possible. If the destructor throws a second exception, call
254280ddee8SMarshall Clow // terminate(). The destructor pointer may be NULL, in which case this
255280ddee8SMarshall Clow // routine does nothing.
256280ddee8SMarshall Clow void __cxa_vec_dtor(
257280ddee8SMarshall Clow     void*  array_address, size_t element_count, size_t element_size,
258280ddee8SMarshall Clow        void (*destructor)(void*) ) {
259280ddee8SMarshall Clow 
260280ddee8SMarshall Clow     if ( NULL != destructor ) {
261280ddee8SMarshall Clow         char *ptr = static_cast <char *> (array_address);
262280ddee8SMarshall Clow         size_t idx = element_count;
263280ddee8SMarshall Clow         st_cxa_cleanup cleanup ( array_address, idx, element_size, destructor );
264280ddee8SMarshall Clow         {
2657fdfd5d2SHoward Hinnant             st_terminate exception_guard (__cxa_uncaught_exception ());
266280ddee8SMarshall Clow             ptr +=  element_count * element_size;   // one past the last element
267280ddee8SMarshall Clow 
268280ddee8SMarshall Clow             while ( idx-- > 0 ) {
269280ddee8SMarshall Clow                 ptr -= element_size;
270280ddee8SMarshall Clow                 destructor ( ptr );
271280ddee8SMarshall Clow             }
272280ddee8SMarshall Clow             exception_guard.release (); //  We're good !
273280ddee8SMarshall Clow         }
274280ddee8SMarshall Clow         cleanup.release ();     // We're still good!
275280ddee8SMarshall Clow     }
276280ddee8SMarshall Clow }
277280ddee8SMarshall Clow 
278280ddee8SMarshall Clow // Given the (data) address of an array, the number of elements, and the
279280ddee8SMarshall Clow // size of its elements, call the given destructor on each element. If the
280280ddee8SMarshall Clow // destructor throws an exception, call terminate(). The destructor pointer
281280ddee8SMarshall Clow // may be NULL, in which case this routine does nothing.
282280ddee8SMarshall Clow void __cxa_vec_cleanup( void* array_address, size_t element_count,
283280ddee8SMarshall Clow         size_t element_size, void  (*destructor)(void*) ) {
284280ddee8SMarshall Clow 
285280ddee8SMarshall Clow     if ( NULL != destructor ) {
286280ddee8SMarshall Clow         char *ptr = static_cast <char *> (array_address);
287280ddee8SMarshall Clow         size_t idx = element_count;
288280ddee8SMarshall Clow         st_terminate exception_guard;
289280ddee8SMarshall Clow 
290280ddee8SMarshall Clow         ptr += element_count * element_size;    // one past the last element
291280ddee8SMarshall Clow         while ( idx-- > 0 ) {
292280ddee8SMarshall Clow             ptr -= element_size;
293280ddee8SMarshall Clow             destructor ( ptr );
294280ddee8SMarshall Clow             }
295280ddee8SMarshall Clow         exception_guard.release ();     // We're done!
296280ddee8SMarshall Clow     }
297280ddee8SMarshall Clow }
298280ddee8SMarshall Clow 
299280ddee8SMarshall Clow 
300280ddee8SMarshall Clow // If the array_address is NULL, return immediately. Otherwise, given the
301280ddee8SMarshall Clow // (data) address of an array, the non-negative size of prefix padding for
302280ddee8SMarshall Clow // the cookie, and the size of its elements, call the given destructor on
303280ddee8SMarshall Clow // each element, using the cookie to determine the number of elements, and
304280ddee8SMarshall Clow // then delete the space by calling ::operator delete[](void *). If the
305280ddee8SMarshall Clow // destructor throws an exception, rethrow after (a) destroying the
306280ddee8SMarshall Clow // remaining elements, and (b) deallocating the storage. If the destructor
307280ddee8SMarshall Clow // throws a second exception, call terminate(). If padding_size is 0, the
308280ddee8SMarshall Clow // destructor pointer must be NULL. If the destructor pointer is NULL, no
309280ddee8SMarshall Clow // destructor call is to be made.
310280ddee8SMarshall Clow //
311280ddee8SMarshall Clow // The intent of this function is to permit an implementation to call this
312280ddee8SMarshall Clow // function when confronted with an expression of the form delete[] p in
313280ddee8SMarshall Clow // the source code, provided that the default deallocation function can be
314280ddee8SMarshall Clow // used. Therefore, the semantics of this function are consistent with
315280ddee8SMarshall Clow // those required by the standard. The requirement that the deallocation
316280ddee8SMarshall Clow // function be called even if the destructor throws an exception derives
317280ddee8SMarshall Clow // from the resolution to DR 353 to the C++ standard, which was adopted in
318280ddee8SMarshall Clow // April, 2003.
319280ddee8SMarshall Clow void __cxa_vec_delete( void* array_address,
320280ddee8SMarshall Clow         size_t element_size, size_t padding_size, void  (*destructor)(void*) ) {
321280ddee8SMarshall Clow 
322280ddee8SMarshall Clow     __cxa_vec_delete2 ( array_address, element_size, padding_size,
323280ddee8SMarshall Clow                destructor, &::operator delete [] );
324280ddee8SMarshall Clow }
325280ddee8SMarshall Clow 
326280ddee8SMarshall Clow 
327280ddee8SMarshall Clow // Same as __cxa_vec_delete, except that the given function is used for
328280ddee8SMarshall Clow // deallocation instead of the default delete function. If dealloc throws
329280ddee8SMarshall Clow // an exception, the result is undefined. The dealloc pointer may not be
330280ddee8SMarshall Clow // NULL.
331280ddee8SMarshall Clow void __cxa_vec_delete2( void* array_address,
332280ddee8SMarshall Clow         size_t element_size, size_t padding_size,
333280ddee8SMarshall Clow         void  (*destructor)(void*), void  (*dealloc)(void*) ) {
334280ddee8SMarshall Clow 
335280ddee8SMarshall Clow     if ( NULL != array_address ) {
336280ddee8SMarshall Clow         char *vec_base   = static_cast <char *> (array_address);
337280ddee8SMarshall Clow         char *heap_block = vec_base - padding_size;
338280ddee8SMarshall Clow         st_heap_block2 heap ( dealloc, heap_block );
339280ddee8SMarshall Clow 
340280ddee8SMarshall Clow         if ( 0 != padding_size && NULL != destructor ) // call the destructors
341280ddee8SMarshall Clow             __cxa_vec_dtor ( array_address, __get_element_count ( vec_base ),
342280ddee8SMarshall Clow                                     element_size, destructor );
343280ddee8SMarshall Clow     }
344280ddee8SMarshall Clow }
345280ddee8SMarshall Clow 
346280ddee8SMarshall Clow 
347280ddee8SMarshall Clow // Same as __cxa_vec_delete, except that the given function is used for
348280ddee8SMarshall Clow // deallocation instead of the default delete function. The deallocation
349280ddee8SMarshall Clow // function takes both the object address and its size. If dealloc throws
350280ddee8SMarshall Clow // an exception, the result is undefined. The dealloc pointer may not be
351280ddee8SMarshall Clow // NULL.
352280ddee8SMarshall Clow void __cxa_vec_delete3( void* array_address,
353280ddee8SMarshall Clow         size_t element_size, size_t padding_size,
354280ddee8SMarshall Clow         void  (*destructor)(void*), void  (*dealloc) (void*, size_t)) {
355280ddee8SMarshall Clow 
356280ddee8SMarshall Clow     if ( NULL != array_address ) {
357280ddee8SMarshall Clow         char *vec_base   = static_cast <char *> (array_address);
358280ddee8SMarshall Clow         char *heap_block = vec_base - padding_size;
359280ddee8SMarshall Clow         const size_t element_count = padding_size ? __get_element_count ( vec_base ) : 0;
360280ddee8SMarshall Clow         const size_t heap_block_size = element_size * element_count + padding_size;
361280ddee8SMarshall Clow         st_heap_block3 heap ( dealloc, heap_block, heap_block_size );
362280ddee8SMarshall Clow 
363280ddee8SMarshall Clow         if ( 0 != padding_size && NULL != destructor ) // call the destructors
364280ddee8SMarshall Clow             __cxa_vec_dtor ( array_address, element_count, element_size, destructor );
365280ddee8SMarshall Clow     }
366280ddee8SMarshall Clow }
367280ddee8SMarshall Clow 
368280ddee8SMarshall Clow 
369280ddee8SMarshall Clow }  // extern "C"
370280ddee8SMarshall Clow 
371280ddee8SMarshall Clow }  // abi
372