2 * IRC - Internet Relay Chat, include/ircd_alloc.h
3 * Copyright (C) 1999 Thomas Helvey <tomh@inxpress.net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 * Commentary by Bleep (Thomas Helvey)
24 #ifndef INCLUDED_ircd_alloc_h
25 #define INCLUDED_ircd_alloc_h
28 * memory resource allocation and test functions
30 typedef void (*OutOfMemoryHandler)(void);
31 extern void set_nomem_handler(OutOfMemoryHandler handler);
33 /* The mappings for the My* functions... */
34 #define MyMalloc(size) \
35 DoMalloc(size, "malloc", __FILE__, __LINE__)
37 #define MyCalloc(nelem, size) \
38 DoMallocZero(size * nelem, "calloc", __FILE__, __LINE__)
42 DoFree(p, __FILE__, __LINE__)
44 #define MyRealloc(p, size) \
45 DoRealloc(p, size, __FILE__, __LINE__)
47 /* First version: fast non-debugging macros... */
49 #ifndef INCLUDED_stdlib_h
50 #include <stdlib.h> /* free */
51 #define INCLUDED_stdlib_h
54 extern OutOfMemoryHandler noMemHandler;
56 #define DoFree(x, file, line) do { free((x)); (x) = 0; } while(0)
57 extern void* DoMalloc(size_t len, const char*, const char*, int);
58 extern void* DoMallocZero(size_t len, const char*, const char*, int);
59 extern void *DoRealloc(void *, size_t, const char*, int);
61 /* Second version: slower debugging versions... */
62 #else /* defined(MDEBUG) */
63 #include <sys/types.h>
66 #define DoMalloc(size, type, file, line) \
67 dbg_malloc(size, type, file, line)
68 #define DoMallocZero(size, type, file, line) \
69 dbg_malloc_zero(size, type, file, line)
70 #define DoFree(p, file, line) \
71 dbg_free(p, file, line)
72 #define DoRealloc(p, size, file, line) \
73 dbg_realloc(p, size, file, line)
74 #endif /* defined(MDEBUG) */
76 #endif /* INCLUDED_ircd_alloc_h */