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
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 #ifndef GWMEM_H
00072 #define GWMEM_H
00073
00074
00075 void *gw_native_noop(void *ptr);
00076 void gw_native_init(void);
00077 void gw_native_check_leaks(void);
00078 void *gw_native_malloc(size_t size);
00079 void *gw_native_realloc(void *ptr, size_t size);
00080 void gw_native_free(void *ptr);
00081 char *gw_native_strdup(const char *str);
00082 void gw_native_shutdown(void);
00083
00084
00085 void gw_check_init_mem(int slow_flag);
00086 void gw_check_check_leaks(void);
00087 void *gw_check_malloc(size_t size,
00088 const char *filename, long line, const char *function);
00089 void *gw_check_realloc(void *p, size_t size,
00090 const char *filename, long line, const char *function);
00091 void gw_check_free(void *p,
00092 const char *filename, long line, const char *function);
00093 char *gw_check_strdup(const char *str,
00094 const char *filename, long line, const char *function);
00095 int gw_check_is_allocated(void *p);
00096 long gw_check_area_size(void *p);
00097 void *gw_check_claim_area(void *p,
00098 const char *filename, long line, const char *function);
00099 void gw_check_shutdown(void);
00100
00101
00102
00103
00104
00105
00106 #if USE_GWMEM_SLOW
00107 #define USE_GWMEM_CHECK 1
00108 #endif
00109
00110
00111 #if USE_GWMEM_NATIVE
00112
00113
00114
00115
00116
00117 #define gw_init_mem()
00118 #define gw_check_leaks()
00119 #define gw_malloc(size) (gw_native_malloc(size))
00120 #define gw_malloc_trace(size, file, line, func) (gw_native_malloc(size))
00121 #define gw_realloc(ptr, size) (gw_native_realloc(ptr, size))
00122 #define gw_free(ptr) (gw_native_free(ptr))
00123 #define gw_strdup(str) (gw_native_strdup(str))
00124 #define gw_assert_allocated(ptr, file, line, function)
00125 #define gw_claim_area(ptr) (gw_native_noop(ptr))
00126 #define gw_claim_area_for(ptr, file, line, func) (gw_native_noop(ptr))
00127 #define gwmem_shutdown()
00128 #define gwmem_type() (octstr_imm("native"))
00129
00130 #elif USE_GWMEM_CHECK
00131
00132
00133
00134
00135
00136 #ifdef USE_GWMEM_SLOW
00137 #define gw_init_mem() (gw_check_init_mem(1))
00138 #define gwmem_type() (octstr_imm("slow"))
00139 #else
00140 #define gw_init_mem() (gw_check_init_mem(0))
00141 #define gwmem_type() (octstr_imm("checking"))
00142 #endif
00143
00144 #define gw_check_leaks() (gw_check_check_leaks())
00145 #define gw_malloc_trace(size, file, line, func) \
00146 (gw_check_malloc(size, file, line, func))
00147 #define gw_malloc(size) \
00148 (gw_check_malloc(size, __FILE__, __LINE__, __func__))
00149 #define gw_realloc(ptr, size) \
00150 (gw_check_realloc(ptr, size, __FILE__, __LINE__, __func__))
00151 #define gw_free(ptr) \
00152 (gw_check_free(ptr, __FILE__, __LINE__, __func__))
00153 #define gw_strdup(str) \
00154 (gw_check_strdup(str, __FILE__, __LINE__, __func__))
00155 #define gw_assert_allocated(ptr, file, line, function) \
00156 (gw_assert_place(gw_check_is_allocated(ptr), file, line, function))
00157 #define gw_claim_area(ptr) \
00158 (gw_check_claim_area(ptr, __FILE__, __LINE__, __func__))
00159 #define gw_claim_area_for(ptr, file, line, func) \
00160 (gw_check_claim_area(ptr, file, line, func))
00161 #define gwmem_shutdown() (gw_check_shutdown())
00162
00163 #else
00164
00165
00166
00167
00168 #error "Unknown malloc wrapper."
00169
00170
00171 #endif
00172
00173
00174
00175
00176
00177
00178 #define malloc(n) do_not_call_malloc_directly
00179 #define calloc(a, b) do_not_use_calloc
00180 #define realloc(p, n) do_not_call_realloc_directly
00181 #define free(p) do_not_call_free_directly
00182
00183
00184 #endif
See file LICENSE for details about the license agreement for using,
modifying, copying or deriving work from this software.