Mercurial > cpython-lru_cache-weakref
annotate Include/mymalloc.h @ 5817:48b94de85bf3 legacy-trunk
Extensive changes by AMK.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Thu, 17 Jul 1997 16:29:42 +0000 |
| parents | 201c8d06e3b7 |
| children | e2cce4adf2a7 |
| rev | line source |
|---|---|
|
1329
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
1 #ifndef Py_MYMALLOC_H |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
2 #define Py_MYMALLOC_H |
|
978
13c99eaf32a8
* renamed malloc.h mymalloc.h, and added MALLARG as the type of the
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
3 /*********************************************************** |
| 2058 | 4 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
| 5 The Netherlands. | |
|
978
13c99eaf32a8
* renamed malloc.h mymalloc.h, and added MALLARG as the type of the
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
6 |
|
13c99eaf32a8
* renamed malloc.h mymalloc.h, and added MALLARG as the type of the
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
7 All Rights Reserved |
|
13c99eaf32a8
* renamed malloc.h mymalloc.h, and added MALLARG as the type of the
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
8 |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2792
diff
changeset
|
9 Permission to use, copy, modify, and distribute this software and its |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2792
diff
changeset
|
10 documentation for any purpose and without fee is hereby granted, |
|
978
13c99eaf32a8
* renamed malloc.h mymalloc.h, and added MALLARG as the type of the
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
11 provided that the above copyright notice appear in all copies and that |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2792
diff
changeset
|
12 both that copyright notice and this permission notice appear in |
|
978
13c99eaf32a8
* renamed malloc.h mymalloc.h, and added MALLARG as the type of the
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
13 supporting documentation, and that the names of Stichting Mathematisch |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2792
diff
changeset
|
14 Centrum or CWI or Corporation for National Research Initiatives or |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2792
diff
changeset
|
15 CNRI not be used in advertising or publicity pertaining to |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2792
diff
changeset
|
16 distribution of the software without specific, written prior |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2792
diff
changeset
|
17 permission. |
|
978
13c99eaf32a8
* renamed malloc.h mymalloc.h, and added MALLARG as the type of the
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
18 |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2792
diff
changeset
|
19 While CWI is the initial source for this software, a modified version |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2792
diff
changeset
|
20 is made available by the Corporation for National Research Initiatives |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2792
diff
changeset
|
21 (CNRI) at the Internet address ftp://ftp.python.org. |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2792
diff
changeset
|
22 |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2792
diff
changeset
|
23 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2792
diff
changeset
|
24 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2792
diff
changeset
|
25 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2792
diff
changeset
|
26 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2792
diff
changeset
|
27 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2792
diff
changeset
|
28 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2792
diff
changeset
|
29 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2792
diff
changeset
|
30 PERFORMANCE OF THIS SOFTWARE. |
|
978
13c99eaf32a8
* renamed malloc.h mymalloc.h, and added MALLARG as the type of the
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
31 |
|
13c99eaf32a8
* renamed malloc.h mymalloc.h, and added MALLARG as the type of the
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
32 ******************************************************************/ |
|
13c99eaf32a8
* renamed malloc.h mymalloc.h, and added MALLARG as the type of the
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
33 |
|
13c99eaf32a8
* renamed malloc.h mymalloc.h, and added MALLARG as the type of the
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
34 /* Lowest-level memory allocation interface */ |
|
13c99eaf32a8
* renamed malloc.h mymalloc.h, and added MALLARG as the type of the
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
35 |
|
13c99eaf32a8
* renamed malloc.h mymalloc.h, and added MALLARG as the type of the
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
36 #ifdef macintosh |
|
13c99eaf32a8
* renamed malloc.h mymalloc.h, and added MALLARG as the type of the
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
37 #define ANY void |
|
13c99eaf32a8
* renamed malloc.h mymalloc.h, and added MALLARG as the type of the
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
38 #endif |
|
13c99eaf32a8
* renamed malloc.h mymalloc.h, and added MALLARG as the type of the
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
39 |
|
13c99eaf32a8
* renamed malloc.h mymalloc.h, and added MALLARG as the type of the
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
40 #ifdef __STDC__ |
|
13c99eaf32a8
* renamed malloc.h mymalloc.h, and added MALLARG as the type of the
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
41 #define ANY void |
|
13c99eaf32a8
* renamed malloc.h mymalloc.h, and added MALLARG as the type of the
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
42 #endif |
|
13c99eaf32a8
* renamed malloc.h mymalloc.h, and added MALLARG as the type of the
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
43 |
|
1369
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1329
diff
changeset
|
44 #ifdef __TURBOC__ |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1329
diff
changeset
|
45 #define ANY void |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1329
diff
changeset
|
46 #endif |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1329
diff
changeset
|
47 |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1329
diff
changeset
|
48 #ifdef __GNUC__ |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1329
diff
changeset
|
49 #define ANY void |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1329
diff
changeset
|
50 #endif |
|
89e1e5d9ccbf
* compile.[ch]: support for lambda()
Guido van Rossum <guido@python.org>
parents:
1329
diff
changeset
|
51 |
|
978
13c99eaf32a8
* renamed malloc.h mymalloc.h, and added MALLARG as the type of the
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
52 #ifndef ANY |
|
13c99eaf32a8
* renamed malloc.h mymalloc.h, and added MALLARG as the type of the
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
53 #define ANY char |
|
13c99eaf32a8
* renamed malloc.h mymalloc.h, and added MALLARG as the type of the
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
54 #endif |
|
13c99eaf32a8
* renamed malloc.h mymalloc.h, and added MALLARG as the type of the
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
55 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
56 #ifdef HAVE_STDLIB_H |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
57 #include <stdlib.h> |
|
2122
ba3fd96f055e
changes for C++ (Tim MacKenzie)
Guido van Rossum <guido@python.org>
parents:
2058
diff
changeset
|
58 #endif |
|
ba3fd96f055e
changes for C++ (Tim MacKenzie)
Guido van Rossum <guido@python.org>
parents:
2058
diff
changeset
|
59 |
|
ba3fd96f055e
changes for C++ (Tim MacKenzie)
Guido van Rossum <guido@python.org>
parents:
2058
diff
changeset
|
60 #ifdef __cplusplus |
|
ba3fd96f055e
changes for C++ (Tim MacKenzie)
Guido van Rossum <guido@python.org>
parents:
2058
diff
changeset
|
61 // Move this down here since some C++ #include's don't like to be included |
|
ba3fd96f055e
changes for C++ (Tim MacKenzie)
Guido van Rossum <guido@python.org>
parents:
2058
diff
changeset
|
62 // inside an extern "C" |
|
ba3fd96f055e
changes for C++ (Tim MacKenzie)
Guido van Rossum <guido@python.org>
parents:
2058
diff
changeset
|
63 extern "C" { |
|
ba3fd96f055e
changes for C++ (Tim MacKenzie)
Guido van Rossum <guido@python.org>
parents:
2058
diff
changeset
|
64 #endif |
|
ba3fd96f055e
changes for C++ (Tim MacKenzie)
Guido van Rossum <guido@python.org>
parents:
2058
diff
changeset
|
65 |
|
2792
af3aab6b07c4
Changed ifdef __CFM68K__ to ifdef SYMANTEC__CFM68K__: CW has its own
Jack Jansen <jack.jansen@cwi.nl>
parents:
2373
diff
changeset
|
66 #ifdef SYMANTEC__CFM68K__ |
|
2373
582b00fbab16
changes for Mac CFM-68K
Guido van Rossum <guido@python.org>
parents:
2129
diff
changeset
|
67 #pragma lib_export on |
|
582b00fbab16
changes for Mac CFM-68K
Guido van Rossum <guido@python.org>
parents:
2129
diff
changeset
|
68 #endif |
|
582b00fbab16
changes for Mac CFM-68K
Guido van Rossum <guido@python.org>
parents:
2129
diff
changeset
|
69 |
|
2122
ba3fd96f055e
changes for C++ (Tim MacKenzie)
Guido van Rossum <guido@python.org>
parents:
2058
diff
changeset
|
70 #ifndef HAVE_STDLIB_H |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2122
diff
changeset
|
71 extern ANY *malloc Py_PROTO((size_t)); |
|
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2122
diff
changeset
|
72 extern ANY *calloc Py_PROTO((size_t, size_t)); |
|
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2122
diff
changeset
|
73 extern ANY *realloc Py_PROTO((ANY *, size_t)); |
|
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2122
diff
changeset
|
74 extern void free Py_PROTO((ANY *)); /* XXX sometimes int on Unix old systems */ |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
75 #endif /* !HAVE_STDLIB */ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
76 |
|
978
13c99eaf32a8
* renamed malloc.h mymalloc.h, and added MALLARG as the type of the
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
77 #ifndef NULL |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1369
diff
changeset
|
78 #define NULL ((ANY *)0) |
|
978
13c99eaf32a8
* renamed malloc.h mymalloc.h, and added MALLARG as the type of the
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
79 #endif |
|
13c99eaf32a8
* renamed malloc.h mymalloc.h, and added MALLARG as the type of the
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
80 |
|
5760
201c8d06e3b7
Only add 1 byte to all malloc calls when it is known that malloc(0) or
Guido van Rossum <guido@python.org>
parents:
5439
diff
changeset
|
81 #ifdef MALLOC_ZERO_RETURNS_NULL |
|
1132
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
978
diff
changeset
|
82 /* XXX Always allocate one extra byte, since some malloc's return NULL |
|
6461dac9a9f2
* mymalloc.h: always allocate one extra byte, since some malloc's
Guido van Rossum <guido@python.org>
parents:
978
diff
changeset
|
83 XXX for malloc(0) or realloc(p, 0). */ |
|
5760
201c8d06e3b7
Only add 1 byte to all malloc calls when it is known that malloc(0) or
Guido van Rossum <guido@python.org>
parents:
5439
diff
changeset
|
84 #define _PyMem_EXTRA 1 |
|
201c8d06e3b7
Only add 1 byte to all malloc calls when it is known that malloc(0) or
Guido van Rossum <guido@python.org>
parents:
5439
diff
changeset
|
85 #else |
|
201c8d06e3b7
Only add 1 byte to all malloc calls when it is known that malloc(0) or
Guido van Rossum <guido@python.org>
parents:
5439
diff
changeset
|
86 #define _PyMem_EXTRA 0 |
|
201c8d06e3b7
Only add 1 byte to all malloc calls when it is known that malloc(0) or
Guido van Rossum <guido@python.org>
parents:
5439
diff
changeset
|
87 #endif |
|
201c8d06e3b7
Only add 1 byte to all malloc calls when it is known that malloc(0) or
Guido van Rossum <guido@python.org>
parents:
5439
diff
changeset
|
88 |
|
201c8d06e3b7
Only add 1 byte to all malloc calls when it is known that malloc(0) or
Guido van Rossum <guido@python.org>
parents:
5439
diff
changeset
|
89 #define PyMem_NEW(type, n) \ |
|
201c8d06e3b7
Only add 1 byte to all malloc calls when it is known that malloc(0) or
Guido van Rossum <guido@python.org>
parents:
5439
diff
changeset
|
90 ( (type *) malloc(_PyMem_EXTRA + (n) * sizeof(type)) ) |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2122
diff
changeset
|
91 #define PyMem_RESIZE(p, type, n) \ |
|
978
13c99eaf32a8
* renamed malloc.h mymalloc.h, and added MALLARG as the type of the
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
92 if ((p) == NULL) \ |
|
5760
201c8d06e3b7
Only add 1 byte to all malloc calls when it is known that malloc(0) or
Guido van Rossum <guido@python.org>
parents:
5439
diff
changeset
|
93 (p) = (type *) malloc(_PyMem_EXTRA + (n) * sizeof(type)); \ |
|
978
13c99eaf32a8
* renamed malloc.h mymalloc.h, and added MALLARG as the type of the
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
94 else \ |
|
5760
201c8d06e3b7
Only add 1 byte to all malloc calls when it is known that malloc(0) or
Guido van Rossum <guido@python.org>
parents:
5439
diff
changeset
|
95 (p) = (type *) realloc((ANY *)(p), \ |
|
201c8d06e3b7
Only add 1 byte to all malloc calls when it is known that malloc(0) or
Guido van Rossum <guido@python.org>
parents:
5439
diff
changeset
|
96 _PyMem_EXTRA + (n) * sizeof(type)) |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2122
diff
changeset
|
97 #define PyMem_DEL(p) free((ANY *)p) |
|
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2122
diff
changeset
|
98 #define PyMem_XDEL(p) if ((p) == NULL) ; else PyMem_DEL(p) |
|
978
13c99eaf32a8
* renamed malloc.h mymalloc.h, and added MALLARG as the type of the
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
99 |
|
1329
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
100 #ifdef __cplusplus |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
101 } |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
102 #endif |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2122
diff
changeset
|
103 |
|
1329
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
104 #endif /* !Py_MYMALLOC_H */ |
