Commit f1f0c5a2 by Mark Mitchell Committed by Mark Mitchell

exception_support.h: New header file.

	* libsupc++/exception_support.h: New header file.
	* libsupc++/vec.cc: Include it.
	(__cxa_vec_new2): Recatch exceptions before rethrows.
	(__cxa_vec_new3): Likewise.
	(__cxa_vec_ctor): Likewise.
	(__cxa_vec_cctor): Likewise.
	(__cxa_vec_dtor): Likewise.
	(__cxa_vec_delete2): Likewise.
	(__cxa_vec_delete3): Likewise.

From-SVN: r37551
parent 0a8ad417
2000-11-18 Mark Mitchell <mark@codesourcery.com>
* libsupc++/exception_support.h: New header file.
* libsupc++/vec.cc: Include it.
(__cxa_vec_new2): Recatch exceptions before rethrows.
(__cxa_vec_new3): Likewise.
(__cxa_vec_ctor): Likewise.
(__cxa_vec_cctor): Likewise.
(__cxa_vec_dtor): Likewise.
(__cxa_vec_delete2): Likewise.
(__cxa_vec_delete3): Likewise.
2000-11-17 Theodore Papadopoulo <Theodore.Papadopoulo@sophia.inria.fr> 2000-11-17 Theodore Papadopoulo <Theodore.Papadopoulo@sophia.inria.fr>
* include/bits/stl_tree.h: Overload operators == and != to be able * include/bits/stl_tree.h: Overload operators == and != to be able
......
...@@ -32,8 +32,7 @@ ...@@ -32,8 +32,7 @@
#include "typeinfo" #include "typeinfo"
#include "exception" #include "exception"
#include <cstddef> #include <cstddef>
#include "gansidecl.h" /* Needed to support macros used in eh-common.h. */ #include "exception_support.h"
#include "eh-common.h"
/* Define terminate, unexpected, set_terminate, set_unexpected as /* Define terminate, unexpected, set_terminate, set_unexpected as
well as the default terminate func and default unexpected func. */ well as the default terminate func and default unexpected func. */
...@@ -80,40 +79,6 @@ std::unexpected () ...@@ -80,40 +79,6 @@ std::unexpected ()
__unexpected_func (); __unexpected_func ();
} }
/* The type of a function called to clean up an exception object.
(These will be destructors.) Under the old ABI, these take a
second argument (the `in-charge' argument), that indicates whether
or not do delete the object, and whether or not to destroy virtual
bases. Under the new ABI, there is no second argument. */
#if !defined (__GXX_ABI_VERSION) || __GXX_ABI_VERSION < 100
typedef void (*cleanup_fn)(void *, int);
/* The `2' is the value for the in-charge parameter that indicates
that virtual bases should be destroyed. */
#define CALL_CLEANUP(FN, THIS) FN (THIS, 2)
#else
typedef void (*cleanup_fn)(void *);
#define CALL_CLEANUP(FN, THIS) FN (THIS)
#endif
/* C++-specific state about the current exception.
This must match init_exception_processing().
Note that handlers and caught are not redundant; when rethrown, an
exception can have multiple active handlers and still be considered
uncaught. */
struct cp_eh_info
{
__eh_info eh_info;
void *value;
void *type;
cleanup_fn cleanup;
bool caught;
cp_eh_info *next;
long handlers;
void *original_value;
};
/* Language-specific EH info pointer, defined in libgcc2. */ /* Language-specific EH info pointer, defined in libgcc2. */
extern "C" cp_eh_info **__get_eh_info (); // actually void ** extern "C" cp_eh_info **__get_eh_info (); // actually void **
...@@ -281,7 +246,7 @@ __cp_pop_exception (cp_eh_info *p) ...@@ -281,7 +246,7 @@ __cp_pop_exception (cp_eh_info *p)
/* We're doing a rethrow. Find the currently handled exception, mark it /* We're doing a rethrow. Find the currently handled exception, mark it
uncaught, and move it to the top of the EH stack. */ uncaught, and move it to the top of the EH stack. */
extern "C" void extern "C" cp_eh_info *
__uncatch_exception (void) __uncatch_exception (void)
{ {
cp_eh_info **stack = __get_eh_info (); cp_eh_info **stack = __get_eh_info ();
...@@ -308,6 +273,16 @@ __uncatch_exception (void) ...@@ -308,6 +273,16 @@ __uncatch_exception (void)
} }
p->caught = false; p->caught = false;
return p;
}
/* Mark P as caught after we previously marked it as uncaught. */
extern "C" void
__recatch_exception (cp_eh_info *p)
{
p->caught = true;
} }
/* As per [except.unexpected]: /* As per [except.unexpected]:
......
...@@ -32,13 +32,21 @@ ...@@ -32,13 +32,21 @@
#include <new> #include <new>
#include <exception> #include <exception>
// Exception handling hook, to mark current exception as not caught -- #include "exception_support.h"
// generally because we're about to rethrow it after some cleanup.
extern "C" void __uncatch_exception (void);
namespace __cxxabiv1 namespace __cxxabiv1
{ {
namespace
{
struct uncatch_exception {
uncatch_exception () { p = __uncatch_exception (); }
~uncatch_exception () { __recatch_exception (p); }
cp_eh_info *p;
};
}
/* allocate and construct array */ /* allocate and construct array */
extern "C" void * extern "C" void *
__cxa_vec_new (std::size_t element_count, __cxa_vec_new (std::size_t element_count,
...@@ -76,8 +84,10 @@ __cxa_vec_new2 (std::size_t element_count, ...@@ -76,8 +84,10 @@ __cxa_vec_new2 (std::size_t element_count,
} }
catch (...) catch (...)
{ {
__uncatch_exception (); {
dealloc (base - padding_size); uncatch_exception ue;
dealloc (base - padding_size);
}
throw; throw;
} }
return base; return base;
...@@ -107,8 +117,10 @@ __cxa_vec_new3 (std::size_t element_count, ...@@ -107,8 +117,10 @@ __cxa_vec_new3 (std::size_t element_count,
} }
catch (...) catch (...)
{ {
__uncatch_exception (); {
dealloc (base - padding_size, size); uncatch_exception ue;
dealloc (base - padding_size, size);
}
throw; throw;
} }
return base; return base;
...@@ -133,8 +145,10 @@ __cxa_vec_ctor (void *array_address, ...@@ -133,8 +145,10 @@ __cxa_vec_ctor (void *array_address,
} }
catch (...) catch (...)
{ {
__uncatch_exception (); {
__cxa_vec_dtor (array_address, ix, element_size, destructor); uncatch_exception ue;
__cxa_vec_dtor (array_address, ix, element_size, destructor);
}
throw; throw;
} }
} }
...@@ -162,8 +176,10 @@ __cxa_vec_cctor (void *dest_array, ...@@ -162,8 +176,10 @@ __cxa_vec_cctor (void *dest_array,
} }
catch (...) catch (...)
{ {
__uncatch_exception (); {
__cxa_vec_dtor (dest_array, ix, element_size, destructor); uncatch_exception ue;
__cxa_vec_dtor (dest_array, ix, element_size, destructor);
}
throw; throw;
} }
} }
...@@ -197,8 +213,11 @@ __cxa_vec_dtor (void *array_address, ...@@ -197,8 +213,11 @@ __cxa_vec_dtor (void *array_address,
// [except.ctor]/3 If a destructor called during stack unwinding // [except.ctor]/3 If a destructor called during stack unwinding
// exits with an exception, terminate is called. // exits with an exception, terminate is called.
std::terminate (); std::terminate ();
__uncatch_exception (); {
__cxa_vec_dtor (array_address, ix, element_size, destructor); uncatch_exception ue;
__cxa_vec_dtor (array_address, ix, element_size,
destructor);
}
throw; throw;
} }
} }
...@@ -236,8 +255,10 @@ __cxa_vec_delete2 (void *array_address, ...@@ -236,8 +255,10 @@ __cxa_vec_delete2 (void *array_address,
} }
catch (...) catch (...)
{ {
__uncatch_exception (); {
dealloc (base); uncatch_exception ue;
dealloc (base);
}
throw; throw;
} }
} }
...@@ -266,8 +287,10 @@ __cxa_vec_delete3 (void *array_address, ...@@ -266,8 +287,10 @@ __cxa_vec_delete3 (void *array_address,
} }
catch (...) catch (...)
{ {
__uncatch_exception (); {
dealloc (base, size); uncatch_exception ue;
dealloc (base, size);
}
throw; throw;
} }
} }
......
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