Author: Bleep <tomh@inxpress.net>
[ircu2.10.12-pk.git] / include / runmalloc.h
1 /*
2  * runmalloc.h
3  *
4  * (C) Copyright 1996 - 1997, Carlo Wood (carlo@runaway.xs4all.nl)
5  *
6  * Headerfile of runmalloc.c
7  *
8  * $Id$
9  */
10 #ifndef INCLUDED_runmalloc_h
11 #define INCLUDED_runmalloc_h
12 #ifndef INCLUDED_config_h
13 #include "config.h"
14 #endif
15 #ifndef INCLUDED_sys_types_h
16 #include <sys/types.h>         /* size_t */
17 #define INCLUDED_sys_types_h
18 #endif
19
20 typedef void (*OutOfMemoryHandler)(void);
21
22 extern void set_nomem_handler(OutOfMemoryHandler handler);
23
24 #if 0
25 /* 
26  * we want to be able to test in DEBUGMODE without turning
27  * DEBUGMALLOC on, change in the config not in the code
28  */
29 #if defined(DEBUGMODE) && !defined(DEBUGMALLOC)
30 #define DEBUGMALLOC
31 #endif
32 #endif
33
34 #ifdef DEBUGMALLOC
35
36 #if defined(MEMMAGICNUMS) && !defined(MEMSIZESTATS)
37 #define MEMSIZESTATS
38 #endif
39
40 #ifndef MEMLEAKSTATS
41 #undef MEMTIMESTATS
42 #endif
43
44 /*
45  * Proto types
46  */
47
48 #ifdef MEMLEAKSTATS
49 extern void *RunMalloc_memleak(size_t size, int line, const char *filename);
50 extern void *RunCalloc_memleak(size_t nmemb, size_t size,
51     int line, const char *filename);
52 extern void *RunRealloc_memleak(void *ptr, size_t size,
53     int line, const char *filename);
54 struct Client;
55 extern void report_memleak_stats(struct Client *sptr, int parc, char *parv[]);
56 #define MyMalloc(x) RunMalloc_memleak(x, __LINE__, __FILE__)
57 #define MyCalloc(x,y) RunCalloc_memleak(x,y, __LINE__, __FILE__)
58 #define MyRealloc(x,y) RunRealloc_memleak(x,y, __LINE__, __FILE__)
59
60 #else /* !MEMLEAKSTATS */
61 extern void *MyMalloc(size_t size);
62 extern void *MyCalloc(size_t nmemb, size_t size);
63 extern void *MyRealloc(void *ptr, size_t size);
64 #endif /* MEMLEAKSTATS */
65
66 extern int MyFree_test(void *ptr);
67 extern void MyFree(void *ptr);
68
69 #ifdef MEMSIZESTATS
70 extern unsigned int get_alloc_cnt(void);
71 extern size_t get_mem_size(void);
72 #endif
73
74 #else /* !DEBUGMALLOC */
75
76 #ifndef INCLUDED_stdlib_h
77 #include <stdlib.h>
78 #define INCLUDED_stdlib_h
79 #endif
80
81 #undef MEMSIZESTATS
82 #undef MEMMAGICNUMS
83 #undef MEMLEAKSTATS
84 #undef MEMTIMESTATS
85
86 #define MyFree(x) do { free((x)); (x) = 0; } while(0)
87 #define Debug_malloc(x)
88 extern void* MyMalloc(size_t size);
89 extern void* MyCalloc(size_t nelem, size_t size);
90 extern void* MyRealloc(void* x, size_t size);
91
92 #endif /* DEBUGMALLOC */
93
94 #endif /* INCLUDED_runmalloc_h */