X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=ircd%2Fircd_alloc.c;h=1fc87fa8769219b84d942d9b389a5cc6dbd7f6eb;hb=a36ad5e29241b0c89379947b13887cb6930ef3e0;hp=d3630123ffa095d6978ca01b07bb7f3517b8f6ca;hpb=cc05a230ac079fa15a2e43e6e68ef7126128cefd;p=ircu2.10.12-pk.git diff --git a/ircd/ircd_alloc.c b/ircd/ircd_alloc.c index d363012..1fc87fa 100644 --- a/ircd/ircd_alloc.c +++ b/ircd/ircd_alloc.c @@ -1,9 +1,9 @@ /************************************************************************ * IRC - Internet Relay Chat, ircd/ircd_alloc.c * Copyright (C) 1999 Thomas Helvey (BleepSoft) - * + * * See file AUTHORS in IRC package for additional names of - * the programmers. + * the programmers. * * 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,68 +18,88 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * $Id$ + */ +/** @file + * @brief IRC daemon memory allocation functions. + * @version $Id$ */ #include "config.h" #include "ircd_alloc.h" +#include "ircd_log.h" #include "ircd_string.h" #include "s_debug.h" -#include +/* #include -- Now using assert in ircd_log.h */ +#include -#if !defined(MDEBUG) -/* - * RELEASE: allocation functions - */ +static void nomem_handler(void); -static void nomem_handler(void) +/** Variable holding out-of-memory callback. */ +static OutOfMemoryHandler noMemHandler = nomem_handler; + +/** Default handler for out-of-memory conditions. */ +static void +nomem_handler(void) { +#ifdef MDEBUG + assert(0); +#else Debug((DEBUG_FATAL, "Out of memory, exiting")); exit(2); +#endif } -static OutOfMemoryHandler noMemHandler = nomem_handler; - -void set_nomem_handler(OutOfMemoryHandler handler) +/** Set callback function for out-of-memory conditions. */ +void +set_nomem_handler(OutOfMemoryHandler handler) { noMemHandler = handler; } -void* MyMalloc(size_t size) -{ - void* p = malloc(size); - if (!p) - (*noMemHandler)(); - return p; -} - -void* MyRealloc(void* p, size_t size) +#ifndef MDEBUG +/** Allocate memory. + * @param[in] size Number of bytes to allocate. + * @param[in] x Type of allocation (ignored). + * @param[in] y Name of file doing allocation (ignored). + * @param[in] z Line number doing allocation (ignored). + * @return Newly allocated block of memory. + */ +void* DoMalloc(size_t size, const char* x, const char* y, int z) { - void* x = realloc(p, size); - if (!x) + void* t = malloc(size); + if (!t) (*noMemHandler)(); - return x; + return t; } -void* MyCalloc(size_t nelem, size_t size) +/** Allocate zero-initialized memory. + * @param[in] size Number of bytes to allocate. + * @param[in] x Type of allocation (ignored). + * @param[in] y Name of file doing allocation (ignored). + * @param[in] z Line number doing allocation (ignored). + * @return Newly allocated block of memory. + */ +void* DoMallocZero(size_t size, const char* x, const char* y, int z) { - void* p = calloc(nelem, size); - if (!p) + void* t = malloc(size); + if (!t) (*noMemHandler)(); - return p; + memset(t, 0, size); + return t; } -#else /* defined(MDEBUG) */ -/* - * DEBUG: allocation functions +/** Resize an allocated block of memory. + * @param[in] orig Original block to resize. + * @param[in] size Minimum size for new block. + * @param[in] file Name of file doing reallocation (ignored). + * @param[in] line Line number doing reallocation (ignored). */ -void set_nomem_handler(OutOfMemoryHandler handler) +void* DoRealloc(void *orig, size_t size, const char *file, int line) { - assert(0 != handler); - fda_set_nomem_handler(handler); + void* t = realloc(orig, size); + if (!t) + (*noMemHandler)(); + return t; } - -#endif /* defined(MDEBUG) */ - +#endif