00001 // -*- mode: C++; c-file-style: "stroustrup"; c-basic-offset: 4; indent-tabs-mode: nil; -*- 00002 //////////////////////////////////////////////////////////////////// 00003 // 00004 // Filename : new.h 00005 // 00006 // This file is a part of the UPPAAL toolkit. 00007 // Copyright (c) 1995 - 2003, Uppsala University and Aalborg University. 00008 // All right reserved. 00009 // 00010 // $Id: new.h,v 1.5 2005/07/22 12:55:54 adavid Exp $ 00011 // 00012 /////////////////////////////////////////////////////////////////// 00013 00014 /** 00015 * @file 00016 * Monitor all new/delete operator calls. ALL or NONE of them must be 00017 * monitored. 00018 * Limitations for more information in new: 00019 * 1) no placement constructor 00020 * 2) the new with no exception will fail too. 00021 * 00022 * Limitation for the verbose delete: 00023 * - delete MUST be enclosed within brackets, statements like 00024 * if (test) delete me; WILL FAIL 00025 * => if (test) { delete me; } is correct 00026 * Check this with a grep command. 00027 * 00028 * Define: 00029 * - ENABLE_MONITOR to enable the monitor 00030 * - NNEW_INFO to skip incompatible new replacements -- local to .h or .cpp 00031 * - NDELETE_INFO to skip incompatible delete replacements -- local to .h or .cpp 00032 * 00033 * NOTE: defining NDEBUG will *not* skip this, which allows for 00034 * optimized compilation with new monitor. 00035 */ 00036 00037 #ifndef INCLUDE_DEBUG_NEW_H 00038 #define INCLUDE_DEBUG_NEW_H 00039 00040 #include "debug/monitor.h" 00041 00042 #if !defined(_WIN32) && defined(ENABLE_MONITOR) 00043 00044 #include <new> 00045 00046 #ifndef NNEW_INFO 00047 00048 void *operator new(size_t size,const char*,int,const char*) throw (std::bad_alloc); 00049 void *operator new[](size_t size,const char*,int,const char*) throw (std::bad_alloc); 00050 00051 #define new new(__FILE__,__LINE__,__FUNCTION__) 00052 00053 // Don't need to overload these: they fail anyway! 00054 // void *operator new(size_t size, const std::nothrow_t&) throw(); 00055 // void *operator new[](size_t size, const std::nothrow_t&) throw(); 00056 00057 #endif // NNEW_INFO 00058 00059 #ifndef NDELETE_INFO 00060 #define delete debug_prepareDelete(__FILE__,__LINE__,__FUNCTION__); delete 00061 #endif 00062 00063 #endif // ndef(_WIN32) && def(ENABLE_MONITOR) 00064 00065 #endif // INCLUDE_DEBUG_NEW_H