Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 1 | |
Fred Drake | 3cf4d2b | 2000-07-09 00:55:06 +0000 | [diff] [blame] | 2 | #ifndef Py_OBJIMPL_H |
| 3 | #define Py_OBJIMPL_H |
Peter Schneider-Kamp | 25f6894 | 2000-07-31 22:19:30 +0000 | [diff] [blame] | 4 | |
| 5 | #include "pymem.h" |
| 6 | |
Fred Drake | 3cf4d2b | 2000-07-09 00:55:06 +0000 | [diff] [blame] | 7 | #ifdef __cplusplus |
| 8 | extern "C" { |
| 9 | #endif |
| 10 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 11 | /* |
Guido van Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 12 | Functions and macros for modules that implement new object types. |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 13 | You must first include "object.h". |
| 14 | |
Guido van Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 15 | - PyObject_New(type, typeobj) allocates memory for a new object of |
| 16 | the given type; here 'type' must be the C structure type used to |
| 17 | represent the object and 'typeobj' the address of the corresponding |
| 18 | type object. Reference count and type pointer are filled in; the |
| 19 | rest of the bytes of the object are *undefined*! The resulting |
| 20 | expression type is 'type *'. The size of the object is actually |
| 21 | determined by the tp_basicsize field of the type object. |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 22 | |
Guido van Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 23 | - PyObject_NewVar(type, typeobj, n) is similar but allocates a |
| 24 | variable-size object with n extra items. The size is computed as |
| 25 | tp_basicsize plus n * tp_itemsize. This fills in the ob_size field |
| 26 | as well. |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 27 | |
Guido van Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 28 | - PyObject_Del(op) releases the memory allocated for an object. |
| 29 | |
| 30 | - PyObject_Init(op, typeobj) and PyObject_InitVar(op, typeobj, n) are |
| 31 | similar to PyObject_{New, NewVar} except that they don't allocate |
| 32 | the memory needed for an object. Instead of the 'type' parameter, |
| 33 | they accept the pointer of a new object (allocated by an arbitrary |
| 34 | allocator) and initialize its object header fields. |
| 35 | |
| 36 | Note that objects created with PyObject_{New, NewVar} are allocated |
Neil Schemenauer | ffd5399 | 2002-03-22 15:25:18 +0000 | [diff] [blame] | 37 | within the Python heap by the raw memory allocator (usually the system |
| 38 | malloc). If you want to use the specialized Python allocator use |
| 39 | PyMalloc_New and PyMalloc_NewVar to allocate the objects and |
| 40 | PyMalloc_Del to free them. |
Guido van Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 41 | |
| 42 | In case a specific form of memory management is needed, implying that |
| 43 | the objects would not reside in the Python heap (for example standard |
| 44 | malloc heap(s) are mandatory, use of shared memory, C++ local storage |
| 45 | or operator new), you must first allocate the object with your custom |
| 46 | allocator, then pass its pointer to PyObject_{Init, InitVar} for |
| 47 | filling in its Python-specific fields: reference count, type pointer, |
| 48 | possibly others. You should be aware that Python has very limited |
| 49 | control over these objects because they don't cooperate with the |
| 50 | Python memory manager. Such objects may not be eligible for automatic |
| 51 | garbage collection and you have to make sure that they are released |
| 52 | accordingly whenever their destructor gets called (cf. the specific |
| 53 | form of memory management you're using). |
| 54 | |
| 55 | Unless you have specific memory management requirements, it is |
| 56 | recommended to use PyObject_{New, NewVar, Del}. */ |
| 57 | |
Tim Peters | 6d483d3 | 2001-10-06 21:27:34 +0000 | [diff] [blame] | 58 | /* |
Guido van Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 59 | * Raw object memory interface |
| 60 | * =========================== |
| 61 | */ |
| 62 | |
| 63 | /* The use of this API should be avoided, unless a builtin object |
| 64 | constructor inlines PyObject_{New, NewVar}, either because the |
| 65 | latter functions cannot allocate the exact amount of needed memory, |
| 66 | either for speed. This situation is exceptional, but occurs for |
| 67 | some object constructors (PyBuffer_New, PyList_New...). Inlining |
| 68 | PyObject_{New, NewVar} for objects that are supposed to belong to |
| 69 | the Python heap is discouraged. If you really have to, make sure |
| 70 | the object is initialized with PyObject_{Init, InitVar}. Do *not* |
| 71 | inline PyObject_{Init, InitVar} for user-extension types or you |
| 72 | might seriously interfere with Python's memory management. */ |
| 73 | |
| 74 | /* Functions */ |
| 75 | |
Neil Schemenauer | 25f3dc2 | 2002-03-18 21:06:21 +0000 | [diff] [blame] | 76 | /* Wrappers that useful if you need to be sure that you are using the |
| 77 | same object memory allocator as Python. These wrappers *do not* make |
| 78 | sure that allocating 0 bytes returns a non-NULL pointer. Returned |
| 79 | pointers must be checked for NULL explicitly; no action is performed |
| 80 | on failure. */ |
Thomas Wouters | 334fb89 | 2000-07-25 12:56:38 +0000 | [diff] [blame] | 81 | extern DL_IMPORT(void *) PyObject_Malloc(size_t); |
| 82 | extern DL_IMPORT(void *) PyObject_Realloc(void *, size_t); |
| 83 | extern DL_IMPORT(void) PyObject_Free(void *); |
Guido van Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 84 | |
| 85 | /* Macros */ |
Neil Schemenauer | ffd5399 | 2002-03-22 15:25:18 +0000 | [diff] [blame] | 86 | #define PyObject_MALLOC(n) PyMem_MALLOC(n) |
| 87 | #define PyObject_REALLOC(op, n) PyMem_REALLOC((void *)(op), (n)) |
| 88 | #define PyObject_FREE(op) PyMem_FREE((void *)(op)) |
Guido van Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 89 | |
| 90 | /* |
| 91 | * Generic object allocator interface |
| 92 | * ================================== |
| 93 | */ |
| 94 | |
| 95 | /* Functions */ |
Fred Drake | 3cf4d2b | 2000-07-09 00:55:06 +0000 | [diff] [blame] | 96 | extern DL_IMPORT(PyObject *) PyObject_Init(PyObject *, PyTypeObject *); |
| 97 | extern DL_IMPORT(PyVarObject *) PyObject_InitVar(PyVarObject *, |
| 98 | PyTypeObject *, int); |
| 99 | extern DL_IMPORT(PyObject *) _PyObject_New(PyTypeObject *); |
| 100 | extern DL_IMPORT(PyVarObject *) _PyObject_NewVar(PyTypeObject *, int); |
| 101 | extern DL_IMPORT(void) _PyObject_Del(PyObject *); |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 102 | |
Guido van Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 103 | #define PyObject_New(type, typeobj) \ |
| 104 | ( (type *) _PyObject_New(typeobj) ) |
| 105 | #define PyObject_NewVar(type, typeobj, n) \ |
| 106 | ( (type *) _PyObject_NewVar((typeobj), (n)) ) |
| 107 | #define PyObject_Del(op) _PyObject_Del((PyObject *)(op)) |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 108 | |
Andrew M. Kuchling | 1582a3a | 2000-08-16 12:27:23 +0000 | [diff] [blame] | 109 | /* Macros trading binary compatibility for speed. See also pymem.h. |
Guido van Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 110 | Note that these macros expect non-NULL object pointers.*/ |
| 111 | #define PyObject_INIT(op, typeobj) \ |
Fred Drake | 4e262a9 | 2001-03-22 18:26:47 +0000 | [diff] [blame] | 112 | ( (op)->ob_type = (typeobj), _Py_NewReference((PyObject *)(op)), (op) ) |
Guido van Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 113 | #define PyObject_INIT_VAR(op, typeobj, size) \ |
| 114 | ( (op)->ob_size = (size), PyObject_INIT((op), (typeobj)) ) |
Guido van Rossum | 5a84914 | 1996-07-21 02:23:54 +0000 | [diff] [blame] | 115 | |
Guido van Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 116 | #define _PyObject_SIZE(typeobj) ( (typeobj)->tp_basicsize ) |
Tim Peters | 6d483d3 | 2001-10-06 21:27:34 +0000 | [diff] [blame] | 117 | |
Tim Peters | f2a67da | 2001-10-07 03:54:51 +0000 | [diff] [blame] | 118 | /* _PyObject_VAR_SIZE returns the number of bytes (as size_t) allocated for a |
| 119 | vrbl-size object with nitems items, exclusive of gc overhead (if any). The |
| 120 | value is rounded up to the closest multiple of sizeof(void *), in order to |
| 121 | ensure that pointer fields at the end of the object are correctly aligned |
| 122 | for the platform (this is of special importance for subclasses of, e.g., |
| 123 | str or long, so that pointers can be stored after the embedded data). |
Tim Peters | 6d483d3 | 2001-10-06 21:27:34 +0000 | [diff] [blame] | 124 | |
Tim Peters | f2a67da | 2001-10-07 03:54:51 +0000 | [diff] [blame] | 125 | Note that there's no memory wastage in doing this, as malloc has to |
| 126 | return (at worst) pointer-aligned memory anyway. |
Tim Peters | 6d483d3 | 2001-10-06 21:27:34 +0000 | [diff] [blame] | 127 | */ |
Tim Peters | f2a67da | 2001-10-07 03:54:51 +0000 | [diff] [blame] | 128 | #if ((SIZEOF_VOID_P - 1) & SIZEOF_VOID_P) != 0 |
| 129 | # error "_PyObject_VAR_SIZE requires SIZEOF_VOID_P be a power of 2" |
| 130 | #endif |
| 131 | |
| 132 | #define _PyObject_VAR_SIZE(typeobj, nitems) \ |
| 133 | (size_t) \ |
| 134 | ( ( (typeobj)->tp_basicsize + \ |
| 135 | (nitems)*(typeobj)->tp_itemsize + \ |
| 136 | (SIZEOF_VOID_P - 1) \ |
| 137 | ) & ~(SIZEOF_VOID_P - 1) \ |
| 138 | ) |
Guido van Rossum | 5a84914 | 1996-07-21 02:23:54 +0000 | [diff] [blame] | 139 | |
Guido van Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 140 | #define PyObject_NEW(type, typeobj) \ |
| 141 | ( (type *) PyObject_Init( \ |
| 142 | (PyObject *) PyObject_MALLOC( _PyObject_SIZE(typeobj) ), (typeobj)) ) |
Tim Peters | 6d483d3 | 2001-10-06 21:27:34 +0000 | [diff] [blame] | 143 | |
Tim Peters | f2a67da | 2001-10-07 03:54:51 +0000 | [diff] [blame] | 144 | #define PyObject_NEW_VAR(type, typeobj, n) \ |
| 145 | ( (type *) PyObject_InitVar( \ |
| 146 | (PyVarObject *) PyObject_MALLOC(_PyObject_VAR_SIZE((typeobj),(n)) ),\ |
| 147 | (typeobj), (n)) ) |
Guido van Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 148 | |
Guido van Rossum | 4cc6ac7 | 2000-07-01 01:00:38 +0000 | [diff] [blame] | 149 | #define PyObject_DEL(op) PyObject_FREE(op) |
| 150 | |
Guido van Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 151 | /* This example code implements an object constructor with a custom |
| 152 | allocator, where PyObject_New is inlined, and shows the important |
| 153 | distinction between two steps (at least): |
| 154 | 1) the actual allocation of the object storage; |
| 155 | 2) the initialization of the Python specific fields |
| 156 | in this storage with PyObject_{Init, InitVar}. |
| 157 | |
| 158 | PyObject * |
| 159 | YourObject_New(...) |
| 160 | { |
| 161 | PyObject *op; |
| 162 | |
| 163 | op = (PyObject *) Your_Allocator(_PyObject_SIZE(YourTypeStruct)); |
| 164 | if (op == NULL) |
| 165 | return PyErr_NoMemory(); |
| 166 | |
| 167 | op = PyObject_Init(op, &YourTypeStruct); |
| 168 | if (op == NULL) |
| 169 | return NULL; |
| 170 | |
| 171 | op->ob_field = value; |
| 172 | ... |
| 173 | return op; |
| 174 | } |
| 175 | |
| 176 | Note that in C++, the use of the new operator usually implies that |
| 177 | the 1st step is performed automatically for you, so in a C++ class |
| 178 | constructor you would start directly with PyObject_Init/InitVar. */ |
Guido van Rossum | 5a84914 | 1996-07-21 02:23:54 +0000 | [diff] [blame] | 179 | |
Jeremy Hylton | c5007aa | 2000-06-30 05:02:53 +0000 | [diff] [blame] | 180 | /* |
Neil Schemenauer | ffd5399 | 2002-03-22 15:25:18 +0000 | [diff] [blame] | 181 | * The PyMalloc Object Allocator |
| 182 | * ============================= |
| 183 | */ |
| 184 | |
| 185 | extern DL_IMPORT(PyObject *) _PyMalloc_New(PyTypeObject *); |
| 186 | extern DL_IMPORT(PyVarObject *) _PyMalloc_NewVar(PyTypeObject *, int); |
| 187 | extern DL_IMPORT(void) _PyMalloc_Del(PyObject *); |
| 188 | |
| 189 | #define PyMalloc_New(type, typeobj) \ |
| 190 | ( (type *) _PyMalloc_New(typeobj) ) |
| 191 | #define PyMalloc_NewVar(type, typeobj, n) \ |
| 192 | ( (type *) _PyMalloc_NewVar((typeobj), (n)) ) |
| 193 | #define PyMalloc_Del(op) _PyMalloc_Del((PyObject *)(op)) |
| 194 | |
| 195 | |
| 196 | /* |
Jeremy Hylton | c5007aa | 2000-06-30 05:02:53 +0000 | [diff] [blame] | 197 | * Garbage Collection Support |
| 198 | * ========================== |
Guido van Rossum | 048eb75 | 2001-10-02 21:24:57 +0000 | [diff] [blame] | 199 | * |
| 200 | * Some of the functions and macros below are always defined; when |
| 201 | * WITH_CYCLE_GC is undefined, they simply don't do anything different |
| 202 | * than their non-GC counterparts. |
Jeremy Hylton | c5007aa | 2000-06-30 05:02:53 +0000 | [diff] [blame] | 203 | */ |
Jeremy Hylton | d08b4c4 | 2000-06-23 19:37:02 +0000 | [diff] [blame] | 204 | |
Neil Schemenauer | 74b5ade | 2001-08-29 23:49:28 +0000 | [diff] [blame] | 205 | /* Test if a type has a GC head */ |
| 206 | #define PyType_IS_GC(t) PyType_HasFeature((t), Py_TPFLAGS_HAVE_GC) |
Jeremy Hylton | d08b4c4 | 2000-06-23 19:37:02 +0000 | [diff] [blame] | 207 | |
Neil Schemenauer | 74b5ade | 2001-08-29 23:49:28 +0000 | [diff] [blame] | 208 | /* Test if an object has a GC head */ |
Guido van Rossum | 048eb75 | 2001-10-02 21:24:57 +0000 | [diff] [blame] | 209 | #define PyObject_IS_GC(o) (PyType_IS_GC((o)->ob_type) && \ |
| 210 | ((o)->ob_type->tp_is_gc == NULL || (o)->ob_type->tp_is_gc(o))) |
Jeremy Hylton | c5007aa | 2000-06-30 05:02:53 +0000 | [diff] [blame] | 211 | |
Tim Peters | 6d483d3 | 2001-10-06 21:27:34 +0000 | [diff] [blame] | 212 | extern DL_IMPORT(PyObject *) _PyObject_GC_Malloc(PyTypeObject *, int); |
Neil Schemenauer | 74b5ade | 2001-08-29 23:49:28 +0000 | [diff] [blame] | 213 | extern DL_IMPORT(PyVarObject *) _PyObject_GC_Resize(PyVarObject *, int); |
| 214 | |
| 215 | #define PyObject_GC_Resize(type, op, n) \ |
| 216 | ( (type *) _PyObject_GC_Resize((PyVarObject *)(op), (n)) ) |
| 217 | |
Neil Schemenauer | 74b5ade | 2001-08-29 23:49:28 +0000 | [diff] [blame] | 218 | extern DL_IMPORT(PyObject *) _PyObject_GC_New(PyTypeObject *); |
| 219 | extern DL_IMPORT(PyVarObject *) _PyObject_GC_NewVar(PyTypeObject *, int); |
| 220 | extern DL_IMPORT(void) _PyObject_GC_Del(PyObject *); |
| 221 | extern DL_IMPORT(void) _PyObject_GC_Track(PyObject *); |
| 222 | extern DL_IMPORT(void) _PyObject_GC_UnTrack(PyObject *); |
| 223 | |
Guido van Rossum | 048eb75 | 2001-10-02 21:24:57 +0000 | [diff] [blame] | 224 | #ifdef WITH_CYCLE_GC |
| 225 | |
Neil Schemenauer | 74b5ade | 2001-08-29 23:49:28 +0000 | [diff] [blame] | 226 | /* GC information is stored BEFORE the object structure */ |
Tim Peters | 9e4ca10 | 2001-10-11 18:31:31 +0000 | [diff] [blame] | 227 | typedef union _gc_head { |
| 228 | struct { |
| 229 | union _gc_head *gc_next; /* not NULL if object is tracked */ |
| 230 | union _gc_head *gc_prev; |
| 231 | int gc_refs; |
| 232 | } gc; |
Tim Peters | 5e67cde | 2002-02-28 19:38:51 +0000 | [diff] [blame] | 233 | long double dummy; /* force worst-case alignment */ |
Neil Schemenauer | 74b5ade | 2001-08-29 23:49:28 +0000 | [diff] [blame] | 234 | } PyGC_Head; |
| 235 | |
| 236 | extern PyGC_Head _PyGC_generation0; |
| 237 | |
Neil Schemenauer | ef99723 | 2002-03-28 21:06:16 +0000 | [diff] [blame^] | 238 | #define _Py_AS_GC(o) ((PyGC_Head *)(o)-1) |
| 239 | |
Neil Schemenauer | 74b5ade | 2001-08-29 23:49:28 +0000 | [diff] [blame] | 240 | /* Tell the GC to track this object. NB: While the object is tracked the |
| 241 | * collector it must be safe to call the ob_traverse method. */ |
| 242 | #define _PyObject_GC_TRACK(o) do { \ |
Neil Schemenauer | ef99723 | 2002-03-28 21:06:16 +0000 | [diff] [blame^] | 243 | PyGC_Head *g = _Py_AS_GC(o); \ |
Tim Peters | 9e4ca10 | 2001-10-11 18:31:31 +0000 | [diff] [blame] | 244 | if (g->gc.gc_next != NULL) \ |
Neil Schemenauer | 74b5ade | 2001-08-29 23:49:28 +0000 | [diff] [blame] | 245 | Py_FatalError("GC object already in linked list"); \ |
Tim Peters | 9e4ca10 | 2001-10-11 18:31:31 +0000 | [diff] [blame] | 246 | g->gc.gc_next = &_PyGC_generation0; \ |
| 247 | g->gc.gc_prev = _PyGC_generation0.gc.gc_prev; \ |
| 248 | g->gc.gc_prev->gc.gc_next = g; \ |
| 249 | _PyGC_generation0.gc.gc_prev = g; \ |
Neil Schemenauer | 74b5ade | 2001-08-29 23:49:28 +0000 | [diff] [blame] | 250 | } while (0); |
| 251 | |
| 252 | /* Tell the GC to stop tracking this object. */ |
| 253 | #define _PyObject_GC_UNTRACK(o) do { \ |
Neil Schemenauer | ef99723 | 2002-03-28 21:06:16 +0000 | [diff] [blame^] | 254 | PyGC_Head *g = _Py_AS_GC(o); \ |
Tim Peters | 9e4ca10 | 2001-10-11 18:31:31 +0000 | [diff] [blame] | 255 | g->gc.gc_prev->gc.gc_next = g->gc.gc_next; \ |
| 256 | g->gc.gc_next->gc.gc_prev = g->gc.gc_prev; \ |
| 257 | g->gc.gc_next = NULL; \ |
Neil Schemenauer | 74b5ade | 2001-08-29 23:49:28 +0000 | [diff] [blame] | 258 | } while (0); |
| 259 | |
| 260 | #define PyObject_GC_Track(op) _PyObject_GC_Track((PyObject *)op) |
| 261 | #define PyObject_GC_UnTrack(op) _PyObject_GC_UnTrack((PyObject *)op) |
Tim Peters | 6d483d3 | 2001-10-06 21:27:34 +0000 | [diff] [blame] | 262 | |
Neil Schemenauer | 74b5ade | 2001-08-29 23:49:28 +0000 | [diff] [blame] | 263 | |
| 264 | #define PyObject_GC_New(type, typeobj) \ |
| 265 | ( (type *) _PyObject_GC_New(typeobj) ) |
| 266 | #define PyObject_GC_NewVar(type, typeobj, n) \ |
| 267 | ( (type *) _PyObject_GC_NewVar((typeobj), (n)) ) |
| 268 | #define PyObject_GC_Del(op) _PyObject_GC_Del((PyObject *)(op)) |
| 269 | |
| 270 | #else /* !WITH_CYCLE_GC */ |
| 271 | |
| 272 | #define PyObject_GC_New PyObject_New |
| 273 | #define PyObject_GC_NewVar PyObject_NewVar |
| 274 | #define PyObject_GC_Del PyObject_Del |
Neil Schemenauer | 49417e7 | 2001-09-03 15:44:48 +0000 | [diff] [blame] | 275 | #define _PyObject_GC_TRACK(op) |
| 276 | #define _PyObject_GC_UNTRACK(op) |
Neil Schemenauer | 74b5ade | 2001-08-29 23:49:28 +0000 | [diff] [blame] | 277 | #define PyObject_GC_Track(op) |
| 278 | #define PyObject_GC_UnTrack(op) |
| 279 | |
| 280 | #endif |
| 281 | |
| 282 | /* This is here for the sake of backwards compatibility. Extensions that |
| 283 | * use the old GC API will still compile but the objects will not be |
| 284 | * tracked by the GC. */ |
Jeremy Hylton | c5007aa | 2000-06-30 05:02:53 +0000 | [diff] [blame] | 285 | #define PyGC_HEAD_SIZE 0 |
| 286 | #define PyObject_GC_Init(op) |
| 287 | #define PyObject_GC_Fini(op) |
| 288 | #define PyObject_AS_GC(op) (op) |
| 289 | #define PyObject_FROM_GC(op) (op) |
Tim Peters | 6d6c1a3 | 2001-08-02 04:15:00 +0000 | [diff] [blame] | 290 | |
Jeremy Hylton | d08b4c4 | 2000-06-23 19:37:02 +0000 | [diff] [blame] | 291 | |
Fred Drake | 41deb1e | 2001-02-01 05:27:45 +0000 | [diff] [blame] | 292 | /* Test if a type supports weak references */ |
Fred Drake | 033f312 | 2001-02-02 18:17:30 +0000 | [diff] [blame] | 293 | #define PyType_SUPPORTS_WEAKREFS(t) \ |
| 294 | (PyType_HasFeature((t), Py_TPFLAGS_HAVE_WEAKREFS) \ |
| 295 | && ((t)->tp_weaklistoffset > 0)) |
Fred Drake | 41deb1e | 2001-02-01 05:27:45 +0000 | [diff] [blame] | 296 | |
| 297 | #define PyObject_GET_WEAKREFS_LISTPTR(o) \ |
| 298 | ((PyObject **) (((char *) (o)) + (o)->ob_type->tp_weaklistoffset)) |
| 299 | |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 300 | #ifdef __cplusplus |
| 301 | } |
| 302 | #endif |
| 303 | #endif /* !Py_OBJIMPL_H */ |