Back to index

cell-binutils  2.17cvs20070401
new.cc
Go to the documentation of this file.
00001 #include <new>
00002 #include <exception_defines.h>
00003 
00004 using std::bad_alloc;
00005 
00006 extern "C" void *malloc (std::size_t);
00007 extern "C" void abort (void);
00008 
00009 void *
00010 operator new (std::size_t sz, const std::nothrow_t&) throw()
00011 {
00012   void *p;
00013 
00014   /* malloc (0) is unpredictable; avoid it.  */
00015   if (sz == 0)
00016     sz = 1;
00017   p = (void *) malloc (sz);
00018   return p;
00019 }
00020 
00021 void *
00022 operator new (std::size_t sz) throw (std::bad_alloc)
00023 {
00024   void *p;
00025 
00026   /* malloc (0) is unpredictable; avoid it.  */
00027   if (sz == 0)
00028     sz = 1;
00029   p = (void *) malloc (sz);
00030   while (p == 0)
00031     {
00032       ::abort();
00033     }
00034 
00035   return p;
00036 }
00037 
00038 void*
00039 operator new[] (std::size_t sz) throw (std::bad_alloc)
00040 {
00041   return ::operator new(sz);
00042 }
00043 
00044 void *
00045 operator new[] (std::size_t sz, const std::nothrow_t& nothrow) throw()
00046 {
00047   return ::operator new(sz, nothrow);
00048 }