avr/cpp/common/NewDelete.cpp

Go to the documentation of this file.
00001 /**********************************************************************************************************************\
00002 
00003         C++ library for Atmel AVR microcontrollers
00004         Copyright (C) 2007 Lauri Kirikal, Mikk Leini, MT� TT� Robotiklubi
00005 
00006         This program is free software; you can redistribute it and/or
00007         modify it under the terms of the GNU General Public License
00008         as published by the Free Software Foundation; either version 2
00009         of the License, or (at your option) any later version.
00010 
00011         This program 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 this program; if not, write to the Free Software
00018         Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00019 
00020         See http://creativecommons.org/licenses/GPL/2.0/
00021 
00022         MT� TT� Robotiklubi  http://www.robotiklubi.ee robotiklubi@gmail.com
00023         Lauri Kirikal        laurikirikal@gmail.com
00024         Mikk Leini           mikk.leini@gmail.com
00025 
00026 \**********************************************************************************************************************/
00027 
00028 extern "C++" {
00029 
00030         namespace std
00031         {
00032                 typedef unsigned int size_t;
00033                 typedef void (*new_handler)();
00034                 new_handler set_new_handler(new_handler) throw();
00035         }
00036         
00037         void operator delete(void*) throw();
00038         void operator delete[](void*) throw();
00039         void* operator new(std::size_t) throw();
00040         void* operator new[](std::size_t) throw();
00041         void operator delete(void*) throw();
00042         void operator delete[](void*) throw();
00043 
00044 }
00045 
00046 using std::new_handler;
00047 extern "C" void *malloc (std::size_t);
00048 extern "C" void free(void *);
00049 extern "C" void abort() __attribute__((noreturn));
00050 extern "C" void __cxa_pure_virtual();
00051 new_handler __new_handler;
00052 
00053 void * operator new (std::size_t sz) throw()
00054 {
00055     void *p;
00056     if (sz == 0)
00057         sz = 1;
00058     p = (void*) malloc(sz);
00059 
00060     while (p == 0)
00061     {
00062         new_handler handler = __new_handler;
00063         if (! handler)
00064             return 0;
00065         handler();
00066         p = (void *) malloc(sz);
00067     }
00068 
00069     return p;
00070 }
00071 
00072 void * operator new[] (std::size_t sz) throw()
00073 {
00074   return ::operator new(sz);
00075 }
00076 
00077 void operator delete (void *ptr) throw ()
00078 {
00079   if (ptr)
00080     free (ptr);
00081 }
00082 
00083 void operator delete[] (void *ptr) throw ()
00084 {
00085   ::operator delete (ptr);
00086 }
00087 
00088 void __cxa_pure_virtual()
00089 {
00090     abort();
00091 }
00092 
00093 

Generated on Sat Sep 15 23:41:46 2007 for AVR C++ Lib (common) by  doxygen 1.5.2
SourceForge.net Logo MTÜ TTÜ Robotiklubi