Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 1 | #ifndef Py_OBJECT_H |
| 2 | #define Py_OBJECT_H |
| 3 | #ifdef __cplusplus |
| 4 | extern "C" { |
| 5 | #endif |
| 6 | |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 7 | /*********************************************************** |
Guido van Rossum | fd71b9e | 2000-06-30 23:50:40 +0000 | [diff] [blame] | 8 | Copyright (c) 2000, BeOpen.com. |
| 9 | Copyright (c) 1995-2000, Corporation for National Research Initiatives. |
| 10 | Copyright (c) 1990-1995, Stichting Mathematisch Centrum. |
| 11 | All rights reserved. |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 12 | |
Guido van Rossum | fd71b9e | 2000-06-30 23:50:40 +0000 | [diff] [blame] | 13 | See the file "Misc/COPYRIGHT" for information on usage and |
| 14 | redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 15 | ******************************************************************/ |
| 16 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 17 | /* Object and type object interface */ |
| 18 | |
| 19 | /* |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 20 | Objects are structures allocated on the heap. Special rules apply to |
| 21 | the use of objects to ensure they are properly garbage-collected. |
| 22 | Objects are never allocated statically or on the stack; they must be |
| 23 | accessed through special macros and functions only. (Type objects are |
| 24 | exceptions to the first rule; the standard types are represented by |
| 25 | statically initialized type objects.) |
| 26 | |
| 27 | An object has a 'reference count' that is increased or decreased when a |
| 28 | pointer to the object is copied or deleted; when the reference count |
| 29 | reaches zero there are no references to the object left and it can be |
| 30 | removed from the heap. |
| 31 | |
| 32 | An object has a 'type' that determines what it represents and what kind |
| 33 | of data it contains. An object's type is fixed when it is created. |
| 34 | Types themselves are represented as objects; an object contains a |
| 35 | pointer to the corresponding type object. The type itself has a type |
| 36 | pointer pointing to the object representing the type 'type', which |
| 37 | contains a pointer to itself!). |
| 38 | |
| 39 | Objects do not float around in memory; once allocated an object keeps |
| 40 | the same size and address. Objects that must hold variable-size data |
| 41 | can contain pointers to variable-size parts of the object. Not all |
| 42 | objects of the same type have the same size; but the size cannot change |
| 43 | after allocation. (These restrictions are made so a reference to an |
| 44 | object can be simply a pointer -- moving an object would require |
| 45 | updating all the pointers, and changing an object's size would require |
| 46 | moving it if there was another object right next to it.) |
| 47 | |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 48 | Objects are always accessed through pointers of the type 'PyObject *'. |
| 49 | The type 'PyObject' is a structure that only contains the reference count |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 50 | and the type pointer. The actual memory allocated for an object |
| 51 | contains other data that can only be accessed after casting the pointer |
| 52 | to a pointer to a longer structure type. This longer type must start |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 53 | with the reference count and type fields; the macro PyObject_HEAD should be |
Thomas Wouters | 7e47402 | 2000-07-16 12:04:32 +0000 | [diff] [blame] | 54 | used for this (to accommodate for future changes). The implementation |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 55 | of a particular object type can cast the object pointer to the proper |
| 56 | type and back. |
| 57 | |
| 58 | A standard interface exists for objects that contain an array of items |
| 59 | whose size is determined when the object is allocated. |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 60 | */ |
| 61 | |
Guido van Rossum | 408027e | 1996-12-30 16:17:54 +0000 | [diff] [blame] | 62 | #ifdef Py_DEBUG |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 63 | |
| 64 | /* Turn on heavy reference debugging */ |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 65 | #define Py_TRACE_REFS |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 66 | |
| 67 | /* Turn on reference counting */ |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 68 | #define Py_REF_DEBUG |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 69 | |
Guido van Rossum | 408027e | 1996-12-30 16:17:54 +0000 | [diff] [blame] | 70 | #endif /* Py_DEBUG */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 71 | |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 72 | #ifdef Py_TRACE_REFS |
| 73 | #define PyObject_HEAD \ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 74 | struct _object *_ob_next, *_ob_prev; \ |
Guido van Rossum | c8564cd | 1990-11-02 17:51:56 +0000 | [diff] [blame] | 75 | int ob_refcnt; \ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 76 | struct _typeobject *ob_type; |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 77 | #define PyObject_HEAD_INIT(type) 0, 0, 1, type, |
Guido van Rossum | 60be1db | 1996-05-22 16:33:22 +0000 | [diff] [blame] | 78 | #else /* !Py_TRACE_REFS */ |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 79 | #define PyObject_HEAD \ |
Guido van Rossum | 5799b52 | 1995-01-04 19:06:22 +0000 | [diff] [blame] | 80 | int ob_refcnt; \ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 81 | struct _typeobject *ob_type; |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 82 | #define PyObject_HEAD_INIT(type) 1, type, |
Guido van Rossum | 60be1db | 1996-05-22 16:33:22 +0000 | [diff] [blame] | 83 | #endif /* !Py_TRACE_REFS */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 84 | |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 85 | #define PyObject_VAR_HEAD \ |
| 86 | PyObject_HEAD \ |
Guido van Rossum | 5799b52 | 1995-01-04 19:06:22 +0000 | [diff] [blame] | 87 | int ob_size; /* Number of items in variable part */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 88 | |
| 89 | typedef struct _object { |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 90 | PyObject_HEAD |
| 91 | } PyObject; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 92 | |
| 93 | typedef struct { |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 94 | PyObject_VAR_HEAD |
Guido van Rossum | d0c87ee | 1997-05-15 21:31:03 +0000 | [diff] [blame] | 95 | } PyVarObject; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 96 | |
| 97 | |
| 98 | /* |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 99 | Type objects contain a string containing the type name (to help somewhat |
| 100 | in debugging), the allocation parameters (see newobj() and newvarobj()), |
| 101 | and methods for accessing objects of the type. Methods are optional,a |
| 102 | nil pointer meaning that particular kind of access is not available for |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 103 | this type. The Py_DECREF() macro uses the tp_dealloc method without |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 104 | checking for a nil pointer; it should always be implemented except if |
| 105 | the implementation can guarantee that the reference count will never |
| 106 | reach zero (e.g., for type objects). |
| 107 | |
| 108 | NB: the methods for certain type groups are now contained in separate |
| 109 | method blocks. |
| 110 | */ |
| 111 | |
Tim Peters | 9ace6bc | 2000-07-08 00:32:04 +0000 | [diff] [blame] | 112 | typedef PyObject * (*unaryfunc)(PyObject *); |
| 113 | typedef PyObject * (*binaryfunc)(PyObject *, PyObject *); |
| 114 | typedef PyObject * (*ternaryfunc)(PyObject *, PyObject *, PyObject *); |
| 115 | typedef int (*inquiry)(PyObject *); |
| 116 | typedef int (*coercion)(PyObject **, PyObject **); |
| 117 | typedef PyObject *(*intargfunc)(PyObject *, int); |
| 118 | typedef PyObject *(*intintargfunc)(PyObject *, int, int); |
| 119 | typedef int(*intobjargproc)(PyObject *, int, PyObject *); |
| 120 | typedef int(*intintobjargproc)(PyObject *, int, int, PyObject *); |
| 121 | typedef int(*objobjargproc)(PyObject *, PyObject *, PyObject *); |
| 122 | typedef int (*getreadbufferproc)(PyObject *, int, void **); |
| 123 | typedef int (*getwritebufferproc)(PyObject *, int, void **); |
| 124 | typedef int (*getsegcountproc)(PyObject *, int *); |
| 125 | typedef int (*getcharbufferproc)(PyObject *, int, const char **); |
| 126 | typedef int (*objobjproc)(PyObject *, PyObject *); |
| 127 | typedef int (*visitproc)(PyObject *, void *); |
| 128 | typedef int (*traverseproc)(PyObject *, visitproc, void *); |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 129 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 130 | typedef struct { |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 131 | binaryfunc nb_add; |
| 132 | binaryfunc nb_subtract; |
| 133 | binaryfunc nb_multiply; |
| 134 | binaryfunc nb_divide; |
| 135 | binaryfunc nb_remainder; |
| 136 | binaryfunc nb_divmod; |
Guido van Rossum | 75abc63 | 1994-08-09 13:21:54 +0000 | [diff] [blame] | 137 | ternaryfunc nb_power; |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 138 | unaryfunc nb_negative; |
| 139 | unaryfunc nb_positive; |
| 140 | unaryfunc nb_absolute; |
| 141 | inquiry nb_nonzero; |
| 142 | unaryfunc nb_invert; |
| 143 | binaryfunc nb_lshift; |
| 144 | binaryfunc nb_rshift; |
| 145 | binaryfunc nb_and; |
| 146 | binaryfunc nb_xor; |
| 147 | binaryfunc nb_or; |
| 148 | coercion nb_coerce; |
| 149 | unaryfunc nb_int; |
| 150 | unaryfunc nb_long; |
| 151 | unaryfunc nb_float; |
| 152 | unaryfunc nb_oct; |
| 153 | unaryfunc nb_hex; |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 154 | } PyNumberMethods; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 155 | |
| 156 | typedef struct { |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 157 | inquiry sq_length; |
| 158 | binaryfunc sq_concat; |
| 159 | intargfunc sq_repeat; |
| 160 | intargfunc sq_item; |
| 161 | intintargfunc sq_slice; |
| 162 | intobjargproc sq_ass_item; |
| 163 | intintobjargproc sq_ass_slice; |
Guido van Rossum | cecb27a | 2000-02-28 15:00:40 +0000 | [diff] [blame] | 164 | objobjproc sq_contains; |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 165 | } PySequenceMethods; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 166 | |
| 167 | typedef struct { |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 168 | inquiry mp_length; |
| 169 | binaryfunc mp_subscript; |
| 170 | objobjargproc mp_ass_subscript; |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 171 | } PyMappingMethods; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 172 | |
Guido van Rossum | fdf95dd | 1997-05-05 22:15:02 +0000 | [diff] [blame] | 173 | typedef struct { |
| 174 | getreadbufferproc bf_getreadbuffer; |
| 175 | getwritebufferproc bf_getwritebuffer; |
| 176 | getsegcountproc bf_getsegcount; |
Guido van Rossum | 36eef3c | 1998-10-08 02:10:56 +0000 | [diff] [blame] | 177 | getcharbufferproc bf_getcharbuffer; |
Guido van Rossum | fdf95dd | 1997-05-05 22:15:02 +0000 | [diff] [blame] | 178 | } PyBufferProcs; |
| 179 | |
| 180 | |
Tim Peters | 9ace6bc | 2000-07-08 00:32:04 +0000 | [diff] [blame] | 181 | typedef void (*destructor)(PyObject *); |
| 182 | typedef int (*printfunc)(PyObject *, FILE *, int); |
| 183 | typedef PyObject *(*getattrfunc)(PyObject *, char *); |
| 184 | typedef PyObject *(*getattrofunc)(PyObject *, PyObject *); |
| 185 | typedef int (*setattrfunc)(PyObject *, char *, PyObject *); |
| 186 | typedef int (*setattrofunc)(PyObject *, PyObject *, PyObject *); |
| 187 | typedef int (*cmpfunc)(PyObject *, PyObject *); |
| 188 | typedef PyObject *(*reprfunc)(PyObject *); |
| 189 | typedef long (*hashfunc)(PyObject *); |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 190 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 191 | typedef struct _typeobject { |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 192 | PyObject_VAR_HEAD |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 193 | char *tp_name; /* For printing */ |
Guido van Rossum | 5799b52 | 1995-01-04 19:06:22 +0000 | [diff] [blame] | 194 | int tp_basicsize, tp_itemsize; /* For allocation */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 195 | |
| 196 | /* Methods to implement standard operations */ |
| 197 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 198 | destructor tp_dealloc; |
| 199 | printfunc tp_print; |
| 200 | getattrfunc tp_getattr; |
| 201 | setattrfunc tp_setattr; |
| 202 | cmpfunc tp_compare; |
| 203 | reprfunc tp_repr; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 204 | |
| 205 | /* Method suites for standard classes */ |
| 206 | |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 207 | PyNumberMethods *tp_as_number; |
| 208 | PySequenceMethods *tp_as_sequence; |
| 209 | PyMappingMethods *tp_as_mapping; |
Guido van Rossum | 9bfef44 | 1993-03-29 10:43:31 +0000 | [diff] [blame] | 210 | |
Fred Drake | 0e12bcd | 2000-03-21 16:14:47 +0000 | [diff] [blame] | 211 | /* More standard operations (here for binary compatibility) */ |
Guido van Rossum | 9bfef44 | 1993-03-29 10:43:31 +0000 | [diff] [blame] | 212 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 213 | hashfunc tp_hash; |
Guido van Rossum | 884afd6 | 1995-07-18 14:21:06 +0000 | [diff] [blame] | 214 | ternaryfunc tp_call; |
Guido van Rossum | 6fde390 | 1995-01-07 10:32:04 +0000 | [diff] [blame] | 215 | reprfunc tp_str; |
Guido van Rossum | 0693dd2 | 1996-08-09 20:48:52 +0000 | [diff] [blame] | 216 | getattrofunc tp_getattro; |
| 217 | setattrofunc tp_setattro; |
Guido van Rossum | 6fde390 | 1995-01-07 10:32:04 +0000 | [diff] [blame] | 218 | |
Guido van Rossum | fdf95dd | 1997-05-05 22:15:02 +0000 | [diff] [blame] | 219 | /* Functions to access object as input/output buffer */ |
| 220 | PyBufferProcs *tp_as_buffer; |
| 221 | |
Guido van Rossum | 36eef3c | 1998-10-08 02:10:56 +0000 | [diff] [blame] | 222 | /* Flags to define presence of optional/expanded features */ |
| 223 | long tp_flags; |
Guido van Rossum | 6fde390 | 1995-01-07 10:32:04 +0000 | [diff] [blame] | 224 | |
| 225 | char *tp_doc; /* Documentation string */ |
| 226 | |
Jeremy Hylton | 8caad49 | 2000-06-23 14:18:11 +0000 | [diff] [blame] | 227 | /* call function for all accessible objects */ |
| 228 | traverseproc tp_traverse; |
| 229 | |
| 230 | /* delete references to contained objects */ |
| 231 | inquiry tp_clear; |
| 232 | |
Guido van Rossum | a9c2d7a | 1998-04-23 19:16:44 +0000 | [diff] [blame] | 233 | /* More spares */ |
Guido van Rossum | a9c2d7a | 1998-04-23 19:16:44 +0000 | [diff] [blame] | 234 | long tp_xxx7; |
| 235 | long tp_xxx8; |
| 236 | |
Sjoerd Mullender | a9c3c22 | 1993-10-11 12:54:31 +0000 | [diff] [blame] | 237 | #ifdef COUNT_ALLOCS |
| 238 | /* these must be last */ |
| 239 | int tp_alloc; |
| 240 | int tp_free; |
| 241 | int tp_maxalloc; |
| 242 | struct _typeobject *tp_next; |
| 243 | #endif |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 244 | } PyTypeObject; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 245 | |
Sjoerd Mullender | 107c747 | 1995-04-25 11:53:24 +0000 | [diff] [blame] | 246 | extern DL_IMPORT(PyTypeObject) PyType_Type; /* The type of type objects */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 247 | |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 248 | #define PyType_Check(op) ((op)->ob_type == &PyType_Type) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 249 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 250 | /* Generic operations on objects */ |
Tim Peters | 9ace6bc | 2000-07-08 00:32:04 +0000 | [diff] [blame] | 251 | extern DL_IMPORT(int) PyObject_Print(PyObject *, FILE *, int); |
| 252 | extern DL_IMPORT(PyObject *) PyObject_Repr(PyObject *); |
| 253 | extern DL_IMPORT(PyObject *) PyObject_Str(PyObject *); |
| 254 | extern DL_IMPORT(int) PyObject_Compare(PyObject *, PyObject *); |
| 255 | extern DL_IMPORT(PyObject *) PyObject_GetAttrString(PyObject *, char *); |
| 256 | extern DL_IMPORT(int) PyObject_SetAttrString(PyObject *, char *, PyObject *); |
| 257 | extern DL_IMPORT(int) PyObject_HasAttrString(PyObject *, char *); |
| 258 | extern DL_IMPORT(PyObject *) PyObject_GetAttr(PyObject *, PyObject *); |
| 259 | extern DL_IMPORT(int) PyObject_SetAttr(PyObject *, PyObject *, PyObject *); |
| 260 | extern DL_IMPORT(int) PyObject_HasAttr(PyObject *, PyObject *); |
| 261 | extern DL_IMPORT(long) PyObject_Hash(PyObject *); |
| 262 | extern DL_IMPORT(int) PyObject_IsTrue(PyObject *); |
| 263 | extern DL_IMPORT(int) PyObject_Not(PyObject *); |
| 264 | extern DL_IMPORT(int) PyCallable_Check(PyObject *); |
| 265 | extern DL_IMPORT(int) PyNumber_Coerce(PyObject **, PyObject **); |
| 266 | extern DL_IMPORT(int) PyNumber_CoerceEx(PyObject **, PyObject **); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 267 | |
Guido van Rossum | 26d4ac3 | 1998-04-10 22:32:24 +0000 | [diff] [blame] | 268 | /* Helpers for printing recursive container types */ |
Tim Peters | 9ace6bc | 2000-07-08 00:32:04 +0000 | [diff] [blame] | 269 | extern DL_IMPORT(int) Py_ReprEnter(PyObject *); |
| 270 | extern DL_IMPORT(void) Py_ReprLeave(PyObject *); |
Guido van Rossum | 26d4ac3 | 1998-04-10 22:32:24 +0000 | [diff] [blame] | 271 | |
Jeremy Hylton | 4a3dd2d | 2000-04-14 19:13:24 +0000 | [diff] [blame] | 272 | /* tstate dict key for PyObject_Compare helper */ |
| 273 | extern PyObject *_PyCompareState_Key; |
| 274 | |
Fred Drake | 13634cf | 2000-06-29 19:17:04 +0000 | [diff] [blame] | 275 | /* Helpers for hash functions */ |
Tim Peters | 9ace6bc | 2000-07-08 00:32:04 +0000 | [diff] [blame] | 276 | extern DL_IMPORT(long) _Py_HashDouble(double); |
| 277 | extern DL_IMPORT(long) _Py_HashPointer(void*); |
Fred Drake | 13634cf | 2000-06-29 19:17:04 +0000 | [diff] [blame] | 278 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 279 | /* Flag bits for printing: */ |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 280 | #define Py_PRINT_RAW 1 /* No string quotes etc. */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 281 | |
| 282 | /* |
Guido van Rossum | 36eef3c | 1998-10-08 02:10:56 +0000 | [diff] [blame] | 283 | |
| 284 | Type flags (tp_flags) |
| 285 | |
| 286 | These flags are used to extend the type structure in a backwards-compatible |
| 287 | fashion. Extensions can use the flags to indicate (and test) when a given |
| 288 | type structure contains a new feature. The Python core will use these when |
| 289 | introducing new functionality between major revisions (to avoid mid-version |
| 290 | changes in the PYTHON_API_VERSION). |
| 291 | |
| 292 | Arbitration of the flag bit positions will need to be coordinated among |
| 293 | all extension writers who publically release their extensions (this will |
| 294 | be fewer than you might expect!).. |
| 295 | |
| 296 | Python 1.5.2 introduced the bf_getcharbuffer slot into PyBufferProcs. |
| 297 | |
| 298 | Type definitions should use Py_TPFLAGS_DEFAULT for their tp_flags value. |
| 299 | |
| 300 | Code can use PyType_HasFeature(type_ob, flag_value) to test whether the |
| 301 | given type object has a specified feature. |
| 302 | |
| 303 | */ |
| 304 | |
| 305 | /* PyBufferProcs contains bf_getcharbuffer */ |
| 306 | #define Py_TPFLAGS_HAVE_GETCHARBUFFER (1L<<0) |
| 307 | |
Guido van Rossum | cecb27a | 2000-02-28 15:00:40 +0000 | [diff] [blame] | 308 | /* PySequenceMethods contains sq_contains */ |
| 309 | #define Py_TPFLAGS_HAVE_SEQUENCE_IN (1L<<1) |
| 310 | |
Jeremy Hylton | d08b4c4 | 2000-06-23 19:37:02 +0000 | [diff] [blame] | 311 | /* Objects which participate in garbage collection (see objimp.h) */ |
| 312 | #ifdef WITH_CYCLE_GC |
| 313 | #define Py_TPFLAGS_GC (1L<<2) |
| 314 | #else |
| 315 | #define Py_TPFLAGS_GC 0 |
| 316 | #endif |
| 317 | |
Guido van Rossum | cecb27a | 2000-02-28 15:00:40 +0000 | [diff] [blame] | 318 | #define Py_TPFLAGS_DEFAULT (Py_TPFLAGS_HAVE_GETCHARBUFFER | \ |
| 319 | Py_TPFLAGS_HAVE_SEQUENCE_IN) |
Guido van Rossum | 36eef3c | 1998-10-08 02:10:56 +0000 | [diff] [blame] | 320 | |
| 321 | #define PyType_HasFeature(t,f) (((t)->tp_flags & (f)) != 0) |
| 322 | |
| 323 | |
| 324 | /* |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 325 | The macros Py_INCREF(op) and Py_DECREF(op) are used to increment or decrement |
| 326 | reference counts. Py_DECREF calls the object's deallocator function; for |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 327 | objects that don't contain references to other objects or heap memory |
| 328 | this can be the standard function free(). Both macros can be used |
Thomas Wouters | 7e47402 | 2000-07-16 12:04:32 +0000 | [diff] [blame] | 329 | wherever a void expression is allowed. The argument shouldn't be a |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 330 | NIL pointer. The macro _Py_NewReference(op) is used only to initialize |
| 331 | reference counts to 1; it is defined here for convenience. |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 332 | |
| 333 | We assume that the reference count field can never overflow; this can |
| 334 | be proven when the size of the field is the same as the pointer size |
| 335 | but even with a 16-bit reference count field it is pretty unlikely so |
| 336 | we ignore the possibility. (If you are paranoid, make it a long.) |
| 337 | |
| 338 | Type objects should never be deallocated; the type pointer in an object |
| 339 | is not considered to be a reference to the type object, to save |
| 340 | complications in the deallocation function. (This is actually a |
| 341 | decision that's up to the implementer of each new type so if you want, |
| 342 | you can count such references to the type object.) |
| 343 | |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 344 | *** WARNING*** The Py_DECREF macro must have a side-effect-free argument |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 345 | since it may evaluate its argument multiple times. (The alternative |
| 346 | would be to mace it a proper function or assign it to a global temporary |
| 347 | variable first, both of which are slower; and in a multi-threaded |
| 348 | environment the global variable trick is not safe.) |
| 349 | */ |
| 350 | |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 351 | #ifdef Py_TRACE_REFS |
| 352 | #ifndef Py_REF_DEBUG |
| 353 | #define Py_REF_DEBUG |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 354 | #endif |
| 355 | #endif |
| 356 | |
Guido van Rossum | d86b380 | 1996-08-12 21:31:32 +0000 | [diff] [blame] | 357 | #ifdef Py_TRACE_REFS |
Tim Peters | 9ace6bc | 2000-07-08 00:32:04 +0000 | [diff] [blame] | 358 | extern DL_IMPORT(void) _Py_Dealloc(PyObject *); |
| 359 | extern DL_IMPORT(void) _Py_NewReference(PyObject *); |
| 360 | extern DL_IMPORT(void) _Py_ForgetReference(PyObject *); |
| 361 | extern DL_IMPORT(void) _Py_PrintReferences(FILE *); |
| 362 | extern DL_IMPORT(void) _Py_ResetReferences(void); |
Guido van Rossum | d86b380 | 1996-08-12 21:31:32 +0000 | [diff] [blame] | 363 | #endif |
| 364 | |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 365 | #ifndef Py_TRACE_REFS |
Sjoerd Mullender | a9c3c22 | 1993-10-11 12:54:31 +0000 | [diff] [blame] | 366 | #ifdef COUNT_ALLOCS |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 367 | #define _Py_Dealloc(op) ((op)->ob_type->tp_free++, (*(op)->ob_type->tp_dealloc)((PyObject *)(op))) |
Sjoerd Mullender | 91e7a0b | 1995-04-06 13:47:48 +0000 | [diff] [blame] | 368 | #define _Py_ForgetReference(op) ((op)->ob_type->tp_free++) |
Guido van Rossum | d86b380 | 1996-08-12 21:31:32 +0000 | [diff] [blame] | 369 | #else /* !COUNT_ALLOCS */ |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 370 | #define _Py_Dealloc(op) (*(op)->ob_type->tp_dealloc)((PyObject *)(op)) |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 371 | #define _Py_ForgetReference(op) /*empty*/ |
Guido van Rossum | d86b380 | 1996-08-12 21:31:32 +0000 | [diff] [blame] | 372 | #endif /* !COUNT_ALLOCS */ |
| 373 | #endif /* !Py_TRACE_REFS */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 374 | |
Sjoerd Mullender | a9c3c22 | 1993-10-11 12:54:31 +0000 | [diff] [blame] | 375 | #ifdef COUNT_ALLOCS |
Tim Peters | 9ace6bc | 2000-07-08 00:32:04 +0000 | [diff] [blame] | 376 | extern DL_IMPORT(void) inc_count(PyTypeObject *); |
Sjoerd Mullender | a9c3c22 | 1993-10-11 12:54:31 +0000 | [diff] [blame] | 377 | #endif |
| 378 | |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 379 | #ifdef Py_REF_DEBUG |
Guido van Rossum | 60be1db | 1996-05-22 16:33:22 +0000 | [diff] [blame] | 380 | |
Guido van Rossum | 43466ec | 1998-12-04 18:48:25 +0000 | [diff] [blame] | 381 | extern DL_IMPORT(long) _Py_RefTotal; |
Guido van Rossum | 60be1db | 1996-05-22 16:33:22 +0000 | [diff] [blame] | 382 | |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 383 | #ifndef Py_TRACE_REFS |
Sjoerd Mullender | a9c3c22 | 1993-10-11 12:54:31 +0000 | [diff] [blame] | 384 | #ifdef COUNT_ALLOCS |
Guido van Rossum | 6f9e433 | 1995-03-29 16:57:48 +0000 | [diff] [blame] | 385 | #define _Py_NewReference(op) (inc_count((op)->ob_type), _Py_RefTotal++, (op)->ob_refcnt = 1) |
Sjoerd Mullender | a9c3c22 | 1993-10-11 12:54:31 +0000 | [diff] [blame] | 386 | #else |
Guido van Rossum | 6f9e433 | 1995-03-29 16:57:48 +0000 | [diff] [blame] | 387 | #define _Py_NewReference(op) (_Py_RefTotal++, (op)->ob_refcnt = 1) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 388 | #endif |
Guido van Rossum | 60be1db | 1996-05-22 16:33:22 +0000 | [diff] [blame] | 389 | #endif /* !Py_TRACE_REFS */ |
| 390 | |
Guido van Rossum | 6f9e433 | 1995-03-29 16:57:48 +0000 | [diff] [blame] | 391 | #define Py_INCREF(op) (_Py_RefTotal++, (op)->ob_refcnt++) |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 392 | #define Py_DECREF(op) \ |
Guido van Rossum | 6f9e433 | 1995-03-29 16:57:48 +0000 | [diff] [blame] | 393 | if (--_Py_RefTotal, --(op)->ob_refcnt != 0) \ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 394 | ; \ |
| 395 | else \ |
Guido van Rossum | 1d529d1 | 1997-08-05 02:30:44 +0000 | [diff] [blame] | 396 | _Py_Dealloc((PyObject *)(op)) |
Guido van Rossum | 60be1db | 1996-05-22 16:33:22 +0000 | [diff] [blame] | 397 | #else /* !Py_REF_DEBUG */ |
| 398 | |
Sjoerd Mullender | a9c3c22 | 1993-10-11 12:54:31 +0000 | [diff] [blame] | 399 | #ifdef COUNT_ALLOCS |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 400 | #define _Py_NewReference(op) (inc_count((op)->ob_type), (op)->ob_refcnt = 1) |
Sjoerd Mullender | a9c3c22 | 1993-10-11 12:54:31 +0000 | [diff] [blame] | 401 | #else |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 402 | #define _Py_NewReference(op) ((op)->ob_refcnt = 1) |
Sjoerd Mullender | a9c3c22 | 1993-10-11 12:54:31 +0000 | [diff] [blame] | 403 | #endif |
Guido van Rossum | 60be1db | 1996-05-22 16:33:22 +0000 | [diff] [blame] | 404 | |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 405 | #define Py_INCREF(op) ((op)->ob_refcnt++) |
| 406 | #define Py_DECREF(op) \ |
Guido van Rossum | 5799b52 | 1995-01-04 19:06:22 +0000 | [diff] [blame] | 407 | if (--(op)->ob_refcnt != 0) \ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 408 | ; \ |
| 409 | else \ |
Guido van Rossum | 1d529d1 | 1997-08-05 02:30:44 +0000 | [diff] [blame] | 410 | _Py_Dealloc((PyObject *)(op)) |
Guido van Rossum | 60be1db | 1996-05-22 16:33:22 +0000 | [diff] [blame] | 411 | #endif /* !Py_REF_DEBUG */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 412 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 413 | /* Macros to use in case the object pointer may be NULL: */ |
| 414 | |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 415 | #define Py_XINCREF(op) if ((op) == NULL) ; else Py_INCREF(op) |
| 416 | #define Py_XDECREF(op) if ((op) == NULL) ; else Py_DECREF(op) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 417 | |
| 418 | /* Definition of NULL, so you don't have to include <stdio.h> */ |
| 419 | |
| 420 | #ifndef NULL |
| 421 | #define NULL 0 |
| 422 | #endif |
| 423 | |
| 424 | |
| 425 | /* |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 426 | _Py_NoneStruct is an object of undefined type which can be used in contexts |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 427 | where NULL (nil) is not suitable (since NULL often means 'error'). |
| 428 | |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 429 | Don't forget to apply Py_INCREF() when returning this value!!! |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 430 | */ |
| 431 | |
Sjoerd Mullender | 107c747 | 1995-04-25 11:53:24 +0000 | [diff] [blame] | 432 | extern DL_IMPORT(PyObject) _Py_NoneStruct; /* Don't use this directly */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 433 | |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 434 | #define Py_None (&_Py_NoneStruct) |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 435 | |
| 436 | |
| 437 | /* |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 438 | A common programming style in Python requires the forward declaration |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 439 | of static, initialized structures, e.g. for a type object that is used |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 440 | by the functions whose address must be used in the initializer. |
| 441 | Some compilers (notably SCO ODT 3.0, I seem to remember early AIX as |
| 442 | well) botch this if you use the static keyword for both declarations |
| 443 | (they allocate two objects, and use the first, uninitialized one until |
| 444 | the second declaration is encountered). Therefore, the forward |
| 445 | declaration should use the 'forwardstatic' keyword. This expands to |
| 446 | static on most systems, but to extern on a few. The actual storage |
| 447 | and name will still be static because the second declaration is |
| 448 | static, so no linker visible symbols will be generated. (Standard C |
| 449 | compilers take offense to the extern forward declaration of a static |
| 450 | object, so I can't just put extern in all cases. :-( ) |
| 451 | */ |
| 452 | |
| 453 | #ifdef BAD_STATIC_FORWARD |
| 454 | #define staticforward extern |
Guido van Rossum | 57836fe | 1995-02-21 21:06:10 +0000 | [diff] [blame] | 455 | #define statichere static |
Guido van Rossum | 57836fe | 1995-02-21 21:06:10 +0000 | [diff] [blame] | 456 | #else /* !BAD_STATIC_FORWARD */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 457 | #define staticforward static |
Guido van Rossum | 57836fe | 1995-02-21 21:06:10 +0000 | [diff] [blame] | 458 | #define statichere static |
| 459 | #endif /* !BAD_STATIC_FORWARD */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 460 | |
| 461 | |
| 462 | /* |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 463 | More conventions |
| 464 | ================ |
| 465 | |
| 466 | Argument Checking |
| 467 | ----------------- |
| 468 | |
| 469 | Functions that take objects as arguments normally don't check for nil |
| 470 | arguments, but they do check the type of the argument, and return an |
| 471 | error if the function doesn't apply to the type. |
| 472 | |
| 473 | Failure Modes |
| 474 | ------------- |
| 475 | |
| 476 | Functions may fail for a variety of reasons, including running out of |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 477 | memory. This is communicated to the caller in two ways: an error string |
| 478 | is set (see errors.h), and the function result differs: functions that |
| 479 | normally return a pointer return NULL for failure, functions returning |
| 480 | an integer return -1 (which could be a legal return value too!), and |
| 481 | other functions return 0 for success and -1 for failure. |
| 482 | Callers should always check for errors before using the result. |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 483 | |
| 484 | Reference Counts |
| 485 | ---------------- |
| 486 | |
| 487 | It takes a while to get used to the proper usage of reference counts. |
| 488 | |
| 489 | Functions that create an object set the reference count to 1; such new |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 490 | objects must be stored somewhere or destroyed again with Py_DECREF(). |
| 491 | Functions that 'store' objects such as PyTuple_SetItem() and |
| 492 | PyDict_SetItemString() |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 493 | don't increment the reference count of the object, since the most |
| 494 | frequent use is to store a fresh object. Functions that 'retrieve' |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 495 | objects such as PyTuple_GetItem() and PyDict_GetItemString() also |
| 496 | don't increment |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 497 | the reference count, since most frequently the object is only looked at |
| 498 | quickly. Thus, to retrieve an object and store it again, the caller |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 499 | must call Py_INCREF() explicitly. |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 500 | |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 501 | NOTE: functions that 'consume' a reference count like |
Fred Drake | 49bb0e3 | 1997-09-05 17:53:53 +0000 | [diff] [blame] | 502 | PyList_SetItemString() even consume the reference if the object wasn't |
| 503 | stored, to simplify error handling. |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 504 | |
| 505 | It seems attractive to make other functions that take an object as |
| 506 | argument consume a reference count; however this may quickly get |
| 507 | confusing (even the current practice is already confusing). Consider |
Guido van Rossum | caa6380 | 1995-01-12 11:45:45 +0000 | [diff] [blame] | 508 | it carefully, it may save lots of calls to Py_INCREF() and Py_DECREF() at |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 509 | times. |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 510 | */ |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 511 | |
Guido van Rossum | d724b23 | 2000-03-13 16:01:29 +0000 | [diff] [blame] | 512 | /* |
| 513 | trashcan |
| 514 | CT 2k0130 |
| 515 | non-recursively destroy nested objects |
| 516 | |
| 517 | CT 2k0223 |
| 518 | redefinition for better locality and less overhead. |
| 519 | |
| 520 | Objects that want to be recursion safe need to use |
Thomas Wouters | 7e47402 | 2000-07-16 12:04:32 +0000 | [diff] [blame] | 521 | the macro's |
Guido van Rossum | d724b23 | 2000-03-13 16:01:29 +0000 | [diff] [blame] | 522 | Py_TRASHCAN_SAFE_BEGIN(name) |
| 523 | and |
| 524 | Py_TRASHCAN_SAFE_END(name) |
| 525 | surrounding their actual deallocation code. |
| 526 | |
| 527 | It would be nice to do this using the thread state. |
| 528 | Also, we could do an exact stack measure then. |
| 529 | Unfortunately, deallocations also take place when |
| 530 | the thread state is undefined. |
Guido van Rossum | e92e610 | 2000-04-24 15:40:53 +0000 | [diff] [blame] | 531 | |
| 532 | CT 2k0422 complete rewrite. |
| 533 | There is no need to allocate new objects. |
| 534 | Everything is done vialob_refcnt and ob_type now. |
| 535 | Adding support for free-threading should be easy, too. |
Guido van Rossum | d724b23 | 2000-03-13 16:01:29 +0000 | [diff] [blame] | 536 | */ |
| 537 | |
| 538 | #define PyTrash_UNWIND_LEVEL 50 |
| 539 | |
| 540 | #define Py_TRASHCAN_SAFE_BEGIN(op) \ |
| 541 | { \ |
| 542 | ++_PyTrash_delete_nesting; \ |
| 543 | if (_PyTrash_delete_nesting < PyTrash_UNWIND_LEVEL) { \ |
| 544 | |
| 545 | #define Py_TRASHCAN_SAFE_END(op) \ |
| 546 | ;} \ |
| 547 | else \ |
| 548 | _PyTrash_deposit_object((PyObject*)op);\ |
| 549 | --_PyTrash_delete_nesting; \ |
| 550 | if (_PyTrash_delete_later && _PyTrash_delete_nesting <= 0) \ |
Guido van Rossum | e92e610 | 2000-04-24 15:40:53 +0000 | [diff] [blame] | 551 | _PyTrash_destroy_chain(); \ |
Guido van Rossum | d724b23 | 2000-03-13 16:01:29 +0000 | [diff] [blame] | 552 | } \ |
| 553 | |
Tim Peters | 9ace6bc | 2000-07-08 00:32:04 +0000 | [diff] [blame] | 554 | extern DL_IMPORT(void) _PyTrash_deposit_object(PyObject*); |
Greg Stein | a90b23c | 2000-07-08 00:46:19 +0000 | [diff] [blame] | 555 | extern DL_IMPORT(void) _PyTrash_destroy_chain(void); |
Guido van Rossum | d724b23 | 2000-03-13 16:01:29 +0000 | [diff] [blame] | 556 | |
| 557 | extern DL_IMPORT(int) _PyTrash_delete_nesting; |
| 558 | extern DL_IMPORT(PyObject *) _PyTrash_delete_later; |
| 559 | |
| 560 | /* swap the "xx" to check the speed loss */ |
| 561 | |
| 562 | #define xxPy_TRASHCAN_SAFE_BEGIN(op) |
| 563 | #define xxPy_TRASHCAN_SAFE_END(op) ; |
Guido van Rossum | e92e610 | 2000-04-24 15:40:53 +0000 | [diff] [blame] | 564 | |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 565 | #ifdef __cplusplus |
| 566 | } |
| 567 | #endif |
| 568 | #endif /* !Py_OBJECT_H */ |