1 // new abi support -*- C++ -*-
3 // Free Software Foundation, Inc.
4 // Written by Nathan Sidwell, Codesourcery LLC, <nathan@codesourcery.com>
6 // GNU CC is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2, or (at your option)
11 // GNU CC is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with GNU CC; see the file COPYING. If not, write to
18 // the Free Software Foundation, 59 Temple Place - Suite 330,
19 // Boston, MA 02111-1307, USA.
21 // As a special exception, if you link this library with other files,
22 // some of which are compiled with GCC, to produce an executable,
23 // this library does not by itself cause the resulting executable
24 // to be covered by the GNU General Public License.
25 // This exception does not however invalidate any other reasons why
26 // the executable file might be covered by the GNU General Public License.
28 #if defined(__GXX_ABI_VERSION) && __GXX_ABI_VERSION >= 100
33 // Exception handling hook, to mark current exception as not caught --
34 // generally because we're about to rethrow it after some cleanup.
35 extern "C" void __uncatch_exception (void);
40 /* allocate and construct array */
42 __cxa_vec_new (size_t element_count,
45 void (*constructor) (void *),
46 void (*destructor) (void *))
48 size_t size = element_count * element_size + padding_size;
49 char *base = static_cast <char *> (operator new[] (size));
54 reinterpret_cast <size_t *> (base)[-1] = element_count;
58 __cxa_vec_ctor (base, element_count, element_size,
59 constructor, destructor);
63 // operator delete [] cannot throw, so no need to protect it
64 operator delete[] (base - padding_size);
72 __cxa_vec_ctor (void *array_address,
75 void (*constructor) (void *),
76 void (*destructor) (void *))
79 char *ptr = static_cast <char *> (array_address);
84 for (; ix != element_count; ix++, ptr += element_size)
89 __uncatch_exception ();
90 __cxa_vec_dtor (array_address, ix, element_size, destructor);
97 __cxa_vec_dtor (void *array_address,
100 void (*destructor) (void *))
104 char *ptr = static_cast <char *> (array_address);
105 size_t ix = element_count;
106 bool unwinding = std::uncaught_exception ();
108 ptr += element_count * element_size;
121 // [except.ctor]/3 If a destructor called during stack unwinding
122 // exists with an exception, terminate is called.
124 __uncatch_exception ();
125 __cxa_vec_dtor (array_address, ix, element_size, destructor);
131 /* destruct and release array */
133 __cxa_vec_delete (void *array_address,
136 void (*destructor) (void *))
138 char *base = static_cast <char *> (array_address);
142 size_t element_count = reinterpret_cast <size_t *> (base)[-1];
143 base -= padding_size;
146 __cxa_vec_dtor (array_address, element_count, element_size,
151 // operator delete [] cannot throw, so no need to protect it
152 operator delete[] (base);
156 operator delete[] (base);
159 } // namespace __cxxabiv1
161 #endif // defined(__GXX_ABI_VERSION) && __GXX_ABI_VERSION >= 100