00001 00002 /* 00003 * Copyright (C) 1997 by the University of Southern California 00004 * $Id: dmalloc_support.cc,v 1.8 2005/08/25 18:58:06 johnh Exp $ 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 * version 2, as published by the Free Software Foundation. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License along 00016 * with this program; if not, write to the Free Software Foundation, Inc., 00017 * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 00018 * 00019 * 00020 * The copyright of this module includes the following 00021 * linking-with-specific-other-licenses addition: 00022 * 00023 * In addition, as a special exception, the copyright holders of 00024 * this module give you permission to combine (via static or 00025 * dynamic linking) this module with free software programs or 00026 * libraries that are released under the GNU LGPL and with code 00027 * included in the standard release of ns-2 under the Apache 2.0 00028 * license or under otherwise-compatible licenses with advertising 00029 * requirements (or modified versions of such code, with unchanged 00030 * license). You may copy and distribute such a system following the 00031 * terms of the GNU GPL for this module and the licenses of the 00032 * other code concerned, provided that you include the source code of 00033 * that other code when and as the GNU GPL requires distribution of 00034 * source code. 00035 * 00036 * Note that people who make modified versions of this module 00037 * are not obligated to grant this special exception for their 00038 * modified versions; it is their choice whether to do so. The GNU 00039 * General Public License gives permission to release a modified 00040 * version without this exception; this exception also makes it 00041 * possible to release a modified version which carries forward this 00042 * exception. 00043 * 00044 */ 00045 00046 00047 /* 00048 * Redefine new and friends to use dmalloc. 00049 */ 00050 00051 #ifdef HAVE_LIBDMALLOC 00052 00053 /* 00054 * XXX dmalloc 3.x is no longer supported 00055 * 00056 * - haoboy, Aug 2000 00057 */ 00058 00059 /* 00060 * This portion copied from ~dmalloc/dmalloc.cc 00061 * Copyright 1999 by Gray Watson 00062 */ 00063 extern "C" { 00064 #include <stdio.h> 00065 #include <stdlib.h> 00066 00067 /* Prototype declaration for TclpAlloc originally 00068 defined in tcl8.3.2/generic/tclAlloc.c */ 00069 char *TclpAlloc(unsigned int); 00070 char *Tcl_Alloc(unsigned int); 00071 00072 00073 #define DMALLOC_DISABLE 00074 00075 #include "dmalloc.h" 00076 #include "return.h" 00077 } 00078 00079 #ifndef DMALLOC_VERSION_MAJOR 00080 #error DMALLOC 3.x is no longer supported. 00081 #endif 00082 00083 /* 00084 * An overload function for the C++ new. 00085 */ 00086 void * 00087 operator new[](size_t size) 00088 { 00089 char *file; 00090 GET_RET_ADDR(file); 00091 return _malloc_leap(file, 0, size); 00092 } 00093 00094 /* 00095 * An overload function for the C++ delete. 00096 */ 00097 void 00098 operator delete(void *pnt) 00099 { 00100 char *file; 00101 GET_RET_ADDR(file); 00102 _free_leap(file, 0, pnt); 00103 } 00104 00105 /* 00106 * An overload function for the C++ delete[]. Thanks to Jens Krinke 00107 * <j.krinke@gmx.de> 00108 */ 00109 void 00110 operator delete[](void *pnt) 00111 { 00112 char *file; 00113 GET_RET_ADDR(file); 00114 _free_leap(file, 0, pnt); 00115 } 00116 00117 char * 00118 TclpAlloc(unsigned int nbytes) 00119 { 00120 char *file; 00121 00122 GET_RET_ADDR(file); 00123 return (char*) _malloc_leap(file,0,nbytes); 00124 } 00125 00126 char * 00127 Tcl_Alloc (unsigned int size) 00128 /* unsigned int size; */ 00129 { 00130 char *result; 00131 char *file; 00132 00133 /* 00134 * Replacing the call to TclpAlloc with malloc directly to help 00135 * memory debugging 00136 * result = TclpAlloc(size); 00137 */ 00138 00139 GET_RET_ADDR(file); 00140 result = (char *)_malloc_leap(file,0,size); 00141 /* 00142 * Most systems will not alloc(0), instead bumping it to one so 00143 * that NULL isn't returned. Some systems (AIX, Tru64) will alloc(0) 00144 * by returning NULL, so we have to check that the NULL we get is 00145 * not in response to alloc(0). 00146 * 00147 * The ANSI spec actually says that systems either return NULL *or* 00148 * a special pointer on failure, but we only check for NULL 00149 */ 00150 00151 if ((result == NULL) && size) { 00152 printf("unable to alloc %d bytes", size); 00153 } 00154 return result; 00155 } 00156 00157 00158 #endif /* HAVE_LIBDMALLOC */
1.4.6