Changeset 391 for python/trunk/Include/objimpl.h
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Include/objimpl.h
r2 r391 102 102 /* Macros */ 103 103 #ifdef WITH_PYMALLOC 104 #ifdef PYMALLOC_DEBUG 104 #ifdef PYMALLOC_DEBUG /* WITH_PYMALLOC && PYMALLOC_DEBUG */ 105 105 PyAPI_FUNC(void *) _PyObject_DebugMalloc(size_t nbytes); 106 106 PyAPI_FUNC(void *) _PyObject_DebugRealloc(void *p, size_t nbytes); … … 109 109 PyAPI_FUNC(void) _PyObject_DebugCheckAddress(const void *p); 110 110 PyAPI_FUNC(void) _PyObject_DebugMallocStats(void); 111 #define PyObject_MALLOC _PyObject_DebugMalloc 112 #define PyObject_Malloc _PyObject_DebugMalloc 113 #define PyObject_REALLOC _PyObject_DebugRealloc 114 #define PyObject_Realloc _PyObject_DebugRealloc 115 #define PyObject_FREE _PyObject_DebugFree 116 #define PyObject_Free _PyObject_DebugFree 117 118 #else /* WITH_PYMALLOC && ! PYMALLOC_DEBUG */ 119 #define PyObject_MALLOC PyObject_Malloc 120 #define PyObject_REALLOC PyObject_Realloc 121 #define PyObject_FREE PyObject_Free 111 PyAPI_FUNC(void *) _PyObject_DebugMallocApi(char api, size_t nbytes); 112 PyAPI_FUNC(void *) _PyObject_DebugReallocApi(char api, void *p, size_t nbytes); 113 PyAPI_FUNC(void) _PyObject_DebugFreeApi(char api, void *p); 114 PyAPI_FUNC(void) _PyObject_DebugCheckAddressApi(char api, const void *p); 115 PyAPI_FUNC(void *) _PyMem_DebugMalloc(size_t nbytes); 116 PyAPI_FUNC(void *) _PyMem_DebugRealloc(void *p, size_t nbytes); 117 PyAPI_FUNC(void) _PyMem_DebugFree(void *p); 118 #define PyObject_MALLOC _PyObject_DebugMalloc 119 #define PyObject_Malloc _PyObject_DebugMalloc 120 #define PyObject_REALLOC _PyObject_DebugRealloc 121 #define PyObject_Realloc _PyObject_DebugRealloc 122 #define PyObject_FREE _PyObject_DebugFree 123 #define PyObject_Free _PyObject_DebugFree 124 125 #else /* WITH_PYMALLOC && ! PYMALLOC_DEBUG */ 126 #define PyObject_MALLOC PyObject_Malloc 127 #define PyObject_REALLOC PyObject_Realloc 128 #define PyObject_FREE PyObject_Free 122 129 #endif 123 130 124 #else 125 #define PyObject_MALLOC 126 #define PyObject_REALLOC 127 #define PyObject_FREE 128 129 #endif 130 131 #define PyObject_Del 132 #define PyObject_DEL 131 #else /* ! WITH_PYMALLOC */ 132 #define PyObject_MALLOC PyMem_MALLOC 133 #define PyObject_REALLOC PyMem_REALLOC 134 #define PyObject_FREE PyMem_FREE 135 136 #endif /* WITH_PYMALLOC */ 137 138 #define PyObject_Del PyObject_Free 139 #define PyObject_DEL PyObject_FREE 133 140 134 141 /* for source compatibility with 2.2 */ 135 #define _PyObject_Del 142 #define _PyObject_Del PyObject_Free 136 143 137 144 /* … … 148 155 149 156 #define PyObject_New(type, typeobj) \ 150 157 ( (type *) _PyObject_New(typeobj) ) 151 158 #define PyObject_NewVar(type, typeobj, n) \ 152 159 ( (type *) _PyObject_NewVar((typeobj), (n)) ) 153 160 154 161 /* Macros trading binary compatibility for speed. See also pymem.h. 155 162 Note that these macros expect non-NULL object pointers.*/ 156 163 #define PyObject_INIT(op, typeobj) \ 157 164 ( Py_TYPE(op) = (typeobj), _Py_NewReference((PyObject *)(op)), (op) ) 158 165 #define PyObject_INIT_VAR(op, typeobj, size) \ 159 166 ( Py_SIZE(op) = (size), PyObject_INIT((op), (typeobj)) ) 160 167 161 168 #define _PyObject_SIZE(typeobj) ( (typeobj)->tp_basicsize ) … … 175 182 #endif 176 183 177 #define _PyObject_VAR_SIZE(typeobj, nitems) 178 (size_t)\179 ( ( (typeobj)->tp_basicsize +\180 (nitems)*(typeobj)->tp_itemsize +\181 (SIZEOF_VOID_P - 1)\182 ) & ~(SIZEOF_VOID_P - 1)\183 184 #define _PyObject_VAR_SIZE(typeobj, nitems) \ 185 (size_t) \ 186 ( ( (typeobj)->tp_basicsize + \ 187 (nitems)*(typeobj)->tp_itemsize + \ 188 (SIZEOF_VOID_P - 1) \ 189 ) & ~(SIZEOF_VOID_P - 1) \ 190 ) 184 191 185 192 #define PyObject_NEW(type, typeobj) \ 186 193 ( (type *) PyObject_Init( \ 187 194 (PyObject *) PyObject_MALLOC( _PyObject_SIZE(typeobj) ), (typeobj)) ) 188 195 189 196 #define PyObject_NEW_VAR(type, typeobj, n) \ … … 197 204 1) the actual allocation of the object storage; 198 205 2) the initialization of the Python specific fields 199 206 in this storage with PyObject_{Init, InitVar}. 200 207 201 208 PyObject * … … 206 213 op = (PyObject *) Your_Allocator(_PyObject_SIZE(YourTypeStruct)); 207 214 if (op == NULL) 208 215 return PyErr_NoMemory(); 209 216 210 217 PyObject_Init(op, &YourTypeStruct); … … 233 240 /* Test if an object has a GC head */ 234 241 #define PyObject_IS_GC(o) (PyType_IS_GC(Py_TYPE(o)) && \ 235 242 (Py_TYPE(o)->tp_is_gc == NULL || Py_TYPE(o)->tp_is_gc(o))) 236 243 237 244 PyAPI_FUNC(PyVarObject *) _PyObject_GC_Resize(PyVarObject *, Py_ssize_t); 238 245 #define PyObject_GC_Resize(type, op, n) \ 239 246 ( (type *) _PyObject_GC_Resize((PyVarObject *)(op), (n)) ) 240 247 241 248 /* for source compatibility with 2.2 */ … … 244 251 /* GC information is stored BEFORE the object structure. */ 245 252 typedef union _gc_head { 246 247 248 249 250 251 253 struct { 254 union _gc_head *gc_next; 255 union _gc_head *gc_prev; 256 Py_ssize_t gc_refs; 257 } gc; 258 long double dummy; /* force worst-case alignment */ 252 259 } PyGC_Head; 253 260 … … 256 263 #define _Py_AS_GC(o) ((PyGC_Head *)(o)-1) 257 264 258 #define _PyGC_REFS_UNTRACKED 259 #define _PyGC_REFS_REACHABLE 260 #define _PyGC_REFS_TENTATIVELY_UNREACHABLE 265 #define _PyGC_REFS_UNTRACKED (-2) 266 #define _PyGC_REFS_REACHABLE (-3) 267 #define _PyGC_REFS_TENTATIVELY_UNREACHABLE (-4) 261 268 262 269 /* Tell the GC to track this object. NB: While the object is tracked the 263 270 * collector it must be safe to call the ob_traverse method. */ 264 271 #define _PyObject_GC_TRACK(o) do { \ 265 266 267 268 269 270 271 272 272 PyGC_Head *g = _Py_AS_GC(o); \ 273 if (g->gc.gc_refs != _PyGC_REFS_UNTRACKED) \ 274 Py_FatalError("GC object already tracked"); \ 275 g->gc.gc_refs = _PyGC_REFS_REACHABLE; \ 276 g->gc.gc_next = _PyGC_generation0; \ 277 g->gc.gc_prev = _PyGC_generation0->gc.gc_prev; \ 278 g->gc.gc_prev->gc.gc_next = g; \ 279 _PyGC_generation0->gc.gc_prev = g; \ 273 280 } while (0); 274 281 … … 278 285 */ 279 286 #define _PyObject_GC_UNTRACK(o) do { \ 280 281 282 283 284 285 287 PyGC_Head *g = _Py_AS_GC(o); \ 288 assert(g->gc.gc_refs != _PyGC_REFS_UNTRACKED); \ 289 g->gc.gc_refs = _PyGC_REFS_UNTRACKED; \ 290 g->gc.gc_prev->gc.gc_next = g->gc.gc_next; \ 291 g->gc.gc_next->gc.gc_prev = g->gc.gc_prev; \ 292 g->gc.gc_next = NULL; \ 286 293 } while (0); 294 295 /* True if the object is currently tracked by the GC. */ 296 #define _PyObject_GC_IS_TRACKED(o) \ 297 ((_Py_AS_GC(o))->gc.gc_refs != _PyGC_REFS_UNTRACKED) 298 299 /* True if the object may be tracked by the GC in the future, or already is. 300 This can be useful to implement some optimizations. */ 301 #define _PyObject_GC_MAY_BE_TRACKED(obj) \ 302 (PyObject_IS_GC(obj) && \ 303 (!PyTuple_CheckExact(obj) || _PyObject_GC_IS_TRACKED(obj))) 304 287 305 288 306 PyAPI_FUNC(PyObject *) _PyObject_GC_Malloc(size_t); … … 294 312 295 313 #define PyObject_GC_New(type, typeobj) \ 296 314 ( (type *) _PyObject_GC_New(typeobj) ) 297 315 #define PyObject_GC_NewVar(type, typeobj, n) \ 298 316 ( (type *) _PyObject_GC_NewVar((typeobj), (n)) ) 299 317 300 318 … … 304 322 * looking as much alike as possible. 305 323 */ 306 #define Py_VISIT(op) 307 do {\308 if (op) {\309 int vret = visit((PyObject *)(op), arg);\310 if (vret)\311 return vret;\312 }\313 324 #define Py_VISIT(op) \ 325 do { \ 326 if (op) { \ 327 int vret = visit((PyObject *)(op), arg); \ 328 if (vret) \ 329 return vret; \ 330 } \ 331 } while (0) 314 332 315 333 /* This is here for the sake of backwards compatibility. Extensions that … … 325 343 /* Test if a type supports weak references */ 326 344 #define PyType_SUPPORTS_WEAKREFS(t) \ 327 328 345 (PyType_HasFeature((t), Py_TPFLAGS_HAVE_WEAKREFS) \ 346 && ((t)->tp_weaklistoffset > 0)) 329 347 330 348 #define PyObject_GET_WEAKREFS_LISTPTR(o) \ 331 349 ((PyObject **) (((char *) (o)) + Py_TYPE(o)->tp_weaklistoffset)) 332 350 333 351 #ifdef __cplusplus
Note:
See TracChangeset
for help on using the changeset viewer.