Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 1 | #ifndef Py_MYMALLOC_H |
| 2 | #define Py_MYMALLOC_H |
Guido van Rossum | 1e28e5e | 1992-08-19 16:46:30 +0000 | [diff] [blame] | 3 | /*********************************************************** |
Guido van Rossum | 5799b52 | 1995-01-04 19:06:22 +0000 | [diff] [blame] | 4 | Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
| 5 | The Netherlands. |
Guido van Rossum | 1e28e5e | 1992-08-19 16:46:30 +0000 | [diff] [blame] | 6 | |
| 7 | All Rights Reserved |
| 8 | |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 9 | Permission to use, copy, modify, and distribute this software and its |
| 10 | documentation for any purpose and without fee is hereby granted, |
Guido van Rossum | 1e28e5e | 1992-08-19 16:46:30 +0000 | [diff] [blame] | 11 | provided that the above copyright notice appear in all copies and that |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 12 | both that copyright notice and this permission notice appear in |
Guido van Rossum | 1e28e5e | 1992-08-19 16:46:30 +0000 | [diff] [blame] | 13 | supporting documentation, and that the names of Stichting Mathematisch |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 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. |
Guido van Rossum | 1e28e5e | 1992-08-19 16:46:30 +0000 | [diff] [blame] | 18 | |
Guido van Rossum | d266eb4 | 1996-10-25 14:44:06 +0000 | [diff] [blame] | 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. |
| 22 | |
| 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. |
Guido van Rossum | 1e28e5e | 1992-08-19 16:46:30 +0000 | [diff] [blame] | 31 | |
| 32 | ******************************************************************/ |
| 33 | |
| 34 | /* Lowest-level memory allocation interface */ |
| 35 | |
| 36 | #ifdef macintosh |
| 37 | #define ANY void |
Guido van Rossum | 1e28e5e | 1992-08-19 16:46:30 +0000 | [diff] [blame] | 38 | #endif |
| 39 | |
| 40 | #ifdef __STDC__ |
| 41 | #define ANY void |
Guido van Rossum | 1e28e5e | 1992-08-19 16:46:30 +0000 | [diff] [blame] | 42 | #endif |
| 43 | |
Guido van Rossum | 12d12c5 | 1993-10-26 17:58:25 +0000 | [diff] [blame] | 44 | #ifdef __TURBOC__ |
| 45 | #define ANY void |
Guido van Rossum | 12d12c5 | 1993-10-26 17:58:25 +0000 | [diff] [blame] | 46 | #endif |
| 47 | |
| 48 | #ifdef __GNUC__ |
| 49 | #define ANY void |
Guido van Rossum | 12d12c5 | 1993-10-26 17:58:25 +0000 | [diff] [blame] | 50 | #endif |
| 51 | |
Guido van Rossum | 1e28e5e | 1992-08-19 16:46:30 +0000 | [diff] [blame] | 52 | #ifndef ANY |
| 53 | #define ANY char |
| 54 | #endif |
| 55 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 56 | #ifdef HAVE_STDLIB_H |
| 57 | #include <stdlib.h> |
Guido van Rossum | 6c1874f | 1995-01-10 17:43:33 +0000 | [diff] [blame] | 58 | #endif |
| 59 | |
| 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 |
| 65 | |
Jack Jansen | f9480ce | 1995-06-27 13:12:09 +0000 | [diff] [blame] | 66 | #ifdef SYMANTEC__CFM68K__ |
Guido van Rossum | 0acd4b6 | 1995-02-18 14:50:12 +0000 | [diff] [blame] | 67 | #pragma lib_export on |
| 68 | #endif |
| 69 | |
Guido van Rossum | 6c1874f | 1995-01-10 17:43:33 +0000 | [diff] [blame] | 70 | #ifndef HAVE_STDLIB_H |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 71 | extern ANY *malloc Py_PROTO((size_t)); |
| 72 | extern ANY *calloc Py_PROTO((size_t, size_t)); |
| 73 | extern ANY *realloc Py_PROTO((ANY *, size_t)); |
| 74 | extern void free Py_PROTO((ANY *)); /* XXX sometimes int on Unix old systems */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 75 | #endif /* !HAVE_STDLIB */ |
| 76 | |
Guido van Rossum | 1e28e5e | 1992-08-19 16:46:30 +0000 | [diff] [blame] | 77 | #ifndef NULL |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 78 | #define NULL ((ANY *)0) |
Guido van Rossum | 1e28e5e | 1992-08-19 16:46:30 +0000 | [diff] [blame] | 79 | #endif |
| 80 | |
Guido van Rossum | 5f59d60 | 1992-12-14 16:59:51 +0000 | [diff] [blame] | 81 | /* XXX Always allocate one extra byte, since some malloc's return NULL |
| 82 | XXX for malloc(0) or realloc(p, 0). */ |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 83 | #define PyMem_NEW(type, n) ( (type *) malloc(1 + (n) * sizeof(type)) ) |
| 84 | #define PyMem_RESIZE(p, type, n) \ |
Guido van Rossum | 1e28e5e | 1992-08-19 16:46:30 +0000 | [diff] [blame] | 85 | if ((p) == NULL) \ |
Guido van Rossum | 5f59d60 | 1992-12-14 16:59:51 +0000 | [diff] [blame] | 86 | (p) = (type *) malloc(1 + (n) * sizeof(type)); \ |
Guido van Rossum | 1e28e5e | 1992-08-19 16:46:30 +0000 | [diff] [blame] | 87 | else \ |
Guido van Rossum | 5f59d60 | 1992-12-14 16:59:51 +0000 | [diff] [blame] | 88 | (p) = (type *) realloc((ANY *)(p), 1 + (n) * sizeof(type)) |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 89 | #define PyMem_DEL(p) free((ANY *)p) |
| 90 | #define PyMem_XDEL(p) if ((p) == NULL) ; else PyMem_DEL(p) |
Guido van Rossum | 1e28e5e | 1992-08-19 16:46:30 +0000 | [diff] [blame] | 91 | |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 92 | #ifdef __cplusplus |
| 93 | } |
| 94 | #endif |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 95 | |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 96 | #endif /* !Py_MYMALLOC_H */ |