3 /***********************************************************
4 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
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
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 */
61 /* Move this down here since some C++ #include's don't like to be included
62 inside an extern "C" */
66 #ifdef SYMANTEC__CFM68K__
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 */
79 #define NULL ((ANY *)0)
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
87 #define _PyMem_EXTRA 0
90 #define PyMem_NEW(type, n) \
91 ( (type *) malloc(_PyMem_EXTRA + (n) * sizeof(type)) )
92 #define PyMem_RESIZE(p, type, n) \
94 (p) = (type *) malloc(_PyMem_EXTRA + (n) * sizeof(type)); \
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
*));
122 #endif /* !Py_MYMALLOC_H */