Actions

icon Post
text/html Subscribe
text/html Unsubscribe

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [cxx-abi-dev] Allocator returning null during array construction (?)


  • To: "Zagorodnev, Grigory" <Grigory_Zagorodnev@xxxxxxxxxxxx>
  • Subject: Re: [cxx-abi-dev] Allocator returning null during array construction (?)
  • From: Mark Mitchell <mark@xxxxxxxxxxxxxxxx>
  • Date: 05 Sep 2003 15:45:17 -0700

On Thu, 2003-09-04 at 06:40, Zagorodnev, Grigory wrote:
> The C++ Standard [clause 5.3.4, paragraph 13] says:
> "...If the allocation function is declared with an empty
> exception-specification, throw(), it returns null to indicate failure to
> allocate storage and a nonnull pointer otherwise. ] If the allocation
> function returns null, initialization shall not be done, the deallocation
> function shall not be called, and the value of the newexpression shall be
> null. "
> 
> The C++ ABI [clause 3.3.3], however, does not specify behaviour of array
> construction functions __cxa_vec_new2 and __cxa_vec_new3 for the case when
> allocator returns null.

You are correct; the functions should return NULL in that case.

I've attached a patch for the ABI here.  The web page will be updated
shortly.

-- 
Mark Mitchell
CodeSourcery, LLC
mark@xxxxxxxxxxxxxxxx
Index: abi.html
===================================================================
RCS file: /usr/local/Repository/cxx-abi/abi.html,v
retrieving revision 1.68
diff -c -5 -p -r1.68 abi.html
*** abi.html	6 Aug 2003 18:14:08 -0000	1.68
--- abi.html	5 Sep 2003 22:35:56 -0000
*************** extern "C" void * __cxa_vec_new (
*** 3187,3213 ****
  	    size_t padding_size,
  	    void (*constructor) ( void *this ),
  	    void (*destructor) ( void *this ) );
  </pre></code></dt>
  <dd>
! Given the number and size of elements for an array
! and the non-negative size of prefix padding for a cookie,
! allocate space for the array preceded by the specified padding,
! initialize the cookie if the padding is non-zero,
! and call the given constructor on each element.
! Return the address of the array proper,
! after the padding.
! If allocation throws, rethrow.
! If the constructor throws an exception,
! call the given destructor for any already-constructed elements,
! delete the space,
! and rethrow the exception.
! If the destructor throws an exception,
! call <code>terminate()</code>.
! The constructor may be NULL.
! The destructor may be NULL only if the padding size is zero.
! If either is NULL, no action is taken when it would have been called.
  </dd>
  
  <dt><code><pre>
  extern "C" void * __cxa_vec_new2 (
  	    size_t element_count,
--- 3187,3201 ----
  	    size_t padding_size,
  	    void (*constructor) ( void *this ),
  	    void (*destructor) ( void *this ) );
  </pre></code></dt>
  <dd>
! <p>Equivalent to <code>
! <pre>
!   __cxa_vec_new2(element_count, element_size, padding_size, constructor,
!                  destructor, &::operator new[], &::operator delete[])
! </pre></code></p>
  </dd>
  
  <dt><code><pre>
  extern "C" void * __cxa_vec_new2 (
  	    size_t element_count,
*************** extern "C" void * __cxa_vec_new2 (
*** 3217,3231 ****
  	    void (*destructor) ( void *this ),
  	    void* (*alloc) ( size_t size ),
  	    void (*dealloc) ( void *obj ) );
  </pre></code></dt>
  <dd>
! Same as <code>__cxa_vec_new</code>, except that the given functions
! are used for allocation/deallocation instead of the default new/delete
! functions.  If <code>dealloc</code> throws an exception,
! <code>std::terminate</code> is called.  The <code>alloc</code> and
! <code>dealloc</code> pointers may not be NULL.
  </dd>
  
  <dt><code><pre>
  extern "C" void * __cxa_vec_new3 (
  	    size_t element_count,
--- 3205,3235 ----
  	    void (*destructor) ( void *this ),
  	    void* (*alloc) ( size_t size ),
  	    void (*dealloc) ( void *obj ) );
  </pre></code></dt>
  <dd>
! <p>Given the number and size of elements for an array and the
! non-negative size of prefix padding for a cookie, allocate space
! (using <code>alloc</code>) for the array preceded by the specified
! padding, initialize the cookie if the padding is non-zero, and call
! the given constructor on each element.  Return the address of the
! array proper, after the padding.</p>
! 
! <p>If <code>alloc</code> throws an exception, rethrow the exception.
! If <code>alloc</code> returns <code>NULL</code>, return
! <code>NULL</code>.  If the <code>constructor</code> throws an
! exception, call <code>destructor</code> for any already constructed
! elements, and rethrow the exception.  If the <code>destructor</code>
! throws an exception, call <code>std::terminate</code>.</p>
! 
! <p>The constructor may be <code>NULL</code>, in which case it must
! not be called.  If the <code>padding_size</code> is zero, the
! <code>destructor</code> may be <code>NULL</code>; in that case it must
! not be called.</p>
! 
! <p>Neither <code>alloc</code> nor <code>dealloc</code> may be
! <code>NULL</code>.</p>
  </dd>
  
  <dt><code><pre>
  extern "C" void * __cxa_vec_new3 (
  	    size_t element_count,
*************** unwind table location.
*** 4899,4908 ****
--- 4903,4918 ----
  
  <p> <hr> <p>
  <a name=revisions>
  <h2> Appendix R: Revision History </h2>
  <p> <hr> <p>
+ 
+ <p>
+ <font color=blue>[030905]</font>
+ Specify the behavior of <code>__cxa_vec_new</code>,
+ <code>__cxa_vec_new2</code>, and <code>__cxa_vec_new3</code> in the
+ event that the allocation function returns <code>NULL</code>.
  
  <p>
  <font color=blue>[030609]</font>
  Use <code>void*<code> instead of <code>dso_handle</code>.