source: vendor/wget/current/src/xmalloc.h

Last change on this file was 3440, checked in by bird, 18 years ago

wget 1.10.2

File size: 4.2 KB
Line 
1/* xmalloc.c declarations.
2 Copyright (C) 2003 Free Software Foundation, Inc.
3
4This file is part of GNU Wget.
5
6GNU Wget is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11GNU Wget is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with Wget; if not, write to the Free Software
18Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
20In addition, as a special exception, the Free Software Foundation
21gives permission to link the code of its release of Wget with the
22OpenSSL project's "OpenSSL" library (or with modified versions of it
23that use the same license as the "OpenSSL" library), and distribute
24the linked executables. You must obey the GNU General Public License
25in all respects for all of the code used other than "OpenSSL". If you
26modify this file, you may extend this exception to your version of the
27file, but you are not obligated to do so. If you do not wish to do
28so, delete this exception statement from your version. */
29
30#ifndef XMALLOC_H
31#define XMALLOC_H
32
33/* Define this to use Wget's builtin malloc debugging, which is crude
34 but occasionally useful. It will make Wget a lot slower and
35 larger, and susceptible to aborting if malloc_table overflows, so
36 it should be used by developers only. */
37#undef DEBUG_MALLOC
38
39/* When DEBUG_MALLOC is not defined (which is normally the case), the
40 allocator identifiers are mapped to checking_* wrappers, which exit
41 Wget if malloc/realloc/strdup return NULL
42
43 In DEBUG_MALLOC mode, the allocators are mapped to debugging_*
44 wrappers, which also record the file and line from which the
45 allocation was attempted. At the end of the program, a detailed
46 summary of unfreed allocations is displayed.
47
48 *Note*: xfree(NULL) aborts in both modes. If the pointer you're
49 freeing can be NULL, use xfree_null instead. */
50
51#ifndef DEBUG_MALLOC
52
53#define xmalloc checking_malloc
54#define xmalloc0 checking_malloc0
55#define xrealloc checking_realloc
56#define xstrdup checking_strdup
57#define xfree checking_free
58
59void *checking_malloc PARAMS ((size_t));
60void *checking_malloc0 PARAMS ((size_t));
61void *checking_realloc PARAMS ((void *, size_t));
62char *checking_strdup PARAMS ((const char *));
63void checking_free PARAMS ((void *));
64
65#else /* DEBUG_MALLOC */
66
67#define xmalloc(s) debugging_malloc (s, __FILE__, __LINE__)
68#define xmalloc0(s) debugging_malloc0 (s, __FILE__, __LINE__)
69#define xrealloc(p, s) debugging_realloc (p, s, __FILE__, __LINE__)
70#define xstrdup(p) debugging_strdup (p, __FILE__, __LINE__)
71#define xfree(p) debugging_free (p, __FILE__, __LINE__)
72
73void *debugging_malloc PARAMS ((size_t, const char *, int));
74void *debugging_malloc0 PARAMS ((size_t, const char *, int));
75void *debugging_realloc PARAMS ((void *, size_t, const char *, int));
76char *debugging_strdup PARAMS ((const char *, const char *, int));
77void debugging_free PARAMS ((void *, const char *, int));
78
79#endif /* DEBUG_MALLOC */
80
81/* Macros that interface to malloc, but know about type sizes, and
82 cast the result to the appropriate type. The casts are not
83 necessary in standard C, but Wget performs them anyway for the sake
84 of pre-standard environments and possibly C++. */
85
86#define xnew(type) ((type *) xmalloc (sizeof (type)))
87#define xnew0(type) ((type *) xmalloc0 (sizeof (type)))
88#define xnew_array(type, len) ((type *) xmalloc ((len) * sizeof (type)))
89#define xnew0_array(type, len) ((type *) xmalloc0 ((len) * sizeof (type)))
90
91#define alloca_array(type, size) ((type *) alloca ((size) * sizeof (type)))
92
93/* Free P if it is non-NULL. C requires free() to behaves this way by
94 default, but Wget's code is historically careful not to pass NULL
95 to free. This allows us to assert p!=NULL in xfree to check
96 additional errors. (But we currently don't do that!) */
97#define xfree_null(p) if (!(p)) ; else xfree (p)
98
99#endif /* XMALLOC_H */
Note: See TracBrowser for help on using the repository browser.