The 0.5 release happened on 2/15, not on 2/14. :-)
[python/dscho.git] / Include / mymalloc.h
blob558af9d29b17cedff582b135c994c39027059446
1 #ifndef Py_MYMALLOC_H
2 #define Py_MYMALLOC_H
3 /***********************************************************
4 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
5 The Netherlands.
7 All Rights Reserved
9 Permission to use, copy, modify, and distribute this software and its
10 documentation for any purpose and without fee is hereby granted,
11 provided that the above copyright notice appear in all copies and that
12 both that copyright notice and this permission notice appear in
13 supporting documentation, and that the names of Stichting Mathematisch
14 Centrum or CWI or Corporation for National Research Initiatives or
15 CNRI not be used in advertising or publicity pertaining to
16 distribution of the software without specific, written prior
17 permission.
19 While CWI is the initial source for this software, a modified version
20 is made available by the Corporation for National Research Initiatives
21 (CNRI) at the Internet address ftp://ftp.python.org.
23 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
24 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
25 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
26 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
27 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
28 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
29 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
30 PERFORMANCE OF THIS SOFTWARE.
32 ******************************************************************/
34 /* Lowest-level memory allocation interface */
36 #ifdef macintosh
37 #define ANY void
38 #endif
40 #ifdef __STDC__
41 #define ANY void
42 #endif
44 #ifdef __TURBOC__
45 #define ANY void
46 #endif
48 #ifdef __GNUC__
49 #define ANY void
50 #endif
52 #ifndef ANY
53 #define ANY char
54 #endif
56 #ifdef HAVE_STDLIB_H
57 #include <stdlib.h>
58 #endif
60 #ifdef __cplusplus
61 /* Move this down here since some C++ #include's don't like to be included
62 inside an extern "C" */
63 extern "C" {
64 #endif
66 #ifdef SYMANTEC__CFM68K__
67 #pragma lib_export on
68 #endif
70 /* The following should never be necessary */
71 #ifdef NEED_TO_DECLARE_MALLOC_AND_FRIEND
72 extern ANY *malloc Py_PROTO((size_t));
73 extern ANY *calloc Py_PROTO((size_t, size_t));
74 extern ANY *realloc Py_PROTO((ANY *, size_t));
75 extern void free Py_PROTO((ANY *)); /* XXX sometimes int on Unix old systems */
76 #endif
78 #ifndef NULL
79 #define NULL ((ANY *)0)
80 #endif
82 #ifdef MALLOC_ZERO_RETURNS_NULL
83 /* XXX Always allocate one extra byte, since some malloc's return NULL
84 XXX for malloc(0) or realloc(p, 0). */
85 #define _PyMem_EXTRA 1
86 #else
87 #define _PyMem_EXTRA 0
88 #endif
90 #define PyMem_NEW(type, n) \
91 ( (type *) malloc(_PyMem_EXTRA + (n) * sizeof(type)) )
92 #define PyMem_RESIZE(p, type, n) \
93 if ((p) == NULL) \
94 (p) = (type *) malloc(_PyMem_EXTRA + (n) * sizeof(type)); \
95 else \
96 (p) = (type *) realloc((ANY *)(p), \
97 _PyMem_EXTRA + (n) * sizeof(type))
98 #define PyMem_DEL(p) free((ANY *)p)
99 #define PyMem_XDEL(p) if ((p) == NULL) ; else PyMem_DEL(p)
102 /* Two sets of function wrappers around malloc and friends; useful if
103 you need to be sure that you are using the same memory allocator as
104 Python. Note that the wrappers make sure that allocating 0 bytes
105 returns a non-NULL pointer, even if the underlying malloc doesn't.
106 The Python interpreter continues to use PyMem_NEW etc. */
108 /* These wrappers around malloc call PyErr_NoMemory() on failure */
109 extern DL_IMPORT(ANY *) Py_Malloc Py_PROTO((size_t));
110 extern DL_IMPORT(ANY *) Py_Realloc Py_PROTO((ANY *, size_t));
111 extern DL_IMPORT(void) Py_Free Py_PROTO((ANY *));
113 /* These wrappers around malloc *don't* call anything on failure */
114 extern DL_IMPORT(ANY *) PyMem_Malloc Py_PROTO((size_t));
115 extern DL_IMPORT(ANY *) PyMem_Realloc Py_PROTO((ANY *, size_t));
116 extern DL_IMPORT(void) PyMem_Free Py_PROTO((ANY *));
118 #ifdef __cplusplus
120 #endif
122 #endif /* !Py_MYMALLOC_H */