dmalloc.cpp Source File (kdecore Library)

| # kdecore Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# dmalloc.cpp

    00001 /*
    00002  * File that facilitates C++ program debugging.
    00003  *
    00004  * Copyright 1999 by Gray Watson
    00005  *
    00006  * This file is part of the dmalloc package.
    00007  *
    00008  * Permission to use, copy, modify, and distribute this software for
    00009  * any purpose and without fee is hereby granted, provided that the
    00010  * above copyright notice and this permission notice appear in all
    00011  * copies, and that the name of Gray Watson not be used in advertising
    00012  * or publicity pertaining to distribution of the document or software
    00013  * without specific, written prior permission.
    00014  *
    00015  * Gray Watson makes no representations about the suitability of the
    00016  * software described herein for any purpose.  It is provided "as is"
    00017  * without express or implied warranty.
    00018  *
    00019  * The author may be contacted via http://www.dmalloc.com/
    00020  *
    00021  * $Id: dmalloc.cpp,v 1.3 1999/10/23 16:16:23 kulow Exp $
    00022  */
    00023
    00024 /*
    00025  * This file is used to effectively redirect new to the more familiar
    00026  * malloc and delete to the more familiar free so they can be debugged
    00027  * with the debug malloc library..  They also give the known error
    00028  * behavior, too.
    00029  *
    00030  * Compile and link this in with the C++ program you want to debug.
    00031  *
    00032  * NOTE: I am not a C++ hacker so feedback in the form of other hints
    00033  * and ideas for C++ users would be much appreciated.
    00034  */
    00035
    00036 #include <config.h>
    00037 #ifdef WITH_DMALLOC2
    00038
    00039 extern "C" {
    00040 #include <stdlib.h>
    00041 #include <stdio.h>
    00042
    00043 #define DMALLOC_DISABLE
    00044
    00045 #include "dmalloc.h"
    00046 #include "return.h"
    00047 }
    00048
    00049 /*
    00050  * An overload function for the C++ new.
    00051  */
    00052 void *
    00053 operator new(size_t size, const char *file, const int line)
    00054 {
    00055     return _malloc_leap(file, line, size);
    00056 }
    00057
    00058 void *
    00059 operator new(size_t size)
    00060 {
    00061     char        *file;
    00062     GET_RET_ADDR(file);
    00063     return _malloc_leap(file, 0, size);
    00064 }
    00065
    00066 /*
    00067  * An overload function for the C++ new[].
    00068  */
    00069 void *
    00070 operator new[](size_t size, const char *file, const int line)
    00071 {
    00072     if (!size) size++;
    00073
    00074     return _malloc_leap(file, line, size);
    00075 }
    00076
    00077 /*
    00078  * An overload function for the C++ new[].
    00079  */
    00080 void *
    00081 operator new[](size_t size)
    00082 {
    00083     if (!size) size++;
    00084
    00085     char        *file;
    00086     GET_RET_ADDR(file);
    00087     return _malloc_leap(file, 0, size);
    00088 }
    00089
    00090 /*
    00091  * An overload function for the C++ delete.
    00092  */
    00093 void
    00094 operator delete(void *pnt)
    00095 {
    00096     if (!pnt)
    00097         return;
    00098
    00099     char        *file;
    00100     GET_RET_ADDR(file);
    00101     _free_leap(file, 0, pnt);
    00102 }
    00103
    00104 /*
    00105  * An overload function for the C++ delete[].  Thanks to Jens Krinke
    00106  * <j.krinke@gmx.de>
    00107  */
    00108 void
    00109 operator delete[](void *pnt)
    00110 {
    00111     if (!pnt)
    00112         return;
    00113
    00114     char        *file;
    00115     GET_RET_ADDR(file);
    00116     _free_leap(file, 0, pnt);
    00117 }
    00118
    00119 #endif
    00120

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 12:46:17 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001