Use new GC API.
This commit is contained in:
parent
fd34369ecb
commit
e83c00efd0
|
@ -38,7 +38,7 @@ new_weakref(void)
|
|||
_Py_NewReference((PyObject *)result);
|
||||
}
|
||||
else {
|
||||
result = PyObject_NEW(PyWeakReference, &PyWeakReference_Type);
|
||||
result = PyObject_GC_New(PyWeakReference, &PyWeakReference_Type);
|
||||
}
|
||||
if (result)
|
||||
result->hash = -1;
|
||||
|
@ -77,8 +77,8 @@ clear_weakref(PyWeakReference *self)
|
|||
static void
|
||||
weakref_dealloc(PyWeakReference *self)
|
||||
{
|
||||
PyObject_GC_UnTrack((PyObject *)self);
|
||||
clear_weakref(self);
|
||||
PyObject_GC_Fini((PyObject *)self);
|
||||
self->wr_next = free_list;
|
||||
free_list = self;
|
||||
}
|
||||
|
@ -170,7 +170,7 @@ PyWeakReference_Type = {
|
|||
PyObject_HEAD_INIT(NULL)
|
||||
0,
|
||||
"weakref",
|
||||
sizeof(PyWeakReference) + PyGC_HEAD_SIZE,
|
||||
sizeof(PyWeakReference),
|
||||
0,
|
||||
(destructor)weakref_dealloc,/*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
|
@ -187,7 +187,7 @@ PyWeakReference_Type = {
|
|||
0, /*tp_getattro*/
|
||||
0, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_GC | Py_TPFLAGS_HAVE_RICHCOMPARE,
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_HAVE_RICHCOMPARE,
|
||||
0, /*tp_doc*/
|
||||
(traverseproc)gc_traverse, /*tp_traverse*/
|
||||
(inquiry)gc_clear, /*tp_clear*/
|
||||
|
@ -429,7 +429,7 @@ PyWeakProxy_Type = {
|
|||
PyObject_HEAD_INIT(NULL)
|
||||
0,
|
||||
"weakproxy",
|
||||
sizeof(PyWeakReference) + PyGC_HEAD_SIZE,
|
||||
sizeof(PyWeakReference),
|
||||
0,
|
||||
/* methods */
|
||||
(destructor)weakref_dealloc,/*tp_dealloc*/
|
||||
|
@ -447,7 +447,7 @@ PyWeakProxy_Type = {
|
|||
(getattrofunc)proxy_getattr,/*tp_getattro*/
|
||||
(setattrofunc)proxy_setattr,/*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_GC
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC
|
||||
|Py_TPFLAGS_CHECKTYPES, /*tp_flags*/
|
||||
0, /*tp_doc*/
|
||||
(traverseproc)gc_traverse, /*tp_traverse*/
|
||||
|
@ -460,7 +460,7 @@ PyWeakCallableProxy_Type = {
|
|||
PyObject_HEAD_INIT(NULL)
|
||||
0,
|
||||
"weakcallableproxy",
|
||||
sizeof(PyWeakReference) + PyGC_HEAD_SIZE,
|
||||
sizeof(PyWeakReference),
|
||||
0,
|
||||
/* methods */
|
||||
(destructor)weakref_dealloc,/*tp_dealloc*/
|
||||
|
@ -478,7 +478,7 @@ PyWeakCallableProxy_Type = {
|
|||
(getattrofunc)proxy_getattr,/*tp_getattro*/
|
||||
(setattrofunc)proxy_setattr,/*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_GC
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC
|
||||
|Py_TPFLAGS_CHECKTYPES, /*tp_flags*/
|
||||
0, /*tp_doc*/
|
||||
(traverseproc)gc_traverse, /*tp_traverse*/
|
||||
|
@ -648,7 +648,7 @@ weakref_ref(PyObject *self, PyObject *args)
|
|||
else
|
||||
insert_after(result, prev);
|
||||
}
|
||||
PyObject_GC_Init((PyObject *) result);
|
||||
PyObject_GC_Track(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -706,7 +706,7 @@ weakref_proxy(PyObject *self, PyObject *args)
|
|||
insert_head(result, list);
|
||||
else
|
||||
insert_after(result, prev);
|
||||
PyObject_GC_Init((PyObject *) result);
|
||||
PyObject_GC_Track(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,11 +7,11 @@ PyCell_New(PyObject *obj)
|
|||
{
|
||||
PyCellObject *op;
|
||||
|
||||
op = (PyCellObject *)PyObject_New(PyCellObject, &PyCell_Type);
|
||||
op = (PyCellObject *)PyObject_GC_New(PyCellObject, &PyCell_Type);
|
||||
op->ob_ref = obj;
|
||||
Py_XINCREF(obj);
|
||||
|
||||
PyObject_GC_Init(op);
|
||||
_PyObject_GC_TRACK(op);
|
||||
return (PyObject *)op;
|
||||
}
|
||||
|
||||
|
@ -42,9 +42,9 @@ PyCell_Set(PyObject *op, PyObject *obj)
|
|||
static void
|
||||
cell_dealloc(PyCellObject *op)
|
||||
{
|
||||
PyObject_GC_Fini(op);
|
||||
_PyObject_GC_UNTRACK(op);
|
||||
Py_XDECREF(op->ob_ref);
|
||||
PyObject_Del(op);
|
||||
PyObject_GC_Del(op);
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -90,7 +90,7 @@ PyTypeObject PyCell_Type = {
|
|||
PyObject_HEAD_INIT(&PyType_Type)
|
||||
0,
|
||||
"cell",
|
||||
sizeof(PyCellObject) + PyGC_HEAD_SIZE,
|
||||
sizeof(PyCellObject),
|
||||
0,
|
||||
(destructor)cell_dealloc, /* tp_dealloc */
|
||||
0, /* tp_print */
|
||||
|
@ -107,7 +107,7 @@ PyTypeObject PyCell_Type = {
|
|||
PyObject_GenericGetAttr, /* tp_getattro */
|
||||
0, /* tp_setattro */
|
||||
0, /* tp_as_buffer */
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_GC, /* tp_flags */
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */
|
||||
0, /* tp_doc */
|
||||
(traverseproc)cell_traverse, /* tp_traverse */
|
||||
(inquiry)cell_clear, /* tp_clear */
|
||||
|
|
|
@ -81,7 +81,7 @@ PyClass_New(PyObject *bases, PyObject *dict, PyObject *name)
|
|||
}
|
||||
Py_INCREF(bases);
|
||||
}
|
||||
op = PyObject_NEW(PyClassObject, &PyClass_Type);
|
||||
op = PyObject_GC_New(PyClassObject, &PyClass_Type);
|
||||
if (op == NULL) {
|
||||
Py_DECREF(bases);
|
||||
return NULL;
|
||||
|
@ -102,7 +102,7 @@ PyClass_New(PyObject *bases, PyObject *dict, PyObject *name)
|
|||
Py_XINCREF(op->cl_getattr);
|
||||
Py_XINCREF(op->cl_setattr);
|
||||
Py_XINCREF(op->cl_delattr);
|
||||
PyObject_GC_Init(op);
|
||||
_PyObject_GC_TRACK(op);
|
||||
return (PyObject *) op;
|
||||
}
|
||||
|
||||
|
@ -123,15 +123,14 @@ class_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
|||
static void
|
||||
class_dealloc(PyClassObject *op)
|
||||
{
|
||||
PyObject_GC_Fini(op);
|
||||
_PyObject_GC_UNTRACK(op);
|
||||
Py_DECREF(op->cl_bases);
|
||||
Py_DECREF(op->cl_dict);
|
||||
Py_XDECREF(op->cl_name);
|
||||
Py_XDECREF(op->cl_getattr);
|
||||
Py_XDECREF(op->cl_setattr);
|
||||
Py_XDECREF(op->cl_delattr);
|
||||
op = (PyClassObject *) PyObject_AS_GC(op);
|
||||
PyObject_DEL(op);
|
||||
PyObject_GC_Del(op);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
|
@ -394,7 +393,7 @@ PyTypeObject PyClass_Type = {
|
|||
PyObject_HEAD_INIT(&PyType_Type)
|
||||
0,
|
||||
"class",
|
||||
sizeof(PyClassObject) + PyGC_HEAD_SIZE,
|
||||
sizeof(PyClassObject),
|
||||
0,
|
||||
(destructor)class_dealloc, /* tp_dealloc */
|
||||
0, /* tp_print */
|
||||
|
@ -411,7 +410,7 @@ PyTypeObject PyClass_Type = {
|
|||
(getattrofunc)class_getattr, /* tp_getattro */
|
||||
(setattrofunc)class_setattr, /* tp_setattro */
|
||||
0, /* tp_as_buffer */
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_GC, /* tp_flags */
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */
|
||||
0, /* tp_doc */
|
||||
(traverseproc)class_traverse, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
|
@ -474,7 +473,7 @@ PyInstance_NewRaw(PyObject *klass, PyObject *dict)
|
|||
}
|
||||
Py_INCREF(dict);
|
||||
}
|
||||
inst = PyObject_NEW(PyInstanceObject, &PyInstance_Type);
|
||||
inst = PyObject_GC_New(PyInstanceObject, &PyInstance_Type);
|
||||
if (inst == NULL) {
|
||||
Py_DECREF(dict);
|
||||
return NULL;
|
||||
|
@ -483,7 +482,7 @@ PyInstance_NewRaw(PyObject *klass, PyObject *dict)
|
|||
Py_INCREF(klass);
|
||||
inst->in_class = (PyClassObject *)klass;
|
||||
inst->in_dict = dict;
|
||||
PyObject_GC_Init(inst);
|
||||
_PyObject_GC_TRACK(inst);
|
||||
return (PyObject *)inst;
|
||||
}
|
||||
|
||||
|
@ -542,7 +541,7 @@ instance_dealloc(register PyInstanceObject *inst)
|
|||
#ifdef Py_REF_DEBUG
|
||||
extern long _Py_RefTotal;
|
||||
#endif
|
||||
|
||||
_PyObject_GC_UNTRACK(inst);
|
||||
PyObject_ClearWeakRefs((PyObject *) inst);
|
||||
|
||||
/* Temporarily resurrect the object. */
|
||||
|
@ -592,6 +591,7 @@ instance_dealloc(register PyInstanceObject *inst)
|
|||
#ifdef COUNT_ALLOCS
|
||||
inst->ob_type->tp_frees--;
|
||||
#endif
|
||||
_PyObject_GC_TRACK(inst);
|
||||
return; /* __del__ added a reference; don't delete now */
|
||||
}
|
||||
#ifdef Py_TRACE_REFS
|
||||
|
@ -604,11 +604,9 @@ instance_dealloc(register PyInstanceObject *inst)
|
|||
inst->ob_type = NULL;
|
||||
#endif
|
||||
#endif
|
||||
PyObject_GC_Fini(inst);
|
||||
Py_DECREF(inst->in_class);
|
||||
Py_XDECREF(inst->in_dict);
|
||||
inst = (PyInstanceObject *) PyObject_AS_GC(inst);
|
||||
PyObject_DEL(inst);
|
||||
PyObject_GC_Del(inst);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
|
@ -1896,7 +1894,7 @@ PyTypeObject PyInstance_Type = {
|
|||
PyObject_HEAD_INIT(&PyType_Type)
|
||||
0,
|
||||
"instance",
|
||||
sizeof(PyInstanceObject) + PyGC_HEAD_SIZE,
|
||||
sizeof(PyInstanceObject),
|
||||
0,
|
||||
(destructor)instance_dealloc, /* tp_dealloc */
|
||||
0, /* tp_print */
|
||||
|
@ -1913,7 +1911,7 @@ PyTypeObject PyInstance_Type = {
|
|||
(getattrofunc)instance_getattr, /* tp_getattro */
|
||||
(setattrofunc)instance_setattr, /* tp_setattro */
|
||||
0, /* tp_as_buffer */
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_GC | Py_TPFLAGS_CHECKTYPES,/*tp_flags*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_CHECKTYPES,/*tp_flags*/
|
||||
0, /* tp_doc */
|
||||
(traverseproc)instance_traverse, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
|
@ -1946,7 +1944,7 @@ PyMethod_New(PyObject *func, PyObject *self, PyObject *class)
|
|||
PyObject_INIT(im, &PyMethod_Type);
|
||||
}
|
||||
else {
|
||||
im = PyObject_NEW(PyMethodObject, &PyMethod_Type);
|
||||
im = PyObject_GC_New(PyMethodObject, &PyMethod_Type);
|
||||
if (im == NULL)
|
||||
return NULL;
|
||||
}
|
||||
|
@ -1957,7 +1955,7 @@ PyMethod_New(PyObject *func, PyObject *self, PyObject *class)
|
|||
im->im_self = self;
|
||||
Py_XINCREF(class);
|
||||
im->im_class = class;
|
||||
PyObject_GC_Init(im);
|
||||
_PyObject_GC_TRACK(im);
|
||||
return (PyObject *)im;
|
||||
}
|
||||
|
||||
|
@ -2018,8 +2016,8 @@ instancemethod_getattro(register PyMethodObject *im, PyObject *name)
|
|||
static void
|
||||
instancemethod_dealloc(register PyMethodObject *im)
|
||||
{
|
||||
_PyObject_GC_UNTRACK(im);
|
||||
PyObject_ClearWeakRefs((PyObject *)im);
|
||||
PyObject_GC_Fini(im);
|
||||
Py_DECREF(im->im_func);
|
||||
Py_XDECREF(im->im_self);
|
||||
Py_XDECREF(im->im_class);
|
||||
|
@ -2244,7 +2242,7 @@ PyTypeObject PyMethod_Type = {
|
|||
PyObject_HEAD_INIT(&PyType_Type)
|
||||
0,
|
||||
"instance method",
|
||||
sizeof(PyMethodObject) + PyGC_HEAD_SIZE,
|
||||
sizeof(PyMethodObject),
|
||||
0,
|
||||
(destructor)instancemethod_dealloc, /* tp_dealloc */
|
||||
0, /* tp_print */
|
||||
|
@ -2261,7 +2259,7 @@ PyTypeObject PyMethod_Type = {
|
|||
(getattrofunc)instancemethod_getattro, /* tp_getattro */
|
||||
(setattrofunc)instancemethod_setattro, /* tp_setattro */
|
||||
0, /* tp_as_buffer */
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_GC, /* tp_flags */
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */
|
||||
0, /* tp_doc */
|
||||
(traverseproc)instancemethod_traverse, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
|
@ -2287,7 +2285,6 @@ PyMethod_Fini(void)
|
|||
while (free_list) {
|
||||
PyMethodObject *im = free_list;
|
||||
free_list = (PyMethodObject *)(im->im_self);
|
||||
im = (PyMethodObject *) PyObject_AS_GC(im);
|
||||
PyObject_DEL(im);
|
||||
PyObject_GC_Del(im);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -158,7 +158,7 @@ PyDict_New(void)
|
|||
Py_AtExit(show_counts);
|
||||
#endif
|
||||
}
|
||||
mp = PyObject_NEW(dictobject, &PyDict_Type);
|
||||
mp = PyObject_GC_New(dictobject, &PyDict_Type);
|
||||
if (mp == NULL)
|
||||
return NULL;
|
||||
EMPTY_TO_MINSIZE(mp);
|
||||
|
@ -166,7 +166,7 @@ PyDict_New(void)
|
|||
#ifdef SHOW_CONVERSION_COUNTS
|
||||
++created;
|
||||
#endif
|
||||
PyObject_GC_Init(mp);
|
||||
_PyObject_GC_TRACK(mp);
|
||||
return (PyObject *)mp;
|
||||
}
|
||||
|
||||
|
@ -692,7 +692,7 @@ dict_dealloc(register dictobject *mp)
|
|||
register dictentry *ep;
|
||||
int fill = mp->ma_fill;
|
||||
Py_TRASHCAN_SAFE_BEGIN(mp)
|
||||
PyObject_GC_Fini(mp);
|
||||
_PyObject_GC_UNTRACK(mp);
|
||||
for (ep = mp->ma_table; fill > 0; ep++) {
|
||||
if (ep->me_key) {
|
||||
--fill;
|
||||
|
@ -702,8 +702,7 @@ dict_dealloc(register dictobject *mp)
|
|||
}
|
||||
if (mp->ma_table != mp->ma_smalltable)
|
||||
PyMem_DEL(mp->ma_table);
|
||||
mp = (dictobject *) PyObject_AS_GC(mp);
|
||||
PyObject_DEL(mp);
|
||||
PyObject_GC_Del(mp);
|
||||
Py_TRASHCAN_SAFE_END(mp)
|
||||
}
|
||||
|
||||
|
@ -1703,7 +1702,7 @@ PyTypeObject PyDict_Type = {
|
|||
PyObject_HEAD_INIT(&PyType_Type)
|
||||
0,
|
||||
"dictionary",
|
||||
sizeof(dictobject) + PyGC_HEAD_SIZE,
|
||||
sizeof(dictobject),
|
||||
0,
|
||||
(destructor)dict_dealloc, /* tp_dealloc */
|
||||
(printfunc)dict_print, /* tp_print */
|
||||
|
@ -1720,7 +1719,7 @@ PyTypeObject PyDict_Type = {
|
|||
PyObject_GenericGetAttr, /* tp_getattro */
|
||||
0, /* tp_setattro */
|
||||
0, /* tp_as_buffer */
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_GC |
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
|
||||
Py_TPFLAGS_BASETYPE, /* tp_flags */
|
||||
"dictionary type", /* tp_doc */
|
||||
(traverseproc)dict_traverse, /* tp_traverse */
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
PyObject *
|
||||
PyFunction_New(PyObject *code, PyObject *globals)
|
||||
{
|
||||
PyFunctionObject *op = PyObject_NEW(PyFunctionObject,
|
||||
PyFunctionObject *op = PyObject_GC_New(PyFunctionObject,
|
||||
&PyFunction_Type);
|
||||
if (op != NULL) {
|
||||
PyObject *doc;
|
||||
|
@ -37,7 +37,7 @@ PyFunction_New(PyObject *code, PyObject *globals)
|
|||
}
|
||||
else
|
||||
return NULL;
|
||||
PyObject_GC_Init(op);
|
||||
_PyObject_GC_TRACK(op);
|
||||
return (PyObject *)op;
|
||||
}
|
||||
|
||||
|
@ -223,8 +223,8 @@ func_setattro(PyObject *op, PyObject *name, PyObject *value)
|
|||
static void
|
||||
func_dealloc(PyFunctionObject *op)
|
||||
{
|
||||
_PyObject_GC_UNTRACK(op);
|
||||
PyObject_ClearWeakRefs((PyObject *) op);
|
||||
PyObject_GC_Fini(op);
|
||||
Py_DECREF(op->func_code);
|
||||
Py_DECREF(op->func_globals);
|
||||
Py_DECREF(op->func_name);
|
||||
|
@ -232,8 +232,7 @@ func_dealloc(PyFunctionObject *op)
|
|||
Py_XDECREF(op->func_doc);
|
||||
Py_XDECREF(op->func_dict);
|
||||
Py_XDECREF(op->func_closure);
|
||||
op = (PyFunctionObject *) PyObject_AS_GC(op);
|
||||
PyObject_DEL(op);
|
||||
PyObject_GC_Del(op);
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
|
@ -352,7 +351,7 @@ PyTypeObject PyFunction_Type = {
|
|||
PyObject_HEAD_INIT(&PyType_Type)
|
||||
0,
|
||||
"function",
|
||||
sizeof(PyFunctionObject) + PyGC_HEAD_SIZE,
|
||||
sizeof(PyFunctionObject),
|
||||
0,
|
||||
(destructor)func_dealloc, /* tp_dealloc */
|
||||
0, /* tp_print */
|
||||
|
@ -369,7 +368,7 @@ PyTypeObject PyFunction_Type = {
|
|||
func_getattro, /* tp_getattro */
|
||||
func_setattro, /* tp_setattro */
|
||||
0, /* tp_as_buffer */
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_GC, /* tp_flags */
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */
|
||||
0, /* tp_doc */
|
||||
(traverseproc)func_traverse, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
|
|
|
@ -61,27 +61,23 @@ PyList_New(int size)
|
|||
if (nbytes / sizeof(PyObject *) != (size_t)size) {
|
||||
return PyErr_NoMemory();
|
||||
}
|
||||
/* PyObject_NewVar is inlined */
|
||||
op = (PyListObject *) PyObject_MALLOC(sizeof(PyListObject)
|
||||
+ PyGC_HEAD_SIZE);
|
||||
op = PyObject_GC_New(PyListObject, &PyList_Type);
|
||||
if (op == NULL) {
|
||||
return PyErr_NoMemory();
|
||||
return NULL;
|
||||
}
|
||||
op = (PyListObject *) PyObject_FROM_GC(op);
|
||||
if (size <= 0) {
|
||||
op->ob_item = NULL;
|
||||
}
|
||||
else {
|
||||
op->ob_item = (PyObject **) PyMem_MALLOC(nbytes);
|
||||
if (op->ob_item == NULL) {
|
||||
PyObject_FREE(PyObject_AS_GC(op));
|
||||
return PyErr_NoMemory();
|
||||
}
|
||||
}
|
||||
PyObject_INIT_VAR(op, &PyList_Type, size);
|
||||
op->ob_size = size;
|
||||
for (i = 0; i < size; i++)
|
||||
op->ob_item[i] = NULL;
|
||||
PyObject_GC_Init(op);
|
||||
_PyObject_GC_TRACK(op);
|
||||
return (PyObject *) op;
|
||||
}
|
||||
|
||||
|
@ -200,7 +196,7 @@ list_dealloc(PyListObject *op)
|
|||
{
|
||||
int i;
|
||||
Py_TRASHCAN_SAFE_BEGIN(op)
|
||||
PyObject_GC_Fini(op);
|
||||
_PyObject_GC_UNTRACK(op);
|
||||
if (op->ob_item != NULL) {
|
||||
/* Do it backwards, for Christian Tismer.
|
||||
There's a simple test case where somehow this reduces
|
||||
|
@ -212,8 +208,7 @@ list_dealloc(PyListObject *op)
|
|||
}
|
||||
PyMem_FREE(op->ob_item);
|
||||
}
|
||||
op = (PyListObject *) PyObject_AS_GC(op);
|
||||
PyObject_DEL(op);
|
||||
PyObject_GC_Del(op);
|
||||
Py_TRASHCAN_SAFE_END(op)
|
||||
}
|
||||
|
||||
|
@ -1675,7 +1670,7 @@ PyTypeObject PyList_Type = {
|
|||
PyObject_HEAD_INIT(&PyType_Type)
|
||||
0,
|
||||
"list",
|
||||
sizeof(PyListObject) + PyGC_HEAD_SIZE,
|
||||
sizeof(PyListObject),
|
||||
0,
|
||||
(destructor)list_dealloc, /* tp_dealloc */
|
||||
(printfunc)list_print, /* tp_print */
|
||||
|
@ -1692,7 +1687,7 @@ PyTypeObject PyList_Type = {
|
|||
PyObject_GenericGetAttr, /* tp_getattro */
|
||||
0, /* tp_setattro */
|
||||
0, /* tp_as_buffer */
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_GC |
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
|
||||
Py_TPFLAGS_BASETYPE, /* tp_flags */
|
||||
list_doc, /* tp_doc */
|
||||
(traverseproc)list_traverse, /* tp_traverse */
|
||||
|
@ -1762,7 +1757,7 @@ static PyTypeObject immutable_list_type = {
|
|||
PyObject_HEAD_INIT(&PyType_Type)
|
||||
0,
|
||||
"list (immutable, during sort)",
|
||||
sizeof(PyListObject) + PyGC_HEAD_SIZE,
|
||||
sizeof(PyListObject),
|
||||
0,
|
||||
0, /* Cannot happen */ /* tp_dealloc */
|
||||
(printfunc)list_print, /* tp_print */
|
||||
|
@ -1779,7 +1774,7 @@ static PyTypeObject immutable_list_type = {
|
|||
PyObject_GenericGetAttr, /* tp_getattro */
|
||||
0, /* tp_setattro */
|
||||
0, /* tp_as_buffer */
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_GC, /* tp_flags */
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */
|
||||
list_doc, /* tp_doc */
|
||||
(traverseproc)list_traverse, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
|
|
|
@ -19,12 +19,11 @@ PyModule_New(char *name)
|
|||
{
|
||||
PyModuleObject *m;
|
||||
PyObject *nameobj;
|
||||
m = PyObject_NEW(PyModuleObject, &PyModule_Type);
|
||||
m = PyObject_GC_New(PyModuleObject, &PyModule_Type);
|
||||
if (m == NULL)
|
||||
return NULL;
|
||||
nameobj = PyString_FromString(name);
|
||||
m->md_dict = PyDict_New();
|
||||
PyObject_GC_Init(m);
|
||||
if (m->md_dict == NULL || nameobj == NULL)
|
||||
goto fail;
|
||||
if (PyDict_SetItemString(m->md_dict, "__name__", nameobj) != 0)
|
||||
|
@ -32,6 +31,7 @@ PyModule_New(char *name)
|
|||
if (PyDict_SetItemString(m->md_dict, "__doc__", Py_None) != 0)
|
||||
goto fail;
|
||||
Py_DECREF(nameobj);
|
||||
PyObject_GC_Track(m);
|
||||
return (PyObject *)m;
|
||||
|
||||
fail:
|
||||
|
@ -146,12 +146,12 @@ module_init(PyModuleObject *m, PyObject *args, PyObject *kw)
|
|||
static void
|
||||
module_dealloc(PyModuleObject *m)
|
||||
{
|
||||
PyObject_GC_Fini(m);
|
||||
PyObject_GC_UnTrack(m);
|
||||
if (m->md_dict != NULL) {
|
||||
_PyModule_Clear((PyObject *)m);
|
||||
Py_DECREF(m->md_dict);
|
||||
}
|
||||
PyObject_DEL(PyObject_AS_GC(m));
|
||||
PyObject_GC_Del(m);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
|
@ -188,7 +188,7 @@ PyTypeObject PyModule_Type = {
|
|||
PyObject_HEAD_INIT(&PyType_Type)
|
||||
0, /* ob_size */
|
||||
"module", /* tp_name */
|
||||
sizeof(PyModuleObject) + PyGC_HEAD_SIZE, /* tp_size */
|
||||
sizeof(PyModuleObject), /* tp_size */
|
||||
0, /* tp_itemsize */
|
||||
(destructor)module_dealloc, /* tp_dealloc */
|
||||
0, /* tp_print */
|
||||
|
@ -205,7 +205,7 @@ PyTypeObject PyModule_Type = {
|
|||
PyObject_GenericGetAttr, /* tp_getattro */
|
||||
PyObject_GenericSetAttr, /* tp_setattro */
|
||||
0, /* tp_as_buffer */
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_GC |
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
|
||||
Py_TPFLAGS_BASETYPE, /* tp_flags */
|
||||
0, /* tp_doc */
|
||||
(traverseproc)module_traverse, /* tp_traverse */
|
||||
|
|
|
@ -62,18 +62,14 @@ PyTuple_New(register int size)
|
|||
int nbytes = size * sizeof(PyObject *);
|
||||
/* Check for overflow */
|
||||
if (nbytes / sizeof(PyObject *) != (size_t)size ||
|
||||
(nbytes += sizeof(PyTupleObject) - sizeof(PyObject *)
|
||||
+ PyGC_HEAD_SIZE)
|
||||
(nbytes += sizeof(PyTupleObject) - sizeof(PyObject *))
|
||||
<= 0)
|
||||
{
|
||||
return PyErr_NoMemory();
|
||||
}
|
||||
/* PyObject_NewVar is inlined */
|
||||
op = (PyTupleObject *) PyObject_MALLOC(nbytes);
|
||||
op = PyObject_GC_NewVar(PyTupleObject, &PyTuple_Type, size);
|
||||
if (op == NULL)
|
||||
return PyErr_NoMemory();
|
||||
op = (PyTupleObject *) PyObject_FROM_GC(op);
|
||||
PyObject_INIT_VAR(op, &PyTuple_Type, size);
|
||||
return NULL;
|
||||
}
|
||||
for (i = 0; i < size; i++)
|
||||
op->ob_item[i] = NULL;
|
||||
|
@ -84,7 +80,7 @@ PyTuple_New(register int size)
|
|||
Py_INCREF(op); /* extra INCREF so that this is never freed */
|
||||
}
|
||||
#endif
|
||||
PyObject_GC_Init(op);
|
||||
_PyObject_GC_TRACK(op);
|
||||
return (PyObject *) op;
|
||||
}
|
||||
|
||||
|
@ -144,7 +140,7 @@ tupledealloc(register PyTupleObject *op)
|
|||
register int i;
|
||||
register int len = op->ob_size;
|
||||
Py_TRASHCAN_SAFE_BEGIN(op)
|
||||
PyObject_GC_Fini(op);
|
||||
_PyObject_GC_UNTRACK(op);
|
||||
if (len > 0) {
|
||||
i = len;
|
||||
while (--i >= 0)
|
||||
|
@ -158,8 +154,7 @@ tupledealloc(register PyTupleObject *op)
|
|||
}
|
||||
#endif
|
||||
}
|
||||
op = (PyTupleObject *) PyObject_AS_GC(op);
|
||||
PyObject_DEL(op);
|
||||
PyObject_GC_Del(op);
|
||||
done:
|
||||
Py_TRASHCAN_SAFE_END(op)
|
||||
}
|
||||
|
@ -517,7 +512,7 @@ PyTypeObject PyTuple_Type = {
|
|||
PyObject_HEAD_INIT(&PyType_Type)
|
||||
0,
|
||||
"tuple",
|
||||
sizeof(PyTupleObject) - sizeof(PyObject *) + PyGC_HEAD_SIZE,
|
||||
sizeof(PyTupleObject) - sizeof(PyObject *),
|
||||
sizeof(PyObject *),
|
||||
(destructor)tupledealloc, /* tp_dealloc */
|
||||
(printfunc)tupleprint, /* tp_print */
|
||||
|
@ -534,7 +529,7 @@ PyTypeObject PyTuple_Type = {
|
|||
PyObject_GenericGetAttr, /* tp_getattro */
|
||||
0, /* tp_setattro */
|
||||
0, /* tp_as_buffer */
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_GC, /* tp_flags */
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */
|
||||
tuple_doc, /* tp_doc */
|
||||
(traverseproc)tupletraverse, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
|
@ -595,30 +590,23 @@ _PyTuple_Resize(PyObject **pv, int newsize)
|
|||
#ifdef Py_REF_DEBUG
|
||||
--_Py_RefTotal;
|
||||
#endif
|
||||
_PyObject_GC_UNTRACK(v);
|
||||
_Py_ForgetReference((PyObject *) v);
|
||||
for (i = newsize; i < v->ob_size; i++) {
|
||||
Py_XDECREF(v->ob_item[i]);
|
||||
v->ob_item[i] = NULL;
|
||||
}
|
||||
PyObject_GC_Fini(v);
|
||||
v = (PyTupleObject *) PyObject_AS_GC(v);
|
||||
sv = (PyTupleObject *) PyObject_REALLOC((char *)v,
|
||||
sizeof(PyTupleObject)
|
||||
+ PyGC_HEAD_SIZE
|
||||
+ newsize * sizeof(PyObject *));
|
||||
sv = PyObject_GC_Resize(PyTupleObject, v, newsize);
|
||||
if (sv == NULL) {
|
||||
*pv = NULL;
|
||||
PyObject_DEL(v);
|
||||
PyErr_NoMemory();
|
||||
PyObject_GC_Del(v);
|
||||
return -1;
|
||||
}
|
||||
sv = (PyTupleObject *) PyObject_FROM_GC(sv);
|
||||
_Py_NewReference((PyObject *) sv);
|
||||
for (i = sv->ob_size; i < newsize; i++)
|
||||
sv->ob_item[i] = NULL;
|
||||
sv->ob_size = newsize;
|
||||
*pv = (PyObject *) sv;
|
||||
PyObject_GC_Init(sv);
|
||||
_PyObject_GC_TRACK(sv);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -638,8 +626,7 @@ PyTuple_Fini(void)
|
|||
while (p) {
|
||||
q = p;
|
||||
p = (PyTupleObject *)(p->ob_item[0]);
|
||||
q = (PyTupleObject *) PyObject_AS_GC(q);
|
||||
PyObject_DEL(q);
|
||||
PyObject_GC_Del(q);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue