blob: 959f29641ddae71c9c48e011a2aceda32ec9eb27 [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
54#ifndef ANY
55#define ANY char
56#endif
57
58#ifndef NULL
59#define NULL 0
60#endif
61
Guido van Rossum5f59d601992-12-14 16:59:51 +000062/* 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 Rossum1e28e5e1992-08-19 16:46:30 +000065#define RESIZE(p, type, n) \
66 if ((p) == NULL) \
Guido van Rossum5f59d601992-12-14 16:59:51 +000067 (p) = (type *) malloc(1 + (n) * sizeof(type)); \
Guido van Rossum1e28e5e1992-08-19 16:46:30 +000068 else \
Guido van Rossum5f59d601992-12-14 16:59:51 +000069 (p) = (type *) realloc((ANY *)(p), 1 + (n) * sizeof(type))
Guido van Rossum1e28e5e1992-08-19 16:46:30 +000070#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
78extern ANY *malloc PROTO((MALLARG));
79extern ANY *calloc PROTO((MALLARG, MALLARG));
80extern ANY *realloc PROTO((ANY *, MALLARG));
81extern void free PROTO((ANY *)); /* XXX sometimes int on Unix old systems */
82#endif
Guido van Rossuma3309961993-07-28 09:05:47 +000083
84#ifdef __cplusplus
85}
86#endif
87#endif /* !Py_MYMALLOC_H */