Fwd: cxa_vec_dtor question

Jason Merrill jason at redhat.com
Wed Jan 24 23:32:14 UTC 2001


>>>>> "Jason" == Jason Merrill <jason at redhat.com> writes:

> I think he's right; we can't use uncaught_exception to determine whether or
> not we're actually being called for a cleanup.  I suppose we'll need a
> different entry point.

i.e., something like this:

*** vec.cc.~1~	Sun Nov 19 20:21:52 2000
--- vec.cc	Wed Jan 24 18:47:03 2001
*************** __cxa_vec_ctor (void *array_address,
*** 147,153 ****
      {
        {
  	uncatch_exception ue;
! 	__cxa_vec_dtor (array_address, ix, element_size, destructor);
        }
        throw;
      }
--- 147,153 ----
      {
        {
  	uncatch_exception ue;
! 	__cxa_vec_cleanup (array_address, ix, element_size, destructor);
        }
        throw;
      }
*************** __cxa_vec_cctor (void *dest_array,
*** 178,184 ****
      {
        {
  	uncatch_exception ue;
! 	__cxa_vec_dtor (dest_array, ix, element_size, destructor);
        }
        throw;
      }
--- 178,184 ----
      {
        {
  	uncatch_exception ue;
! 	__cxa_vec_cleanup (dest_array, ix, element_size, destructor);
        }
        throw;
      }
*************** __cxa_vec_dtor (void *array_address,
*** 195,201 ****
      {
        char *ptr = static_cast <char *> (array_address);
        std::size_t ix = element_count;
-       bool unwinding = std::uncaught_exception ();
        
        ptr += element_count * element_size;
        
--- 195,200 ----
*************** __cxa_vec_dtor (void *array_address,
*** 209,225 ****
          }
        catch (...)
          {
-           if (unwinding)
-             // [except.ctor]/3 If a destructor called during stack unwinding
-             // exits with an exception, terminate is called.
-             std::terminate ();
  	  {
  	    uncatch_exception ue;
! 	    __cxa_vec_dtor (array_address, ix, element_size,
! 			    destructor);
  	  }
            throw;
          }
      }
  }
  
--- 208,251 ----
          }
        catch (...)
          {
  	  {
  	    uncatch_exception ue;
! 	    __cxa_vec_cleanup (array_address, ix, element_size,
! 			       destructor);
  	  }
            throw;
          }
+     }
+ }
+ 
+ /* destruct array as a result of throwing an exception */
+ // [except.ctor]/3 If a destructor called during stack unwinding
+ // exits with an exception, terminate is called.
+ extern "C" void
+ __cxa_vec_cleanup (void *array_address,
+ 		   std::size_t element_count,
+ 		   std::size_t element_size,
+ 		   void (*destructor) (void *))
+ {
+   if (destructor)
+     {
+       char *ptr = static_cast <char *> (array_address);
+       std::size_t ix = element_count;
+ 
+       ptr += element_count * element_size;
+ 
+       try
+ 	{
+ 	  while (ix--)
+ 	    {
+ 	      ptr -= element_size;
+ 	      destructor (ptr);
+ 	    }
+ 	}
+       catch (...)
+ 	{
+ 	  std::terminate ();
+ 	}
      }
  }
  




More information about the cxx-abi-dev mailing list