[Python-checkins] CVS: python/dist/src/Objects classobject.c,2.92,2.93 dictobject.c,2.54,2.55 funcobject.c,2.23,2.24 listobject.c,2.75,2.76 object.c,2.74,2.75 tupleobject.c,2.38,2.39
Jeremy Hylton
python-dev@python.org
Thu, 29 Jun 2000 22:02:56 -0700
Update of /cvsroot/python/python/dist/src/Objects
In directory slayer.i.sourceforge.net:/tmp/cvs-serv3220/Objects
Modified Files:
classobject.c dictobject.c funcobject.c listobject.c object.c
tupleobject.c
Log Message:
final patches from Neil Schemenauer for garbage collection
Index: classobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/classobject.c,v
retrieving revision 2.92
retrieving revision 2.93
diff -C2 -r2.92 -r2.93
*** classobject.c 2000/06/29 19:17:04 2.92
--- classobject.c 2000/06/30 05:02:53 2.93
***************
*** 133,136 ****
--- 133,137 ----
Py_XINCREF(op->cl_setattr);
Py_XINCREF(op->cl_delattr);
+ PyObject_GC_Init(op);
return (PyObject *) op;
}
***************
*** 142,145 ****
--- 143,147 ----
PyClassObject *op;
{
+ PyObject_GC_Fini(op);
Py_DECREF(op->cl_bases);
Py_DECREF(op->cl_dict);
***************
*** 429,433 ****
0,
"class",
! sizeof(PyClassObject) + PyGC_INFO_SIZE,
0,
(destructor)class_dealloc, /*tp_dealloc*/
--- 431,435 ----
0,
"class",
! sizeof(PyClassObject) + PyGC_HEAD_SIZE,
0,
(destructor)class_dealloc, /*tp_dealloc*/
***************
*** 491,494 ****
--- 493,497 ----
return NULL;
inst->in_dict = PyDict_New();
+ PyObject_GC_Init(inst);
if (inst->in_dict == NULL) {
PyObject_DEL(inst);
***************
*** 540,548 ****
PyObject *del;
static PyObject *delstr;
/* Call the __del__ method if it exists. First temporarily
revive the object and save the current exception, if any. */
#ifdef Py_TRACE_REFS
/* much too complicated if Py_TRACE_REFS defined */
- extern long _Py_RefTotal;
inst->ob_type = &PyInstance_Type;
_Py_NewReference((PyObject *)inst);
--- 543,552 ----
PyObject *del;
static PyObject *delstr;
+ extern long _Py_RefTotal;
+ PyObject_GC_Fini(inst);
/* Call the __del__ method if it exists. First temporarily
revive the object and save the current exception, if any. */
#ifdef Py_TRACE_REFS
/* much too complicated if Py_TRACE_REFS defined */
inst->ob_type = &PyInstance_Type;
_Py_NewReference((PyObject *)inst);
***************
*** 592,595 ****
--- 596,600 ----
inst->ob_type->tp_free--;
#endif
+ PyObject_GC_Init((PyObject *)inst);
return; /* __del__ added a reference; don't delete now */
}
***************
*** 599,603 ****
--- 604,610 ----
#endif
_Py_ForgetReference((PyObject *)inst);
+ #ifndef WITH_CYCLE_GC
inst->ob_type = NULL;
+ #endif
#endif /* Py_TRACE_REFS */
Py_DECREF(inst->in_class);
***************
*** 1511,1515 ****
0,
"instance",
! sizeof(PyInstanceObject) + PyGC_INFO_SIZE,
0,
(destructor)instance_dealloc, /*tp_dealloc*/
--- 1518,1522 ----
0,
"instance",
! sizeof(PyInstanceObject) + PyGC_HEAD_SIZE,
0,
(destructor)instance_dealloc, /*tp_dealloc*/
***************
*** 1569,1572 ****
--- 1576,1580 ----
Py_INCREF(class);
im->im_class = class;
+ PyObject_GC_Init(im);
return (PyObject *)im;
}
***************
*** 1644,1647 ****
--- 1652,1656 ----
register PyMethodObject *im;
{
+ PyObject_GC_Fini(im);
Py_DECREF(im->im_func);
Py_XDECREF(im->im_self);
***************
*** 1746,1750 ****
0,
"instance method",
! sizeof(PyMethodObject) + PyGC_INFO_SIZE,
0,
(destructor)instancemethod_dealloc, /*tp_dealloc*/
--- 1755,1759 ----
0,
"instance method",
! sizeof(PyMethodObject) + PyGC_HEAD_SIZE,
0,
(destructor)instancemethod_dealloc, /*tp_dealloc*/
Index: dictobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/dictobject.c,v
retrieving revision 2.54
retrieving revision 2.55
diff -C2 -r2.54 -r2.55
*** dictobject.c 2000/06/23 19:37:01 2.54
--- dictobject.c 2000/06/30 05:02:53 2.55
***************
*** 130,133 ****
--- 130,134 ----
mp->ma_fill = 0;
mp->ma_used = 0;
+ PyObject_GC_Init(mp);
return (PyObject *)mp;
}
***************
*** 482,485 ****
--- 483,487 ----
register dictentry *ep;
Py_TRASHCAN_SAFE_BEGIN(mp)
+ PyObject_GC_Fini(mp);
for (i = 0, ep = mp->ma_table; i < mp->ma_size; i++, ep++) {
if (ep->me_key != NULL) {
***************
*** 1088,1092 ****
0,
"dictionary",
! sizeof(dictobject) + PyGC_INFO_SIZE,
0,
(destructor)dict_dealloc, /*tp_dealloc*/
--- 1090,1094 ----
0,
"dictionary",
! sizeof(dictobject) + PyGC_HEAD_SIZE,
0,
(destructor)dict_dealloc, /*tp_dealloc*/
Index: funcobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/funcobject.c,v
retrieving revision 2.23
retrieving revision 2.24
diff -C2 -r2.23 -r2.24
*** funcobject.c 2000/06/29 19:17:04 2.23
--- funcobject.c 2000/06/30 05:02:53 2.24
***************
*** 64,67 ****
--- 64,68 ----
op->func_doc = doc;
}
+ PyObject_GC_Init(op);
return (PyObject *)op;
}
***************
*** 187,190 ****
--- 188,192 ----
PyFunctionObject *op;
{
+ PyObject_GC_Fini(op);
Py_DECREF(op->func_code);
Py_DECREF(op->func_globals);
***************
*** 278,282 ****
0,
"function",
! sizeof(PyFunctionObject) + PyGC_INFO_SIZE,
0,
(destructor)func_dealloc, /*tp_dealloc*/
--- 280,284 ----
0,
"function",
! sizeof(PyFunctionObject) + PyGC_HEAD_SIZE,
0,
(destructor)func_dealloc, /*tp_dealloc*/
Index: listobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/listobject.c,v
retrieving revision 2.75
retrieving revision 2.76
diff -C2 -r2.75 -r2.76
*** listobject.c 2000/06/23 19:37:01 2.75
--- listobject.c 2000/06/30 05:02:53 2.76
***************
*** 73,80 ****
/* PyObject_NewVar is inlined */
op = (PyListObject *) PyObject_MALLOC(sizeof(PyListObject)
! + PyGC_INFO_SIZE);
if (op == NULL) {
return PyErr_NoMemory();
}
if (size <= 0) {
op->ob_item = NULL;
--- 73,81 ----
/* PyObject_NewVar is inlined */
op = (PyListObject *) PyObject_MALLOC(sizeof(PyListObject)
! + PyGC_HEAD_SIZE);
if (op == NULL) {
return PyErr_NoMemory();
}
+ op = (PyListObject *) PyObject_FROM_GC(op);
if (size <= 0) {
op->ob_item = NULL;
***************
*** 90,93 ****
--- 91,95 ----
for (i = 0; i < size; i++)
op->ob_item[i] = NULL;
+ PyObject_GC_Init(op);
return (PyObject *) op;
}
***************
*** 217,220 ****
--- 219,223 ----
int i;
Py_TRASHCAN_SAFE_BEGIN(op)
+ PyObject_GC_Fini(op);
if (op->ob_item != NULL) {
/* Do it backwards, for Christian Tismer.
***************
*** 1499,1503 ****
0,
"list",
! sizeof(PyListObject) + PyGC_INFO_SIZE,
0,
(destructor)list_dealloc, /*tp_dealloc*/
--- 1502,1506 ----
0,
"list",
! sizeof(PyListObject) + PyGC_HEAD_SIZE,
0,
(destructor)list_dealloc, /*tp_dealloc*/
***************
*** 1578,1582 ****
0,
"list (immutable, during sort)",
! sizeof(PyListObject) + PyGC_INFO_SIZE,
0,
0, /*tp_dealloc*/ /* Cannot happen */
--- 1581,1585 ----
0,
"list (immutable, during sort)",
! sizeof(PyListObject) + PyGC_HEAD_SIZE,
0,
0, /*tp_dealloc*/ /* Cannot happen */
Index: object.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/object.c,v
retrieving revision 2.74
retrieving revision 2.75
diff -C2 -r2.74 -r2.75
*** object.c 2000/06/29 19:17:04 2.74
--- object.c 2000/06/30 05:02:53 2.75
***************
*** 125,128 ****
--- 125,132 ----
return op;
}
+ #ifdef WITH_CYCLE_GC
+ if (PyType_IS_GC(tp))
+ op = (PyObject *) PyObject_FROM_GC(op);
+ #endif
/* Any changes should be reflected in PyObject_INIT (objimpl.h) */
op->ob_type = tp;
***************
*** 142,145 ****
--- 146,153 ----
return op;
}
+ #ifdef WITH_CYCLE_GC
+ if (PyType_IS_GC(tp))
+ op = (PyVarObject *) PyObject_FROM_GC(op);
+ #endif
/* Any changes should be reflected in PyObject_INIT_VAR */
op->ob_size = size;
***************
*** 157,160 ****
--- 165,172 ----
if (op == NULL)
return PyErr_NoMemory();
+ #ifdef WITH_CYCLE_GC
+ if (PyType_IS_GC(tp))
+ op = (PyObject *) PyObject_FROM_GC(op);
+ #endif
return PyObject_INIT(op, tp);
}
***************
*** 169,172 ****
--- 181,188 ----
if (op == NULL)
return (PyVarObject *)PyErr_NoMemory();
+ #ifdef WITH_CYCLE_GC
+ if (PyType_IS_GC(tp))
+ op = (PyVarObject *) PyObject_FROM_GC(op);
+ #endif
return PyObject_INIT_VAR(op, tp, size);
}
***************
*** 176,182 ****
PyObject *op;
{
! PyObject_FREE(op);
}
int
PyObject_Print(op, fp, flags)
--- 192,212 ----
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);
! }
}
+ #ifndef WITH_CYCLE_GC
+ /* extension modules might need these */
+ void _PyGC_Insert(PyObject *op) { }
+ void _PyGC_Remove(PyObject *op) { }
+ #endif
+
int
PyObject_Print(op, fp, flags)
***************
*** 918,923 ****
--- 948,955 ----
destructor dealloc = op->ob_type->tp_dealloc;
_Py_ForgetReference(op);
+ #ifndef WITH_CYCLE_GC
if (_PyTrash_delete_nesting < PyTrash_UNWIND_LEVEL-1)
op->ob_type = NULL;
+ #endif
(*dealloc)(op);
}
Index: tupleobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/tupleobject.c,v
retrieving revision 2.38
retrieving revision 2.39
diff -C2 -r2.38 -r2.39
*** tupleobject.c 2000/06/23 19:37:02 2.38
--- tupleobject.c 2000/06/30 05:02:53 2.39
***************
*** 95,99 ****
if (nbytes / sizeof(PyObject *) != (size_t)size ||
(nbytes += sizeof(PyTupleObject) - sizeof(PyObject *)
! + PyGC_INFO_SIZE)
<= 0)
{
--- 95,99 ----
if (nbytes / sizeof(PyObject *) != (size_t)size ||
(nbytes += sizeof(PyTupleObject) - sizeof(PyObject *)
! + PyGC_HEAD_SIZE)
<= 0)
{
***************
*** 104,108 ****
if (op == NULL)
return PyErr_NoMemory();
!
PyObject_INIT_VAR(op, &PyTuple_Type, size);
}
--- 104,108 ----
if (op == NULL)
return PyErr_NoMemory();
! op = (PyTupleObject *) PyObject_FROM_GC(op);
PyObject_INIT_VAR(op, &PyTuple_Type, size);
}
***************
*** 116,119 ****
--- 116,120 ----
}
#endif
+ PyObject_GC_Init(op);
return (PyObject *) op;
}
***************
*** 182,185 ****
--- 183,187 ----
register int len = op->ob_size;
Py_TRASHCAN_SAFE_BEGIN(op)
+ PyObject_GC_Fini(op);
if (len > 0) {
i = len;
***************
*** 454,458 ****
0,
"tuple",
! sizeof(PyTupleObject) - sizeof(PyObject *) + PyGC_INFO_SIZE,
sizeof(PyObject *),
(destructor)tupledealloc, /*tp_dealloc*/
--- 456,460 ----
0,
"tuple",
! sizeof(PyTupleObject) - sizeof(PyObject *) + PyGC_HEAD_SIZE,
sizeof(PyObject *),
(destructor)tupledealloc, /*tp_dealloc*/
***************
*** 558,567 ****
#endif
{
sv = (PyTupleObject *)
PyObject_REALLOC((char *)v, sizeof(PyTupleObject)
! + PyGC_INFO_SIZE
+ newsize * sizeof(PyObject *));
*pv = (PyObject *) sv;
if (sv == NULL) {
PyObject_DEL(v);
PyErr_NoMemory();
--- 560,584 ----
#endif
{
+ #ifdef WITH_CYCLE_GC
+ PyGC_Head *g = PyObject_AS_GC((PyObject *)v);
+ PyObject_GC_Fini((PyObject *)v);
sv = (PyTupleObject *)
+ PyObject_REALLOC((char *)g, sizeof(PyTupleObject)
+ + PyGC_HEAD_SIZE
+ + newsize * sizeof(PyObject *));
+ if (g == NULL) {
+ sv = NULL;
+ } else {
+ sv = (PyTupleObject *)PyObject_FROM_GC(g);
+ }
+ #else
+ sv = (PyTupleObject *)
PyObject_REALLOC((char *)v, sizeof(PyTupleObject)
! + PyGC_HEAD_SIZE
+ newsize * sizeof(PyObject *));
+ #endif
*pv = (PyObject *) sv;
if (sv == NULL) {
+ PyObject_GC_Init((PyObject *)v);
PyObject_DEL(v);
PyErr_NoMemory();
***************
*** 579,582 ****
--- 596,600 ----
}
}
+ PyObject_GC_Init(sv);
sv->ob_size = newsize;
return 0;