X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=include%2Fircd_alloc.h;h=237daa4681976885c37874c3a4081061ca0edc33;hb=refs%2Fheads%2Fupstream;hp=99602930a650109db88a42d060b92ef07bfb58b7;hpb=ae91ef6320f611af74e70a0db2620c338fbaa7d5;p=ircu2.10.12-pk.git diff --git a/include/ircd_alloc.h b/include/ircd_alloc.h index 9960293..237daa4 100644 --- a/include/ircd_alloc.h +++ b/include/ircd_alloc.h @@ -1,7 +1,6 @@ /* * IRC - Internet Relay Chat, include/ircd_alloc.h * Copyright (C) 1999 Thomas Helvey - * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,8 +17,10 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * Commentary by Bleep (Thomas Helvey) - * - * $Id$ + */ +/** @file + * @brief IRC daemon memory allocation functions. + * @version $Id$ */ #ifndef INCLUDED_ircd_alloc_h #define INCLUDED_ircd_alloc_h @@ -27,38 +28,54 @@ /* * memory resource allocation and test functions */ +/** Type of handler for out-of-memory conditions. */ typedef void (*OutOfMemoryHandler)(void); extern void set_nomem_handler(OutOfMemoryHandler handler); -#if defined(NDEBUG) -/* - * RELEASE: allocation functions - */ -#ifndef INCLUDED_stdlib_h -#include /* free */ -#define INCLUDED_stdlib_h -#endif +/* The mappings for the My* functions... */ +/** Helper macro for standard allocations. */ +#define MyMalloc(size) \ + DoMalloc(size, "malloc", __FILE__, __LINE__) -#define MyFree(x) do { free((x)); (x) = 0; } while(0) +/** Helper macro for zero-initialized allocations. */ +#define MyCalloc(nelem, size) \ + DoMallocZero((size) * (nelem), "calloc", __FILE__, __LINE__) -extern void* MyMalloc(size_t size); -extern void* MyCalloc(size_t nelem, size_t size); -extern void* MyRealloc(void* p, size_t size); +/** Helper macro for freeing memory. */ +#define MyFree(p) \ + if (p) \ + DoFree(p, __FILE__, __LINE__) -#else /* !defined(NDEBUG) */ -/* - * DEBUG: allocation functions - */ -#ifndef INCLUDED_fda_h -#include "fda.h" +/** Helper macro for reallocating memory. */ +#define MyRealloc(p, size) \ + DoRealloc(p, size, __FILE__, __LINE__) + +/* First version: fast non-debugging macros... */ +#ifndef MDEBUG +#ifndef INCLUDED_stdlib_h +#include /* free */ +#define INCLUDED_stdlib_h #endif -#define MyMalloc(s) fda_malloc((s), __FILE__, __LINE__) -#define MyCalloc(n, s) fda_calloc((n), (s), __FILE__, __LINE__) -#define MyFree(p) fda_free((p)) -#define MyRealloc(p, s) fda_realloc((p), (s), __FILE__, __LINE__) +/** Implementation macro for freeing memory. */ +#define DoFree(x, file, line) do { free((x)); (x) = 0; } while(0) +extern void* DoMalloc(size_t len, const char*, const char*, int); +extern void* DoMallocZero(size_t len, const char*, const char*, int); +extern void *DoRealloc(void *, size_t, const char*, int); -#endif /* !defined(NDEBUG) */ +/* Second version: slower debugging versions... */ +#else /* defined(MDEBUG) */ +#include +#include "memdebug.h" -#endif /* INCLUDED_ircd_alloc_h */ +#define DoMalloc(size, type, file, line) \ + dbg_malloc(size, type, file, line) +#define DoMallocZero(size, type, file, line) \ + dbg_malloc_zero(size, type, file, line) +#define DoFree(p, file, line) \ + do { dbg_free(p, file, line); (p) = 0; } while (0) +#define DoRealloc(p, size, file, line) \ + dbg_realloc(p, size, file, line) +#endif /* defined(MDEBUG) */ +#endif /* INCLUDED_ircd_alloc_h */