blob: cbdc429a37c26773c2a6dec8837854244e45c0d8 [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
Guido van Rossumd266eb41996-10-25 14:44:06 +00009Permission to use, copy, modify, and distribute this software and its
10documentation for any purpose and without fee is hereby granted,
Guido van Rossum1e28e5e1992-08-19 16:46:30 +000011provided that the above copyright notice appear in all copies and that
Guido van Rossumd266eb41996-10-25 14:44:06 +000012both that copyright notice and this permission notice appear in
Guido van Rossum1e28e5e1992-08-19 16:46:30 +000013supporting documentation, and that the names of Stichting Mathematisch
Guido van Rossumd266eb41996-10-25 14:44:06 +000014Centrum or CWI or Corporation for National Research Initiatives or
15CNRI not be used in advertising or publicity pertaining to
16distribution of the software without specific, written prior
17permission.
Guido van Rossum1e28e5e1992-08-19 16:46:30 +000018
Guido van Rossumd266eb41996-10-25 14:44:06 +000019While CWI is the initial source for this software, a modified version
20is made available by the Corporation for National Research Initiatives
21(CNRI) at the Internet address ftp://ftp.python.org.
22
23STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
24REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
25MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
26CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
27DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
28PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
29TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
30PERFORMANCE OF THIS SOFTWARE.
Guido van Rossum1e28e5e1992-08-19 16:46:30 +000031
32******************************************************************/
33
34/* Lowest-level memory allocation interface */
35
36#ifdef macintosh
37#define ANY void
Guido van Rossum1e28e5e1992-08-19 16:46:30 +000038#endif
39
40#ifdef __STDC__
41#define ANY void
Guido van Rossum1e28e5e1992-08-19 16:46:30 +000042#endif
43
Guido van Rossum12d12c51993-10-26 17:58:25 +000044#ifdef __TURBOC__
45#define ANY void
Guido van Rossum12d12c51993-10-26 17:58:25 +000046#endif
47
48#ifdef __GNUC__
49#define ANY void
Guido van Rossum12d12c51993-10-26 17:58:25 +000050#endif
51
Guido van Rossum1e28e5e1992-08-19 16:46:30 +000052#ifndef ANY
53#define ANY char
54#endif
55
Guido van Rossumb6775db1994-08-01 11:34:53 +000056#ifdef HAVE_STDLIB_H
57#include <stdlib.h>
Guido van Rossum6c1874f1995-01-10 17:43:33 +000058#endif
59
60#ifdef __cplusplus
61// Move this down here since some C++ #include's don't like to be included
62// inside an extern "C"
63extern "C" {
64#endif
65
Jack Jansenf9480ce1995-06-27 13:12:09 +000066#ifdef SYMANTEC__CFM68K__
Guido van Rossum0acd4b61995-02-18 14:50:12 +000067#pragma lib_export on
68#endif
69
Guido van Rossum6c1874f1995-01-10 17:43:33 +000070#ifndef HAVE_STDLIB_H
Guido van Rossumcaa63801995-01-12 11:45:45 +000071extern ANY *malloc Py_PROTO((size_t));
72extern ANY *calloc Py_PROTO((size_t, size_t));
73extern ANY *realloc Py_PROTO((ANY *, size_t));
74extern void free Py_PROTO((ANY *)); /* XXX sometimes int on Unix old systems */
Guido van Rossumb6775db1994-08-01 11:34:53 +000075#endif /* !HAVE_STDLIB */
76
Guido van Rossum1e28e5e1992-08-19 16:46:30 +000077#ifndef NULL
Guido van Rossumb6775db1994-08-01 11:34:53 +000078#define NULL ((ANY *)0)
Guido van Rossum1e28e5e1992-08-19 16:46:30 +000079#endif
80
Guido van Rossum5f59d601992-12-14 16:59:51 +000081/* XXX Always allocate one extra byte, since some malloc's return NULL
82 XXX for malloc(0) or realloc(p, 0). */
Guido van Rossumcaa63801995-01-12 11:45:45 +000083#define PyMem_NEW(type, n) ( (type *) malloc(1 + (n) * sizeof(type)) )
84#define PyMem_RESIZE(p, type, n) \
Guido van Rossum1e28e5e1992-08-19 16:46:30 +000085 if ((p) == NULL) \
Guido van Rossum5f59d601992-12-14 16:59:51 +000086 (p) = (type *) malloc(1 + (n) * sizeof(type)); \
Guido van Rossum1e28e5e1992-08-19 16:46:30 +000087 else \
Guido van Rossum5f59d601992-12-14 16:59:51 +000088 (p) = (type *) realloc((ANY *)(p), 1 + (n) * sizeof(type))
Guido van Rossumcaa63801995-01-12 11:45:45 +000089#define PyMem_DEL(p) free((ANY *)p)
90#define PyMem_XDEL(p) if ((p) == NULL) ; else PyMem_DEL(p)
Guido van Rossum1e28e5e1992-08-19 16:46:30 +000091
Guido van Rossuma3309961993-07-28 09:05:47 +000092#ifdef __cplusplus
93}
94#endif
Guido van Rossumcaa63801995-01-12 11:45:45 +000095
96#ifndef Py_USE_NEW_NAMES
97#include "rename2.h"
98#endif
Guido van Rossuma3309961993-07-28 09:05:47 +000099#endif /* !Py_MYMALLOC_H */