Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame^] | 1 | #ifndef Py_MYMALLOC_H |
| 2 | #define Py_MYMALLOC_H |
| 3 | #ifdef __cplusplus |
| 4 | extern "C" { |
| 5 | #endif |
| 6 | |
Guido van Rossum | 1e28e5e | 1992-08-19 16:46:30 +0000 | [diff] [blame] | 7 | /*********************************************************** |
Guido van Rossum | 9bfef44 | 1993-03-29 10:43:31 +0000 | [diff] [blame] | 8 | Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum, |
| 9 | Amsterdam, The Netherlands. |
Guido van Rossum | 1e28e5e | 1992-08-19 16:46:30 +0000 | [diff] [blame] | 10 | |
| 11 | All Rights Reserved |
| 12 | |
| 13 | Permission to use, copy, modify, and distribute this software and its |
| 14 | documentation for any purpose and without fee is hereby granted, |
| 15 | provided that the above copyright notice appear in all copies and that |
| 16 | both that copyright notice and this permission notice appear in |
| 17 | supporting documentation, and that the names of Stichting Mathematisch |
| 18 | Centrum or CWI not be used in advertising or publicity pertaining to |
| 19 | distribution of the software without specific, written prior permission. |
| 20 | |
| 21 | STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO |
| 22 | THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 23 | FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE |
| 24 | FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 25 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 26 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
| 27 | OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 28 | |
| 29 | ******************************************************************/ |
| 30 | |
| 31 | /* Lowest-level memory allocation interface */ |
| 32 | |
| 33 | #ifdef macintosh |
| 34 | #define ANY void |
| 35 | #ifndef THINK_C_3_0 |
| 36 | #define HAVE_STDLIB |
| 37 | #endif |
| 38 | #endif |
| 39 | |
| 40 | #ifdef sun |
| 41 | /* Maybe not for very old versions of SunOS ? */ |
| 42 | #define HAVE_STDLIB |
| 43 | #endif |
| 44 | |
| 45 | #ifdef sgi |
| 46 | #define HAVE_STDLIB |
| 47 | #endif |
| 48 | |
| 49 | #ifdef __STDC__ |
| 50 | #define ANY void |
| 51 | #define HAVE_STDLIB |
| 52 | #endif |
| 53 | |
| 54 | #ifndef ANY |
| 55 | #define ANY char |
| 56 | #endif |
| 57 | |
| 58 | #ifndef NULL |
| 59 | #define NULL 0 |
| 60 | #endif |
| 61 | |
Guido van Rossum | 5f59d60 | 1992-12-14 16:59:51 +0000 | [diff] [blame] | 62 | /* XXX Always allocate one extra byte, since some malloc's return NULL |
| 63 | XXX for malloc(0) or realloc(p, 0). */ |
| 64 | #define NEW(type, n) ( (type *) malloc(1 + (n) * sizeof(type)) ) |
Guido van Rossum | 1e28e5e | 1992-08-19 16:46:30 +0000 | [diff] [blame] | 65 | #define RESIZE(p, type, n) \ |
| 66 | if ((p) == NULL) \ |
Guido van Rossum | 5f59d60 | 1992-12-14 16:59:51 +0000 | [diff] [blame] | 67 | (p) = (type *) malloc(1 + (n) * sizeof(type)); \ |
Guido van Rossum | 1e28e5e | 1992-08-19 16:46:30 +0000 | [diff] [blame] | 68 | else \ |
Guido van Rossum | 5f59d60 | 1992-12-14 16:59:51 +0000 | [diff] [blame] | 69 | (p) = (type *) realloc((ANY *)(p), 1 + (n) * sizeof(type)) |
Guido van Rossum | 1e28e5e | 1992-08-19 16:46:30 +0000 | [diff] [blame] | 70 | #define DEL(p) free((ANY *)p) |
| 71 | #define XDEL(p) if ((p) == NULL) ; else DEL(p) |
| 72 | |
| 73 | #ifdef HAVE_STDLIB |
| 74 | #include <stdlib.h> |
| 75 | #define MALLARG size_t |
| 76 | #else |
| 77 | #define MALLARG size_t |
| 78 | extern ANY *malloc PROTO((MALLARG)); |
| 79 | extern ANY *calloc PROTO((MALLARG, MALLARG)); |
| 80 | extern ANY *realloc PROTO((ANY *, MALLARG)); |
| 81 | extern void free PROTO((ANY *)); /* XXX sometimes int on Unix old systems */ |
| 82 | #endif |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame^] | 83 | |
| 84 | #ifdef __cplusplus |
| 85 | } |
| 86 | #endif |
| 87 | #endif /* !Py_MYMALLOC_H */ |