summaryrefslogtreecommitdiffstats
path: root/Objects/listobject.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2000-05-03 23:44:39 (GMT)
committerGuido van Rossum <guido@python.org>2000-05-03 23:44:39 (GMT)
commitb18618dab7b6b85bb05b084693706e59211fa180 (patch)
tree785d51f6677da8366be2ad4b4296a62f53161276 /Objects/listobject.c
parent2808b744e8d94459f189e1d89c97072d6a1f53b6 (diff)
downloadcpython-b18618dab7b6b85bb05b084693706e59211fa180.zip
cpython-b18618dab7b6b85bb05b084693706e59211fa180.tar.gz
cpython-b18618dab7b6b85bb05b084693706e59211fa180.tar.bz2
Vladimir Marangozov's long-awaited malloc restructuring.
For more comments, read the patches@python.org archives. For documentation read the comments in mymalloc.h and objimpl.h. (This is not exactly what Vladimir posted to the patches list; I've made a few changes, and Vladimir sent me a fix in private email for a problem that only occurs in debug mode. I'm also holding back on his change to main.c, which seems unnecessary to me.)
Diffstat (limited to 'Objects/listobject.c')
-rw-r--r--Objects/listobject.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c
index 005d709..f70d19b 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -70,7 +70,8 @@ PyList_New(size)
if (nbytes / sizeof(PyObject *) != (size_t)size) {
return PyErr_NoMemory();
}
- op = (PyListObject *) malloc(sizeof(PyListObject));
+ /* PyObject_NewVar is inlined */
+ op = (PyListObject *) PyObject_MALLOC(sizeof(PyListObject));
if (op == NULL) {
return PyErr_NoMemory();
}
@@ -78,17 +79,15 @@ PyList_New(size)
op->ob_item = NULL;
}
else {
- op->ob_item = (PyObject **) malloc(nbytes);
+ op->ob_item = (PyObject **) PyMem_MALLOC(nbytes);
if (op->ob_item == NULL) {
- free((ANY *)op);
+ PyObject_FREE(op);
return PyErr_NoMemory();
}
}
- op->ob_type = &PyList_Type;
- op->ob_size = size;
+ PyObject_INIT_VAR(op, &PyList_Type, size);
for (i = 0; i < size; i++)
op->ob_item[i] = NULL;
- _Py_NewReference((PyObject *)op);
return (PyObject *) op;
}
@@ -225,9 +224,9 @@ list_dealloc(op)
while (--i >= 0) {
Py_XDECREF(op->ob_item[i]);
}
- free((ANY *)op->ob_item);
+ PyMem_FREE(op->ob_item);
}
- free((ANY *)op);
+ PyObject_DEL(op);
Py_TRASHCAN_SAFE_END(op)
}
@@ -501,7 +500,8 @@ list_ass_slice(a, ilow, ihigh, v)
else { /* Insert d items; recycle ihigh-ilow items */
NRESIZE(item, PyObject *, a->ob_size + d);
if (item == NULL) {
- PyMem_XDEL(recycle);
+ if (recycle != NULL)
+ PyMem_DEL(recycle);
PyErr_NoMemory();
return -1;
}