This is the mail archive of the libstdc++@sourceware.cygnus.com mailing list for the libstdc++ project. See the libstdc++ home page for more information.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: PATCH: libio/streambuf.h


Nathan Sidwell wrote:
> here's a patch for libio/streambuf.h. It contains some undefined C++ code by

From the egcs list,
Mark Mitchell wrote:
>   Actually, shouldn't the libio change be:
> 
>     operator delete[](_arrays)
> 
> rather than:
> 
>     operator delete (_arrays)?
oops, you are correct. _But_ libio would still appear to be relying on
implementation defined behaviour. _arrays is allocated as `new T[e]'
(ioextend.cc/get_array_element) where T is a POD struct. This is array new, so
array delete should be used, as you point out. 5.3.4/10 says the implementation
has liberty to allocate more space for vector new (secrete a cookie, so
delete[] knows how many dtors to call). We only add the cookie, if the type has
a dtor (or the delete[] takes a size operand), so libio's usage is ok. The
second half of 5.3.4/10 indicates that even `new char[e]' can have a cookie. We
do not document this feature - perhaps we should ...

Sorry for not getting it right first time.

nathan
-- 
Dr Nathan Sidwell :: Computer Science Department :: Bristol University
      You can up the bandwidth, but you can't up the speed of light      
nathan@acm.org  http://www.cs.bris.ac.uk/~nathan/  nathan@cs.bris.ac.uk
libio/ChangeLog:
Fri Apr 16 09:44:36 BST 1999  Nathan Sidwell  <nathan@acm.org>

	* streambuf.h (ios::~ios): Use operator delete[] to remove _arrays.

Index: egcs/libio/streambuf.h
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/libio/streambuf.h,v
retrieving revision 1.5
diff -c -3 -p -r1.5 streambuf.h
*** streambuf.h	1998/02/24 20:09:55	1.5
--- streambuf.h	1999/04/16 08:40:42
*************** inline ios::~ios() {
*** 482,488 ****
  #ifndef _IO_NEW_STREAMS
      if (!(_flags & (unsigned int)ios::dont_close)) delete rdbuf();
  #endif
!     if (_arrays) delete [] _arrays;
  }
  } // extern "C++"
  #endif /* _STREAMBUF_H */
--- 482,490 ----
  #ifndef _IO_NEW_STREAMS
      if (!(_flags & (unsigned int)ios::dont_close)) delete rdbuf();
  #endif
!     // It is safe to use naked operator delete[] as we know elements have no
!     // dtor, and g++ does not add a new[] cookie for such cases.
!     operator delete[] (_arrays);
  }
  } // extern "C++"
  #endif /* _STREAMBUF_H */