00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00036 #ifndef _walloc_h_
00037 #define _walloc_h_
00038
00039 #include "common.h"
00040 #include "malloc.h"
00041
00042
00043
00044
00045
00046
00047 #if defined(USE_DMALLOC) && !defined(REMAP_ZALLOC)
00048 #define REMAP_ZALLOC
00049 #endif
00050
00051 #ifdef REMAP_ZALLOC
00052
00053 #ifdef TRACK_ZALLOC
00054 #error "TRACK_ZALLOC and REMAP_ZALLOC are mutually exclusive"
00055 #endif
00056
00057 #if 0 && GLIB_CHECK_VERSION(2, 10, 0)
00058 static inline gpointer walloc(size_t size) { return g_slice_alloc(size); }
00059 static inline gpointer walloc0(size_t size) { return g_slice_alloc0(size); }
00060 static inline void wfree(gpointer p, size_t size) { g_slice_free1(size, p); }
00061
00062 static inline gpointer
00063 wcopy(gconstpointer p, size_t size)
00064 {
00065 gpointer x = g_slice_alloc(size);
00066 memcpy(x, p, size);
00067 return x;
00068 }
00069
00070 static inline gpointer
00071 wrealloc(gpointer p, size_t old_size, size_t new_size)
00072 {
00073 gpointer x = g_slice_alloc(new_size);
00074 memcpy(x, p, MIN(new_size, old_size));
00075 g_slice_free1(old_size, p);
00076 return x;
00077 }
00078
00079 #else
00080 #define walloc(s) g_malloc(s)
00081 #define walloc0(s) g_malloc0(s)
00082
00083 static inline gpointer
00084 wcopy(gconstpointer p, size_t size)
00085 {
00086 return g_memdup(p, size);
00087 }
00088
00089 static inline void
00090 wfree(gpointer p, size_t size)
00091 {
00092 (void) size;
00093 g_free(p);
00094 }
00095
00096 static inline gpointer
00097 wrealloc(gpointer p, size_t o, size_t n)
00098 {
00099 (void) o;
00100 return g_realloc(p, n);
00101 }
00102 #endif
00103
00104 #else
00105
00106 gpointer walloc(size_t size) WARN_UNUSED_RESULT G_GNUC_MALLOC;
00107 gpointer walloc0(size_t size) WARN_UNUSED_RESULT G_GNUC_MALLOC;
00108 void wfree(gpointer ptr, size_t size);
00109 gpointer wrealloc(gpointer old, size_t old_size, size_t new_size)
00110 WARN_UNUSED_RESULT G_GNUC_MALLOC;
00111 static inline gpointer wcopy(gconstpointer ptr, size_t size)
00112 WARN_UNUSED_RESULT G_GNUC_MALLOC;
00113
00114 static inline gpointer
00115 wcopy(gconstpointer ptr, size_t size)
00116 {
00117 gpointer cp = walloc(size);
00118 memcpy(cp, ptr, size);
00119 return cp;
00120 }
00121
00122 #endif
00123
00124 #ifdef TRACK_ZALLOC
00125
00126 #define walloc(s) walloc_track(s, __FILE__, __LINE__)
00127 #define wcopy(p,s) wcopy_track(p, s, __FILE__, __LINE__)
00128 #define walloc0(s) walloc0_track(s, __FILE__, __LINE__)
00129 #define wrealloc(p,o,n) wrealloc_track(p, o, n, __FILE__, __LINE__)
00130
00131 gpointer walloc_track(size_t size, gchar *file, gint line);
00132 gpointer walloc0_track(size_t size, gchar *file, gint line);
00133 gpointer wcopy_track(gconstpointer, size_t size, gchar *file, gint line);
00134 gpointer wrealloc_track(gpointer old, size_t old_size, size_t new_size,
00135 gchar *file, gint line);
00136
00137 #endif
00138
00139 void wdestroy(void);
00140
00141 #define WFREE_NULL(p,size) \
00142 G_STMT_START { \
00143 if (p) { \
00144 wfree(p,size); \
00145 p = NULL; \
00146 } \
00147 } G_STMT_END
00148
00149 #endif
00150