From b8c1233b5e3d2cdc5ab6db633195675b98ee515a Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Sun, 9 Apr 2000 16:05:16 +0000 Subject: [PATCH] vec.cc: Include and . * vec.cc: Include and . (__cxa_vec_ctor): Use __cxa_vec_dtor for cleanup. (__cxa_vec_dtor): Catch dtor exceptions, and rethrow or terminate. (__cxa_vec_delete): Catch dtor exceptions. From-SVN: r33042 --- gcc/cp/ChangeLog | 8 +++++++ gcc/cp/vec.cc | 55 +++++++++++++++++++++++++++++++++--------------- 2 files changed, 46 insertions(+), 17 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index f76ef394477..3457d8e38ce 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2000-04-09 Nathan Sidwell + + * vec.cc: Include and . + (__cxa_vec_ctor): Use __cxa_vec_dtor for cleanup. + (__cxa_vec_dtor): Catch dtor exceptions, and rethrow or + terminate. + (__cxa_vec_delete): Catch dtor exceptions. + 2000-04-09 Nathan Sidwell Prepend __ to implementation defined names. diff --git a/gcc/cp/vec.cc b/gcc/cp/vec.cc index 3b5182cdcb8..4f5ce4960ef 100644 --- a/gcc/cp/vec.cc +++ b/gcc/cp/vec.cc @@ -27,6 +27,12 @@ #if defined(__GXX_ABI_VERSION) && __GXX_ABI_VERSION >= 100 #include +#include +#include + +// Exception handling hook, to mark current exception as not caught -- +// generally because we're about to rethrow it after some cleanup. +extern "C" void __uncatch_exception (void); namespace __cxxabiv1 { @@ -54,6 +60,7 @@ __cxa_vec_new (size_t element_count, } catch (...) { + // operator delete [] cannot throw, so no need to protect it operator delete[] (base - padding_size); throw; } @@ -79,18 +86,8 @@ __cxa_vec_ctor (void *array_address, } catch (...) { - try - { - if (destructor) - for (; ix--; ptr -= element_size) - destructor (ptr); - } - catch (...) - { - // [except.ctor]/3 If a destructor called during stack unwinding - // exists with an exception, terminate is called. - std::terminate (); - } + __uncatch_exception (); + __cxa_vec_dtor (array_address, ix, element_size, destructor); throw; } } @@ -105,13 +102,28 @@ __cxa_vec_dtor (void *array_address, if (destructor) { char *ptr = static_cast (array_address); + size_t ix = element_count; + bool unwinding = std::uncaught_exception (); ptr += element_count * element_size; - for (size_t ix = element_count; ix--;) + try + { + while (ix--) + { + ptr -= element_size; + destructor (ptr); + } + } + catch (...) { - ptr -= element_size; - destructor (ptr); + if (unwinding) + // [except.ctor]/3 If a destructor called during stack unwinding + // exists with an exception, terminate is called. + std::terminate (); + __uncatch_exception (); + __cxa_vec_dtor (array_address, ix, element_size, destructor); + throw; } } } @@ -128,9 +140,18 @@ __cxa_vec_delete (void *array_address, if (padding_size) { size_t element_count = reinterpret_cast (base)[-1]; - - __cxa_vec_dtor (base, element_count, element_size, destructor); base -= padding_size; + try + { + __cxa_vec_dtor (array_address, element_count, element_size, + destructor); + } + catch (...) + { + // operator delete [] cannot throw, so no need to protect it + operator delete[] (base); + throw; + } } operator delete[] (base); } -- 2.30.2