00001 #ifndef __XALLOC_H
00002 #define __XALLOC_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #include "arch.h"
00042
00043
00044
00045
00046
00047 #ifndef XALLOC_LVL
00048 #ifdef NDEBUG
00049 #define XALLOC_LVL 1
00050 #else
00051 #define XALLOC_LVL 2
00052 #endif
00053 #endif
00054
00055
00056
00057
00058 #if XALLOC_LVL==2
00059 #define __XALLOC_XFUNCS
00060 #define __XALLOC_SRCNAME
00061
00062 #elif XALLOC_LVL==1
00063 #define __XALLOC_XFUNCS
00064
00065 #elif XALLOC_LVL==-2
00066 #define __XALLOC_XFUNCS
00067 #define __XALLOC_SRCNAME
00068 #define __XALLOC_STDOVL
00069
00070 #elif XALLOC_LVL==-1
00071 #define __XALLOC_XFUNCS
00072 #define __XALLOC_STDOVL
00073
00074 #endif
00075
00076
00077
00078 #ifdef __cplusplus
00079 extern "C" {
00080 #endif
00081
00082
00083
00084
00085
00086 #define XALLOC_BLK_NOT_CORRUPTED 0
00087 #define XALLOC_BLK_CORRUPTED_START 1
00088 #define XALLOC_BLK_CORRUPTED_END 2
00089 #define XALLOC_BLK_CORRUPTED 3
00090 #define XALLOC_BLK_NULLPTR 4
00091
00092 #define XALLOC_HEAP_NOT_CORRUPTED 0
00093 #define XALLOC_HEAP_CORRUPTED 5
00094 #define XALLOC_HEAP_WRITE_IN_FREE_MEM 6
00095 #define XALLOC_HEAP_VERY_CORRUPTED 7
00096
00097
00098
00099
00100 #ifdef __XALLOC_SRCNAME
00101 #define IFLARGS char *srcname, int line
00102 #define IFLPARAM __FILE__,__LINE__
00103 #define FLARGS ,char *srcname, int line
00104 #define FLPARAM ,__FILE__,__LINE__
00105 #else
00106 #define IFLARGS
00107 #define IFLPARAM
00108 #define FLARGS
00109 #define FLPARAM
00110 #endif
00111
00112 #ifdef __XALLOC_XFUNCS
00113
00114 #ifdef __XALLOC_SRCNAME
00115 void * _xmalloc_src( unsigned long size FLARGS );
00116 void * _xcalloc_src( unsigned long nitems, unsigned long size FLARGS );
00117 void _xfree_src( void * block FLARGS );
00118 char * _xstrdup_src( const char * str FLARGS );
00119 unsigned long _xblksize_src( void * block FLARGS );
00120 void _xblk2disk_src( char * fname, void * block FLARGS );
00121 void * _xdisk2blk_src( char * fname FLARGS );
00122 void _assertblk_src( void * block FLARGS );
00123 void _assertheap_src( IFLARGS );
00124 #else
00125 void * _xmalloc( unsigned long size );
00126 void * _xcalloc( unsigned long nitems, unsigned long size );
00127 void _xfree( void * block );
00128 char * _xstrdup( const char * str );
00129 unsigned long _xblksize( void * block );
00130 void _xblk2disk( char * fname, void * block );
00131 void * _xdisk2blk( char * fname );
00132 void _assertblk( void * block );
00133 void _assertheap( void );
00134 #endif
00135 #endif
00136
00137
00138
00139 #ifdef __XALLOC_XFUNCS
00140
00141 #ifdef __XALLOC_SRCNAME
00142 #define xmalloc(unsigned_long_size) _xmalloc_src(unsigned_long_size FLPARAM)
00143 #define xcalloc(unsigned_long_nitems,unsigned_long_size) _xcalloc_src(unsigned_long_nitems,unsigned_long_size FLPARAM)
00144 #define xfree(void_ptr_block) _xfree_src(void_ptr_block FLPARAM)
00145 #define xstrdup(const_char_ptr_str) _xstrdup_src(const_char_ptr_str FLPARAM)
00146 #define xblksize(void_ptr_block) _xblksize_src(void_ptr_block FLPARAM)
00147 unsigned long xusedmem( void );
00148 int testblk( void * block );
00149 #define assertblk(void_ptr_block) _assertblk_src(void_ptr_block FLPARAM)
00150 void fillheap( void );
00151 unsigned long xusedheap( void );
00152 int testheap( void );
00153 #define assertheap() _assertheap_src(FLPARAM)
00154 #define heapcmd(cmd) { assertheap(); cmd; fillheap(); }
00155 #define xblk2disk(char_ptr_fname,void_ptr_block) \
00156 _xblk2disk_src(char_ptr_fname,void_ptr_block FLPARAM)
00157 #define xdisk2blk(char_ptr_fname) \
00158 _xdisk2blk_src(char_ptr_fname FLPARAM)
00159 #else
00160 #define xmalloc(unsigned_long_size) _xmalloc(unsigned_long_size )
00161 #define xcalloc(unsigned_long_nitems,unsigned_long_size) \
00162 _xcalloc(unsigned_long_nitems,unsigned_long_size)
00163 #define xfree(void_ptr_block) _xfree(void_ptr_block)
00164 #define xstrdup(const_char_ptr_str) _xstrdup(const_char_ptr_str)
00165 #define xblksize(void_ptr_block) _xblksize(void_ptr_block)
00166 unsigned long xusedmem( void );
00167 int testblk( void * block );
00168 #define assertblk(void_ptr_block) _assertblk(void_ptr_block)
00169 void fillheap( void );
00170 unsigned long xusedheap( void );
00171 int testheap( void );
00172 #define assertheap() _assertheap()
00173 #define heapcmd(cmd) { assertheap(); cmd; fillheap(); }
00174 #define xblk2disk(char_ptr_fname,void_ptr_block) \
00175 _xblk2disk(char_ptr_fname,void_ptr_block)
00176 #define xdisk2blk(char_ptr_fname) \
00177 _xdisk2blk(char_ptr_fname)
00178 #endif
00179
00180 void xalloc_logf(int on);
00181 void xalloc_heapcheck(int on);
00182 void xalloc_showmem(int on);
00183 void xalloc_showheap(int on);
00184 void xalloc_showfree(int on);
00185
00186 #else
00187
00188 #include <stdlib.h>
00189 #include <string.h>
00190
00191 #define xmalloc(unsigned_long_size) malloc(unsigned_long_size)
00192 #define xcalloc(unsigned_long_nitems,unsigned_long_size) \
00193 calloc(unsigned_long_nitems,unsigned_long_size)
00194 #define xfree(void_ptr_block) free(void_ptr_block)
00195 #define xstrdup(const_char_ptr_str) strdup(const_char_ptr_str)
00196 #define xblksize(void_ptr_block) 0
00197 #define xusedmem() 0
00198 #define testblk(block) XALLOC_BLK_NOT_CORRUPTED
00199 #define assertblk(void_ptr_block) {}
00200 #define fillheap() {}
00201 #define xusedheap() 0
00202 #define testheap() XALLOC_HEAP_NOT_CORRUPTED
00203 #define assertheap() {}
00204 #define heapcmd(cmd) { cmd; }
00205 #define xblk2disk(char_ptr_fname,void_ptr_block) {}
00206 #define xdisk2blk(char_ptr_fname) NULL
00207
00208 #define xalloc_logf(b) {}
00209 #define xalloc_heapcheck(b) {}
00210 #define xalloc_showmem(b) {}
00211 #define xalloc_showheap(b) {}
00212 #define xalloc_showfree(b) {}
00213
00214 #endif
00215
00216
00217
00218 #ifdef __cplusplus
00219 }
00220 #endif
00221
00222
00223
00224
00225 #ifdef __XALLOC_STDOVL
00226
00227 #define malloc(unsigned_long_size) xmalloc(unsigned_long_size)
00228 #define calloc(unsigned_long_nitems,unsigned_long_size) \
00229 xcalloc(unsigned_long_nitems,unsigned_long_size)
00230 #define free(void_ptr_block) xfree(void_ptr_block)
00231 #define strdup(const_char_ptr_str) xstrdup(const_char_ptr_str)
00232
00233 #ifdef __CC_BORLANDC__
00234 #define farmalloc(unsigned_long_size) xmalloc(unsigned_long_size)
00235 #define farcalloc(unsigned_long_nitems,unsigned_long_size) \
00236 xcalloc(unsigned_long_nitems,unsigned_long_size)
00237 #define farfree(void_ptr_block) xfree(void_ptr_block)
00238 #define _fstrdup(const_char_ptr_str) xstrdup(const_char_ptr_str)
00239 #endif
00240
00241 #endif
00242
00243
00244
00245 #endif