X-Git-Url: http://sjero.net/git/?a=blobdiff_plain;f=src%2Fxmalloc.h;h=ebcf4c8e82bd3dc2c6040088df76df193e01f6c1;hb=4d7c5e087b2bc82c9f503dff003916d1047903ce;hp=7729e5ababb545e09d447e8584b0a0eda262bdb2;hpb=095d89995e49ef96ac0d82793702acce95b71459;p=wget diff --git a/src/xmalloc.h b/src/xmalloc.h index 7729e5ab..ebcf4c8e 100644 --- a/src/xmalloc.h +++ b/src/xmalloc.h @@ -1,12 +1,12 @@ /* xmalloc.c declarations. - Copyright (C) 2003 Free Software Foundation, Inc. + Copyright (C) 2003-2006 Free Software Foundation, Inc. This file is part of GNU Wget. GNU Wget is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. +the Free Software Foundation; either version 3 of the License, or +(at your option) any later version. GNU Wget is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -14,8 +14,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with Wget; if not, write to the Free Software -Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +along with Wget. If not, see . In addition, as a special exception, the Free Software Foundation gives permission to link the code of its release of Wget with the @@ -30,46 +29,51 @@ so, delete this exception statement from your version. */ #ifndef XMALLOC_H #define XMALLOC_H -/* Define this if you want primitive but extensive malloc debugging. - It will make Wget extremely slow, so only do it in development - builds. */ -#define DEBUG_MALLOC +/* Define this to use Wget's builtin malloc debugging, which is crude + but occasionally useful. It will make Wget a lot slower and + larger, and susceptible to aborting if malloc_table overflows, so + it should be used by developers only. */ +#undef DEBUG_MALLOC /* When DEBUG_MALLOC is not defined (which is normally the case), the - allocation functions directly map to *_real wrappers. In the - DEBUG_MALLOC mode, they also record the file and line where the - offending malloc/free/... was invoked. + allocator identifiers are mapped to checking_* wrappers, which exit + Wget if malloc/realloc/strdup return NULL - *Note*: xfree(NULL) aborts. If the pointer you're freeing can be - NULL, use xfree_null instead. */ + In DEBUG_MALLOC mode, the allocators are mapped to debugging_* + wrappers, which also record the file and line from which the + allocation was attempted. At the end of the program, a detailed + summary of unfreed allocations is displayed. + + *Note*: xfree(NULL) aborts in both modes. If the pointer you're + freeing can be NULL, use xfree_null instead. */ #ifndef DEBUG_MALLOC -#define xmalloc xmalloc_real -#define xmalloc0 xmalloc0_real -#define xrealloc xrealloc_real -#define xstrdup xstrdup_real -#define xfree xfree_real +#define xmalloc checking_malloc +#define xmalloc0 checking_malloc0 +#define xrealloc checking_realloc +#define xstrdup checking_strdup +#define xfree checking_free -void *xmalloc_real PARAMS ((size_t)); -void *xmalloc0_real PARAMS ((size_t)); -void *xrealloc_real PARAMS ((void *, size_t)); -char *xstrdup_real PARAMS ((const char *)); -void xfree_real PARAMS ((void *)); +void *checking_malloc (size_t); +void *checking_malloc0 (size_t); +void *checking_realloc (void *, size_t); +char *checking_strdup (const char *); +void checking_free (void *); #else /* DEBUG_MALLOC */ -#define xmalloc(s) xmalloc_debug (s, __FILE__, __LINE__) -#define xmalloc0(s) xmalloc0_debug (s, __FILE__, __LINE__) -#define xrealloc(p, s) xrealloc_debug (p, s, __FILE__, __LINE__) -#define xstrdup(p) xstrdup_debug (p, __FILE__, __LINE__) -#define xfree(p) xfree_debug (p, __FILE__, __LINE__) +#define xmalloc(s) debugging_malloc (s, __FILE__, __LINE__) +#define xmalloc0(s) debugging_malloc0 (s, __FILE__, __LINE__) +#define xrealloc(p, s) debugging_realloc (p, s, __FILE__, __LINE__) +#define xstrdup(p) debugging_strdup (p, __FILE__, __LINE__) +#define xfree(p) debugging_free (p, __FILE__, __LINE__) -void *xmalloc_debug PARAMS ((size_t, const char *, int)); -void *xmalloc0_debug PARAMS ((size_t, const char *, int)); -void *xrealloc_debug PARAMS ((void *, size_t, const char *, int)); -char *xstrdup_debug PARAMS ((const char *, const char *, int)); -void xfree_debug PARAMS ((void *, const char *, int)); +void *debugging_malloc (size_t, const char *, int); +void *debugging_malloc0 (size_t, const char *, int); +void *debugging_realloc (void *, size_t, const char *, int); +char *debugging_strdup (const char *, const char *, int); +void debugging_free (void *, const char *, int); #endif /* DEBUG_MALLOC */ @@ -78,10 +82,10 @@ void xfree_debug PARAMS ((void *, const char *, int)); necessary in standard C, but Wget performs them anyway for the sake of pre-standard environments and possibly C++. */ -#define xnew(type) ((type *) xmalloc (sizeof (type))) -#define xnew0(type) ((type *) xmalloc0 (sizeof (type))) -#define xnew_array(type, len) ((type *) xmalloc ((len) * sizeof (type))) -#define xnew0_array(type, len) ((type *) xmalloc0 ((len) * sizeof (type))) +#define xnew(type) (xmalloc (sizeof (type))) +#define xnew0(type) (xmalloc0 (sizeof (type))) +#define xnew_array(type, len) (xmalloc ((len) * sizeof (type))) +#define xnew0_array(type, len) (xmalloc0 ((len) * sizeof (type))) #define alloca_array(type, size) ((type *) alloca ((size) * sizeof (type)))