Whole document tree
    

Whole document tree

new_op.cc Source File
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

new_op.cc

Go to the documentation of this file.
00001 // Support routines for the -*- C++ -*- dynamic memory management.
00002 // Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation
00003 //
00004 // This file is part of GNU CC.
00005 //
00006 // GNU CC is free software; you can redistribute it and/or modify
00007 // it under the terms of the GNU General Public License as published by
00008 // the Free Software Foundation; either version 2, or (at your option)
00009 // any later version.
00010 //
00011 // GNU CC is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU General Public License
00017 // along with GNU CC; see the file COPYING.  If not, write to
00018 // the Free Software Foundation, 59 Temple Place - Suite 330,
00019 // Boston, MA 02111-1307, USA.
00020 //
00021 // As a special exception, you may use this file as part of a free software
00022 // library without restriction.  Specifically, if other files instantiate
00023 // templates or use macros or inline functions from this file, or you compile
00024 // this file and link it with other files to produce an executable, this
00025 // file does not by itself cause the resulting executable to be covered by
00026 // the GNU General Public License.  This exception does not however
00027 // invalidate any other reasons why the executable file might be covered by
00028 // the GNU General Public License.
00029 
00030 #include "new"
00031 #include <exception_defines.h>
00032 
00033 using std::new_handler;
00034 using std::bad_alloc;
00035 
00036 extern "C" void *malloc (std::size_t);
00037 extern new_handler __new_handler;
00038 
00039 void *
00040 operator new (std::size_t sz) throw (std::bad_alloc)
00041 {
00042   void *p;
00043 
00044   /* malloc (0) is unpredictable; avoid it.  */
00045   if (sz == 0)
00046     sz = 1;
00047   p = (void *) malloc (sz);
00048   while (p == 0)
00049     {
00050       new_handler handler = __new_handler;
00051       if (! handler)
00052 #ifdef __EXCEPTIONS
00053     throw bad_alloc();
00054 #else
00055         std::abort();
00056 #endif
00057       handler ();
00058       p = (void *) malloc (sz);
00059     }
00060 
00061   return p;
00062 }

Generated on Mon Apr 8 03:11:30 2002 for libstdc++-v3 Source by doxygen1.2.15