blob: f1e9352c35467d31b4b2058d9e388d42f029e824 [file] [log] [blame]
Guido van Rossuma3309961993-07-28 09:05:47 +00001#ifndef Py_MYMALLOC_H
2#define Py_MYMALLOC_H
Guido van Rossum1e28e5e1992-08-19 16:46:30 +00003/***********************************************************
Guido van Rossum5799b521995-01-04 19:06:22 +00004Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
5The Netherlands.
Guido van Rossum1e28e5e1992-08-19 16:46:30 +00006
7 All Rights Reserved
8
9Permission to use, copy, modify, and distribute this software and its
10documentation for any purpose and without fee is hereby granted,
11provided that the above copyright notice appear in all copies and that
12both that copyright notice and this permission notice appear in
13supporting documentation, and that the names of Stichting Mathematisch
14Centrum or CWI not be used in advertising or publicity pertaining to
15distribution of the software without specific, written prior permission.
16
17STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
18THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
19FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
20FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
21WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
22ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
23OF 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 Rossum1e28e5e1992-08-19 16:46:30 +000031#endif
32
33#ifdef __STDC__
34#define ANY void
Guido van Rossum1e28e5e1992-08-19 16:46:30 +000035#endif
36
Guido van Rossum12d12c51993-10-26 17:58:25 +000037#ifdef __TURBOC__
38#define ANY void
Guido van Rossum12d12c51993-10-26 17:58:25 +000039#endif
40
41#ifdef __GNUC__
42#define ANY void
Guido van Rossum12d12c51993-10-26 17:58:25 +000043#endif
44
Guido van Rossum1e28e5e1992-08-19 16:46:30 +000045#ifndef ANY
46#define ANY char
47#endif
48
Guido van Rossumb6775db1994-08-01 11:34:53 +000049#ifdef HAVE_STDLIB_H
50#include <stdlib.h>
Guido van Rossum6c1874f1995-01-10 17:43:33 +000051#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"
56extern "C" {
57#endif
58
Jack Jansenf9480ce1995-06-27 13:12:09 +000059#ifdef SYMANTEC__CFM68K__
Guido van Rossum0acd4b61995-02-18 14:50:12 +000060#pragma lib_export on
61#endif
62
Guido van Rossum6c1874f1995-01-10 17:43:33 +000063#ifndef HAVE_STDLIB_H
Guido van Rossumcaa63801995-01-12 11:45:45 +000064extern ANY *malloc Py_PROTO((size_t));
65extern ANY *calloc Py_PROTO((size_t, size_t));
66extern ANY *realloc Py_PROTO((ANY *, size_t));
67extern void free Py_PROTO((ANY *)); /* XXX sometimes int on Unix old systems */
Guido van Rossumb6775db1994-08-01 11:34:53 +000068#endif /* !HAVE_STDLIB */
69
Guido van Rossum1e28e5e1992-08-19 16:46:30 +000070#ifndef NULL
Guido van Rossumb6775db1994-08-01 11:34:53 +000071#define NULL ((ANY *)0)
Guido van Rossum1e28e5e1992-08-19 16:46:30 +000072#endif
73
Guido van Rossum5f59d601992-12-14 16:59:51 +000074/* XXX Always allocate one extra byte, since some malloc's return NULL
75 XXX for malloc(0) or realloc(p, 0). */
Guido van Rossumcaa63801995-01-12 11:45:45 +000076#define PyMem_NEW(type, n) ( (type *) malloc(1 + (n) * sizeof(type)) )
77#define PyMem_RESIZE(p, type, n) \
Guido van Rossum1e28e5e1992-08-19 16:46:30 +000078 if ((p) == NULL) \
Guido van Rossum5f59d601992-12-14 16:59:51 +000079 (p) = (type *) malloc(1 + (n) * sizeof(type)); \
Guido van Rossum1e28e5e1992-08-19 16:46:30 +000080 else \
Guido van Rossum5f59d601992-12-14 16:59:51 +000081 (p) = (type *) realloc((ANY *)(p), 1 + (n) * sizeof(type))
Guido van Rossumcaa63801995-01-12 11:45:45 +000082#define PyMem_DEL(p) free((ANY *)p)
83#define PyMem_XDEL(p) if ((p) == NULL) ; else PyMem_DEL(p)
Guido van Rossum1e28e5e1992-08-19 16:46:30 +000084
Guido van Rossuma3309961993-07-28 09:05:47 +000085#ifdef __cplusplus
86}
87#endif
Guido van Rossumcaa63801995-01-12 11:45:45 +000088
89#ifndef Py_USE_NEW_NAMES
90#include "rename2.h"
91#endif
Guido van Rossuma3309961993-07-28 09:05:47 +000092#endif /* !Py_MYMALLOC_H */