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 | |
| 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 not be used in advertising or publicity pertaining to |
| 15 | distribution of the software without specific, written prior permission. |
| 16 | |
| 17 | STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO |
| 18 | THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 19 | FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE |
| 20 | FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 21 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 22 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
| 23 | OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 24 | |
| 25 | ******************************************************************/ |
| 26 | |
| 27 | /* Lowest-level memory allocation interface */ |
| 28 | |
| 29 | #ifdef macintosh |
| 30 | #define ANY void |
Guido van Rossum | 1e28e5e | 1992-08-19 16:46:30 +0000 | [diff] [blame] | 31 | #endif |
| 32 | |
| 33 | #ifdef __STDC__ |
| 34 | #define ANY void |
Guido van Rossum | 1e28e5e | 1992-08-19 16:46:30 +0000 | [diff] [blame] | 35 | #endif |
| 36 | |
Guido van Rossum | 12d12c5 | 1993-10-26 17:58:25 +0000 | [diff] [blame] | 37 | #ifdef __TURBOC__ |
| 38 | #define ANY void |
Guido van Rossum | 12d12c5 | 1993-10-26 17:58:25 +0000 | [diff] [blame] | 39 | #endif |
| 40 | |
| 41 | #ifdef __GNUC__ |
| 42 | #define ANY void |
Guido van Rossum | 12d12c5 | 1993-10-26 17:58:25 +0000 | [diff] [blame] | 43 | #endif |
| 44 | |
Guido van Rossum | 1e28e5e | 1992-08-19 16:46:30 +0000 | [diff] [blame] | 45 | #ifndef ANY |
| 46 | #define ANY char |
| 47 | #endif |
| 48 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 49 | #ifdef HAVE_STDLIB_H |
| 50 | #include <stdlib.h> |
Guido van Rossum | 6c1874f | 1995-01-10 17:43:33 +0000 | [diff] [blame] | 51 | #endif |
| 52 | |
| 53 | #ifdef __cplusplus |
| 54 | // Move this down here since some C++ #include's don't like to be included |
| 55 | // inside an extern "C" |
| 56 | extern "C" { |
| 57 | #endif |
| 58 | |
Guido van Rossum | 0acd4b6 | 1995-02-18 14:50:12 +0000 | [diff] [blame] | 59 | #ifdef __CFM68K__ |
| 60 | #pragma lib_export on |
| 61 | #endif |
| 62 | |
Guido van Rossum | 6c1874f | 1995-01-10 17:43:33 +0000 | [diff] [blame] | 63 | #ifndef HAVE_STDLIB_H |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 64 | extern ANY *malloc Py_PROTO((size_t)); |
| 65 | extern ANY *calloc Py_PROTO((size_t, size_t)); |
| 66 | extern ANY *realloc Py_PROTO((ANY *, size_t)); |
| 67 | 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] | 68 | #endif /* !HAVE_STDLIB */ |
| 69 | |
Guido van Rossum | 1e28e5e | 1992-08-19 16:46:30 +0000 | [diff] [blame] | 70 | #ifndef NULL |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 71 | #define NULL ((ANY *)0) |
Guido van Rossum | 1e28e5e | 1992-08-19 16:46:30 +0000 | [diff] [blame] | 72 | #endif |
| 73 | |
Guido van Rossum | 5f59d60 | 1992-12-14 16:59:51 +0000 | [diff] [blame] | 74 | /* XXX Always allocate one extra byte, since some malloc's return NULL |
| 75 | XXX for malloc(0) or realloc(p, 0). */ |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 76 | #define PyMem_NEW(type, n) ( (type *) malloc(1 + (n) * sizeof(type)) ) |
| 77 | #define PyMem_RESIZE(p, type, n) \ |
Guido van Rossum | 1e28e5e | 1992-08-19 16:46:30 +0000 | [diff] [blame] | 78 | if ((p) == NULL) \ |
Guido van Rossum | 5f59d60 | 1992-12-14 16:59:51 +0000 | [diff] [blame] | 79 | (p) = (type *) malloc(1 + (n) * sizeof(type)); \ |
Guido van Rossum | 1e28e5e | 1992-08-19 16:46:30 +0000 | [diff] [blame] | 80 | else \ |
Guido van Rossum | 5f59d60 | 1992-12-14 16:59:51 +0000 | [diff] [blame] | 81 | (p) = (type *) realloc((ANY *)(p), 1 + (n) * sizeof(type)) |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 82 | #define PyMem_DEL(p) free((ANY *)p) |
| 83 | #define PyMem_XDEL(p) if ((p) == NULL) ; else PyMem_DEL(p) |
Guido van Rossum | 1e28e5e | 1992-08-19 16:46:30 +0000 | [diff] [blame] | 84 | |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 85 | #ifdef __cplusplus |
| 86 | } |
| 87 | #endif |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 88 | |
| 89 | #ifndef Py_USE_NEW_NAMES |
| 90 | #include "rename2.h" |
| 91 | #endif |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 92 | #endif /* !Py_MYMALLOC_H */ |