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