1 |
/* Memory management include file. |
2 |
* |
3 |
* IRC Services is copyright (c) 1996-2009 Andrew Church. |
4 |
* E-mail: <achurch@achurch.org> |
5 |
* Parts written by Andrew Kempe and others. |
6 |
* This program is free but copyrighted software; see the file GPL.txt for |
7 |
* details. |
8 |
*/ |
9 |
|
10 |
#ifndef MEMORY_H |
11 |
#define MEMORY_H |
12 |
|
13 |
/*************************************************************************/ |
14 |
|
15 |
#if MEMCHECKS |
16 |
# define FILELINE , const char *file, int line |
17 |
#else |
18 |
# define FILELINE /*nothing*/ |
19 |
#endif |
20 |
extern void *smalloc(long size FILELINE); |
21 |
extern void *scalloc(long els, long elsize FILELINE); |
22 |
extern void *srealloc(void *oldptr, long newsize FILELINE); |
23 |
extern char *sstrdup(const char *s FILELINE); |
24 |
#undef FILELINE |
25 |
|
26 |
#if MEMCHECKS |
27 |
|
28 |
# if SHOWALLOCS |
29 |
extern int showallocs; |
30 |
# endif |
31 |
extern void init_memory(void); |
32 |
extern void uninit_memory(void); |
33 |
extern void *MCmalloc(long size, const char *file, int line); |
34 |
extern void *MCcalloc(long elsize, long els, const char *file, int line); |
35 |
extern void *MCrealloc(void *oldptr, long newsize, const char *file, int line); |
36 |
extern void MCfree(void *ptr, const char *file, int line); |
37 |
extern char *MCstrdup(const char *s, const char *file, int line); |
38 |
|
39 |
#else /* !MEMCHECKS */ |
40 |
|
41 |
# define init_memory() /*nothing*/ |
42 |
# define uninit_memory() /*nothing*/ |
43 |
|
44 |
#endif |
45 |
|
46 |
/*************************************************************************/ |
47 |
|
48 |
#if MEMCHECKS && !defined(NO_MEMREDEF) |
49 |
|
50 |
# undef malloc |
51 |
# undef calloc |
52 |
# undef realloc |
53 |
# undef free |
54 |
# undef strdup |
55 |
|
56 |
# define malloc(size) MCmalloc(size,__FILE__,__LINE__) |
57 |
# define calloc(elsize,els) MCcalloc(elsize,els,__FILE__,__LINE__) |
58 |
# define realloc(ptr,size) MCrealloc(ptr,size,__FILE__,__LINE__) |
59 |
# define free(ptr) MCfree(ptr,__FILE__,__LINE__) |
60 |
# define strdup(str) MCstrdup(str,__FILE__,__LINE__) |
61 |
|
62 |
# define smalloc(size) smalloc(size,__FILE__,__LINE__) |
63 |
# define scalloc(elsize,els) scalloc(elsize,els,__FILE__,__LINE__) |
64 |
# define srealloc(ptr,size) srealloc(ptr,size,__FILE__,__LINE__) |
65 |
# define sstrdup(str) sstrdup(str,__FILE__,__LINE__) |
66 |
|
67 |
#endif /* MEMCHECKS && !NO_MEMREDEF */ |
68 |
|
69 |
/*************************************************************************/ |
70 |
|
71 |
#endif /* MEMORY_H */ |
72 |
|
73 |
/* |
74 |
* Local variables: |
75 |
* c-file-style: "stroustrup" |
76 |
* c-file-offsets: ((case-label . *) (statement-case-intro . *)) |
77 |
* indent-tabs-mode: nil |
78 |
* End: |
79 |
* |
80 |
* vim: expandtab shiftwidth=4: |
81 |
*/ |