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 #ifndef R_MALLOC_H
00046 #define R_MALLOC_H
00047
00048
00049
00050
00051
00052 #include <stdlib.h>
00053 #include <string.h>
00054
00055
00056
00057
00058
00059
00060
00061
00062 #define FUNCTIONIZE(a,b) a(b)
00063 #define STRINGIZE(a) #a
00064 #define INT2STRING(i) FUNCTIONIZE(STRINGIZE,i)
00065
00066
00067 #define RM_STATIC (0x0001 << 0)
00068 #define RM_STRING (0x0001 << 1)
00069
00070 #ifdef MALLOC_DEBUG
00071
00072 #define RM_FILE_POS __FILE__ ":" INT2STRING(__LINE__)
00073
00074 #ifdef RM_UPPERSTYLE
00075
00076 # define MALLOC(s) Rmalloc((s), RM_FILE_POS)
00077 # define CALLOC(n,s) Rcalloc((n), (s), RM_FILE_POS)
00078 # define REALLOC(p,s) Rrealloc((p), (s), RM_FILE_POS)
00079 # define FREE(p) Rfree((p), RM_FILE_POS)
00080 # define FREE0(p) Rfree((p), RM_FILE_POS),(p)=NULL
00081 # define STRDUP(s) Rstrdup((s), RM_FILE_POS)
00082 #else
00083
00084 # define malloc(s) Rmalloc((s), RM_FILE_POS)
00085 # define calloc(n,s) Rcalloc((n), (s), RM_FILE_POS)
00086 # define realloc(p,s) Rrealloc((p), (s), RM_FILE_POS)
00087 # define free(p) Rfree((p), RM_FILE_POS)
00088 # define free0(p) Rfree((p), RM_FILE_POS),(p)=NULL
00089 # define strdup(s) Rstrdup((s), RM_FILE_POS)
00090 # define getcwd(b,s) Rgetcwd((b), (s), RM_FILE_POS)
00091 #endif
00092 #define RM_TEST Rmalloc_test(RM_FILE_POS)
00093 #define RM_STAT Rmalloc_stat(RM_FILE_POS)
00094 #define RM_RETAG(p) Rmalloc_retag((p), RM_FILE_POS)
00095 #define RM_SET(p, f) Rmalloc_set_flags((p), (f), RM_FILE_POS)
00096
00097 #else
00098
00099 #ifdef RM_UPPERSTYLE
00100
00101 # define MALLOC(s) malloc((s))
00102 # define CALLOC(n,s) calloc((n), (s))
00103 # define REALLOC(p,s) realloc((p), (s))
00104 # define FREE(p) free((p))
00105 # define FREE0(p) free((p)), (p)=NULL
00106 # define STRDUP(s) (char *)strdup((s))
00107 #else
00108 # define free0(p) free((p)), (p)=NULL
00109 #endif
00110 #define RM_TEST
00111 #define RM_STAT
00112 #define RM_RETAG(p) (p)
00113 #define RM_SET(p, f) (p)
00114
00115 #endif
00116
00117
00118
00119
00120
00121 #if defined(MALLOC_DEBUG) || defined(RM_NEED_PROTOTYPES)
00122 void *Rmalloc(size_t size, const char *file);
00123 void *Rcalloc(size_t nelem, size_t size, const char *file);
00124 void *Rrealloc(void *p, size_t size, const char *file);
00125 void Rfree(void *p, const char *file);
00126 char *Rstrdup(const char *str, const char *file);
00127 char *Rgetcwd(char *buffer, size_t size, const char *file);
00128 void Rtest_malloc(const char *file);
00129 void Rmalloc_test(const char *file);
00130 void Rmalloc_stat(const char *file);
00131 void *Rmalloc_retag(void *p, const char *file);
00132 void *Rmalloc_set_flags(void *p, unsigned flags, const char *file);
00133 #endif
00134
00135 #endif