Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

walloc.h

Go to the documentation of this file.
00001 /*
00002  * $Id: walloc.h,v 1.5 2005/11/02 09:29:55 cbiere Exp $
00003  *
00004  * Copyright (c) 2002-2003, Raphael Manfredi
00005  *
00006  *----------------------------------------------------------------------
00007  * This file is part of gtk-gnutella.
00008  *
00009  *  gtk-gnutella is free software; you can redistribute it and/or modify
00010  *  it under the terms of the GNU General Public License as published by
00011  *  the Free Software Foundation; either version 2 of the License, or
00012  *  (at your option) any later version.
00013  *
00014  *  gtk-gnutella is distributed in the hope that it will be useful,
00015  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  *  GNU General Public License for more details.
00018  *
00019  *  You should have received a copy of the GNU General Public License
00020  *  along with gtk-gnutella; if not, write to the Free Software
00021  *  Foundation, Inc.:
00022  *      59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023  *----------------------------------------------------------------------
00024  */
00025 
00036 #ifndef _walloc_h_
00037 #define _walloc_h_
00038 
00039 #include <glib.h>
00040 
00041 /*
00042  * Under REMAP_ZALLOC control, those routines are remapped to malloc/free.
00043  * Under TRACK_ZALLOC, we keep tack of the allocation places.
00044  */
00045 
00046 #if defined(USE_DMALLOC) && !defined(REMAP_ZALLOC)
00047 #define REMAP_ZALLOC
00048 #endif
00049 
00050 #ifdef REMAP_ZALLOC
00051 
00052 #ifdef TRACK_ZALLOC
00053 #error "TRACK_ZALLOC and REMAP_ZALLOC are mutually exclusive"
00054 #endif
00055 
00056 #define walloc(s)           g_malloc(s)
00057 #define walloc0(s)          g_malloc0(s)
00058 #define wcopy(p,s)          g_memdup((p), (s))
00059 #define wfree(p,s)          g_free(p)
00060 #define wrealloc(p,o,n)     g_realloc((p), (n));
00061 
00062 #else   /* !REMAP_ZALLOC */
00063 
00064 gpointer walloc(size_t size);
00065 gpointer walloc0(size_t size);
00066 void wfree(gpointer ptr, size_t size);
00067 gpointer wrealloc(gpointer old, size_t old_size, size_t new_size);
00068 
00069 static inline WARN_UNUSED_RESULT gpointer
00070 wcopy(gconstpointer ptr, size_t size)
00071 {
00072     gpointer cp = walloc(size);
00073     memcpy(cp, ptr, size);
00074     return cp;
00075 }
00076 
00077 #endif  /* REMAP_ZALLOC */
00078 
00079 #ifdef TRACK_ZALLOC
00080 
00081 #define walloc(s)           walloc_track(s, __FILE__, __LINE__)
00082 #define wcopy(p,s)          wcopy_track(p, s, __FILE__, __LINE__)
00083 #define walloc0(s)          walloc0_track(s, __FILE__, __LINE__)
00084 #define wrealloc(p,o,n)     wrealloc_track(p, o, n, __FILE__, __LINE__)
00085 
00086 gpointer walloc_track(size_t size, gchar *file, gint line);
00087 gpointer walloc0_track(size_t size, gchar *file, gint line);
00088 gpointer wcopy_track(gconstpointer, size_t size, gchar *file, gint line);
00089 gpointer wrealloc_track(gpointer old, size_t old_size, size_t new_size,
00090     gchar *file, gint line);
00091 
00092 #endif  /* TRACK_ZALLOC */
00093 
00094 void wdestroy(void);
00095 
00096 #define WFREE_NULL(p,size)  \
00097 G_STMT_START {              \
00098     if (p) {                \
00099         wfree(p,size);      \
00100         p = NULL;           \
00101     }                       \
00102 } G_STMT_END
00103 
00104 #endif /* _walloc_h_ */
00105 /* vi: set ts=4 sw=4 cindent: */

Generated on Sun Feb 12 10:49:58 2006 for Gtk-Gnutella by doxygen 1.3.6