blob: 24e212539ca8aafe7b085df60982dfc8d349d1da [file] [log] [blame]
Guido van Rossuma3309961993-07-28 09:05:47 +00001#ifndef Py_MYMALLOC_H
2#define Py_MYMALLOC_H
3#ifdef __cplusplus
4extern "C" {
5#endif
6
Guido van Rossum1e28e5e1992-08-19 16:46:30 +00007/***********************************************************
Guido van Rossum9bfef441993-03-29 10:43:31 +00008Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
9Amsterdam, The Netherlands.
Guido van Rossum1e28e5e1992-08-19 16:46:30 +000010
11 All Rights Reserved
12
13Permission to use, copy, modify, and distribute this software and its
14documentation for any purpose and without fee is hereby granted,
15provided that the above copyright notice appear in all copies and that
16both that copyright notice and this permission notice appear in
17supporting documentation, and that the names of Stichting Mathematisch
18Centrum or CWI not be used in advertising or publicity pertaining to
19distribution of the software without specific, written prior permission.
20
21STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
22THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
23FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
24FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
25WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
26ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
27OF 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
Guido van Rossum12d12c51993-10-26 17:58:25 +000054#ifdef __TURBOC__
55#define ANY void
56#define HAVE_STDLIB
57#endif
58
59#ifdef __GNUC__
60#define ANY void
61#define HAVE_STDLIB
62#endif
63
Guido van Rossum1e28e5e1992-08-19 16:46:30 +000064#ifndef ANY
65#define ANY char
66#endif
67
68#ifndef NULL
69#define NULL 0
70#endif
71
Guido van Rossum5f59d601992-12-14 16:59:51 +000072/* XXX Always allocate one extra byte, since some malloc's return NULL
73 XXX for malloc(0) or realloc(p, 0). */
74#define NEW(type, n) ( (type *) malloc(1 + (n) * sizeof(type)) )
Guido van Rossum1e28e5e1992-08-19 16:46:30 +000075#define RESIZE(p, type, n) \
76 if ((p) == NULL) \
Guido van Rossum5f59d601992-12-14 16:59:51 +000077 (p) = (type *) malloc(1 + (n) * sizeof(type)); \
Guido van Rossum1e28e5e1992-08-19 16:46:30 +000078 else \
Guido van Rossum5f59d601992-12-14 16:59:51 +000079 (p) = (type *) realloc((ANY *)(p), 1 + (n) * sizeof(type))
Guido van Rossum1e28e5e1992-08-19 16:46:30 +000080#define DEL(p) free((ANY *)p)
81#define XDEL(p) if ((p) == NULL) ; else DEL(p)
82
83#ifdef HAVE_STDLIB
84#include <stdlib.h>
85#define MALLARG size_t
86#else
87#define MALLARG size_t
88extern ANY *malloc PROTO((MALLARG));
89extern ANY *calloc PROTO((MALLARG, MALLARG));
90extern ANY *realloc PROTO((ANY *, MALLARG));
91extern void free PROTO((ANY *)); /* XXX sometimes int on Unix old systems */
92#endif
Guido van Rossuma3309961993-07-28 09:05:47 +000093
94#ifdef __cplusplus
95}
96#endif
97#endif /* !Py_MYMALLOC_H */