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 | |
| 59 | #ifndef HAVE_STDLIB_H |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 60 | extern ANY *malloc PROTO((size_t)); |
| 61 | extern ANY *calloc PROTO((size_t, size_t)); |
| 62 | extern ANY *realloc PROTO((ANY *, size_t)); |
| 63 | extern void free PROTO((ANY *)); /* XXX sometimes int on Unix old systems */ |
| 64 | #endif /* !HAVE_STDLIB */ |
| 65 | |
Guido van Rossum | 1e28e5e | 1992-08-19 16:46:30 +0000 | [diff] [blame] | 66 | #ifndef NULL |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 67 | #define NULL ((ANY *)0) |
Guido van Rossum | 1e28e5e | 1992-08-19 16:46:30 +0000 | [diff] [blame] | 68 | #endif |
| 69 | |
Guido van Rossum | 5f59d60 | 1992-12-14 16:59:51 +0000 | [diff] [blame] | 70 | /* XXX Always allocate one extra byte, since some malloc's return NULL |
| 71 | XXX for malloc(0) or realloc(p, 0). */ |
| 72 | #define NEW(type, n) ( (type *) malloc(1 + (n) * sizeof(type)) ) |
Guido van Rossum | 1e28e5e | 1992-08-19 16:46:30 +0000 | [diff] [blame] | 73 | #define RESIZE(p, type, n) \ |
| 74 | if ((p) == NULL) \ |
Guido van Rossum | 5f59d60 | 1992-12-14 16:59:51 +0000 | [diff] [blame] | 75 | (p) = (type *) malloc(1 + (n) * sizeof(type)); \ |
Guido van Rossum | 1e28e5e | 1992-08-19 16:46:30 +0000 | [diff] [blame] | 76 | else \ |
Guido van Rossum | 5f59d60 | 1992-12-14 16:59:51 +0000 | [diff] [blame] | 77 | (p) = (type *) realloc((ANY *)(p), 1 + (n) * sizeof(type)) |
Guido van Rossum | 1e28e5e | 1992-08-19 16:46:30 +0000 | [diff] [blame] | 78 | #define DEL(p) free((ANY *)p) |
| 79 | #define XDEL(p) if ((p) == NULL) ; else DEL(p) |
| 80 | |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 81 | #ifdef __cplusplus |
| 82 | } |
| 83 | #endif |
| 84 | #endif /* !Py_MYMALLOC_H */ |