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