]> granicus.if.org Git - python/commitdiff
Neil Schemenauer: small fixes for GC
authorGuido van Rossum <guido@python.org>
Sat, 1 Jul 2000 01:00:38 +0000 (01:00 +0000)
committerGuido van Rossum <guido@python.org>
Sat, 1 Jul 2000 01:00:38 +0000 (01:00 +0000)
Include/objimpl.h
Objects/classobject.c
Objects/dictobject.c
Objects/funcobject.c
Objects/listobject.c
Objects/object.c
Objects/tupleobject.c

index 665cec59eb41d2441f9676d2254fc3b47cfb5527..defdc9cd31d11beaae09f7b6532ff88124c27cb2 100644 (file)
@@ -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
index 4a7de7b46cbee00ad5abe773eba2067c08e2f514..4f73ff8b2fed6046931c1a8c1a14c747ae0d81d4 100644 (file)
@@ -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);
        }
 }
index fd0ad10e94e5603a3fe26afdd11249f7706d2868..60945f0c2989154bd64419df258ea0313ec0a8c6 100644 (file)
@@ -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)
 }
index 289a29f21d7263487a8f747820bf21ac4a2a3076..b6c008906e7d3ca93c1460bd62ddd00830a01b71 100644 (file)
@@ -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);
 }
 
index 2cf381f74f367f238e927bc170db23f8b3c4ead6..d260a88947cde8bb883c61a86a6defaf2ef0c4d4 100644 (file)
@@ -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)
 }
index 4479e7dba12f0c046dc61a96e8a16324d243a07e..3052d38174c162a7dabe945b26e704567086848f 100644 (file)
@@ -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
index f39f6c0885872887345b403ba479c64e0b9ceb87..7ce941703e8e24b8659da8579fe5220a0075841f 100644 (file)
@@ -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);
                }
        }