This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: stl_alloc.h: malloc_alloc out of memory handling abort()s instead
- To: Mike Harrold <mharrold at cas dot org>
- Subject: Re: stl_alloc.h: malloc_alloc out of memory handling abort()s instead
- From: Kip Macy <kip at lyris dot com>
- Date: Sun, 8 Aug 1999 20:30:41 -0700 (PDT)
- cc: doko at cs dot tu-berlin dot de, gcc-bugs at gcc dot gnu dot org, inaky at peloncho dot fis dot ucm dot es, 42622-forwarded at bugs dot debian dot org
That is always the conundrum of dealing with exceptions.
-Kip
On Sun, 8 Aug 1999, Mike Harrold wrote:
> Please correct me if I am wrong, I'm trying to remember back quite a way.
> I believe this is because the exception mechanism needs to allocate memory
> in order to throw an exception the way gcc handles exceptions. Since it
> is already out of memory, trying to allocate more memory probably isn't
> a good idea.
>
> I seem to remember some mail in the past regarding this situation.
>
> /Mike
>
> >
> > That is really weird -- I thought the standard specified that it should be
> > throwing bad_alloc.
> > -Kip
> >
> >
> >
> > On Sun, 8 Aug 1999, Matthias Klose wrote:
> >
> > > [This bug/behaviour was reported to me as a co-maintainer of the
> > > Debian GNU/Linux GCC packages. Please Cc: 42622@bugs.debian.org in
> > > your response so it gets archived in the Debian bugtracking system
> > > (http://www.debian.org/Bugs/db/42/42622.html).]
> > >
> > >
> > > While coding some proof-of-concepts I've come around using a
> > > vector<> of a big lot of elements. Wanted to push the limits and try
> > > to recover possible failures. No way. The program was aborting on the
> > > library's own.
> > >
> > > That should not do. You want exceptions to be able to dictate
> > > how the program should behave on error situations. The thing is at
> > > stl_alloc.h, instead of throwing an exception on OOM, it was printing
> > > the message "out of memory" to stderr and aborting. It is also
> > > prepared for doing it via exceptions, so I think it should be the
> > > default way.
> > >
> > > I think that behaviour should be made extensible to the whole
> > > libstdc++ library, as as far as I know, exception support in GCC is
> > > mature enough as to handle it [and I hope so :)]. That's the only way
> > > to fully control a program's flow. Libraries should not dictate what
> > > to do on error [I'm sure I'm not telling you anything new].
> > >
> > > The changes to make stl_alloc work ok with exceptions are:
> > >
> > > diff -uN /usr/include/g\+\+-3/stl_alloc.h\~ /usr/include/g\+\+-3/stl_alloc.h
> > > --- /usr/include/g++-3/stl_alloc.h~ Fri May 7 12:13:28 1999
> > > +++ /usr/include/g++-3/stl_alloc.h Sat Aug 7 04:16:22 1999
> > > @@ -38,7 +38,7 @@
> > > // The allocation primitives are intended to allocate individual objects,
> > > // not larger arenas as with the original STL allocators.
> > >
> > > -#if 0
> > > +#if 1
> > > # include <new>
> > > # define __THROW_BAD_ALLOC throw bad_alloc()
> > > #elif !defined(__THROW_BAD_ALLOC)
> > >
> > > Thanks, anyway, for such nice packages for GCC & Co.
> > >
> > > Your happy Debian user,
> > >
> > >
> >
> >
> >
>
>
>