summaryrefslogtreecommitdiffstats
path: root/Objects/listobject.c
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2004-01-18 20:29:55 (GMT)
committerTim Peters <tim.peters@gmail.com>2004-01-18 20:29:55 (GMT)
commit58eb11cf62dd04ccc2c364b62fd51b4265e2e203 (patch)
tree6b4639f640391b3d40332ee045dba325c63a920d /Objects/listobject.c
parent5303a968080bdb2690eaab89495ae51939fa6397 (diff)
downloadcpython-58eb11cf62dd04ccc2c364b62fd51b4265e2e203.zip
cpython-58eb11cf62dd04ccc2c364b62fd51b4265e2e203.tar.gz
cpython-58eb11cf62dd04ccc2c364b62fd51b4265e2e203.tar.bz2
Whitespace normalization.
Diffstat (limited to 'Objects/listobject.c')
-rw-r--r--Objects/listobject.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c
index 3397fbb..a18f3d7 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -57,13 +57,15 @@ PyList_New(int size)
{
PyListObject *op;
size_t nbytes;
+ int allocated_size = roundupsize(size);
+
if (size < 0) {
PyErr_BadInternalCall();
return NULL;
}
- nbytes = size * sizeof(PyObject *);
+ nbytes = allocated_size * sizeof(PyObject *);
/* Check for overflow */
- if (nbytes / sizeof(PyObject *) != (size_t)size) {
+ if (nbytes / sizeof(PyObject *) != (size_t)allocated_size) {
return PyErr_NoMemory();
}
op = PyObject_GC_New(PyListObject, &PyList_Type);
@@ -78,7 +80,7 @@ PyList_New(int size)
if (op->ob_item == NULL) {
return PyErr_NoMemory();
}
- memset(op->ob_item, 0, sizeof(*op->ob_item) * size);
+ memset(op->ob_item, 0, sizeof(*op->ob_item) * allocated_size);
}
op->ob_size = size;
_PyObject_GC_TRACK(op);
@@ -154,7 +156,8 @@ ins1(PyListObject *self, int where, PyObject *v)
return -1;
}
items = self->ob_item;
- NRESIZE(items, PyObject *, self->ob_size+1);
+ if (roundupsize(self->ob_size) - 1 == self->ob_size || items == NULL)
+ NRESIZE(items, PyObject *, self->ob_size+1);
if (items == NULL) {
PyErr_NoMemory();
return -1;
@@ -1878,7 +1881,8 @@ listsort(PyListObject *self, PyObject *args, PyObject *kwds)
saved_ob_size = self->ob_size;
saved_ob_item = self->ob_item;
self->ob_size = 0;
- self->ob_item = empty_ob_item = PyMem_NEW(PyObject *, 0);
+/* self->ob_item = empty_ob_item = PyMem_NEW(PyObject *, 0); */
+ self->ob_item = empty_ob_item = PyMem_NEW(PyObject *, roundupsize(0));
if (keyfunc != NULL) {
for (i=0 ; i < saved_ob_size ; i++) {