Mercurial > cpython-lru_cache-weakref
annotate Include/object.h @ 25838:8540887bcec6 2.2
Backport of 2.183:
Fix memory leak in add_subclass() found by NealN with valgrind.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 18 Oct 2002 13:42:21 +0000 |
| parents | 91dd223829c6 |
| children | aa8d59823add |
| 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 |
| 6 | 8 /* Object and type object interface */ |
| 9 | |
| 10 /* | |
| 11 Objects are structures allocated on the heap. Special rules apply to | |
| 12 the use of objects to ensure they are properly garbage-collected. | |
| 13 Objects are never allocated statically or on the stack; they must be | |
| 14 accessed through special macros and functions only. (Type objects are | |
| 15 exceptions to the first rule; the standard types are represented by | |
| 16 statically initialized type objects.) | |
| 17 | |
| 18 An object has a 'reference count' that is increased or decreased when a | |
| 19 pointer to the object is copied or deleted; when the reference count | |
| 20 reaches zero there are no references to the object left and it can be | |
| 21 removed from the heap. | |
| 22 | |
| 23 An object has a 'type' that determines what it represents and what kind | |
| 24 of data it contains. An object's type is fixed when it is created. | |
| 25 Types themselves are represented as objects; an object contains a | |
| 26 pointer to the corresponding type object. The type itself has a type | |
| 27 pointer pointing to the object representing the type 'type', which | |
| 28 contains a pointer to itself!). | |
| 29 | |
| 30 Objects do not float around in memory; once allocated an object keeps | |
| 31 the same size and address. Objects that must hold variable-size data | |
| 32 can contain pointers to variable-size parts of the object. Not all | |
| 33 objects of the same type have the same size; but the size cannot change | |
| 34 after allocation. (These restrictions are made so a reference to an | |
| 35 object can be simply a pointer -- moving an object would require | |
| 36 updating all the pointers, and changing an object's size would require | |
| 37 moving it if there was another object right next to it.) | |
| 38 | |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
39 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
|
40 The type 'PyObject' is a structure that only contains the reference count |
| 6 | 41 and the type pointer. The actual memory allocated for an object |
| 42 contains other data that can only be accessed after casting the pointer | |
| 43 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
|
44 with the reference count and type fields; the macro PyObject_HEAD should be |
|
13620
5b727ab37092
Spelling fixes supplied by Rob W. W. Hooft. All these are fixes in either
Thomas Wouters <thomas@python.org>
parents:
13464
diff
changeset
|
45 used for this (to accommodate for future changes). The implementation |
| 6 | 46 of a particular object type can cast the object pointer to the proper |
| 47 type and back. | |
| 48 | |
| 49 A standard interface exists for objects that contain an array of items | |
| 50 whose size is determined when the object is allocated. | |
| 51 */ | |
| 52 | |
|
4839
4567e158d20c
Rename DEBUG macro to Py_DEBUG
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
53 #ifdef Py_DEBUG |
| 86 | 54 |
| 55 /* 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
|
56 #define Py_TRACE_REFS |
| 86 | 57 |
| 58 /* 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
|
59 #define Py_REF_DEBUG |
| 86 | 60 |
|
4839
4567e158d20c
Rename DEBUG macro to Py_DEBUG
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
61 #endif /* Py_DEBUG */ |
| 6 | 62 |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
63 #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
|
64 #define PyObject_HEAD \ |
| 6 | 65 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
|
66 int ob_refcnt; \ |
| 6 | 67 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
|
68 #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
|
69 #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
|
70 #define PyObject_HEAD \ |
| 2058 | 71 int ob_refcnt; \ |
| 6 | 72 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
|
73 #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
|
74 #endif /* !Py_TRACE_REFS */ |
| 6 | 75 |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
76 #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
|
77 PyObject_HEAD \ |
| 2058 | 78 int ob_size; /* Number of items in variable part */ |
| 6 | 79 |
| 80 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
|
81 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
|
82 } PyObject; |
| 6 | 83 |
| 84 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
|
85 PyObject_VAR_HEAD |
|
5535
20c2b715188e
Oops, another forgotten renaming: varobject -> PyVarObject.
Guido van Rossum <guido@python.org>
parents:
5410
diff
changeset
|
86 } PyVarObject; |
| 6 | 87 |
| 88 | |
| 89 /* | |
| 90 Type objects contain a string containing the type name (to help somewhat | |
| 91 in debugging), the allocation parameters (see newobj() and newvarobj()), | |
| 92 and methods for accessing objects of the type. Methods are optional,a | |
| 93 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
|
94 this type. The Py_DECREF() macro uses the tp_dealloc method without |
| 6 | 95 checking for a nil pointer; it should always be implemented except if |
| 96 the implementation can guarantee that the reference count will never | |
| 97 reach zero (e.g., for type objects). | |
| 98 | |
| 99 NB: the methods for certain type groups are now contained in separate | |
| 100 method blocks. | |
| 101 */ | |
| 102 | |
|
13418
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
103 typedef PyObject * (*unaryfunc)(PyObject *); |
|
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
104 typedef PyObject * (*binaryfunc)(PyObject *, PyObject *); |
|
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
105 typedef PyObject * (*ternaryfunc)(PyObject *, PyObject *, PyObject *); |
|
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
106 typedef int (*inquiry)(PyObject *); |
|
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
107 typedef int (*coercion)(PyObject **, PyObject **); |
|
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
108 typedef PyObject *(*intargfunc)(PyObject *, int); |
|
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
109 typedef PyObject *(*intintargfunc)(PyObject *, int, int); |
|
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
110 typedef int(*intobjargproc)(PyObject *, int, PyObject *); |
|
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
111 typedef int(*intintobjargproc)(PyObject *, int, int, PyObject *); |
|
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
112 typedef int(*objobjargproc)(PyObject *, PyObject *, PyObject *); |
|
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
113 typedef int (*getreadbufferproc)(PyObject *, int, void **); |
|
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
114 typedef int (*getwritebufferproc)(PyObject *, int, void **); |
|
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
115 typedef int (*getsegcountproc)(PyObject *, int *); |
|
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
116 typedef int (*getcharbufferproc)(PyObject *, int, const char **); |
|
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
117 typedef int (*objobjproc)(PyObject *, PyObject *); |
|
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
118 typedef int (*visitproc)(PyObject *, void *); |
|
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
119 typedef int (*traverseproc)(PyObject *, visitproc, void *); |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
120 |
| 6 | 121 typedef struct { |
|
15938
8fd221aed357
Introduction to rich comparisons:
Guido van Rossum <guido@python.org>
parents:
15716
diff
changeset
|
122 /* For numbers without flag bit Py_TPFLAGS_CHECKTYPES set, all |
|
8fd221aed357
Introduction to rich comparisons:
Guido van Rossum <guido@python.org>
parents:
15716
diff
changeset
|
123 arguments are guaranteed to be of the object's type (modulo |
|
8fd221aed357
Introduction to rich comparisons:
Guido van Rossum <guido@python.org>
parents:
15716
diff
changeset
|
124 coercion hacks that is -- i.e. if the type's coercion function |
|
8fd221aed357
Introduction to rich comparisons:
Guido van Rossum <guido@python.org>
parents:
15716
diff
changeset
|
125 returns other types, then these are allowed as well). Numbers that |
|
8fd221aed357
Introduction to rich comparisons:
Guido van Rossum <guido@python.org>
parents:
15716
diff
changeset
|
126 have the Py_TPFLAGS_CHECKTYPES flag bit set should check *both* |
|
8fd221aed357
Introduction to rich comparisons:
Guido van Rossum <guido@python.org>
parents:
15716
diff
changeset
|
127 arguments for proper type and implement the necessary conversions |
|
8fd221aed357
Introduction to rich comparisons:
Guido van Rossum <guido@python.org>
parents:
15716
diff
changeset
|
128 in the slot functions themselves. */ |
|
15716
362e53f43dd2
- Add nb_cmp slot for new style nubmers.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14497
diff
changeset
|
129 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
130 binaryfunc nb_add; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
131 binaryfunc nb_subtract; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
132 binaryfunc nb_multiply; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
133 binaryfunc nb_divide; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
134 binaryfunc nb_remainder; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
135 binaryfunc nb_divmod; |
|
1770
b0dca2972b2b
* Objects/{int,long,float}object.c, Include/object.h,
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
136 ternaryfunc nb_power; |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
137 unaryfunc nb_negative; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
138 unaryfunc nb_positive; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
139 unaryfunc nb_absolute; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
140 inquiry nb_nonzero; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
141 unaryfunc nb_invert; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
142 binaryfunc nb_lshift; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
143 binaryfunc nb_rshift; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
144 binaryfunc nb_and; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
145 binaryfunc nb_xor; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
146 binaryfunc nb_or; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
147 coercion nb_coerce; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
148 unaryfunc nb_int; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
149 unaryfunc nb_long; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
150 unaryfunc nb_float; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
151 unaryfunc nb_oct; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
152 unaryfunc nb_hex; |
|
19283
b865cd5c1925
Added comments before recently added/assigned slots in the type object,
Fred Drake <fdrake@acm.org>
parents:
19134
diff
changeset
|
153 /* Added in release 2.0 */ |
|
14162
27d7d89c774b
The real suport for augmented assignment: new opcodes, new PyNumber and
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
154 binaryfunc nb_inplace_add; |
|
27d7d89c774b
The real suport for augmented assignment: new opcodes, new PyNumber and
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
155 binaryfunc nb_inplace_subtract; |
|
27d7d89c774b
The real suport for augmented assignment: new opcodes, new PyNumber and
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
156 binaryfunc nb_inplace_multiply; |
|
27d7d89c774b
The real suport for augmented assignment: new opcodes, new PyNumber and
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
157 binaryfunc nb_inplace_divide; |
|
27d7d89c774b
The real suport for augmented assignment: new opcodes, new PyNumber and
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
158 binaryfunc nb_inplace_remainder; |
|
27d7d89c774b
The real suport for augmented assignment: new opcodes, new PyNumber and
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
159 ternaryfunc nb_inplace_power; |
|
27d7d89c774b
The real suport for augmented assignment: new opcodes, new PyNumber and
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
160 binaryfunc nb_inplace_lshift; |
|
27d7d89c774b
The real suport for augmented assignment: new opcodes, new PyNumber and
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
161 binaryfunc nb_inplace_rshift; |
|
27d7d89c774b
The real suport for augmented assignment: new opcodes, new PyNumber and
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
162 binaryfunc nb_inplace_and; |
|
27d7d89c774b
The real suport for augmented assignment: new opcodes, new PyNumber and
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
163 binaryfunc nb_inplace_xor; |
|
27d7d89c774b
The real suport for augmented assignment: new opcodes, new PyNumber and
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
164 binaryfunc nb_inplace_or; |
|
19051
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
19040
diff
changeset
|
165 |
|
19283
b865cd5c1925
Added comments before recently added/assigned slots in the type object,
Fred Drake <fdrake@acm.org>
parents:
19134
diff
changeset
|
166 /* Added in release 2.2 */ |
|
19051
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
19040
diff
changeset
|
167 /* The following require the Py_TPFLAGS_HAVE_CLASS flag */ |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
19040
diff
changeset
|
168 binaryfunc nb_floor_divide; |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
19040
diff
changeset
|
169 binaryfunc nb_true_divide; |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
19040
diff
changeset
|
170 binaryfunc nb_inplace_floor_divide; |
|
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
19040
diff
changeset
|
171 binaryfunc nb_inplace_true_divide; |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
172 } PyNumberMethods; |
| 6 | 173 |
| 174 typedef struct { | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
175 inquiry sq_length; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
176 binaryfunc sq_concat; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
177 intargfunc sq_repeat; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
178 intargfunc sq_item; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
179 intintargfunc sq_slice; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
180 intobjargproc sq_ass_item; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
181 intintobjargproc sq_ass_slice; |
|
11867
06104bcf06a6
Patch by Mozhe Zadka, for __contains__ (overloading 'in'). This adds
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
182 objobjproc sq_contains; |
|
19283
b865cd5c1925
Added comments before recently added/assigned slots in the type object,
Fred Drake <fdrake@acm.org>
parents:
19134
diff
changeset
|
183 /* Added in release 2.0 */ |
|
14162
27d7d89c774b
The real suport for augmented assignment: new opcodes, new PyNumber and
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
184 binaryfunc sq_inplace_concat; |
|
27d7d89c774b
The real suport for augmented assignment: new opcodes, new PyNumber and
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
185 intargfunc sq_inplace_repeat; |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
186 } PySequenceMethods; |
| 6 | 187 |
| 188 typedef struct { | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
189 inquiry mp_length; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
190 binaryfunc mp_subscript; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
191 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
|
192 } PyMappingMethods; |
| 6 | 193 |
|
5410
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
4839
diff
changeset
|
194 typedef struct { |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
4839
diff
changeset
|
195 getreadbufferproc bf_getreadbuffer; |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
4839
diff
changeset
|
196 getwritebufferproc bf_getwritebuffer; |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
4839
diff
changeset
|
197 getsegcountproc bf_getsegcount; |
|
9304
cc3e14837379
Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents:
8124
diff
changeset
|
198 getcharbufferproc bf_getcharbuffer; |
|
5410
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
4839
diff
changeset
|
199 } PyBufferProcs; |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
4839
diff
changeset
|
200 |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
4839
diff
changeset
|
201 |
|
13418
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
202 typedef void (*destructor)(PyObject *); |
|
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
203 typedef int (*printfunc)(PyObject *, FILE *, int); |
|
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
204 typedef PyObject *(*getattrfunc)(PyObject *, char *); |
|
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
205 typedef PyObject *(*getattrofunc)(PyObject *, PyObject *); |
|
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
206 typedef int (*setattrfunc)(PyObject *, char *, PyObject *); |
|
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
207 typedef int (*setattrofunc)(PyObject *, PyObject *, PyObject *); |
|
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
208 typedef int (*cmpfunc)(PyObject *, PyObject *); |
|
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
209 typedef PyObject *(*reprfunc)(PyObject *); |
|
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
210 typedef long (*hashfunc)(PyObject *); |
|
15938
8fd221aed357
Introduction to rich comparisons:
Guido van Rossum <guido@python.org>
parents:
15716
diff
changeset
|
211 typedef PyObject *(*richcmpfunc) (PyObject *, PyObject *, int); |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
16768
diff
changeset
|
212 typedef PyObject *(*getiterfunc) (PyObject *); |
|
17617
aac65f50df6f
Mondo changes to the iterator stuff, without changing how Python code
Guido van Rossum <guido@python.org>
parents:
17597
diff
changeset
|
213 typedef PyObject *(*iternextfunc) (PyObject *); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17617
diff
changeset
|
214 typedef PyObject *(*descrgetfunc) (PyObject *, PyObject *, PyObject *); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17617
diff
changeset
|
215 typedef int (*descrsetfunc) (PyObject *, PyObject *, PyObject *); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17617
diff
changeset
|
216 typedef int (*initproc)(PyObject *, PyObject *, PyObject *); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17617
diff
changeset
|
217 typedef PyObject *(*newfunc)(struct _typeobject *, PyObject *, PyObject *); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17617
diff
changeset
|
218 typedef PyObject *(*allocfunc)(struct _typeobject *, int); |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
219 |
| 6 | 220 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
|
221 PyObject_VAR_HEAD |
|
21313
91dd223829c6
Patch supplied by Burton Radons for his own SF bug #487390: Modifying
Guido van Rossum <guido@python.org>
parents:
20725
diff
changeset
|
222 char *tp_name; /* For printing, in format "<module>.<name>" */ |
| 2058 | 223 int tp_basicsize, tp_itemsize; /* For allocation */ |
| 6 | 224 |
| 225 /* Methods to implement standard operations */ | |
| 226 | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
227 destructor tp_dealloc; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
228 printfunc tp_print; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
229 getattrfunc tp_getattr; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
230 setattrfunc tp_setattr; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
231 cmpfunc tp_compare; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
232 reprfunc tp_repr; |
| 6 | 233 |
| 234 /* Method suites for standard classes */ | |
| 235 | |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
236 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
|
237 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
|
238 PyMappingMethods *tp_as_mapping; |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1049
diff
changeset
|
239 |
|
12026
8dc0918ae2c2
Updated comment: in PyTypeObject:
Fred Drake <fdrake@acm.org>
parents:
11999
diff
changeset
|
240 /* More standard operations (here for binary compatibility) */ |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1049
diff
changeset
|
241 |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
242 hashfunc tp_hash; |
|
2841
64928f6a8e80
keyword arguments and faster function calls
Guido van Rossum <guido@python.org>
parents:
2669
diff
changeset
|
243 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
|
244 reprfunc tp_str; |
|
3983
44902516614a
Added tp_getattro, tp_setattro (Sjoerd)
Guido van Rossum <guido@python.org>
parents:
3605
diff
changeset
|
245 getattrofunc tp_getattro; |
|
44902516614a
Added tp_getattro, tp_setattro (Sjoerd)
Guido van Rossum <guido@python.org>
parents:
3605
diff
changeset
|
246 setattrofunc tp_setattro; |
|
2071
048e91a59c75
new tp_str and tp_doc members in type object
Guido van Rossum <guido@python.org>
parents:
2058
diff
changeset
|
247 |
|
5410
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
4839
diff
changeset
|
248 /* Functions to access object as input/output buffer */ |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
4839
diff
changeset
|
249 PyBufferProcs *tp_as_buffer; |
|
3b2fda31bf1b
Checkin of Jack's buffer mods.
Guido van Rossum <guido@python.org>
parents:
4839
diff
changeset
|
250 |
|
9304
cc3e14837379
Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents:
8124
diff
changeset
|
251 /* Flags to define presence of optional/expanded features */ |
|
cc3e14837379
Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents:
8124
diff
changeset
|
252 long tp_flags; |
|
2071
048e91a59c75
new tp_str and tp_doc members in type object
Guido van Rossum <guido@python.org>
parents:
2058
diff
changeset
|
253 |
|
048e91a59c75
new tp_str and tp_doc members in type object
Guido van Rossum <guido@python.org>
parents:
2058
diff
changeset
|
254 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
|
255 |
|
19283
b865cd5c1925
Added comments before recently added/assigned slots in the type object,
Fred Drake <fdrake@acm.org>
parents:
19134
diff
changeset
|
256 /* Assigned meaning in release 2.0 */ |
|
12990
e615596c5c47
Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12481
diff
changeset
|
257 /* call function for all accessible objects */ |
|
e615596c5c47
Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12481
diff
changeset
|
258 traverseproc tp_traverse; |
|
e615596c5c47
Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12481
diff
changeset
|
259 |
|
e615596c5c47
Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12481
diff
changeset
|
260 /* delete references to contained objects */ |
|
e615596c5c47
Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12481
diff
changeset
|
261 inquiry tp_clear; |
|
e615596c5c47
Round 1 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12481
diff
changeset
|
262 |
|
19283
b865cd5c1925
Added comments before recently added/assigned slots in the type object,
Fred Drake <fdrake@acm.org>
parents:
19134
diff
changeset
|
263 /* Assigned meaning in release 2.1 */ |
|
15938
8fd221aed357
Introduction to rich comparisons:
Guido van Rossum <guido@python.org>
parents:
15716
diff
changeset
|
264 /* rich comparisons */ |
|
8fd221aed357
Introduction to rich comparisons:
Guido van Rossum <guido@python.org>
parents:
15716
diff
changeset
|
265 richcmpfunc tp_richcompare; |
|
8fd221aed357
Introduction to rich comparisons:
Guido van Rossum <guido@python.org>
parents:
15716
diff
changeset
|
266 |
|
16385
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
16235
diff
changeset
|
267 /* weak reference enabler */ |
|
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
16235
diff
changeset
|
268 long tp_weaklistoffset; |
|
8124
bd744af6845f
Add new spares to the end of the type object struct.
Guido van Rossum <guido@python.org>
parents:
7983
diff
changeset
|
269 |
|
19283
b865cd5c1925
Added comments before recently added/assigned slots in the type object,
Fred Drake <fdrake@acm.org>
parents:
19134
diff
changeset
|
270 /* Added in release 2.2 */ |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
16768
diff
changeset
|
271 /* Iterators */ |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
16768
diff
changeset
|
272 getiterfunc tp_iter; |
|
17617
aac65f50df6f
Mondo changes to the iterator stuff, without changing how Python code
Guido van Rossum <guido@python.org>
parents:
17597
diff
changeset
|
273 iternextfunc tp_iternext; |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
16768
diff
changeset
|
274 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17617
diff
changeset
|
275 /* Attribute descriptor and subclassing stuff */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17617
diff
changeset
|
276 struct PyMethodDef *tp_methods; |
|
20012
3faabf54b8b8
Add optional docstrings to member descriptors. For backwards
Guido van Rossum <guido@python.org>
parents:
19970
diff
changeset
|
277 struct PyMemberDef *tp_members; |
|
20015
ca7af2a5d915
Add optional docstrings to getset descriptors. Fortunately, there's
Guido van Rossum <guido@python.org>
parents:
20012
diff
changeset
|
278 struct PyGetSetDef *tp_getset; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17617
diff
changeset
|
279 struct _typeobject *tp_base; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17617
diff
changeset
|
280 PyObject *tp_dict; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17617
diff
changeset
|
281 descrgetfunc tp_descr_get; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17617
diff
changeset
|
282 descrsetfunc tp_descr_set; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17617
diff
changeset
|
283 long tp_dictoffset; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17617
diff
changeset
|
284 initproc tp_init; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17617
diff
changeset
|
285 allocfunc tp_alloc; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17617
diff
changeset
|
286 newfunc tp_new; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17617
diff
changeset
|
287 destructor tp_free; /* Low-level free-memory routine */ |
|
20220
0b99174d6b17
Add Garbage Collection support to new-style classes (not yet to their
Guido van Rossum <guido@python.org>
parents:
20015
diff
changeset
|
288 inquiry tp_is_gc; /* For PyObject_IS_GC */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17617
diff
changeset
|
289 PyObject *tp_bases; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17617
diff
changeset
|
290 PyObject *tp_mro; /* method resolution order */ |
|
20445
27ab0327b2fc
Get rid of __defined__ and tp_defined -- there's no need to
Guido van Rossum <guido@python.org>
parents:
20439
diff
changeset
|
291 PyObject *tp_cache; |
|
20315
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20284
diff
changeset
|
292 PyObject *tp_subclasses; |
|
7b41f7a2e528
Keep track of a type's subclasses (subtypes), in tp_subclasses, which
Guido van Rossum <guido@python.org>
parents:
20284
diff
changeset
|
293 PyObject *tp_weaklist; |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17617
diff
changeset
|
294 |
|
1347
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1329
diff
changeset
|
295 #ifdef COUNT_ALLOCS |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
16768
diff
changeset
|
296 /* these must be last and never explicitly initialized */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17617
diff
changeset
|
297 int tp_allocs; |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17617
diff
changeset
|
298 int tp_frees; |
|
1347
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1329
diff
changeset
|
299 int tp_maxalloc; |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1329
diff
changeset
|
300 struct _typeobject *tp_next; |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1329
diff
changeset
|
301 #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
|
302 } PyTypeObject; |
| 6 | 303 |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17617
diff
changeset
|
304 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17617
diff
changeset
|
305 /* Generic type check */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17617
diff
changeset
|
306 extern DL_IMPORT(int) PyType_IsSubtype(PyTypeObject *, PyTypeObject *); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17617
diff
changeset
|
307 #define PyObject_TypeCheck(ob, tp) \ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17617
diff
changeset
|
308 ((ob)->ob_type == (tp) || PyType_IsSubtype((ob)->ob_type, (tp))) |
| 6 | 309 |
|
19470
45ea3b5fcbe5
Add decl of PySuper_Type; fixup comments for the two other types.
Guido van Rossum <guido@python.org>
parents:
19343
diff
changeset
|
310 extern DL_IMPORT(PyTypeObject) PyType_Type; /* built-in 'type' */ |
|
45ea3b5fcbe5
Add decl of PySuper_Type; fixup comments for the two other types.
Guido van Rossum <guido@python.org>
parents:
19343
diff
changeset
|
311 extern DL_IMPORT(PyTypeObject) PyBaseObject_Type; /* built-in 'object' */ |
|
45ea3b5fcbe5
Add decl of PySuper_Type; fixup comments for the two other types.
Guido van Rossum <guido@python.org>
parents:
19343
diff
changeset
|
312 extern DL_IMPORT(PyTypeObject) PySuper_Type; /* built-in 'super' */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17617
diff
changeset
|
313 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17617
diff
changeset
|
314 #define PyType_Check(op) PyObject_TypeCheck(op, &PyType_Type) |
|
20725
7130750a6222
SF bug #475327: type() produces incorrect error msg
Tim Peters <tim.peters@gmail.com>
parents:
20445
diff
changeset
|
315 #define PyType_CheckExact(op) ((op)->ob_type == &PyType_Type) |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17617
diff
changeset
|
316 |
|
19040
4df72ea78ae8
- Rename PyType_InitDict() to PyType_Ready().
Guido van Rossum <guido@python.org>
parents:
19006
diff
changeset
|
317 extern DL_IMPORT(int) PyType_Ready(PyTypeObject *); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17617
diff
changeset
|
318 extern DL_IMPORT(PyObject *) PyType_GenericAlloc(PyTypeObject *, int); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17617
diff
changeset
|
319 extern DL_IMPORT(PyObject *) PyType_GenericNew(PyTypeObject *, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17617
diff
changeset
|
320 PyObject *, PyObject *); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17617
diff
changeset
|
321 extern DL_IMPORT(PyObject *) _PyType_Lookup(PyTypeObject *, PyObject *); |
| 6 | 322 |
| 86 | 323 /* Generic operations on objects */ |
|
13418
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
324 extern DL_IMPORT(int) PyObject_Print(PyObject *, FILE *, int); |
|
16195
1aa8349f6695
PyObject_Dump() -> _PyObject_Dump()
Barry Warsaw <barry@python.org>
parents:
16168
diff
changeset
|
325 extern DL_IMPORT(void) _PyObject_Dump(PyObject *); |
|
13418
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
326 extern DL_IMPORT(PyObject *) PyObject_Repr(PyObject *); |
|
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
327 extern DL_IMPORT(PyObject *) PyObject_Str(PyObject *); |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19283
diff
changeset
|
328 #ifdef Py_USING_UNICODE |
|
15952
1f92d63b20f0
This patch adds a new builtin unistr() which behaves like str()
Marc-André Lemburg <mal@egenix.com>
parents:
15938
diff
changeset
|
329 extern DL_IMPORT(PyObject *) PyObject_Unicode(PyObject *); |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
19283
diff
changeset
|
330 #endif |
|
13418
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
331 extern DL_IMPORT(int) PyObject_Compare(PyObject *, PyObject *); |
|
15938
8fd221aed357
Introduction to rich comparisons:
Guido van Rossum <guido@python.org>
parents:
15716
diff
changeset
|
332 extern DL_IMPORT(PyObject *) PyObject_RichCompare(PyObject *, PyObject *, int); |
|
8fd221aed357
Introduction to rich comparisons:
Guido van Rossum <guido@python.org>
parents:
15716
diff
changeset
|
333 extern DL_IMPORT(int) PyObject_RichCompareBool(PyObject *, PyObject *, int); |
|
13418
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
334 extern DL_IMPORT(PyObject *) PyObject_GetAttrString(PyObject *, char *); |
|
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
335 extern DL_IMPORT(int) PyObject_SetAttrString(PyObject *, char *, PyObject *); |
|
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
336 extern DL_IMPORT(int) PyObject_HasAttrString(PyObject *, char *); |
|
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
337 extern DL_IMPORT(PyObject *) PyObject_GetAttr(PyObject *, PyObject *); |
|
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
338 extern DL_IMPORT(int) PyObject_SetAttr(PyObject *, PyObject *, PyObject *); |
|
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
339 extern DL_IMPORT(int) PyObject_HasAttr(PyObject *, PyObject *); |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17617
diff
changeset
|
340 extern DL_IMPORT(PyObject **) _PyObject_GetDictPtr(PyObject *); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17617
diff
changeset
|
341 extern DL_IMPORT(PyObject *) PyObject_GenericGetAttr(PyObject *, PyObject *); |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17617
diff
changeset
|
342 extern DL_IMPORT(int) PyObject_GenericSetAttr(PyObject *, |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17617
diff
changeset
|
343 PyObject *, PyObject *); |
|
13418
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
344 extern DL_IMPORT(long) PyObject_Hash(PyObject *); |
|
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
345 extern DL_IMPORT(int) PyObject_IsTrue(PyObject *); |
|
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
346 extern DL_IMPORT(int) PyObject_Not(PyObject *); |
|
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
347 extern DL_IMPORT(int) PyCallable_Check(PyObject *); |
|
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
348 extern DL_IMPORT(int) PyNumber_Coerce(PyObject **, PyObject **); |
|
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
349 extern DL_IMPORT(int) PyNumber_CoerceEx(PyObject **, PyObject **); |
| 6 | 350 |
|
20284
fb5f12117036
PyObject_ClearWeakRefs() is now a real function instead of a function pointer;
Fred Drake <fdrake@acm.org>
parents:
20220
diff
changeset
|
351 extern DL_IMPORT(void) PyObject_ClearWeakRefs(PyObject *); |
|
16385
1fb6672b20ef
PEP 205, Weak References -- initial checkin.
Fred Drake <fdrake@acm.org>
parents:
16235
diff
changeset
|
352 |
|
19970
f761cab28c1c
Hopefully fix 3-way comparisons. This unfortunately adds yet another
Guido van Rossum <guido@python.org>
parents:
19705
diff
changeset
|
353 /* A slot function whose address we need to compare */ |
|
f761cab28c1c
Hopefully fix 3-way comparisons. This unfortunately adds yet another
Guido van Rossum <guido@python.org>
parents:
19705
diff
changeset
|
354 extern int _PyObject_SlotCompare(PyObject *, PyObject *); |
|
f761cab28c1c
Hopefully fix 3-way comparisons. This unfortunately adds yet another
Guido van Rossum <guido@python.org>
parents:
19705
diff
changeset
|
355 |
|
f761cab28c1c
Hopefully fix 3-way comparisons. This unfortunately adds yet another
Guido van Rossum <guido@python.org>
parents:
19705
diff
changeset
|
356 |
|
19705
b7f6fbc087a7
At Guido's suggestion, here's a new C API function, PyObject_Dir(), like
Tim Peters <tim.peters@gmail.com>
parents:
19576
diff
changeset
|
357 /* PyObject_Dir(obj) acts like Python __builtin__.dir(obj), returning a |
|
b7f6fbc087a7
At Guido's suggestion, here's a new C API function, PyObject_Dir(), like
Tim Peters <tim.peters@gmail.com>
parents:
19576
diff
changeset
|
358 list of strings. PyObject_Dir(NULL) is like __builtin__.dir(), |
|
b7f6fbc087a7
At Guido's suggestion, here's a new C API function, PyObject_Dir(), like
Tim Peters <tim.peters@gmail.com>
parents:
19576
diff
changeset
|
359 returning the names of the current locals. In this case, if there are |
|
b7f6fbc087a7
At Guido's suggestion, here's a new C API function, PyObject_Dir(), like
Tim Peters <tim.peters@gmail.com>
parents:
19576
diff
changeset
|
360 no current locals, NULL is returned, and PyErr_Occurred() is false. |
|
b7f6fbc087a7
At Guido's suggestion, here's a new C API function, PyObject_Dir(), like
Tim Peters <tim.peters@gmail.com>
parents:
19576
diff
changeset
|
361 */ |
|
b7f6fbc087a7
At Guido's suggestion, here's a new C API function, PyObject_Dir(), like
Tim Peters <tim.peters@gmail.com>
parents:
19576
diff
changeset
|
362 extern DL_IMPORT(PyObject *) PyObject_Dir(PyObject *); |
|
b7f6fbc087a7
At Guido's suggestion, here's a new C API function, PyObject_Dir(), like
Tim Peters <tim.peters@gmail.com>
parents:
19576
diff
changeset
|
363 |
|
b7f6fbc087a7
At Guido's suggestion, here's a new C API function, PyObject_Dir(), like
Tim Peters <tim.peters@gmail.com>
parents:
19576
diff
changeset
|
364 |
|
7983
068303f925ea
Add prototypes for Py_Repr{Enter,Leave}.
Guido van Rossum <guido@python.org>
parents:
7935
diff
changeset
|
365 /* Helpers for printing recursive container types */ |
|
13418
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
366 extern DL_IMPORT(int) Py_ReprEnter(PyObject *); |
|
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
367 extern DL_IMPORT(void) Py_ReprLeave(PyObject *); |
|
7983
068303f925ea
Add prototypes for Py_Repr{Enter,Leave}.
Guido van Rossum <guido@python.org>
parents:
7935
diff
changeset
|
368 |
|
13141
cca84745da3e
This patch addresses two main issues: (1) There exist some non-fatal
Fred Drake <fdrake@acm.org>
parents:
12993
diff
changeset
|
369 /* Helpers for hash functions */ |
|
13418
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
370 extern DL_IMPORT(long) _Py_HashDouble(double); |
|
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
371 extern DL_IMPORT(long) _Py_HashPointer(void*); |
|
13141
cca84745da3e
This patch addresses two main issues: (1) There exist some non-fatal
Fred Drake <fdrake@acm.org>
parents:
12993
diff
changeset
|
372 |
|
16394
f700e6b8de1f
Undo recent change that banned using import to bind a global, as per
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16385
diff
changeset
|
373 /* Helper for passing objects to printf and the like */ |
|
f700e6b8de1f
Undo recent change that banned using import to bind a global, as per
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16385
diff
changeset
|
374 #define PyObject_REPR(obj) PyString_AS_STRING(PyObject_Repr(obj)) |
|
f700e6b8de1f
Undo recent change that banned using import to bind a global, as per
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16385
diff
changeset
|
375 |
| 6 | 376 /* 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
|
377 #define Py_PRINT_RAW 1 /* No string quotes etc. */ |
| 6 | 378 |
| 379 /* | |
|
9304
cc3e14837379
Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents:
8124
diff
changeset
|
380 |
|
cc3e14837379
Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents:
8124
diff
changeset
|
381 Type flags (tp_flags) |
|
cc3e14837379
Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents:
8124
diff
changeset
|
382 |
|
cc3e14837379
Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents:
8124
diff
changeset
|
383 These flags are used to extend the type structure in a backwards-compatible |
|
cc3e14837379
Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents:
8124
diff
changeset
|
384 fashion. Extensions can use the flags to indicate (and test) when a given |
|
cc3e14837379
Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents:
8124
diff
changeset
|
385 type structure contains a new feature. The Python core will use these when |
|
cc3e14837379
Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents:
8124
diff
changeset
|
386 introducing new functionality between major revisions (to avoid mid-version |
|
cc3e14837379
Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents:
8124
diff
changeset
|
387 changes in the PYTHON_API_VERSION). |
|
cc3e14837379
Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents:
8124
diff
changeset
|
388 |
|
cc3e14837379
Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents:
8124
diff
changeset
|
389 Arbitration of the flag bit positions will need to be coordinated among |
|
cc3e14837379
Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents:
8124
diff
changeset
|
390 all extension writers who publically release their extensions (this will |
|
cc3e14837379
Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents:
8124
diff
changeset
|
391 be fewer than you might expect!).. |
|
cc3e14837379
Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents:
8124
diff
changeset
|
392 |
|
cc3e14837379
Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents:
8124
diff
changeset
|
393 Python 1.5.2 introduced the bf_getcharbuffer slot into PyBufferProcs. |
|
cc3e14837379
Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents:
8124
diff
changeset
|
394 |
|
cc3e14837379
Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents:
8124
diff
changeset
|
395 Type definitions should use Py_TPFLAGS_DEFAULT for their tp_flags value. |
|
cc3e14837379
Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents:
8124
diff
changeset
|
396 |
|
cc3e14837379
Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents:
8124
diff
changeset
|
397 Code can use PyType_HasFeature(type_ob, flag_value) to test whether the |
|
cc3e14837379
Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents:
8124
diff
changeset
|
398 given type object has a specified feature. |
|
cc3e14837379
Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents:
8124
diff
changeset
|
399 |
|
cc3e14837379
Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents:
8124
diff
changeset
|
400 */ |
|
cc3e14837379
Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents:
8124
diff
changeset
|
401 |
|
cc3e14837379
Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents:
8124
diff
changeset
|
402 /* PyBufferProcs contains bf_getcharbuffer */ |
|
cc3e14837379
Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents:
8124
diff
changeset
|
403 #define Py_TPFLAGS_HAVE_GETCHARBUFFER (1L<<0) |
|
cc3e14837379
Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents:
8124
diff
changeset
|
404 |
|
11867
06104bcf06a6
Patch by Mozhe Zadka, for __contains__ (overloading 'in'). This adds
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
405 /* PySequenceMethods contains sq_contains */ |
|
06104bcf06a6
Patch by Mozhe Zadka, for __contains__ (overloading 'in'). This adds
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
406 #define Py_TPFLAGS_HAVE_SEQUENCE_IN (1L<<1) |
|
06104bcf06a6
Patch by Mozhe Zadka, for __contains__ (overloading 'in'). This adds
Guido van Rossum <guido@python.org>
parents:
11673
diff
changeset
|
407 |
|
19576
b67309407cfc
Change the GC type flag since the API has changed. Allow types using
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19470
diff
changeset
|
408 /* This is here for backwards compatibility. Extensions that use the old GC |
|
b67309407cfc
Change the GC type flag since the API has changed. Allow types using
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19470
diff
changeset
|
409 * API will still compile but the objects will not be tracked by the GC. */ |
|
b67309407cfc
Change the GC type flag since the API has changed. Allow types using
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19470
diff
changeset
|
410 #define Py_TPFLAGS_GC 0 /* used to be (1L<<2) */ |
|
12993
8f79c5b69e0a
part 2 of Neil Schemenauer's GC patches:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12990
diff
changeset
|
411 |
|
14162
27d7d89c774b
The real suport for augmented assignment: new opcodes, new PyNumber and
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
412 /* PySequenceMethods and PyNumberMethods contain in-place operators */ |
|
27d7d89c774b
The real suport for augmented assignment: new opcodes, new PyNumber and
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
413 #define Py_TPFLAGS_HAVE_INPLACEOPS (1L<<3) |
|
27d7d89c774b
The real suport for augmented assignment: new opcodes, new PyNumber and
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
414 |
|
15716
362e53f43dd2
- Add nb_cmp slot for new style nubmers.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14497
diff
changeset
|
415 /* PyNumberMethods do their own coercion */ |
|
15938
8fd221aed357
Introduction to rich comparisons:
Guido van Rossum <guido@python.org>
parents:
15716
diff
changeset
|
416 #define Py_TPFLAGS_CHECKTYPES (1L<<4) |
|
15716
362e53f43dd2
- Add nb_cmp slot for new style nubmers.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14497
diff
changeset
|
417 |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
16768
diff
changeset
|
418 /* tp_richcompare is defined */ |
|
16235
5c60184f7f52
Add a flag to indicate the presence of the tp_richcompare field, and
Guido van Rossum <guido@python.org>
parents:
16195
diff
changeset
|
419 #define Py_TPFLAGS_HAVE_RICHCOMPARE (1L<<5) |
|
5c60184f7f52
Add a flag to indicate the presence of the tp_richcompare field, and
Guido van Rossum <guido@python.org>
parents:
16195
diff
changeset
|
420 |
|
16420
38204093d9c9
Use a type flag to determine the applicability of the tp_weaklistoffset
Fred Drake <fdrake@acm.org>
parents:
16394
diff
changeset
|
421 /* Objects which are weakly referencable if their tp_weaklistoffset is >0 */ |
|
38204093d9c9
Use a type flag to determine the applicability of the tp_weaklistoffset
Fred Drake <fdrake@acm.org>
parents:
16394
diff
changeset
|
422 #define Py_TPFLAGS_HAVE_WEAKREFS (1L<<6) |
|
38204093d9c9
Use a type flag to determine the applicability of the tp_weaklistoffset
Fred Drake <fdrake@acm.org>
parents:
16394
diff
changeset
|
423 |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
16768
diff
changeset
|
424 /* tp_iter is defined */ |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
16768
diff
changeset
|
425 #define Py_TPFLAGS_HAVE_ITER (1L<<7) |
|
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
16768
diff
changeset
|
426 |
|
19051
f20727cc3d0f
Implement PEP 238 in its (almost) full glory.
Guido van Rossum <guido@python.org>
parents:
19040
diff
changeset
|
427 /* New members introduced by Python 2.2 exist */ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17617
diff
changeset
|
428 #define Py_TPFLAGS_HAVE_CLASS (1L<<8) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17617
diff
changeset
|
429 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17617
diff
changeset
|
430 /* Set if the type object is dynamically allocated */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17617
diff
changeset
|
431 #define Py_TPFLAGS_HEAPTYPE (1L<<9) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17617
diff
changeset
|
432 |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17617
diff
changeset
|
433 /* Set if the type allows subclassing */ |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17617
diff
changeset
|
434 #define Py_TPFLAGS_BASETYPE (1L<<10) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17617
diff
changeset
|
435 |
|
19134
d98121930e70
Add new flags for PyType_Ready(): READY to explicitly indicate the
Guido van Rossum <guido@python.org>
parents:
19051
diff
changeset
|
436 /* Set if the type is 'ready' -- fully initialized */ |
|
d98121930e70
Add new flags for PyType_Ready(): READY to explicitly indicate the
Guido van Rossum <guido@python.org>
parents:
19051
diff
changeset
|
437 #define Py_TPFLAGS_READY (1L<<12) |
|
d98121930e70
Add new flags for PyType_Ready(): READY to explicitly indicate the
Guido van Rossum <guido@python.org>
parents:
19051
diff
changeset
|
438 |
|
d98121930e70
Add new flags for PyType_Ready(): READY to explicitly indicate the
Guido van Rossum <guido@python.org>
parents:
19051
diff
changeset
|
439 /* Set while the type is being 'readied', to prevent recursive ready calls */ |
|
d98121930e70
Add new flags for PyType_Ready(): READY to explicitly indicate the
Guido van Rossum <guido@python.org>
parents:
19051
diff
changeset
|
440 #define Py_TPFLAGS_READYING (1L<<13) |
|
d98121930e70
Add new flags for PyType_Ready(): READY to explicitly indicate the
Guido van Rossum <guido@python.org>
parents:
19051
diff
changeset
|
441 |
|
19576
b67309407cfc
Change the GC type flag since the API has changed. Allow types using
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19470
diff
changeset
|
442 /* Objects support garbage collection (see objimp.h) */ |
|
b67309407cfc
Change the GC type flag since the API has changed. Allow types using
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19470
diff
changeset
|
443 #ifdef WITH_CYCLE_GC |
|
b67309407cfc
Change the GC type flag since the API has changed. Allow types using
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19470
diff
changeset
|
444 #define Py_TPFLAGS_HAVE_GC (1L<<14) |
|
b67309407cfc
Change the GC type flag since the API has changed. Allow types using
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19470
diff
changeset
|
445 #else |
|
b67309407cfc
Change the GC type flag since the API has changed. Allow types using
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19470
diff
changeset
|
446 #define Py_TPFLAGS_HAVE_GC 0 |
|
b67309407cfc
Change the GC type flag since the API has changed. Allow types using
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19470
diff
changeset
|
447 #endif |
|
b67309407cfc
Change the GC type flag since the API has changed. Allow types using
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
19470
diff
changeset
|
448 |
|
16235
5c60184f7f52
Add a flag to indicate the presence of the tp_richcompare field, and
Guido van Rossum <guido@python.org>
parents:
16195
diff
changeset
|
449 #define Py_TPFLAGS_DEFAULT ( \ |
|
5c60184f7f52
Add a flag to indicate the presence of the tp_richcompare field, and
Guido van Rossum <guido@python.org>
parents:
16195
diff
changeset
|
450 Py_TPFLAGS_HAVE_GETCHARBUFFER | \ |
|
14162
27d7d89c774b
The real suport for augmented assignment: new opcodes, new PyNumber and
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
451 Py_TPFLAGS_HAVE_SEQUENCE_IN | \ |
|
16235
5c60184f7f52
Add a flag to indicate the presence of the tp_richcompare field, and
Guido van Rossum <guido@python.org>
parents:
16195
diff
changeset
|
452 Py_TPFLAGS_HAVE_INPLACEOPS | \ |
|
5c60184f7f52
Add a flag to indicate the presence of the tp_richcompare field, and
Guido van Rossum <guido@python.org>
parents:
16195
diff
changeset
|
453 Py_TPFLAGS_HAVE_RICHCOMPARE | \ |
|
16420
38204093d9c9
Use a type flag to determine the applicability of the tp_weaklistoffset
Fred Drake <fdrake@acm.org>
parents:
16394
diff
changeset
|
454 Py_TPFLAGS_HAVE_WEAKREFS | \ |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
16768
diff
changeset
|
455 Py_TPFLAGS_HAVE_ITER | \ |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17617
diff
changeset
|
456 Py_TPFLAGS_HAVE_CLASS | \ |
|
16235
5c60184f7f52
Add a flag to indicate the presence of the tp_richcompare field, and
Guido van Rossum <guido@python.org>
parents:
16195
diff
changeset
|
457 0) |
|
9304
cc3e14837379
Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents:
8124
diff
changeset
|
458 |
|
cc3e14837379
Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents:
8124
diff
changeset
|
459 #define PyType_HasFeature(t,f) (((t)->tp_flags & (f)) != 0) |
|
cc3e14837379
Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents:
8124
diff
changeset
|
460 |
|
cc3e14837379
Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents:
8124
diff
changeset
|
461 |
|
cc3e14837379
Changes by Greg Stein (code) and GvR (design).
Guido van Rossum <guido@python.org>
parents:
8124
diff
changeset
|
462 /* |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
463 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
|
464 reference counts. Py_DECREF calls the object's deallocator function; for |
| 6 | 465 objects that don't contain references to other objects or heap memory |
| 466 this can be the standard function free(). Both macros can be used | |
|
13620
5b727ab37092
Spelling fixes supplied by Rob W. W. Hooft. All these are fixes in either
Thomas Wouters <thomas@python.org>
parents:
13464
diff
changeset
|
467 wherever 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
|
468 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
|
469 reference counts to 1; it is defined here for convenience. |
| 6 | 470 |
| 471 We assume that the reference count field can never overflow; this can | |
| 472 be proven when the size of the field is the same as the pointer size | |
| 473 but even with a 16-bit reference count field it is pretty unlikely so | |
| 474 we ignore the possibility. (If you are paranoid, make it a long.) | |
| 475 | |
| 476 Type objects should never be deallocated; the type pointer in an object | |
| 477 is not considered to be a reference to the type object, to save | |
| 478 complications in the deallocation function. (This is actually a | |
| 479 decision that's up to the implementer of each new type so if you want, | |
| 480 you can count such references to the type object.) | |
| 481 | |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
482 *** WARNING*** The Py_DECREF macro must have a side-effect-free argument |
| 6 | 483 since it may evaluate its argument multiple times. (The alternative |
| 484 would be to mace it a proper function or assign it to a global temporary | |
| 485 variable first, both of which are slower; and in a multi-threaded | |
| 486 environment the global variable trick is not safe.) | |
| 487 */ | |
| 488 | |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
489 #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
|
490 #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
|
491 #define Py_REF_DEBUG |
| 6 | 492 #endif |
| 493 #endif | |
| 494 | |
|
4001
1ed773e15936
Added extern declarations for reference count admin debug functions.
Guido van Rossum <guido@python.org>
parents:
3983
diff
changeset
|
495 #ifdef Py_TRACE_REFS |
|
13418
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
496 extern DL_IMPORT(void) _Py_Dealloc(PyObject *); |
|
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
497 extern DL_IMPORT(void) _Py_NewReference(PyObject *); |
|
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
498 extern DL_IMPORT(void) _Py_ForgetReference(PyObject *); |
|
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
499 extern DL_IMPORT(void) _Py_PrintReferences(FILE *); |
|
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
500 extern DL_IMPORT(void) _Py_ResetReferences(void); |
|
4001
1ed773e15936
Added extern declarations for reference count admin debug functions.
Guido van Rossum <guido@python.org>
parents:
3983
diff
changeset
|
501 #endif |
|
1ed773e15936
Added extern declarations for reference count admin debug functions.
Guido van Rossum <guido@python.org>
parents:
3983
diff
changeset
|
502 |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
503 #ifndef Py_TRACE_REFS |
|
1347
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1329
diff
changeset
|
504 #ifdef COUNT_ALLOCS |
|
18933
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17617
diff
changeset
|
505 #define _Py_Dealloc(op) ((op)->ob_type->tp_frees++, (*(op)->ob_type->tp_dealloc)((PyObject *)(op))) |
|
09df3254b49d
Merge of descr-branch back into trunk.
Tim Peters <tim.peters@gmail.com>
parents:
17617
diff
changeset
|
506 #define _Py_ForgetReference(op) ((op)->ob_type->tp_frees++) |
|
4001
1ed773e15936
Added extern declarations for reference count admin debug functions.
Guido van Rossum <guido@python.org>
parents:
3983
diff
changeset
|
507 #else /* !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
|
508 #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
|
509 #define _Py_ForgetReference(op) /*empty*/ |
|
4001
1ed773e15936
Added extern declarations for reference count admin debug functions.
Guido van Rossum <guido@python.org>
parents:
3983
diff
changeset
|
510 #endif /* !COUNT_ALLOCS */ |
|
1ed773e15936
Added extern declarations for reference count admin debug functions.
Guido van Rossum <guido@python.org>
parents:
3983
diff
changeset
|
511 #endif /* !Py_TRACE_REFS */ |
| 6 | 512 |
|
1347
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1329
diff
changeset
|
513 #ifdef COUNT_ALLOCS |
|
13418
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
514 extern DL_IMPORT(void) inc_count(PyTypeObject *); |
|
1347
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1329
diff
changeset
|
515 #endif |
|
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1329
diff
changeset
|
516 |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
517 #ifdef Py_REF_DEBUG |
|
3573
4c7bab4cdca6
Added some visual enhancements of debugging ifdefs.
Guido van Rossum <guido@python.org>
parents:
2862
diff
changeset
|
518 |
|
9586
60fdb1db1175
Add DL_IMPORT(returntype) for all officially exported functions.
Guido van Rossum <guido@python.org>
parents:
9304
diff
changeset
|
519 extern DL_IMPORT(long) _Py_RefTotal; |
|
3573
4c7bab4cdca6
Added some visual enhancements of debugging ifdefs.
Guido van Rossum <guido@python.org>
parents:
2862
diff
changeset
|
520 |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
521 #ifndef Py_TRACE_REFS |
|
1347
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1329
diff
changeset
|
522 #ifdef COUNT_ALLOCS |
|
2612
ca6b60d4ea90
fix dusty debugging macros
Guido van Rossum <guido@python.org>
parents:
2436
diff
changeset
|
523 #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
|
524 #else |
|
2612
ca6b60d4ea90
fix dusty debugging macros
Guido van Rossum <guido@python.org>
parents:
2436
diff
changeset
|
525 #define _Py_NewReference(op) (_Py_RefTotal++, (op)->ob_refcnt = 1) |
| 6 | 526 #endif |
|
3573
4c7bab4cdca6
Added some visual enhancements of debugging ifdefs.
Guido van Rossum <guido@python.org>
parents:
2862
diff
changeset
|
527 #endif /* !Py_TRACE_REFS */ |
|
4c7bab4cdca6
Added some visual enhancements of debugging ifdefs.
Guido van Rossum <guido@python.org>
parents:
2862
diff
changeset
|
528 |
|
2612
ca6b60d4ea90
fix dusty debugging macros
Guido van Rossum <guido@python.org>
parents:
2436
diff
changeset
|
529 #define Py_INCREF(op) (_Py_RefTotal++, (op)->ob_refcnt++) |
|
19006
81114209ee8e
Patch #448194: Debuging negative reference counts.
Martin v. Löwis <martin@v.loewis.de>
parents:
18933
diff
changeset
|
530 /* under Py_REF_DEBUG: also log negative ref counts after Py_DECREF() !! */ |
|
81114209ee8e
Patch #448194: Debuging negative reference counts.
Martin v. Löwis <martin@v.loewis.de>
parents:
18933
diff
changeset
|
531 #define Py_DECREF(op) \ |
|
81114209ee8e
Patch #448194: Debuging negative reference counts.
Martin v. Löwis <martin@v.loewis.de>
parents:
18933
diff
changeset
|
532 if (--_Py_RefTotal, 0 < (--((op)->ob_refcnt))) ; \ |
|
81114209ee8e
Patch #448194: Debuging negative reference counts.
Martin v. Löwis <martin@v.loewis.de>
parents:
18933
diff
changeset
|
533 else if (0 == (op)->ob_refcnt) _Py_Dealloc( (PyObject*)(op)); \ |
|
81114209ee8e
Patch #448194: Debuging negative reference counts.
Martin v. Löwis <martin@v.loewis.de>
parents:
18933
diff
changeset
|
534 else (void)fprintf( stderr, "%s:%i negative ref count %i\n", \ |
|
81114209ee8e
Patch #448194: Debuging negative reference counts.
Martin v. Löwis <martin@v.loewis.de>
parents:
18933
diff
changeset
|
535 __FILE__, __LINE__, (op)->ob_refcnt) |
|
3573
4c7bab4cdca6
Added some visual enhancements of debugging ifdefs.
Guido van Rossum <guido@python.org>
parents:
2862
diff
changeset
|
536 #else /* !Py_REF_DEBUG */ |
|
4c7bab4cdca6
Added some visual enhancements of debugging ifdefs.
Guido van Rossum <guido@python.org>
parents:
2862
diff
changeset
|
537 |
|
1347
a22a350d3a5d
* Extended X interface: pixmap objects, colormap objects visual objects,
Sjoerd Mullender <sjoerd@acm.org>
parents:
1329
diff
changeset
|
538 #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
|
539 #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
|
540 #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
|
541 #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
|
542 #endif |
|
3573
4c7bab4cdca6
Added some visual enhancements of debugging ifdefs.
Guido van Rossum <guido@python.org>
parents:
2862
diff
changeset
|
543 |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
544 #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
|
545 #define Py_DECREF(op) \ |
| 2058 | 546 if (--(op)->ob_refcnt != 0) \ |
| 6 | 547 ; \ |
| 548 else \ | |
|
5943
ac877c4768e1
Add a cast to the call to _Py_Dealloc in the expanded version of
Guido van Rossum <guido@python.org>
parents:
5535
diff
changeset
|
549 _Py_Dealloc((PyObject *)(op)) |
|
3573
4c7bab4cdca6
Added some visual enhancements of debugging ifdefs.
Guido van Rossum <guido@python.org>
parents:
2862
diff
changeset
|
550 #endif /* !Py_REF_DEBUG */ |
| 6 | 551 |
| 86 | 552 /* Macros to use in case the object pointer may be NULL: */ |
| 553 | |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
554 #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
|
555 #define Py_XDECREF(op) if ((op) == NULL) ; else Py_DECREF(op) |
| 6 | 556 |
| 557 /* | |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
558 _Py_NoneStruct is an object of undefined type which can be used in contexts |
| 6 | 559 where NULL (nil) is not suitable (since NULL often means 'error'). |
| 560 | |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
561 Don't forget to apply Py_INCREF() when returning this value!!! |
| 6 | 562 */ |
| 563 | |
|
2669
34eefa226709
DL_IMPORT needs an argument.
Sjoerd Mullender <sjoerd@acm.org>
parents:
2664
diff
changeset
|
564 extern DL_IMPORT(PyObject) _Py_NoneStruct; /* Don't use this directly */ |
| 6 | 565 |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
566 #define Py_None (&_Py_NoneStruct) |
| 6 | 567 |
|
15716
362e53f43dd2
- Add nb_cmp slot for new style nubmers.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14497
diff
changeset
|
568 /* |
|
362e53f43dd2
- Add nb_cmp slot for new style nubmers.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14497
diff
changeset
|
569 Py_NotImplemented is a singleton used to signal that an operation is |
|
362e53f43dd2
- Add nb_cmp slot for new style nubmers.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14497
diff
changeset
|
570 not implemented for a given type combination. |
|
362e53f43dd2
- Add nb_cmp slot for new style nubmers.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14497
diff
changeset
|
571 */ |
|
362e53f43dd2
- Add nb_cmp slot for new style nubmers.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14497
diff
changeset
|
572 |
|
362e53f43dd2
- Add nb_cmp slot for new style nubmers.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14497
diff
changeset
|
573 extern DL_IMPORT(PyObject) _Py_NotImplementedStruct; /* Don't use this directly */ |
|
362e53f43dd2
- Add nb_cmp slot for new style nubmers.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14497
diff
changeset
|
574 |
|
362e53f43dd2
- Add nb_cmp slot for new style nubmers.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
14497
diff
changeset
|
575 #define Py_NotImplemented (&_Py_NotImplementedStruct) |
| 6 | 576 |
|
15938
8fd221aed357
Introduction to rich comparisons:
Guido van Rossum <guido@python.org>
parents:
15716
diff
changeset
|
577 /* Rich comparison opcodes */ |
|
8fd221aed357
Introduction to rich comparisons:
Guido van Rossum <guido@python.org>
parents:
15716
diff
changeset
|
578 #define Py_LT 0 |
|
8fd221aed357
Introduction to rich comparisons:
Guido van Rossum <guido@python.org>
parents:
15716
diff
changeset
|
579 #define Py_LE 1 |
|
8fd221aed357
Introduction to rich comparisons:
Guido van Rossum <guido@python.org>
parents:
15716
diff
changeset
|
580 #define Py_EQ 2 |
|
8fd221aed357
Introduction to rich comparisons:
Guido van Rossum <guido@python.org>
parents:
15716
diff
changeset
|
581 #define Py_NE 3 |
|
8fd221aed357
Introduction to rich comparisons:
Guido van Rossum <guido@python.org>
parents:
15716
diff
changeset
|
582 #define Py_GT 4 |
|
8fd221aed357
Introduction to rich comparisons:
Guido van Rossum <guido@python.org>
parents:
15716
diff
changeset
|
583 #define Py_GE 5 |
|
8fd221aed357
Introduction to rich comparisons:
Guido van Rossum <guido@python.org>
parents:
15716
diff
changeset
|
584 |
| 6 | 585 /* |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
586 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
|
587 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
|
588 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
|
589 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
|
590 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
|
591 (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
|
592 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
|
593 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
|
594 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
|
595 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
|
596 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
|
597 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
|
598 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
|
599 */ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
600 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
601 #ifdef BAD_STATIC_FORWARD |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
602 #define staticforward extern |
|
2422
f4f71ebea53f
change in staticforward -- added statichere
Guido van Rossum <guido@python.org>
parents:
2364
diff
changeset
|
603 #define statichere static |
|
f4f71ebea53f
change in staticforward -- added statichere
Guido van Rossum <guido@python.org>
parents:
2364
diff
changeset
|
604 #else /* !BAD_STATIC_FORWARD */ |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
605 #define staticforward static |
|
2422
f4f71ebea53f
change in staticforward -- added statichere
Guido van Rossum <guido@python.org>
parents:
2364
diff
changeset
|
606 #define statichere static |
|
f4f71ebea53f
change in staticforward -- added statichere
Guido van Rossum <guido@python.org>
parents:
2364
diff
changeset
|
607 #endif /* !BAD_STATIC_FORWARD */ |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
608 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
609 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
610 /* |
| 6 | 611 More conventions |
| 612 ================ | |
| 613 | |
| 614 Argument Checking | |
| 615 ----------------- | |
| 616 | |
| 617 Functions that take objects as arguments normally don't check for nil | |
| 618 arguments, but they do check the type of the argument, and return an | |
| 619 error if the function doesn't apply to the type. | |
| 620 | |
| 621 Failure Modes | |
| 622 ------------- | |
| 623 | |
| 624 Functions may fail for a variety of reasons, including running out of | |
| 86 | 625 memory. This is communicated to the caller in two ways: an error string |
| 626 is set (see errors.h), and the function result differs: functions that | |
| 627 normally return a pointer return NULL for failure, functions returning | |
| 628 an integer return -1 (which could be a legal return value too!), and | |
| 629 other functions return 0 for success and -1 for failure. | |
| 630 Callers should always check for errors before using the result. | |
| 6 | 631 |
| 632 Reference Counts | |
| 633 ---------------- | |
| 634 | |
| 635 It takes a while to get used to the proper usage of reference counts. | |
| 636 | |
| 637 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
|
638 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
|
639 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
|
640 PyDict_SetItemString() |
| 6 | 641 don't increment the reference count of the object, since the most |
| 642 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
|
643 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
|
644 don't increment |
| 6 | 645 the reference count, since most frequently the object is only looked at |
| 646 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
|
647 must call Py_INCREF() explicitly. |
| 6 | 648 |
|
2129
05360cd616ae
The great renaming, phase two: all header files have been updated to
Guido van Rossum <guido@python.org>
parents:
2071
diff
changeset
|
649 NOTE: functions that 'consume' a reference count like |
|
6244
5ab21d1b61d8
Fix in trailing comment: PyDict_SetItemString() does *not* consume a reference
Fred Drake <fdrake@acm.org>
parents:
5943
diff
changeset
|
650 PyList_SetItemString() even consume the reference if the object wasn't |
|
5ab21d1b61d8
Fix in trailing comment: PyDict_SetItemString() does *not* consume a reference
Fred Drake <fdrake@acm.org>
parents:
5943
diff
changeset
|
651 stored, to simplify error handling. |
| 6 | 652 |
| 653 It seems attractive to make other functions that take an object as | |
| 654 argument consume a reference count; however this may quickly get | |
| 655 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
|
656 it carefully, it may save lots of calls to Py_INCREF() and Py_DECREF() at |
| 6 | 657 times. |
| 658 */ | |
|
1329
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1324
diff
changeset
|
659 |
|
11999
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11891
diff
changeset
|
660 /* |
|
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11891
diff
changeset
|
661 trashcan |
|
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11891
diff
changeset
|
662 CT 2k0130 |
|
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11891
diff
changeset
|
663 non-recursively destroy nested objects |
|
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11891
diff
changeset
|
664 |
|
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11891
diff
changeset
|
665 CT 2k0223 |
|
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11891
diff
changeset
|
666 redefinition for better locality and less overhead. |
|
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11891
diff
changeset
|
667 |
|
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11891
diff
changeset
|
668 Objects that want to be recursion safe need to use |
|
13620
5b727ab37092
Spelling fixes supplied by Rob W. W. Hooft. All these are fixes in either
Thomas Wouters <thomas@python.org>
parents:
13464
diff
changeset
|
669 the macro's |
|
11999
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11891
diff
changeset
|
670 Py_TRASHCAN_SAFE_BEGIN(name) |
|
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11891
diff
changeset
|
671 and |
|
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11891
diff
changeset
|
672 Py_TRASHCAN_SAFE_END(name) |
|
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11891
diff
changeset
|
673 surrounding their actual deallocation code. |
|
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11891
diff
changeset
|
674 |
|
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11891
diff
changeset
|
675 It would be nice to do this using the thread state. |
|
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11891
diff
changeset
|
676 Also, we could do an exact stack measure then. |
|
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11891
diff
changeset
|
677 Unfortunately, deallocations also take place when |
|
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11891
diff
changeset
|
678 the thread state is undefined. |
|
12481
a8898a172fe2
Christian Tismer -- total rewrite on trashcan code.
Guido van Rossum <guido@python.org>
parents:
12406
diff
changeset
|
679 |
|
a8898a172fe2
Christian Tismer -- total rewrite on trashcan code.
Guido van Rossum <guido@python.org>
parents:
12406
diff
changeset
|
680 CT 2k0422 complete rewrite. |
|
a8898a172fe2
Christian Tismer -- total rewrite on trashcan code.
Guido van Rossum <guido@python.org>
parents:
12406
diff
changeset
|
681 There is no need to allocate new objects. |
|
a8898a172fe2
Christian Tismer -- total rewrite on trashcan code.
Guido van Rossum <guido@python.org>
parents:
12406
diff
changeset
|
682 Everything is done vialob_refcnt and ob_type now. |
|
a8898a172fe2
Christian Tismer -- total rewrite on trashcan code.
Guido van Rossum <guido@python.org>
parents:
12406
diff
changeset
|
683 Adding support for free-threading should be easy, too. |
|
11999
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11891
diff
changeset
|
684 */ |
|
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11891
diff
changeset
|
685 |
|
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11891
diff
changeset
|
686 #define PyTrash_UNWIND_LEVEL 50 |
|
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11891
diff
changeset
|
687 |
|
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11891
diff
changeset
|
688 #define Py_TRASHCAN_SAFE_BEGIN(op) \ |
|
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11891
diff
changeset
|
689 { \ |
|
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11891
diff
changeset
|
690 ++_PyTrash_delete_nesting; \ |
|
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11891
diff
changeset
|
691 if (_PyTrash_delete_nesting < PyTrash_UNWIND_LEVEL) { \ |
|
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11891
diff
changeset
|
692 |
|
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11891
diff
changeset
|
693 #define Py_TRASHCAN_SAFE_END(op) \ |
|
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11891
diff
changeset
|
694 ;} \ |
|
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11891
diff
changeset
|
695 else \ |
|
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11891
diff
changeset
|
696 _PyTrash_deposit_object((PyObject*)op);\ |
|
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11891
diff
changeset
|
697 --_PyTrash_delete_nesting; \ |
|
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11891
diff
changeset
|
698 if (_PyTrash_delete_later && _PyTrash_delete_nesting <= 0) \ |
|
12481
a8898a172fe2
Christian Tismer -- total rewrite on trashcan code.
Guido van Rossum <guido@python.org>
parents:
12406
diff
changeset
|
699 _PyTrash_destroy_chain(); \ |
|
11999
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11891
diff
changeset
|
700 } \ |
|
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11891
diff
changeset
|
701 |
|
13418
85520c220067
Got RID of redundant coercions in longobject.c (as spotted by Greg
Tim Peters <tim.peters@gmail.com>
parents:
13256
diff
changeset
|
702 extern DL_IMPORT(void) _PyTrash_deposit_object(PyObject*); |
|
13419
db9392a04bed
One of the new prototypes was missing the "void" args.
Greg Stein <gstein@lyra.org>
parents:
13418
diff
changeset
|
703 extern DL_IMPORT(void) _PyTrash_destroy_chain(void); |
|
11999
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11891
diff
changeset
|
704 |
|
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11891
diff
changeset
|
705 extern DL_IMPORT(int) _PyTrash_delete_nesting; |
|
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11891
diff
changeset
|
706 extern DL_IMPORT(PyObject *) _PyTrash_delete_later; |
|
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11891
diff
changeset
|
707 |
|
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11891
diff
changeset
|
708 /* swap the "xx" to check the speed loss */ |
|
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11891
diff
changeset
|
709 |
|
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11891
diff
changeset
|
710 #define xxPy_TRASHCAN_SAFE_BEGIN(op) |
|
c94247b5c355
Christian Tismer's "trashcan" patch:
Guido van Rossum <guido@python.org>
parents:
11891
diff
changeset
|
711 #define xxPy_TRASHCAN_SAFE_END(op) ; |
|
12481
a8898a172fe2
Christian Tismer -- total rewrite on trashcan code.
Guido van Rossum <guido@python.org>
parents:
12406
diff
changeset
|
712 |
|
1329
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1324
diff
changeset
|
713 #ifdef __cplusplus |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1324
diff
changeset
|
714 } |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1324
diff
changeset
|
715 #endif |
|
519c25039c6a
* Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents:
1324
diff
changeset
|
716 #endif /* !Py_OBJECT_H */ |
