Mercurial > cpython-lru_cache-weakref
annotate Include/object.h @ 3720:b341def4eef8 legacy-trunk
Ignore latex intermediate products.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 26 Jun 1996 19:30:01 +0000 |
| parents | aa5f3ecbf56f |
| children | 44902516614a |
| rev | line source |
|---|---|
|
1329
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1324
diff
changeset
|
1 #ifndef Py_OBJECT_H |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1324
diff
changeset
|
2 #define Py_OBJECT_H |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1324
diff
changeset
|
3 #ifdef __cplusplus |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1324
diff
changeset
|
4 extern "C" { |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1324
diff
changeset
|
5 #endif |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1324
diff
changeset
|
6 |
| 145 | 7 /*********************************************************** |
| 2058 | 8 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
| 9 The Netherlands. | |
| 145 | 10 |
| 11 All Rights Reserved | |
| 12 | |
| 13 Permission to use, copy, modify, and distribute this software and its | |
| 14 documentation for any purpose and without fee is hereby granted, | |
| 15 provided that the above copyright notice appear in all copies and that | |
| 16 both that copyright notice and this permission notice appear in | |
| 17 supporting documentation, and that the names of Stichting Mathematisch | |
| 18 Centrum or CWI not be used in advertising or publicity pertaining to | |
| 19 distribution of the software without specific, written prior permission. | |
| 20 | |
| 21 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO | |
| 22 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND | |
| 23 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE | |
| 24 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
| 25 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
| 26 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT | |
| 27 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
| 28 | |
| 29 ******************************************************************/ | |
| 30 | |
| 6 | 31 /* Object and type object interface */ |
| 32 | |
| 33 /* | |
| 34 123456789-123456789-123456789-123456789-123456789-123456789-123456789-12 | |
| 35 | |
| 36 Objects are structures allocated on the heap. Special rules apply to | |
| 37 the use of objects to ensure they are properly garbage-collected. | |
| 38 Objects are never allocated statically or on the stack; they must be | |
| 39 accessed through special macros and functions only. (Type objects are | |
| 40 exceptions to the first rule; the standard types are represented by | |
| 41 statically initialized type objects.) | |
| 42 | |
| 43 An object has a 'reference count' that is increased or decreased when a | |
| 44 pointer to the object is copied or deleted; when the reference count | |
| 45 reaches zero there are no references to the object left and it can be | |
| 46 removed from the heap. | |
| 47 | |
| 48 An object has a 'type' that determines what it represents and what kind | |
| 49 of data it contains. An object's type is fixed when it is created. | |
| 50 Types themselves are represented as objects; an object contains a | |
| 51 pointer to the corresponding type object. The type itself has a type | |
| 52 pointer pointing to the object representing the type 'type', which | |
| 53 contains a pointer to itself!). | |
| 54 | |
| 55 Objects do not float around in memory; once allocated an object keeps | |
| 56 the same size and address. Objects that must hold variable-size data | |
| 57 can contain pointers to variable-size parts of the object. Not all | |
| 58 objects of the same type have the same size; but the size cannot change | |
| 59 after allocation. (These restrictions are made so a reference to an | |
| 60 object can be simply a pointer -- moving an object would require | |
| 61 updating all the pointers, and changing an object's size would require | |
| 62 moving it if there was another object right next to it.) | |
| 63 | |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
64 Objects are always accessed through pointers of the type 'PyObject *'. |
|
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
65 The type 'PyObject' is a structure that only contains the reference count |
| 6 | 66 and the type pointer. The actual memory allocated for an object |
| 67 contains other data that can only be accessed after casting the pointer | |
| 68 to a pointer to a longer structure type. This longer type must start | |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
69 with the reference count and type fields; the macro PyObject_HEAD should be |
| 6 | 70 used for this (to accomodate for future changes). The implementation |
| 71 of a particular object type can cast the object pointer to the proper | |
| 72 type and back. | |
| 73 | |
| 74 A standard interface exists for objects that contain an array of items | |
| 75 whose size is determined when the object is allocated. | |
| 76 | |
| 77 123456789-123456789-123456789-123456789-123456789-123456789-123456789-12 | |
| 78 */ | |
| 79 | |
| 3605 | 80 #ifdef DEBUG |
| 86 | 81 |
| 82 /* Turn on heavy reference debugging */ | |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
83 #define Py_TRACE_REFS |
| 86 | 84 |
| 85 /* Turn on reference counting */ | |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
86 #define Py_REF_DEBUG |
| 86 | 87 |
| 3605 | 88 #endif /* DEBUG */ |
| 6 | 89 |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
90 #ifdef Py_TRACE_REFS |
|
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
91 #define PyObject_HEAD \ |
| 6 | 92 struct _object *_ob_next, *_ob_prev; \ |
|
62
fffd1286c882
Be more careful with negative reference counts.
Guido van Rossum <guido@python.org>
parents:
6
diff
changeset
|
93 int ob_refcnt; \ |
| 6 | 94 struct _typeobject *ob_type; |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
95 #define PyObject_HEAD_INIT(type) 0, 0, 1, type, |
|
3573
4c7bab4cdca6
Added some visual enhancements of debugging ifdefs.
Guido van Rossum <guido@python.org>
parents:
2862
diff
changeset
|
96 #else /* !Py_TRACE_REFS */ |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
97 #define PyObject_HEAD \ |
| 2058 | 98 int ob_refcnt; \ |
| 6 | 99 struct _typeobject *ob_type; |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
100 #define PyObject_HEAD_INIT(type) 1, type, |
|
3573
4c7bab4cdca6
Added some visual enhancements of debugging ifdefs.
Guido van Rossum <guido@python.org>
parents:
2862
diff
changeset
|
101 #endif /* !Py_TRACE_REFS */ |
| 6 | 102 |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
103 #define PyObject_VAR_HEAD \ |
|
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
104 PyObject_HEAD \ |
| 2058 | 105 int ob_size; /* Number of items in variable part */ |
| 6 | 106 |
| 107 typedef struct _object { | |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
108 PyObject_HEAD |
|
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
109 } PyObject; |
| 6 | 110 |
| 111 typedef struct { | |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
112 PyObject_VAR_HEAD |
| 6 | 113 } varobject; |
| 114 | |
| 115 | |
| 116 /* | |
| 117 123456789-123456789-123456789-123456789-123456789-123456789-123456789-12 | |
| 118 | |
| 119 Type objects contain a string containing the type name (to help somewhat | |
| 120 in debugging), the allocation parameters (see newobj() and newvarobj()), | |
| 121 and methods for accessing objects of the type. Methods are optional,a | |
| 122 nil pointer meaning that particular kind of access is not available for | |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
123 this type. The Py_DECREF() macro uses the tp_dealloc method without |
| 6 | 124 checking for a nil pointer; it should always be implemented except if |
| 125 the implementation can guarantee that the reference count will never | |
| 126 reach zero (e.g., for type objects). | |
| 127 | |
| 128 NB: the methods for certain type groups are now contained in separate | |
| 129 method blocks. | |
| 130 */ | |
| 131 | |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
132 typedef PyObject * (*unaryfunc) Py_PROTO((PyObject *)); |
|
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
133 typedef PyObject * (*binaryfunc) Py_PROTO((PyObject *, PyObject *)); |
|
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
134 typedef PyObject * (*ternaryfunc) Py_PROTO((PyObject *, PyObject *, PyObject *)); |
|
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
135 typedef int (*inquiry) Py_PROTO((PyObject *)); |
|
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
136 typedef int (*coercion) Py_PROTO((PyObject **, PyObject **)); |
|
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
137 typedef PyObject *(*intargfunc) Py_PROTO((PyObject *, int)); |
|
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
138 typedef PyObject *(*intintargfunc) Py_PROTO((PyObject *, int, int)); |
|
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
139 typedef int(*intobjargproc) Py_PROTO((PyObject *, int, PyObject *)); |
|
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
140 typedef int(*intintobjargproc) Py_PROTO((PyObject *, int, int, PyObject *)); |
|
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
141 typedef int(*objobjargproc) Py_PROTO((PyObject *, PyObject *, PyObject *)); |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
142 |
| 6 | 143 typedef struct { |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
144 binaryfunc nb_add; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
145 binaryfunc nb_subtract; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
146 binaryfunc nb_multiply; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
147 binaryfunc nb_divide; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
148 binaryfunc nb_remainder; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
149 binaryfunc nb_divmod; |
|
1770
b0dca2972b2b
* Objects/{int,long,float}object.c, Include/object.h,
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
150 ternaryfunc nb_power; |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
151 unaryfunc nb_negative; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
152 unaryfunc nb_positive; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
153 unaryfunc nb_absolute; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
154 inquiry nb_nonzero; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
155 unaryfunc nb_invert; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
156 binaryfunc nb_lshift; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
157 binaryfunc nb_rshift; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
158 binaryfunc nb_and; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
159 binaryfunc nb_xor; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
160 binaryfunc nb_or; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
161 coercion nb_coerce; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
162 unaryfunc nb_int; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
163 unaryfunc nb_long; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
164 unaryfunc nb_float; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
165 unaryfunc nb_oct; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
166 unaryfunc nb_hex; |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
167 } PyNumberMethods; |
| 6 | 168 |
| 169 typedef struct { | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
170 inquiry sq_length; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
171 binaryfunc sq_concat; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
172 intargfunc sq_repeat; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
173 intargfunc sq_item; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
174 intintargfunc sq_slice; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
175 intobjargproc sq_ass_item; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
176 intintobjargproc sq_ass_slice; |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
177 } PySequenceMethods; |
| 6 | 178 |
| 179 typedef struct { | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
180 inquiry mp_length; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
181 binaryfunc mp_subscript; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
182 objobjargproc mp_ass_subscript; |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
183 } PyMappingMethods; |
| 6 | 184 |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
185 typedef void (*destructor) Py_PROTO((PyObject *)); |
|
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
186 typedef int (*printfunc) Py_PROTO((PyObject *, FILE *, int)); |
|
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
187 typedef PyObject *(*getattrfunc) Py_PROTO((PyObject *, char *)); |
|
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
188 typedef int (*setattrfunc) Py_PROTO((PyObject *, char *, PyObject *)); |
|
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
189 typedef int (*cmpfunc) Py_PROTO((PyObject *, PyObject *)); |
|
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
190 typedef PyObject *(*reprfunc) Py_PROTO((PyObject *)); |
|
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
191 typedef long (*hashfunc) Py_PROTO((PyObject *)); |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
192 |
| 6 | 193 typedef struct _typeobject { |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
194 PyObject_VAR_HEAD |
| 6 | 195 char *tp_name; /* For printing */ |
| 2058 | 196 int tp_basicsize, tp_itemsize; /* For allocation */ |
| 6 | 197 |
| 198 /* Methods to implement standard operations */ | |
| 199 | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
200 destructor tp_dealloc; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
201 printfunc tp_print; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
202 getattrfunc tp_getattr; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
203 setattrfunc tp_setattr; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
204 cmpfunc tp_compare; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
205 reprfunc tp_repr; |
| 6 | 206 |
| 207 /* Method suites for standard classes */ | |
| 208 | |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
209 PyNumberMethods *tp_as_number; |
|
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
210 PySequenceMethods *tp_as_sequence; |
|
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
211 PyMappingMethods *tp_as_mapping; |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1049
diff
changeset
|
212 |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1049
diff
changeset
|
213 /* More standard operations (at end for binary compatibility) */ |
|
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1049
diff
changeset
|
214 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
215 hashfunc tp_hash; |
|
2841
64928f6a8e80
keyword arguments and faster function calls
Guido van Rossum <guido@python.org>
parents:
2669
diff
changeset
|
216 ternaryfunc tp_call; |
|
2071
048e91a59c75
new tp_str and tp_doc members in type object
Guido van Rossum <guido@python.org>
parents:
2058
diff
changeset
|
217 reprfunc tp_str; |
|
048e91a59c75
new tp_str and tp_doc members in type object
Guido van Rossum <guido@python.org>
parents:
2058
diff
changeset
|
218 |
|
048e91a59c75
new tp_str and tp_doc members in type object
Guido van Rossum <guido@python.org>
parents:
2058
diff
changeset
|
219 /* Space for future expansion */ |
|
048e91a59c75
new tp_str and tp_doc members in type object
Guido van Rossum <guido@python.org>
parents:
2058
diff
changeset
|
220 long tp_xxx1; |
|
048e91a59c75
new tp_str and tp_doc members in type object
Guido van Rossum <guido@python.org>
parents:
2058
diff
changeset
|
221 long tp_xxx2; |
|
048e91a59c75
new tp_str and tp_doc members in type object
Guido van Rossum <guido@python.org>
parents:
2058
diff
changeset
|
222 long tp_xxx3; |
|
048e91a59c75
new tp_str and tp_doc members in type object
Guido van Rossum <guido@python.org>
parents:
2058
diff
changeset
|
223 long tp_xxx4; |
|
048e91a59c75
new tp_str and tp_doc members in type object
Guido van Rossum <guido@python.org>
parents:
2058
diff
changeset
|
224 |
|
048e91a59c75
new tp_str and tp_doc members in type object
Guido van Rossum <guido@python.org>
parents:
2058
diff
changeset
|
225 char *tp_doc; /* Documentation string */ |
|
048e91a59c75
new tp_str and tp_doc members in type object
Guido van Rossum <guido@python.org>
parents:
2058
diff
changeset
|
226 |
|
1347
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1329
diff
changeset
|
227 #ifdef COUNT_ALLOCS |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1329
diff
changeset
|
228 /* these must be last */ |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1329
diff
changeset
|
229 int tp_alloc; |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1329
diff
changeset
|
230 int tp_free; |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1329
diff
changeset
|
231 int tp_maxalloc; |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1329
diff
changeset
|
232 struct _typeobject *tp_next; |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1329
diff
changeset
|
233 #endif |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
234 } PyTypeObject; |
| 6 | 235 |
|
2669
34eefa226709
DL_IMPORT needs an argument.
Sjoerd Mullender <sjoerd@acm.org>
parents:
2664
diff
changeset
|
236 extern DL_IMPORT(PyTypeObject) PyType_Type; /* The type of type objects */ |
| 6 | 237 |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
238 #define PyType_Check(op) ((op)->ob_type == &PyType_Type) |
| 6 | 239 |
| 86 | 240 /* Generic operations on objects */ |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
241 extern int PyObject_Print Py_PROTO((PyObject *, FILE *, int)); |
|
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
242 extern PyObject * PyObject_Repr Py_PROTO((PyObject *)); |
|
2146
9afdbf944c2a
new names for lots of new functions
Guido van Rossum <guido@python.org>
parents:
2129
diff
changeset
|
243 extern PyObject * PyObject_Str Py_PROTO((PyObject *)); |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
244 extern int PyObject_Compare Py_PROTO((PyObject *, PyObject *)); |
|
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
245 extern PyObject *PyObject_GetAttrString Py_PROTO((PyObject *, char *)); |
|
2862
df8ceda84545
add forgotten PyObject_SetAttrString
Guido van Rossum <guido@python.org>
parents:
2841
diff
changeset
|
246 extern int PyObject_SetAttrString Py_PROTO((PyObject *, char *, PyObject *)); |
|
2146
9afdbf944c2a
new names for lots of new functions
Guido van Rossum <guido@python.org>
parents:
2129
diff
changeset
|
247 extern int PyObject_HasAttrString Py_PROTO((PyObject *, char *)); |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
248 extern PyObject *PyObject_GetAttr Py_PROTO((PyObject *, PyObject *)); |
|
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
249 extern int PyObject_SetAttr Py_PROTO((PyObject *, PyObject *, PyObject *)); |
|
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
250 extern long PyObject_Hash Py_PROTO((PyObject *)); |
|
2364
96747c787a83
added PyObject_IsTrue & PyCallable_Check to object interface
Guido van Rossum <guido@python.org>
parents:
2146
diff
changeset
|
251 extern int PyObject_IsTrue Py_PROTO((PyObject *)); |
|
96747c787a83
added PyObject_IsTrue & PyCallable_Check to object interface
Guido van Rossum <guido@python.org>
parents:
2146
diff
changeset
|
252 extern int PyCallable_Check Py_PROTO((PyObject *)); |
|
3573
4c7bab4cdca6
Added some visual enhancements of debugging ifdefs.
Guido van Rossum <guido@python.org>
parents:
2862
diff
changeset
|
253 extern int PyNumber_Coerce Py_PROTO((PyObject **, PyObject **)); |
| 6 | 254 |
| 255 /* Flag bits for printing: */ | |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
256 #define Py_PRINT_RAW 1 /* No string quotes etc. */ |
| 6 | 257 |
| 258 /* | |
| 259 123456789-123456789-123456789-123456789-123456789-123456789-123456789-12 | |
| 260 | |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
261 The macros Py_INCREF(op) and Py_DECREF(op) are used to increment or decrement |
|
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
262 reference counts. Py_DECREF calls the object's deallocator function; for |
| 6 | 263 objects that don't contain references to other objects or heap memory |
| 264 this can be the standard function free(). Both macros can be used | |
| 265 whereever a void expression is allowed. The argument shouldn't be a | |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
266 NIL pointer. The macro _Py_NewReference(op) is used only to initialize |
|
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
267 reference counts to 1; it is defined here for convenience. |
| 6 | 268 |
| 269 We assume that the reference count field can never overflow; this can | |
| 270 be proven when the size of the field is the same as the pointer size | |
| 271 but even with a 16-bit reference count field it is pretty unlikely so | |
| 272 we ignore the possibility. (If you are paranoid, make it a long.) | |
| 273 | |
| 274 Type objects should never be deallocated; the type pointer in an object | |
| 275 is not considered to be a reference to the type object, to save | |
| 276 complications in the deallocation function. (This is actually a | |
| 277 decision that's up to the implementer of each new type so if you want, | |
| 278 you can count such references to the type object.) | |
| 279 | |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
280 *** WARNING*** The Py_DECREF macro must have a side-effect-free argument |
| 6 | 281 since it may evaluate its argument multiple times. (The alternative |
| 282 would be to mace it a proper function or assign it to a global temporary | |
| 283 variable first, both of which are slower; and in a multi-threaded | |
| 284 environment the global variable trick is not safe.) | |
| 285 */ | |
| 286 | |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
287 #ifdef Py_TRACE_REFS |
|
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
288 #ifndef Py_REF_DEBUG |
|
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
289 #define Py_REF_DEBUG |
| 6 | 290 #endif |
| 291 #endif | |
| 292 | |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
293 #ifndef Py_TRACE_REFS |
|
1347
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1329
diff
changeset
|
294 #ifdef COUNT_ALLOCS |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
295 #define _Py_Dealloc(op) ((op)->ob_type->tp_free++, (*(op)->ob_type->tp_dealloc)((PyObject *)(op))) |
|
2638
68c7a0a61fd5
Also count UNREF's as freeing an object (only relevant when
Sjoerd Mullender <sjoerd@acm.org>
parents:
2612
diff
changeset
|
296 #define _Py_ForgetReference(op) ((op)->ob_type->tp_free++) |
|
1347
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1329
diff
changeset
|
297 #else |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
298 #define _Py_Dealloc(op) (*(op)->ob_type->tp_dealloc)((PyObject *)(op)) |
|
2638
68c7a0a61fd5
Also count UNREF's as freeing an object (only relevant when
Sjoerd Mullender <sjoerd@acm.org>
parents:
2612
diff
changeset
|
299 #define _Py_ForgetReference(op) /*empty*/ |
|
1347
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1329
diff
changeset
|
300 #endif |
| 6 | 301 #endif |
| 302 | |
|
1347
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1329
diff
changeset
|
303 #ifdef COUNT_ALLOCS |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
304 extern void inc_count Py_PROTO((PyTypeObject *)); |
|
1347
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1329
diff
changeset
|
305 #endif |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1329
diff
changeset
|
306 |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
307 #ifdef Py_REF_DEBUG |
|
3573
4c7bab4cdca6
Added some visual enhancements of debugging ifdefs.
Guido van Rossum <guido@python.org>
parents:
2862
diff
changeset
|
308 |
|
2612
ca6b60d4ea90
fix dusty debugging macros
Guido van Rossum <guido@python.org>
parents:
2436
diff
changeset
|
309 extern long _Py_RefTotal; |
|
3573
4c7bab4cdca6
Added some visual enhancements of debugging ifdefs.
Guido van Rossum <guido@python.org>
parents:
2862
diff
changeset
|
310 |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
311 #ifndef Py_TRACE_REFS |
|
1347
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1329
diff
changeset
|
312 #ifdef COUNT_ALLOCS |
|
2612
ca6b60d4ea90
fix dusty debugging macros
Guido van Rossum <guido@python.org>
parents:
2436
diff
changeset
|
313 #define _Py_NewReference(op) (inc_count((op)->ob_type), _Py_RefTotal++, (op)->ob_refcnt = 1) |
|
1347
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1329
diff
changeset
|
314 #else |
|
2612
ca6b60d4ea90
fix dusty debugging macros
Guido van Rossum <guido@python.org>
parents:
2436
diff
changeset
|
315 #define _Py_NewReference(op) (_Py_RefTotal++, (op)->ob_refcnt = 1) |
| 6 | 316 #endif |
|
3573
4c7bab4cdca6
Added some visual enhancements of debugging ifdefs.
Guido van Rossum <guido@python.org>
parents:
2862
diff
changeset
|
317 #endif /* !Py_TRACE_REFS */ |
|
4c7bab4cdca6
Added some visual enhancements of debugging ifdefs.
Guido van Rossum <guido@python.org>
parents:
2862
diff
changeset
|
318 |
|
2612
ca6b60d4ea90
fix dusty debugging macros
Guido van Rossum <guido@python.org>
parents:
2436
diff
changeset
|
319 #define Py_INCREF(op) (_Py_RefTotal++, (op)->ob_refcnt++) |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
320 #define Py_DECREF(op) \ |
|
2612
ca6b60d4ea90
fix dusty debugging macros
Guido van Rossum <guido@python.org>
parents:
2436
diff
changeset
|
321 if (--_Py_RefTotal, --(op)->ob_refcnt != 0) \ |
| 6 | 322 ; \ |
| 323 else \ | |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
324 _Py_Dealloc(op) |
|
3573
4c7bab4cdca6
Added some visual enhancements of debugging ifdefs.
Guido van Rossum <guido@python.org>
parents:
2862
diff
changeset
|
325 #else /* !Py_REF_DEBUG */ |
|
4c7bab4cdca6
Added some visual enhancements of debugging ifdefs.
Guido van Rossum <guido@python.org>
parents:
2862
diff
changeset
|
326 |
|
1347
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1329
diff
changeset
|
327 #ifdef COUNT_ALLOCS |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
328 #define _Py_NewReference(op) (inc_count((op)->ob_type), (op)->ob_refcnt = 1) |
|
1347
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1329
diff
changeset
|
329 #else |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
330 #define _Py_NewReference(op) ((op)->ob_refcnt = 1) |
|
1347
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1329
diff
changeset
|
331 #endif |
|
3573
4c7bab4cdca6
Added some visual enhancements of debugging ifdefs.
Guido van Rossum <guido@python.org>
parents:
2862
diff
changeset
|
332 |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
333 #define Py_INCREF(op) ((op)->ob_refcnt++) |
|
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
334 #define Py_DECREF(op) \ |
| 2058 | 335 if (--(op)->ob_refcnt != 0) \ |
| 6 | 336 ; \ |
| 337 else \ | |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
338 _Py_Dealloc(op) |
|
3573
4c7bab4cdca6
Added some visual enhancements of debugging ifdefs.
Guido van Rossum <guido@python.org>
parents:
2862
diff
changeset
|
339 #endif /* !Py_REF_DEBUG */ |
| 6 | 340 |
| 86 | 341 /* Macros to use in case the object pointer may be NULL: */ |
| 342 | |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
343 #define Py_XINCREF(op) if ((op) == NULL) ; else Py_INCREF(op) |
|
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
344 #define Py_XDECREF(op) if ((op) == NULL) ; else Py_DECREF(op) |
| 6 | 345 |
| 346 /* Definition of NULL, so you don't have to include <stdio.h> */ | |
| 347 | |
| 348 #ifndef NULL | |
| 349 #define NULL 0 | |
| 350 #endif | |
| 351 | |
| 352 | |
| 353 /* | |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
354 _Py_NoneStruct is an object of undefined type which can be used in contexts |
| 6 | 355 where NULL (nil) is not suitable (since NULL often means 'error'). |
| 356 | |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
357 Don't forget to apply Py_INCREF() when returning this value!!! |
| 6 | 358 */ |
| 359 | |
|
2669
34eefa226709
DL_IMPORT needs an argument.
Sjoerd Mullender <sjoerd@acm.org>
parents:
2664
diff
changeset
|
360 extern DL_IMPORT(PyObject) _Py_NoneStruct; /* Don't use this directly */ |
| 6 | 361 |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
362 #define Py_None (&_Py_NoneStruct) |
| 6 | 363 |
| 364 | |
| 365 /* | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
366 A common programming style in Python requires the forward declaration |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
367 of static, initialized structures, e.g. for a type object that is used |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
368 by the functions whose address must be used in the initializer. |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
369 Some compilers (notably SCO ODT 3.0, I seem to remember early AIX as |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
370 well) botch this if you use the static keyword for both declarations |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
371 (they allocate two objects, and use the first, uninitialized one until |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
372 the second declaration is encountered). Therefore, the forward |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
373 declaration should use the 'forwardstatic' keyword. This expands to |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
374 static on most systems, but to extern on a few. The actual storage |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
375 and name will still be static because the second declaration is |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
376 static, so no linker visible symbols will be generated. (Standard C |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
377 compilers take offense to the extern forward declaration of a static |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
378 object, so I can't just put extern in all cases. :-( ) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
379 */ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
380 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
381 #ifdef BAD_STATIC_FORWARD |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
382 #define staticforward extern |
|
2422
f4f71ebea53f
change in staticforward -- added statichere
Guido van Rossum <guido@python.org>
parents:
2364
diff
changeset
|
383 #ifdef __SC__ |
|
f4f71ebea53f
change in staticforward -- added statichere
Guido van Rossum <guido@python.org>
parents:
2364
diff
changeset
|
384 #define statichere |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
385 #else |
|
2422
f4f71ebea53f
change in staticforward -- added statichere
Guido van Rossum <guido@python.org>
parents:
2364
diff
changeset
|
386 #define statichere static |
|
f4f71ebea53f
change in staticforward -- added statichere
Guido van Rossum <guido@python.org>
parents:
2364
diff
changeset
|
387 #endif /* __SC__ */ |
|
f4f71ebea53f
change in staticforward -- added statichere
Guido van Rossum <guido@python.org>
parents:
2364
diff
changeset
|
388 #else /* !BAD_STATIC_FORWARD */ |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
389 #define staticforward static |
|
2422
f4f71ebea53f
change in staticforward -- added statichere
Guido van Rossum <guido@python.org>
parents:
2364
diff
changeset
|
390 #define statichere static |
|
f4f71ebea53f
change in staticforward -- added statichere
Guido van Rossum <guido@python.org>
parents:
2364
diff
changeset
|
391 #endif /* !BAD_STATIC_FORWARD */ |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
392 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
393 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
394 /* |
| 6 | 395 123456789-123456789-123456789-123456789-123456789-123456789-123456789-12 |
| 396 | |
| 397 More conventions | |
| 398 ================ | |
| 399 | |
| 400 Argument Checking | |
| 401 ----------------- | |
| 402 | |
| 403 Functions that take objects as arguments normally don't check for nil | |
| 404 arguments, but they do check the type of the argument, and return an | |
| 405 error if the function doesn't apply to the type. | |
| 406 | |
| 407 Failure Modes | |
| 408 ------------- | |
| 409 | |
| 410 Functions may fail for a variety of reasons, including running out of | |
| 86 | 411 memory. This is communicated to the caller in two ways: an error string |
| 412 is set (see errors.h), and the function result differs: functions that | |
| 413 normally return a pointer return NULL for failure, functions returning | |
| 414 an integer return -1 (which could be a legal return value too!), and | |
| 415 other functions return 0 for success and -1 for failure. | |
| 416 Callers should always check for errors before using the result. | |
| 6 | 417 |
| 418 Reference Counts | |
| 419 ---------------- | |
| 420 | |
| 421 It takes a while to get used to the proper usage of reference counts. | |
| 422 | |
| 423 Functions that create an object set the reference count to 1; such new | |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
424 objects must be stored somewhere or destroyed again with Py_DECREF(). |
|
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
425 Functions that 'store' objects such as PyTuple_SetItem() and |
|
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
426 PyDict_SetItemString() |
| 6 | 427 don't increment the reference count of the object, since the most |
| 428 frequent use is to store a fresh object. Functions that 'retrieve' | |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
429 objects such as PyTuple_GetItem() and PyDict_GetItemString() also |
|
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
430 don't increment |
| 6 | 431 the reference count, since most frequently the object is only looked at |
| 432 quickly. Thus, to retrieve an object and store it again, the caller | |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
433 must call Py_INCREF() explicitly. |
| 6 | 434 |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
435 NOTE: functions that 'consume' a reference count like |
|
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
436 PyDict_SetItemString() even |
| 6 | 437 consume the reference if the object wasn't stored, to simplify error |
| 438 handling. | |
| 439 | |
| 440 It seems attractive to make other functions that take an object as | |
| 441 argument consume a reference count; however this may quickly get | |
| 442 confusing (even the current practice is already confusing). Consider | |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
443 it carefully, it may save lots of calls to Py_INCREF() and Py_DECREF() at |
| 6 | 444 times. |
| 445 | |
| 446 123456789-123456789-123456789-123456789-123456789-123456789-123456789-12 | |
| 447 */ | |
|
1329
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1324
diff
changeset
|
448 |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1324
diff
changeset
|
449 #ifdef __cplusplus |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1324
diff
changeset
|
450 } |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1324
diff
changeset
|
451 #endif |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1324
diff
changeset
|
452 #endif /* !Py_OBJECT_H */ |
