diff options
author | Guido van Rossum <guido@python.org> | 2000-07-01 01:00:38 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2000-07-01 01:00:38 (GMT) |
commit | 4cc6ac7b8797dd55cf9c93b6da7eae1d225b7dfe (patch) | |
tree | 33188a2be2a6d62e6f647f842303aa80ce9de474 | |
parent | ce8e1dc39531c8bed47cef0dd9d05bd3e9c0bd66 (diff) | |
download | cpython-4cc6ac7b8797dd55cf9c93b6da7eae1d225b7dfe.zip cpython-4cc6ac7b8797dd55cf9c93b6da7eae1d225b7dfe.tar.gz cpython-4cc6ac7b8797dd55cf9c93b6da7eae1d225b7dfe.tar.bz2 |
Neil Schemenauer: small fixes for GC
-rw-r--r-- | Include/objimpl.h | 9 | ||||
-rw-r--r-- | Objects/classobject.c | 4 | ||||
-rw-r--r-- | Objects/dictobject.c | 1 | ||||
-rw-r--r-- | Objects/funcobject.c | 1 | ||||
-rw-r--r-- | Objects/listobject.c | 1 | ||||
-rw-r--r-- | Objects/object.c | 11 | ||||
-rw-r--r-- | Objects/tupleobject.c | 3 |
7 files changed, 17 insertions, 13 deletions
diff --git a/Include/objimpl.h b/Include/objimpl.h index 665cec5..defdc9c 100644 --- a/Include/objimpl.h +++ b/Include/objimpl.h @@ -183,6 +183,8 @@ extern DL_IMPORT(void) _PyObject_Del Py_PROTO((PyObject *)); (PyVarObject *) PyObject_MALLOC( _PyObject_VAR_SIZE((typeobj),(n)) ),\ (typeobj), (n)) ) +#define PyObject_DEL(op) PyObject_FREE(op) + /* This example code implements an object constructor with a custom allocator, where PyObject_New is inlined, and shows the important distinction between two steps (at least): @@ -221,7 +223,7 @@ extern DL_IMPORT(void) _PyObject_Del Py_PROTO((PyObject *)); PyObject_{New, VarNew, Del} to manage the memory. Set the type flag Py_TPFLAGS_GC and define the type method tp_recurse. You should also add the method tp_clear if your object is mutable. Include - PyGC_INFO_SIZE in the calculation of tp_basicsize. Call + PyGC_HEAD_SIZE in the calculation of tp_basicsize. Call PyObject_GC_Init after the pointers followed by tp_recurse become valid (usually just before returning the object from the allocation method. Call PyObject_GC_Fini before those pointers become invalid @@ -234,7 +236,6 @@ extern DL_IMPORT(void) _PyObject_Del Py_PROTO((PyObject *)); #define PyObject_GC_Fini(op) #define PyObject_AS_GC(op) (op) #define PyObject_FROM_GC(op) (op) -#define PyObject_DEL(op) PyObject_FREE(op) #else @@ -268,10 +269,6 @@ typedef struct _gc_head { /* Get the object given the PyGC_Head */ #define PyObject_FROM_GC(g) ((PyObject *)(((PyGC_Head *)g)+1)) -#define PyObject_DEL(op) PyObject_FREE( PyObject_IS_GC(op) ? \ - (ANY *)PyObject_AS_GC(op) : \ - (ANY *)(op) ) - #endif /* WITH_CYCLE_GC */ #ifdef __cplusplus diff --git a/Objects/classobject.c b/Objects/classobject.c index 4a7de7b..4f73ff8 100644 --- a/Objects/classobject.c +++ b/Objects/classobject.c @@ -128,6 +128,7 @@ class_dealloc(op) Py_XDECREF(op->cl_getattr); Py_XDECREF(op->cl_setattr); Py_XDECREF(op->cl_delattr); + op = (PyClassObject *) PyObject_AS_GC(op); PyObject_DEL(op); } @@ -473,6 +474,7 @@ PyInstance_New(class, arg, kw) inst->in_dict = PyDict_New(); PyObject_GC_Init(inst); if (inst->in_dict == NULL) { + inst = (PyInstanceObject *) PyObject_AS_GC(inst); PyObject_DEL(inst); return NULL; } @@ -588,6 +590,7 @@ instance_dealloc(inst) #endif /* Py_TRACE_REFS */ Py_DECREF(inst->in_class); Py_XDECREF(inst->in_dict); + inst = (PyInstanceObject *) PyObject_AS_GC(inst); PyObject_DEL(inst); } @@ -1763,6 +1766,7 @@ PyMethod_Fini() while (free_list) { PyMethodObject *im = free_list; free_list = (PyMethodObject *)(im->im_self); + im = (PyMethodObject *) PyObject_AS_GC(im); PyObject_DEL(im); } } diff --git a/Objects/dictobject.c b/Objects/dictobject.c index fd0ad10..60945f0 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -472,6 +472,7 @@ dict_dealloc(mp) } if (mp->ma_table != NULL) PyMem_DEL(mp->ma_table); + mp = (dictobject *) PyObject_AS_GC(mp); PyObject_DEL(mp); Py_TRASHCAN_SAFE_END(mp) } diff --git a/Objects/funcobject.c b/Objects/funcobject.c index 289a29f..b6c0089 100644 --- a/Objects/funcobject.c +++ b/Objects/funcobject.c @@ -172,6 +172,7 @@ func_dealloc(op) Py_DECREF(op->func_name); Py_XDECREF(op->func_defaults); Py_XDECREF(op->func_doc); + op = (PyFunctionObject *) PyObject_AS_GC(op); PyObject_DEL(op); } diff --git a/Objects/listobject.c b/Objects/listobject.c index 2cf381f..d260a88 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -209,6 +209,7 @@ list_dealloc(op) } PyMem_FREE(op->ob_item); } + op = (PyListObject *) PyObject_AS_GC(op); PyObject_DEL(op); Py_TRASHCAN_SAFE_END(op) } diff --git a/Objects/object.c b/Objects/object.c index 4479e7d..3052d38 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -171,14 +171,11 @@ _PyObject_Del(op) PyObject *op; { #ifdef WITH_CYCLE_GC - if (PyType_IS_GC(op->ob_type)) { - PyGC_Head *g = PyObject_AS_GC(op); - PyObject_FREE(g); - } else -#endif - { - PyObject_FREE(op); + if (op && PyType_IS_GC(op->ob_type)) { + op = (PyObject *) PyObject_AS_GC(op); } +#endif + PyObject_FREE(op); } #ifndef WITH_CYCLE_GC diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c index f39f6c0..7ce9417 100644 --- a/Objects/tupleobject.c +++ b/Objects/tupleobject.c @@ -175,6 +175,7 @@ tupledealloc(op) } #endif } + op = (PyTupleObject *) PyObject_AS_GC(op); PyObject_DEL(op); done: Py_TRASHCAN_SAFE_END(op) @@ -559,6 +560,7 @@ _PyTuple_Resize(pv, newsize, last_is_sticky) *pv = (PyObject *) sv; if (sv == NULL) { PyObject_GC_Init((PyObject *)v); + v = (PyTupleObject *) PyObject_AS_GC(v); PyObject_DEL(v); PyErr_NoMemory(); return -1; @@ -595,6 +597,7 @@ PyTuple_Fini() while (p) { q = p; p = (PyTupleObject *)(p->ob_item[0]); + q = (PyTupleObject *) PyObject_AS_GC(q); PyObject_DEL(q); } } |