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