]> andersk Git - splint.git/blame - src/Headers/dmalloc.h
Making fixes for Microsoft Visual C++ compiler.
[splint.git] / src / Headers / dmalloc.h
CommitLineData
885824d3 1/*
2 * defines for the dmalloc library
3 *
4 * Copyright 1995 by Gray Watson
5 *
6 * This file is part of the dmalloc package.
7 *
8 * Permission to use, copy, modify, and distribute this software for any
9 * NON-COMMERCIAL purpose and without fee is hereby granted, provided
10 * that the above copyright notice and this permission notice appear
11 * in all copies, and that the name of Gray Watson not be used in
12 * advertising or publicity pertaining to distribution of the document
13 * or software without specific, written prior permission.
14 *
15 * Gray Watson makes no representations about the suitability of the
16 * software described herein for any purpose. It is provided "as is"
17 * without express or implied warranty.
18 *
19 * The author may be contacted at gray.watson@letters.com
20 *
21 * $Id$
22 */
23
24#ifndef __DMALLOC_H__
25#define __DMALLOC_H__
26
27/* this is inserted into dmalloc.h */
28/* used to handle the const operator */
29/* const is available */
30
31/* NOTE: start of $Id$ */
32
33/*
34 * NOTE: some archetectures have malloc, realloc, etc. using size_t or
35 * an unsigned long instead of the traditional unsigned int. You may
36 * have to edit this by hand due to the difficulties I am having
37 * getting it to auto configure. Finding the definition of size_t in
38 * the /usr/include files may be a good guess. YEACH!!
39 *
40 * Uncomment the include file and set to the correct file which
41 * defines the size type, if necessary.
42 */
43#define DMALLOC_SIZE unsigned long
44/* #include <sys/types.h> */
45
46/* this defines what type the standard void memory-pointer is */
47#if defined(__STDC__) && __STDC__ == 1
48#define DMALLOC_PNT void *
49#define DMALLOC_FREE_RET void
50#else
51#define DMALLOC_PNT void *
52#define DMALLOC_FREE_RET void
53#endif
54
55/*
56 * malloc function return codes
57 */
58#define CALLOC_ERROR 0L /* error from calloc */
59#define MALLOC_ERROR 0L /* error from malloc */
60#define REALLOC_ERROR 0L /* error from realloc */
61
62/* NOTE: this if for non- __STDC__ systems only */
63#define FREE_ERROR 0 /* error from free */
64#define FREE_NOERROR 1 /* no error from free */
65
66#define DMALLOC_VERIFY_ERROR 0 /* checks failed, error */
67#define DMALLOC_VERIFY_NOERROR 1 /* checks passed, no error */
68
69/*
70 * default values if _malloc_file and _malloc_line are not set
71 */
72#define DMALLOC_DEFAULT_FILE 0L
73#define DMALLOC_DEFAULT_LINE 0
74#define DMALLOC_UNKNOWN_FILE "unknown"
75
76/*
77 * alloc macros to improve memory usage readibility...
78 */
79#undef ALLOC
80#define ALLOC(type, count) \
81 (type *)malloc((DMALLOC_SIZE)(sizeof(type) * (count)))
82
83#undef MALLOC
84#define MALLOC(size) \
85 (char *)malloc((DMALLOC_SIZE)(size))
86
87/* NOTICE: the arguments are REVERSED from normal calloc() */
88#undef CALLOC
89#define CALLOC(type, count) \
90 (type *)calloc((DMALLOC_SIZE)(count), (DMALLOC_SIZE)sizeof(type))
91
92#undef REALLOC
93#define REALLOC(ptr, type, count) \
94 (type *)realloc((char *)(ptr), (DMALLOC_SIZE)(sizeof(type) * (count)))
95
96#undef REMALLOC
97#define REMALLOC(ptr, size) \
98 (char *)realloc((char *)(ptr), (DMALLOC_SIZE)(size))
99
100#undef FREE
101#define FREE(ptr) \
102 free((char *)(ptr))
103
104/*<<<<<<<<<< The below prototypes are auto-generated by fillproto */
105
106#ifdef __cplusplus
107extern "C" {
108#endif
109
110/* logfile for dumping dmalloc info, DMALLOC_LOGFILE env var overrides this */
111extern char *dmalloc_logpath;
112
113/* internal dmalloc error number for reference purposes only */
114extern int dmalloc_errno;
115
116/* address to look for. when discovered call dmalloc_error() */
117extern DMALLOC_PNT dmalloc_address;
118
119/*
120 * argument to dmalloc_address, if 0 then never call dmalloc_error()
121 * else call it after seeing dmalloc_address for this many times.
122 */
123extern int dmalloc_address_count;
124
125/*
126 * shutdown memory-allocation module, provide statistics if necessary
127 */
128extern void dmalloc_shutdown(void);
129
130/*
131 * allocate and return a SIZE block of bytes. returns 0L on error.
132 */
133extern DMALLOC_PNT malloc(DMALLOC_SIZE size);
134
135/*
136 * allocate and return a block of bytes able to hold NUM_ELEMENTS of elements
137 * of SIZE bytes and zero the block. returns 0L on error.
138 */
139extern DMALLOC_PNT calloc(DMALLOC_SIZE num_elements, DMALLOC_SIZE size);
140
141/*
142 * resizes OLD_PNT to SIZE bytes and return the new space after either copying
143 * all of OLD_PNT to the new area or truncating. returns 0L on error.
144 */
145extern DMALLOC_PNT realloc(DMALLOC_PNT old_pnt, DMALLOC_SIZE new_size);
146
147/*
148 * release PNT in the heap, returning FREE_ERROR, FREE_NOERROR or void
149 * depending on whether STDC is defined by your compiler.
150 */
151extern DMALLOC_FREE_RET free(DMALLOC_PNT pnt);
152
153/*
154 * same as free(PNT)
155 */
156extern DMALLOC_FREE_RET cfree(DMALLOC_PNT pnt);
157
158/*
159 * log the heap structure plus information on the blocks if necessary.
160 */
161extern void dmalloc_log_heap_map(void);
162
163/*
164 * dump dmalloc statistics to logfile
165 */
166extern void dmalloc_log_stats(void);
167
168/*
169 * dump unfreed-memory info to logfile
170 */
171extern void dmalloc_log_unfreed(void);
172
173/*
174 * verify pointer PNT, if PNT is 0 then check the entire heap.
175 * returns MALLOC_VERIFY_ERROR or MALLOC_VERIFY_NOERROR
176 */
177extern int dmalloc_verify(const DMALLOC_PNT pnt);
178
179/*
180 * same as dmalloc_verify
181 */
182extern int _malloc_verify(const DMALLOC_PNT pnt);
183
184/*
185 * set the global debug functionality flags to DEBUG (0 to disable).
186 * NOTE: after this module has started up, you cannot set certain flags
187 * such as fence-post or free-space checking.
188 */
189extern void dmalloc_debug(const int debug);
190
191/*
192 * returns the current debug functionality flags. this allows you to
193 * save a dmalloc library state to be restored later.
194 */
195extern int dmalloc_debug_current(void);
196
197/*
198 * examine pointer PNT and returns SIZE, and FILE / LINE info on it,
199 * or return-address RET_ADDR if any of the pointers are not 0L.
200 * if FILE returns 0L then RET_ATTR may have a value and vice versa.
201 * returns NOERROR or ERROR depending on whether PNT is good or not
202 */
203extern int dmalloc_examine(const DMALLOC_PNT pnt, DMALLOC_SIZE * size,
204 char ** file, unsigned int * line,
205 DMALLOC_PNT * ret_attr);
206
207/*
208 * dmalloc version of strerror to return the string version of ERRNUM
209 * returns the string for MALLOC_BAD_ERRNO if ERRNUM is out-of-range.
210 */
211extern char *dmalloc_strerror(const int errnum);
212
213#ifdef __cplusplus
214}
215#endif
216
217/*<<<<<<<<<< This is end of the auto-generated output from fillproto. */
218
219/*
220 * alloc macros to provide for memory FILE/LINE debugging information.
221 */
222
223#ifndef DMALLOC_DISABLE
224
225#undef calloc
226#define calloc(count, size) \
227 _calloc_leap(__FILE__, __LINE__, count, size)
228#undef free
229#define free(ptr) \
230 _free_leap(__FILE__, __LINE__, ptr)
231#undef malloc
232#define malloc(size) \
233 _malloc_leap(__FILE__, __LINE__, size)
234#undef realloc
235#define realloc(ptr, size) \
236 _realloc_leap(__FILE__, __LINE__, ptr, size)
237
238#undef xcalloc
239#define xcalloc(count, size) \
240 _xcalloc_leap(__FILE__, __LINE__, count, size)
241#undef xfree
242#define xfree(ptr) \
243 _xfree_leap(__FILE__, __LINE__, ptr)
244#undef xmalloc
245#define xmalloc(size) \
246 _xmalloc_leap(__FILE__, __LINE__, size)
247#undef xrealloc
248#define xrealloc(ptr, size) \
249 _xrealloc_leap(__FILE__, __LINE__, ptr, size)
250#undef xstrdup
251#define xstrdup(str) \
252 _xstrdup_leap(__FILE__, __LINE__, str)
253
254#ifdef DMALLOC_FUNC_CHECK
255
256/*
257 * do debugging on the following functions. this may cause compilation or
258 * other problems depending on your architecture.
259 */
260#undef bcmp
261#define bcmp(b1, b2, len) _dmalloc_bcmp(b1, b2, len)
262#undef bcopy
263#define bcopy(from, to, len) _dmalloc_bcopy(from, to, len)
264
265#undef memcmp
266#define memcmp(b1, b2, len) _dmalloc_memcmp(b1, b2, len)
267#undef memcpy
268#define memcpy(to, from, len) _dmalloc_memcpy(to, from, len)
269#undef memset
270#define memset(buf, ch, len) _dmalloc_memset(buf, ch, len)
271
272#undef index
273#define index(str, ch) _dmalloc_index(str, ch)
274#undef rindex
275#define rindex(str, ch) _dmalloc_rindex(str, ch)
276
277#undef strcat
278#define strcat(to, from) _dmalloc_strcat(to, from)
279#undef strcmp
280#define strcmp(s1, s2) _dmalloc_strcmp(s1, s2)
281#undef strlen
282#define strlen(str) _dmalloc_strlen(str)
283#undef strtok
284#define strtok(str, sep) _dmalloc_strtok(str, sep)
285
286#undef bzero
287#define bzero(buf, len) _dmalloc_bzero(buf, len)
288
289#undef memccpy
290#define memccpy(s1, s2, ch, len) _dmalloc_memccpy(s1, s2, ch, len)
291#undef memchr
292#define memchr(s1, ch, len) _dmalloc_memchr(s1, ch, len)
293
294#undef strchr
295#define strchr(str, ch) _dmalloc_strchr(str, ch)
296#undef strrchr
297#define strrchr(str, ch) _dmalloc_strrchr(str, ch)
298
299#undef strcpy
300#define strcpy(to, from) _dmalloc_strcpy(to, from)
301#undef strncpy
302#define strncpy(to, from, len) _dmalloc_strncpy(to, from, len)
303#undef strcasecmp
304#define strcasecmp(s1, s2) _dmalloc_strcasecmp(s1, s2)
305#undef strncasecmp
306#define strncasecmp(s1, s2, len) _dmalloc_strncasecmp(s1, s2, len)
307#undef strspn
308#define strspn(str, list) _dmalloc_strspn(str, list)
309#undef strcspn
310#define strcspn(str, list) _dmalloc_strcspn(str, list)
311#undef strncat
312#define strncat(to, from, len) _dmalloc_strncat(to, from, len)
313#undef strncmp
314#define strncmp(s1, s2, len) _dmalloc_strncmp(s1, s2, len)
315#undef strpbrk
316#define strpbrk(str, list) _dmalloc_strpbrk(str, list)
317#undef strstr
318#define strstr(str, pat) _dmalloc_strstr(str, pat)
319
320/*
321 * feel free to add your favorite functions here and to arg_check.[ch]
322 */
323
324#ifdef __cplusplus
325extern "C" {
326#endif
327
328/*
329 * copied in from arg_check.h with IMPORT -> extern, all comments removed
330 */
331extern int _dmalloc_bcmp(const void * b1, const void * b2,
332 const DMALLOC_SIZE len);
333extern void _dmalloc_bcopy(const char * from, char * to,
334 const DMALLOC_SIZE len);
335extern int _dmalloc_memcmp(const void * b1, const void * b2,
336 const DMALLOC_SIZE len);
337extern char *_dmalloc_memcpy(char * to, const char * from,
338 const DMALLOC_SIZE len);
339extern char *_dmalloc_memset(void * buf, const char ch,
340 const DMALLOC_SIZE len);
341extern char *_dmalloc_index(const char * str, const char ch);
342extern char *_dmalloc_rindex(const char * str, const char ch);
343extern char *_dmalloc_strcat(char * to, const char * from);
344extern int _dmalloc_strcmp(const char * s1, const char * s2);
345extern DMALLOC_SIZE _dmalloc_strlen(const char * str);
346extern char *_dmalloc_strtok(char * str, const char * sep);
347extern void _dmalloc_bzero(void * buf, const DMALLOC_SIZE len);
348extern char *_dmalloc_memccpy(char * s1, const char * s2, const char ch,
349 const DMALLOC_SIZE len);
350extern char *_dmalloc_memchr(const char * s1, const char ch,
351 const DMALLOC_SIZE len);
352extern char *_dmalloc_strchr(const char * str, const char ch);
353extern char *_dmalloc_strrchr(const char * str, const char ch);
354extern char *_dmalloc_strcpy(char * to, const char * from);
355extern char *_dmalloc_strncpy(char * to, const char * from,
356 const DMALLOC_SIZE len);
357extern int _dmalloc_strcasecmp(const char * s1, const char * s2);
358extern int _dmalloc_strncasecmp(const char * s1, const char * s2,
359 const DMALLOC_SIZE len);
360extern int _dmalloc_strspn(const char * str, const char * list);
361extern int _dmalloc_strcspn(const char * str, const char * list);
362extern char *_dmalloc_strncat(char * to, const char * from,
363 const DMALLOC_SIZE len);
364extern int _dmalloc_strncmp(const char * s1, const char * s2,
365 const DMALLOC_SIZE len);
366extern char *_dmalloc_strpbrk(const char * str, const char * list);
367extern char *_dmalloc_strstr(const char * str, const char * pat);
368
369#ifdef __cplusplus
370}
371#endif
372
373#endif /* DMALLOC_FUNC_CHECK */
374
375#ifdef __cplusplus
376extern "C" {
377#endif
378
379/*
380 * copied directly from malloc_lp.h with IMPORT -> extern, routines trimmed
381 */
382/* to inform the dmalloc library from which file the call comes from */
383extern char *_dmalloc_file;
384
385/* to inform the library from which line-number the call comes from */
386extern unsigned int _dmalloc_line;
387
388/*
389 * leap routine to calloc
390 */
391extern DMALLOC_PNT _calloc_leap(const char * file, const int line,
392 DMALLOC_SIZE elen, DMALLOC_SIZE size);
393
394/*
395 * leap routine to free
396 */
397extern DMALLOC_FREE_RET _free_leap(const char * file, const int line,
398 DMALLOC_PNT pnt);
399
400/*
401 * leap routine to malloc
402 */
403extern DMALLOC_PNT _malloc_leap(const char * file, const int line,
404 DMALLOC_SIZE size);
405
406/*
407 * leap routine to realloc
408 */
409extern DMALLOC_PNT _realloc_leap(const char * file, const int line,
410 DMALLOC_PNT oldp, DMALLOC_SIZE new_size);
411
412/*
413 * leap routine to calloc with error checking
414 */
415extern DMALLOC_PNT _xcalloc_leap(const char * file, const int line,
416 DMALLOC_SIZE elen, DMALLOC_SIZE size);
417
418/*
419 * leap routine to free
420 */
421extern DMALLOC_FREE_RET _xfree_leap(const char * file, const int line,
422 DMALLOC_PNT pnt);
423
424/*
425 * leap routine to malloc with error checking
426 */
427extern DMALLOC_PNT _xmalloc_leap(const char * file, const int line,
428 DMALLOC_SIZE size);
429
430/*
431 * leap routine to realloc with error checking
432 */
433extern DMALLOC_PNT _xrealloc_leap(const char * file, const int line,
434 DMALLOC_PNT oldp, DMALLOC_SIZE new_size);
435
436/*
437 * leap routine for strdup with error checking
438 */
439extern char *_xstrdup_leap(const char * file, const int line,
440 const char * str);
441
442#ifdef __cplusplus
443}
444#endif
445
446#endif /* ! DMALLOC_DISABLE */
447
448#endif /* ! __DMALLOC_H__ */
This page took 0.116002 seconds and 5 git commands to generate.