annotate cos/python/Include/object.h @ 104:ed230e947dc6

Added hexviewer
author windel
date Sun, 30 Dec 2012 22:31:55 +0100
parents 7f74363f4c82
children
rev   line source
27
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
1 #ifndef Py_OBJECT_H
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
2 #define Py_OBJECT_H
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
3
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
4 /* Object and type object interface */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
5
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
6 /*
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
7 Objects are structures allocated on the heap. Special rules apply to
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
8 the use of objects to ensure they are properly garbage-collected.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
9 Objects are never allocated statically or on the stack; they must be
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
10 accessed through special macros and functions only. (Type objects are
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
11 exceptions to the first rule; the standard types are represented by
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
12 statically initialized type objects, although work on type/class unification
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
13 for Python 2.2 made it possible to have heap-allocated type objects too).
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
14
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
15 An object has a 'reference count' that is increased or decreased when a
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
16 pointer to the object is copied or deleted; when the reference count
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
17 reaches zero there are no references to the object left and it can be
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
18 removed from the heap.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
19
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
20 An object has a 'type' that determines what it represents and what kind
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
21 of data it contains. An object's type is fixed when it is created.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
22 Types themselves are represented as objects; an object contains a
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
23 pointer to the corresponding type object. The type itself has a type
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
24 pointer pointing to the object representing the type 'type', which
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
25 contains a pointer to itself!).
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
26
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
27 Objects do not float around in memory; once allocated an object keeps
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
28 the same size and address. Objects that must hold variable-size data
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
29 can contain pointers to variable-size parts of the object. Not all
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
30 objects of the same type have the same size; but the size cannot change
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
31 after allocation. (These restrictions are made so a reference to an
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
32 object can be simply a pointer -- moving an object would require
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
33 updating all the pointers, and changing an object's size would require
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
34 moving it if there was another object right next to it.)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
35
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
36 Objects are always accessed through pointers of the type 'PyObject *'.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
37 The type 'PyObject' is a structure that only contains the reference count
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
38 and the type pointer. The actual memory allocated for an object
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
39 contains other data that can only be accessed after casting the pointer
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
40 to a pointer to a longer structure type. This longer type must start
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
41 with the reference count and type fields; the macro PyObject_HEAD should be
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
42 used for this (to accommodate for future changes). The implementation
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
43 of a particular object type can cast the object pointer to the proper
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
44 type and back.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
45
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
46 A standard interface exists for objects that contain an array of items
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
47 whose size is determined when the object is allocated.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
48 */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
49
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
50 /* PyObject_HEAD defines the initial segment of every PyObject. */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
51 #define PyObject_HEAD PyObject ob_base;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
52
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
53 #define PyObject_HEAD_INIT(type) { 1, type },
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
54
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
55 #define PyVarObject_HEAD_INIT(type, size) \
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
56 { PyObject_HEAD_INIT(type) size },
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
57
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
58 /* PyObject_VAR_HEAD defines the initial segment of all variable-size
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
59 * container objects. These end with a declaration of an array with 1
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
60 * element, but enough space is malloc'ed so that the array actually
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
61 * has room for ob_size elements. Note that ob_size is an element count,
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
62 * not necessarily a byte count.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
63 */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
64 #define PyObject_VAR_HEAD PyVarObject ob_base;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
65 #define Py_INVALID_SIZE (Py_ssize_t)-1
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
66
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
67 /* Nothing is actually declared to be a PyObject, but every pointer to
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
68 * a Python object can be cast to a PyObject*. This is inheritance built
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
69 * by hand. Similarly every pointer to a variable-size Python object can,
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
70 * in addition, be cast to PyVarObject*.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
71 */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
72 typedef struct _object {
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
73 int ob_refcnt;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
74 struct _typeobject *ob_type;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
75 } PyObject;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
76
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
77 typedef struct {
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
78 PyObject ob_base;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
79 int ob_size; /* Number of items in variable part */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
80 } PyVarObject;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
81
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
82 #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
83 #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
84 #define Py_SIZE(ob) (((PyVarObject*)(ob))->ob_size)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
85
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
86 /*
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
87 Type objects contain a string containing the type name (to help somewhat
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
88 in debugging), the allocation parameters (see PyObject_New() and
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
89 PyObject_NewVar()),
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
90 and methods for accessing objects of the type. Methods are optional, a
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
91 nil pointer meaning that particular kind of access is not available for
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
92 this type. The Py_DECREF() macro uses the tp_dealloc method without
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
93 checking for a nil pointer; it should always be implemented except if
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
94 the implementation can guarantee that the reference count will never
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
95 reach zero (e.g., for statically allocated type objects).
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
96
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
97 NB: the methods for certain type groups are now contained in separate
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
98 method blocks.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
99 */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
100
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
101 typedef PyObject * (*unaryfunc)(PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
102 typedef PyObject * (*binaryfunc)(PyObject *, PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
103 typedef PyObject * (*ternaryfunc)(PyObject *, PyObject *, PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
104 typedef int (*inquiry)(PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
105 typedef int (*lenfunc)(PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
106 typedef PyObject *(*ssizeargfunc)(PyObject *, int);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
107 typedef PyObject *(*ssizessizeargfunc)(PyObject *, int, int);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
108 typedef int(*ssizeobjargproc)(PyObject *, int, PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
109 typedef int(*ssizessizeobjargproc)(PyObject *, int, int, PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
110 typedef int(*objobjargproc)(PyObject *, PyObject *, PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
111
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
112 /* buffer interface */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
113 typedef struct bufferinfo {
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
114 void *buf;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
115 PyObject *obj; /* owned reference */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
116 Py_ssize_t len;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
117 Py_ssize_t itemsize; /* This is Py_ssize_t so it can be
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
118 pointed to by strides in simple case.*/
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
119 int readonly;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
120 int ndim;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
121 char *format;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
122 Py_ssize_t *shape;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
123 Py_ssize_t *strides;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
124 Py_ssize_t *suboffsets;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
125 Py_ssize_t smalltable[2]; /* static store for shape and strides of
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
126 mono-dimensional buffers. */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
127 void *internal;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
128 } Py_buffer;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
129
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
130 typedef int (*getbufferproc)(PyObject *, Py_buffer *, int);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
131 typedef void (*releasebufferproc)(PyObject *, Py_buffer *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
132
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
133 /* Flags for getting buffers */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
134 #define PyBUF_SIMPLE 0
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
135 #define PyBUF_WRITABLE 0x0001
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
136 /* we used to include an E, backwards compatible alias */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
137 #define PyBUF_WRITEABLE PyBUF_WRITABLE
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
138 #define PyBUF_FORMAT 0x0004
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
139 #define PyBUF_ND 0x0008
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
140 #define PyBUF_STRIDES (0x0010 | PyBUF_ND)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
141 #define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
142 #define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
143 #define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
144 #define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
145
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
146 #define PyBUF_CONTIG (PyBUF_ND | PyBUF_WRITABLE)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
147 #define PyBUF_CONTIG_RO (PyBUF_ND)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
148
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
149 #define PyBUF_STRIDED (PyBUF_STRIDES | PyBUF_WRITABLE)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
150 #define PyBUF_STRIDED_RO (PyBUF_STRIDES)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
151
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
152 #define PyBUF_RECORDS (PyBUF_STRIDES | PyBUF_WRITABLE | PyBUF_FORMAT)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
153 #define PyBUF_RECORDS_RO (PyBUF_STRIDES | PyBUF_FORMAT)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
154
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
155 #define PyBUF_FULL (PyBUF_INDIRECT | PyBUF_WRITABLE | PyBUF_FORMAT)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
156 #define PyBUF_FULL_RO (PyBUF_INDIRECT | PyBUF_FORMAT)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
157
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
158
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
159 #define PyBUF_READ 0x100
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
160 #define PyBUF_WRITE 0x200
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
161
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
162 /* End buffer interface */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
163
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
164 typedef int (*objobjproc)(PyObject *, PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
165 typedef int (*visitproc)(PyObject *, void *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
166 typedef int (*traverseproc)(PyObject *, visitproc, void *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
167
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
168 typedef struct {
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
169 /* Number implementations must check *both*
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
170 arguments for proper type and implement the necessary conversions
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
171 in the slot functions themselves. */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
172
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
173 binaryfunc nb_add;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
174 binaryfunc nb_subtract;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
175 binaryfunc nb_multiply;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
176 binaryfunc nb_remainder;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
177 binaryfunc nb_divmod;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
178 ternaryfunc nb_power;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
179 unaryfunc nb_negative;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
180 unaryfunc nb_positive;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
181 unaryfunc nb_absolute;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
182 inquiry nb_bool;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
183 unaryfunc nb_invert;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
184 binaryfunc nb_lshift;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
185 binaryfunc nb_rshift;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
186 binaryfunc nb_and;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
187 binaryfunc nb_xor;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
188 binaryfunc nb_or;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
189 unaryfunc nb_int;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
190 void *nb_reserved; /* the slot formerly known as nb_long */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
191 unaryfunc nb_float;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
192
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
193 binaryfunc nb_inplace_add;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
194 binaryfunc nb_inplace_subtract;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
195 binaryfunc nb_inplace_multiply;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
196 binaryfunc nb_inplace_remainder;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
197 ternaryfunc nb_inplace_power;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
198 binaryfunc nb_inplace_lshift;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
199 binaryfunc nb_inplace_rshift;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
200 binaryfunc nb_inplace_and;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
201 binaryfunc nb_inplace_xor;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
202 binaryfunc nb_inplace_or;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
203
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
204 binaryfunc nb_floor_divide;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
205 binaryfunc nb_true_divide;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
206 binaryfunc nb_inplace_floor_divide;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
207 binaryfunc nb_inplace_true_divide;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
208
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
209 unaryfunc nb_index;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
210 } PyNumberMethods;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
211
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
212 typedef struct {
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
213 lenfunc sq_length;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
214 binaryfunc sq_concat;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
215 ssizeargfunc sq_repeat;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
216 ssizeargfunc sq_item;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
217 void *was_sq_slice;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
218 ssizeobjargproc sq_ass_item;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
219 void *was_sq_ass_slice;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
220 objobjproc sq_contains;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
221
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
222 binaryfunc sq_inplace_concat;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
223 ssizeargfunc sq_inplace_repeat;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
224 } PySequenceMethods;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
225
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
226 typedef struct {
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
227 lenfunc mp_length;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
228 binaryfunc mp_subscript;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
229 objobjargproc mp_ass_subscript;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
230 } PyMappingMethods;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
231
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
232
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
233 typedef struct {
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
234 getbufferproc bf_getbuffer;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
235 releasebufferproc bf_releasebuffer;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
236 } PyBufferProcs;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
237
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
238 typedef void (*freefunc)(void *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
239 typedef void (*destructor)(PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
240 /* We can't provide a full compile-time check that limited-API
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
241 users won't implement tp_print. However, not defining printfunc
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
242 and making tp_print of a different function pointer type
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
243 should at least cause a warning in most cases. */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
244 typedef int (*printfunc)(PyObject *, FILE *, int);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
245 typedef PyObject *(*getattrfunc)(PyObject *, char *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
246 typedef PyObject *(*getattrofunc)(PyObject *, PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
247 typedef int (*setattrfunc)(PyObject *, char *, PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
248 typedef int (*setattrofunc)(PyObject *, PyObject *, PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
249 typedef PyObject *(*reprfunc)(PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
250 typedef Py_hash_t (*hashfunc)(PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
251 typedef PyObject *(*richcmpfunc) (PyObject *, PyObject *, int);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
252 typedef PyObject *(*getiterfunc) (PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
253 typedef PyObject *(*iternextfunc) (PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
254 typedef PyObject *(*descrgetfunc) (PyObject *, PyObject *, PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
255 typedef int (*descrsetfunc) (PyObject *, PyObject *, PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
256 typedef int (*initproc)(PyObject *, PyObject *, PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
257 typedef PyObject *(*newfunc)(struct _typeobject *, PyObject *, PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
258 typedef PyObject *(*allocfunc)(struct _typeobject *, int);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
259
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
260 typedef struct _typeobject PyTypeObject; /* opaque */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
261 typedef struct _typeobject {
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
262 PyObject_VAR_HEAD
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
263 const char *tp_name; /* For printing, in format "<module>.<name>" */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
264 int tp_basicsize, tp_itemsize; /* For allocation */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
265
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
266 /* Methods to implement standard operations */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
267
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
268 destructor tp_dealloc;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
269 printfunc tp_print;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
270 getattrfunc tp_getattr;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
271 setattrfunc tp_setattr;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
272 void *tp_reserved; /* formerly known as tp_compare */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
273 reprfunc tp_repr;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
274
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
275 /* Method suites for standard classes */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
276
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
277 PyNumberMethods *tp_as_number;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
278 PySequenceMethods *tp_as_sequence;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
279 PyMappingMethods *tp_as_mapping;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
280
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
281 /* More standard operations (here for binary compatibility) */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
282
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
283 hashfunc tp_hash;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
284 ternaryfunc tp_call;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
285 reprfunc tp_str;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
286 getattrofunc tp_getattro;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
287 setattrofunc tp_setattro;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
288
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
289 /* Functions to access object as input/output buffer */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
290 PyBufferProcs *tp_as_buffer;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
291
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
292 /* Flags to define presence of optional/expanded features */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
293 long tp_flags;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
294
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
295 const char *tp_doc; /* Documentation string */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
296
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
297 /* Assigned meaning in release 2.0 */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
298 /* call function for all accessible objects */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
299 traverseproc tp_traverse;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
300
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
301 /* delete references to contained objects */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
302 inquiry tp_clear;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
303
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
304 /* Assigned meaning in release 2.1 */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
305 /* rich comparisons */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
306 richcmpfunc tp_richcompare;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
307
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
308 /* weak reference enabler */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
309 Py_ssize_t tp_weaklistoffset;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
310
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
311 /* Iterators */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
312 getiterfunc tp_iter;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
313 iternextfunc tp_iternext;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
314
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
315 /* Attribute descriptor and subclassing stuff */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
316 struct PyMethodDef *tp_methods;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
317 struct PyMemberDef *tp_members;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
318 struct PyGetSetDef *tp_getset;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
319 struct _typeobject *tp_base;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
320 PyObject *tp_dict;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
321 descrgetfunc tp_descr_get;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
322 descrsetfunc tp_descr_set;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
323 Py_ssize_t tp_dictoffset;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
324 initproc tp_init;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
325 allocfunc tp_alloc;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
326 newfunc tp_new;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
327 freefunc tp_free; /* Low-level free-memory routine */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
328 inquiry tp_is_gc; /* For PyObject_IS_GC */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
329 PyObject *tp_bases;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
330 PyObject *tp_mro; /* method resolution order */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
331 PyObject *tp_cache;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
332 PyObject *tp_subclasses;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
333 PyObject *tp_weaklist;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
334 destructor tp_del;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
335
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
336 /* Type attribute cache version tag. Added in version 2.6 */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
337 unsigned int tp_version_tag;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
338
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
339 } PyTypeObject;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
340
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
341 typedef struct{
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
342 int slot; /* slot id, see below */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
343 void *pfunc; /* function pointer */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
344 } PyType_Slot;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
345
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
346 typedef struct{
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
347 const char* name;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
348 int basicsize;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
349 int itemsize;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
350 int flags;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
351 PyType_Slot *slots; /* terminated by slot==0. */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
352 } PyType_Spec;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
353
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
354 PyAPI_FUNC(PyObject*) PyType_FromSpec(PyType_Spec*);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
355
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
356 #ifndef Py_LIMITED_API
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
357 /* The *real* layout of a type object when allocated on the heap */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
358 typedef struct _heaptypeobject {
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
359 /* Note: there's a dependency on the order of these members
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
360 in slotptr() in typeobject.c . */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
361 PyTypeObject ht_type;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
362 PyNumberMethods as_number;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
363 PyMappingMethods as_mapping;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
364 PySequenceMethods as_sequence; /* as_sequence comes after as_mapping,
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
365 so that the mapping wins when both
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
366 the mapping and the sequence define
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
367 a given operator (e.g. __getitem__).
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
368 see add_operators() in typeobject.c . */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
369 PyBufferProcs as_buffer;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
370 PyObject *ht_name, *ht_slots, *ht_qualname;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
371 /* here are optional user slots, followed by the members. */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
372 } PyHeapTypeObject;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
373
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
374 /* access macro to the members which are floating "behind" the object */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
375 #define PyHeapType_GET_MEMBERS(etype) \
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
376 ((PyMemberDef *)(((char *)etype) + Py_TYPE(etype)->tp_basicsize))
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
377 #endif
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
378
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
379 /* Generic type check */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
380 PyAPI_FUNC(int) PyType_IsSubtype(PyTypeObject *, PyTypeObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
381 #define PyObject_TypeCheck(ob, tp) \
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
382 (Py_TYPE(ob) == (tp) || PyType_IsSubtype(Py_TYPE(ob), (tp)))
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
383
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
384 PyAPI_DATA(PyTypeObject) PyType_Type; /* built-in 'type' */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
385 PyAPI_DATA(PyTypeObject) PyBaseObject_Type; /* built-in 'object' */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
386 PyAPI_DATA(PyTypeObject) PySuper_Type; /* built-in 'super' */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
387
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
388 PyAPI_FUNC(long) PyType_GetFlags(PyTypeObject*);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
389
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
390 #define PyType_Check(op) \
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
391 PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_TYPE_SUBCLASS)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
392 #define PyType_CheckExact(op) (Py_TYPE(op) == &PyType_Type)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
393
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
394 PyAPI_FUNC(int) PyType_Ready(PyTypeObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
395 PyAPI_FUNC(PyObject *) PyType_GenericAlloc(PyTypeObject *, Py_ssize_t);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
396 PyAPI_FUNC(PyObject *) PyType_GenericNew(PyTypeObject *,
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
397 PyObject *, PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
398 #ifndef Py_LIMITED_API
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
399 PyAPI_FUNC(PyObject *) _PyType_Lookup(PyTypeObject *, PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
400 PyAPI_FUNC(PyObject *) _PyObject_LookupSpecial(PyObject *, char *, PyObject **);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
401 PyAPI_FUNC(PyTypeObject *) _PyType_CalculateMetaclass(PyTypeObject *, PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
402 #endif
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
403 PyAPI_FUNC(unsigned int) PyType_ClearCache(void);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
404 PyAPI_FUNC(void) PyType_Modified(PyTypeObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
405
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
406 /* Generic operations on objects */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
407 struct _Py_Identifier;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
408 #ifndef Py_LIMITED_API
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
409 PyAPI_FUNC(int) PyObject_Print(PyObject *, FILE *, int);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
410 PyAPI_FUNC(void) _Py_BreakPoint(void);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
411 PyAPI_FUNC(void) _PyObject_Dump(PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
412 #endif
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
413 PyAPI_FUNC(PyObject *) PyObject_Repr(PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
414 PyAPI_FUNC(PyObject *) PyObject_Str(PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
415 PyAPI_FUNC(PyObject *) PyObject_ASCII(PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
416 PyAPI_FUNC(PyObject *) PyObject_Bytes(PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
417 PyAPI_FUNC(PyObject *) PyObject_RichCompare(PyObject *, PyObject *, int);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
418 PyAPI_FUNC(int) PyObject_RichCompareBool(PyObject *, PyObject *, int);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
419 PyAPI_FUNC(PyObject *) PyObject_GetAttrString(PyObject *, const char *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
420 PyAPI_FUNC(int) PyObject_SetAttrString(PyObject *, const char *, PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
421 PyAPI_FUNC(int) PyObject_HasAttrString(PyObject *, const char *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
422 PyAPI_FUNC(PyObject *) PyObject_GetAttr(PyObject *, PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
423 PyAPI_FUNC(int) PyObject_SetAttr(PyObject *, PyObject *, PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
424 PyAPI_FUNC(int) PyObject_HasAttr(PyObject *, PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
425 PyAPI_FUNC(PyObject *) _PyObject_GetAttrId(PyObject *, struct _Py_Identifier *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
426 PyAPI_FUNC(int) _PyObject_SetAttrId(PyObject *, struct _Py_Identifier *, PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
427 PyAPI_FUNC(int) _PyObject_HasAttrId(PyObject *, struct _Py_Identifier *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
428 #ifndef Py_LIMITED_API
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
429 PyAPI_FUNC(PyObject **) _PyObject_GetDictPtr(PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
430 #endif
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
431 PyAPI_FUNC(PyObject *) PyObject_SelfIter(PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
432 #ifndef Py_LIMITED_API
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
433 PyAPI_FUNC(PyObject *) _PyObject_NextNotImplemented(PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
434 #endif
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
435 PyAPI_FUNC(PyObject *) PyObject_GenericGetAttr(PyObject *, PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
436 PyAPI_FUNC(int) PyObject_GenericSetAttr(PyObject *,
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
437 PyObject *, PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
438 PyAPI_FUNC(Py_hash_t) PyObject_Hash(PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
439 PyAPI_FUNC(Py_hash_t) PyObject_HashNotImplemented(PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
440 PyAPI_FUNC(int) PyObject_IsTrue(PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
441 PyAPI_FUNC(int) PyObject_Not(PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
442 PyAPI_FUNC(int) PyCallable_Check(PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
443
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
444 PyAPI_FUNC(void) PyObject_ClearWeakRefs(PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
445
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
446 /* Same as PyObject_Generic{Get,Set}Attr, but passing the attributes
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
447 dict as the last parameter. */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
448 PyAPI_FUNC(PyObject *)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
449 _PyObject_GenericGetAttrWithDict(PyObject *, PyObject *, PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
450 PyAPI_FUNC(int)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
451 _PyObject_GenericSetAttrWithDict(PyObject *, PyObject *,
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
452 PyObject *, PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
453
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
454
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
455 /* PyObject_Dir(obj) acts like Python builtins.dir(obj), returning a
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
456 list of strings. PyObject_Dir(NULL) is like builtins.dir(),
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
457 returning the names of the current locals. In this case, if there are
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
458 no current locals, NULL is returned, and PyErr_Occurred() is false.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
459 */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
460 PyAPI_FUNC(PyObject *) PyObject_Dir(PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
461
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
462
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
463 /* Helpers for printing recursive container types */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
464 PyAPI_FUNC(int) Py_ReprEnter(PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
465 PyAPI_FUNC(void) Py_ReprLeave(PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
466
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
467 /* Helpers for hash functions */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
468 PyAPI_FUNC(Py_hash_t) _Py_HashDouble(double);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
469 PyAPI_FUNC(Py_hash_t) _Py_HashPointer(void*);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
470 PyAPI_FUNC(Py_hash_t) _Py_HashBytes(unsigned char*, Py_ssize_t);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
471
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
472 /* Helper for passing objects to printf and the like */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
473 #define PyObject_REPR(obj) _PyUnicode_AsString(PyObject_Repr(obj))
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
474
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
475 /* Flag bits for printing: */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
476 #define Py_PRINT_RAW 1 /* No string quotes etc. */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
477
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
478 /*
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
479 `Type flags (tp_flags)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
480
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
481 These flags are used to extend the type structure in a backwards-compatible
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
482 fashion. Extensions can use the flags to indicate (and test) when a given
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
483 type structure contains a new feature. The Python core will use these when
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
484 introducing new functionality between major revisions (to avoid mid-version
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
485 changes in the PYTHON_API_VERSION).
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
486
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
487 Arbitration of the flag bit positions will need to be coordinated among
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
488 all extension writers who publically release their extensions (this will
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
489 be fewer than you might expect!)..
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
490
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
491 Most flags were removed as of Python 3.0 to make room for new flags. (Some
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
492 flags are not for backwards compatibility but to indicate the presence of an
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
493 optional feature; these flags remain of course.)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
494
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
495 Type definitions should use Py_TPFLAGS_DEFAULT for their tp_flags value.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
496
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
497 Code can use PyType_HasFeature(type_ob, flag_value) to test whether the
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
498 given type object has a specified feature.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
499 */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
500
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
501 /* Set if the type object is dynamically allocated */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
502 #define Py_TPFLAGS_HEAPTYPE (1L<<9)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
503
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
504 /* Set if the type allows subclassing */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
505 #define Py_TPFLAGS_BASETYPE (1L<<10)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
506
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
507 /* Set if the type is 'ready' -- fully initialized */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
508 #define Py_TPFLAGS_READY (1L<<12)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
509
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
510 /* Set while the type is being 'readied', to prevent recursive ready calls */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
511 #define Py_TPFLAGS_READYING (1L<<13)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
512
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
513 /* Objects support garbage collection (see objimp.h) */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
514 #define Py_TPFLAGS_HAVE_GC (1L<<14)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
515
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
516 /* These two bits are preserved for Stackless Python, next after this is 17 */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
517 #ifdef STACKLESS
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
518 #define Py_TPFLAGS_HAVE_STACKLESS_EXTENSION (3L<<15)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
519 #else
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
520 #define Py_TPFLAGS_HAVE_STACKLESS_EXTENSION 0
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
521 #endif
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
522
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
523 /* Objects support type attribute cache */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
524 #define Py_TPFLAGS_HAVE_VERSION_TAG (1L<<18)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
525 #define Py_TPFLAGS_VALID_VERSION_TAG (1L<<19)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
526
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
527 /* Type is abstract and cannot be instantiated */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
528 #define Py_TPFLAGS_IS_ABSTRACT (1L<<20)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
529
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
530 /* These flags are used to determine if a type is a subclass. */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
531 #define Py_TPFLAGS_INT_SUBCLASS (1L<<23)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
532 #define Py_TPFLAGS_LONG_SUBCLASS (1L<<24)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
533 #define Py_TPFLAGS_LIST_SUBCLASS (1L<<25)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
534 #define Py_TPFLAGS_TUPLE_SUBCLASS (1L<<26)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
535 #define Py_TPFLAGS_BYTES_SUBCLASS (1L<<27)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
536 #define Py_TPFLAGS_UNICODE_SUBCLASS (1L<<28)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
537 #define Py_TPFLAGS_DICT_SUBCLASS (1L<<29)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
538 #define Py_TPFLAGS_BASE_EXC_SUBCLASS (1L<<30)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
539 #define Py_TPFLAGS_TYPE_SUBCLASS (1L<<31)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
540
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
541 #define Py_TPFLAGS_DEFAULT ( \
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
542 Py_TPFLAGS_HAVE_STACKLESS_EXTENSION | \
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
543 Py_TPFLAGS_HAVE_VERSION_TAG | \
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
544 0)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
545
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
546 #ifdef Py_LIMITED_API
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
547 #define PyType_HasFeature(t,f) ((PyType_GetFlags(t) & (f)) != 0)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
548 #else
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
549 #define PyType_HasFeature(t,f) (((t)->tp_flags & (f)) != 0)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
550 #endif
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
551 #define PyType_FastSubclass(t,f) PyType_HasFeature(t,f)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
552
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
553
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
554 /*
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
555 The macros Py_INCREF(op) and Py_DECREF(op) are used to increment or decrement
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
556 reference counts. Py_DECREF calls the object's deallocator function when
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
557 the refcount falls to 0; for
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
558 objects that don't contain references to other objects or heap memory
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
559 this can be the standard function free(). Both macros can be used
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
560 wherever a void expression is allowed. The argument must not be a
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
561 NULL pointer. If it may be NULL, use Py_XINCREF/Py_XDECREF instead.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
562 The macro _Py_NewReference(op) initialize reference counts to 1, and
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
563 in special builds (Py_REF_DEBUG, Py_TRACE_REFS) performs additional
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
564 bookkeeping appropriate to the special build.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
565
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
566 We assume that the reference count field can never overflow; this can
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
567 be proven when the size of the field is the same as the pointer size, so
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
568 we ignore the possibility. Provided a C int is at least 32 bits (which
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
569 is implicitly assumed in many parts of this code), that's enough for
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
570 about 2**31 references to an object.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
571
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
572 XXX The following became out of date in Python 2.2, but I'm not sure
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
573 XXX what the full truth is now. Certainly, heap-allocated type objects
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
574 XXX can and should be deallocated.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
575 Type objects should never be deallocated; the type pointer in an object
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
576 is not considered to be a reference to the type object, to save
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
577 complications in the deallocation function. (This is actually a
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
578 decision that's up to the implementer of each new type so if you want,
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
579 you can count such references to the type object.)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
580
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
581 *** WARNING*** The Py_DECREF macro must have a side-effect-free argument
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
582 since it may evaluate its argument multiple times. (The alternative
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
583 would be to mace it a proper function or assign it to a global temporary
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
584 variable first, both of which are slower; and in a multi-threaded
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
585 environment the global variable trick is not safe.)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
586 */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
587
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
588 /* First define a pile of simple helper macros, one set per special
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
589 * build symbol. These either expand to the obvious things, or to
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
590 * nothing at all when the special mode isn't in effect. The main
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
591 * macros can later be defined just once then, yet expand to different
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
592 * things depending on which special build options are and aren't in effect.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
593 * Trust me <wink>: while painful, this is 20x easier to understand than,
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
594 * e.g, defining _Py_NewReference five different times in a maze of nested
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
595 * #ifdefs (we used to do that -- it was impenetrable).
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
596 */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
597 #define _Py_INC_REFTOTAL
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
598 #define _Py_DEC_REFTOTAL
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
599 #define _Py_REF_DEBUG_COMMA
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
600 #define _Py_CHECK_REFCNT(OP) /* a semicolon */;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
601
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
602 #define _Py_INC_TPALLOCS(OP)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
603 #define _Py_INC_TPFREES(OP)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
604 #define _Py_DEC_TPFREES(OP)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
605 #define _Py_COUNT_ALLOCS_COMMA
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
606
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
607 /* Without Py_TRACE_REFS, there's little enough to do that we expand code
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
608 * inline.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
609 */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
610 #define _Py_NewReference(op) ( \
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
611 _Py_INC_TPALLOCS(op) \
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
612 _Py_INC_REFTOTAL \
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
613 Py_REFCNT(op) = 1)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
614
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
615 #define _Py_ForgetReference(op) _Py_INC_TPFREES(op)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
616
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
617 #define _Py_Dealloc(op) ( \
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
618 _Py_INC_TPFREES(op) _Py_COUNT_ALLOCS_COMMA \
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
619 (*Py_TYPE(op)->tp_dealloc)((PyObject *)(op)))
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
620
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
621 #define Py_INCREF(op) ( \
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
622 _Py_INC_REFTOTAL \
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
623 ((PyObject*)(op))->ob_refcnt++)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
624
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
625 #define Py_DECREF(op) \
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
626 do { \
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
627 if (_Py_DEC_REFTOTAL _Py_REF_DEBUG_COMMA \
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
628 --((PyObject*)(op))->ob_refcnt != 0) \
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
629 _Py_CHECK_REFCNT(op) \
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
630 else \
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
631 _Py_Dealloc((PyObject *)(op)); \
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
632 } while (0)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
633
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
634 /* Safely decref `op` and set `op` to NULL, especially useful in tp_clear
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
635 * and tp_dealloc implementatons.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
636 *
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
637 * Note that "the obvious" code can be deadly:
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
638 *
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
639 * Py_XDECREF(op);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
640 * op = NULL;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
641 *
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
642 * Typically, `op` is something like self->containee, and `self` is done
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
643 * using its `containee` member. In the code sequence above, suppose
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
644 * `containee` is non-NULL with a refcount of 1. Its refcount falls to
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
645 * 0 on the first line, which can trigger an arbitrary amount of code,
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
646 * possibly including finalizers (like __del__ methods or weakref callbacks)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
647 * coded in Python, which in turn can release the GIL and allow other threads
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
648 * to run, etc. Such code may even invoke methods of `self` again, or cause
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
649 * cyclic gc to trigger, but-- oops! --self->containee still points to the
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
650 * object being torn down, and it may be in an insane state while being torn
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
651 * down. This has in fact been a rich historic source of miserable (rare &
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
652 * hard-to-diagnose) segfaulting (and other) bugs.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
653 *
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
654 * The safe way is:
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
655 *
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
656 * Py_CLEAR(op);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
657 *
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
658 * That arranges to set `op` to NULL _before_ decref'ing, so that any code
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
659 * triggered as a side-effect of `op` getting torn down no longer believes
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
660 * `op` points to a valid object.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
661 *
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
662 * There are cases where it's safe to use the naive code, but they're brittle.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
663 * For example, if `op` points to a Python integer, you know that destroying
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
664 * one of those can't cause problems -- but in part that relies on that
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
665 * Python integers aren't currently weakly referencable. Best practice is
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
666 * to use Py_CLEAR() even if you can't think of a reason for why you need to.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
667 */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
668 #define Py_CLEAR(op) \
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
669 do { \
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
670 if (op) { \
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
671 PyObject *_py_tmp = (PyObject *)(op); \
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
672 (op) = NULL; \
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
673 Py_DECREF(_py_tmp); \
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
674 } \
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
675 } while (0)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
676
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
677 /* Macros to use in case the object pointer may be NULL: */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
678 #define Py_XINCREF(op) do { if ((op) == NULL) ; else Py_INCREF(op); } while (0)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
679 #define Py_XDECREF(op) do { if ((op) == NULL) ; else Py_DECREF(op); } while (0)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
680
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
681 /*
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
682 These are provided as conveniences to Python runtime embedders, so that
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
683 they can have object code that is not dependent on Python compilation flags.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
684 */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
685 PyAPI_FUNC(void) Py_IncRef(PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
686 PyAPI_FUNC(void) Py_DecRef(PyObject *);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
687
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
688 /*
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
689 _Py_NoneStruct is an object of undefined type which can be used in contexts
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
690 where NULL (nil) is not suitable (since NULL often means 'error').
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
691
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
692 Don't forget to apply Py_INCREF() when returning this value!!!
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
693 */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
694 PyAPI_DATA(PyObject) _Py_NoneStruct; /* Don't use this directly */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
695 #define Py_None (&_Py_NoneStruct)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
696
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
697 /* Macro for returning Py_None from a function */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
698 #define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
699
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
700 /*
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
701 Py_NotImplemented is a singleton used to signal that an operation is
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
702 not implemented for a given type combination.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
703 */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
704 PyAPI_DATA(PyObject) _Py_NotImplementedStruct; /* Don't use this directly */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
705 #define Py_NotImplemented (&_Py_NotImplementedStruct)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
706
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
707 /* Macro for returning Py_NotImplemented from a function */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
708 #define Py_RETURN_NOTIMPLEMENTED \
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
709 return Py_INCREF(Py_NotImplemented), Py_NotImplemented
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
710
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
711 /* Rich comparison opcodes */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
712 #define Py_LT 0
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
713 #define Py_LE 1
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
714 #define Py_EQ 2
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
715 #define Py_NE 3
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
716 #define Py_GT 4
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
717 #define Py_GE 5
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
718
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
719 /* Maps Py_LT to Py_GT, ..., Py_GE to Py_LE.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
720 * Defined in object.c.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
721 */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
722 PyAPI_DATA(int) _Py_SwappedOp[];
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
723
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
724
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
725 /*
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
726 More conventions
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
727 ================
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
728
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
729 Argument Checking
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
730 -----------------
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
731
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
732 Functions that take objects as arguments normally don't check for nil
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
733 arguments, but they do check the type of the argument, and return an
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
734 error if the function doesn't apply to the type.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
735
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
736 Failure Modes
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
737 -------------
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
738
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
739 Functions may fail for a variety of reasons, including running out of
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
740 memory. This is communicated to the caller in two ways: an error string
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
741 is set (see errors.h), and the function result differs: functions that
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
742 normally return a pointer return NULL for failure, functions returning
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
743 an integer return -1 (which could be a legal return value too!), and
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
744 other functions return 0 for success and -1 for failure.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
745 Callers should always check for errors before using the result. If
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
746 an error was set, the caller must either explicitly clear it, or pass
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
747 the error on to its caller.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
748
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
749 Reference Counts
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
750 ----------------
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
751
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
752 It takes a while to get used to the proper usage of reference counts.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
753
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
754 Functions that create an object set the reference count to 1; such new
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
755 objects must be stored somewhere or destroyed again with Py_DECREF().
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
756 Some functions that 'store' objects, such as PyTuple_SetItem() and
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
757 PyList_SetItem(),
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
758 don't increment the reference count of the object, since the most
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
759 frequent use is to store a fresh object. Functions that 'retrieve'
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
760 objects, such as PyTuple_GetItem() and PyDict_GetItemString(), also
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
761 don't increment
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
762 the reference count, since most frequently the object is only looked at
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
763 quickly. Thus, to retrieve an object and store it again, the caller
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
764 must call Py_INCREF() explicitly.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
765
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
766 NOTE: functions that 'consume' a reference count, like
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
767 PyList_SetItem(), consume the reference even if the object wasn't
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
768 successfully stored, to simplify error handling.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
769
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
770 It seems attractive to make other functions that take an object as
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
771 argument consume a reference count; however, this may quickly get
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
772 confusing (even the current practice is already confusing). Consider
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
773 it carefully, it may save lots of calls to Py_INCREF() and Py_DECREF() at
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
774 times.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
775 */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
776
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
777
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
778 /* Trashcan mechanism, thanks to Christian Tismer.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
779
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
780 When deallocating a container object, it's possible to trigger an unbounded
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
781 chain of deallocations, as each Py_DECREF in turn drops the refcount on "the
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
782 next" object in the chain to 0. This can easily lead to stack faults, and
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
783 especially in threads (which typically have less stack space to work with).
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
784
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
785 A container object that participates in cyclic gc can avoid this by
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
786 bracketing the body of its tp_dealloc function with a pair of macros:
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
787
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
788 static void
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
789 mytype_dealloc(mytype *p)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
790 {
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
791 ... declarations go here ...
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
792
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
793 PyObject_GC_UnTrack(p); // must untrack first
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
794 Py_TRASHCAN_SAFE_BEGIN(p)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
795 ... The body of the deallocator goes here, including all calls ...
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
796 ... to Py_DECREF on contained objects. ...
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
797 Py_TRASHCAN_SAFE_END(p)
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
798 }
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
799
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
800 CAUTION: Never return from the middle of the body! If the body needs to
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
801 "get out early", put a label immediately before the Py_TRASHCAN_SAFE_END
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
802 call, and goto it. Else the call-depth counter (see below) will stay
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
803 above 0 forever, and the trashcan will never get emptied.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
804
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
805 How it works: The BEGIN macro increments a call-depth counter. So long
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
806 as this counter is small, the body of the deallocator is run directly without
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
807 further ado. But if the counter gets large, it instead adds p to a list of
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
808 objects to be deallocated later, skips the body of the deallocator, and
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
809 resumes execution after the END macro. The tp_dealloc routine then returns
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
810 without deallocating anything (and so unbounded call-stack depth is avoided).
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
811
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
812 When the call stack finishes unwinding again, code generated by the END macro
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
813 notices this, and calls another routine to deallocate all the objects that
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
814 may have been added to the list of deferred deallocations. In effect, a
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
815 chain of N deallocations is broken into N / PyTrash_UNWIND_LEVEL pieces,
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
816 with the call stack never exceeding a depth of PyTrash_UNWIND_LEVEL.
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
817 */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
818
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
819 PyAPI_FUNC(void) _PyTrash_deposit_object(PyObject*);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
820 PyAPI_FUNC(void) _PyTrash_destroy_chain(void);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
821 PyAPI_DATA(int) _PyTrash_delete_nesting;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
822 PyAPI_DATA(PyObject *) _PyTrash_delete_later;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
823
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
824 #define PyTrash_UNWIND_LEVEL 50
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
825
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
826 #define Py_TRASHCAN_SAFE_BEGIN(op) \
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
827 if (_PyTrash_delete_nesting < PyTrash_UNWIND_LEVEL) { \
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
828 ++_PyTrash_delete_nesting;
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
829 /* The body of the deallocator is here. */
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
830 #define Py_TRASHCAN_SAFE_END(op) \
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
831 --_PyTrash_delete_nesting; \
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
832 if (_PyTrash_delete_later && _PyTrash_delete_nesting <= 0) \
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
833 _PyTrash_destroy_chain(); \
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
834 } \
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
835 else \
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
836 _PyTrash_deposit_object((PyObject*)op);
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
837
7f74363f4c82 Added some files for the python port
windel
parents:
diff changeset
838 #endif /* !Py_OBJECT_H */